36#ifndef _FREERTOS_DRIVERS_PIC32MX_PIC32MXUART_HXX_
37#define _FREERTOS_DRIVERS_PIC32MX_PIC32MXUART_HXX_
40#include "peripheral/uart.h"
44 extern const unsigned long pic32_periph_clock_hz;
51 unsigned baud = 115200,
bool enable_rts_cts =
false)
56 unsigned rtscfg = UART_ENABLE_PINS_TX_RX_ONLY;
59 rtscfg = UART_ENABLE_PINS_CTS_RTS | UART_RTS_WHEN_RX_NOT_FULL;
62 hw_, (UART_CONFIGURATION)(UART_ENABLE_HIGH_SPEED | rtscfg));
64 (UART_FIFO_MODE)(UART_INTERRUPT_ON_TX_NOT_FULL |
65 UART_INTERRUPT_ON_RX_NOT_EMPTY));
66 UARTSetLineControl(
hw_,
67 (UART_LINE_CONTROL_MODE)(
68 UART_DATA_SIZE_8_BITS | UART_PARITY_NONE | UART_STOP_BITS_1));
69 UARTSetDataRate(
hw_, get_pclk(), baud);
71 INTSetVectorPriority(int_vector(), INT_PRIORITY_LEVEL_3);
72 INTSetVectorSubPriority(int_vector(), INT_SUB_PRIORITY_LEVEL_0);
79 UART_ENABLE_FLAGS(UART_PERIPHERAL | UART_RX | UART_TX)));
82 INTEnable(rx_int(), INT_ENABLED);
89 UARTEnable(
hw_, (UART_ENABLE_MODE)(UART_DISABLE_FLAGS(UART_RX)));
90 INTEnable(rx_int(), INT_DISABLED);
93 inline void interrupt_handler()
95 if (INTGetFlag(rx_int()))
102 INTClearFlag(rx_int());
104 if (INTGetFlag(tx_int()) && INTGetEnable(tx_int()))
111 INTClearFlag(tx_int());
132 while (UARTReceivedDataIsAvailable(
hw_))
134 auto d = UARTGetDataByte(
hw_);
156 INTEnable(tx_int(), INT_DISABLED);
159 if (!UARTTransmitterIsReady(
hw_))
162 INTEnable(tx_int(), INT_ENABLED);
167 UARTSendDataByte(
hw_, d);
172 inline unsigned get_pclk()
174 return pic32_periph_clock_hz;
177 inline INT_SOURCE tx_int()
179 return (INT_SOURCE)INT_SOURCE_UART_TX(
hw_);
182 inline INT_SOURCE rx_int()
184 return (INT_SOURCE)INT_SOURCE_UART_RX(
hw_);
187 inline INT_VECTOR int_vector()
189 return (INT_VECTOR)(INT_VECTOR_UART(
hw_));
void signal_condition()
Signal the wakeup condition.
size_t pending()
Return the number of items in the queue.
void signal_condition_from_isr()
Signal the wakeup condition from an ISR context.
size_t get(T *buf, size_t items)
remove a number of items from the buffer.
size_t put(const T *buf, size_t items)
Insert a number of items to the buffer.
const char * name
device name
void disable() override
This will be called when reference count goes from non-zero to 0.
bool send_some_data()
Copies data from the tx buffer to the hardware send register / fifo.
unsigned numIrq_
Stats variable.
unsigned numIrqTx_
Stats variable.
unsigned intVector_
This is the hardware vector number for the UART module.
bool receive_some_data()
Copies data from the RX fifo into the receive ring buffer.
void enable() override
This will be called once when reference-count goes from 0 to positive.
unsigned numIrqRx_
Stats variable.
void tx_char() override
Function to try and transmit a character.
UART_MODULE hw_
Enum describing which uart module we are using.
Private data for a serial device.
DeviceBuffer< uint8_t > * rxBuf
receive buffer
DeviceBuffer< uint8_t > * txBuf
transmit buffer
unsigned int overrunCount
overrun count