14 #include <hal_samv71/interrupt_handler.h>
29 #ifndef SATCAT5_SAMV71_UART_BUFFSIZE
30 #define SATCAT5_SAMV71_UART_BUFFSIZE 1600
35 #ifndef SATCAT5_SAMV71_UART_DCACHE
36 #define SATCAT5_SAMV71_UART_DCACHE 0
116 Usart* usart,
unsigned baud_hz,
unsigned poll_ms,
117 u8* txbuff,
unsigned txbytes, u8* rxbuff,
unsigned rxbytes,
118 u8* rxdma0, u8* rxdma1,
unsigned rxdmabytes,
123 void configure(
unsigned baud_hz,
bool rts_en,
bool cts_en);
126 inline void configure(
unsigned baud_hz,
bool fc_on=
false)
147 {
return m_rxdma_buffidx == 0 ? m_rxdma0 : m_rxdma1; }
167 unsigned m_txdma_nbytes;
170 const unsigned m_rxdma_nbytes;
171 unsigned m_rxdma_buffidx;
186 template <
unsigned SIZE = SATCAT5_SAMV71_UART_BUFFSIZE>
198 Usart* usart,
unsigned baud_hz,
199 unsigned poll_ms,
bool fc_on=
false)
201 m_txbuff, SIZE, m_rxbuff, SIZE,
202 m_rxdma0, m_rxdma1, SIZE, fc_on) {}
219 unsigned TASK_PRIORITY,
220 unsigned SIZE = SATCAT5_SAMV71_UART_BUFFSIZE,
221 configSTACK_DEPTH_TYPE TASK_SIZE = 1024>
222 class UsartSamv71Preempt
224 ,
public UsartSamv71Static<SIZE> {
232 Usart* usart,
unsigned baud_hz,
unsigned poll_ms,
233 bool poll_always=
false,
bool fc_on=
false)
234 : satcat5::freertos::StaticTask<TASK_SIZE, TASK_PRIORITY>(
235 "UsartSamv71Preempt", task, this)
236 , UsartSamv71Static<SIZE>(usart, baud_hz, 0, fc_on)
237 , m_poll_ms(satcat5::util::max_unsigned(1, poll_ms))
240 if (!poll_always) { this->poll_unregister(); }
245 static void task(
void* pvParams) {
246 UsartSamv71Preempt* arg = (UsartSamv71Preempt*) pvParams;
247 const TickType_t poll_rate = pdMS_TO_TICKS(arg->m_poll_ms);
248 TickType_t last_wake_time = xTaskGetTickCount();
250 vTaskDelayUntil(&last_wake_time, poll_rate);
258 const unsigned m_poll_ms;
Instantiate a FreeRTOS statically-allocated Task.
Extensible transmit and receive buffer.
Abstract API for reading byte-streams and packets.
An "Always" object is polled whenever service() is called.
Timer objects are polled after a fixed delay or at a regular interval.
Interrupt handler interface for the Microchip SAM V71.
io::BufferedIO interface for the SAMV71 USART and UART peripherals.
void rts_low()
Drive the RTS signal high/low if flow-control is on.
void rts_high()
Drive the RTS signal high/low if flow-control is on.
void configure(unsigned baud_hz, bool fc_on=false)
Alias for backwards compatibility (deprecated).
void configure(unsigned baud_hz, bool rts_en, bool cts_en)
Set baud rate and RTS/CTS enable.
void timer_event() override
The user may configure either continuous polling or timer-based polling; either should perform the sa...
void configure_xdmac(u32 tx_dma_ch, u32 rx_dma_ch)
Initial setup of the TX/RX DMA controllers.
void poll_tx_dma()
Poll the RX DMA engine for new data received.
void poll_rx_dma()
Poll the TX DMA engine for unsent data to transmit.
u8 * get_rxdma_buff()
Get the RX buffer the DMA is currently writing to.
void irq_event() override
IRQ indicates the RX DMA is full or the TX DMA is empty.
void data_rcvd(satcat5::io::Readable *src) override
Immediately transfer incoming TX data to the DMA engine.
void poll_always() override
The user may configure either continuous polling or timer-based polling; either should perform the sa...
UsartSamv71(Usart *usart, unsigned baud_hz, unsigned poll_ms, u8 *txbuff, unsigned txbytes, u8 *rxbuff, unsigned rxbytes, u8 *rxdma0, u8 *rxdma1, unsigned rxdmabytes, bool fc_on=false)
Constructor for an ASF3 USART with user-provided buffers.
UsartSamv71 variant with statically-allocated TX and RX buffers; most users should instantiate this i...
UsartSamv71Static(Usart *usart, unsigned baud_hz, unsigned poll_ms, bool fc_on=false)
Constructor for an ASF3 USART with built-in buffers.
Buffered I/O wrappers for PacketBuffer.
Core event-processing loop for SatCat5 software.
Provides a FreeRTOS task function and hooks for using SatCat5 as a task inside a larger FreeRTOS proj...
Miscellaneous mathematical utility functions.