📄 mfrc50~1.s
字号:
.module mfrc500uc.c
.area data(ram, con, rel)
_MpIsrInfo::
.blkb 2
.area idata
.word 0
.area data(ram, con, rel)
.dbfile D:\gkdoor\oldboardsoftware\mfrc500uc.c
.dbstruct 0 10 .1
.dbfield 0 cmd c
.dbfield 1 status I
.dbfield 3 nBytesSent c
.dbfield 4 nBytesToSend c
.dbfield 5 nBytesReceived c
.dbfield 6 nBitsReceived s
.dbfield 8 irqSource c
.dbfield 9 collPos c
.dbend
.dbsym e MpIsrInfo _MpIsrInfo pS[.1]
_MpIsrOut::
.blkb 2
.area idata
.word 0
.area data(ram, con, rel)
.dbfile D:\gkdoor\oldboardsoftware\mfrc500uc.c
.dbsym e MpIsrOut _MpIsrOut pc
_MpIsrIn::
.blkb 2
.area idata
.word 0
.area data(ram, con, rel)
.dbfile D:\gkdoor\oldboardsoftware\mfrc500uc.c
.dbsym e MpIsrIn _MpIsrIn pc
_MFIFOLength::
.blkb 1
.area idata
.byte 64
.area data(ram, con, rel)
.dbfile D:\gkdoor\oldboardsoftware\mfrc500uc.c
.dbsym e MFIFOLength _MFIFOLength c
_mc500_time::
.blkb 1
.area idata
.byte 0
.area data(ram, con, rel)
.dbfile D:\gkdoor\oldboardsoftware\mfrc500uc.c
.dbsym e mc500_time _mc500_time c
.area text(rom, con, rel)
.dbfile D:\gkdoor\oldboardsoftware\mfrc500uc.c
.dbfunc e Mf500PcdConfig _Mf500PcdConfig fc
; CmdWaitCnt -> R20,R21
; RstLoopCnt -> R20,R21
; status -> R22,R23
; i -> R20
.even
_Mf500PcdConfig::
xcall push_gset2
.dbline -1
.dbline 30
; #include <string.h>
; #include <stdio.h>
; #include <d:\gkdoor\oldboardsoftware\MfRc500.h>
; #include <d:\gkdoor\oldboardsoftware\main.h>
; #include <iom128v.h>
; unsigned char MLastSelectedSnr[5];
; #define TCLFSDSNDMAX 8 ///< max. frame size send
; #define TCLFSDRECMAX 8 ///< max. frame size rcv
; #define TCLDSMAX 3 ///< max. baudrate divider PICC --> PCD
; #define TCLDRMAX 3 ///< max. baudrate divider PCD --> PICC
; #define TCLDSDFLT 0 ///< default baudrate divider PICC --> PCD
; #define TCLDRDFLT 0 ///< default baudrate divider PCD --> PICC
; unsigned char *MSndBuffer;
; unsigned char *MRcvBuffer;
; MfCmdInfo MInfo;
;
; MfCmdInfo *MpIsrInfo = 0;
; unsigned char *MpIsrOut = 0;
; unsigned char *MpIsrIn = 0;
; unsigned char CountDown;
; unsigned char T2IR;
;
; unsigned char RicRxTxBuffer[256];
; unsigned char MFIFOLength = DEF_FIFO_LENGTH;
; char Mf500PiccAuthState(unsigned char auth_mode,// PICC_AUTHENT1A, PICC_AUTHENT1B
; unsigned char *snr, // 4 byte serial number
; unsigned char sector); // 0 <= sector <= 15
; unsigned char mc500_time=0;
; char Mf500PcdConfig(void)
; {
.dbline 32
; unsigned char i;
; int status = MI_RESETERR;
ldi R22,-25
ldi R23,-1
.dbline 33
; unsigned short RstLoopCnt = 0;
clr R20
clr R21
.dbline 34
; unsigned short CmdWaitCnt = 0;
.dbline 35
; MSndBuffer = RicRxTxBuffer; // initialise send buffer
ldi R24,<_RicRxTxBuffer
ldi R25,>_RicRxTxBuffer
sts _MSndBuffer+1,R25
sts _MSndBuffer,R24
.dbline 36
; MRcvBuffer = RicRxTxBuffer; // initialise receive buffer
sts _MRcvBuffer+1,R25
sts _MRcvBuffer,R24
.dbline 37
; status = PcdReset();
xcall _PcdReset
mov R22,R16
clr R23
.dbline 38
; if (status == MI_OK)
cpi R22,0
cpc R22,R23
brne L3
X0:
.dbline 39
; {
.dbline 40
; WriteRC(RegClockQControl,0x0);
clr R18
ldi R16,31
xcall _WriteRC
.dbline 41
clr R20
xjmp L8
L5:
.dbline 41
L6:
.dbline 41
inc R20
L8:
.dbline 41
; for(i=0;i<105;i++);
cpi R20,105
brlo L5
.dbline 42
; ClearBitMask(RegClockQControl,0x40); // clear bit ClkQCalib for
ldi R18,64
ldi R16,31
xcall _ClearBitMask
.dbline 43
; WriteRC(RegBitPhase,0xAD);
ldi R18,173
ldi R16,27
xcall _WriteRC
.dbline 44
; WriteRC(RegRxThreshold,0xFF);
ldi R18,255
ldi R16,28
xcall _WriteRC
.dbline 45
; WriteRC(RegRxControl2,00);
clr R18
ldi R16,30
xcall _WriteRC
.dbline 46
; WriteRC(RegFIFOLevel,0x1A); // initialize to 26d
ldi R18,26
ldi R16,41
xcall _WriteRC
.dbline 47
; WriteRC(RegTimerControl,0x02); // TStopRxEnd=0,TStopRxBeg=0,
ldi R18,2
ldi R16,43
xcall _WriteRC
.dbline 48
; WriteRC(RegIRqPinConfig,0x3); // interrupt active low enable
ldi R18,3
ldi R16,45
xcall _WriteRC
.dbline 49
; PcdRfReset(1); // Rf - reset and enable output driver
ldi R16,1
ldi R17,0
xcall _PcdRfReset
.dbline 50
; }
L3:
.dbline 51
; return status;
mov R16,R22
.dbline -2
L2:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r CmdWaitCnt 20 s
.dbsym r RstLoopCnt 20 s
.dbsym r status 22 I
.dbsym r i 20 c
.dbend
.dbfunc e Mf500PiccRequest _Mf500PiccRequest fc
; atq -> R22,R23
; req_code -> R20
.even
_Mf500PiccRequest::
xcall push_gset2
movw R22,R18
mov R20,R16
.dbline -1
.dbline 57
; }
;
; char Mf500PiccRequest(unsigned char req_code, // request code ALL = 0x52
; // or IDLE = 0x26
; unsigned char *atq) // answer to request
; {
.dbline 58
; return Mf500PiccCommonRequest(req_code,atq);
movw R18,R22
mov R16,R20
xcall _Mf500PiccCommonRequest
.dbline -2
L9:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r atq 22 pc
.dbsym r req_code 20 c
.dbend
.dbfunc e Mf500PiccCommonRequest _Mf500PiccCommonRequest fc
; status -> R20,R21
; atq -> R22,R23
; req_code -> R10
.even
_Mf500PiccCommonRequest::
xcall push_gset3
movw R22,R18
mov R10,R16
sbiw R28,4
.dbline -1
.dbline 61
; }
; char Mf500PiccCommonRequest(unsigned char req_code,unsigned char *atq)
; {
.dbline 62
; int status = MI_OK;
clr R20
clr R21
.dbline 64
; //************* initialize ******************************
; PcdSetTmo(106);
ldi R16,106
ldi R17,0
xcall _PcdSetTmo
.dbline 65
; WriteRC(RegChannelRedundancy,0x03); // RxCRC and TxCRC disable, parity enable
ldi R18,3
ldi R16,34
xcall _WriteRC
.dbline 66
; ClearBitMask(RegControl,0x08); // disable crypto 1 unit
ldi R18,8
ldi R16,9
xcall _ClearBitMask
.dbline 67
; WriteRC(RegBitFraming,0x07); // set TxLastBits to 7
ldi R18,7
ldi R16,15
xcall _WriteRC
.dbline 68
; ResetInfo(MInfo);
clr R2
sts _MInfo,R2
.dbline 68
clr R3
sts _MInfo+1+1,R3
sts _MInfo+1,R2
.dbline 68
sts _MInfo+3,R2
.dbline 68
sts _MInfo+4,R2
.dbline 68
sts _MInfo+5,R2
.dbline 68
sts _MInfo+6+1,R3
sts _MInfo+6,R2
.dbline 68
sts _MInfo+8,R2
.dbline 68
sts _MInfo+9,R2
.dbline 68
.dbline 69
; MSndBuffer[0] = req_code;
lds R30,_MSndBuffer
lds R31,_MSndBuffer+1
std z+0,R10
.dbline 70
; MInfo.nBytesToSend = 1;
ldi R24,1
sts _MInfo+4,R24
.dbline 71
; status = PcdSingleResponseCmd(0x1e,MSndBuffer,MRcvBuffer,&MInfo);
ldi R24,<_MInfo
ldi R25,>_MInfo
std y+3,R25
std y+2,R24
lds R2,_MRcvBuffer
lds R3,_MRcvBuffer+1
std y+1,R3
std y+0,R2
movw R18,R30
ldi R16,30
xcall _PcdSingleResponseCmd
mov R20,R16
clr R21
.dbline 72
; if (status) // error occured
cpi R20,0
cpc R20,R21
breq L19
X1:
.dbline 73
; {
.dbline 74
; *atq = 0;
clr R2
movw R30,R22
std z+0,R2
.dbline 75
; }
xjmp L20
L19:
.dbline 77
; else
; {
.dbline 78
; if (MInfo.nBitsReceived != 16) // 2 bytes expected
lds R24,_MInfo+6
lds R25,_MInfo+6+1
cpi R24,16
ldi R30,0
cpc R25,R30
breq L21
.dbline 79
; {
.dbline 80
; status = MI_BITCOUNTERR;
ldi R20,-11
ldi R21,-1
.dbline 81
; }
xjmp L22
L21:
.dbline 83
; else
; {
.dbline 84
; status = MI_OK;
clr R20
clr R21
.dbline 85
; memcpy(atq,MRcvBuffer,2);
ldi R24,2
ldi R25,0
std y+1,R25
std y+0,R24
lds R18,_MRcvBuffer
lds R19,_MRcvBuffer+1
movw R16,R22
xcall _memcpy
.dbline 86
; }
L22:
.dbline 87
; }
L20:
.dbline 88
; return status;
mov R16,R20
.dbline -2
L10:
adiw R28,4
xcall pop_gset3
.dbline 0 ; func end
ret
.dbsym r status 20 I
.dbsym r atq 22 pc
.dbsym r req_code 10 c
.dbend
.dbfunc e Mf500PiccAnticoll _Mf500PiccAnticoll fc
; snr -> R22,R23
; bcnt -> R20
.even
_Mf500PiccAnticoll::
xcall push_gset2
movw R22,R18
mov R20,R16
sbiw R28,2
.dbline -1
.dbline 96
; }
; ///////////////////////////////////////////////////////////////////////
; // M I F A R E A N T I C O L L I S I O N
; // for standard select
; ///////////////////////////////////////////////////////////////////////
; char Mf500PiccAnticoll (unsigned char bcnt,
; unsigned char *snr)
; {
.dbline 97
; return Mf500PiccCascAnticoll(0x93,bcnt,snr); // first cascade level
std y+1,R23
std y+0,R22
mov R18,R20
ldi R16,147
xcall _Mf500PiccCascAnticoll
.dbline -2
L24:
adiw R28,2
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r snr 22 pc
.dbsym r bcnt 20 c
.dbend
.dbfunc e Mf500PiccCascAnticoll _Mf500PiccCascAnticoll fc
; snr_check -> R14
; snr_crc -> R20
; complete -> R10
; byteOffset -> R22
; status -> y+10
; nbits -> y+9
; dummyShift2 -> R14
; dummyShift1 -> R20
; snr_in -> y+4
; nbytes -> y+8
; i -> R12
; snr -> y+26
; bcnt -> y+24
; select_code -> y+22
.even
_Mf500PiccCascAnticoll::
xcall push_arg4
xcall push_gset5
sbiw R28,12
.dbline -1
.dbline 100
; }
; char Mf500PiccCascAnticoll(unsigned char select_code,unsigned char bcnt,unsigned char *snr)
; {
.dbline 101
; int status = MI_OK;
clr R0
clr R1
std y+11,R1
std y+10,R0
.dbline 103
; char snr_in[4]; // copy of the input parameter snr
; char nbytes = 0; // how many bytes received
std y+8,R0
.dbline 104
; char nbits = 0; // how many bits received
std y+9,R0
.dbline 105
; char complete = 0; // complete snr recived
clr R10
.dbline 106
; char i = 0;
clr R12
.dbline 107
; char byteOffset = 0;
clr R22
.dbline 113
; unsigned char snr_crc; // check byte calculation
; unsigned char snr_check;
; unsigned char dummyShift1; // dummy byte for snr shift
; unsigned char dummyShift2; // dummy byte for snr shift
; //************* Initialisierung ******************************
; if ((status = Mf500PcdSetDefaultAttrib()) == MI_OK)
xcall _Mf500PcdSetDefaultAttrib
mov R2,R16
clr R3
std y+11,R3
std y+10,R2
tst R16
breq X5
xjmp L26
X5:
.dbline 114
; {
.dbline 115
; PcdSetTmo(106);
ldi R16,106
ldi R17,0
xcall _PcdSetTmo
.dbline 116
; memcpy(snr_in,snr,4);
ldi R24,4
ldi R25,0
std y+1,R25
std y+0,R24
ldd R18,y+26
ldd R19,y+27
movw R16,R28
subi R16,252 ; offset = 4
sbci R17,255
xcall _memcpy
.dbline 117
; WriteRC(RegDecoderControl,0x28); // ZeroAfterColl aktivieren
ldi R18,40
ldi R16,26
xcall _WriteRC
.dbline 118
; ClearBitMask(RegControl,0x08); // disable crypto 1 unit
ldi R18,8
ldi R16,9
xcall _ClearBitMask
.dbline 120
; //************** Anticollision Loop ***************************
; complete=0;
xjmp L29
L28:
.dbline 122
; while (!complete && (status == MI_OK) )
; {
.dbline 123
; ResetInfo(MInfo);
clr R2
sts _MInfo,R2
.dbline 123
clr R3
sts _MInfo+1+1,R3
sts _MInfo+1,R2
.dbline 123
sts _MInfo+3,R2
.dbline 123
sts _MInfo+4,R2
.dbline 123
sts _MInfo+5,R2
.dbline 123
sts _MInfo+6+1,R3
sts _MInfo+6,R2
.dbline 123
sts _MInfo+8,R2
.dbline 123
sts _MInfo+9,R2
.dbline 123
.dbline 124
; WriteRC(RegChannelRedundancy,0x03); // RxCRC and TxCRC disable, parity enable
ldi R18,3
ldi R16,34
xcall _WriteRC
.dbline 125
; nbits = bcnt % 8; // remaining number of bits
ldi R17,8
ldd R16,y+24
xcall mod8u
std y+9,R16
.dbline 126
; if (nbits)
mov R0,R16
tst R16
breq L38
.dbline 127
; {
.dbline 128
; WriteRC(RegBitFraming,nbits << 4 | nbits); // TxLastBits/RxAlign auf nb_bi
mov R18,R0
andi R18,#0x0F
swap R18
or R18,R16
ldi R16,15
xcall _WriteRC
.dbline 129
; nbytes = bcnt / 8 + 1;
ldd R24,y+24
lsr R24
lsr R24
lsr R24
subi R24,255 ; addi 1
std y+8,R24
.dbline 130
; if (nbits == 7 )
ldd R24,y+9
cpi R24,7
brne L39
.dbline 131
; {
.dbline 132
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -