USB Device CDC API#

USB Device CDC API.

Modules#

sl_usbd_cdc_subclass_driver_t

Typedefs#

typedef void(*
sl_usbd_cdc_async_function_t)(uint8_t class_nbr, void *p_buf, uint32_t buf_len, uint32_t xfer_len, void *p_callback_arg, sl_status_t status)

Async comm callback.

Functions#

sl_status_t

FUNCTION PROTOTYPES.

sl_status_t
sl_usbd_cdc_create_instance(uint8_t subclass, sl_usbd_cdc_subclass_driver_t *p_subclass_drv, void *p_subclass_arg, uint8_t protocol, bool notify_en, uint16_t notify_interval, uint8_t *p_class_nbr)

Add a new instance of the CDC class.

sl_status_t
sl_usbd_cdc_add_to_configuration(uint8_t class_nbr, uint8_t config_nbr)

Add a CDC instance into the USB device configuration.

sl_status_t
sl_usbd_cdc_is_enabled(uint8_t class_nbr, bool *p_enabled)

Get the CDC class enable state.

sl_status_t
sl_usbd_cdc_add_data_interface(uint8_t class_nbr, bool isoc_en, uint8_t protocol, uint8_t *p_if_nbr)

Add a data interface class to the CDC communication interface class.

sl_status_t
sl_usbd_cdc_read_data(uint8_t class_nbr, uint8_t data_if_nbr, uint8_t *p_buf, uint32_t buf_len, uint16_t timeout, uint32_t *p_xfer_len)

Receive data on the CDC data interface.

sl_status_t
sl_usbd_cdc_read_data_async(uint8_t class_nbr, uint8_t data_if_nbr, uint8_t *p_buf, uint32_t buf_len, sl_usbd_cdc_async_function_t async_fnct, void *p_async_arg)

Receive data on the CDC data interface asynchronously.

sl_status_t
sl_usbd_cdc_write_data(uint8_t class_nbr, uint8_t data_if_nbr, uint8_t *p_buf, uint32_t buf_len, uint16_t timeout, uint32_t *p_xfer_len)

Send data on the CDC data interface.

sl_status_t
sl_usbd_cdc_write_data_async(uint8_t class_nbr, uint8_t data_if_nbr, uint8_t *p_buf, uint32_t buf_len, sl_usbd_cdc_async_function_t async_fnct, void *p_async_arg)

Send data on the CDC data interface asynchronously.

sl_status_t
sl_usbd_cdc_notify_host(uint8_t class_nbr, uint8_t notification, uint16_t value, uint8_t *p_buf, uint16_t data_len, bool *p_result)

Send a communication interface class notification to the host.

Macros#

#define
SL_USBD_CDC_NBR_NONE 255u

MODULE.

#define
SL_USBD_CDC_DATA_IF_NBR_NONE 255u
#define
SL_USBD_CDC_SUBCLASS_RSVD 0x00u

COMMUNICATIONS CLASS SUBCLASS CODES DEFINES.

#define
SL_USBD_CDC_SUBCLASS_DLCM 0x01u
#define
SL_USBD_CDC_SUBCLASS_ACM 0x02u
#define
SL_USBD_CDC_SUBCLASS_TCM 0x03u
#define
SL_USBD_CDC_SUBCLASS_MCCM 0x04u
#define
SL_USBD_CDC_SUBCLASS_CAPICM 0x05u
#define
SL_USBD_CDC_SUBCLASS_ENCM 0x06u
#define
SL_USBD_CDC_SUBCLASS_ATM 0x07u
#define
SL_USBD_CDC_SUBCLASS_WHCM 0x08u
#define
SL_USBD_CDC_SUBCLASS_DEV_MGMT 0x09u
#define
SL_USBD_CDC_SUBCLASS_MDLM 0x0Au
#define
SL_USBD_CDC_SUBCLASS_OBEX 0x0Bu
#define
SL_USBD_CDC_SUBCLASS_EEM 0x0Cu
#define
SL_USBD_CDC_SUBCLASS_NCM 0x0Du
#define
SL_USBD_CDC_SUBCLASS_VENDOR 0xFEu
#define
SL_USBD_CDC_COMM_PROTOCOL_NONE 0x00u

COMMUNICATION CLASS PROTOCOL CODES DEFINES.

#define
SL_USBD_CDC_COMM_PROTOCOL_AT_V250 0x01u
#define
SL_USBD_CDC_COMM_PROTOCOL_AT_PCCA_101 0x02u
#define
SL_USBD_CDC_COMM_PROTOCOL_AT_PCCA_101_ANNEX 0x03u
#define
SL_USBD_CDC_COMM_PROTOCOL_AT_GSM_7_07 0x04u
#define
SL_USBD_CDC_COMM_PROTOCOL_AT_3GPP_27_07 0x05u
#define
SL_USBD_CDC_COMM_PROTOCOL_AT_TIA_CDMA 0x06u
#define
SL_USBD_CDC_COMM_PROTOCOL_EEM 0x07u
#define
SL_USBD_CDC_COMM_PROTOCOL_EXT 0xFEu
#define
SL_USBD_CDC_COMM_PROTOCOL_VENDOR 0xFFu
#define
SL_USBD_CDC_DATA_PROTOCOL_NONE 0x00u

DATA INTERFACE CLASS PROTOCOL CODES DEFINES.

#define
SL_USBD_CDC_DATA_PROTOCOL_NTB 0x01u
#define
SL_USBD_CDC_DATA_PROTOCOL_PHY 0x30u
#define
SL_USBD_CDC_DATA_PROTOCOL_HDLC 0x31u
#define
SL_USBD_CDC_DATA_PROTOCOL_TRANS 0x32u
#define
SL_USBD_CDC_DATA_PROTOCOL_Q921M 0x50u
#define
SL_USBD_CDC_DATA_PROTOCOL_Q921 0x51u
#define
SL_USBD_CDC_DATA_PROTOCOL_Q921TM 0x52u
#define
SL_USBD_CDC_DATA_PROTOCOL_COMPRES 0x90u
#define
SL_USBD_CDC_DATA_PROTOCOL_Q9131 0x91u
#define
SL_USBD_CDC_DATA_PROTOCOL_V24 0x92u
#define
SL_USBD_CDC_DATA_PROTOCOL_CAPI 0x93u
#define
SL_USBD_CDC_DATA_PROTOCOL_HOST 0xFDu
#define
SL_USBD_CDC_DATA_PROTOCOL_CDC 0xFEu
#define
SL_USBD_CDC_DATA_PROTOCOL_VENDOR 0xFFu
#define
SL_USBD_CDC_REQ_SEND_ENCAP_COMM 0x00u

MANAGEMENT ELEMENTS REQUESTS DEFINES.

#define
SL_USBD_CDC_REQ_GET_ENCAP_RESP 0x01u
#define
SL_USBD_CDC_REQ_SET_COMM_FEATURE 0x02u
#define
SL_USBD_CDC_REQ_GET_COMM_FEATURE 0x03u
#define
SL_USBD_CDC_REQ_CLR_COMM_FEATURE 0x04u
#define
SL_USBD_CDC_REQ_SET_AUX_LINE_STATE 0x10u
#define
SL_USBD_CDC_REQ_SET_HOOK_STATE 0x11u
#define
SL_USBD_CDC_REQ_PULSE_SETUP 0x12u
#define
SL_USBD_CDC_REQ_SEND_PULSE 0x13u
#define
SL_USBD_CDC_REQ_SET_PULSE_TIME 0x14u
#define
SL_USBD_CDC_REQ_RING_AUX_JACK 0x15u
#define
SL_USBD_CDC_REQ_SET_LINE_CODING 0x20u
#define
SL_USBD_CDC_REQ_GET_LINE_CODING 0x21u
#define
SL_USBD_CDC_REQ_SET_CTRL_LINE_STATE 0x22u
#define
SL_USBD_CDC_REQ_SEND_BREAK 0x23u
#define
SL_USBD_CDC_REQ_SET_RINGER_PAARMS 0x30u
#define
SL_USBD_CDC_REQ_GET_RINGER_PARAMS 0x31u
#define
SL_USBD_CDC_REQ_SET_OPERATION_PARAMS 0x32u
#define
SL_USBD_CDC_REQ_GET_OPERATION_PARAMS 0x33u
#define
SL_USBD_CDC_REQ_SET_LINE_PARAMS 0x34u
#define
SL_USBD_CDC_REQ_GET_LINE_PARAMS 0x35u
#define
SL_USBD_CDC_REQ_DIAL_DIGITS 0x36u
#define
SL_USBD_CDC_REQ_SET_UNIT_PARAM 0x37u
#define
SL_USBD_CDC_REQ_GET_UNIT_PARAM 0x38u
#define
SL_USBD_CDC_REQ_CLR_UNUT_PARAM 0x39u
#define
SL_USBD_CDC_REQ_GET_PROFILE 0x3Au
#define
SL_USBD_CDC_REQ_SET_ETHER_MULTI_FILTER 0x40u
#define
SL_USBD_CDC_REQ_SET_ETHER_PWR_MGT_FILTER 0x41u
#define
SL_USBD_CDC_REQ_GET_ETHER_PWR_MGT_FILTER 0x42u
#define
SL_USBD_CDC_REQ_SET_ETHER_PKT_FILTER 0x43u
#define
SL_USBD_CDC_REQ_GET_ETHER_STAT 0x44u
#define
SL_USBD_CDC_REQ_SET_ATM_DATA_FMT 0x50u
#define
SL_USBD_CDC_REQ_GET_ATM_DATA_FMT 0x51u
#define
SL_USBD_CDC_REQ_GET_ATM_DEV_STAT 0x52u
#define
SL_USBD_CDC_REQ_SET_ATM_DFLT_VC 0x53u
#define
SL_USBD_CDC_REQ_GET_ATM_VC_STAT 0x54u
#define
SL_USBD_CDC_REQ_GET_NTB_PARAM2 0x80u
#define
SL_USBD_CDC_REQ_GET_NET_ADDR 0x81u
#define
SL_USBD_CDC_REQ_SET_NET_ADDR 0x82u
#define
SL_USBD_CDC_REQ_GET_NTB_FMT 0x83u
#define
SL_USBD_CDC_REQ_SET_NTB_FMT 0x84u
#define
SL_USBD_CDC_REQ_GET_NTB_INPUT_SIZE 0x85u
#define
SL_USBD_CDC_REQ_SET_NTB_INPUT_SIZE 0x86u
#define
SL_USBD_CDC_REQ_GET_MAX_DATAGRAM_SIZE 0x87u
#define
SL_USBD_CDC_REQ_SET_MAX_DATAGRAM_SIZE 0x88u
#define
SL_USBD_CDC_REQ_GET_CRC_MODE 0x89u
#define
SL_USBD_CDC_REQ_SET_CRC_MODE 0x8Au
#define
SL_USBD_CDC_DESC_TYPE_CS_IF 0x24u

CDC FUNCTIONAL DESCRIPTOR TYPE DEFINES.

#define
SL_USBD_CDC_DESC_TYPE_CS_EP 0x25u
#define
SL_USBD_CDC_DESC_SUBTYPE_HEADER 0x00u

CDC FUNCTIONAL DESCRIPTOR SUBTYPE DEFINES.

#define
SL_USBD_CDC_DESC_SUBTYPE_CALL_MGMT 0x01u
#define
SL_USBD_CDC_DESC_SUBTYPE_ACM 0x02u
#define
SL_USBD_CDC_DESC_SUBTYPE_DLM 0x03u
#define
SL_USBD_CDC_DESC_SUBTYPE_TEL_RINGER 0x04u
#define
SL_USBD_CDC_DESC_SUBTYPE_TEL_CALL_LINE 0x05u
#define
SL_USBD_CDC_DESC_SUBTYPE_UNION 0x06u
#define
SL_USBD_CDC_DESC_SUBTYPE_COUNTRY_SEL 0x07u
#define
SL_USBD_CDC_DESC_SUBTYPE_TEL_OPERA 0x08u
#define
SL_USBD_CDC_DESC_SUBTYPE_USB_TERM 0x09u
#define
SL_USBD_CDC_DESC_SUBTYPE_NET_CH_TERM 0x0Au
#define
SL_USBD_CDC_DESC_SUBTYPE_PROTOCOL_UNIT 0x0Bu
#define
SL_USBD_CDC_DESC_SUBTYPE_EXT_UNIT 0x0Cu
#define
SL_USBD_CDC_DESC_SUBTYPE_MULTI_CH_MGMT 0x0Du
#define
SL_USBD_CDC_DESC_SUBTYPE_CAPI_CTRL 0x0Eu
#define
SL_USBD_CDC_DESC_SUBTYPE_ETHER_NET 0x0Fu
#define
SL_USBD_CDC_DESC_SUBTYPE_ATM_NET 0x10u
#define
SL_USBD_CDC_DESC_SUBTYPE_WIRELESS_CTRL 0x11u
#define
SL_USBD_CDC_DESC_SUBTYPE_MOBILE DLM 0x12u
#define
SL_USBD_CDC_DESC_SUBTYPE_DETAIL 0x13u
#define
SL_USBD_CDC_DESC_SUBTYPE_DEV_MGMT 0x14u
#define
SL_USBD_CDC_DESC_SUBTYPE_OBEX 0x15u
#define
SL_USBD_CDC_DESC_SUBTYPE_CMD_SET 0x16u
#define
SL_USBD_CDC_DESC_SUBTYPE_CMD_SET_DETAIL 0x17u
#define
SL_USBD_CDC_DESC_SUBTYPE_TCM 0x18u
#define
SL_USBD_CDC_DESC_SUBTYPE_OBEX_SERV 0x19u
#define
SL_USBD_CDC_DESC_SUBTYPE_NCM 0x1Au
#define
SL_USBD_CDC_DESC_SUBTYPE_VENDOR 0xFEu
#define
SL_USBD_CDC_NOTIFICATION_HEADER 8u

CDC NOTIFICATION DEFINES.

Typedef Documentation#

sl_usbd_cdc_async_function_t#

typedef void(* sl_usbd_cdc_async_function_t) (uint8_t class_nbr, void *p_buf, uint32_t buf_len, uint32_t xfer_len, void *p_callback_arg, sl_status_t status) )(uint8_t class_nbr, void *p_buf, uint32_t buf_len, uint32_t xfer_len, void *p_callback_arg, sl_status_t status)

Async comm callback.


Function Documentation#

sl_usbd_cdc_init#

sl_status_t sl_usbd_cdc_init (void )

FUNCTION PROTOTYPES.

Parameters
TypeDirectionArgument NameDescription
voidN/A

CDC FUNCTIONS

Initializes CDC class.

Returns

  • Returns SL_STATUS_OK on success or another SL_STATUS code on failure.


sl_usbd_cdc_create_instance#

sl_status_t sl_usbd_cdc_create_instance (uint8_t subclass, sl_usbd_cdc_subclass_driver_t * p_subclass_drv, void * p_subclass_arg, uint8_t protocol, bool notify_en, uint16_t notify_interval, uint8_t * p_class_nbr)

Add a new instance of the CDC class.

Parameters
TypeDirectionArgument NameDescription
uint8_tN/Asubclass

Communication class subclass subcode (see Note #1).

sl_usbd_cdc_subclass_driver_t *N/Ap_subclass_drv

Pointer to the CDC subclass driver.

void *N/Ap_subclass_arg

Pointer to the CDC subclass driver argument.

uint8_tN/Aprotocol

Communication class protocol code.

boolN/Anotify_en

Notification enabled : true Enable CDC class notifications. false Disable CDC class notifications.

uint16_tN/Anotify_interval

Notification interval in milliseconds (must be a power of 2).

uint8_t *N/Ap_class_nbr

Pointer to a variable that will receive class instance number. The variable is set to CDC class instance number if no errors are returned., otherwise it is set to SL_USBD_CDC_NBR_NONE.

Returns

  • Returns SL_STATUS_OK on success or another SL_STATUS code on failure.

Note

  • (1) Communication class subclass codes are defined in 'sl_usbd_class_cdc.h' 'SL_USBD_CDC_SUBCLASS_XXXX'.


sl_usbd_cdc_add_to_configuration#

sl_status_t sl_usbd_cdc_add_to_configuration (uint8_t class_nbr, uint8_t config_nbr)

Add a CDC instance into the USB device configuration.

Parameters
TypeDirectionArgument NameDescription
uint8_tN/Aclass_nbr

Class instance number.

uint8_tN/Aconfig_nbr

Configuration index to which to add the new CDC class interface.

Returns

  • Returns SL_STATUS_OK on success or another SL_STATUS code on failure.


sl_usbd_cdc_is_enabled#

sl_status_t sl_usbd_cdc_is_enabled (uint8_t class_nbr, bool * p_enabled)

Get the CDC class enable state.

Parameters
TypeDirectionArgument NameDescription
uint8_tN/Aclass_nbr

Class instance number.

bool *N/Ap_enabled

Pointer to a boolean variable that will receive enable state. The variable is set to true if CDC class is enabled. The variable is set to false if CDC class is not enabled.

Returns

  • Returns SL_STATUS_OK on success or another SL_STATUS code on failure.


sl_usbd_cdc_add_data_interface#

sl_status_t sl_usbd_cdc_add_data_interface (uint8_t class_nbr, bool isoc_en, uint8_t protocol, uint8_t * p_if_nbr)

Add a data interface class to the CDC communication interface class.

Parameters
TypeDirectionArgument NameDescription
uint8_tN/Aclass_nbr

Class instance number.

boolN/Aisoc_en

Data interface isochronous enable (see Note #1) :

  • true Data interface uses isochronous EPs.

  • false Data interface uses bulk EPs.

uint8_tN/Aprotocol

Data interface protocol code.

uint8_t *N/Ap_if_nbr

Pointer to a variable that will receive data interface number.

Returns

  • Returns SL_STATUS_OK on success or another SL_STATUS code on failure.

Note

  • (1) The value of 'isoc_en' must be false. Isochronous EPs are not supported.


sl_usbd_cdc_read_data#

sl_status_t sl_usbd_cdc_read_data (uint8_t class_nbr, uint8_t data_if_nbr, uint8_t * p_buf, uint32_t buf_len, uint16_t timeout, uint32_t * p_xfer_len)

Receive data on the CDC data interface.

Parameters
TypeDirectionArgument NameDescription
uint8_tN/Aclass_nbr

Class instance number.

uint8_tN/Adata_if_nbr

CDC data interface number.

uint8_t *N/Ap_buf

Pointer to the destination buffer to receive data.

uint32_tN/Abuf_len

Number of octets to receive.

uint16_tN/Atimeout

Timeout in milliseconds.

uint32_t *N/Ap_xfer_len

Pointer to a variable that will receive transfer length. If no errors are returned, the variable is set to number of octets received, otherwise it is set to 0.

Returns

  • Returns SL_STATUS_OK on success or another SL_STATUS code on failure.


sl_usbd_cdc_read_data_async#

sl_status_t sl_usbd_cdc_read_data_async (uint8_t class_nbr, uint8_t data_if_nbr, uint8_t * p_buf, uint32_t buf_len, sl_usbd_cdc_async_function_t async_fnct, void * p_async_arg)

Receive data on the CDC data interface asynchronously.

Parameters
TypeDirectionArgument NameDescription
uint8_tN/Aclass_nbr

Class instance number.

uint8_tN/Adata_if_nbr

CDC data interface number.

uint8_t *N/Ap_buf

Pointer to the destination buffer to receive data.

uint32_tN/Abuf_len

Number of octets to receive.

sl_usbd_cdc_async_function_tN/Aasync_fnct

Function that will be invoked upon completion of receive operation.

void *N/Ap_async_arg

Pointer to the argument that will be passed as parameter of 'async_fnct'.

Returns

  • Returns SL_STATUS_OK on success or another SL_STATUS code on failure.


sl_usbd_cdc_write_data#

sl_status_t sl_usbd_cdc_write_data (uint8_t class_nbr, uint8_t data_if_nbr, uint8_t * p_buf, uint32_t buf_len, uint16_t timeout, uint32_t * p_xfer_len)

Send data on the CDC data interface.

Parameters
TypeDirectionArgument NameDescription
uint8_tN/Aclass_nbr

Class instance number.

uint8_tN/Adata_if_nbr

CDC data interface number.

uint8_t *N/Ap_buf

Pointer to the buffer of data that will be transmitted.

uint32_tN/Abuf_len

Number of octets to transmit.

uint16_tN/Atimeout

Timeout in milliseconds.

uint32_t *N/Ap_xfer_len

Pointer to a variable that will receive transfer length. If no errors are returned, the variable is set to number of octets transmitted, otherwise it is set to 0.

Returns

  • Returns SL_STATUS_OK on success or another SL_STATUS code on failure.


sl_usbd_cdc_write_data_async#

sl_status_t sl_usbd_cdc_write_data_async (uint8_t class_nbr, uint8_t data_if_nbr, uint8_t * p_buf, uint32_t buf_len, sl_usbd_cdc_async_function_t async_fnct, void * p_async_arg)

Send data on the CDC data interface asynchronously.

Parameters
TypeDirectionArgument NameDescription
uint8_tN/Aclass_nbr

Class instance number.

uint8_tN/Adata_if_nbr

CDC data interface number.

uint8_t *N/Ap_buf

Pointer to the buffer of data that will be transmitted.

uint32_tN/Abuf_len

Number of octets to transmit.

sl_usbd_cdc_async_function_tN/Aasync_fnct

Function that will be invoked upon completion of transfer operation.

void *N/Ap_async_arg

Pointer to the argument that will be passed as parameter of 'async_fnct'.

Returns

  • Returns SL_STATUS_OK on success or another SL_STATUS code on failure.


sl_usbd_cdc_notify_host#

sl_status_t sl_usbd_cdc_notify_host (uint8_t class_nbr, uint8_t notification, uint16_t value, uint8_t * p_buf, uint16_t data_len, bool * p_result)

Send a communication interface class notification to the host.

Parameters
TypeDirectionArgument NameDescription
uint8_tN/Aclass_nbr

Class instance number.

uint8_tN/Anotification

Notification code.

uint16_tN/Avalue

Notification value.

uint8_t *N/Ap_buf

Pointer to the notification buffer (see Note #1).

uint16_tN/Adata_len

Length of the data portion of the notification.

bool *N/Ap_result

Pointer to a boolean variable that will receive the result of the operation. The variable is set to true if no errors are encountered, otherwise it is set to false.

Returns

  • Returns SL_STATUS_OK on success or another SL_STATUS code on failure.

Note

  • (1) The notification buffer MUST contain space for the notification header 'SL_USBD_CDC_NOTIFICATION_HEADER' plus the variable-length data portion.