CM_NOPOWER.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // Functions control the logical power on/off for the chip
  2. #include "CM_LIB.h"
  3. #include "CM_I2C.h"
  4. #include "CM_I2C_L.h"
  5. #include <unistd.h>
  6. #include <stdio.h>
  7. #include "linux/fcntl.h"
  8. #include "driver.h"
  9. #include <string.h>
  10. // Power On Chip
  11. //
  12. // Returns 0 (SUCCESS) if no error
  13. //
  14. void cm_PowerOn(void)
  15. {
  16. // printf("---> cm_PowerOn\n");
  17. // Reset chip data
  18. cm_ResetCrypto();
  19. ucCM_UserZone = ucCM_AntiTearing = 0;
  20. int ret;
  21. crypto_t crypto_arg;
  22. crypto_arg.loop = CM_PWRON_CLKS;
  23. int fd = open("/dev/crypto", O_RDWR);
  24. if(fd <= 0)
  25. {
  26. printf("Open /dev/crypto error!\n");
  27. return;
  28. }
  29. ret = ioctl(fd, CRYPTO_POWER_ON, &crypto_arg);
  30. if(ret != 0)
  31. {
  32. printf("cm_PowerOn failed!\n");
  33. close(fd);
  34. return;
  35. }
  36. close(fd);
  37. // // Sequence for powering on secure memory according to ATMEL spec
  38. // CM_DATA_OUT; // SDA and SCL start as outputs
  39. // CM_CLK_OUT;
  40. // CM_CLK_LO; // Clock should start LOW
  41. // CM_DATA_HI; // Data high during reset
  42. // cm_ClockCycles(CM_PWRON_CLKS); // Give chip some clocks cycles to get started
  43. // Chip should now be in sync mode and ready to operate
  44. }
  45. // Shut down secure memory
  46. //
  47. void cm_PowerOff(void)
  48. {
  49. printf("---> cm_PowerOff\n");
  50. // cm_Delay(1);
  51. // CM_CLK_LO;
  52. // cm_Delay(6);
  53. int ret;
  54. crypto_t crypto_arg;
  55. int fd = open("/dev/crypto", O_RDWR);
  56. if(fd <= 0)
  57. {
  58. printf("Open /dev/crypto error!\n");
  59. return;
  60. }
  61. ret = ioctl(fd, CRYPTO_POWER_OFF, &crypto_arg);
  62. if(ret != 0)
  63. {
  64. printf("cm_PowerOff failed!\n");
  65. close(fd);
  66. return;
  67. }
  68. close(fd);
  69. }