main.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #include "sys.h"
  2. #include "delay.h"
  3. #include "usart.h"
  4. #include "led.h"
  5. #include "relay.h"
  6. #include "pwm.h"
  7. #include <SIM_EEPROM.h>
  8. #include "All_define.h"
  9. #include "modbus.h"
  10. #include "lcd_task.h"
  11. #include "led_task.h"
  12. #include "zigbee_task.h"
  13. #include "key_task.h"
  14. #include "MB_RTU_task.h"
  15. #include "MB_RTU_deal_task.h"
  16. #include "relay_task.h"
  17. #include "uart.h"
  18. #include "./mcu_sdk/zigbee.h"
  19. #include "HT16C22.h"
  20. #define START_TASK_PRIO 1
  21. #define START_STK_SIZE 128
  22. TaskHandle_t StartTask_Handler;
  23. void start_task(void *pvParameters);
  24. #define LED_TASK_PRIO 3
  25. #define LED_STK_SIZE 256
  26. TaskHandle_t LEDTask_Handler;
  27. #define LCD_TASK_PRIO 4
  28. #define LCD_STK_SIZE 512
  29. TaskHandle_t LCDTask_Handler;
  30. #define ZIGBEE_TASK_PRIO 2
  31. #define ZIGBEE_STK_SIZE 512
  32. TaskHandle_t ZIGBEETask_Handler;
  33. #define KEY_TASK_PRIO 5
  34. #define KEY_STK_SIZE 512
  35. TaskHandle_t KEYTask_Handler;
  36. #define MB_RTU_TASK_PRIO 16
  37. #define MB_RTU_STK_SIZE 512
  38. TaskHandle_t MB_RTUTask_Handler;
  39. #define MB_RTU_deal_TASK_PRIO 8
  40. #define MB_RTU_deal_STK_SIZE 512
  41. TaskHandle_t MB_RTU_dealTask_Handler;
  42. #define Relay_TASK_PRIO 18
  43. #define Relay_STK_SIZE 512
  44. TaskHandle_t RELAYTask_Handler;
  45. void BSP_init(void )
  46. {
  47. gpio_uart_config();
  48. usart_config();
  49. MemData_init();
  50. delay_init();
  51. BSP_PWMOUT_Init();
  52. BSP_modbus(dis_page_param.face_plate_param.Device_BaudRate);
  53. Relay_Init();
  54. zigbee_protocol_init();
  55. //zigbee_uart_write_frame(NULL,0);
  56. }
  57. int main(void)
  58. {
  59. nvic_priority_group_set(NVIC_PRIGROUP_PRE4_SUB0);
  60. BSP_init();
  61. xTaskCreate((TaskFunction_t )start_task,
  62. (const char* )"start_task",
  63. (uint16_t )START_STK_SIZE,
  64. (void* )NULL,
  65. (UBaseType_t )START_TASK_PRIO,
  66. (TaskHandle_t* )&StartTask_Handler);
  67. vTaskStartScheduler();
  68. }
  69. QueueHandle_t MB_RTU_Rx_Queue;
  70. QueueHandle_t MB_RTU_Tx_Queue;
  71. SemaphoreHandle_t modebus_tx_semap;
  72. void start_task(void *pvParameters)
  73. {
  74. taskENTER_CRITICAL();
  75. MB_RTU_Rx_Queue=xQueueCreate(7,140);
  76. MB_RTU_Tx_Queue=xQueueCreate(7,140);
  77. modebus_tx_semap=xSemaphoreCreateBinary();
  78. xTaskCreate((TaskFunction_t )zigbee_task,
  79. (const char* )"zigbee_task",
  80. (uint16_t )ZIGBEE_STK_SIZE,
  81. (void* )NULL,
  82. (UBaseType_t )ZIGBEE_TASK_PRIO,
  83. (TaskHandle_t* )&ZIGBEETask_Handler);
  84. xTaskCreate((TaskFunction_t )led_task,
  85. (const char* )"led_task",
  86. (uint16_t )LED_STK_SIZE,
  87. (void* )NULL,
  88. (UBaseType_t )LED_TASK_PRIO,
  89. (TaskHandle_t* )&LEDTask_Handler);
  90. xTaskCreate((TaskFunction_t )lcd_task,
  91. (const char* )"lcd_task",
  92. (uint16_t )LCD_STK_SIZE,
  93. (void* )NULL,
  94. (UBaseType_t )LCD_TASK_PRIO,
  95. (TaskHandle_t* )&LCDTask_Handler);
  96. xTaskCreate((TaskFunction_t )key_task,
  97. (const char* )"key_task",
  98. (uint16_t )KEY_STK_SIZE,
  99. (void* )NULL,
  100. (UBaseType_t )KEY_TASK_PRIO,
  101. (TaskHandle_t* )&KEYTask_Handler);
  102. xTaskCreate((TaskFunction_t )mb_rtu_task,
  103. (const char* )"mb_rtu_task",
  104. (uint16_t )MB_RTU_STK_SIZE,
  105. (void* )NULL,
  106. (UBaseType_t )MB_RTU_TASK_PRIO,
  107. (TaskHandle_t* )&MB_RTUTask_Handler);
  108. xTaskCreate((TaskFunction_t )mb_rtu_deal_task,
  109. (const char* )"mb_rtu_deal_task",
  110. (uint16_t )MB_RTU_deal_STK_SIZE,
  111. (void* )NULL,
  112. (UBaseType_t )MB_RTU_deal_TASK_PRIO,
  113. (TaskHandle_t* )&MB_RTU_dealTask_Handler);
  114. xTaskCreate((TaskFunction_t )relay_task,
  115. (const char* )"mb_rtu_deal_task",
  116. (uint16_t )Relay_TASK_PRIO,
  117. (void* )NULL,
  118. (UBaseType_t )Relay_STK_SIZE,
  119. (TaskHandle_t* )&RELAYTask_Handler);
  120. vTaskDelete(StartTask_Handler);
  121. taskEXIT_CRITICAL();
  122. }