📄 udisk.s
字号:
; else
; {
; CopyBytes(nComBuff.AckData.VeryData.ReadDataVer.DataBuff,FILE_DATA_BUF,512);
; nComBuff.AckData.VeryData.ReadDataVer.ReadBytes = mCmdParam.ReadX.mSectorCount;
; RETURN_SUCCESS;
; nComBuff.ReqData.FrameLen = (nComBuff.AckData.VeryData.ReadDataVer.ReadBytes<<9) + 5;
; }
; }
; else
; {
; ReturnErrorCode(A_BYTEMODE);
; }
; }
;
; /************************************************************************/
; /* 模块的扇区写入函数
; 在 */
; /************************************************************************/
; void ModuleSectorWrite(void)
; {
; if(CH375DiskStatus == DISK_OPEN_FILE)
; {
; mCmdParam.Write.mSectorCount = nComBuff.ReqData.VeryData.WriteDataVer.Bytes; /*把要写入的扇区数确定*/
; CopyBytes(FILE_DATA_BUF,nComBuff.ReqData.VeryData.WriteDataVer.DataBuff,512);
; LIGHT_WR;
; OperReturn = CH375FileWrite( );
; OFF_WR;
; if(OperReturn)
; {
; ReturnErrorCode(OperReturn);
; }
; else
; {
; nComBuff.AckData.VeryData.RealWriteByte = mCmdParam.Write.mSectorCount;
; RETURN_SUCCESS;
; nComBuff.AckData.FrameLen = 5;
; }
; }
; else
; {
; ReturnErrorCode(A_BYTEMODE);
; }
;
;
; }
; /************************************************************************/
; /* 模块编辑文件属性函数
; 修改文件的属性,日期,长度,时间,
; */
; /************************************************************************/
;
; /************************************************************************/
; /* 模块文件的偏移
; 入口:ModeLocate ,0--字节模式,!0--扇区模式
; */
; /************************************************************************/
; void ModuleSetOffset(uchar ModeLocate)
; {
; if(ModeLocate == LOCATE_SECTOR_MODE)
; {
; mCmdParam.Locate.mSectorOffset = nComBuff.ReqData.VeryData.SetOffset;
; OperReturn = CH375FileLocate();
; if(OperReturn)
; ReturnErrorCode(OperReturn);
; else
; {
; RETURN_SUCCESS;
; nComBuff.AckData.VeryData.RealOffset = mCmdParam.Locate.mSectorOffset;
; nComBuff.AckData.FrameLen = 7;
; }
; }
; else
; {
; mCmdParam.ByteLocate.mByteOffset = nComBuff.ReqData.VeryData.SetOffset;
; OperReturn = CH375ByteLocate( );
; if(OperReturn)
; ReturnErrorCode(OperReturn);
; else
; {
; RETURN_SUCCESS;
; nComBuff.AckData.VeryData.RealOffset = mCmdParam.ByteLocate.mByteOffset;
; nComBuff.AckData.FrameLen = 7;
; }
; }
; }
; /************************************************************************/
; /* 如果是有文件打开的状态,帧处理函数 */
; /************************************************************************/
; void StatusOpen(void)
; {
; uint rdcount;
; switch(nComBuff.ReqData.Com)
.dbline 674
; {
ldi R24,<_FILE_DATA_BUF
ldi R25,>_FILE_DATA_BUF
sts _mCmdParam+8+1,R25
sts _mCmdParam+8,R24
.dbline 675
; case R_RD_FILE_DATA:
xcall _CH375FileReadX
.dbline -2
L33:
.dbline 0 ; func end
ret
.dbend
.dbfunc e CH375FileWrite _CH375FileWrite fc
.even
_CH375FileWrite::
.dbline -1
.dbline 679
; ModuleByteRead();
; break;
; case R_RD_FILE_ATTR:
; ModuleAttrRead();
.dbline 680
; break;
ldi R24,<_FILE_DATA_BUF
ldi R25,>_FILE_DATA_BUF
sts _mCmdParam+8+1,R25
sts _mCmdParam+8,R24
.dbline 681
; case R_WR_FILE_DATA:
xcall _CH375FileWriteX
.dbline -2
L35:
.dbline 0 ; func end
ret
.dbend
.dbfunc e CH375FileQuery _CH375FileQuery fc
; count -> R20
; buf -> R22,R23
.even
_CH375FileQuery::
xcall push_gset2
.dbline -1
.dbline 700
; ModuleByteWrite();
; break;
; case R_RD_FILE_SECTOR:
; ModuleSectorRead();
; break;
; case R_WR_FILE_SECTOR:
; ModuleSectorWrite();
; break;
; case R_CLOSEFILE:
; mCmdParam.Close.mUpdateLen = 1; //自动更新文件长度
; OperReturn = CH375FileClose( );
; if(OperReturn)
; {
; ReturnErrorCode(OperReturn);
; }
; else
; {
; ReturnErrorCode(A_SUCCESS);
; }
.dbline 703
; B_status = S_READY;
; break;
; case R_SET_OFFSETBYTE:
ldi R22,<_mCmdParam
ldi R23,>_mCmdParam
.dbline 704
ldi R20,9
xjmp L41
L38:
.dbline 704
.dbline 705
ldi R24,255
movw R30,R22
std z+0,R24
.dbline 706
subi R22,255 ; offset = 1
sbci R23,255
.dbline 707
L39:
.dbline 704
dec R20
L41:
.dbline 704
; ModuleSetOffset(LOCATE_BYTE_MODE);
tst R20
brne L38
.dbline 708
; break;
; case R_SET_OFFSETSECTOR:
; ModuleSetOffset(LOCATE_SECTOR_MODE);
; break;
xcall _CH375FileModify
.dbline -2
L37:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r count 20 c
.dbsym r buf 22 pc
.dbend
.dbfunc e xQueryInterrupt _xQueryInterrupt fV
.even
_xQueryInterrupt::
.dbline -1
.dbline 715
;
; case R_MODIFY_ATTR:
; mCmdParam.Modify.mFileAttr = nComBuff.ReqData.VeryData.ModifyFileAttrVer.FileAttr;
; mCmdParam.Modify.mFileDate = nComBuff.ReqData.VeryData.ModifyFileAttrVer.FileDate;
; mCmdParam.Modify.mFileSize = nComBuff.ReqData.VeryData.ModifyFileAttrVer.FileSize;
; mCmdParam.Modify.mFileTime = nComBuff.ReqData.VeryData.ModifyFileAttrVer.FileTime;
; OperReturn = CH375FileModify();
L43:
.dbline 716
L44:
.dbline 716
; if(OperReturn)
sbic 0x10,2
rjmp L43
.dbline 717
; {
ldi R16,34
xcall _xWriteCH375Cmd
.dbline 718
; ReturnErrorCode(OperReturn);
xcall _xReadCH375Data
sts _CH375IntStatus,R16
.dbline 719
; }
lds R24,_CH375IntStatus
cpi R24,22
brne L46
.dbline 719
ldi R24,1
sts _CH375DiskStatus,R24
xjmp L47
L46:
.dbline 720
; else
lds R24,_CH375IntStatus
cpi R24,21
brne L48
.dbline 720
ldi R24,2
sts _CH375DiskStatus,R24
L48:
L47:
.dbline -2
L42:
.dbline 0 ; func end
ret
.dbend
.dbfunc e xFileNameEnumer _xFileNameEnumer fV
.even
_xFileNameEnumer::
.dbline -1
.dbline 764
; {
; RETURN_SUCCESS;
; nComBuff.AckData.VeryData.ModifyFileAttrVer.FileAttr = mCmdParam.Modify.mFileAttr;
; nComBuff.AckData.VeryData.ModifyFileAttrVer.FileDate = mCmdParam.Modify.mFileDate;
; nComBuff.AckData.VeryData.ModifyFileAttrVer.FileSize = mCmdParam.Modify.mFileSize;
; nComBuff.AckData.VeryData.ModifyFileAttrVer.FileTime = mCmdParam.Modify.mFileTime;
; nComBuff.AckData.FrameLen = FILE_ATTRI_BYTES+3;
; }
; B_status = S_OPEN;
; break;
; default:
; ReturnErrorCode(A_OPEN);
; break;
; }
;
; }
;
; /************************************************************************
; /接收到数据帧时的处理函数
; *************************************************************************/
; void RecieveFrameProcess( void )
; {
; if(nComBuff.AckData.Ack == R_RESET)
; return;
; switch( B_status)
; {
; case S_NOTREADY: // 如果是未准备好状态
; nComBuff.AckData.Ack = A_NOTREADY;
; I2C_SEND_READY; //发送已经准备好
; nComBuff.AckData.FrameLen = 3;
; break;
; case S_READY: //如果是准备好但未读写状态
; StatusReady();
; break;
;
; case S_OPEN: //有文件打开的情况下
; StatusOpen();
; break;
;
; default:
; break;
;
; }
;
.dbline -2
L50:
.dbline 0 ; func end
ret
.dbend
.dbfunc e xWriteToExtBuf _xWriteToExtBuf fV
; mLength -> R16
.even
_xWriteToExtBuf::
.dbline -1
.dbline 827
; }
;
; /******************************************************************************
; /全局变量的初始化
; ******************************************************************************/
; void variable(void)
; {
; B_status=S_NOTREADY;
; SlaveSendLength = &nComBuff.ReqData.FrameLen;
; I2cReceiveData = (uchar*) &nComBuff;
; I2cSendData = (uchar*) &nComBuff;
; UartRx = temp;
; nComBuff.AckData.Ack = A_NOTREADY;
; nComBuff.AckData.FrameLen = 3;
; }
; //ICC-AVR application builder : 2007-7-15 10:41:34
; // Target : M32
; // Crystal: 8.0000Mhz
;
; void port_init(void)
; {
; PORTA = 0x00;
; DDRA = 0x00;
; PORTB = 0xFF;
; DDRB = 0x03;
; PORTC = 0xFF;
; DDRC = 0xC0;
; PORTD = 0xFF;
; DDRD = 0xF1;
; }
;
; //Watchdog initialize
; // prescale: 512K
; void watchdog_init(void)
; {
; WDR(); //this prevents a timout on enabling
; WDTCR = 0x0D; //WATCHDOG ENABLED - dont forget to issue WDRs
; }
;
; //TIMER0 initialize - prescale:1024
; // desired value: 20mSec
; // actual value: 19.952mSec (0.2%)
; void timer0_init(void)
; {
; TCCR0 = 0x00; //stop
; TCNT0 = 0x64; //set count
; OCR0 = 0xEA; //set compare
; TCCR0 = 0x05; //start timer
; }
;
; #pragma interrupt_handler timer0_ovf_isr:12
; void timer0_ovf_isr(void)
; {
; TCNT0 = 0x64; //reload counter value
; WDR();
; if(ys20ms)
; ys20ms--;
;
; }
;
; //call this routine to initialize all peripherals
; void init_devices(void)
; {
.dbline 828
; //stop errant interrupts until set up
dec R16
.dbline -2
L51:
.dbline 0 ; func end
ret
.dbsym r mLength 16 c
.dbend
.dbfunc e xReadFromExtBuf _xReadFromExtBuf fV
; mLength -> R16
.even
_xReadFromExtBuf::
.dbline -1
.dbline 832
; CLI(); //disable all interrupts
; port_init();
; watchdog_init();
; timer0_init();
.dbline 833
;
dec R16
.dbline -2
L52:
.dbline 0 ; func end
ret
.dbsym r mLength 16 c
.dbend
.dbfunc e CH375LibInit _CH375LibInit fc
.even
_CH375LibInit::
.dbline -1
.dbline 841
; MCUCR = 0x00;
; GICR = 0x00;
; TIMSK = 0x01; //timer interrupt sources
; SEI(); //re-enable interrupts
; //all peripherals are now initialized
; }
;
;
.dbline 842
;
ldi R24,5
sts _CH375LibConfig,R24
.dbline 843
;
clr R2
sts _DISK_BASE_BUF,R2
.dbline 844
;
xcall _CH375GetVer
cpi R16,48
brsh L54
.dbline 844
ldi R16,255
xjmp L53
L54:
.dbline 845
;
xcall _CH375Init
.dbline -2
L53:
.dbline 0 ; func end
ret
.dbend
.dbfile E:\xm\jxf\u盘读写模块\code\udisk_test0827\udisk.c
.dbfunc e main _main fV
; j -> R20,R21
; i -> R20
.even
_main::
.dbline -1
.dbline 152
.dbline 154
ldi R20,200
ldi R21,0
L57:
.dbline 155
xcall _variable
.dbline 156
ldi R16,100
ldi R17,0
xcall _i2cSetBitrate
.dbline 157
xcall _i2cInit
.dbline 158
ldi R18,1
ldi R16,96
xcall _i2cSetLocalDeviceAddr
.dbline 159
clr R16
xcall _init_USART
.dbline 160
xcall _init_devices
.dbline 162
xcall _xDelay100uS
.dbline 163
xcall _delay_us
.dbline 164
ldi R16,<L58
ldi R17,>L58
xcall _put_s
.dbline 165
clr R20
xjmp L62
L59:
.dbline 166
.dbline 167
in R24,0x12
andi R24,15
out 0x12,R24
.dbline 168
ldi R24,20
sts _ys20ms,R24
L63:
.dbline 169
L64:
.dbline 169
lds R2,_ys20ms
tst R2
brne L63
.dbline 170
in R24,0x12
ori R24,240
out 0x12,R24
.dbline 171
ldi R24,20
sts _ys20ms,R24
L66:
.dbline 172
L67:
.dbline 172
lds R2,_ys20ms
tst R2
brne L66
.dbline 174
L60:
.dbline 165
inc R20
L62:
.dbline 165
cpi R20,3
brlo L59
.dbline 176
xcall _CH375LibInit
sts _OperReturn,R16
.dbline 177
tst R16
breq L72
.dbline 178
.dbline 179
xjmp L57
L71:
.dbline 182
xcall _xQueryInterrupt
L72:
.dbline 182
lds R24,_CH375DiskStatus
cpi R24,2
brne L71
.dbline 184
ldi R16,200
xcall _mDelaymS
.dbline 187
clr R20
xjmp L77
L74:
.dbline 188
.dbline 189
ldi R16,100
xcall _mDelaymS
.dbline 190
xcall _CH375DiskReady
tst R16
brne L78
.dbline 191
.dbline 192
ldi R24,2
sts _B_status,R24
.dbline 193
xjmp L76
L78:
.dbline 196
.dbline 197
ldi R24,1
sts _B_status,R24
.dbline 198
.dbline 199
L75:
.dbline 187
inc R20
L77:
.dbline 187
cpi R20,10
brlo L74
L76:
.dbline 200
ldi R16,<L80
ldi R17,>L80
xcall _put_s
xjmp L82
L81:
.dbline 203
.dbline 205
lds R2,_I2cComStatus
sbrs R2,7
rjmp L84
.dbline 206
.dbline 207
in R24,0x36
andi R24,191
out 0x36,R24
.dbline 208
cbi 0x12,5
.dbline 209
ldi R16,<L86
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -