uart_tasks.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * uart_tasks.h
  3. *
  4. * Created on: Aug 14, 2024
  5. * Author: jakubski
  6. */
  7. #ifndef INC_UART_TASKS_H_
  8. #define INC_UART_TASKS_H_
  9. #include "FreeRTOS.h"
  10. #include "FreeRTOSConfig.h"
  11. #include "task.h"
  12. #include "message_buffer.h"
  13. #include "main.h"
  14. #include "serial_protocol.h"
  15. #include "measurements.h"
  16. #define UART_RX_BUFF_SIZE 256
  17. #define UART_TX_BUFF_SIZE 256
  18. #define UART1_RX_BUFF_SIZE UART_RX_BUFF_SIZE
  19. #define UART1_TX_BUFF_SIZE UART_TX_BUFF_SIZE
  20. #define UART2_RX_BUFF_SIZE UART_RX_BUFF_SIZE
  21. #define UART2_TX_BUFF_SIZE UART_TX_BUFF_SIZE
  22. #define UART3_RX_BUFF_SIZE UART_RX_BUFF_SIZE
  23. #define UART3_TX_BUFF_SIZE UART_TX_BUFF_SIZE
  24. #define UART6_RX_BUFF_SIZE UART_RX_BUFF_SIZE
  25. #define UART6_TX_BUFF_SIZE UART_TX_BUFF_SIZE
  26. #define UART8_RX_BUFF_SIZE UART_RX_BUFF_SIZE
  27. #define UART8_TX_BUFF_SIZE UART_TX_BUFF_SIZE
  28. #define INPUT_DATA_BUFF_SIZE UART8_RX_BUFF_SIZE
  29. #define OUTPUT_DATA_BUFF_SIZE 128
  30. struct _SerialProtocolFrameHeader {
  31. uint16_t frameId;
  32. SerialProtocolCommands frameCommand;
  33. SerialProtocolRespStatus respStatus;
  34. uint16_t frameDataLength;
  35. portBASE_TYPE isResponseFrame;
  36. };
  37. typedef struct _SerialProtocolFrameHeader SerialProtocolFrameHeader;
  38. struct _SerialProtocolFrameData {
  39. SerialProtocolFrameHeader frameHeader;
  40. uint8_t dataBuffer[INPUT_DATA_BUFF_SIZE];
  41. };
  42. typedef struct _SerialProtocolFrameData SerialProtocolFrameData;
  43. typedef void (*ProcessDataCallbackFunc) (void* arg, SerialProtocolFrameData* spFrameData);
  44. struct _UartTaskData {
  45. uint8_t* uartRxBuffer;
  46. uint16_t uartRxBufferLen;
  47. uint16_t uartRxBufferPos;
  48. uint8_t* uartTxBuffer;
  49. uint16_t uartTxBufferLen;
  50. uint8_t* frameData;
  51. uint16_t frameDataLen;
  52. uint16_t frameBytesCount;
  53. osThreadId_t uartRecieveTaskHandle;
  54. osThreadId_t uartTransmitTaskHandle;
  55. osMutexId_t rxDataBufferMutex;
  56. MessageBufferHandle_t processRxDataMsgBuffer;
  57. ProcessDataCallbackFunc processDataCb;
  58. osMessageQueueId_t *sendCmdToSlaveQueue;
  59. UART_HandleTypeDef* huart;
  60. uint8_t uartNumber;
  61. };
  62. typedef struct _UartTaskData UartTaskData;
  63. extern RESMeasurements resMeasurements[SLAVES_COUNT];
  64. extern SesnorsInfo sensorsInfo[SLAVES_COUNT];
  65. extern uint32_t slaveLastSeen[SLAVES_COUNT];
  66. extern osMutexId_t resMeasurementsMutex;
  67. extern osMutexId_t sensorsInfoMutex;
  68. extern UartTaskData uart1TaskData; // Board 1
  69. extern UartTaskData uart3TaskData; // Board 2
  70. extern UartTaskData uart6TaskData; // Board 3
  71. extern UartTaskData uart2TaskData; // Board 4
  72. extern UartTaskData uart8TaskData; // Debug
  73. void UartTasksInit(void);
  74. void UartTaskCreate (UartTaskData* uartTaskData);
  75. void UartRxTask (void* argument);
  76. void UartTxTask (void* argument);
  77. void HandleUartRxCallback (UartTaskData* uartTaskData, UART_HandleTypeDef* huart, uint16_t Size);
  78. void MeasurmentsReqSchedulerTaskInit(void);
  79. void MeasurmentsReqSchedulerTask(void* argument);
  80. #endif /* INC_UART_TASKS_H_ */