CM_WRCFG.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  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. uint8_t ucReturn, ucEncrypt;
  12. ucCM_InsBuff[0] = 0xb4;
  13. if(ucAntiTearing) ucCM_InsBuff[1] = 0x08;
  14. else ucCM_InsBuff[1] = 0x00;
  15. ucCM_InsBuff[2] = ucCryptoAddr;
  16. ucCM_InsBuff[3] = ucCount;
  17. // Three bytes of the command must be included in the polynominals
  18. cm_GPAcmd2(ucCM_InsBuff);
  19. // Only password zone is ever encrypted
  20. ucEncrypt = ((ucCryptoAddr>= CM_PSW) && ucCM_Encrypt);
  21. // Include the data in the polynominals and encrypt if required
  22. cm_GPAencrypt(ucEncrypt, pucBuffer, ucCount);
  23. // Do the write
  24. ucReturn = cm_WriteCommand(ucCM_InsBuff, pucBuffer,ucCount);
  25. // when anti-tearing, the host should send ACK should >= 20ms after write command
  26. if (ucAntiTearing) CM_LOW_LEVEL.WaitClock(10);
  27. return ucReturn;
  28. }