📄 m500auc.lst
字号:
925 1 char status = MI_OK;
926 1 Pt = &MSndBuffer;
927 1 // ************* Cmd Sequence **********************************
928 1 ResetInfo(MInfo);
929 1 //宏定义的部分
930 1 // #define ResetInfo(info) \
*** WARNING C329 IN LINE 930 OF M500AuC.c: single-line comment contains line-continuation
931 1 // info.cmd = 0; \
932 1 // info.status = MI_OK;\
933 1 // info.irqSource = 0; \
934 1 // info.nBytesSent = 0; \
935 1 // info.nBytesToSend = 0; \
936 1 // info.nBytesReceived = 0; \
937 1 // info.nBitsReceived = 0; \
938 1 // info.collPos = 0;
*** WARNING C329 IN LINE 931 OF M500AuC.c: single-line comment contains line-continuation
*** WARNING C329 IN LINE 932 OF M500AuC.c: single-line comment contains line-continuation
*** WARNING C329 IN LINE 933 OF M500AuC.c: single-line comment contains line-continuation
*** WARNING C329 IN LINE 934 OF M500AuC.c: single-line comment contains line-continuation
*** WARNING C329 IN LINE 935 OF M500AuC.c: single-line comment contains line-continuation
*** WARNING C329 IN LINE 936 OF M500AuC.c: single-line comment contains line-continuation
*** WARNING C329 IN LINE 937 OF M500AuC.c: single-line comment contains line-continuation
939 1
940 1
941 1
942 1 MSndBuffer[0] = startaddr & 0xFF; //低字节
943 1 MSndBuffer[1] = (startaddr >> 8) & 0xFF; //高字节
944 1 MSndBuffer[2] = length; //数据长度
945 1 MInfo.nBytesToSend = 3;
946 1
947 1 status = M500PcdCmd(PCD_READE2,
948 1 MSndBuffer,
949 1 MRcvBuffer,
950 1 &MInfo);
951 1 if (status == MI_OK)
952 1 {
953 2
954 2 memcpy(_data,MRcvBuffer,length);
955 2
956 2 }
957 1 else // Response Processing
958 1 {
959 2 _data[0] = 0;
960 2 }
961 1 return status ;
962 1 }
963
964 ///////////////////////////////////////////////////////////////////////
965 // E E P R O M W R I T E
966 ///////////////////////////////////////////////////////////////////////
967 char PcdWriteE2(unsigned short startaddr,
968 unsigned char length,
969 unsigned char* _data)
970 {
971 1 char status = MI_OK;
972 1
973 1 // ************* Cmd Sequence **********************************
974 1 ResetInfo(MInfo);
975 1 MSndBuffer[0] = startaddr & 0xFF;
976 1 MSndBuffer[1] = (startaddr >> 8) & 0xFF;
C51 COMPILER V7.06 M500AUC 03/21/2005 16:36:23 PAGE 17
977 1 memcpy(MSndBuffer + 2,_data,length);
978 1
979 1 MInfo.nBytesToSend = length + 2;
980 1
981 1 status = M500PcdCmd(PCD_WRITEE2,
982 1 MSndBuffer,
983 1 MRcvBuffer,
984 1 &MInfo); // write e2
985 1 return status;
986 1 }
987
988 ///////////////////////////////////////////////////////////////////////
989 // C O N F I G M F O U T S E L E C T
990 ///////////////////////////////////////////////////////////////////////
991 char M500PcdMfOutSelect(unsigned char type)
992 {
993 1 WriteIO(RegMfOutSelect,type&0x7);
994 1 return MI_OK;
995 1 }
996
997 ///////////////////////////////////////////////////////////////////////
998 // W R I T E R E G I S T E R
999 ///////////////////////////////////////////////////////////////////////
1000 char M500PcdWriteRegister(unsigned char Reg, unsigned char value)
1001 {
1002 1 WriteIO(Reg,value);
1003 1 return MI_OK;
1004 1 }
1005
1006 ///////////////////////////////////////////////////////////////////////
1007 // R E A D R E G I S T E R
1008 ///////////////////////////////////////////////////////////////////////
1009 char M500PcdReadRegister(unsigned char Reg)
1010 {
1011 1 char value;
1012 1
1013 1 value = ReadIO(Reg);
1014 1 return (value);
1015 1 }
1016
1017 ///////////////////////////////////////////////////////////////////////
1018 // M I F A R E R E Q U E S T
1019 ///////////////////////////////////////////////////////////////////////
1020 char M500PiccRequest(unsigned char req_code, // request code ALL = 0x52
1021 // or IDLE = 0x26
1022 unsigned char *atq) // answer to request
1023 {
1024 1 return M500PiccCommonRequest(req_code,atq);
1025 1 }
1026
1027 ///////////////////////////////////////////////////////////////////////
1028 // M I F A R E C O M M O N R E Q U E S T
1029 ///////////////////////////////////////////////////////////////////////
1030 char M500PiccCommonRequest(unsigned char req_code,
1031 unsigned char *atq)
1032 {
1033 1 char data status = MI_OK;
1034 1
1035 1 //************* initialize ******************************
1036 1 WriteIO(RegChannelRedundancy,0x03); // RxCRC and TxCRC disable, parity enable
1037 1 Temp = ReadIO(RegChannelRedundancy);
1038 1
C51 COMPILER V7.06 M500AUC 03/21/2005 16:36:23 PAGE 18
1039 1 ClearBitMask(RegControl,0x08); // disable crypto 1 unit
1040 1 WriteIO(RegBitFraming,0x07); // set TxLastBits to 7
1041 1 SetBitMask(RegTxControl,0x03); // Tx2RF-En, Tx1RF-En enable
1042 1
1043 1 ResetInfo(MInfo);
1044 1 MSndBuffer[0] = req_code;
1045 1 MInfo.nBytesToSend = 1;
1046 1 status = M500PcdCmd(PCD_TRANSCEIVE, //PCD_TRANSCEIVE:收发数据命令
1047 1 MSndBuffer,
1048 1 MRcvBuffer,
1049 1 &MInfo);
1050 1
1051 1 if (status) // error occured
1052 1 {
1053 2 *atq = 0;
1054 2 }
1055 1 else
1056 1 {
1057 2 if (MInfo.nBitsReceived != 16) // 2 bytes expected
1058 2 {
1059 3 *atq = 0;
1060 3 status = MI_BITCOUNTERR;
1061 3 }
1062 2 else
1063 2 {
1064 3 status = MI_OK;
1065 3 Pt = MRcvBuffer;
1066 3 memcpy(atq,MRcvBuffer,2);
1067 3 }
1068 2 }
1069 1 return status;
1070 1 }
1071
1072 ///////////////////////////////////////////////////////////////////////
1073 // M I F A R E A N T I C O L L I S I O N
1074 // for standard select
1075 ///////////////////////////////////////////////////////////////////////
1076 char M500PiccAnticoll (unsigned char bcnt,
1077 unsigned char *snr)
1078 {
1079 1 return M500PiccCascAnticoll(0x93,bcnt,snr); // first cascade level
1080 1 }
1081
1082 ///////////////////////////////////////////////////////////////////////
1083 // M I F A R E A N T I C O L L I S I O N
1084 // for extended serial numbers
1085 ///////////////////////////////////////////////////////////////////////
1086 char M500PiccCascAnticoll (unsigned char select_code,
1087 unsigned char bcnt,
1088 unsigned char *snr)
1089 {
1090 1 char data status = MI_OK;
1091 1 char data snr_in[4]; // copy of the input parameter snr
1092 1 char data nbytes = 0;
1093 1 char data nbits = 0;
1094 1 char data complete = 0;
1095 1 char data i = 0;
1096 1 char data byteOffset = 0;
1097 1 unsigned char data snr_crc;
1098 1 unsigned char data snr_check;
1099 1 unsigned char dummyShift1; // dummy byte for snr shift
1100 1 unsigned char dummyShift2; // dummy byte for snr shift
C51 COMPILER V7.06 M500AUC 03/21/2005 16:36:23 PAGE 19
1101 1
1102 1 //************* Initialisation ******************************
1103 1 M500PcdSetTmo(106);
1104 1 memcpy(snr_in,snr,4);
1105 1
1106 1 WriteIO(RegDecoderControl,0x28); // ZeroAfterColl aktivieren
1107 1 Temp = ReadIO(RegDecoderControl);
1108 1 ClearBitMask(RegControl,0x08); // disable crypto 1 unit
1109 1
1110 1 //************** Anticollision Loop ***************************
1111 1 complete = 0;
1112 1 // bcnt = 0; // no part of the snr is known
1113 1 while (!complete && (status == MI_OK) )
1114 1 {
1115 2 ResetInfo(MInfo);
1116 2 WriteIO(RegChannelRedundancy,0x03); // RxCRC and TxCRC disable, parity enable
1117 2 nbits = bcnt % 8; // remaining number of bits
1118 2 if (nbits)
1119 2 {
1120 3 WriteIO(RegBitFraming,nbits << 4 | nbits); // TxLastBits/RxAlign auf nb_bi
1121 3 nbytes = bcnt / 8 + 1;
1122 3 // number of bytes known
1123 3
1124 3 // in order to solve an inconsistancy in the anticollision sequence
1125 3 // (will be solved soon), the case of 7 bits has to be treated in a
1126 3 // separate way - please note the errata sheet
1127 3 if (nbits == 7)
1128 3 {
1129 4 MInfo.cmd = PICC_ANTICOLL1; // pass command flag to ISR
1130 4 WriteIO(RegBitFraming,nbits); // reset RxAlign to zero
1131 4 }
1132 3 }
1133 2 else
1134 2 {
1135 3 nbytes = bcnt / 8;
1136 3 }
1137 2
1138 2 MSndBuffer[0] = select_code;
1139 2 MSndBuffer[1] = 0x20 + ((bcnt/8) << 4) + nbits; //number of bytes send
1140 2
1141 2 for (i = 0; i < nbytes; i++) // Sende Buffer beschreiben
1142 2 {
1143 3 MSndBuffer[i + 2] = snr_in[i];
1144 3 }
1145 2 MInfo.nBytesToSend = 2 + nbytes;
1146 2
1147 2
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -