ChibiOS/HAL
6.1.0
|
Serial over USB Driver. More...
Serial over USB Driver.
This module implements an USB Communication Device Class (CDC) as a normal serial communication port accessible from the device application.
HAL_USE_SERIAL_USB
option must be enabled in halconf.h
.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).
Macros | |
#define | _serial_usb_driver_data |
SerialDriver specific data. More... | |
#define | _serial_usb_driver_methods _base_asynchronous_channel_methods |
SerialUSBDriver specific methods. More... | |
SERIAL_USB configuration options | |
#define | SERIAL_USB_BUFFERS_SIZE 256 |
Serial over USB buffers size. More... | |
#define | SERIAL_USB_BUFFERS_NUMBER 2 |
Serial over USB number of buffers. More... | |
Typedefs | |
typedef struct SerialUSBDriver | SerialUSBDriver |
Structure representing a serial over USB driver. More... | |
Data Structures | |
struct | SerialUSBConfig |
Serial over USB Driver configuration structure. More... | |
struct | SerialUSBDriverVMT |
SerialDriver virtual methods table. More... | |
struct | SerialUSBDriver |
Full duplex serial driver class. More... | |
Functions | |
static void | ibnotify (io_buffers_queue_t *bqp) |
Notification of empty buffer released into the input buffers queue. More... | |
static void | obnotify (io_buffers_queue_t *bqp) |
Notification of filled buffer inserted into the output buffers queue. More... | |
void | sduInit (void) |
Serial Driver initialization. More... | |
void | sduObjectInit (SerialUSBDriver *sdup) |
Initializes a generic full duplex driver object. More... | |
void | sduStart (SerialUSBDriver *sdup, const SerialUSBConfig *config) |
Configures and starts the driver. More... | |
void | sduStop (SerialUSBDriver *sdup) |
Stops the driver. More... | |
void | sduSuspendHookI (SerialUSBDriver *sdup) |
USB device suspend handler. More... | |
void | sduWakeupHookI (SerialUSBDriver *sdup) |
USB device wakeup handler. More... | |
void | sduConfigureHookI (SerialUSBDriver *sdup) |
USB device configured handler. More... | |
bool | sduRequestsHook (USBDriver *usbp) |
Default requests hook. More... | |
void | sduSOFHookI (SerialUSBDriver *sdup) |
SOF handler. More... | |
void | sduDataTransmitted (USBDriver *usbp, usbep_t ep) |
Default data transmitted callback. More... | |
void | sduDataReceived (USBDriver *usbp, usbep_t ep) |
Default data received callback. More... | |
void | sduInterruptTransmitted (USBDriver *usbp, usbep_t ep) |
Default data received callback. More... | |
msg_t | sduControl (USBDriver *usbp, unsigned int operation, void *arg) |
Control operation on a serial USB port. More... | |
Enumerations |
#define SERIAL_USB_BUFFERS_SIZE 256 |
Serial over USB buffers size.
Configuration parameter, the buffer size must be a multiple of the USB data endpoint maximum packet size.
Definition at line 52 of file hal_serial_usb.h.
Referenced by sduObjectInit().
#define SERIAL_USB_BUFFERS_NUMBER 2 |
Serial over USB number of buffers.
Definition at line 60 of file hal_serial_usb.h.
Referenced by sduObjectInit().
#define _serial_usb_driver_data |
SerialDriver
specific data.
Definition at line 119 of file hal_serial_usb.h.
#define _serial_usb_driver_methods _base_asynchronous_channel_methods |
SerialUSBDriver
specific methods.
Definition at line 140 of file hal_serial_usb.h.
typedef struct SerialUSBDriver SerialUSBDriver |
Structure representing a serial over USB driver.
Definition at line 88 of file hal_serial_usb.h.
enum sdustate_t |
Driver state machine possible states.
Enumerator | |
---|---|
SDU_UNINIT |
Not initialized. |
SDU_STOP |
Stopped. |
SDU_READY |
Ready. |
Definition at line 79 of file hal_serial_usb.h.
|
static |
Notification of empty buffer released into the input buffers queue.
[in] | bqp | the buffers queue pointer. |
Definition at line 168 of file hal_serial_usb.c.
References bqGetLinkX.
Referenced by sduObjectInit().
|
static |
Notification of filled buffer inserted into the output buffers queue.
[in] | bqp | the buffers queue pointer. |
Definition at line 178 of file hal_serial_usb.c.
References bqGetLinkX, obqGetFullBufferI(), SDU_READY, USB_ACTIVE, usbGetDriverStateI, usbGetTransmitStatusI, and usbStartTransmitI().
Referenced by sduObjectInit().
void sduInit | ( | void | ) |
Serial Driver initialization.
halInit()
, there is no need to explicitly initialize the driver.Definition at line 211 of file hal_serial_usb.c.
Referenced by halInit().
void sduObjectInit | ( | SerialUSBDriver * | sdup | ) |
Initializes a generic full duplex driver object.
The HW dependent part of the initialization has to be performed outside, usually in the hardware initialization code.
[out] | sdup | pointer to a SerialUSBDriver structure |
Definition at line 223 of file hal_serial_usb.c.
References ibnotify(), ibqObjectInit(), obnotify(), obqObjectInit(), osalEventObjectInit(), SDU_STOP, SERIAL_USB_BUFFERS_NUMBER, SERIAL_USB_BUFFERS_SIZE, and SerialUSBDriver::vmt.
void sduStart | ( | SerialUSBDriver * | sdup, |
const SerialUSBConfig * | config | ||
) |
Configures and starts the driver.
[in] | sdup | pointer to a SerialUSBDriver object |
[in] | config | the serial over USB driver configuration |
Definition at line 244 of file hal_serial_usb.c.
References SerialUSBConfig::bulk_in, SerialUSBConfig::bulk_out, USBDriver::in_params, SerialUSBConfig::int_in, osalDbgAssert, osalDbgCheck, osalSysLock(), osalSysUnlock(), USBDriver::out_params, SDU_READY, SDU_STOP, and SerialUSBConfig::usbp.
void sduStop | ( | SerialUSBDriver * | sdup | ) |
Stops the driver.
Any thread waiting on the driver's queues will be awakened with the message MSG_RESET
.
[in] | sdup | pointer to a SerialUSBDriver object |
Definition at line 271 of file hal_serial_usb.c.
References CHN_DISCONNECTED, chnAddFlagsI, ibqResetI(), USBDriver::in_params, obqResetI(), osalDbgAssert, osalDbgCheck, osalOsRescheduleS(), osalSysLock(), osalSysUnlock(), USBDriver::out_params, SDU_READY, and SDU_STOP.
void sduSuspendHookI | ( | SerialUSBDriver * | sdup | ) |
USB device suspend handler.
Generates a CHN_DISCONNECT
event and puts queues in non-blocking mode, this way the application cannot get stuck in the middle of an I/O operations.
osalOsRescheduleS()
in necessary afterward.[in] | sdup | pointer to a SerialUSBDriver object |
Definition at line 311 of file hal_serial_usb.c.
References bqSuspendI, CHN_DISCONNECTED, and chnAddFlagsI.
void sduWakeupHookI | ( | SerialUSBDriver * | sdup | ) |
USB device wakeup handler.
Generates a CHN_CONNECT
event and resumes normal queues operations.
osalOsRescheduleS()
in necessary afterward.[in] | sdup | pointer to a SerialUSBDriver object |
Definition at line 330 of file hal_serial_usb.c.
References bqResumeX, CHN_CONNECTED, and chnAddFlagsI.
void sduConfigureHookI | ( | SerialUSBDriver * | sdup | ) |
USB device configured handler.
[in] | sdup | pointer to a SerialUSBDriver object |
Definition at line 344 of file hal_serial_usb.c.
References bqResumeX, CHN_CONNECTED, chnAddFlagsI, ibqResetI(), and obqResetI().
bool sduRequestsHook | ( | USBDriver * | usbp | ) |
Default requests hook.
Applications wanting to use the Serial over USB driver can use this function as requests hook in the USB configuration. The following requests are emulated:
[in] | usbp | pointer to the USBDriver object |
true | Message handled internally. |
false | Message not handled. |
Definition at line 369 of file hal_serial_usb.c.
References USBDriver::setup, and usbSetupTransfer.
void sduSOFHookI | ( | SerialUSBDriver * | sdup | ) |
SOF handler.
The SOF interrupt is used for automatic flushing of incomplete buffers pending in the output queue.
[in] | sdup | pointer to a SerialUSBDriver object |
Definition at line 399 of file hal_serial_usb.c.
References obqGetFullBufferI(), obqTryFlushI(), osalDbgAssert, SDU_READY, USB_ACTIVE, usbGetDriverStateI, usbGetTransmitStatusI, and usbStartTransmitI().
Default data transmitted callback.
The application must use this function as callback for the IN data endpoint.
[in] | usbp | pointer to the USBDriver object |
[in] | ep | IN endpoint number |
Definition at line 434 of file hal_serial_usb.c.
References CHN_OUTPUT_EMPTY, chnAddFlagsI, USBDriver::epc, USBEndpointConfig::in_maxsize, USBDriver::in_params, USBEndpointConfig::in_state, obqGetFullBufferI(), obqReleaseEmptyBufferI(), osalSysLockFromISR(), osalSysUnlockFromISR(), USBDriver::setup, USBInEndpointState::txsize, and usbStartTransmitI().
Default data received callback.
The application must use this function as callback for the OUT data endpoint.
[in] | usbp | pointer to the USBDriver object |
[in] | ep | OUT endpoint number |
Definition at line 486 of file hal_serial_usb.c.
References CHN_INPUT_AVAILABLE, chnAddFlagsI, ibqPostFullBufferI(), osalSysLockFromISR(), osalSysUnlockFromISR(), USBDriver::out_params, and usbGetReceiveTransactionSizeX.
Default data received callback.
The application must use this function as callback for the IN interrupt endpoint.
[in] | usbp | pointer to the USBDriver object |
[in] | ep | endpoint number |
Definition at line 523 of file hal_serial_usb.c.
Control operation on a serial USB port.
[in] | usbp | pointer to a USBDriver object |
[in] | operation | control operation code |
[in,out] | arg | operation argument |
MSG_OK | in case of success. |
MSG_TIMEOUT | in case of operation timeout. |
MSG_RESET | in case of operation reset. |
Definition at line 543 of file hal_serial_usb.c.