dev_iap.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #ifndef __DEV_IAP_H
  2. #define __DEV_IAP_H
  3. #ifdef __cplusplus
  4. extern 'C'
  5. {
  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 "dev_can.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 (UPGRADE_FLAG_DATA_SIZE + UPGRADE_APP_DATA_SIZE) // 升级参数数组元素个数
  32. #define APP_START_ADDR ((uint32_t)0x08008000)
  33. #define APP_END_ADDR ((uint32_t)0x0805FFFF)
  34. #define UPGRADE_FLAG_START_ADDR ((uint32_t)0x08060000)
  35. #define UPGRADE_FLAG_END_ADDR ((uint32_t)0x0807FFFF)
  36. #define DOWNLOAD_START_ADDR ((uint32_t)0x08080000)
  37. #define DOWNLOAD_END_ADDR ((uint32_t)0x080DFFFF)
  38. #define DOWNLOAD_MIDDLE_ADDR ((uint32_t)0x080A0000)
  39. // 升级命令
  40. #define IAP_CMD_VERSION 0x71 // 查询版本号
  41. #define IAP_CMD_INFO 0x72 // 包信息
  42. #define IAP_CMD_ERASE 0x73 // 擦除命令
  43. #define IAP_CMD_DATA 0x80 // 数据帧 IAP_CMD_DATA |帧号
  44. #define IAP_CMD_CRC 0x74 // 传输结果校验
  45. #define IAP_CMD_JUMP 0x75 // 执行跳转
  46. #define IAP_CMD_JUMP_OVER 0x0175 // 执行跳转
  47. #define IAP_CMD_MODEL_TYPE 0x76 // 执行跳转
  48. #define UPGRADE_SIGN 0x5AA5
  49. #define DEVICE_ID 0x5AA5
  50. typedef union
  51. {
  52. uint16_t u8_buf[8];
  53. uint16_t u16_buf[4];
  54. } u16_u8;
  55. typedef union
  56. {
  57. uint16_t u8_save[200];
  58. uint16_t u16_save[100];
  59. } u16save_u8save;
  60. typedef struct
  61. {
  62. uint16_t total_packages;
  63. uint16_t current_packages;
  64. uint16_t count_packages;
  65. uint16_t recv_len;
  66. uint16_t crc16;
  67. uint16_t firmware_crc16;
  68. uint16_t firmware_ver;
  69. uint16_t total_bytes;
  70. uint16_t count_bytes;
  71. u16_u8 flash_data;
  72. u16_u8 recheck_data;
  73. u16save_u8save save_data;
  74. } iap_type;
  75. typedef union
  76. {
  77. struct
  78. {
  79. uint16_t sign; // 首地址 buf[0]
  80. uint16_t crc16; // 中地址 buf[1]
  81. uint32_t moving_size; // 高地址 buf[2] buf[3]
  82. } param;
  83. uint16_t infor_buf[UPGRADE_FLAG_DATA_SIZE];
  84. } upgrade_param; // 升级参数使用
  85. extern upgrade_param upgrade;
  86. void iap_param_init(void);
  87. void iap_flag_release(void);
  88. uint8_t erase_app_flash(uint32_t start_address, uint32_t end_addr);
  89. void jump_boot_time_ctrl(void);
  90. void iap_rec_handler(pdu_tag rec_msg);
  91. /************************************************************************************************
  92. * Defines *
  93. ************************************************************************************************/
  94. #ifdef __cplusplus
  95. };
  96. #endif
  97. #endif // __DEV_IAP_H