testbox_update.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. #include "update_loader_download.h"
  2. #include "update.h"
  3. #include "btctrler_task.h"
  4. #include "app_config.h"
  5. #include "asm/power/p33.h"
  6. #include "asm/power_interface.h"
  7. void power_set_mode(u8 mode);
  8. #if defined(CONFIG_SPP_AND_LE_CASE_ENABLE) || defined(CONFIG_HID_CASE_ENABLE)
  9. #include "lib_profile_cfg.h"
  10. #else
  11. #include "bt_profile_cfg.h"
  12. #endif
  13. #if (SMART_BOX_EN) && (CONFIG_WATCH_CASE_ENABLE)
  14. #include "smartbox/smartbox_task.h"
  15. #endif
  16. #define LOG_TAG "[TEST-UPDATE]"
  17. #define LOG_INFO_ENABLE
  18. #define LOG_ERROR_ENABLE
  19. #include "system/debug.h"
  20. extern u8 check_le_conn_disconnet_flag(void);
  21. extern void ble_app_disconnect(void);
  22. extern void ll_hci_destory(void);
  23. extern void ram_protect_close(void);
  24. extern void update_close_hw(void *filter_name);
  25. extern void btctrler_testbox_update_msg_handle_register(void (*handle)(int));
  26. extern void __bt_updata_reset_bt_bredrexm_addr(void);
  27. extern int __bt_updata_save_connection_info(void);
  28. extern const update_op_api_t lmp_ch_update_op;
  29. extern const update_op_api_t ble_ll_ch_update_op;
  30. static u8 ble_update_ready_jump_flag = 0;
  31. static void testbox_bt_classic_update_private_param_fill(UPDATA_PARM *p)
  32. {
  33. }
  34. static void testbox_bt_classic_update_before_jump_handle(int type)
  35. {
  36. if (UPDATE_MODULE_IS_SUPPORT(UPDATE_BT_LMP_EN)) {
  37. #if TCFG_USER_TWS_ENABLE || TCFG_USER_BLE_ENABLE
  38. log_info("close ble hw\n");
  39. ll_hci_destory();
  40. #endif
  41. y_printf("\n >>>[test]:func = %s,line= %d\n", __FUNCTION__, __LINE__);
  42. update_close_hw("bredr");
  43. if (__bt_updata_save_connection_info()) {
  44. log_error("bt save conn info fail!\n");
  45. return;
  46. }
  47. ram_protect_close();
  48. //note:last func will not return;
  49. power_set_mode(PWR_LDO15);
  50. __bt_updata_reset_bt_bredrexm_addr();
  51. }
  52. }
  53. static void testbox_bt_classic_update_state_cbk(int type, u32 state, void *priv)
  54. {
  55. update_ret_code_t *ret_code = (update_ret_code_t *)priv;
  56. if (ret_code) {
  57. log_info("state:%x err:%x\n", ret_code->stu, ret_code->err_code);
  58. }
  59. switch (state) {
  60. case UPDATE_CH_EXIT:
  61. if (UPDATE_DUAL_BANK_IS_SUPPORT()) {
  62. if ((0 == ret_code->stu) && (0 == ret_code->err_code)) {
  63. log_info("bt update succ\n");
  64. update_result_set(UPDATA_SUCC);
  65. } else {
  66. log_info("bt update fail\n");
  67. update_result_set(UPDATA_DEV_ERR);
  68. }
  69. } else {
  70. if ((0 == ret_code->stu) && (0 == ret_code->err_code)) {
  71. //update_mode_api(BT_UPDATA);
  72. update_mode_api_v2(BT_UPDATA,
  73. testbox_bt_classic_update_private_param_fill,
  74. testbox_bt_classic_update_before_jump_handle);
  75. } else if ((1 == ret_code->stu)) { //文件相同的情况
  76. cpu_reset();
  77. }
  78. }
  79. break;
  80. }
  81. }
  82. u8 ble_update_get_ready_jump_flag(void)
  83. {
  84. return ble_update_ready_jump_flag;
  85. }
  86. static void testbox_ble_update_private_param_fill(UPDATA_PARM *p)
  87. {
  88. u8 addr[6];
  89. extern int le_controller_get_mac(void *addr);
  90. if (BT_MODULES_IS_SUPPORT(BT_MODULE_LE) && UPDATE_MODULE_IS_SUPPORT(UPDATE_BLE_TEST_EN)) {
  91. le_controller_get_mac(addr);
  92. //memcpy(p->parm_priv, addr, 6);
  93. update_param_priv_fill(p, addr, sizeof(addr));
  94. puts("ble addr:\n");
  95. put_buf(p->parm_priv, 6);
  96. }
  97. }
  98. static void testbox_ble_update_before_jump_handle(int type)
  99. {
  100. if (BT_MODULES_IS_SUPPORT(BT_MODULE_LE) && UPDATE_MODULE_IS_SUPPORT(UPDATE_BLE_TEST_EN)) {
  101. ll_hci_destory();
  102. }
  103. #if CONFIG_UPDATE_JUMP_TO_MASK
  104. y_printf(">>>[test]:latch reset update\n");
  105. latch_reset();
  106. #if 0
  107. update_close_hw("null");
  108. ram_protect_close();
  109. /* save_spi_port(); */
  110. extern void __BT_UPDATA_JUMP();
  111. y_printf("update jump to __BT_UPDATA ...\n");
  112. /* clk_set("sys", 48 * 1000000L); */
  113. //跳转到uboot加载完,30ms左右(200410_yzb)
  114. __BT_UPDATA_JUMP();
  115. #endif
  116. #else
  117. cpu_reset();
  118. #endif
  119. }
  120. static void testbox_ble_update_state_cbk(int type, u32 state, void *priv)
  121. {
  122. update_ret_code_t *ret_code = (update_ret_code_t *)priv;
  123. if (ret_code) {
  124. printf("ret_code->stu:%d err_code:%d\n", ret_code->stu, ret_code->err_code);
  125. }
  126. switch (state) {
  127. case UPDATE_CH_EXIT:
  128. if (UPDATE_DUAL_BANK_IS_SUPPORT()) {
  129. if ((0 == ret_code->stu) && (0 == ret_code->err_code)) {
  130. log_info("bt update succ\n");
  131. update_result_set(UPDATA_SUCC);
  132. } else {
  133. log_info("bt update fail\n");
  134. update_result_set(UPDATA_DEV_ERR);
  135. }
  136. } else {
  137. if ((0 == ret_code->stu) && (0 == ret_code->err_code)) {
  138. #if TCFG_USER_BLE_ENABLE && (TCFG_BLE_DEMO_SELECT != DEF_BLE_DEMO_NULL) \
  139. &&(TCFG_BLE_DEMO_SELECT != DEF_BLE_DEMO_ADV) \
  140. && (TCFG_BLE_DEMO_SELECT != DEF_BLE_DEMO_CLIENT) \
  141. || defined(CONFIG_MESH_CASE_ENABLE)
  142. ble_update_ready_jump_flag = 1;
  143. /* ble_app_disconnect(); */
  144. extern void ble_module_enable(u8 en);
  145. ble_module_enable(0);
  146. u8 cnt = 0;
  147. while (!check_le_conn_disconnet_flag()) {
  148. log_info("wait discon\n");
  149. os_time_dly(2);
  150. if (cnt++ > 5) {
  151. break;
  152. }
  153. }
  154. //update_mode_api(BLE_TEST_UPDATA);
  155. update_mode_api_v2(BLE_TEST_UPDATA,
  156. testbox_ble_update_private_param_fill,
  157. testbox_ble_update_before_jump_handle);
  158. #endif
  159. } else if ((1 == ret_code->stu)) { //文件相同的情况,默认是复位
  160. #if TCFG_USER_BLE_ENABLE && (TCFG_BLE_DEMO_SELECT != DEF_BLE_DEMO_NULL) \
  161. &&(TCFG_BLE_DEMO_SELECT != DEF_BLE_DEMO_ADV || defined(CONFIG_MESH_CASE_ENABLE))\
  162. && (TCFG_BLE_DEMO_SELECT != DEF_BLE_DEMO_CLIENT)
  163. extern void ble_module_enable(u8 en);
  164. ble_module_enable(0);
  165. u8 cnt = 0;
  166. while (!check_le_conn_disconnet_flag()) {
  167. log_info("wait discon\n");
  168. os_time_dly(2);
  169. if (cnt++ > 5) {
  170. break;
  171. }
  172. }
  173. #endif
  174. cpu_reset();
  175. }
  176. }
  177. break;
  178. }
  179. }
  180. void testbox_update_msg_handle(int msg)
  181. {
  182. log_info("msg:%x\n", msg);
  183. switch (msg) {
  184. case MSG_BT_UPDATE_LOADER_DOWNLOAD_START:
  185. if (UPDATE_MODULE_IS_SUPPORT(UPDATE_BT_LMP_EN)) {
  186. #if (SMART_BOX_EN) && (CONFIG_WATCH_CASE_ENABLE)
  187. app_smartbox_task_prepare(0, SMARTBOX_TASK_ACTION_WATCH_TRANSFER, 0);
  188. #endif
  189. update_mode_info_t info = {
  190. .type = BT_UPDATA,
  191. .state_cbk = testbox_bt_classic_update_state_cbk,
  192. .p_op_api = &lmp_ch_update_op,
  193. .task_en = 1,
  194. };
  195. app_active_update_task_init(&info);
  196. }
  197. break;
  198. case MSG_BLE_TEST_OTA_LOADER_DOWNLOAD_START:
  199. if (UPDATE_MODULE_IS_SUPPORT(UPDATE_BLE_TEST_EN)) {
  200. update_mode_info_t info = {
  201. .type = BLE_TEST_UPDATA,
  202. .state_cbk = testbox_ble_update_state_cbk,
  203. .p_op_api = &ble_ll_ch_update_op,
  204. .task_en = 1,
  205. };
  206. app_active_update_task_init(&info);
  207. }
  208. break;
  209. defaut:
  210. log_error("not support update msg:%x\n", msg);
  211. break;
  212. }
  213. }
  214. void testbox_update_init(void)
  215. {
  216. if (UPDATE_MODULE_IS_SUPPORT(UPDATE_BLE_TEST_EN) || UPDATE_MODULE_IS_SUPPORT(UPDATE_BT_LMP_EN)) {
  217. log_info("testbox msg handle reg:%x\n", testbox_update_msg_handle);
  218. btctrler_testbox_update_msg_handle_register(testbox_update_msg_handle);
  219. }
  220. }