app_main.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. /*********************************************************************************************
  2. * Filename : app_main.c
  3. * Description :
  4. * Copyright:(c)JIELI 2011-2019 @ , All Rights Reserved.
  5. *********************************************************************************************/
  6. #include "system/includes.h"
  7. #include "app_config.h"
  8. #include "app_action.h"
  9. #include "app_main.h"
  10. #include "update.h"
  11. #include "update_loader_download.h"
  12. #include "app_charge.h"
  13. #include "app_power_manage.h"
  14. #include "asm/charge.h"
  15. #if TCFG_KWS_VOICE_RECOGNITION_ENABLE
  16. #include "jl_kws/jl_kws_api.h"
  17. #endif /* #if TCFG_KWS_VOICE_RECOGNITION_ENABLE */
  18. #define LOG_TAG_CONST APP
  19. #define LOG_TAG "[APP]"
  20. #define LOG_ERROR_ENABLE
  21. #define LOG_DEBUG_ENABLE
  22. #define LOG_INFO_ENABLE
  23. /* #define LOG_DUMP_ENABLE */
  24. #define LOG_CLI_ENABLE
  25. #include "debug.h"
  26. /*任务列表 */
  27. const struct task_info task_info_table[] = {
  28. #if CONFIG_APP_FINDMY
  29. {"app_core", 1, 0, 640 * 2, 128},
  30. #else
  31. {"app_core", 1, 0, 640, 128},
  32. #endif
  33. {"sys_event", 7, 0, 256, 0},
  34. {"btctrler", 4, 0, 512, 256},
  35. {"btencry", 1, 0, 512, 128},
  36. {"btstack", 3, 0, 768, 256},
  37. {"systimer", 7, 0, 128, 0},
  38. {"update", 1, 0, 512, 0},
  39. {"dw_update", 2, 0, 256, 128},
  40. #if (RCSP_BTMATE_EN)
  41. {"rcsp_task", 2, 0, 640, 0},
  42. #endif
  43. #if (USER_UART_UPDATE_ENABLE)
  44. {"uart_update", 1, 0, 256, 128},
  45. #endif
  46. #if (XM_MMA_EN)
  47. {"xm_mma", 2, 0, 640, 256},
  48. #endif
  49. {"usb_msd", 1, 0, 512, 128},
  50. #if TCFG_AUDIO_ENABLE
  51. {"audio_dec", 3, 0, 768, 128},
  52. {"audio_enc", 4, 0, 512, 128},
  53. #endif /*TCFG_AUDIO_ENABLE*/
  54. #if TCFG_KWS_VOICE_RECOGNITION_ENABLE
  55. {"kws", 2, 0, 256, 64},
  56. #endif /* #if TCFG_KWS_VOICE_RECOGNITION_ENABLE */
  57. #if (TUYA_DEMO_EN)
  58. {"user_deal", 2, 0, 512, 512}, // 定义线程 tuya任务调度
  59. #endif
  60. #if (CONFIG_APP_HILINK)
  61. {"hilink_task", 2, 0, 1024, 0}, // 定义线程 hilink任务调度
  62. #endif
  63. {0, 0},
  64. };
  65. APP_VAR app_var;
  66. void app_var_init(void)
  67. {
  68. app_var.play_poweron_tone = 1;
  69. app_var.auto_off_time = TCFG_AUTO_SHUT_DOWN_TIME;
  70. app_var.warning_tone_v = 340;
  71. app_var.poweroff_tone_v = 330;
  72. }
  73. __attribute__((weak))
  74. u8
  75. get_charge_online_flag(void)
  76. {
  77. return 0;
  78. }
  79. void clr_wdt(void);
  80. void check_power_on_key(void)
  81. {
  82. #if TCFG_POWER_ON_NEED_KEY
  83. u32 delay_10ms_cnt = 0;
  84. while (1)
  85. {
  86. clr_wdt();
  87. os_time_dly(1);
  88. extern u8 get_power_on_status(void);
  89. if (get_power_on_status())
  90. {
  91. log_info("+");
  92. delay_10ms_cnt++;
  93. if (delay_10ms_cnt > 70)
  94. {
  95. /* extern void set_key_poweron_flag(u8 flag); */
  96. /* set_key_poweron_flag(1); */
  97. return;
  98. }
  99. }
  100. else
  101. {
  102. log_info("-");
  103. delay_10ms_cnt = 0;
  104. log_info("enter softpoweroff\n");
  105. power_set_soft_poweroff();
  106. }
  107. }
  108. #endif
  109. }
  110. void my_app(void *pvParameters)
  111. {
  112. char taskListBuffer[1024];
  113. char *test = "helloworld";
  114. while (1)
  115. {
  116. printf(">>> start my_app task\n");
  117. ct_uart_send_packet(test, 10);
  118. os_time_dly(10);
  119. // gpio_direction_output(IO_PORTA_09, 1);
  120. // os_time_dly(10);
  121. // gpio_direction_output(IO_PORTA_09, 0);
  122. }
  123. }
  124. void app_main()
  125. {
  126. struct intent it;
  127. if (!UPDATE_SUPPORT_DEV_IS_NULL())
  128. {
  129. int update = 0;
  130. update = update_result_deal();
  131. }
  132. // xTaskCreate(my_app, "my_app", 256, NULL, 1, NULL);
  133. printf(">>>>>>>>>>>>>>>>>app_main...\n");
  134. printf(">>> v220,2022-11-23 >>>\n");
  135. // if (get_charge_online_flag())
  136. // {
  137. // #if (TCFG_SYS_LVD_EN == 1)
  138. // vbat_check_init();
  139. // #endif
  140. // }
  141. // else
  142. // {
  143. // check_power_on_voltage();
  144. // }
  145. // #if TCFG_POWER_ON_NEED_KEY
  146. // check_power_on_key();
  147. // #endif
  148. // #if TCFG_AUDIO_ENABLE
  149. // extern int audio_dec_init();
  150. // extern int audio_enc_init();
  151. // audio_dec_init();
  152. // audio_enc_init();
  153. // #endif /*TCFG_AUDIO_ENABLE*/
  154. // #if TCFG_KWS_VOICE_RECOGNITION_ENABLE
  155. // jl_kws_main_user_demo();
  156. // #endif /* #if TCFG_KWS_VOICE_RECOGNITION_ENABLE */
  157. init_intent(&it);
  158. #if CONFIG_APP_SPP_LE
  159. it.name = "spp_le";
  160. it.action = ACTION_SPPLE_MAIN;
  161. #elif CONFIG_APP_AT_COM || CONFIG_APP_AT_CHAR_COM
  162. it.name = "at_com";
  163. it.action = ACTION_AT_COM;
  164. #elif CONFIG_APP_DONGLE
  165. it.name = "dongle";
  166. it.action = ACTION_DONGLE_MAIN;
  167. #elif CONFIG_APP_MULTI
  168. it.name = "multi_conn";
  169. it.action = ACTION_MULTI_MAIN;
  170. #elif CONFIG_APP_NONCONN_24G
  171. it.name = "nonconn_24g";
  172. it.action = ACTION_NOCONN_24G_MAIN;
  173. #elif CONFIG_APP_HILINK
  174. it.name = "hilink";
  175. it.action = ACTION_HILINK_MAIN;
  176. #elif CONFIG_APP_LL_SYNC
  177. it.name = "ll_sync";
  178. it.action = ACTION_LL_SYNC;
  179. #elif CONFIG_APP_TUYA
  180. it.name = "tuya";
  181. it.action = ACTION_TUYA;
  182. #elif CONFIG_APP_CENTRAL
  183. it.name = "central";
  184. it.action = ACTION_CENTRAL_MAIN;
  185. #elif CONFIG_APP_DONGLE
  186. it.name = "dongle";
  187. it.action = ACTION_DONGLE_MAIN;
  188. #elif CONFIG_APP_BEACON
  189. it.name = "beacon";
  190. it.action = ACTION_BEACON_MAIN;
  191. #elif CONFIG_APP_IDLE
  192. it.name = "idle";
  193. it.action = ACTION_IDLE_MAIN;
  194. #elif CONFIG_APP_CONN_24G
  195. it.name = "conn_24g";
  196. it.action = ACTION_CONN_24G_MAIN;
  197. #elif CONFIG_APP_FINDMY
  198. it.name = "findmy";
  199. it.action = ACTION_FINDMY;
  200. #else
  201. while (1)
  202. {
  203. printf("no app!!!");
  204. }
  205. #endif
  206. log_info("run app>>> %s", it.name);
  207. log_info("%s,%s", __DATE__, __TIME__);
  208. start_app(&it);
  209. // #if TCFG_CHARGE_ENABLE
  210. // set_charge_event_flag(1);
  211. // #endif
  212. }
  213. /*
  214. * app模式切换
  215. */
  216. void app_switch(const char *name, int action)
  217. {
  218. struct intent it;
  219. struct application *app;
  220. log_info("app_exit\n");
  221. init_intent(&it);
  222. app = get_current_app();
  223. if (app)
  224. {
  225. /*
  226. * 退出当前app, 会执行state_machine()函数中APP_STA_STOP 和 APP_STA_DESTORY
  227. */
  228. it.name = app->name;
  229. it.action = ACTION_BACK;
  230. start_app(&it);
  231. }
  232. /*
  233. * 切换到app (name)并执行action分支
  234. */
  235. it.name = name;
  236. it.action = action;
  237. start_app(&it);
  238. }
  239. int eSystemConfirmStopStatus(void)
  240. {
  241. /* 系统进入在未来时间里,无任务超时唤醒,可根据用户选择系统停止,或者系统定时唤醒(100ms) */
  242. // 1:Endless Sleep
  243. // 0:100 ms wakeup
  244. /* log_info("100ms wakeup"); */
  245. return 1;
  246. }
  247. __attribute__((used)) int *__errno()
  248. {
  249. static int err;
  250. return &err;
  251. }