ChibiOS/HAL 9.0.0
Serial Driver

Generic Serial Driver. More...

Detailed Description

Generic Serial Driver.

This module implements a generic full duplex serial driver. The driver implements a SerialDriver interface and uses I/O Queues for communication between the upper and the lower driver. Event flags are used to notify the application about incoming data, outgoing data and other I/O events.
The module also contains functions that make the implementation of the interrupt service routines much easier.

Precondition
In order to use the SERIAL driver the HAL_USE_SERIAL option must be enabled in halconf.h.

Driver State Machine

The driver implements a state machine internally, not all the driver functionalities can be used in any moment, any transition not explicitly shown in the following diagram has to be considered an error and shall be captured by an assertion (if enabled).

dot_inline_dotgraph_10.png
Collaboration diagram for Serial Driver:

Serial status flags (legacy)

#define SD_PARITY_ERROR   CHN_PARITY_ERROR
#define SD_FRAMING_ERROR   CHN_FRAMING_ERROR
#define SD_OVERRUN_ERROR   CHN_OVERRUN_ERROR
#define SD_NOISE_ERROR   CHN_NOISE_ERROR
#define SD_BREAK_DETECTED   CHN_BREAK_DETECTED
#define SD_QUEUE_FULL_ERROR   CHN_BUFFER_FULL_ERROR

Serial configuration options

#define SERIAL_DEFAULT_BITRATE   38400
 Default bit rate.
#define SERIAL_BUFFERS_SIZE   16
 Serial buffers size.

Macro Functions

#define sdPutI(sdp, b)
 Direct write to a SerialDriver.
#define sdPut(sdp, b)
 Direct write to a SerialDriver.
#define sdPutTimeout(sdp, b, t)
 Direct write to a SerialDriver with timeout specification.
#define sdGetI(sdp)
 Direct read from a SerialDriver.
#define sdGet(sdp)
 Direct read from a SerialDriver.
#define sdGetTimeout(sdp, t)
 Direct read from a SerialDriver with timeout specification.
#define sdWriteI(sdp, b, n)
 Direct non-blocking write to a SerialDriver.
#define sdWrite(sdp, b, n)
 Direct blocking write to a SerialDriver.
#define sdWriteTimeout(sdp, b, n, t)
 Direct blocking write to a SerialDriver with timeout specification.
#define sdAsynchronousWrite(sdp, b, n)
 Direct non-blocking write to a SerialDriver.
#define sdReadI(sdp, b, n)
 Direct non-blocking read from a SerialDriver.
#define sdRead(sdp, b, n)
 Direct blocking read from a SerialDriver.
#define sdReadTimeout(sdp, b, n, t)
 Direct blocking read from a SerialDriver with timeout specification.
#define sdAsynchronousRead(sdp, b, n)
 Direct non-blocking read from a SerialDriver.

PLATFORM configuration options

#define PLATFORM_SERIAL_USE_USART1   FALSE
 USART1 driver enable switch.

Data Structures

struct  SerialDriverVMT
 SerialDriver virtual methods table. More...
struct  hal_serial_driver
 Full duplex serial driver class. More...
struct  hal_serial_config
 PLATFORM Serial Driver configuration structure. More...

Macros

#define _serial_driver_methods    _base_asynchronous_channel_methods
 SerialDriver specific methods.
#define _serial_driver_data
 SerialDriver specific data.

Typedefs

typedef struct hal_serial_driver SerialDriver
 Structure representing a serial driver.
typedef struct hal_serial_config SerialConfig
 PLATFORM Serial Driver configuration structure.

Enumerations

enum  sdstate_t { SD_UNINIT = 0 , SD_STOP = 1 , SD_READY = 2 }
 Driver state machine possible states. More...

Functions

static size_t _write (void *ip, const uint8_t *bp, size_t n)
static size_t _read (void *ip, uint8_t *bp, size_t n)
static msg_t _put (void *ip, uint8_t b)
static msg_t _get (void *ip)
static msg_t _putt (void *ip, uint8_t b, sysinterval_t timeout)
static msg_t _gett (void *ip, sysinterval_t timeout)
static size_t _writet (void *ip, const uint8_t *bp, size_t n, sysinterval_t timeout)
static size_t _readt (void *ip, uint8_t *bp, size_t n, sysinterval_t timeout)
static msg_t _ctl (void *ip, unsigned int operation, void *arg)
void sdInit (void)
 Serial Driver initialization.
void sdObjectInit (SerialDriver *sdp, qnotify_t inotify, qnotify_t onotify)
 Initializes a generic serial driver object.
msg_t sdStart (SerialDriver *sdp, const SerialConfig *config)
 Configures and starts the driver.
void sdStop (SerialDriver *sdp)
 Stops the driver.
void sdIncomingDataI (SerialDriver *sdp, uint8_t b)
 Handles incoming data.
msg_t sdRequestDataI (SerialDriver *sdp)
 Handles outgoing data.
bool sdPutWouldBlock (SerialDriver *sdp)
 Direct output check on a SerialDriver.
bool sdGetWouldBlock (SerialDriver *sdp)
 Direct input check on a SerialDriver.
msg_t sdControl (SerialDriver *sdp, unsigned int operation, void *arg)
 Control operation on a serial port.
void sd_lld_init (void)
 Low level serial driver initialization.
void sd_lld_start (SerialDriver *sdp, const SerialConfig *config)
 Low level serial driver configuration and (re)start.
void sd_lld_stop (SerialDriver *sdp)
 Low level serial driver stop.

Variables

static const struct SerialDriverVMT vmt
SerialDriver SD1
 USART1 serial driver identifier.
static const SerialConfig default_config
 Driver default configuration.

Macro Definition Documentation

◆ SD_PARITY_ERROR

#define SD_PARITY_ERROR   CHN_PARITY_ERROR

Definition at line 38 of file hal_serial.h.

◆ SD_FRAMING_ERROR

#define SD_FRAMING_ERROR   CHN_FRAMING_ERROR

Definition at line 39 of file hal_serial.h.

◆ SD_OVERRUN_ERROR

#define SD_OVERRUN_ERROR   CHN_OVERRUN_ERROR

Definition at line 40 of file hal_serial.h.

◆ SD_NOISE_ERROR

#define SD_NOISE_ERROR   CHN_NOISE_ERROR

Definition at line 41 of file hal_serial.h.

◆ SD_BREAK_DETECTED

#define SD_BREAK_DETECTED   CHN_BREAK_DETECTED

Definition at line 42 of file hal_serial.h.

◆ SD_QUEUE_FULL_ERROR

#define SD_QUEUE_FULL_ERROR   CHN_BUFFER_FULL_ERROR

Definition at line 43 of file hal_serial.h.

Referenced by sdIncomingDataI().

◆ SERIAL_DEFAULT_BITRATE

#define SERIAL_DEFAULT_BITRATE   38400

Default bit rate.

Configuration parameter, this is the baud rate selected for the default configuration.

Definition at line 60 of file hal_serial.h.

◆ SERIAL_BUFFERS_SIZE

#define SERIAL_BUFFERS_SIZE   16

Serial buffers size.

Configuration parameter, you can change the depth of the queue buffers depending on the requirements of your application.

Note
The default is 16 bytes for both the transmission and receive buffers.
This is a global setting and it can be overridden by low level driver specific settings.

Definition at line 73 of file hal_serial.h.

Referenced by sdObjectInit().

◆ _serial_driver_methods

#define _serial_driver_methods    _base_asynchronous_channel_methods

SerialDriver specific methods.

Definition at line 104 of file hal_serial.h.

◆ sdPutI

#define sdPutI ( sdp,
b )
Value:
oqPutI(&(sdp)->oqueue, b)
msg_t oqPutI(output_queue_t *oqp, uint8_t b)
Output queue non-blocking write.
Definition hal_queues.c:490

Direct write to a SerialDriver.

Note
This function bypasses the indirect access to the channel and writes directly on the output queue. This is faster but cannot be used to write to different channels implementations.
Parameters
[in]sdppointer to a SerialDriver object
[in]bthe byte value to be written in the output queue
Returns
The operation status.
Return values
MSG_OKif the operation succeeded.
MSG_TIMEOUTif the queue is full.
Function Class:
This is an I-Class API, this function can be invoked from within a system lock zone by both threads and interrupt handlers.

Definition at line 151 of file hal_serial.h.

◆ sdPut

#define sdPut ( sdp,
b )
Value:
oqPut(&(sdp)->oqueue, b)
#define oqPut(oqp, b)
Output queue write.
Definition hal_queues.h:292

Direct write to a SerialDriver.

Note
This function bypasses the indirect access to the channel and writes directly on the output queue. This is faster but cannot be used to write to different channels implementations.
Parameters
[in]sdppointer to a SerialDriver object
[in]bthe byte value to be written in the output queue
Returns
The operation status.
Return values
MSG_OKif the operation succeeded.
MSG_RESETif the SerialDriver has been stopped.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 167 of file hal_serial.h.

◆ sdPutTimeout

#define sdPutTimeout ( sdp,
b,
t )
Value:
oqPutTimeout(&(sdp)->oqueue, b, t)
msg_t oqPutTimeout(output_queue_t *oqp, uint8_t b, sysinterval_t timeout)
Output queue write with timeout.
Definition hal_queues.c:535

Direct write to a SerialDriver with timeout specification.

Note
This function bypasses the indirect access to the channel and writes directly on the output queue. This is faster but cannot be used to write to different channels implementations.
Parameters
[in]sdppointer to a SerialDriver object
[in]bthe byte value to be written in the output queue
[in]tthe number of ticks before the operation timeouts, the following special values are allowed:
  • TIME_IMMEDIATE immediate timeout.
  • TIME_INFINITE no timeout.
Returns
The operation status.
Return values
MSG_OKif the operation succeeded.
MSG_TIMEOUTif the specified time expired.
MSG_RESETif the SerialDriver has been stopped.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 188 of file hal_serial.h.

◆ sdGetI

#define sdGetI ( sdp)
Value:
iqGetI(&(sdp)->iqueue)
msg_t iqGetI(input_queue_t *iqp)
Input queue non-blocking read.
Definition hal_queues.c:257

Direct read from a SerialDriver.

Note
This function bypasses the indirect access to the channel and reads directly from the input queue. This is faster but cannot be used to read from different channels implementations.
Parameters
[in]sdppointer to a SerialDriver object
Returns
A byte value from the input queue.
Return values
MSG_TIMEOUTif the queue is empty.
Function Class:
This is an I-Class API, this function can be invoked from within a system lock zone by both threads and interrupt handlers.

Definition at line 202 of file hal_serial.h.

◆ sdGet

#define sdGet ( sdp)
Value:
iqGet(&(sdp)->iqueue)
#define iqGet(iqp)
Input queue read.
Definition hal_queues.h:227

Direct read from a SerialDriver.

Note
This function bypasses the indirect access to the channel and reads directly from the input queue. This is faster but cannot be used to read from different channels implementations.
Parameters
[in]sdppointer to a SerialDriver object
Returns
A byte value from the input queue.
Return values
MSG_RESETif the SerialDriver has been stopped.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 216 of file hal_serial.h.

◆ sdGetTimeout

#define sdGetTimeout ( sdp,
t )
Value:
iqGetTimeout(&(sdp)->iqueue, t)
msg_t iqGetTimeout(input_queue_t *iqp, sysinterval_t timeout)
Input queue read with timeout.
Definition hal_queues.c:302

Direct read from a SerialDriver with timeout specification.

Note
This function bypasses the indirect access to the channel and reads directly from the input queue. This is faster but cannot be used to read from different channels implementations.
Parameters
[in]sdppointer to a SerialDriver object
[in]tthe number of ticks before the operation timeouts, the following special values are allowed:
  • TIME_IMMEDIATE immediate timeout.
  • TIME_INFINITE no timeout.
Returns
A byte value from the input queue.
Return values
MSG_TIMEOUTif the specified time expired.
MSG_RESETif the SerialDriver has been stopped.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 235 of file hal_serial.h.

◆ sdWriteI

#define sdWriteI ( sdp,
b,
n )
Value:
oqWriteI(&(sdp)->oqueue, b, n)
size_t oqWriteI(output_queue_t *oqp, const uint8_t *bp, size_t n)
Output queue non-blocking write.
Definition hal_queues.c:611

Direct non-blocking write to a SerialDriver.

Note
This function bypasses the indirect access to the channel and writes directly to the output queue. This is faster but cannot be used to write from different channels implementations.
Parameters
[in]sdppointer to a SerialDriver object
[in]bpointer to the data buffer
[in]nthe maximum amount of data to be transferred, the value 0 is reserved
Returns
The number of bytes effectively transferred.
Function Class:
This is an I-Class API, this function can be invoked from within a system lock zone by both threads and interrupt handlers.

Definition at line 251 of file hal_serial.h.

◆ sdWrite

#define sdWrite ( sdp,
b,
n )
Value:
oqWriteTimeout(&(sdp)->oqueue, b, n, TIME_INFINITE)
size_t oqWriteTimeout(output_queue_t *oqp, const uint8_t *bp, size_t n, sysinterval_t timeout)
Output queue write with timeout.
Definition hal_queues.c:651
#define TIME_INFINITE
Definition osal.h:66

Direct blocking write to a SerialDriver.

Note
This function bypasses the indirect access to the channel and writes directly to the output queue. This is faster but cannot be used to write from different channels implementations.
Parameters
[in]sdppointer to a SerialDriver object
[in]bpointer to the data buffer
[in]nthe maximum amount of data to be transferred, the value 0 is reserved
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 266 of file hal_serial.h.

◆ sdWriteTimeout

#define sdWriteTimeout ( sdp,
b,
n,
t )
Value:
oqWriteTimeout(&(sdp)->oqueue, b, n, t)

Direct blocking write to a SerialDriver with timeout specification.

Note
This function bypasses the indirect access to the channel and writes directly to the output queue. This is faster but cannot be used to write to different channels implementations.
Parameters
[in]sdppointer to a SerialDriver object
[in]bpointer to the data buffer
[in]nthe maximum amount of data to be transferred, the value 0 is reserved
[in]tthe number of ticks before the operation timeouts, the following special values are allowed:
  • TIME_IMMEDIATE immediate timeout.
  • TIME_INFINITE no timeout.
Returns
The number of bytes effectively transferred.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 287 of file hal_serial.h.

◆ sdAsynchronousWrite

#define sdAsynchronousWrite ( sdp,
b,
n )
Value:
oqWriteTimeout(&(sdp)->oqueue, b, n, TIME_IMMEDIATE)
#define TIME_IMMEDIATE
Definition osal.h:65

Direct non-blocking write to a SerialDriver.

Note
This function bypasses the indirect access to the channel and writes directly to the output queue. This is faster but cannot be used to write to different channels implementations.
Parameters
[in]sdppointer to a SerialDriver object
[in]bpointer to the data buffer
[in]nthe maximum amount of data to be transferred, the value 0 is reserved
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 303 of file hal_serial.h.

◆ sdReadI

#define sdReadI ( sdp,
b,
n )
Value:
iqReadI(&(sdp)->iqueue, b, n)
size_t iqReadI(input_queue_t *iqp, uint8_t *bp, size_t n)
Input queue non-blocking read.
Definition hal_queues.c:346

Direct non-blocking read from a SerialDriver.

Note
This function bypasses the indirect access to the channel and reads directly from the input queue. This is faster but cannot be used to read from different channels implementations.
Parameters
[in]sdppointer to a SerialDriver object
[in]bpointer to the data buffer
[in]nthe maximum amount of data to be transferred, the value 0 is reserved
Returns
The number of bytes effectively transferred.
Function Class:
This is an I-Class API, this function can be invoked from within a system lock zone by both threads and interrupt handlers.

Definition at line 320 of file hal_serial.h.

◆ sdRead

#define sdRead ( sdp,
b,
n )
Value:
iqReadTimeout(&(sdp)->iqueue, b, n, TIME_INFINITE)
size_t iqReadTimeout(input_queue_t *iqp, uint8_t *bp, size_t n, sysinterval_t timeout)
Input queue read with timeout.
Definition hal_queues.c:386

Direct blocking read from a SerialDriver.

Note
This function bypasses the indirect access to the channel and reads directly from the input queue. This is faster but cannot be used to read from different channels implementations.
Parameters
[in]sdppointer to a SerialDriver object
[in]bpointer to the data buffer
[in]nthe maximum amount of data to be transferred, the value 0 is reserved
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 335 of file hal_serial.h.

◆ sdReadTimeout

#define sdReadTimeout ( sdp,
b,
n,
t )
Value:
iqReadTimeout(&(sdp)->iqueue, b, n, t)

Direct blocking read from a SerialDriver with timeout specification.

Note
This function bypasses the indirect access to the channel and reads directly from the input queue. This is faster but cannot be used to read from different channels implementations.
Parameters
[in]sdppointer to a SerialDriver object
[in]bpointer to the data buffer
[in]nthe maximum amount of data to be transferred, the value 0 is reserved
[in]tthe number of ticks before the operation timeouts, the following special values are allowed:
  • TIME_IMMEDIATE immediate timeout.
  • TIME_INFINITE no timeout.
Returns
The number of bytes effectively transferred.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 356 of file hal_serial.h.

◆ sdAsynchronousRead

#define sdAsynchronousRead ( sdp,
b,
n )
Value:
iqReadTimeout(&(sdp)->iqueue, b, n, TIME_IMMEDIATE)

Direct non-blocking read from a SerialDriver.

Note
This function bypasses the indirect access to the channel and reads directly from the input queue. This is faster but cannot be used to read from different channels implementations.
Parameters
[in]sdppointer to a SerialDriver object
[in]bpointer to the data buffer
[in]nthe maximum amount of data to be transferred, the value 0 is reserved
Returns
The number of bytes effectively transferred.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 372 of file hal_serial.h.

◆ PLATFORM_SERIAL_USE_USART1

#define PLATFORM_SERIAL_USE_USART1   FALSE

USART1 driver enable switch.

If set to TRUE the support for USART1 is included.

Note
The default is FALSE.

Definition at line 48 of file hal_serial_lld.h.

◆ _serial_driver_data

#define _serial_driver_data
Value:
/* Driver state.*/ \
sdstate_t state; \
/* Input queue.*/ \
input_queue_t iqueue; \
/* Output queue.*/ \
output_queue_t oqueue; \
/* Input circular buffer.*/ \
uint8_t ib[SERIAL_BUFFERS_SIZE]; \
/* Output circular buffer.*/ \
uint8_t ob[SERIAL_BUFFERS_SIZE]; \
/* End of the mandatory fields.*/
io_queue_t output_queue_t
Type of an output queue structure.
Definition hal_queues.h:109
io_queue_t input_queue_t
Type of an input queue structure.
Definition hal_queues.h:97
#define _base_asynchronous_channel_data
BaseAsynchronousChannel specific data.
#define SERIAL_BUFFERS_SIZE
Serial buffers size.
Definition hal_serial.h:73
sdstate_t
Driver state machine possible states.
Definition hal_serial.h:88

SerialDriver specific data.

Definition at line 79 of file hal_serial_lld.h.

Typedef Documentation

◆ SerialDriver

Structure representing a serial driver.

Definition at line 97 of file hal_serial.h.

◆ SerialConfig

PLATFORM Serial Driver configuration structure.

An instance of this structure must be passed to sdStart() in order to configure and start a serial driver operations.

Note
This structure content is architecture dependent, each driver implementation defines its own version and the custom static initializers.

Enumeration Type Documentation

◆ sdstate_t

enum sdstate_t

Driver state machine possible states.

Enumerator
SD_UNINIT 

Not initialized.

SD_STOP 

Stopped.

SD_READY 

Ready.

Definition at line 88 of file hal_serial.h.

Function Documentation

◆ _write()

size_t _write ( void * ip,
const uint8_t * bp,
size_t n )
static

Definition at line 50 of file hal_serial.c.

References oqWriteTimeout(), and TIME_INFINITE.

Here is the call graph for this function:

◆ _read()

size_t _read ( void * ip,
uint8_t * bp,
size_t n )
static

Definition at line 56 of file hal_serial.c.

References iqReadTimeout(), and TIME_INFINITE.

Here is the call graph for this function:

◆ _put()

msg_t _put ( void * ip,
uint8_t b )
static

Definition at line 62 of file hal_serial.c.

References oqPutTimeout(), and TIME_INFINITE.

Here is the call graph for this function:

◆ _get()

msg_t _get ( void * ip)
static

Definition at line 67 of file hal_serial.c.

References iqGetTimeout(), and TIME_INFINITE.

Here is the call graph for this function:

◆ _putt()

msg_t _putt ( void * ip,
uint8_t b,
sysinterval_t timeout )
static

Definition at line 72 of file hal_serial.c.

References oqPutTimeout().

Here is the call graph for this function:

◆ _gett()

msg_t _gett ( void * ip,
sysinterval_t timeout )
static

Definition at line 77 of file hal_serial.c.

References iqGetTimeout().

Here is the call graph for this function:

◆ _writet()

size_t _writet ( void * ip,
const uint8_t * bp,
size_t n,
sysinterval_t timeout )
static

Definition at line 82 of file hal_serial.c.

References oqWriteTimeout().

Here is the call graph for this function:

◆ _readt()

size_t _readt ( void * ip,
uint8_t * bp,
size_t n,
sysinterval_t timeout )
static

Definition at line 88 of file hal_serial.c.

References iqReadTimeout().

Here is the call graph for this function:

◆ _ctl()

msg_t _ctl ( void * ip,
unsigned int operation,
void * arg )
static

Definition at line 94 of file hal_serial.c.

References CHN_CTL_INVALID, CHN_CTL_NOP, HAL_RET_SUCCESS, HAL_RET_UNKNOWN_CTL, and osalDbgCheck.

Referenced by sdControl().

◆ sdInit()

void sdInit ( void )

Serial Driver initialization.

Note
This function is implicitly invoked by halInit(), there is no need to explicitly initialize the driver.
Function Class:
Object or module nitializer function.

Definition at line 134 of file hal_serial.c.

References sd_lld_init().

Referenced by halInit().

Here is the call graph for this function:

◆ sdObjectInit()

void sdObjectInit ( SerialDriver * sdp,
qnotify_t inotify,
qnotify_t onotify )

Initializes a generic serial driver object.

The HW dependent part of the initialization has to be performed outside, usually in the hardware initialization code.

Parameters
[out]sdppointer to a SerialDriver structure
[in]inotifypointer to a callback function that is invoked when some data is read from the Queue. The value can be NULL.
[in]onotifypointer to a callback function that is invoked when some data is written in the Queue. The value can be NULL.
Function Class:
Object or module nitializer function.

Definition at line 157 of file hal_serial.c.

References iqObjectInit(), oqObjectInit(), osalEventObjectInit(), SD_STOP, SERIAL_BUFFERS_SIZE, hal_serial_driver::vmt, and vmt.

Referenced by sd_lld_init().

Here is the call graph for this function:

◆ sdStart()

msg_t sdStart ( SerialDriver * sdp,
const SerialConfig * config )

Configures and starts the driver.

Parameters
[in]sdppointer to a SerialDriver object
[in]configthe architecture-dependent serial driver configuration. If this parameter is set to NULL then a default configuration is used.
Returns
The operation status.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 185 of file hal_serial.c.

References HAL_RET_SUCCESS, osalDbgAssert, osalDbgCheck, osalSysLock(), osalSysUnlock(), sd_lld_start(), SD_READY, and SD_STOP.

Here is the call graph for this function:

◆ sdStop()

void sdStop ( SerialDriver * sdp)

Stops the driver.

Any thread waiting on the driver's queues will be awakened with the message MSG_RESET.

Parameters
[in]sdppointer to a SerialDriver object
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 222 of file hal_serial.c.

References iqResetI(), oqResetI(), osalDbgAssert, osalDbgCheck, osalOsRescheduleS(), osalSysLock(), osalSysUnlock(), sd_lld_stop(), SD_READY, and SD_STOP.

Here is the call graph for this function:

◆ sdIncomingDataI()

void sdIncomingDataI ( SerialDriver * sdp,
uint8_t b )

Handles incoming data.

This function must be called from the input interrupt service routine in order to enqueue incoming data and generate the related events.

Note
The incoming data event is only generated when the input queue becomes non-empty.
In order to gain some performance it is suggested to not use this function directly but copy this code directly into the interrupt service routine.
Parameters
[in]sdppointer to a SerialDriver structure
[in]bthe byte to be written in the driver's Input Queue
Function Class:
This is an I-Class API, this function can be invoked from within a system lock zone by both threads and interrupt handlers.

Definition at line 256 of file hal_serial.c.

References CHN_INPUT_AVAILABLE, chnAddFlagsI, iqIsEmptyI, iqPutI(), MSG_OK, osalDbgCheck, osalDbgCheckClassI, and SD_QUEUE_FULL_ERROR.

Here is the call graph for this function:

◆ sdRequestDataI()

msg_t sdRequestDataI ( SerialDriver * sdp)

Handles outgoing data.

Must be called from the output interrupt service routine in order to get the next byte to be transmitted.

Note
In order to gain some performance it is suggested to not use this function directly but copy this code directly into the interrupt service routine.
Parameters
[in]sdppointer to a SerialDriver structure
Returns
The byte value read from the driver's output queue.
Return values
MSG_TIMEOUTif the queue is empty (the lower driver usually disables the interrupt source when this happens).
Function Class:
This is an I-Class API, this function can be invoked from within a system lock zone by both threads and interrupt handlers.

Definition at line 282 of file hal_serial.c.

References CHN_OUTPUT_EMPTY, chnAddFlagsI, MSG_OK, oqGetI(), osalDbgCheck, and osalDbgCheckClassI.

Here is the call graph for this function:

◆ sdPutWouldBlock()

bool sdPutWouldBlock ( SerialDriver * sdp)

Direct output check on a SerialDriver.

Note
This function bypasses the indirect access to the channel and checks directly the output queue. This is faster but cannot be used to check different channels implementations.
Parameters
[in]sdppointer to a SerialDriver structure
Returns
The queue status.
Return values
falseif the next write operation would not block.
trueif the next write operation would block.
Deprecated
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 309 of file hal_serial.c.

References oqIsFullI, osalSysLock(), and osalSysUnlock().

Here is the call graph for this function:

◆ sdGetWouldBlock()

bool sdGetWouldBlock ( SerialDriver * sdp)

Direct input check on a SerialDriver.

Note
This function bypasses the indirect access to the channel and checks directly the input queue. This is faster but cannot be used to check different channels implementations.
Parameters
[in]sdppointer to a SerialDriver structure
Returns
The queue status.
Return values
falseif the next write operation would not block.
trueif the next write operation would block.
Deprecated
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 334 of file hal_serial.c.

References iqIsEmptyI, osalSysLock(), and osalSysUnlock().

Here is the call graph for this function:

◆ sdControl()

msg_t sdControl ( SerialDriver * sdp,
unsigned int operation,
void * arg )

Control operation on a serial port.

Parameters
[in]sdppointer to a SerialDriver object
[in]operationcontrol operation code
[in,out]argoperation argument
Returns
The control operation status.
Return values
MSG_OKin case of success.
MSG_TIMEOUTin case of operation timeout.
MSG_RESETin case of operation reset.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 358 of file hal_serial.c.

References _ctl().

Here is the call graph for this function:

◆ sd_lld_init()

void sd_lld_init ( void )

Low level serial driver initialization.

Function Class:
Not an API, this function is for internal use only.

Definition at line 70 of file hal_serial_lld.c.

References SD1, and sdObjectInit().

Referenced by sdInit().

Here is the call graph for this function:

◆ sd_lld_start()

void sd_lld_start ( SerialDriver * sdp,
const SerialConfig * config )

Low level serial driver configuration and (re)start.

Parameters
[in]sdppointer to a SerialDriver object
[in]configthe architecture-dependent serial driver configuration. If this parameter is set to NULL then a default configuration is used.
Function Class:
Not an API, this function is for internal use only.

Definition at line 87 of file hal_serial_lld.c.

References default_config, SD1, and SD_STOP.

Referenced by sdStart().

◆ sd_lld_stop()

void sd_lld_stop ( SerialDriver * sdp)

Low level serial driver stop.

De-initializes the USART, stops the associated clock, resets the interrupt vector.

Parameters
[in]sdppointer to a SerialDriver object
Function Class:
Not an API, this function is for internal use only.

Definition at line 113 of file hal_serial_lld.c.

References SD1, and SD_READY.

Referenced by sdStop().

Variable Documentation

◆ vmt

const struct SerialDriverVMT vmt
static
Initial value:
= {
(size_t)0,
}
static size_t _writet(void *ip, const uint8_t *bp, size_t n, sysinterval_t timeout)
Definition hal_serial.c:82
static msg_t _get(void *ip)
Definition hal_serial.c:67
static msg_t _gett(void *ip, sysinterval_t timeout)
Definition hal_serial.c:77
static msg_t _ctl(void *ip, unsigned int operation, void *arg)
Definition hal_serial.c:94
static msg_t _put(void *ip, uint8_t b)
Definition hal_serial.c:62
static size_t _write(void *ip, const uint8_t *bp, size_t n)
Definition hal_serial.c:50
static msg_t _putt(void *ip, uint8_t b, sysinterval_t timeout)
Definition hal_serial.c:72
static size_t _readt(void *ip, uint8_t *bp, size_t n, sysinterval_t timeout)
Definition hal_serial.c:88
static size_t _read(void *ip, uint8_t *bp, size_t n)
Definition hal_serial.c:56

Definition at line 116 of file hal_serial.c.

◆ SD1

USART1 serial driver identifier.

Definition at line 39 of file hal_serial_lld.c.

Referenced by sd_lld_init(), sd_lld_start(), and sd_lld_stop().

◆ default_config

const SerialConfig default_config
static
Initial value:
= {
38400
}

Driver default configuration.

Definition at line 49 of file hal_serial_lld.c.

Referenced by sd_lld_start().