uart_tasks.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. #define UART_RX_BUFF_SIZE 256
  16. #define UART_TX_BUFF_SIZE 256
  17. #define UART1_RX_BUFF_SIZE UART_RX_BUFF_SIZE
  18. #define UART1_TX_BUFF_SIZE UART_TX_BUFF_SIZE
  19. #define UART8_RX_BUFF_SIZE UART_RX_BUFF_SIZE
  20. #define UART8_TX_BUFF_SIZE UART_TX_BUFF_SIZE
  21. #define INPUT_DATA_BUFF_SIZE UART8_RX_BUFF_SIZE
  22. #define OUTPUT_DATA_BUFF_SIZE 128
  23. struct _SerialProtocolFrameHeader {
  24. uint16_t frameId;
  25. SerialProtocolCommands frameCommand;
  26. SerialProtocolRespStatus respStatus;
  27. uint16_t frameDataLength;
  28. portBASE_TYPE isResponseFrame;
  29. };
  30. typedef struct _SerialProtocolFrameHeader SerialProtocolFrameHeader;
  31. struct _SerialProtocolFrameData {
  32. SerialProtocolFrameHeader frameHeader;
  33. uint8_t dataBuffer[INPUT_DATA_BUFF_SIZE];
  34. };
  35. typedef struct _SerialProtocolFrameData SerialProtocolFrameData;
  36. typedef void (*ProcessDataCallbackFunc) (void* arg, SerialProtocolFrameData* spFrameData);
  37. struct _UartTaskData {
  38. uint8_t* uartRxBuffer;
  39. uint16_t uartRxBufferLen;
  40. uint16_t uartRxBufferPos;
  41. uint8_t* uartTxBuffer;
  42. uint16_t uartTxBufferLen;
  43. uint8_t* frameData;
  44. uint16_t frameDataLen;
  45. uint16_t frameBytesCount;
  46. osThreadId_t uartRecieveTaskHandle;
  47. osThreadId_t uartTransmitTaskHandle;
  48. osMutexId_t rxDataBufferMutex;
  49. #if 0
  50. osMessageQueueId_t processDataQueue;
  51. #endif
  52. MessageBufferHandle_t processRxDataMsgBuffer;
  53. ProcessDataCallbackFunc processDataCb;
  54. osMessageQueueId_t *sendCmdToSlaveQueue;
  55. UART_HandleTypeDef* huart;
  56. uint8_t uartNumber;
  57. };
  58. typedef struct _UartTaskData UartTaskData;
  59. //void Uart8TasksInit (void);
  60. void UartTasksInit(void);
  61. void UartTaskCreate (UartTaskData* uartTaskData);
  62. void Uart1ReceivedDataProcessCallback (void* arg, SerialProtocolFrameData* spFrameData);
  63. void Uart8ReceivedDataProcessCallback (void* arg, SerialProtocolFrameData* spFrameData);
  64. void UartRxTask (void* argument);
  65. void UartTxTask (void* argument);
  66. void HandleUartRxCallback (UartTaskData* uartTaskData, UART_HandleTypeDef* huart, uint16_t Size);
  67. #endif /* INC_UART_TASKS_H_ */