'-------------------------------------------------------------------------------
' MMCSD_Analysis.BAS
' Test MMC / SD Card
'-------------------------------------------------------------------------------
' Show the Card Capacity and the Card-Register CSD, CID, OCR and SD_Status
' First you have to init the Card in the File Config_MMCSD_HC.bas with
' $Include "Config_MMCSD_HC.bas"
' All Card registers are written with the MSB first to the Byte-array
' f.E. CSD(1) contains then MSB (Bit 120-127) of the CSD-Register
$regfile = "m128def.dat"
$crystal = 7372800 '8000000
$hwstack = 128
$swstack = 128
$framesize = 128
$baud = 57600
Config Serialin = Buffered , Size = 20
Config Clock = Soft
Enable Interrupts
Config Date = Dmy , Separator = .
Print "Test_Dos_Drive compiled at " ; Version()
$include "Config_MMCSD_HC.bas"
$include "Config_AVR-DOS.BAS"
Dim Xc As Byte ' for Print - counter
Dim Xd As Byte ' for Print - Counter
Print "Start of Card Analysis"
Print "Last Drive-Error-Code = " ; Gbdriveerror
Print "Gbdrivestatusreg =" ; Gbdrivestatusreg
' Check detected Card Type
Select Case Mmcsd_cardtype
Case 1
Print "MMC-Card detected"
Case 2
Print "SD-Card Spec. 1.x detected"
Case 4
Print "SD-Card Spec. 2.0 detected"
Case 12
Print "SD-Card Spec. 2.0 High Capacity detected"
Case Else
Print "No Card detected"
End Select
If Mmcsd_cardtype > 0 Then
' check the CSD Register
Dim Csd(16) As Byte
Print "Get CSD"
Csd(1) = Mmcsd_getcsd()
If Gbdriveerror <> 0 Then
Print "Error at reading CSD"
Else
For Xc = 1 To 16
Print Hex(csd(xc)) ; " " ;
Next
Print " "
End If
' Get the Card Capacity from the CSD Register
Dim Mmcsd_size As Long
Print "Get Card Capacity [KB]"
Mmcsd_size = Mmcsd_getsize()
If Gbdriveerror <> 0 Then
Print "Error at reading CSD"
Else
Print "Card Capacity = " ; Mmcsd_size ; "kb (1KB=1024 Bytes)"
End If
' Get the CID Register
Dim Cid(16) As Byte
Print "Get CID"
Cid(1) = Mmcsd_getcid()
If Gbdriveerror <> 0 Then
Print "Error at reading CID"
Else
For Xc = 1 To 16
Print Hex(cid(xc)) ; " " ;
Next
Print " "
End If
' Get the OCR Register
Dim Ocr(4) As Byte
Print "Get OCR"
Ocr(1) = Mmcsd_getocr()
If Gbdriveerror <> 0 Then
Print "Error at reading OCR"
Else
For Xc = 1 To 4
Print Hex(ocr(xc)) ; " " ;
Next
Print " "
End If
If Mmcsd_cardtype > 1 Then
' Get the SD_Status Register on SD-Cards
Dim Sd_status(64) As Byte
Print "Get SD_Status"
Sd_status(1) = Sd_getsd_status()
If Gbdriveerror <> 0 Then
Print "Error at reading SD_Status"
Else
For Xc = 1 To 64
Print Hex(sd_status(xc)) ; " " ;
Xd = Xc Mod 8
If Xd = 0 Then
Print " "
End If
Next
End If
End If
End If
Print "End of Card Analysis"
Dim Btemp1 As Byte
Print "Init File System ... ";
Btemp1 = Initfilesystem(1) ' Partition 1
' use 0 for drive without Master boot record
If Btemp1 <> 0 Then
Print "Error: " ; Btemp1 ; " at Init file system"
Else
Print " OK"
Print "Filesystem: " ; Gbfilesystem
Print "FAT Start Sector: " ; Glfatfirstsector
Print "Root Start Sector: " ; Glrootfirstsector
Print "Data First Sector: " ; Gldatafirstsector
Print "Max. Cluster Nummber: " ; Glmaxclusternumber
Print "Sectors per Cluster: " ; Gbsectorspercluster
Print "Root Entries: " ; Gwrootentries
Print "Sectors per FAT: " ; Glsectorsperfat
Print "Number of FATs: " ; Gbnumberoffats
End If
End