init.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #include <rtthread.h>
  2. #include "flash.h"
  3. #include "ad.h"
  4. #include "buffer.h"
  5. #include "usart.h"
  6. #include "plan.h"
  7. #include "weight.h"
  8. #include "display.h"
  9. rt_sem_t thread_init_sem = RT_NULL;
  10. void init_usart(void)
  11. {
  12. __HAL_UART_ENABLE_IT(&huart1, UART_IT_IDLE); //使能IDLE中断
  13. HAL_UART_Receive_DMA(&huart1, rx_buffer1, BUFFER_SIZE);
  14. __HAL_UART_ENABLE_IT(&huart2, UART_IT_IDLE); //使能IDLE中断
  15. HAL_UART_Receive_DMA(&huart2, rx_buffer2, BUFFER_SIZE);
  16. __HAL_UART_ENABLE_IT(&huart3, UART_IT_IDLE); //使能IDLE中断
  17. HAL_UART_Receive_DMA(&huart3, rx_buffer3, BUFFER_SIZE);
  18. __HAL_UART_ENABLE_IT(&huart4, UART_IT_IDLE); //使能IDLE中断
  19. HAL_UART_Receive_DMA(&huart4, rx_buffer4, BUFFER_SIZE);
  20. }
  21. static void init_entry(void *parameter)
  22. {
  23. RB_init();
  24. init_usart();
  25. //if (WeightConst_TQ==14)
  26. ArgRead();
  27. rt_sem_release(thread_init_sem);
  28. }
  29. #define THREAD_PRIORITY 3
  30. #define THREAD_STACK_SIZE 800
  31. #define THREAD_TIMESLICE 5
  32. static rt_thread_t tid1 = RT_NULL;
  33. void thread_init(void)
  34. {
  35. thread_init_sem = rt_sem_create("thread_init_sem", 0, RT_IPC_FLAG_FIFO);
  36. pop_product_sem = rt_sem_create("pop_product_sem", 0, RT_IPC_FLAG_FIFO);
  37. delay_key_sem = rt_sem_create("delay_key_sem", 0, RT_IPC_FLAG_FIFO);
  38. weight_lock = rt_sem_create("weight_lock", 1, RT_IPC_FLAG_FIFO);
  39. displayRemote_lock = rt_sem_create("displayRemote_lock", 1, RT_IPC_FLAG_FIFO);
  40. sendLora_lock = rt_sem_create("sendLora_lock", 1, RT_IPC_FLAG_FIFO);
  41. display_lock = rt_sem_create("display_lock", 1, RT_IPC_FLAG_FIFO);
  42. rt_event_init(&display_event, "display_event", RT_IPC_FLAG_FIFO);
  43. uart1_lock = rt_sem_create("uart1_lock", 1, RT_IPC_FLAG_FIFO);
  44. uart2_lock = rt_sem_create("uart2_lock", 1, RT_IPC_FLAG_FIFO);
  45. uart3_lock = rt_sem_create("uart3_lock", 1, RT_IPC_FLAG_FIFO);
  46. uart4_lock = rt_sem_create("uart4_lock", 1, RT_IPC_FLAG_FIFO);
  47. uart5_lock = rt_sem_create("uart5_lock", 1, RT_IPC_FLAG_FIFO);
  48. setTIME_lock = rt_sem_create("setTIME_lock", 1, RT_IPC_FLAG_FIFO);
  49. thread_EmptyBuffer_sem = rt_sem_create("thread_EmptyBuffer_sem", 0, RT_IPC_FLAG_FIFO);
  50. tid1 = rt_thread_create("init_entry",
  51. init_entry, RT_NULL,
  52. THREAD_STACK_SIZE,
  53. THREAD_PRIORITY, THREAD_TIMESLICE);
  54. /* 如果获得线程控制块,启动这个线程 */
  55. if (tid1 != RT_NULL)
  56. rt_thread_startup(tid1);
  57. }