📄 sddriver.lis
字号:
.module sddriver.c
.area lit(rom, con, rel)
0000 _time_unit::
0000 00CA9A3B .word 51712,15258
0004 00E1F505 .word 57600,1525
0008 80969800 .word 38528,152
000C 40420F00 .word 16960,15
0010 A0860100 .word 34464,1
0014 10270000 .word 10000,0
0018 E8030000 .word 1000,0
001C 64000000 .word 100,0
0020 .dbfile D:\new_sd\SD\SD\sddriver.c
0020 .dbsym e time_unit _time_unit A[32:8]kl
0020 _time_value::
0020 000A .byte 0,10
0022 0C0D .byte 12,13
0024 0F14 .byte 15,20
0026 191E .byte 25,30
0028 2328 .byte 35,40
002A 2D32 .byte 45,50
002C 373C .byte 55,60
002E 4650 .byte 'F,'P
0030 .dbsym e time_value _time_value A[16:16]kc
0030 _r2w_fator::
0030 0102 .byte 1,2
0032 0408 .byte 4,8
0034 1020 .byte 16,32
0036 .dbsym e r2w_fator _r2w_fator A[6:6]kc
.area text(rom, con, rel)
0000 .dbfile D:\new_sd\SD\SD\sddriver.c
0000 .dbfunc e SD_Initialize _SD_Initialize fc
0000 ; recbuf -> y+0
0000 ; ret -> R10
.even
0000 _SD_Initialize::
0000 0E940000 xcall push_gset3
0004 2497 sbiw R28,4
0006 .dbline -1
0006 .dbline 35
0006 ; /*******************************************************************************************************
0006 ; ** Descriptions: sd 卡驱动软件包: SD卡物理层 用户API函数
0006 ; ********************************************************************************************************/
0006 ; #include "D:\new_sd\define.h"
0006 ;
0006 ;
0006 ; /* SD卡信息结构体变量 the information structure variable of SD Card */
0006 ; sd_struct sds;
0006 ;
0006 ; /* 超时时间单位表(单位:0.000000001ns) timeout unit table */
0006 ; const uint32 time_unit[8] = {1000000000,100000000,10000000,
0006 ; 1000000,100000,10000,1000,100};
0006 ;
0006 ; /* 超时时间表 timeout value table */
0006 ; const uint8 time_value[16] = { 0,10,12,13,15,20,25,30,
0006 ; 35,40,45,50,55,60,70,80};
0006 ;
0006 ; /* 超时时间因数表 timeout factor table */
0006 ; const uint8 r2w_fator[6] = {1,2,4,8,16,32};
0006 ;
0006 ; /********************************************************************************************
0006 ;
0006 ; 用户API函数: 初始化,读,写,擦 SD卡 User API Function: Initialize,read,write,erase SD Card
0006 ;
0006 ; ********************************************************************************************/
0006 ;
0006 ;
0006 ; /*******************************************************************************************************************
0006 ; ** 函数名称: INT8U SD_Initialize() Name: INT8U SD_Initialize()
0006 ; ** 功能描述: 初始化SD卡 Function: initialize sd card
0006 ; ** 输 入: 无 Input: NULL
0006 ; ** 输 出: 0: 正确 >0: 错误码 Output: 0: right >0: error code
0006 ; ********************************************************************************************************************/
0006 ; uint8 SD_Initialize(void)
0006 ; {
0006 .dbline 38
0006 ; uint8 recbuf[4],ret;
0006 ;
0006 ; SD_HardWareInit(); /* 初始化读写SD卡的硬件条件 Initialize the hardware that access SD Card */
0006 0E940000 xcall _SD_HardWareInit
000A .dbline 40
000A ;
000A ; SPI_CS_Assert(); /* 1. 置CS为低 assert CS */
000A 0E940000 xcall _SPI_CS_Assert
000E .dbline 41
000E ; SD_SPIDelay(30); /* 2. 至少延时 74 clock delay more than 74 clock */
000E 0EE1 ldi R16,30
0010 0E940000 xcall _SD_SPIDelay
0014 .dbline 42
0014 ; SPI_CS_Deassert(); /* 3. 置CS为高 dessert CS */
0014 0E940000 xcall _SPI_CS_Deassert
0018 .dbline 43
0018 ; SD_SPIDelay(3); /* 4. 延时2(8 clock) delay 2(8 clock) */
0018 03E0 ldi R16,3
001A 0E940000 xcall _SD_SPIDelay
001E .dbline 45
001E ;
001E ; ret = SD_ResetSD(); /* 5. 发出CMDO命令复位SD卡 send CMD0 command to reset sd card */
001E 0E940000 xcall _SD_ResetSD
0022 A02E mov R10,R16
0024 .dbline 46
0024 ; if (ret != SD_NO_ERR)
0024 0023 tst R16
0026 09F0 breq L2
0028 .dbline 47
0028 ; return ret;
0028 27C0 xjmp L1
002A L2:
002A .dbline 49
002A ;
002A ; ret = SD_ActiveInit(); /* 6. 激活卡进入初始化过程. active card initialize process */
002A 86D1 xcall _SD_ActiveInit
002C A02E mov R10,R16
002E .dbline 50
002E ; if (ret != SD_NO_ERR)
002E 0023 tst R16
0030 09F0 breq L4
0032 .dbline 51
0032 ; return ret;
0032 22C0 xjmp L1
0034 L4:
0034 .dbline 53
0034 ;
0034 ; ret = SD_ReadOCR(4, recbuf); /* 7. 读OCR寄存器,查询卡支持的电压值 read OCR register,get the supported voltage */
0034 9E01 movw R18,R28
0036 04E0 ldi R16,4
0038 0E940000 xcall _SD_ReadOCR
003C A02E mov R10,R16
003E .dbline 54
003E ; if (ret != SD_NO_ERR)
003E 0023 tst R16
0040 09F0 breq L6
0042 .dbline 55
0042 ; return ret;
0042 1AC0 xjmp L1
0044 L6:
0044 .dbline 57
0044 ;
0044 ; if ((recbuf[1] & MSK_OCR_33) != MSK_OCR_33)
0044 8981 ldd R24,y+1
0046 807C andi R24,192
0048 803C cpi R24,192
004A 11F0 breq L8
004C .dbline 58
004C ; return SD_ERR_VOL_NOTSUSP; /* 不支持3.3V,返回错误码 not support 3.3V,return error code */
004C 04E0 ldi R16,4
004E 14C0 xjmp L1
0050 L8:
0050 .dbline 60
0050 ;
0050 ; SPI_ClkToMax(); /* 8. 设置SPI时钟到最大值 set SPI clock to maximum */
0050 0E940000 xcall _SPI_ClkToMax
0054 .dbline 63
0054 ;
0054 ; #if SD_CRC_EN
0054 ; ret = SD_EnableCRC(1); /* 使能CRC校验 enable CRC check */
0054 01E0 ldi R16,1
0056 0E940000 xcall _SD_EnableCRC
005A A02E mov R10,R16
005C .dbline 64
005C ; if (ret != SD_NO_ERR)
005C 0023 tst R16
005E 09F0 breq L11
0060 .dbline 65
0060 ; return ret;
0060 0BC0 xjmp L1
0062 L11:
0062 .dbline 68
0062 ; #endif
0062 ;
0062 ; ret = SD_SetBlockLen(SD_BLOCKSIZE); /* 9. 设置块的长度: 512Bytes Set the block length: 512Bytes */
0062 00E0 ldi R16,0
0064 12E0 ldi R17,2
0066 20E0 ldi R18,0
0068 30E0 ldi R19,0
006A 0E940000 xcall _SD_SetBlockLen
006E A02E mov R10,R16
0070 .dbline 69
0070 ; if (ret != SD_NO_ERR)
0070 0023 tst R16
0072 09F0 breq L13
0074 .dbline 70
0074 ; return ret;
0074 01C0 xjmp L1
0076 L13:
0076 .dbline 72
0076 ;
0076 ; return (SD_GetCardInfo()); /* 10. 读CSD寄存器,获取SD卡信息 read CSD register, get the information of SD card */
0076 04D0 xcall _SD_GetCardInfo
0078 .dbline -2
0078 L1:
0078 2496 adiw R28,4
007A 0E940000 xcall pop_gset3
007E .dbline 0 ; func end
007E 0895 ret
0080 .dbsym l recbuf 0 A[4:4]c
0080 .dbsym r ret 10 c
0080 .dbend
0080 .dbfunc e SD_GetCardInfo _SD_GetCardInfo fc
0080 ; tmp -> y+16
0080 ; ret -> R20
0080 ; csdbuf -> y+0
.even
0080 _SD_GetCardInfo::
0080 0E940000 xcall push_gset1
0084 6497 sbiw R28,20
0086 .dbline -1
0086 .dbline 82
0086 ; }
0086 ;
0086 ; /*******************************************************************************************************************
0086 ; ** 函数名称: INT8U SD_GetCardInfo() Name: INT8U SD_GetCardInfo()
0086 ; ** 功能描述: 获得SD卡的信息 Function: get the information of SD card
0086 ; ** 输 入: INT8U cardtype: 卡类型 Input: INT8U cardtype: card type
0086 ; ** 输 出: 0: 正确 >0: 错误码 Output: 0: right >0: error code
0086 ; *******************************************************************************************************************/
0086 ; uint8 SD_GetCardInfo()
0086 ; {
0086 .dbline 86
0086 ; uint32 tmp;
0086 ; uint8 csdbuf[16],ret;
0086 ;
0086 ; ret = SD_ReadCSD(16,csdbuf); /* 读CSD寄存器 read CSD register */
0086 9E01 movw R18,R28
0088 00E1 ldi R16,16
008A 0E940000 xcall _SD_ReadCSD
008E 402F mov R20,R16
0090 .dbline 87
0090 ; if (ret != SD_NO_ERR)
0090 0023 tst R16
0092 09F0 breq L16
0094 .dbline 88
0094 ; return ret;
0094 5DC0 xjmp L15
0096 L16:
0096 .dbline 90
0096 ;
0096 ; SD_CalTimeout(csdbuf); /* 计算超时时间值 calculate timeout value */
0096 8E01 movw R16,R28
0098 5FD0 xcall _SD_CalTimeout
009A .dbline 93
009A ;
009A ; /* 计算块的最大长度 */ /* calculate the size of a sector */
009A ; sds.block_len = 1 << (csdbuf[READ_BL_LEN_POS] & READ_BL_LEN_MSK); /* (2 ^ READ_BL_LEN) */
009A 1D81 ldd R17,y+5
009C 1F70 andi R17,15
009E 01E0 ldi R16,1
00A0 0E940000 xcall lsl8
00A4 00930100 sts _sds+1,R16
00A8 .dbline 96
00A8 ;
00A8 ; /* 计算卡中块的个数 */ /* calculate the sector numbers of the SD Card */
00A8 ; sds.block_num = ((csdbuf[C_SIZE_POS1] & C_SIZE_MSK1) << 10) +
00A8 1AE0 ldi R17,10
00AA 0E81 ldd R16,y+6
00AC 0370 andi R16,3
00AE 0E940000 xcall lsl8
00B2 202E mov R2,R16
00B4 3F80 ldd R3,y+7
00B6 330C lsl R3
00B8 330C lsl R3
00BA 230C add R2,R3
00BC 8885 ldd R24,y+8
00BE 807C andi R24,192
00C0 8695 lsr R24
00C2 8695 lsr R24
00C4 8695 lsr R24
00C6 8695 lsr R24
00C8 8695 lsr R24
00CA 8695 lsr R24
00CC 280E add R2,R24
00CE 822D mov R24,R2
00D0 8F5F subi R24,255 ; addi 1
00D2 80930000 sts _sds,R24
00D6 .dbline 100
00D6 ; (csdbuf[C_SIZE_POS2] << 2) +
00D6 ; ((csdbuf[C_SIZE_POS3] & C_SIZE_MSK3) >> 6) + 1; /* (C_SIZE + 1)*/
00D6 ;
00D6 ; tmp = ((csdbuf[C_SIZE_MULT_POS1] & C_SIZE_MULT_MSK1) << 1) +
00D6 27E0 ldi R18,7
00D8 30E0 ldi R19,0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -