eeprom.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /*
  2. * eeprom.h
  3. *
  4. * Created on: 2020. 4. 22.
  5. * Author: parkyj
  6. */
  7. #ifndef EEPROM_H_
  8. #define EEPROM_H_
  9. #define EEPROM_M24C08_ID 0xA0
  10. #define EEPROM_Block0_ADDRESS EEPROM_M24C08_ID
  11. #define EEPROM_ATT_BASE 0x0000
  12. #define EEPROM_ATT_DL1_TABLE_ADDRESDS EEPROM_ATT_BASE + (sizeof(ATT_TABLE_st) * 2)
  13. #define EEPROM_ATT_DL2_TABLE_ADDRESDS EEPROM_ATT_DL1_TABLE_ADDRESDS + (sizeof(ATT_TABLE_st) * 2)
  14. #define EEPROM_ATT_DL3_TABLE_ADDRESDS EEPROM_ATT_DL2_TABLE_ADDRESDS + (sizeof(ATT_TABLE_st) * 2)
  15. #define EEPROM_ATT_DL4_TABLE_ADDRESDS EEPROM_ATT_DL3_TABLE_ADDRESDS + (sizeof(ATT_TABLE_st) * 2)
  16. #define EEPROM_ATT_UL1_TABLE_ADDRESDS EEPROM_ATT_DL4_TABLE_ADDRESDS + (sizeof(ATT_TABLE_st) * 2)
  17. #define EEPROM_ATT_UL2_TABLE_ADDRESDS EEPROM_ATT_UL1_TABLE_ADDRESDS + (sizeof(ATT_TABLE_st) * 2)
  18. #define EEPROM_ATT_UL3_TABLE_ADDRESDS EEPROM_ATT_UL2_TABLE_ADDRESDS + (sizeof(ATT_TABLE_st) * 2)
  19. #define EEPROM_ATT_UL4_TABLE_ADDRESDS EEPROM_ATT_UL3_TABLE_ADDRESDS + (sizeof(ATT_TABLE_st) * 2)
  20. #define EEPROM_DET_DL1_TABLE_ADDRESDS EEPROM_ATT_UL4_TABLE_ADDRESDS + (sizeof(DET_TABLEDL_st) * 2)
  21. #define EEPROM_DET_DL2_TABLE_ADDRESDS EEPROM_DET_DL1_TABLE_ADDRESDS + (sizeof(DET_TABLEDL_st) * 2)
  22. #define EEPROM_DET_DL3_TABLE_ADDRESDS EEPROM_DET_DL2_TABLE_ADDRESDS + (sizeof(DET_TABLEDL_st) * 2)
  23. #define EEPROM_DET_DL4_TABLE_ADDRESDS EEPROM_DET_DL3_TABLE_ADDRESDS + (sizeof(DET_TABLEDL_st) * 2)
  24. #define EEPROM_DET_UL1_TABLE_ADDRESDS EEPROM_DET_DL4_TABLE_ADDRESDS + (sizeof(DET_TABLEUL_st) * 2)
  25. #define EEPROM_DET_UL2_TABLE_ADDRESDS EEPROM_DET_UL1_TABLE_ADDRESDS + (sizeof(DET_TABLEUL_st) * 2)
  26. #define EEPROM_DET_UL3_TABLE_ADDRESDS EEPROM_DET_UL2_TABLE_ADDRESDS + (sizeof(DET_TABLEUL_st) * 2)
  27. #define EEPROM_DET_UL4_TABLE_ADDRESDS EEPROM_DET_UL3_TABLE_ADDRESDS + (sizeof(DET_TABLEUL_st) * 2)
  28. #define EEPROM_TEMP_DL1_TABLE_ADDRESDS EEPROM_DET_UL4_TABLE_ADDRESDS + (sizeof(TEMP_TABLE_st) * 2)
  29. #define EEPROM_TEMP_DL2_TABLE_ADDRESDS EEPROM_TEMP_DL1_TABLE_ADDRESDS +( sizeof(TEMP_TABLE_st) * 2)
  30. #define EEPROM_TEMP_DL3_TABLE_ADDRESDS EEPROM_TEMP_DL2_TABLE_ADDRESDS +( sizeof(TEMP_TABLE_st) * 2)
  31. #define EEPROM_TEMP_DL4_TABLE_ADDRESDS EEPROM_TEMP_DL3_TABLE_ADDRESDS +( sizeof(TEMP_TABLE_st) * 2)
  32. #define EEPROM_TEMP_UL1_TABLE_ADDRESDS EEPROM_TEMP_DL4_TABLE_ADDRESDS +( sizeof(TEMP_TABLE_st) * 2)
  33. #define EEPROM_TEMP_UL2_TABLE_ADDRESDS EEPROM_TEMP_UL1_TABLE_ADDRESDS +( sizeof(TEMP_TABLE_st) * 2)
  34. #define EEPROM_TEMP_UL3_TABLE_ADDRESDS EEPROM_TEMP_UL2_TABLE_ADDRESDS +( sizeof(TEMP_TABLE_st) * 2)
  35. #define EEPROM_TEMP_UL4_TABLE_ADDRESDS EEPROM_TEMP_UL3_TABLE_ADDRESDS +( sizeof(TEMP_TABLE_st) * 2)
  36. #define EEPROM_WINDOW_STATUS_ADDRESDS EEPROM_TEMP_UL4_TABLE_ADDRESDS +( sizeof(BLUESTATUS_st) * 2)
  37. #define MAKE_ADDRESS(_addr, _e2) ((uint8_t)EEPROM_M24C08_ADDR | \
  38. ((_e2) ? EEPROM_M24C08_ADDR_E2 : 0) | \
  39. ((uint8_t)((_addr) >> 7) & EEPROM_M24C08_BYTE_ADDR_H))
  40. #define EEPROM_M24C08_ADDR 0xA0 //!< M24C08 device identifier
  41. #define EEPROM_M24C08_ADDR_E2 0x08 //!< M24C08 E2 address bit
  42. #define EEPROM_M24C08_BYTE_ADDR_H 0x06
  43. HAL_StatusTypeDef EEPROM_M24C08_Read(uint16_t devid,uint16_t Address,uint16_t* data,uint8_t size);
  44. HAL_StatusTypeDef EEPROM_M24C08_write(uint16_t devid,uint16_t Address,uint16_t* data,uint8_t size);
  45. HAL_StatusTypeDef EEPROM_M24C08_ByteRead(uint16_t devid,uint16_t Address,uint8_t* data,uint8_t size);
  46. HAL_StatusTypeDef EEPROM_M24C08_Bytewrite(uint16_t devid,uint16_t Address,uint8_t* data,uint8_t size);
  47. void EEPROM_M24C08_Init(void);
  48. // Exported type definitions --------------------------------------------------
  49. /**
  50. * The possible states the EEPROM driver can be in.
  51. */
  52. typedef enum
  53. {
  54. EE_UNINIT = 0, //!< Driver has not been initialized
  55. EE_IDLE, //!< Driver has been initialized and is ready to start a transfer
  56. EE_FINISH, //!< Driver has finished with a transfer
  57. EE_READ, //!< Driver is doing a read operation
  58. EE_WRITE_SEND, //!< Driver is writing data
  59. EE_WRITE_WAIT //!< Driver is waiting for the EEPROM to finish a write cycle
  60. } EEPROM_Status;
  61. /**
  62. * The possible outcomes of an operation.
  63. */
  64. typedef enum
  65. {
  66. EE_OK = 0, //!< Indicates success
  67. EE_BUSY, //!< Indicates that the driver is currently busy doing a transfer
  68. EE_ERROR //!< Indicates an error condition
  69. } EEPROM_Error;
  70. /**
  71. * Contains static configuration for the board such as populated peripherals, fitted resistor values and Ethernet MAC
  72. * address, that are stored on the EEPROM.
  73. */
  74. // Macros ---------------------------------------------------------------------
  75. #ifndef LOBYTE
  76. #define LOBYTE(x) ((uint8_t)(x & 0x00FF))
  77. #endif
  78. #ifndef HIBYTE
  79. #define HIBYTE(x) ((uint8_t)((x & 0xFF00) >> 8))
  80. #endif
  81. #define MAKE_ADDRESS(_addr, _e2) ((uint8_t)EEPROM_M24C08_ADDR | \
  82. ((_e2) ? EEPROM_M24C08_ADDR_E2 : 0) | \
  83. ((uint8_t)((_addr) >> 7) & EEPROM_M24C08_BYTE_ADDR_H))
  84. // Constants ------------------------------------------------------------------
  85. /**
  86. * @defgroup EEPROM_M24C08_ADDRESS M24C08 Address definitions
  87. *
  88. * The address byte that is sent to an M24C08 consists of 4 parts:
  89. * + The device identifier {@link EEPROM_M24C08_ADDR} (4 bits)
  90. * + An address bit {@link EEPROM_M24C08_ADDR_E2} that is either set or not, depending on the value of the `E2` pin on
  91. * the M24C08 device
  92. * + The two most significant bits of the memory address to be read/written {@link EEPROM_M24C08_BYTE_ADDR_H}
  93. * + The standard I2C read/write bit
  94. * @{
  95. */
  96. #define EEPROM_M24C08_ADDR 0xA0 //!< M24C08 device identifier
  97. #define EEPROM_M24C08_ADDR_E2 0x08 //!< M24C08 E2 address bit
  98. /**
  99. * Bitmask for the M24C08 I2C Address bits that are used for the high byte of the memory address. The address bits are
  100. * either the high byte shifted left by one or the 16 bit address shifted right by 7 and then masked.
  101. */
  102. #define EEPROM_M24C08_BYTE_ADDR_H 0x06
  103. /** @} */
  104. /**
  105. * Timeout in ms for I2C communication
  106. */
  107. #define EEPROM_I2C_TIMEOUT 0x200
  108. /**
  109. * EEPROM size in bytes
  110. */
  111. #define EEPROM_SIZE 0x400
  112. /**
  113. * Mask for the page address, a page write can only write to addresses which have the same page address
  114. */
  115. #define EEPROM_PAGE_MASK 0x03F0
  116. /**
  117. * Page size of the EEPROM, only one page can be written at a time
  118. */
  119. #define EEPROM_PAGE_SIZE 0x10
  120. /**
  121. * Configuration data offset, that is the first address of the configuration data space
  122. */
  123. #define EEPROM_CONFIG_OFFSET 0
  124. /**
  125. * Size of the configuration data section in bytes
  126. */
  127. #define EEPROM_CONFIG_SIZE 128
  128. /**
  129. * Data offset, that is the first address for arbitrary data
  130. */
  131. #define EEPROM_DATA_OFFSET 0x80
  132. /**
  133. * Size of the data section in bytes, this is the EEPROM size minus the data offset
  134. */
  135. #define EEPROM_DATA_SIZE (EEPROM_SIZE - EEPROM_DATA_OFFSET)
  136. /**
  137. * Size of the settings buffer in bytes
  138. */
  139. #define EEPROM_SETTINGS_SIZE 64
  140. // Exported functions ---------------------------------------------------------
  141. // ----------------------------------------------------------------------------
  142. #endif /* EEPROM_H_ */