| |
| |
| |
| |
| |
| |
|
|
| #ifndef FASTUART_H_ |
| #define FASTUART_H_ |
|
|
| #include <stdint.h> |
| #include <stdio.h> |
| #include "FreeRTOS.h" |
| #include "queue.h" |
| extern "C" { |
| #include "cmd_buffer.h" |
| } |
|
|
| typedef struct _fastuart_t |
| { |
| uint8_t data; |
| uint8_t flags; |
| uint8_t ictrl; |
| uint8_t flowctrl; |
| uint8_t rate_l; |
| uint8_t rate_h; |
| uint8_t rx_count; |
| uint8_t tx_count; |
| } fastuart_t; |
|
|
| typedef struct |
| { |
| int size; |
| bool error; |
| } slipElement_t; |
|
|
| typedef struct |
| { |
| int rxHead; |
| int rxTail; |
| uint8_t *rxBuffer; |
| } rxBuffer_t; |
|
|
| #define RX_BUFFER_SIZE 16384 |
|
|
| class FastUART |
| { |
| volatile fastuart_t *uart; |
| void *rxSemaphore; |
| bool slipMode; |
| rxBuffer_t stdRx; |
|
|
| |
| command_buf_context_t *packets; |
| command_buf_t *current_tx_buf; |
| command_buf_t *current_rx_buf; |
| int current_tx_pnt; |
|
|
| BaseType_t RxInterrupt(); |
| int ReadImpl(rxBuffer_t *b, uint8_t *buffer, int bufferSize); |
| public: |
| bool txDebug; |
|
|
| FastUART(void *registers, void *sem, command_buf_context_t *pkts) |
| { |
| uart = (volatile fastuart_t *) registers; |
| packets = pkts; |
| rxSemaphore = sem; |
| stdRx.rxHead = 0; |
| stdRx.rxTail = 0; |
| stdRx.rxBuffer = new uint8_t[RX_BUFFER_SIZE]; |
| current_tx_buf = NULL; |
| current_rx_buf = NULL; |
| current_tx_pnt = 0; |
| slipMode = false; |
| txDebug = false; |
| uint16_t rate = (((uint16_t)uart->rate_h) << 8) | uart->rate_l; |
|
|
| printf("FastUART initialized. Start rate: %d bps\n", CLOCK_FREQ / (rate + 1)); |
| } |
|
|
| void EnableSlip(bool enabled) { slipMode = enabled; } |
| void EnableLoopback(bool enable); |
| void FlowControl(bool enable); |
| void EnableIRQ(bool); |
| void ClearRxBuffer(void); |
| void PrintRxMessage(void); |
| void SetBaudRate(int bps); |
| static void FastUartInterrupt(void *context); |
|
|
| |
| int Read(uint8_t *buffer, int bufferSize); |
|
|
| int GetRxCount(); |
| BaseType_t SendSlipPacket(const uint8_t *buffer, int length); |
| BaseType_t TransmitPacket(command_buf_t *buf, uint16_t *ms = NULL); |
| BaseType_t ReceivePacket(command_buf_t **buf, TickType_t ticks); |
| BaseType_t FreeBuffer(command_buf_t *buf); |
| BaseType_t GetBuffer(command_buf_t **buf, TickType_t ticks); |
| }; |
|
|
| BaseType_t u64_buffer_received_isr(command_buf_context_t *context, command_buf_t *b, BaseType_t *w); |
|
|
| #endif |
|
|