CM_I2C.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. // CryptoMemory I2C Header File
  2. //
  3. // This library is used in all of the low level hardware interface for I2C communications.
  4. //
  5. // Revision Date Changes
  6. // -------- --------- -----------------------------------------------------------------
  7. // 0.1 26 Oct 04 First Release
  8. // Protect Library against multiple inclusion
  9. #ifndef CM_I2C_H
  10. #define CM_I2C_H
  11. //#include "hal_interface_api.h"
  12. //#include "com_gpio.h"
  13. // -------------------------------------------------------------------------------------------------
  14. // Other includes required by this header file
  15. // -------------------------------------------------------------------------------------------------
  16. #include "CM_LIB.h"
  17. // //Ô¬¿­À¬»ø³ÌÐò
  18. // #define CM_DETECT_PI (*(volatile unsigned char *)(CM_PORT_CFG.ucCardSensePort+IO_PORT_IN))
  19. // #define CM_DETECT_PD (*(volatile unsigned char *)(CM_PORT_CFG.ucCardSensePort+IO_PORT_DIR))
  20. // #define CM_DETECT_PIN (CM_PORT_CFG.ucCardSensePin)
  21. // #define CM_DETECT_POL (CM_PORT_CFG.ucCardSensePolarity)
  22. // #define CM_DETECT_IN CM_DETECT_PD&=~(1<<CM_DETECT_PIN)
  23. // #define CM_DETECT_RD CM_DETECT_PI&(1<<CM_DETECT_PIN)
  24. // #define CM_POWER_PD (*(volatile unsigned char *)(CM_PORT_CFG.ucPowerPort+IO_PORT_DIR))
  25. // #define CM_POWER_PO (*(volatile unsigned char *)(CM_PORT_CFG.ucPowerPort+IO_PORT_OUT))
  26. // #define CM_POWER_PIN (CM_PORT_CFG.ucPowerPin)
  27. // #define CM_POWER_POL (CM_PORT_CFG.ucPowerPolarity)
  28. // #define CM_POWER_OUT CM_POWER_PD|=(1<<CM_POWER_PIN)
  29. // #define CM_POWER_HI CM_POWER_PO|=(1<<CM_POWER_PIN)
  30. // #define CM_POWER_LO CM_POWER_PO&=~(1<<CM_POWER_PIN)
  31. // #define CM_DATA_BIT ((CM_DATA_PI>>CM_DATA_PIN)&1)
  32. // #define CM_CLK_PD (*(volatile unsigned char *)(CM_PORT_CFG.ucClockPort+IO_PORT_DIR))
  33. // #define CM_CLK_PO (*(volatile unsigned char *)(CM_PORT_CFG.ucClockPort+IO_PORT_OUT))
  34. // #define CM_CLK_PIN (CM_PORT_CFG.ucClockPin)
  35. // #define CM_DATA_PI (*(volatile unsigned char *)(CM_PORT_CFG.ucDataPort+IO_PORT_IN))
  36. // #define CM_DATA_PD (*(volatile unsigned char *)(CM_PORT_CFG.ucDataPort+IO_PORT_DIR))
  37. // #define CM_DATA_PO (*(volatile unsigned char *)(CM_PORT_CFG.ucDataPort+IO_PORT_OUT))
  38. // #define CM_DATA_PIN (CM_PORT_CFG.ucDataPin)
  39. // #define rPIOA_OER (*(volatile unsigned *)0x40020000 + 0x14)
  40. // #define rPIOA_ODR (*(volatile unsigned *)0x40020000 + 0x10)
  41. // #define rPIOA_SODR (*(volatile unsigned *)0x40020000 + 0x18)
  42. // #define rPIOA_CODR (*(volatile unsigned *)0x40020000 + 0x1A)
  43. // #define rPIOA_PDSR (*(volatile unsigned *)0x40020000 + 0x10)
  44. // #define SDA ((rPIOA_PDSR&PIN25)?1:0)
  45. // /*================================Àî=====================================*/
  46. // #define IO_PORT_DIR (-1)
  47. // #define IO_PORT_OUT (0)
  48. #if 0
  49. #define GIO_DIR_INPUT 0x00
  50. #define GIO_DIR_OUTPUT 0x01
  51. #define GPIO_CLK GPIO_PIN_6
  52. #define PORT_CLK GPIOE
  53. #define GPIO_DATA GPIO_PIN_5
  54. #define PORT_DATA GPIOE
  55. #define CM_CLK_OUT stm32_gpio_direct(PORT_CLK,GPIO_CLK,GIO_DIR_OUTPUT)
  56. #define CM_CLK_HI stm32_gpio_write(PORT_CLK,GPIO_CLK,GPIO_PIN_SET)
  57. #define CM_CLK_LO stm32_gpio_write(PORT_CLK,GPIO_CLK,GPIO_PIN_RESET)
  58. #define CM_DATA_OUT stm32_gpio_direct(PORT_DATA,GPIO_DATA,GIO_DIR_OUTPUT)
  59. #define CM_DATA_IN stm32_gpio_direct(PORT_DATA,GPIO_DATA,GIO_DIR_INPUT)
  60. #define CM_DATA_HI stm32_gpio_write(PORT_DATA,GPIO_DATA,GPIO_PIN_SET)
  61. #define CM_DATA_LO stm32_gpio_write(PORT_DATA,GPIO_DATA,GPIO_PIN_RESET)
  62. #define CM_DATA_RD stm32_gpio_read(PORT_DATA,GPIO_DATA)
  63. #define CM_START_TRIES 10 //(CM_PORT_CFG.ucStartTries)
  64. // -------------------------------------------------------------------------------------------------
  65. // Macros that replace small common function
  66. // -------------------------------------------------------------------------------------------------
  67. #define CM_CLOCKHIGH cm_Delay(1);(CM_CLK_HI);cm_Delay(1)
  68. #define CM_CLOCKLOW cm_Delay(1);(CM_CLK_LO);cm_Delay(1)
  69. #define CM_CLOCKCYCLE cm_Delay(1);(CM_CLK_LO);cm_Delay(2);(CM_CLK_HI);cm_Delay(1)
  70. #endif /* #if 0 */
  71. // -------------------------------------------------------------------------------------------------
  72. // Low Level Function Prototypes
  73. // -------------------------------------------------------------------------------------------------
  74. // Placeholder function that always returns TRUE
  75. uint8_t cm_TRUE(void);
  76. void cm_PowerOn(void);
  77. void cm_PowerOff(void);
  78. // Send Command
  79. uint8_t cm_SendCommand(uint8_t * pucCommandBuffer);
  80. // Receive Data
  81. uint8_t cm_ReceiveData(uint8_t * pucReceiveData, uint8_t ucLength);
  82. // Send Data
  83. uint8_t cm_SendData(uint8_t * pucSendData, uint8_t ucLength);
  84. // Random
  85. void cm_RandGen(uint8_t * pucRandomData);
  86. // Wait Clock
  87. void cm_WaitClock(uint8_t ucLoop);
  88. // Send Command Byte
  89. uint8_t cm_SendCmdByte(uint8_t ucCommand);
  90. // end of multiple inclusion protection
  91. #endif