USB Device CDC API

Description

USB Device CDC API.

Data Structures

struct  sl_usbd_cdc_subclass_driver_t
 CDC Subclass Driver.

Functions

sl_status_t sl_usbd_cdc_init (void)
 Initializes CDC class.
 
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_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_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
 
#define SL_USBD_CDC_DATA_IF_NBR_NONE   255u
 
#define SL_USBD_CDC_SUBCLASS_RSVD   0x00u
 
#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
 
#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
 
#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
 
#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
 
#define SL_USBD_CDC_DESC_TYPE_CS_EP   0x25u
 
#define SL_USBD_CDC_DESC_SUBTYPE_HEADER   0x00u
 
#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

Function Documentation

◆ sl_usbd_cdc_init()

sl_status_t sl_usbd_cdc_init ( void  )

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
subclassCommunication class subclass subcode (see Note #1).
p_subclass_drvPointer to the CDC subclass driver.
p_subclass_argPointer to the CDC subclass driver argument.
protocolCommunication class protocol code.
notify_enNotification enabled : true Enable CDC class notifications. false Disable CDC class notifications.
notify_intervalNotification interval in milliseconds (must be a power of 2).
p_class_nbrPointer 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
class_nbrClass instance number.
config_nbrConfiguration 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
class_nbrClass instance number.
p_enabledPointer 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
class_nbrClass instance number.
isoc_enData interface isochronous enable (see Note #1) :
  • true Data interface uses isochronous EPs.
  • false Data interface uses bulk EPs.
protocolData interface protocol code.
p_if_nbrPointer 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
class_nbrClass instance number.
data_if_nbrCDC data interface number.
p_bufPointer to the destination buffer to receive data.
buf_lenNumber of octets to receive.
timeoutTimeout in milliseconds.
p_xfer_lenPointer 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_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
class_nbrClass instance number.
data_if_nbrCDC data interface number.
p_bufPointer to the buffer of data that will be transmitted.
buf_lenNumber of octets to transmit.
timeoutTimeout in milliseconds.
p_xfer_lenPointer 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_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
class_nbrClass instance number.
notificationNotification code.
valueNotification value.
p_bufPointer to the notification buffer (see Note #1).
data_lenLength of the data portion of the notification.
p_resultPointer 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.