ChibiOS/HAL
6.1.0
|
Generic USB Driver. More...
Generic USB Driver.
This module implements a generic USB (Universal Serial Bus) driver supporting device-mode operations.
HAL_USE_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).
The USB driver is quite complex and USB is complex in itself, it is recommended to study the USB specification before trying to use the driver.
The USB driver abstracts the inner details of the underlying USB hardware. The driver works asynchronously and communicates with the application using callbacks. The application is responsible of the descriptors and strings required by the USB device class to be implemented and of the handling of the specific messages sent over the endpoint zero. Standard messages are handled internally to the driver. The application can use hooks in order to handle custom messages or override the handling of the default handling of standard messages.
USB endpoints are the objects that the application uses to exchange data with the host. There are two kind of endpoints:
The driver invokes a callback after finishing an IN or OUT transaction. States diagram for OUT endpoints in transaction mode:
States diagram for IN endpoints in transaction mode:
The USB driver uses callbacks in order to interact with the application. There are several kinds of callbacks to be handled:
Macros | |
#define | USB_USE_WAIT FALSE |
Enables synchronous APIs. More... | |
#define | USB_MAX_ENDPOINTS 4 |
Maximum endpoint address. More... | |
#define | USB_EP0_STATUS_STAGE USB_EP0_STATUS_STAGE_SW |
Status stage handling method. More... | |
#define | USB_SET_ADDRESS_MODE USB_LATE_SET_ADDRESS |
The address can be changed immediately upon packet reception. More... | |
#define | USB_SET_ADDRESS_ACK_HANDLING USB_SET_ADDRESS_ACK_SW |
Method for set address acknowledge. More... | |
#define | usb_lld_get_frame_number(usbp) 0 |
Returns the current frame number. More... | |
#define | usb_lld_get_transaction_size(usbp, ep) ((usbp)->epc[ep]->out_state->rxcnt) |
Returns the exact size of a receive transaction. More... | |
#define | usb_lld_connect_bus(usbp) |
Connects the USB device. More... | |
#define | usb_lld_disconnect_bus(usbp) |
Disconnect the USB device. More... | |
#define | usb_lld_wakeup_host(usbp) |
Start of host wake-up procedure. More... | |
Helper macros for USB descriptors | |
#define | USB_DESC_INDEX(i) ((uint8_t)(i)) |
Helper macro for index values into descriptor strings. More... | |
#define | USB_DESC_BYTE(b) ((uint8_t)(b)) |
Helper macro for byte values into descriptor strings. More... | |
#define | USB_DESC_WORD(w) |
Helper macro for word values into descriptor strings. More... | |
#define | USB_DESC_BCD(bcd) |
Helper macro for BCD values into descriptor strings. More... | |
#define | USB_DESC_DEVICE_SIZE 18U |
#define | USB_DESC_DEVICE(bcdUSB, bDeviceClass, bDeviceSubClass, bDeviceProtocol, bMaxPacketSize, idVendor, idProduct, bcdDevice, iManufacturer, iProduct, iSerialNumber, bNumConfigurations) |
Device Descriptor helper macro. More... | |
#define | USB_DESC_CONFIGURATION_SIZE 9U |
Configuration Descriptor size. More... | |
#define | USB_DESC_CONFIGURATION(wTotalLength, bNumInterfaces, bConfigurationValue, iConfiguration, bmAttributes, bMaxPower) |
Configuration Descriptor helper macro. More... | |
#define | USB_DESC_INTERFACE_SIZE 9U |
Interface Descriptor size. More... | |
#define | USB_DESC_INTERFACE(bInterfaceNumber, bAlternateSetting, bNumEndpoints, bInterfaceClass, bInterfaceSubClass, bInterfaceProtocol, iInterface) |
Interface Descriptor helper macro. More... | |
#define | USB_DESC_INTERFACE_ASSOCIATION_SIZE 8U |
Interface Association Descriptor size. More... | |
#define | USB_DESC_INTERFACE_ASSOCIATION(bFirstInterface, bInterfaceCount, bFunctionClass, bFunctionSubClass, bFunctionProcotol, iInterface) |
Interface Association Descriptor helper macro. More... | |
#define | USB_DESC_ENDPOINT_SIZE 7U |
Endpoint Descriptor size. More... | |
#define | USB_DESC_ENDPOINT(bEndpointAddress, bmAttributes, wMaxPacketSize, bInterval) |
Endpoint Descriptor helper macro. More... | |
Endpoint types and settings | |
#define | USB_EP_MODE_TYPE 0x0003U |
#define | USB_EP_MODE_TYPE_CTRL 0x0000U |
#define | USB_EP_MODE_TYPE_ISOC 0x0001U |
#define | USB_EP_MODE_TYPE_BULK 0x0002U |
#define | USB_EP_MODE_TYPE_INTR 0x0003U |
Macro Functions | |
#define | usbGetDriverStateI(usbp) ((usbp)->state) |
Returns the driver state. More... | |
#define | usbConnectBus(usbp) usb_lld_connect_bus(usbp) |
Connects the USB device. More... | |
#define | usbDisconnectBus(usbp) usb_lld_disconnect_bus(usbp) |
Disconnect the USB device. More... | |
#define | usbGetFrameNumberX(usbp) usb_lld_get_frame_number(usbp) |
Returns the current frame number. More... | |
#define | usbGetTransmitStatusI(usbp, ep) (((usbp)->transmitting & (uint16_t)((unsigned)1U << (unsigned)(ep))) != 0U) |
Returns the status of an IN endpoint. More... | |
#define | usbGetReceiveStatusI(usbp, ep) (((usbp)->receiving & (uint16_t)((unsigned)1U << (unsigned)(ep))) != 0U) |
Returns the status of an OUT endpoint. More... | |
#define | usbGetReceiveTransactionSizeX(usbp, ep) usb_lld_get_transaction_size(usbp, ep) |
Returns the exact size of a receive transaction. More... | |
#define | usbSetupTransfer(usbp, buf, n, endcb) |
Request transfer setup. More... | |
#define | usbReadSetup(usbp, ep, buf) usb_lld_read_setup(usbp, ep, buf) |
Reads a setup packet from the dedicated packet buffer. More... | |
Low level driver helper macros | |
#define | _usb_isr_invoke_event_cb(usbp, evt) |
Common ISR code, usb event callback. More... | |
#define | _usb_isr_invoke_sof_cb(usbp) |
Common ISR code, SOF callback. More... | |
#define | _usb_isr_invoke_setup_cb(usbp, ep) |
Common ISR code, setup packet callback. More... | |
#define | _usb_isr_invoke_in_cb(usbp, ep) |
Common ISR code, IN endpoint callback. More... | |
#define | _usb_isr_invoke_out_cb(usbp, ep) |
Common ISR code, OUT endpoint event. More... | |
PLATFORM configuration options | |
#define | PLATFORM_USB_USE_USB1 FALSE |
USB driver enable switch. More... | |
Typedefs | |
typedef struct USBDriver | USBDriver |
Type of a structure representing an USB driver. More... | |
typedef uint8_t | usbep_t |
Type of an endpoint identifier. More... | |
typedef void(* | usbcallback_t) (USBDriver *usbp) |
Type of an USB generic notification callback. More... | |
typedef void(* | usbepcallback_t) (USBDriver *usbp, usbep_t ep) |
Type of an USB endpoint callback. More... | |
typedef void(* | usbeventcb_t) (USBDriver *usbp, usbevent_t event) |
Type of an USB event notification callback. More... | |
typedef bool(* | usbreqhandler_t) (USBDriver *usbp) |
Type of a requests handler callback. More... | |
typedef const USBDescriptor *(* | usbgetdescriptor_t) (USBDriver *usbp, uint8_t dtype, uint8_t dindex, uint16_t lang) |
Type of an USB descriptor-retrieving callback. More... | |
Data Structures | |
struct | USBDescriptor |
Type of an USB descriptor. More... | |
struct | USBInEndpointState |
Type of an IN endpoint state structure. More... | |
struct | USBOutEndpointState |
Type of an OUT endpoint state structure. More... | |
struct | USBEndpointConfig |
Type of an USB endpoint configuration structure. More... | |
struct | USBConfig |
Type of an USB driver configuration structure. More... | |
struct | USBDriver |
Structure representing an USB driver. More... | |
Functions | |
static void | set_address (USBDriver *usbp) |
SET ADDRESS transaction callback. More... | |
static bool | default_handler (USBDriver *usbp) |
Standard requests handler. More... | |
void | usbInit (void) |
USB Driver initialization. More... | |
void | usbObjectInit (USBDriver *usbp) |
Initializes the standard part of a USBDriver structure. More... | |
void | usbStart (USBDriver *usbp, const USBConfig *config) |
Configures and activates the USB peripheral. More... | |
void | usbStop (USBDriver *usbp) |
Deactivates the USB peripheral. More... | |
void | usbInitEndpointI (USBDriver *usbp, usbep_t ep, const USBEndpointConfig *epcp) |
Enables an endpoint. More... | |
void | usbDisableEndpointsI (USBDriver *usbp) |
Disables all the active endpoints. More... | |
void | usbStartReceiveI (USBDriver *usbp, usbep_t ep, uint8_t *buf, size_t n) |
Starts a receive transaction on an OUT endpoint. More... | |
void | usbStartTransmitI (USBDriver *usbp, usbep_t ep, const uint8_t *buf, size_t n) |
Starts a transmit transaction on an IN endpoint. More... | |
msg_t | usbReceive (USBDriver *usbp, usbep_t ep, uint8_t *buf, size_t n) |
Performs a receive transaction on an OUT endpoint. More... | |
msg_t | usbTransmit (USBDriver *usbp, usbep_t ep, const uint8_t *buf, size_t n) |
Performs a transmit transaction on an IN endpoint. More... | |
bool | usbStallReceiveI (USBDriver *usbp, usbep_t ep) |
Stalls an OUT endpoint. More... | |
bool | usbStallTransmitI (USBDriver *usbp, usbep_t ep) |
Stalls an IN endpoint. More... | |
void | usbWakeupHost (USBDriver *usbp) |
Host wake-up procedure. More... | |
void | _usb_reset (USBDriver *usbp) |
USB reset routine. More... | |
void | _usb_suspend (USBDriver *usbp) |
USB suspend routine. More... | |
void | _usb_wakeup (USBDriver *usbp) |
USB wake-up routine. More... | |
void | _usb_ep0setup (USBDriver *usbp, usbep_t ep) |
Default EP0 SETUP callback. More... | |
void | _usb_ep0in (USBDriver *usbp, usbep_t ep) |
Default EP0 IN callback. More... | |
void | _usb_ep0out (USBDriver *usbp, usbep_t ep) |
Default EP0 OUT callback. More... | |
void | usb_lld_init (void) |
Low level USB driver initialization. More... | |
void | usb_lld_start (USBDriver *usbp) |
Configures and activates the USB peripheral. More... | |
void | usb_lld_stop (USBDriver *usbp) |
Deactivates the USB peripheral. More... | |
void | usb_lld_reset (USBDriver *usbp) |
USB low level reset routine. More... | |
void | usb_lld_set_address (USBDriver *usbp) |
Sets the USB address. More... | |
void | usb_lld_init_endpoint (USBDriver *usbp, usbep_t ep) |
Enables an endpoint. More... | |
void | usb_lld_disable_endpoints (USBDriver *usbp) |
Disables all the active endpoints except the endpoint zero. More... | |
usbepstatus_t | usb_lld_get_status_out (USBDriver *usbp, usbep_t ep) |
Returns the status of an OUT endpoint. More... | |
usbepstatus_t | usb_lld_get_status_in (USBDriver *usbp, usbep_t ep) |
Returns the status of an IN endpoint. More... | |
void | usb_lld_read_setup (USBDriver *usbp, usbep_t ep, uint8_t *buf) |
Reads a setup packet from the dedicated packet buffer. More... | |
void | usb_lld_prepare_receive (USBDriver *usbp, usbep_t ep) |
Prepares for a receive operation. More... | |
void | usb_lld_prepare_transmit (USBDriver *usbp, usbep_t ep) |
Prepares for a transmit operation. More... | |
void | usb_lld_start_out (USBDriver *usbp, usbep_t ep) |
Starts a receive operation on an OUT endpoint. More... | |
void | usb_lld_start_in (USBDriver *usbp, usbep_t ep) |
Starts a transmit operation on an IN endpoint. More... | |
void | usb_lld_stall_out (USBDriver *usbp, usbep_t ep) |
Brings an OUT endpoint in the stalled state. More... | |
void | usb_lld_stall_in (USBDriver *usbp, usbep_t ep) |
Brings an IN endpoint in the stalled state. More... | |
void | usb_lld_clear_out (USBDriver *usbp, usbep_t ep) |
Brings an OUT endpoint in the active state. More... | |
void | usb_lld_clear_in (USBDriver *usbp, usbep_t ep) |
Brings an IN endpoint in the active state. More... | |
Enumerations |
Variables | |
USBDriver | USBD1 |
USB1 driver identifier. More... | |
union { | |
USBInEndpointState in | |
IN EP0 state. More... | |
USBOutEndpointState out | |
OUT EP0 state. More... | |
} | ep0_state |
EP0 state. More... | |
static const USBEndpointConfig | ep0config |
EP0 initialization structure. More... | |
#define USB_DESC_INDEX | ( | i | ) | ((uint8_t)(i)) |
#define USB_DESC_BYTE | ( | b | ) | ((uint8_t)(b)) |
#define USB_DESC_WORD | ( | w | ) |
#define USB_DESC_BCD | ( | bcd | ) |
#define USB_DESC_DEVICE | ( | bcdUSB, | |
bDeviceClass, | |||
bDeviceSubClass, | |||
bDeviceProtocol, | |||
bMaxPacketSize, | |||
idVendor, | |||
idProduct, | |||
bcdDevice, | |||
iManufacturer, | |||
iProduct, | |||
iSerialNumber, | |||
bNumConfigurations | |||
) |
Device Descriptor helper macro.
#define USB_DESC_CONFIGURATION_SIZE 9U |
#define USB_DESC_CONFIGURATION | ( | wTotalLength, | |
bNumInterfaces, | |||
bConfigurationValue, | |||
iConfiguration, | |||
bmAttributes, | |||
bMaxPower | |||
) |
Configuration Descriptor helper macro.
#define USB_DESC_INTERFACE_SIZE 9U |
#define USB_DESC_INTERFACE | ( | bInterfaceNumber, | |
bAlternateSetting, | |||
bNumEndpoints, | |||
bInterfaceClass, | |||
bInterfaceSubClass, | |||
bInterfaceProtocol, | |||
iInterface | |||
) |
Interface Descriptor helper macro.
#define USB_DESC_INTERFACE_ASSOCIATION_SIZE 8U |
#define USB_DESC_INTERFACE_ASSOCIATION | ( | bFirstInterface, | |
bInterfaceCount, | |||
bFunctionClass, | |||
bFunctionSubClass, | |||
bFunctionProcotol, | |||
iInterface | |||
) |
Interface Association Descriptor helper macro.
#define USB_DESC_ENDPOINT_SIZE 7U |
#define USB_DESC_ENDPOINT | ( | bEndpointAddress, | |
bmAttributes, | |||
wMaxPacketSize, | |||
bInterval | |||
) |
Endpoint Descriptor helper macro.
#define USB_EP_MODE_TYPE_ISOC 0x0001U |
#define USB_USE_WAIT FALSE |
#define usbGetDriverStateI | ( | usbp | ) | ((usbp)->state) |
Returns the driver state.
[in] | usbp | pointer to the USBDriver object |
Definition at line 391 of file hal_usb.h.
Referenced by obnotify(), sduSOFHookI(), usbReceive(), and usbTransmit().
#define usbConnectBus | ( | usbp | ) | usb_lld_connect_bus(usbp) |
#define usbDisconnectBus | ( | usbp | ) | usb_lld_disconnect_bus(usbp) |
#define usbGetFrameNumberX | ( | usbp | ) | usb_lld_get_frame_number(usbp) |
#define usbGetTransmitStatusI | ( | usbp, | |
ep | |||
) | (((usbp)->transmitting & (uint16_t)((unsigned)1U << (unsigned)(ep))) != 0U) |
Returns the status of an IN endpoint.
[in] | usbp | pointer to the USBDriver object |
[in] | ep | endpoint number |
false | Endpoint ready. |
true | Endpoint transmitting. |
Definition at line 432 of file hal_usb.h.
Referenced by obnotify(), sduSOFHookI(), usbStallTransmitI(), and usbStartTransmitI().
#define usbGetReceiveStatusI | ( | usbp, | |
ep | |||
) | (((usbp)->receiving & (uint16_t)((unsigned)1U << (unsigned)(ep))) != 0U) |
Returns the status of an OUT endpoint.
[in] | usbp | pointer to the USBDriver object |
[in] | ep | endpoint number |
false | Endpoint ready. |
true | Endpoint receiving. |
Definition at line 446 of file hal_usb.h.
Referenced by usbStallReceiveI(), and usbStartReceiveI().
#define usbGetReceiveTransactionSizeX | ( | usbp, | |
ep | |||
) | usb_lld_get_transaction_size(usbp, ep) |
Returns the exact size of a receive transaction.
The received size can be different from the size specified in usbStartReceiveI()
because the last packet could have a size different from the expected one.
[in] | usbp | pointer to the USBDriver object |
[in] | ep | endpoint number |
Definition at line 461 of file hal_usb.h.
Referenced by _usb_ep0out(), and sduDataReceived().
#define usbSetupTransfer | ( | usbp, | |
buf, | |||
n, | |||
endcb | |||
) |
Request transfer setup.
This macro is used by the request handling callbacks in order to prepare a transaction over the endpoint zero.
[in] | usbp | pointer to the USBDriver object |
[in] | buf | pointer to a buffer for the transaction data |
[in] | n | number of bytes to be transferred |
[in] | endcb | callback to be invoked after the transfer or NULL |
Definition at line 476 of file hal_usb.h.
Referenced by default_handler(), and sduRequestsHook().
#define usbReadSetup | ( | usbp, | |
ep, | |||
buf | |||
) | usb_lld_read_setup(usbp, ep, buf) |
Reads a setup packet from the dedicated packet buffer.
This function must be invoked in the context of the setup_cb
callback in order to read the received setup packet.
[in] | usbp | pointer to the USBDriver object |
[in] | ep | endpoint number |
[out] | buf | buffer where to copy the packet data |
Definition at line 496 of file hal_usb.h.
Referenced by _usb_ep0setup().
#define _usb_isr_invoke_event_cb | ( | usbp, | |
evt | |||
) |
Common ISR code, usb event callback.
[in] | usbp | pointer to the USBDriver object |
[in] | evt | USB event code |
Definition at line 511 of file hal_usb.h.
Referenced by _usb_ep0in(), _usb_ep0out(), _usb_ep0setup(), _usb_reset(), _usb_suspend(), _usb_wakeup(), default_handler(), and set_address().
#define _usb_isr_invoke_sof_cb | ( | usbp | ) |
#define _usb_isr_invoke_setup_cb | ( | usbp, | |
ep | |||
) |
#define _usb_isr_invoke_in_cb | ( | usbp, | |
ep | |||
) |
Common ISR code, IN endpoint callback.
[in] | usbp | pointer to the USBDriver object |
[in] | ep | endpoint number |
#define _usb_isr_invoke_out_cb | ( | usbp, | |
ep | |||
) |
Common ISR code, OUT endpoint event.
[in] | usbp | pointer to the USBDriver object |
[in] | ep | endpoint number |
#define USB_MAX_ENDPOINTS 4 |
Maximum endpoint address.
Definition at line 37 of file hal_usb_lld.h.
Referenced by _usb_reset(), _usb_suspend(), usbDisableEndpointsI(), usbObjectInit(), usbStart(), usbStartReceiveI(), usbStartTransmitI(), and usbStop().
#define USB_EP0_STATUS_STAGE USB_EP0_STATUS_STAGE_SW |
Status stage handling method.
Definition at line 42 of file hal_usb_lld.h.
#define USB_SET_ADDRESS_MODE USB_LATE_SET_ADDRESS |
The address can be changed immediately upon packet reception.
Definition at line 47 of file hal_usb_lld.h.
#define USB_SET_ADDRESS_ACK_HANDLING USB_SET_ADDRESS_ACK_SW |
Method for set address acknowledge.
Definition at line 52 of file hal_usb_lld.h.
#define PLATFORM_USB_USE_USB1 FALSE |
USB driver enable switch.
If set to TRUE
the support for USB1 is included.
FALSE
. Definition at line 68 of file hal_usb_lld.h.
#define usb_lld_get_frame_number | ( | usbp | ) | 0 |
Returns the current frame number.
[in] | usbp | pointer to the USBDriver object |
Definition at line 306 of file hal_usb_lld.h.
#define usb_lld_get_transaction_size | ( | usbp, | |
ep | |||
) | ((usbp)->epc[ep]->out_state->rxcnt) |
Returns the exact size of a receive transaction.
The received size can be different from the size specified in usbStartReceiveI()
because the last packet could have a size different from the expected one.
[in] | usbp | pointer to the USBDriver object |
[in] | ep | endpoint number |
Definition at line 322 of file hal_usb_lld.h.
#define usb_lld_connect_bus | ( | usbp | ) |
Connects the USB device.
Definition at line 330 of file hal_usb_lld.h.
#define usb_lld_disconnect_bus | ( | usbp | ) |
Disconnect the USB device.
Definition at line 337 of file hal_usb_lld.h.
#define usb_lld_wakeup_host | ( | usbp | ) |
Start of host wake-up procedure.
Definition at line 344 of file hal_usb_lld.h.
Referenced by usbWakeupHost().
typedef void(* usbcallback_t) (USBDriver *usbp) |
typedef void(* usbeventcb_t) (USBDriver *usbp, usbevent_t event) |
typedef bool(* usbreqhandler_t) (USBDriver *usbp) |
Type of a requests handler callback.
The request is encoded in the usb_setup
buffer.
[in] | usbp | pointer to the USBDriver object triggering the callback |
false | Request not recognized by the handler. |
true | Request handled. |
typedef const USBDescriptor*(* usbgetdescriptor_t) (USBDriver *usbp, uint8_t dtype, uint8_t dindex, uint16_t lang) |
enum usbstate_t |
enum usbepstatus_t |
enum usbep0state_t |
Type of an endpoint zero state machine states.
enum usbevent_t |
Type of an enumeration of the possible USB events.
|
static |
SET ADDRESS transaction callback.
[in] | usbp | pointer to the USBDriver object |
Definition at line 64 of file hal_usb.c.
References _usb_isr_invoke_event_cb, USBDriver::address, USBDriver::setup, USBDriver::state, USB_EVENT_ADDRESS, usb_lld_set_address(), and USB_SELECTED.
Referenced by default_handler().
|
static |
Standard requests handler.
This is the standard requests default handler, most standard requests are handled here, the user can override the standard handling using the requests_hook_cb
hook in the USBConfig
structure.
[in] | usbp | pointer to the USBDriver object |
false | Request not recognized by the handler or error. |
true | Request handled. |
Definition at line 84 of file hal_usb.c.
References _usb_isr_invoke_event_cb, USBDriver::config, USBDriver::configuration, EP_STATUS_ACTIVE, EP_STATUS_DISABLED, EP_STATUS_STALLED, USBConfig::get_descriptor_cb, osalSysLockFromISR(), osalSysUnlockFromISR(), set_address(), USBDriver::setup, USBDriver::state, USBDriver::status, USBDescriptor::ud_size, USBDescriptor::ud_string, USB_ACTIVE, USB_EVENT_CONFIGURED, USB_EVENT_UNCONFIGURED, usb_lld_clear_in(), usb_lld_clear_out(), usb_lld_get_status_in(), usb_lld_get_status_out(), usb_lld_stall_in(), usb_lld_stall_out(), USB_SELECTED, usbDisableEndpointsI(), and usbSetupTransfer.
Referenced by _usb_ep0setup().
void usbInit | ( | void | ) |
USB Driver initialization.
halInit()
, there is no need to explicitly initialize the driver.Definition at line 270 of file hal_usb.c.
References usb_lld_init().
Referenced by halInit().
void usbObjectInit | ( | USBDriver * | usbp | ) |
Initializes the standard part of a USBDriver
structure.
[out] | usbp | pointer to the USBDriver object |
Definition at line 282 of file hal_usb.c.
References USBDriver::config, USBDriver::in_params, USBDriver::out_params, USBDriver::receiving, USBDriver::state, USBDriver::transmitting, USB_MAX_ENDPOINTS, and USB_STOP.
Referenced by usb_lld_init().
Configures and activates the USB peripheral.
Definition at line 303 of file hal_usb.c.
References USBDriver::config, USBDriver::epc, osalDbgAssert, osalDbgCheck, osalSysLock(), osalSysUnlock(), USBDriver::state, usb_lld_start(), USB_MAX_ENDPOINTS, USB_READY, and USB_STOP.
void usbStop | ( | USBDriver * | usbp | ) |
Deactivates the USB peripheral.
[in] | usbp | pointer to the USBDriver object |
Definition at line 327 of file hal_usb.c.
References USBDriver::config, USBDriver::epc, USBEndpointConfig::in_state, osalDbgAssert, osalDbgCheck, osalOsRescheduleS(), osalSysLock(), osalSysUnlock(), osalThreadResumeI(), USBEndpointConfig::out_state, USBDriver::state, USBInEndpointState::thread, USBOutEndpointState::thread, USB_ACTIVE, usb_lld_stop(), USB_MAX_ENDPOINTS, USB_READY, USB_SELECTED, USB_STOP, and USB_SUSPENDED.
void usbInitEndpointI | ( | USBDriver * | usbp, |
usbep_t | ep, | ||
const USBEndpointConfig * | epcp | ||
) |
Enables an endpoint.
This function enables an endpoint, both IN and/or OUT directions depending on the configuration structure.
[in] | usbp | pointer to the USBDriver object |
[in] | ep | endpoint number |
[in] | epcp | the endpoint configuration |
Definition at line 375 of file hal_usb.c.
References USBDriver::epc, USBEndpointConfig::in_state, osalDbgAssert, osalDbgCheck, osalDbgCheckClassI, USBEndpointConfig::out_state, USBDriver::state, USB_ACTIVE, and usb_lld_init_endpoint().
void usbDisableEndpointsI | ( | USBDriver * | usbp | ) |
Disables all the active endpoints.
This function disables all the active endpoints except the endpoint zero.
[in] | usbp | pointer to the USBDriver object |
Definition at line 410 of file hal_usb.c.
References USBDriver::epc, USBEndpointConfig::in_state, osalDbgAssert, osalDbgCheck, osalDbgCheckClassI, osalThreadResumeI(), USBEndpointConfig::out_state, USBDriver::receiving, USBDriver::state, USBInEndpointState::thread, USBOutEndpointState::thread, USBDriver::transmitting, USB_ACTIVE, usb_lld_disable_endpoints(), and USB_MAX_ENDPOINTS.
Referenced by default_handler().
Starts a receive transaction on an OUT endpoint.
[in] | usbp | pointer to the USBDriver object |
[in] | ep | endpoint number |
[out] | buf | buffer where to copy the received data |
[in] | n | transaction size. It is recommended a multiple of the packet size because the excess is discarded. |
Definition at line 453 of file hal_usb.c.
References USBDriver::epc, osalDbgAssert, osalDbgCheck, osalDbgCheckClassI, USBEndpointConfig::out_state, USBDriver::receiving, USBOutEndpointState::rxbuf, USBOutEndpointState::rxcnt, USBOutEndpointState::rxsize, USBOutEndpointState::thread, usb_lld_start_out(), USB_MAX_ENDPOINTS, and usbGetReceiveStatusI.
Referenced by _usb_ep0in(), _usb_ep0setup(), and usbReceive().
Starts a transmit transaction on an IN endpoint.
[in] | usbp | pointer to the USBDriver object |
[in] | ep | endpoint number |
[in] | buf | buffer where to fetch the data to be transmitted |
[in] | n | transaction size |
Definition at line 492 of file hal_usb.c.
References USBDriver::epc, USBEndpointConfig::in_state, osalDbgAssert, osalDbgCheck, osalDbgCheckClassI, USBInEndpointState::thread, USBDriver::transmitting, USBInEndpointState::txbuf, USBInEndpointState::txcnt, USBInEndpointState::txsize, usb_lld_start_in(), USB_MAX_ENDPOINTS, and usbGetTransmitStatusI.
Referenced by _usb_ep0in(), _usb_ep0out(), _usb_ep0setup(), obnotify(), sduDataTransmitted(), sduSOFHookI(), and usbTransmit().
Performs a receive transaction on an OUT endpoint.
[in] | usbp | pointer to the USBDriver object |
[in] | ep | endpoint number |
[out] | buf | buffer where to copy the received data |
[in] | n | transaction size. It is recommended a multiple of the packet size because the excess is discarded. |
MSG_RESET | driver not in USB_ACTIVE state or the operation has been aborted by an USB reset or a transition to the USB_SUSPENDED state. |
Definition at line 536 of file hal_usb.c.
References USBDriver::epc, osalSysLock(), osalSysUnlock(), osalThreadSuspendS(), USBEndpointConfig::out_state, USBOutEndpointState::thread, USB_ACTIVE, usbGetDriverStateI, and usbStartReceiveI().
Performs a transmit transaction on an IN endpoint.
[in] | usbp | pointer to the USBDriver object |
[in] | ep | endpoint number |
[in] | buf | buffer where to fetch the data to be transmitted |
[in] | n | transaction size |
MSG_OK | operation performed successfully. |
MSG_RESET | driver not in USB_ACTIVE state or the operation has been aborted by an USB reset or a transition to the USB_SUSPENDED state. |
Definition at line 569 of file hal_usb.c.
References USBDriver::epc, USBEndpointConfig::in_state, osalSysLock(), osalSysUnlock(), osalThreadSuspendS(), USBInEndpointState::thread, USB_ACTIVE, usbGetDriverStateI, and usbStartTransmitI().
Stalls an OUT endpoint.
[in] | usbp | pointer to the USBDriver object |
[in] | ep | endpoint number |
false | Endpoint stalled. |
true | Endpoint busy, not stalled. |
Definition at line 599 of file hal_usb.c.
References osalDbgCheck, osalDbgCheckClassI, usb_lld_stall_out(), and usbGetReceiveStatusI.
Stalls an IN endpoint.
[in] | usbp | pointer to the USBDriver object |
[in] | ep | endpoint number |
false | Endpoint stalled. |
true | Endpoint busy, not stalled. |
Definition at line 624 of file hal_usb.c.
References osalDbgCheck, osalDbgCheckClassI, usb_lld_stall_in(), and usbGetTransmitStatusI.
void usbWakeupHost | ( | USBDriver * | usbp | ) |
Host wake-up procedure.
USB_SUSPENDED
state.[in] | usbp | pointer to the USBDriver object |
Definition at line 646 of file hal_usb.c.
References USBDriver::state, usb_lld_wakeup_host, and USB_SUSPENDED.
void _usb_reset | ( | USBDriver * | usbp | ) |
USB reset routine.
This function must be invoked when an USB bus reset condition is detected.
[in] | usbp | pointer to the USBDriver object |
Definition at line 663 of file hal_usb.c.
References _usb_isr_invoke_event_cb, USBDriver::address, USBDriver::configuration, USBDriver::ep0state, USBDriver::epc, USBEndpointConfig::in_state, osalSysLockFromISR(), osalSysUnlockFromISR(), osalThreadResumeI(), USBEndpointConfig::out_state, USBDriver::receiving, USBDriver::state, USBDriver::status, USBInEndpointState::thread, USBOutEndpointState::thread, USBDriver::transmitting, USB_EP0_STP_WAITING, USB_EVENT_RESET, usb_lld_reset(), USB_MAX_ENDPOINTS, and USB_READY.
void _usb_suspend | ( | USBDriver * | usbp | ) |
USB suspend routine.
This function must be invoked when an USB bus suspend condition is detected.
[in] | usbp | pointer to the USBDriver object |
Definition at line 713 of file hal_usb.c.
References _usb_isr_invoke_event_cb, USBDriver::epc, USBEndpointConfig::in_state, osalSysLockFromISR(), osalSysUnlockFromISR(), osalThreadResumeI(), USBEndpointConfig::out_state, USBDriver::saved_state, USBDriver::state, USBInEndpointState::thread, USBOutEndpointState::thread, USB_EVENT_SUSPEND, USB_MAX_ENDPOINTS, and USB_SUSPENDED.
void _usb_wakeup | ( | USBDriver * | usbp | ) |
USB wake-up routine.
This function must be invoked when an USB bus wake-up condition is detected.
[in] | usbp | pointer to the USBDriver object |
Definition at line 753 of file hal_usb.c.
References _usb_isr_invoke_event_cb, USBDriver::saved_state, USBDriver::state, and USB_EVENT_WAKEUP.
Default EP0 SETUP callback.
This function is used by the low level driver as default handler for EP0 SETUP events.
[in] | usbp | pointer to the USBDriver object |
[in] | ep | endpoint number, always zero |
Definition at line 772 of file hal_usb.c.
References _usb_isr_invoke_event_cb, USBDriver::config, default_handler(), USBDriver::ep0n, USBDriver::ep0next, USBDriver::ep0state, osalSysLockFromISR(), osalSysUnlockFromISR(), USBConfig::requests_hook_cb, USBDriver::setup, USB_EP0_ERROR, USB_EP0_IN_SENDING_STS, USB_EP0_IN_TX, USB_EP0_OUT_RX, USB_EP0_OUT_WAITING_STS, USB_EP0_STP_WAITING, USB_EVENT_STALLED, usb_lld_stall_in(), usb_lld_stall_out(), usbReadSetup, usbStartReceiveI(), and usbStartTransmitI().
Default EP0 IN callback.
This function is used by the low level driver as default handler for EP0 IN events.
[in] | usbp | pointer to the USBDriver object |
[in] | ep | endpoint number, always zero |
Definition at line 880 of file hal_usb.c.
References _usb_isr_invoke_event_cb, USBDriver::ep0endcb, USBDriver::ep0n, USBDriver::ep0state, USBDriver::epc, USBEndpointConfig::in_maxsize, osalDbgAssert, osalSysLockFromISR(), osalSysUnlockFromISR(), USBDriver::setup, USB_EP0_ERROR, USB_EP0_IN_SENDING_STS, USB_EP0_IN_TX, USB_EP0_IN_WAITING_TX0, USB_EP0_OUT_RX, USB_EP0_OUT_WAITING_STS, USB_EP0_STP_WAITING, USB_EVENT_STALLED, usb_lld_stall_in(), usb_lld_stall_out(), usbStartReceiveI(), and usbStartTransmitI().
Default EP0 OUT callback.
This function is used by the low level driver as default handler for EP0 OUT events.
[in] | usbp | pointer to the USBDriver object |
[in] | ep | endpoint number, always zero |
Definition at line 947 of file hal_usb.c.
References _usb_isr_invoke_event_cb, USBDriver::ep0endcb, USBDriver::ep0state, osalDbgAssert, osalSysLockFromISR(), osalSysUnlockFromISR(), USB_EP0_ERROR, USB_EP0_IN_SENDING_STS, USB_EP0_IN_TX, USB_EP0_IN_WAITING_TX0, USB_EP0_OUT_RX, USB_EP0_OUT_WAITING_STS, USB_EP0_STP_WAITING, USB_EVENT_STALLED, usb_lld_stall_in(), usb_lld_stall_out(), usbGetReceiveTransactionSizeX, and usbStartTransmitI().
void usb_lld_init | ( | void | ) |
Low level USB driver initialization.
Definition at line 99 of file hal_usb_lld.c.
References usbObjectInit().
Referenced by usbInit().
void usb_lld_start | ( | USBDriver * | usbp | ) |
Configures and activates the USB peripheral.
[in] | usbp | pointer to the USBDriver object |
Definition at line 114 of file hal_usb_lld.c.
References USBDriver::state, and USB_STOP.
Referenced by usbStart().
void usb_lld_stop | ( | USBDriver * | usbp | ) |
Deactivates the USB peripheral.
[in] | usbp | pointer to the USBDriver object |
Definition at line 135 of file hal_usb_lld.c.
References USBDriver::state, and USB_READY.
Referenced by usbStop().
void usb_lld_reset | ( | USBDriver * | usbp | ) |
USB low level reset routine.
[in] | usbp | pointer to the USBDriver object |
Definition at line 156 of file hal_usb_lld.c.
References ep0config, USBDriver::epc, and usb_lld_init_endpoint().
Referenced by _usb_reset().
void usb_lld_set_address | ( | USBDriver * | usbp | ) |
Sets the USB address.
[in] | usbp | pointer to the USBDriver object |
Definition at line 172 of file hal_usb_lld.c.
Referenced by set_address().
Enables an endpoint.
[in] | usbp | pointer to the USBDriver object |
[in] | ep | endpoint number |
Definition at line 186 of file hal_usb_lld.c.
Referenced by usb_lld_reset(), and usbInitEndpointI().
void usb_lld_disable_endpoints | ( | USBDriver * | usbp | ) |
Disables all the active endpoints except the endpoint zero.
[in] | usbp | pointer to the USBDriver object |
Definition at line 200 of file hal_usb_lld.c.
Referenced by usbDisableEndpointsI().
usbepstatus_t usb_lld_get_status_out | ( | USBDriver * | usbp, |
usbep_t | ep | ||
) |
Returns the status of an OUT endpoint.
[in] | usbp | pointer to the USBDriver object |
[in] | ep | endpoint number |
EP_STATUS_DISABLED | The endpoint is not active. |
EP_STATUS_STALLED | The endpoint is stalled. |
EP_STATUS_ACTIVE | The endpoint is active. |
Definition at line 218 of file hal_usb_lld.c.
References EP_STATUS_DISABLED.
Referenced by default_handler().
usbepstatus_t usb_lld_get_status_in | ( | USBDriver * | usbp, |
usbep_t | ep | ||
) |
Returns the status of an IN endpoint.
[in] | usbp | pointer to the USBDriver object |
[in] | ep | endpoint number |
EP_STATUS_DISABLED | The endpoint is not active. |
EP_STATUS_STALLED | The endpoint is stalled. |
EP_STATUS_ACTIVE | The endpoint is active. |
Definition at line 238 of file hal_usb_lld.c.
References EP_STATUS_DISABLED.
Referenced by default_handler().
Reads a setup packet from the dedicated packet buffer.
This function must be invoked in the context of the setup_cb
callback in order to read the received setup packet.
[in] | usbp | pointer to the USBDriver object |
[in] | ep | endpoint number |
[out] | buf | buffer where to copy the packet data |
Definition at line 260 of file hal_usb_lld.c.
Prepares for a receive operation.
[in] | usbp | pointer to the USBDriver object |
[in] | ep | endpoint number |
Definition at line 276 of file hal_usb_lld.c.
Prepares for a transmit operation.
[in] | usbp | pointer to the USBDriver object |
[in] | ep | endpoint number |
Definition at line 291 of file hal_usb_lld.c.
Starts a receive operation on an OUT endpoint.
[in] | usbp | pointer to the USBDriver object |
[in] | ep | endpoint number |
Definition at line 306 of file hal_usb_lld.c.
Referenced by usbStartReceiveI().
Starts a transmit operation on an IN endpoint.
[in] | usbp | pointer to the USBDriver object |
[in] | ep | endpoint number |
Definition at line 321 of file hal_usb_lld.c.
Referenced by usbStartTransmitI().
Brings an OUT endpoint in the stalled state.
[in] | usbp | pointer to the USBDriver object |
[in] | ep | endpoint number |
Definition at line 336 of file hal_usb_lld.c.
Referenced by _usb_ep0in(), _usb_ep0out(), _usb_ep0setup(), default_handler(), and usbStallReceiveI().
Brings an IN endpoint in the stalled state.
[in] | usbp | pointer to the USBDriver object |
[in] | ep | endpoint number |
Definition at line 351 of file hal_usb_lld.c.
Referenced by _usb_ep0in(), _usb_ep0out(), _usb_ep0setup(), default_handler(), and usbStallTransmitI().
Brings an OUT endpoint in the active state.
[in] | usbp | pointer to the USBDriver object |
[in] | ep | endpoint number |
Definition at line 366 of file hal_usb_lld.c.
Referenced by default_handler().
Brings an IN endpoint in the active state.
[in] | usbp | pointer to the USBDriver object |
[in] | ep | endpoint number |
Definition at line 381 of file hal_usb_lld.c.
Referenced by default_handler().
USBDriver USBD1 |
USB1 driver identifier.
Definition at line 41 of file hal_usb_lld.c.
union { ... } ep0_state |
EP0 state.
USBInEndpointState { ... } in |
IN EP0 state.
Definition at line 57 of file hal_usb_lld.c.
USBOutEndpointState { ... } out |
OUT EP0 state.
Definition at line 61 of file hal_usb_lld.c.
|
static |
EP0 initialization structure.
Definition at line 67 of file hal_usb_lld.c.
Referenced by usb_lld_reset().