CM_WRCFG.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Write Configuration Zone
  2. //
  3. // CryptoMemory Library Include Files
  4. #include "CM_LIB.h"
  5. #include "CM_I2C.h"
  6. #include "CM_I2C_L.h"
  7. #include "CM_GPA.h"
  8. // Write Configuration Zone
  9. uint8_t cm_WriteConfigZone(uint8_t ucCryptoAddr, uint8_t* pucBuffer, uint8_t ucCount, uint8_t ucAntiTearing)
  10. {
  11. // printf("\n===> cm_WriteConfigZone start\n");
  12. uint8_t ucReturn, ucEncrypt;
  13. ucCM_InsBuff[0] = 0xb4;
  14. if(ucAntiTearing) ucCM_InsBuff[1] = 0x08;
  15. else ucCM_InsBuff[1] = 0x00;
  16. ucCM_InsBuff[2] = ucCryptoAddr;
  17. ucCM_InsBuff[3] = ucCount;
  18. // Three bytes of the command must be included in the polynominals
  19. cm_GPAcmd2(ucCM_InsBuff);
  20. // Only password zone is ever encrypted
  21. ucEncrypt = ((ucCryptoAddr>= CM_PSW) && ucCM_Encrypt);
  22. // Include the data in the polynominals and encrypt if required
  23. cm_GPAencrypt(ucEncrypt, pucBuffer, ucCount);
  24. // Do the write
  25. ucReturn = cm_WriteCommand(ucCM_InsBuff, pucBuffer,ucCount);
  26. // when anti-tearing, the host should send ACK should >= 20ms after write command
  27. if (ucAntiTearing) CM_LOW_LEVEL.WaitClock(100); //10
  28. // printf("===> cm_WriteConfigZone over\n");
  29. return ucReturn;
  30. }