APM:Libraries
Classes | Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
ChibiOS::UARTDriver Class Reference

#include <UARTDriver.h>

Inheritance diagram for ChibiOS::UARTDriver:
[legend]
Collaboration diagram for ChibiOS::UARTDriver:
[legend]

Classes

struct  SerialDef
 

Public Member Functions

 UARTDriver (uint8_t serial_num)
 
void begin (uint32_t b)
 
void begin (uint32_t b, uint16_t rxS, uint16_t txS)
 
void end ()
 
void flush ()
 
bool is_initialized ()
 
void set_blocking_writes (bool blocking)
 
bool tx_pending ()
 
uint32_t available () override
 
uint32_t txspace () override
 
int16_t read () override
 
void _timer_tick (void) override
 
size_t write (uint8_t c)
 
size_t write (const uint8_t *buffer, size_t size)
 
bool lock_port (uint32_t key) override
 
size_t write_locked (const uint8_t *buffer, size_t size, uint32_t key) override
 
bool wait_timeout (uint16_t n, uint32_t timeout_ms) override
 
void set_flow_control (enum flow_control flow_control) override
 
enum flow_control get_flow_control (void) override
 
bool set_unbuffered_writes (bool on) override
 
void configure_parity (uint8_t v) override
 
void set_stop_bits (int n) override
 
uint64_t receive_time_constraint_us (uint16_t nbytes) override
 
- Public Member Functions inherited from AP_HAL::UARTDriver
 UARTDriver ()
 
virtual void set_flow_control (enum flow_control flow_control_setting)
 
- Public Member Functions inherited from AP_HAL::BetterStream
virtual void printf (const char *,...) FMT_PRINTF(2
 
virtual void virtual void vprintf (const char *, va_list)
 
void print (const char *str)
 
void println (const char *str)
 
size_t write (const char *str)
 

Private Member Functions

void dma_tx_allocate (Shared_DMA *ctx)
 
void dma_tx_deallocate (Shared_DMA *ctx)
 
void update_rts_line (void)
 
void check_dma_tx_completion (void)
 
void write_pending_bytes_DMA (uint32_t n)
 
void write_pending_bytes_NODMA (uint32_t n)
 
void write_pending_bytes (void)
 
void receive_timestamp_update (void)
 
void thread_init ()
 

Static Private Member Functions

static void rx_irq_cb (void *sd)
 
static void rxbuff_full_irq (void *self, uint32_t flags)
 
static void tx_complete (void *self, uint32_t flags)
 
static void uart_thread (void *)
 

Private Attributes

bool tx_bounce_buf_ready
 
const SerialDefsdef
 
uint8_t serial_num
 
uint32_t lock_key
 
uint32_t _baudrate
 
uint16_t tx_len
 
SerialConfig sercfg
 
const thread_t * _uart_owner_thd
 
struct {
   thread_t *   thread_ctx
 
   uint16_t   n
 
_wait
 
uint8_t rx_bounce_buf [RX_BOUNCE_BUFSIZE]
 
uint8_t tx_bounce_buf [TX_BOUNCE_BUFSIZE]
 
ByteBuffer _readbuf {0}
 
ByteBuffer _writebuf {0}
 
Semaphore _write_mutex
 
const stm32_dma_stream_t * rxdma
 
const stm32_dma_stream_t * txdma
 
bool _in_timer
 
bool _blocking_writes
 
bool _initialised
 
bool _device_initialised
 
bool _lock_rx_in_timer_tick = false
 
Shared_DMAdma_handle
 
uint64_t _receive_timestamp [2]
 
uint8_t _receive_timestamp_idx
 
enum flow_control _flow_control = FLOW_CONTROL_DISABLE
 
bool _rts_is_active
 
uint32_t _last_write_completed_us
 
uint32_t _first_write_started_us
 
bool unbuffered_writes
 

Static Private Attributes

static thread_t * uart_thread_ctx
 
static uint32_t last_thread_run_us
 
static UARTDriveruart_drivers [UART_MAX_DRIVERS]
 
static const SerialDef _serial_tab [] = { HAL_UART_DEVICE_LIST }
 

Additional Inherited Members

- Public Types inherited from AP_HAL::UARTDriver
enum  flow_control { FLOW_CONTROL_DISABLE =0, FLOW_CONTROL_ENABLE =1, FLOW_CONTROL_AUTO =2 }
 

Detailed Description

Definition at line 30 of file UARTDriver.h.

Constructor & Destructor Documentation

◆ UARTDriver()

UARTDriver::UARTDriver ( uint8_t  serial_num)

Definition at line 55 of file UARTDriver.cpp.

Member Function Documentation

◆ _timer_tick()

void UARTDriver::_timer_tick ( void  )
overridevirtual

Reimplemented from AP_HAL::UARTDriver.

Definition at line 727 of file UARTDriver.cpp.

Referenced by uart_thread().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ available()

uint32_t UARTDriver::available ( void  )
overridevirtual

Implements AP_HAL::BetterStream.

Definition at line 436 of file UARTDriver.cpp.

Referenced by receive_time_constraint_us(), and wait_timeout().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ begin() [1/2]

void UARTDriver::begin ( uint32_t  b)
virtual

Implements AP_HAL::UARTDriver.

Definition at line 387 of file UARTDriver.cpp.

◆ begin() [2/2]

void UARTDriver::begin ( uint32_t  baud,
uint16_t  rxSpace,
uint16_t  txSpace 
)
virtual

Extended port open method

Allows for both opening with specified buffer sizes, and re-opening to adjust a subset of the port's settings.

Note
Buffer sizes greater than ::_max_buffer_size will be rounded down.
Parameters
baudSelects the speed that the port will be configured to. If zero, the port speed is left unchanged.
rxSpaceSets the receive buffer size for the port. If zero then the buffer size is left unchanged if the port is open, or set to ::_default_rx_buffer_size if it is currently closed.
txSpaceSets the transmit buffer size for the port. If zero then the buffer size is left unchanged if the port is open, or set to ::_default_tx_buffer_size if it is currently closed.

Implements AP_HAL::UARTDriver.

Definition at line 128 of file UARTDriver.cpp.

Here is the call graph for this function:

◆ check_dma_tx_completion()

void UARTDriver::check_dma_tx_completion ( void  )
private

Definition at line 588 of file UARTDriver.cpp.

Referenced by write_pending_bytes(), and write_pending_bytes_DMA().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ configure_parity()

void UARTDriver::configure_parity ( uint8_t  v)
overridevirtual

Reimplemented from AP_HAL::UARTDriver.

Definition at line 902 of file UARTDriver.cpp.

Referenced by get_flow_control().

Here is the caller graph for this function:

◆ dma_tx_allocate()

void UARTDriver::dma_tx_allocate ( Shared_DMA ctx)
private

Definition at line 284 of file UARTDriver.cpp.

Referenced by begin().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dma_tx_deallocate()

void UARTDriver::dma_tx_deallocate ( Shared_DMA ctx)
private

Definition at line 304 of file UARTDriver.cpp.

Referenced by begin().

Here is the caller graph for this function:

◆ end()

void UARTDriver::end ( )
virtual

Implements AP_HAL::UARTDriver.

Definition at line 392 of file UARTDriver.cpp.

Here is the call graph for this function:

◆ flush()

void UARTDriver::flush ( void  )
virtual

Implements AP_HAL::UARTDriver.

Definition at line 411 of file UARTDriver.cpp.

◆ get_flow_control()

enum flow_control ChibiOS::UARTDriver::get_flow_control ( void  )
inlineoverridevirtual

Reimplemented from AP_HAL::UARTDriver.

Definition at line 76 of file UARTDriver.h.

Here is the call graph for this function:

◆ is_initialized()

bool UARTDriver::is_initialized ( )
virtual

Implements AP_HAL::UARTDriver.

Definition at line 423 of file UARTDriver.cpp.

◆ lock_port()

bool UARTDriver::lock_port ( uint32_t  key)
overridevirtual

Reimplemented from AP_HAL::UARTDriver.

Definition at line 540 of file UARTDriver.cpp.

◆ read()

int16_t UARTDriver::read ( void  )
overridevirtual

Implements AP_HAL::BetterStream.

Definition at line 459 of file UARTDriver.cpp.

Here is the call graph for this function:

◆ receive_time_constraint_us()

uint64_t UARTDriver::receive_time_constraint_us ( uint16_t  nbytes)
overridevirtual

Reimplemented from AP_HAL::UARTDriver.

Definition at line 991 of file UARTDriver.cpp.

Referenced by get_flow_control().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ receive_timestamp_update()

void UARTDriver::receive_timestamp_update ( void  )
private

Definition at line 972 of file UARTDriver.cpp.

Referenced by _timer_tick(), and rxbuff_full_irq().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rx_irq_cb()

void UARTDriver::rx_irq_cb ( void *  sd)
staticprivate

Definition at line 332 of file UARTDriver.cpp.

Referenced by begin().

Here is the caller graph for this function:

◆ rxbuff_full_irq()

void UARTDriver::rxbuff_full_irq ( void *  self,
uint32_t  flags 
)
staticprivate

Definition at line 354 of file UARTDriver.cpp.

Referenced by begin().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_blocking_writes()

void UARTDriver::set_blocking_writes ( bool  blocking)
virtual

Implements AP_HAL::UARTDriver.

Definition at line 428 of file UARTDriver.cpp.

◆ set_flow_control()

void ChibiOS::UARTDriver::set_flow_control ( enum flow_control  flow_control)
override

Referenced by _timer_tick(), begin(), ChibiOS::UARTDriver::SerialDef::get_index(), and write_pending_bytes().

Here is the caller graph for this function:

◆ set_stop_bits()

void UARTDriver::set_stop_bits ( int  n)
overridevirtual

Reimplemented from AP_HAL::UARTDriver.

Definition at line 943 of file UARTDriver.cpp.

Referenced by get_flow_control().

Here is the caller graph for this function:

◆ set_unbuffered_writes()

bool UARTDriver::set_unbuffered_writes ( bool  on)
overridevirtual

Reimplemented from AP_HAL::UARTDriver.

Definition at line 889 of file UARTDriver.cpp.

Referenced by get_flow_control().

Here is the caller graph for this function:

◆ thread_init()

void UARTDriver::thread_init ( void  )
private

Definition at line 100 of file UARTDriver.cpp.

Referenced by begin().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ tx_complete()

void UARTDriver::tx_complete ( void *  self,
uint32_t  flags 
)
staticprivate

Definition at line 315 of file UARTDriver.cpp.

Referenced by dma_tx_allocate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ tx_pending()

bool UARTDriver::tx_pending ( )
virtual

Implements AP_HAL::UARTDriver.

Definition at line 433 of file UARTDriver.cpp.

◆ txspace()

uint32_t UARTDriver::txspace ( void  )
overridevirtual

Implements AP_HAL::BetterStream.

Definition at line 451 of file UARTDriver.cpp.

Here is the call graph for this function:

◆ uart_thread()

void UARTDriver::uart_thread ( void *  arg)
staticprivate

Definition at line 73 of file UARTDriver.cpp.

Referenced by thread_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ update_rts_line()

void UARTDriver::update_rts_line ( void  )
private

Definition at line 871 of file UARTDriver.cpp.

Referenced by _timer_tick(), read(), and rxbuff_full_irq().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ wait_timeout()

bool UARTDriver::wait_timeout ( uint16_t  n,
uint32_t  timeout_ms 
)
overridevirtual

Reimplemented from AP_HAL::UARTDriver.

Definition at line 573 of file UARTDriver.cpp.

Referenced by ChibiOS::UARTDriver::SerialDef::get_index().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ write() [1/2]

size_t UARTDriver::write ( uint8_t  c)
virtual

Implements AP_HAL::BetterStream.

Definition at line 480 of file UARTDriver.cpp.

Referenced by write().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ write() [2/2]

size_t UARTDriver::write ( const uint8_t *  buffer,
size_t  size 
)
virtual

Reimplemented from AP_HAL::BetterStream.

Definition at line 506 of file UARTDriver.cpp.

Here is the call graph for this function:

◆ write_locked()

size_t UARTDriver::write_locked ( const uint8_t *  buffer,
size_t  size,
uint32_t  key 
)
overridevirtual

Reimplemented from AP_HAL::UARTDriver.

Definition at line 554 of file UARTDriver.cpp.

Here is the call graph for this function:

◆ write_pending_bytes()

void UARTDriver::write_pending_bytes ( void  )
private

Definition at line 687 of file UARTDriver.cpp.

Referenced by _timer_tick(), and write().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_pending_bytes_DMA()

void UARTDriver::write_pending_bytes_DMA ( uint32_t  n)
private

Definition at line 606 of file UARTDriver.cpp.

Referenced by write_pending_bytes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_pending_bytes_NODMA()

void UARTDriver::write_pending_bytes_NODMA ( uint32_t  n)
private

Definition at line 652 of file UARTDriver.cpp.

Referenced by write_pending_bytes().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ _baudrate

uint32_t ChibiOS::UARTDriver::_baudrate
private

Definition at line 118 of file UARTDriver.h.

Referenced by begin(), receive_time_constraint_us(), and write_pending_bytes_DMA().

◆ _blocking_writes

bool ChibiOS::UARTDriver::_blocking_writes
private

Definition at line 142 of file UARTDriver.h.

Referenced by set_blocking_writes(), and write().

◆ _device_initialised

bool ChibiOS::UARTDriver::_device_initialised
private

Definition at line 144 of file UARTDriver.h.

Referenced by begin().

◆ _first_write_started_us

uint32_t ChibiOS::UARTDriver::_first_write_started_us
private

Definition at line 157 of file UARTDriver.h.

Referenced by _timer_tick(), and write_pending_bytes().

◆ _flow_control

enum flow_control ChibiOS::UARTDriver::_flow_control = FLOW_CONTROL_DISABLE
private

◆ _in_timer

bool ChibiOS::UARTDriver::_in_timer
private

Definition at line 141 of file UARTDriver.h.

Referenced by _timer_tick(), begin(), and end().

◆ _initialised

bool ChibiOS::UARTDriver::_initialised
private

◆ _last_write_completed_us

uint32_t ChibiOS::UARTDriver::_last_write_completed_us
private

◆ _lock_rx_in_timer_tick

bool ChibiOS::UARTDriver::_lock_rx_in_timer_tick = false
private

Definition at line 145 of file UARTDriver.h.

Referenced by _timer_tick(), and rxbuff_full_irq().

◆ _readbuf

ByteBuffer ChibiOS::UARTDriver::_readbuf {0}
private

Definition at line 136 of file UARTDriver.h.

Referenced by _timer_tick(), available(), begin(), end(), read(), rxbuff_full_irq(), and update_rts_line().

◆ _receive_timestamp

uint64_t ChibiOS::UARTDriver::_receive_timestamp[2]
private

Definition at line 150 of file UARTDriver.h.

Referenced by receive_time_constraint_us(), and receive_timestamp_update().

◆ _receive_timestamp_idx

uint8_t ChibiOS::UARTDriver::_receive_timestamp_idx
private

Definition at line 151 of file UARTDriver.h.

Referenced by receive_time_constraint_us(), and receive_timestamp_update().

◆ _rts_is_active

bool ChibiOS::UARTDriver::_rts_is_active
private

Definition at line 155 of file UARTDriver.h.

Referenced by _timer_tick(), read(), rxbuff_full_irq(), and update_rts_line().

◆ _serial_tab

const UARTDriver::SerialDef UARTDriver::_serial_tab = { HAL_UART_DEVICE_LIST }
staticprivate

Definition at line 147 of file UARTDriver.h.

Referenced by ChibiOS::UARTDriver::SerialDef::get_index().

◆ _uart_owner_thd

const thread_t* ChibiOS::UARTDriver::_uart_owner_thd
private

Definition at line 123 of file UARTDriver.h.

Referenced by begin(), and read().

◆ _wait

struct { ... } ChibiOS::UARTDriver::_wait

◆ _write_mutex

Semaphore ChibiOS::UARTDriver::_write_mutex
private

Definition at line 138 of file UARTDriver.h.

Referenced by _timer_tick(), write(), and write_locked().

◆ _writebuf

ByteBuffer ChibiOS::UARTDriver::_writebuf {0}
private

◆ dma_handle

Shared_DMA* ChibiOS::UARTDriver::dma_handle
private

Definition at line 146 of file UARTDriver.h.

Referenced by begin(), check_dma_tx_completion(), tx_complete(), and write_pending_bytes_DMA().

◆ last_thread_run_us

uint32_t UARTDriver::last_thread_run_us
staticprivate

Definition at line 107 of file UARTDriver.h.

Referenced by uart_thread().

◆ lock_key

uint32_t ChibiOS::UARTDriver::lock_key
private

Definition at line 116 of file UARTDriver.h.

Referenced by lock_port(), write(), and write_locked().

◆ n

uint16_t ChibiOS::UARTDriver::n

◆ rx_bounce_buf

uint8_t ChibiOS::UARTDriver::rx_bounce_buf[RX_BOUNCE_BUFSIZE]
private

Definition at line 134 of file UARTDriver.h.

Referenced by _timer_tick(), begin(), and rxbuff_full_irq().

◆ rxdma

const stm32_dma_stream_t* ChibiOS::UARTDriver::rxdma
private

Definition at line 139 of file UARTDriver.h.

Referenced by _timer_tick(), begin(), rx_irq_cb(), and rxbuff_full_irq().

◆ sdef

const SerialDef& ChibiOS::UARTDriver::sdef
private

◆ sercfg

SerialConfig ChibiOS::UARTDriver::sercfg
private

Definition at line 121 of file UARTDriver.h.

Referenced by begin(), configure_parity(), and set_stop_bits().

◆ serial_num

uint8_t ChibiOS::UARTDriver::serial_num
private

Definition at line 113 of file UARTDriver.h.

Referenced by begin(), tx_complete(), and UARTDriver().

◆ thread_ctx

thread_t* ChibiOS::UARTDriver::thread_ctx

Definition at line 127 of file UARTDriver.h.

Referenced by rxbuff_full_irq().

◆ tx_bounce_buf

uint8_t ChibiOS::UARTDriver::tx_bounce_buf[TX_BOUNCE_BUFSIZE]
private

Definition at line 135 of file UARTDriver.h.

Referenced by write_pending_bytes_DMA().

◆ tx_bounce_buf_ready

bool ChibiOS::UARTDriver::tx_bounce_buf_ready
private

Definition at line 100 of file UARTDriver.h.

Referenced by check_dma_tx_completion(), tx_complete(), and write_pending_bytes_DMA().

◆ tx_len

uint16_t ChibiOS::UARTDriver::tx_len
private

Definition at line 119 of file UARTDriver.h.

Referenced by write_pending_bytes_DMA().

◆ txdma

const stm32_dma_stream_t* ChibiOS::UARTDriver::txdma
private

◆ uart_drivers

UARTDriver * UARTDriver::uart_drivers
staticprivate

Definition at line 110 of file UARTDriver.h.

Referenced by uart_thread(), and UARTDriver().

◆ uart_thread_ctx

thread_t * UARTDriver::uart_thread_ctx
staticprivate

Definition at line 104 of file UARTDriver.h.

Referenced by thread_init(), tx_complete(), and uart_thread().

◆ unbuffered_writes

bool ChibiOS::UARTDriver::unbuffered_writes
private

Definition at line 160 of file UARTDriver.h.

Referenced by _timer_tick(), set_unbuffered_writes(), tx_complete(), and write().


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