📄 disk3.lst
字号:
273 1 return false;
274 1 else
275 1 return true;
276 1 }
277
278 /*
279 **************************************************
280 * prototype : static void GetSnCrc(BYTE *dat,BYTE len)
281 * Des: get CRC value of sending package.
282 * "dat" is package's start address,"len" is the length.
283 ***************************************************
284 */
285 static void GetSn(BYTE *dat,BYTE len) //len>8 <72
286 {
287 1 WORD chksum;
288 1 chksum=uCal(dat,len);
289 1 *(dat+len)=(chksum)&0xff;
290 1 *(dat+len+1)=(chksum>>8)&0xff;
291 1
292 1 // chksum1=uCal(dat,len+2); //==800d?
293 1 }
294
295
296 /*
297 **************************************************
298 * prototype : static BOOL GetStatus(BYTE t)
C51 COMPILER V7.02b DISK3 03/16/2006 13:52:41 PAGE 6
299 * Des: Send 10 bytes package on SPI or I2C bus.
300 * "t" is first command value .
301 ***************************************************
302 */
303
304 static BOOL GetStatus(BYTE t) //t =CMD GetState 公用子程序
305 {
306 1 // BYTE package[8+2];
307 1 // memset(package,0,10);
308 1 package[0]=t;
309 1 // package[1]=RN;
310 1
311 1 DoXX(package,package,8,1);
312 1 GetSn(package,8);
313 1
314 1 return(DoComunication(package,10, 1));
315 1
316 1 }
317
318
319 /**********************************************************
320 basic command class function interface
321 **********************************************************/
322 /*
323 **************************************************
324 * prototype : BOOL SendPlainTextCmd(BYTE *text,BYTE len)
325 * Des: "Send Plain Text" command
326 * "text" is plain text array addess .
327 * "len" is the array length.
328 * If comunication succeed,it return true;
329 * If input parametre is error,it return false and errcode is 1.
330 *If comunication is not success,it return false and errcode is 2.
331 * Use GetLastError to determine.
332 ***************************************************
333 */
334 BOOL SendPlainTextCmd(BYTE *text,BYTE len) //send plain text
335 {
336 1 // BYTE package[8+64+2];
337 1
338 1 errcode=0;
339 1 if(text==NULL||len>64||(len%8!=0))
340 1 {
341 2 errcode=PRAMWRONG;
342 2 return false;
343 2 }
344 1
345 1 memset(package,0,8);
346 1 package[0]=0x81;
347 1 package[1]=MCU_SN;
348 1 memcpy(package+8,text,len);
349 1
350 1 DoXX(package, package, 8+len,1);
351 1
352 1 GetSn(package,8+len);
353 1
354 1 if(DoComunication(package, 8+len+2, 1))
355 1 {
356 2 if(++MCU_SN==0x00)
357 2 SN_High++;
358 2
359 2 return true;
360 2 }
C51 COMPILER V7.02b DISK3 03/16/2006 13:52:41 PAGE 7
361 1 else
362 1 return false;
363 1 }
364
365 /*
366 **************************************************
367 * prototype : BOOL SendEncryptedDigestCmd(BYTE *text)
368 * Des: "Send Encrypted Digest" command
369 * "text" is Encrypted Digest array(8 bytes) addess .
370 * If comunication succeed,it return true;
371 * If input parametre is error,it return false and errcode is 1.
372 *If comunication is not success,it return false and errcode is 2.
373 * Use GetLastError to determine.
374 ***************************************************
375 */
376
377 BOOL SendEncryptedDigestCmd(BYTE *text) //send plain MAC digest
378 {
379 1 // BYTE package[8+8+2];
380 1
381 1 errcode=0;
382 1 if(text==NULL)
383 1 {
384 2 errcode=PRAMWRONG;
385 2 return false;
386 2 }
387 1
388 1 memset(package,0,8);
389 1 package[0]=0x82;
390 1 package[1]=MCU_SN;
391 1 package[2]=RN;
392 1 memcpy(package+8,text,8);
393 1
394 1 DoXX(package, package, 8+8,1);
395 1 GetSn(package,8+8);
396 1
397 1 if(DoComunication(package, 8+8+2, 1))
398 1 {
399 2 if(++MCU_SN==0x00)
400 2 SN_High++;
401 2
402 2 return true;
403 2 }
404 1 else
405 1 return false;
406 1 }
407
408 /*
409 **************************************************
410 * prototype : BOOL GetReceiveStatusCmd()
411 * Des: send "Get receive status " command on SPI or I2C bus
412 * If comunication succeed,it return true;
413 *If comunication is not success,it return false and errcode is 2.
414 * Use GetLastError to determine.
415 ***************************************************
416 */
417
418 BOOL GetReceiveStatusCmd(){
419 1 return(GetStatus(0x91));
420 1 }
421
422
C51 COMPILER V7.02b DISK3 03/16/2006 13:52:41 PAGE 8
423 /*
424 **************************************************
425 * prototype : BOOL GetResponseCmd()
426 * Des: send "Get response " command on SPI or I2C bus
427 * If comunication succeed,it return true;
428 *If comunication is not success,it return false and errcode is 2.
429 * Use GetLastError to determine.
430 ***************************************************
431 */
432 BOOL GetResponseCmd(){
433 1 package[1]=0xee;
434 1 package[2]=0xaa;
435 1 package[3]=0x11;
436 1 package[4]=0x22;
437 1 package[5]=0x55;
438 1 package[6]=0x77;
439 1 package[7]=0x99;
440 1
441 1 return(GetStatus(0x92));
442 1
443 1 }
444
445
446 /*
447 **************************************************
448 * prototype : BOOL GetKeyWriteStatusCmd()
449 * Des: send "Get the key write status "command on SPI or I2C bus
450 * If comunication succeed,it return true;
451 *If comunication is not success,it return false and errcode is 2.
452 * Use GetLastError to determine.
453 ***************************************************
454 */
455 BOOL GetKeyWriteStatusCmd(){
456 1 return(GetStatus(0x93));
457 1 }
458
459 /*
460 **************************************************
461 * prototype : BOOL GetPowerDownReceiveStatusCmd()
462 * Des: send "Get Powner down command receive status "
463 * command on SPI or I2C bus
464 * If comunication succeed,it return true;
465 *If comunication is not success,it return false and errcode is 2.
466 * Use GetLastError to determine.
467 ***************************************************
468 */
469 BOOL GetPowerDownReceiveStatusCmd(){
470 1 return(GetStatus(0x94));
471 1 }
472
473 /*
474 **************************************************
475 * prototype : BOOL GetResetReceiveStatusCmd()
476 * Des: send "Get reset command receive status " command
477 * on SPI or I2C bus
478 * If comunication succeed,it return true;
479 *If comunication is not success,it return false and errcode is 2.
480 * Use GetLastError to determine.
481 ***************************************************
482 */
483 BOOL GetResetReceiveStatusCmd(){
484 1 return(GetStatus(0x95));
C51 COMPILER V7.02b DISK3 03/16/2006 13:52:41 PAGE 9
485 1 }
486
487
488 /*
489 **************************************************
490 * prototype : BOOL GetChipIdCmd()
491 * Des: send "Get chip ID" command on SPI or I2C bus
492 * If comunication succeed,it return true;
493 *If comunication is not success,it return false and errcode is 2.
494 * Use GetLastError to determine.
495 ***************************************************
496 */
497 BOOL GetChipIdCmd(){
498 1 package[1]=0x71;
499 1 package[2]=0x72;
500 1 package[3]=0x73;
501 1 package[4]=0x74;
502 1 package[5]=0x75;
503 1 package[6]=0x76;
504 1 package[7]=0x77;
505 1
506 1 return(GetStatus(0x96));
507 1 }
508
509
510 /*
511 **************************************************
512 * prototype : BOOL GetCustomIdWriteStatusCmd()
513 * Des: send "Get CustomId Write Status" command on SPI or I2C bus
514 * If comunication succeed,it return true;
515 *If comunication is not success,it return false and errcode is 2.
516 * Use GetLastError to determine.
517 ***************************************************
518 */
519 BOOL GetCustomIdWriteStatusCmd() //add
520 {
521 1 return(GetStatus(0x97));
522 1 }
523
524 /*
525 **************************************************
526 * prototype : BOOL GetCustomIdResponseCmd()
527 * Des: send "Get CustomId Response" command on SPI or I2C bus
528 * If comunication succeed,it return true;
529 *If comunication is not success,it return false and errcode is 2.
530 * Use GetLastError to determine.
531 ***************************************************
532 */
533 BOOL GetCustomIdResponseCmd() //add
534 {
535 1 return(GetStatus(0x98));
536 1 }
537 /*
538 **************************************************
539 * prototype : BOOL GetReply()
540 * Des: read data from SPI or I2c bus to interal package
541 * "len" is the length of data bytes
542
543 * If comunication and CRC check succeed,it return true;
544 * If input parametre is error,it return false and errcode is 1.
545 *If comunication is not success,it return false and errcode is 2.
546 *If CRC check is error,it return false and errcode is 3.
C51 COMPILER V7.02b DISK3 03/16/2006 13:52:41 PAGE 10
547 * Use GetLastError to determine.
548 ***************************************************
549 */
550 BOOL GetReply(BYTE len)
551 {
552 1 errcode=0;
553 1 if(len>8+8+2||len<8+2) //check parametre
554 1 {
555 2 errcode=PRAMWRONG;
556 2 return false;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -