eeprom.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. /**
  2. ******************************************************************************
  3. * @file EEPROM_Emulation/inc/eeprom.h
  4. * @author MCD Application Team
  5. * @version V3.1.0
  6. * @date 07/27/2009
  7. * @brief This file contains all the functions prototypes for the EEPROM
  8. * emulation firmware library.
  9. ******************************************************************************
  10. * @copy
  11. *
  12. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  13. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  14. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  15. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  16. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  17. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  18. *
  19. * <h2><center>&copy; COPYRIGHT 2009 STMicroelectronics</center></h2>
  20. */
  21. /* Define to prevent recursive inclusion -------------------------------------*/
  22. #ifndef __EEPROM_H
  23. #define __EEPROM_H
  24. /* Includes ------------------------------------------------------------------*/
  25. #include "stm32f10x.h"
  26. //#define EEPROM_DEBUG_EN 1
  27. #ifdef EEPROM_DEBUG_EN
  28. #include <stdio.h>
  29. #define EEPROM_DEBUG(fmt, x...) \
  30. do \
  31. { \
  32. printf(fmt,##x); \
  33. }while(0)
  34. #define EEPROM_DEBUG1(fmt, x...) \
  35. do \
  36. { \
  37. printf("%s(Line %d): "fmt,__FUNCTION__,__LINE__, ##x); \
  38. }while(0)
  39. #define EEPROM_DEBUG_F(fmt, x...) \
  40. do \
  41. { \
  42. printf("%s %s(Line %d): "fmt,__FILE__,__FUNCTION__,__LINE__, ##x); \
  43. }while(0)
  44. #else
  45. #define EEPROM_DEBUG(fmt, x...)
  46. #define EEPROM_DEBUG1(fmt, x...)
  47. #define EEPROM_DEBUG_F(fmt, x...)
  48. #endif
  49. /* Exported constants --------------------------------------------------------*/
  50. /* Define the STM32F10Xxx Flash page size depending on the used STM32 device */
  51. #if defined (STM32F10X_LD) || defined (STM32F10X_MD)
  52. #define PAGE_SIZE (uint16_t)0x400 /* Page size = 1KByte */
  53. #elif defined (STM32F10X_HD) || defined (STM32F10X_CL)
  54. #define PAGE_SIZE (uint16_t)0x800 /* Page size = 2KByte */
  55. #endif
  56. /* EEPROM start address in Flash */
  57. #define EEPROM_START_ADDRESS ((uint32_t)0x0800F000) /* EEPROM emulation start address:
  58. after 64KByte of used Flash memory */
  59. /* Pages 0 and 1 base and end addresses */
  60. #define PAGE0_BASE_ADDRESS ((uint32_t)(EEPROM_START_ADDRESS + 0x000))
  61. #define PAGE0_END_ADDRESS ((uint32_t)(EEPROM_START_ADDRESS + (PAGE_SIZE - 1)))
  62. #define PAGE1_BASE_ADDRESS ((uint32_t)(EEPROM_START_ADDRESS + PAGE_SIZE))
  63. #define PAGE1_END_ADDRESS ((uint32_t)(EEPROM_START_ADDRESS + (2 * PAGE_SIZE - 1)))
  64. /* Used Flash pages for EEPROM emulation */
  65. #define PAGE0 ((uint16_t)0x0000)
  66. #define PAGE1 ((uint16_t)0x0001)
  67. /* No valid page define */
  68. #define NO_VALID_PAGE ((uint16_t)0x00AB)
  69. /* Page status definitions */
  70. #define ERASED ((uint16_t)0xFFFF) /* PAGE is empty */
  71. #define RECEIVE_DATA ((uint16_t)0xEEEE) /* PAGE is marked to receive data */
  72. #define VALID_PAGE ((uint16_t)0x0000) /* PAGE containing valid data */
  73. /* Valid pages in read and write defines */
  74. #define READ_FROM_VALID_PAGE ((uint8_t)0x00)
  75. #define WRITE_IN_VALID_PAGE ((uint8_t)0x01)
  76. /* Page full define */
  77. #define PAGE_FULL ((uint8_t)0x80)
  78. extern uint16_t VirtAddVarTab[];
  79. /* Variables' number */
  80. //#define NumbOfVar ((uint16_t)0x0041)
  81. #define NumbOfVar (sizeof(VirtAddVarTab)/sizeof(VirtAddVarTab[0]))
  82. /*复位次数*/
  83. #define CURSET_RESET_TIME 0x0000
  84. /*升级状态*/
  85. #define CURSET_UPDATE_STATE 0x0001
  86. /*set版本*/
  87. #define CURSET_SET_VER 0x0002
  88. /*预留*/
  89. #define CURSET_RESERVED1 0x0003
  90. /*预留*/
  91. #define CURSET_RESERVED2 0x0004
  92. /*预留*/
  93. #define CURSET_RESERVED3 0x0005
  94. /*设备唯一ID(MAC)(最低16位/共64位)*/
  95. #define CURSET_DEVICE_DevEUI0 0x0006
  96. /**/
  97. #define CURSET_DEVICE_DevEUI1 0x0007
  98. /**/
  99. #define CURSET_DEVICE_DevEUI2 0x0008
  100. /*设备唯一ID(MAC)(最高16位/共64位)*/
  101. #define CURSET_DEVICE_DevEUI3 0x0009
  102. /*设备地址(IP)(最低16位/共32位)*/
  103. #define CURSET_DEVICE_DevAddr0 0x000A
  104. /*设备地址(IP)(最高16位/共32位)*/
  105. #define CURSET_DEVICE_DevAddr1 0x000B
  106. /*设备类型:
  107. 0x01,网关
  108. 0x02,液位仪
  109. 0x03,采集器
  110. 0x04,NB油机
  111. 0x05,NB液位仪
  112. 0x09,英泰赛福模块*/
  113. #define CURSET_DEVICE_TYPE 0x000C
  114. /*硬件版本*/
  115. #define CURSET_DEVICE_HARD_VER 0x000D
  116. /*生产日期(2020)*/
  117. #define CURSET_DEVICE_MFD0 0x000E
  118. /*生产日期(08/08)*/
  119. #define CURSET_DEVICE_MFD1 0x000F
  120. /*所属网关ID(最低16位/共32位)*/
  121. #define CURSET_GW_ID0 0x0010
  122. /*所属网关ID(最高16位/共32位)*/
  123. #define CURSET_GW_ID1 0x0011
  124. /*Channel通道号*/
  125. #define CURSET_CHANNELL_NUM 0x0012
  126. /*BootLoader软件版本(最低16位/共32位)*/
  127. #define CURSET_BT_SOFT_VER0 0x0013
  128. /*BootLoader软件版本(最高16位/共32位)*/
  129. #define CURSET_BT_SOFT_VER1 0x0014
  130. /*协议版本(最低16位/共32位)*/
  131. #define CURSET_PROTOCOL_VER0 0x0015
  132. /*协议版本(最高16位/共32位)*/
  133. #define CURSET_PROTOCOL_VER1 0x0016
  134. /*app1起始地址(低16位)*/
  135. #define CURSET_APP1_START_ADDR0 0x0017
  136. /*app1起始地址(高16位)*/
  137. #define CURSET_APP1_START_ADDR1 0x0018
  138. /*app1版本存放地址(低16位)*/
  139. #define CURSET_APP1_VER_ADDR0 0x0019
  140. /*app1版本存放地址(高16位)*/
  141. #define CURSET_APP1_VER_ADDR1 0x001A
  142. /*app1长度存放地址(低16位)*/
  143. #define CURSET_APP1_LEN_ADDR0 0x001B
  144. /*app1长度存放地址(高16位)*/
  145. #define CURSET_APP1_LEN_ADDR1 0x001C
  146. /*app1CRC存放地址(低16位)*/
  147. #define CURSET_APP1_CRC_ADDR0 0x001D
  148. /*app1CRC存放地址(高16位)*/
  149. #define CURSET_APP1_CRC_ADDR1 0x001E
  150. /*app2起始地址(低16位)*/
  151. #define CURSET_APP2_START_ADDR0 0x001F
  152. /*app2起始地址(高16位)*/
  153. #define CURSET_APP2_START_ADDR1 0x0020
  154. /*app2版本存放地址(低16位)*/
  155. #define CURSET_APP2_VER_ADDR0 0x0021
  156. /*app2版本存放地址(高16位)*/
  157. #define CURSET_APP2_VER_ADDR1 0x0022
  158. /*app2长度存放地址(低16位)*/
  159. #define CURSET_APP2_LEN_ADDR0 0x0023
  160. /*app2长度存放地址(高16位)*/
  161. #define CURSET_APP2_LEN_ADDR1 0x0024
  162. /*app2CRC存放地址(低16位)*/
  163. #define CURSET_APP2_CRC_ADDR0 0x0025
  164. /*app2CRC存放地址(高16位)*/
  165. #define CURSET_APP2_CRC_ADDR1 0x0026
  166. /*app3起始地址(低16位)*/
  167. #define CURSET_APP3_START_ADDR0 0x0027
  168. /*app3起始地址(高16位)*/
  169. #define CURSET_APP3_START_ADDR1 0x0028
  170. /*app3版本存放地址(低16位)*/
  171. #define CURSET_APP3_VER_ADDR0 0x0029
  172. /*app3版本存放地址(高16位)*/
  173. #define CURSET_APP3_VER_ADDR1 0x002A
  174. /*app3长度存放地址(低16位)*/
  175. #define CURSET_APP3_LEN_ADDR0 0x002B
  176. /*app3长度存放地址(高16位)*/
  177. #define CURSET_APP3_LEN_ADDR1 0x002C
  178. /*app3CRC存放地址(低16位)*/
  179. #define CURSET_APP3_CRC_ADDR0 0x002D
  180. /*app3CRC存放地址(高16位)*/
  181. #define CURSET_APP3_CRC_ADDR1 0x002E
  182. /*app3固件类型*/
  183. #define CURSET_APP3_FIREWARE_TYPE 0x002F
  184. /*BASE_KEY0(最低16位/共128位)*/
  185. #define CURSET_BASE_KEY0 0x0030
  186. /**/
  187. #define CURSET_BASE_KEY1 0x0031
  188. /**/
  189. #define CURSET_BASE_KEY2 0x0032
  190. /**/
  191. #define CURSET_BASE_KEY3 0x0033
  192. /**/
  193. #define CURSET_BASE_KEY4 0x0034
  194. /**/
  195. #define CURSET_BASE_KEY5 0x0035
  196. /**/
  197. #define CURSET_BASE_KEY6 0x0036
  198. /*BASE_KEY7(最高16位/共128位)*/
  199. #define CURSET_BASE_KEY7 0x0037
  200. /*LORA 信道0 参数0
  201. [15]信道0使能,默认1b
  202. [14:08] Power,功率,默认20=0x14
  203. [07:00] (Freq/100)[07:00],默认0x88*/
  204. #define CURSET_LORA_CH0_PARM0 0x0038
  205. /*LORA 信道0 参数0
  206. [15:00] (Freq/100)[24:08],默认0x4A4B
  207. [07]信道0使能
  208. [06:00] Power*/
  209. #define CURSET_LORA_CH0_PARM1 0x0039
  210. /*LORA 信道0 参数1
  211. [15:08]SignalBw,默认9(500 kHz)
  212. [07:00]SpreadingFactor7(128)*/
  213. #define CURSET_LORA_CH0_PARM2 0x003A
  214. /*LORA 信道0 参数2
  215. [15:12]ErrorCoding,默认1(4/5)
  216. [11]CrcOn,默认1(on)
  217. [10]ImplicitHeaderOn,默认0(显示报头模式)
  218. [09]RxSingleOn,默认0(持续接收)
  219. [08]FreqHopOn,默认0
  220. [07:00]PayloadLength,默认128*/
  221. #define CURSET_LORA_CH0_PARM3 0x003B
  222. /*LORA 信道0参数3
  223. [15:08]TxPacketTimeout
  224. [07:00]RxPacketTimeout*/
  225. #define CURSET_LORA_CH0_PARM4 0x003C
  226. /*LORA 信道1 参数0
  227. [15]信道0使能,默认1b
  228. [14:08] Power,功率,默认20=0x14
  229. [07:00] (Freq/100)[07:00],默认0x68*/
  230. #define CURSET_LORA_CH1_PARM0 0x003D
  231. /*LORA 信道1 参数0
  232. [15:00] (Freq/100)[24:08],默认0x4D68
  233. [07]信道0使能
  234. [06:00] Power*/
  235. #define CURSET_LORA_CH1_PARM1 0x003E
  236. /*LORA 信道1 参数1
  237. [15:08]SignalBw,默认9(500 kHz)
  238. [07:00]SpreadingFactor7(128)*/
  239. #define CURSET_LORA_CH1_PARM2 0x003F
  240. /*LORA 信道1 参数2
  241. [15:12]ErrorCoding,默认1(4/5)
  242. [11]CrcOn,默认1(on)
  243. [10]ImplicitHeaderOn,默认0(显示报头模式)
  244. [09]RxSingleOn,默认0(持续接收)
  245. [08]FreqHopOn,默认0
  246. [07:00]PayloadLength,默认128*/
  247. #define CURSET_LORA_CH1_PARM3 0x0040
  248. /*LORA 信道1参数3
  249. [15:08]TxPacketTimeout
  250. [07:00]RxPacketTimeout*/
  251. #define CURSET_LORA_CH1_PARM4 0x0041
  252. /*税控口是否加解密,即英泰赛福模块是否使能*/
  253. #define CURSET_YTSF_EN 0x0042
  254. /*税控口轮询间隔*/
  255. #define CURSET_LOOP_PERIOD 0x0043
  256. /*税控口0参数
  257. [15:8] 税控口0有效标记,0为无效,非0有效
  258. [07] 枪7有效标记
  259. [06] 枪6有效标记
  260. [05] 枪5有效标记
  261. [04] 枪4有效标记
  262. [03] 枪3有效标记
  263. [02] 枪2有效标记
  264. [01] 枪1有效标记
  265. [00] 枪0有效标记*/
  266. #define CURSET_SKK_PORT0 0x0044
  267. /*税控口1参数
  268. [15:8] 税控口1有效标记,0为无效,非0有效
  269. [07] 枪7有效标记
  270. [06] 枪6有效标记
  271. [05] 枪5有效标记
  272. [04] 枪4有效标记
  273. [03] 枪3有效标记
  274. [02] 枪2有效标记
  275. [01] 枪1有效标记
  276. [00] 枪0有效标记*/
  277. #define CURSET_SKK_PORT1 0x0045
  278. /*税控口0序列号
  279. [15:08] SN第1个字节(首字节)ASCII格式
  280. [07:00] SN第1个字节(首字节)BCD格式*/
  281. #define CURSET_YTSF_PORT0_SN0 0x0046
  282. /*税控口0序列号
  283. [15:08] SN第2个字节BCD格式
  284. [07:00] SN第3个字节BCD格式*/
  285. #define CURSET_YTSF_PORT0_SN1 0x0047
  286. /*税控口0序列号
  287. [15:08] SN第4个字节BCD格式
  288. [07:00] SN第5个字节BCD格式*/
  289. #define CURSET_YTSF_PORT0_SN2 0x0048
  290. /*税控口1序列号
  291. [15:08] SN第1个字节(首字节)ASCII格式
  292. [07:00] SN第1个字节(首字节)BCD格式*/
  293. #define CURSET_YTSF_PORT1_SN0 0x0049
  294. /*税控口1序列号
  295. [15:08] SN第2个字节BCD格式
  296. [07:00] SN第3个字节BCD格式*/
  297. #define CURSET_YTSF_PORT1_SN1 0x004A
  298. /*税控口1序列号
  299. [15:08] SN第4个字节BCD格式
  300. [07:00] SN第5个字节BCD格式*/
  301. #define CURSET_YTSF_PORT1_SN2 0x004B
  302. /*除此字段以外所有参数做CRC(高16位)*/
  303. #define CURSET_CRC0 0x004C
  304. /*除此字段以外所有参数做CRC(低16位)*/
  305. #define CURSET_CRC1 0x004D
  306. /* Exported types ------------------------------------------------------------*/
  307. /* Exported macro ------------------------------------------------------------*/
  308. /* Exported functions ------------------------------------------------------- */
  309. uint16_t EE_Init(void);
  310. uint16_t EE_ReadVariable(uint16_t VirtAddress, uint16_t* Data);
  311. uint16_t EE_WriteVariable(uint16_t VirtAddress, uint16_t Data);
  312. uint16_t eeprom_test(void);
  313. #endif /* __EEPROM_H */
  314. /******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/