main.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. #include "main.h"
  2. #include "sram.h"
  3. #include "nandflash.h"
  4. #include "usart.h"
  5. #include "malloc.h"
  6. #include "demo_nand_fatfs.h"
  7. #include "cjson.h"
  8. #include "delay.h"
  9. #include "string.h"
  10. #include "includes.h"
  11. #include "lwip/timers.h"
  12. #include "led.h"
  13. #include "sys_tcpdemo.h"
  14. #include "sys_mqtt.h"
  15. #include "sys_http.h"
  16. #include "task.h"
  17. #include "sys_sx1278.h"
  18. /*关于任务优先级分配(上限为12个、需要增加请修改上限)
  19. * 0: 保留
  20. * 1: 用于ucos的软件定时器
  21. * 2: 保留
  22. * 3: 用于 以太网的网卡数据包读取 ETHERNETIF_THREAD_PRO
  23. * 4: LWIP 核心线程 TCPIP_THREAD_PRIO
  24. * 5: 用于 ota升级
  25. * 6: 用于 MQTT数据发送线程 APP_TASK_MQTTMAIN_PRIO
  26. * 7: 用于 MQTT数据接收线程 APP_TASK_MQTTRECEIVE_PRIO
  27. * 8: 用于 sx1278发送/接收处理数据
  28. * 9: 用于 本机状态led显示
  29. * 10:用于网络状态led显示
  30. * 11:用于轮询读出本机保存信息发送到sx1278发送接收线程
  31. * 12:用于管理所有线程
  32. */
  33. ///////////////////////////////////////
  34. #define PERIOD_TASK_PRIO 2
  35. #define PERIOD_STK_SIZE 256
  36. OS_STK PERIOD_TASK_STK[PERIOD_STK_SIZE];
  37. void period_taskFuntcion(void *arg);
  38. //////////////////////////////////////////////
  39. //LED
  40. //LED优先级
  41. #define LED_TASK_PRIO 28
  42. //LED栈空间大小
  43. #define LED_STK_SIZE 128
  44. //任务堆栈
  45. OS_STK LED_TASK_STK[LED_STK_SIZE];
  46. //led运行任务
  47. void led_taskFuntcion(void *pdata);
  48. ////////////////////////////////////////////////////////
  49. /*---------------------------本地数据线程堆栈----------------------------------------------------------------*/
  50. __align(8) OS_STK DATA_TASK_STK[DATA_STK_SIZE];
  51. /*---------------------------lora通信线程堆栈----------------------------------------------------------------*/
  52. __align(8) OS_STK SX1278_TASK_STK[SX1278_STK_SIZE];
  53. void NVIC_Configuration(void);
  54. int main(void)
  55. {
  56. NVIC_Configuration();
  57. my_mem_init(SRAMEX);
  58. my_mem_init(SRAMIN);
  59. delay_init();
  60. //nandflash并不用初始化,调用fafts时会初始化
  61. NET_STATUS_LED_Config();
  62. USART_485_config();
  63. USART_232_config();
  64. NAND_Init();
  65. OSInit();
  66. //OSTaskCreate(start_task,(void*)0,(OS_STK*)&START_TASK_STK[START_STK_SIZE-1],START_TASK_PRIO);
  67. OSTaskCreate(period_taskFuntcion,(void*)0,(OS_STK*)&PERIOD_TASK_STK[PERIOD_STK_SIZE-1],PERIOD_TASK_PRIO);
  68. OSTaskCreate(led_taskFuntcion,(void*)0,(OS_STK*)&LED_TASK_STK[LED_STK_SIZE-1],LED_TASK_PRIO);
  69. OSTaskCreate(data_task,(void*)0,(OS_STK*)&DATA_TASK_STK[DATA_STK_SIZE-1],DATA_TASK_PRIO);
  70. OSTaskCreate(sx1278_send_task,(void *)0,(OS_STK*)&SX1278_TASK_STK[SX1278_STK_SIZE-1],SX1278_TASK_PRIO);
  71. printf("system start \r\n");
  72. OSStart(); //ucos启动
  73. /* Infinite loop */
  74. while (1)
  75. {
  76. }
  77. }
  78. void period_taskFuntcion(void *arg)
  79. {
  80. #if OS_TASK_STAT_EN > 0u
  81. OSStatInit();
  82. #endif
  83. lwIP_Init();
  84. http_getDemo();
  85. http_postDemo();
  86. mqtt_threadCreate();
  87. OSTaskSuspend(OS_PRIO_SELF);
  88. }
  89. //测试任务
  90. void led_taskFuntcion(void *pdata)
  91. {
  92. int tms;
  93. while(1)
  94. {
  95. tms = hd_netledOpen();
  96. OSTimeDly(tms);
  97. tms = hd_netledClose();
  98. OSTimeDly(tms);
  99. }
  100. }
  101. void bsp_Idle(void)
  102. {
  103. /* --- 喂狗 */
  104. /* --- 让CPU进入休眠,由Systick定时中断唤醒或者其他中断唤醒 */
  105. }
  106. /**
  107. * @brief 配置嵌套向量中断控制器NVIC分组
  108. * @param 无
  109. * @retval 无
  110. */
  111. void NVIC_Configuration(void)
  112. {
  113. // NVIC_InitTypeDef NVIC_InitStructure;
  114. /* 嵌套向量中断控制器组选择 */
  115. NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
  116. }
  117. #ifdef USE_FULL_ASSERT
  118. /**
  119. * @brief Reports the name of the source file and the source line number
  120. * where the assert_param error has occurred.
  121. * @param file: pointer to the source file name
  122. * @param line: assert_param error line source number
  123. * @retval None
  124. */
  125. void assert_failed(uint8_t* file, uint32_t line)
  126. {
  127. /* User can add his own implementation to report the file name and line number,
  128. ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  129. /* Infinite loop */
  130. while (1)
  131. {}
  132. }
  133. #endif