rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes
UartDmaTsChannel Class Referencefinal

#include <connector_uart_dma.h>

Inheritance diagram for UartDmaTsChannel:
Inheritance graph
[legend]
Collaboration diagram for UartDmaTsChannel:
Collaboration graph
[legend]

Public Member Functions

 UartDmaTsChannel (UARTDriver &uartDriver)
 
void start (uint32_t baud) override
 
size_t readTimeout (uint8_t *buffer, size_t size, int timeout) override
 
void copyDataFromDMA ()
 
- Public Member Functions inherited from UartTsChannel
 UartTsChannel (UARTDriver &driver)
 
void start (uint32_t baud) override
 
void stop () override
 
void write (const uint8_t *buffer, size_t size, bool isEndOfPacket) override
 
size_t readTimeout (uint8_t *buffer, size_t size, int timeout) override
 
- Public Member Functions inherited from SerialTsChannelBase
 SerialTsChannelBase (const char *p_name)
 
- Public Member Functions inherited from TsChannelBase
 TsChannelBase (const char *name)
 
virtual void flush ()
 
virtual bool isConfigured () const
 
virtual bool isReady () const
 
size_t read (uint8_t *buffer, size_t size)
 
virtual void writeCrcPacket (uint8_t responseCode, const uint8_t *buf, size_t size, bool allowLongPackets=false)
 
void sendResponse (ts_response_format_e mode, const uint8_t *buffer, int size, bool allowLongPackets=false)
 
void assertPacketSize (size_t size, bool allowLongPackets)
 
uint32_t writePacketHeader (const uint8_t responseCode, const size_t size)
 
void crcAndWriteBuffer (const uint8_t responseCode, const size_t size)
 
void copyAndWriteSmallCrcPacket (uint8_t responseCode, const uint8_t *buf, size_t size)
 
void writeCrcResponse (uint8_t responseCode)
 

Private Attributes

uint8_t dmaBuffer [TS_DMA_BUFFER_SIZE]
 
volatile int readPos
 
uint8_t buffer [TS_FIFO_BUFFER_SIZE]
 
input_queue_t fifoRxQueue
 

Additional Inherited Members

- Data Fields inherited from TsChannelBase
int bytesIn = 0
 
int bytesOut = 0
 
char scratchBuffer [scratchBuffer_SIZE+30]
 
page1_s page1
 
const charname
 
bool in_sync = false
 
- Protected Attributes inherited from UartTsChannel
UARTDriver *const m_driver
 
UARTConfig m_config
 

Detailed Description

Definition at line 19 of file connector_uart_dma.h.

Constructor & Destructor Documentation

◆ UartDmaTsChannel()

UartDmaTsChannel::UartDmaTsChannel ( UARTDriver uartDriver)

Definition at line 45 of file connector_uart_dma.cpp.

46 : UartTsChannel(driver)
47{
48 // Store a pointer to this instance so we can get it back later in the DMA callback
49 driver.dmaAdapterInstance = this;
50
51 iqObjectInit(&fifoRxQueue, buffer, sizeof(buffer), nullptr, nullptr);
52}
uint8_t buffer[TS_FIFO_BUFFER_SIZE]
input_queue_t fifoRxQueue

Member Function Documentation

◆ copyDataFromDMA()

void UartDmaTsChannel::copyDataFromDMA ( )

Definition at line 13 of file connector_uart_dma.cpp.

13 {
14 chSysLockFromISR();
15 // get 0-based DMA buffer position
16 int dmaPos = TS_DMA_BUFFER_SIZE - dmaStreamGetTransactionSize(m_driver->dmarx);
17 // if the position is wrapped (circular DMA-mode enabled)
18 if (dmaPos < readPos)
19 dmaPos += TS_DMA_BUFFER_SIZE;
20 // we need to update the current readPos
21 int newReadPos = readPos;
22 for (int i = newReadPos; i < dmaPos; ) {
23 if (iqPutI(&fifoRxQueue, dmaBuffer[newReadPos]) != Q_OK) {
24 break; // todo: ignore overflow?
25 }
26 // the read position should always stay inside the buffer range
27 newReadPos = (++i) & (TS_DMA_BUFFER_SIZE - 1);
28 }
29 readPos = newReadPos;
30 chSysUnlockFromISR();
31}
uint8_t dmaBuffer[TS_DMA_BUFFER_SIZE]
UARTDriver *const m_driver

◆ readTimeout()

size_t UartDmaTsChannel::readTimeout ( uint8_t *  buffer,
size_t  size,
int  timeout 
)
overridevirtual

Implements TsChannelBase.

Definition at line 76 of file connector_uart_dma.cpp.

76 {
77 // Instead of reading from the device, read from our custom RX queue
78 size_t transferred = iqReadTimeout(&fifoRxQueue, p_buffer, size, timeout);
79 bytesIn += transferred;
80 return transferred;
81}
composite packet size

◆ start()

void UartDmaTsChannel::start ( uint32_t  baud)
overridevirtual

Implements SerialTsChannelBase.

Definition at line 54 of file connector_uart_dma.cpp.

54 {
55 m_config = {
56 .txend1_cb = NULL,
57 .txend2_cb = NULL,
58 .rxend_cb = NULL,
59 .rxchar_cb = NULL,
60 .rxerr_cb = NULL,
61 .timeout_cb = tsRxIRQIdleHandler,
62 .speed = baud,
63 .cr1 = 0,
64 .cr2 = USART_CR2_STOP1_BITS | USART_CR2_LINEN,
65 .cr3 = 0,
66 .rxhalf_cb = tsRxIRQHalfHandler
67 };
68
69 uartStart(m_driver, &m_config);
70
71 // Start the buffered read process
72 readPos = 0;
73 uartStartReceive(m_driver, sizeof(dmaBuffer), dmaBuffer);
74}
UARTConfig m_config
static void tsRxIRQIdleHandler(UARTDriver *uartp)
static void tsRxIRQHalfHandler(UARTDriver *uartp, uartflags_t full)
uartcb_t txend1_cb
End of transmission buffer callback.
Here is the call graph for this function:

Field Documentation

◆ buffer

uint8_t UartDmaTsChannel::buffer[TS_FIFO_BUFFER_SIZE]
private

Definition at line 37 of file connector_uart_dma.h.

Referenced by UartDmaTsChannel().

◆ dmaBuffer

uint8_t UartDmaTsChannel::dmaBuffer[TS_DMA_BUFFER_SIZE]
private

Definition at line 33 of file connector_uart_dma.h.

Referenced by copyDataFromDMA(), and start().

◆ fifoRxQueue

input_queue_t UartDmaTsChannel::fifoRxQueue
private

Definition at line 39 of file connector_uart_dma.h.

Referenced by copyDataFromDMA(), readTimeout(), and UartDmaTsChannel().

◆ readPos

volatile int UartDmaTsChannel::readPos
private

Definition at line 35 of file connector_uart_dma.h.

Referenced by copyDataFromDMA(), and start().


The documentation for this class was generated from the following files: