iap.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #ifndef __DEV_IAP_H
  2. #define __DEV_IAP_H
  3. #include "can_interface.h"
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. #ifdef __DEV_IAP_H_GLOBAL
  8. #define __DEV_IAP_H_EXTERN
  9. #else
  10. #define __DEV_IAP_H_EXTERN extern
  11. #endif
  12. /************************************************************************************************
  13. * Version *
  14. ************************************************************************************************/
  15. /************************************************************************************************
  16. * How to use *
  17. ************************************************************************************************/
  18. /************************************************************************************************
  19. * Enable config *
  20. ************************************************************************************************/
  21. /************************************************************************************************
  22. * Includes *
  23. ************************************************************************************************/
  24. #include "can_interface.h"
  25. #include <stdint.h>
  26. /************************************************************************************************
  27. * Defines *
  28. ************************************************************************************************/
  29. #define UPGRADE_FLAG_DATA_SIZE 4 // 升级参数数组元素个数
  30. #define UPGRADE_APP_DATA_SIZE 4 // 升级参数数组元素个数
  31. #define UPGRADE_BUFF_DATA_SIZE \
  32. (UPGRADE_FLAG_DATA_SIZE + UPGRADE_APP_DATA_SIZE) // 升级参数数组元素个数
  33. #define APP_START_ADDR ((uint32_t)0x08004000)
  34. #define APP_END_ADDR ((uint32_t)0x0801D000)
  35. #define UPGRADE_FLAG_START_ADDR ((uint32_t)0x0801D000)
  36. #define UPGRADE_FLAG_END_ADDR ((uint32_t)0x08027000)
  37. #define DOWNLOAD_START_ADDR ((uint32_t)0x08027000)
  38. #define DOWNLOAD_END_ADDR ((uint32_t)0x08040000)
  39. #define DOWNLOAD_MIDDLE_ADDR ((uint32_t)0x08033800)
  40. // 升级命令
  41. #define IAP_CMD_VERSION 0x71 // 查询版本号
  42. #define IAP_CMD_INFO 0x72 // 包信息
  43. #define IAP_CMD_ERASE 0x73 // 擦除命令
  44. #define IAP_CMD_DATA 0x80 // 数据帧 IAP_CMD_DATA |帧号
  45. #define IAP_CMD_CRC 0x74 // 传输结果校验
  46. #define IAP_CMD_JUMP 0x75 // 执行跳转
  47. #define IAP_CMD_JUMP_OVER 0x0175 // 执行跳转
  48. #define IAP_CMD_MODEL_TYPE 0x76 // 执行跳转
  49. #define UPGRADE_SIGN 0x5AA5
  50. #define DEVICE_ID 0x5AA5
  51. typedef union
  52. {
  53. uint16_t u8_buf[8];
  54. uint16_t u16_buf[4];
  55. } u16_u8;
  56. typedef union
  57. {
  58. uint16_t u8_save[200];
  59. uint16_t u16_save[100];
  60. } u16save_u8save;
  61. typedef struct
  62. {
  63. uint16_t total_packages;
  64. uint16_t current_packages;
  65. uint16_t count_packages;
  66. uint16_t recv_len;
  67. uint16_t crc16;
  68. uint16_t firmware_crc16;
  69. uint16_t firmware_ver;
  70. uint16_t total_bytes;
  71. uint16_t count_bytes;
  72. u16_u8 flash_data;
  73. u16_u8 recheck_data;
  74. u16save_u8save save_data;
  75. } iap_type;
  76. typedef union
  77. {
  78. struct
  79. {
  80. uint16_t sign; // 首地址 buf[0]
  81. uint16_t crc16; // 中地址 buf[1]
  82. uint32_t moving_size; // 高地址 buf[2] buf[3]
  83. } param;
  84. uint16_t infor_buf[UPGRADE_FLAG_DATA_SIZE];
  85. } upgrade_param; // 升级参数使用
  86. extern upgrade_param upgrade;
  87. void set_firmver(void);
  88. void iap_param_init(void);
  89. void iap_flag_release(void);
  90. uint8_t erase_app_flash(uint32_t start_address, uint32_t end_addr);
  91. void jump_boot_time_ctrl(void);
  92. void iap_rec_handler(pdu_tag rec_msg);
  93. /************************************************************************************************
  94. * Defines *
  95. ************************************************************************************************/
  96. #ifdef __cplusplus
  97. };
  98. #endif
  99. #endif // __DEV_IAP_H