ota.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /********************************** (C) COPYRIGHT *******************************
  2. * File Name : ota.h
  3. * Author : WCH
  4. * Version : V1.10
  5. * Date : 2018/12/14
  6. * Description : oad相关配置定义
  7. *********************************************************************************
  8. * Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
  9. * Attention: This software (modified or not) and binary are used for
  10. * microcontroller manufactured by Nanjing Qinheng Microelectronics.
  11. *******************************************************************************/
  12. /******************************************************************************/
  13. #ifndef __OTA_H
  14. #define __OTA_H
  15. /* ------------------------------------------------------------------------------------------------
  16. * OTA FLASH
  17. * ------------------------------------------------------------------------------------------------
  18. */
  19. /* 整个用户code区分成3块,依次为16K,240K,192K 分别叫做imageIAP(IAP),imageA(APP),LIB */
  20. /* FLASH定义 */
  21. #define FLASH_BLOCK_SIZE 4096
  22. #define FLASH_PAGE_SIZE 256
  23. /* imageIAP定义 */
  24. #define IMAGE_IAP_FLAG 0x02
  25. #define IMAGE_IAP_START_ADD 0x08000000
  26. #define IMAGE_IAP_SIZE 20 * 1024
  27. /* imageA定义 */
  28. #define IMAGE_A_FLAG 0x01
  29. #define IMAGE_A_START_ADD (IMAGE_IAP_START_ADD+IMAGE_IAP_SIZE)
  30. #define IMAGE_A_SIZE 236 * 1024
  31. #define IMAGE_OTA_FLAG 0x03
  32. #define jumpApp ((void (*)(void))((int *)(IMAGE_A_START_ADD-0x08000000)))
  33. /* IAP定义 */
  34. /* 以下为IAP下载命令定义 */
  35. #define CMD_IAP_PROM 0x80 // IAP编程命令
  36. #define CMD_IAP_ERASE 0x81 // IAP擦除命令
  37. #define CMD_IAP_VERIFY 0x82 // IAP校验命令
  38. #define CMD_IAP_END 0x83 // IAP结束标志
  39. #define CMD_IAP_INFO 0x84 // IAP获取设备信息
  40. /* 数据帧长度定义 */
  41. #define IAP_LEN 247
  42. /* 存放在DataFlash地址,不能占用蓝牙的位置 */
  43. #define OTA_DATAFLASH_ADD 0x08077000
  44. /* 存放在DataFlash里的OTA信息 */
  45. typedef struct
  46. {
  47. unsigned char ImageFlag; //记录的当前的image标志
  48. unsigned char flag[3];
  49. } OTADataFlashInfo_t;
  50. /* OTA IAP通讯协议定义 */
  51. /* 地址使用4倍偏移 */
  52. typedef union
  53. {
  54. struct
  55. {
  56. unsigned char cmd; /* 命令码 0x81 */
  57. unsigned char len; /* 后续数据长度 */
  58. unsigned char addr[2]; /* 擦除地址 */
  59. unsigned char block_num[2]; /* 擦除块数 */
  60. } erase; /* 擦除命令 */
  61. struct
  62. {
  63. unsigned char cmd; /* 命令码 0x83 */
  64. unsigned char len; /* 后续数据长度 */
  65. unsigned char status[2]; /* 两字节状态,保留 */
  66. } end; /* 结束命令 */
  67. struct
  68. {
  69. unsigned char cmd; /* 命令码 0x82 */
  70. unsigned char len; /* 后续数据长度 */
  71. unsigned char addr[2]; /* 校验地址 */
  72. unsigned char buf[IAP_LEN - 4]; /* 校验数据 */
  73. } verify; /* 校验命令 */
  74. struct
  75. {
  76. unsigned char cmd; /* 命令码 0x80 */
  77. unsigned char len; /* 后续数据长度 */
  78. unsigned char addr[2]; /* 地址 */
  79. unsigned char buf[IAP_LEN - 4]; /* 后续数据 */
  80. } program; /* 编程命令 */
  81. struct
  82. {
  83. unsigned char cmd; /* 命令码 0x84 */
  84. unsigned char len; /* 后续数据长度 */
  85. unsigned char buf[IAP_LEN - 2]; /* 后续数据 */
  86. } info; /* 编程命令 */
  87. struct
  88. {
  89. unsigned char buf[IAP_LEN]; /* 接收数据包*/
  90. } other;
  91. } OTA_IAP_CMD_t;
  92. /* 记录当前的Image */
  93. extern unsigned char CurrImageFlag;
  94. #endif