📄 disk3.lst
字号:
1126 2 }
1127 1
1128 1 else //(lenbak>0)
1129 1 {
1130 2 if(!ChallengeCustomIdCmd(iCId,lenbak,Nvmoffset))
1131 2 {
1132 3 errcode=WriteCustomIdCmdErr;
1133 3 return false;
1134 3 }
1135 2 MCU_SN++;
1136 2 }
1137 1
1138 1 while(!CommMode)
1139 1 {
1140 2 // Delay_0_5us(10);
1141 2 if(!GetCustomIdResponseCmd())
1142 2 {
1143 3 errcode=GetCustomIdResponseCmdErr;
1144 3 goto ChallengeCustomIdExit;
1145 3 }
1146 2 //Delay_0_5us(10);
1147 2 b_retry=!GetReply(18);
1148 2
1149 2 b_retry=(b_retry||(!IsCustomIdResponseCmd(from)));
1150 2 b_retry=b_retry&&(readcnt<3);
1151 2 if(b_retry)
1152 2 readcnt++;
1153 2 else
1154 2 break;
1155 2 }
1156 1
1157 1 if(CommMode)
1158 1 {
1159 2 GetCustomIdResponseCmd();
1160 2 while(1)
1161 2 {
1162 3 b_retry=!GetReply(18);
1163 3 b_retry=(b_retry||(!IsCustomIdResponseCmd(from)));
1164 3 b_retry=b_retry&&(readcnt<2);
1165 3 if(b_retry)
C51 COMPILER V7.02b DISK3 03/16/2006 13:52:41 PAGE 20
1166 3 readcnt++;
1167 3 else
1168 3 break;
1169 3
1170 3 }
1171 2 }
1172 1
1173 1 if(errcode!=0) //=2 ,3
1174 1 goto ChallengeCustomIdExit;
1175 1 if(IsCustomIdResponseCmd(from))
1176 1 {
1177 2
1178 2 BYTE j;
1179 2 for(j=0;j<lenbak;j++)
1180 2 {
1181 3 if((from[j]|CId[j])!=0xff)
1182 3 return false;
1183 3 }
1184 2 return true;
1185 2 }
1186 1 else
1187 1 errcode=CMDERR;
1188 1 ChallengeCustomIdExit:
1189 1 MCU_SN--;
1190 1 if(MCU_SN==0xff)
1191 1 SN_High--;
1192 1 return false;
1193 1
1194 1 }
1195 /*
1196 **************************************************
1197 * prototype : BOOL WriteKeyOpr(BYTE *Key)
1198 * Des: Write Key flow operation
1199 * "Key" is 2 bytes array addess of Key.
1200 * If Receive state is ready,it return true;
1201 * If Receive state is not ready,it return false and errcode is 0.
1202 *If Receive state is neither above,it return false and errcode is not 0.
1203 * Use GetLastError to determine.
1204 ***************************************************
1205 */
1206 #define WriteKeyCmdErr 0x21
1207 #define GetKeyWriteStatusCmdErr 0x22
1208
1209
1210 BOOL WriteKeyOpr(BYTE *nId,BYTE adr,BYTE * KEY)
1211 {
1212 1 BYTE readcnt=1;
1213 1 BOOL b_retry;
1214 1
1215 1 if(!WriteKeyCmd(nId,adr,KEY))
1216 1 {
1217 2 errcode=WriteKeyCmdErr;
1218 2 return false;
1219 2 }
1220 1
1221 1 Delay4_2ms(28*3);
1222 1
1223 1 while(!CommMode)
1224 1 {
1225 2 // Delay_0_5us(10);
1226 2 if(!GetKeyWriteStatusCmd())
1227 2 {
C51 COMPILER V7.02b DISK3 03/16/2006 13:52:41 PAGE 21
1228 3 errcode=GetKeyWriteStatusCmdErr;
1229 3 return false;
1230 3 }
1231 2 //Delay_0_5us(10);
1232 2 b_retry=!GetReply(10);
1233 2
1234 2 b_retry=(b_retry||(!IsWriteKeyReadyCmd()&&(!IsWriteKeyNotReadyCmd())));
1235 2 b_retry=b_retry&&(readcnt<3);
1236 2 if(b_retry)
1237 2 readcnt++;
1238 2 else
1239 2 break;
1240 2 }
1241 1
1242 1 if(CommMode)
1243 1 {
1244 2 GetKeyWriteStatusCmd();
1245 2 while(1)
1246 2 {
1247 3 b_retry=!GetReply(10);
1248 3 b_retry=(b_retry||(!IsWriteKeyReadyCmd()&&(!IsWriteKeyNotReadyCmd())));
1249 3 b_retry=b_retry&&(readcnt<3);
1250 3 if(b_retry)
1251 3 readcnt++;
1252 3 else
1253 3 break;
1254 3
1255 3 }
1256 2 }
1257 1
1258 1 if(errcode!=0) //=2 ,3
1259 1 return false;
1260 1
1261 1 if(IsWriteKeyReadyCmd())
1262 1 return true;
1263 1 if(IsWriteKeyNotReadyCmd())
1264 1 return false;
1265 1 else
1266 1 {
1267 2 errcode=CMDERR;
1268 2 return false;
1269 2 }
1270 1 }
1271
1272 /*
1273 **************************************************
1274 * prototype : BOOL SendPlainTextOpr(BYTE *text,BYTE len)
1275 * Des: "Send Plain Text" flow operation
1276 * "text" is plain text array addess .
1277 * "len" is the array length.
1278 * If Receive state is ready,it return true;
1279 * If Receive state is not ready,it return false and errcode is 0.
1280 *If Receive state is neither above,it return false and errcode is not 0.
1281 * Use GetLastError to determine.
1282 ***************************************************
1283 */
1284
1285 extern const BYTE CHK_INTERVAL ;
1286
1287 #define SendPlainTextCmdErr 0x21
1288 #define GetReceiveStatusCmdErr 0x22
1289
C51 COMPILER V7.02b DISK3 03/16/2006 13:52:41 PAGE 22
1290 BOOL SendPlainTextOpr(BYTE *text,BYTE len) //send plain text
1291 {
1292 1 BYTE readcnt=1;
1293 1 BOOL b_retry;
1294 1 static BYTE chkcnt=0;
1295 1
1296 1 // Delay_0_5us(10);
1297 1 if(!SendPlainTextCmd(text,len))
1298 1 {
1299 2 errcode=SendPlainTextCmdErr;
1300 2 return false;
1301 2 }
1302 1
1303 1
1304 1 if(++chkcnt<CHK_INTERVAL)
1305 1 return true;
1306 1
1307 1 chkcnt=0;
1308 1
1309 1 //get receive state
1310 1
1311 1 while(!CommMode) //CommMode=0 I2c mode
1312 1 {
1313 2 // Delay_0_5us(100);
1314 2 if(!GetReceiveStatusCmd()) //errcode=2
1315 2 {
1316 3 errcode=GetReceiveStatusCmdErr;
1317 3 goto SendPlainTextExit;
1318 3 }
1319 2
1320 2 // Delay_0_5us(100);
1321 2 b_retry=!GetReply(10);
1322 2
1323 2 b_retry=(b_retry||(!IsReceiveReadyCmd()&&(!IsReceiveNotReadyCmd())));
1324 2 b_retry=b_retry&&(readcnt<3);
1325 2 if(b_retry)
1326 2 readcnt++;
1327 2 else
1328 2 break;
1329 2 }
1330 1
1331 1 if(CommMode) //CommMode=1 SPI mode
1332 1 {
1333 2 //Delay_0_5us(100);
1334 2 GetReceiveStatusCmd();
1335 2 while(1)
1336 2 {
1337 3 //Delay_0_5us(100);
1338 3 b_retry=!GetReply(10);
1339 3
1340 3 b_retry=(b_retry||(!IsReceiveReadyCmd()&&(!IsReceiveNotReadyCmd())));
1341 3 b_retry=b_retry&&(readcnt<3);
1342 3 if(b_retry)
1343 3 readcnt++;
1344 3 else
1345 3 break;
1346 3 }
1347 2 }
1348 1
1349 1 //check
1350 1
1351 1 if(errcode!=0) //errcode=2x or 3
C51 COMPILER V7.02b DISK3 03/16/2006 13:52:41 PAGE 23
1352 1 goto SendPlainTextExit;
1353 1
1354 1 if(IsReceiveReadyCmd()&&MCU_SN==package[1])
1355 1 {
1356 2 return true;
1357 2 }
1358 1
1359 1 else if(IsReceiveNotReadyCmd())
1360 1 {
1361 2 if(MCU_SN>package[1])
1362 2 SN_diff=MCU_SN-1-package[1];
1363 2 // else if(MCU_SN==package[1]) //perhaps won't happen
1364 2 // SN_diff=0;
1365 2 else
1366 2 {
1367 3 SN_diff=256-package[1]+MCU_SN-1;
1368 3 SN_High--;
1369 3 }
1370 2 MCU_SN=package[1];
1371 2 errcode=NotRdy;
1372 2 chkcnt= CHK_INTERVAL-1;
1373 2 return false;
1374 2 }
1375 1 else if(IsReceiveReadyCmd()&&(MCU_SN!=package[1]))
1376 1 {
1377 2 if(MCU_SN>package[1])
1378 2 SN_diff=MCU_SN-package[1]-1;
1379 2 else
1380 2 {
1381 3 SN_diff=256-package[1]+MCU_SN-1;
1382 3 SN_High--;
1383 3 }
1384 2 MCU_SN=package[1]; //use next frame no
1385 2
1386 2 errcode=RDYERR;
1387 2 chkcnt= CHK_INTERVAL-1;
1388 2 return false;
1389 2 }
1390 1 else if(MCU_SN==package[1]&&(!IsReceiveReadyCmd()&&(!IsReceiveNotReadyCmd())))
1391 1 {
1392 2 errcode=SNERR;
1393 2 goto SendPlainTextExit;
1394 2 }
1395 1 else
1396 1 errcode=CMDERR;
1397 1
1398 1 SendPlainTextExit:
1399 1 // MCU_SN-=CHK_INTERVAL;
1400 1 //if(MCU_SN>=0xf6)
1401 1 // SN_High--;
1402 1 //SN_diff=5; //repeat to send again
1403 1 MCU_SN--;
1404 1 if(MCU_SN==0xff)
1405 1 SN_High--;
1406 1 chkcnt= CHK_INTERVAL-1;
1407 1 return false;
1408 1 //return true; // surppose roght
1409 1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -