Microchip® Advanced Software Framework

udi_cdc.c File Reference

USB Device Communication Device Class (CDC) interface.

Copyright (c) 2009-2018 Microchip Technology Inc. and its subsidiaries.

#include "conf_usb.h"
#include "usb_protocol.h"
#include "usb_protocol_cdc.h"
#include "udd.h"
#include "udc.h"
#include "udi_cdc.h"
#include <string.h>

Macros

#define UDI_CDC_DATA_EP_IN_TO_PORT(index, unused)
 
#define UDI_CDC_DATA_EP_OUT_TO_PORT(index, unused)
 
#define UDI_CDC_GET_PORT_FROM_COMM_EP(iface, unused)
 
#define UDI_CDC_IFACE_COMM_TO_PORT(iface, unused)
 
#define UDI_CDC_PORT_TO_COMM_EP(index, unused)
 
#define UDI_CDC_PORT_TO_DATA_EP_IN(index, unused)
 
#define UDI_CDC_PORT_TO_DATA_EP_OUT(index, unused)
 
#define UDI_CDC_PORT_TO_IFACE_COMM(index, unused)
 
#define UDI_CDC_RX_BUFFERS   (UDI_CDC_DATA_EPS_FS_SIZE)
 
#define UDI_CDC_TX_BUFFERS   (UDI_CDC_DATA_EPS_FS_SIZE)
 

Functions

void udi_cdc_comm_disable (void)
 
bool udi_cdc_comm_enable (void)
 
bool udi_cdc_comm_setup (void)
 
void udi_cdc_ctrl_signal_dcd (bool b_set)
 Notify a state change of DCD signal. More...
 
void udi_cdc_ctrl_signal_dsr (bool b_set)
 Notify a state change of DSR signal. More...
 
void udi_cdc_data_disable (void)
 
bool udi_cdc_data_enable (void)
 
bool udi_cdc_data_setup (void)
 
void udi_cdc_data_sof_notify (void)
 
iram_size_t udi_cdc_get_free_tx_buffer (void)
 Gets the number of free byte in TX buffer. More...
 
iram_size_t udi_cdc_get_nb_received_data (void)
 Gets the number of byte received. More...
 
int udi_cdc_getc (void)
 Waits and gets a value on CDC line. More...
 
uint8_t udi_cdc_getsetting (void)
 
bool udi_cdc_is_rx_ready (void)
 This function checks if a character has been received on the CDC line. More...
 
bool udi_cdc_is_tx_ready (void)
 This function checks if a new character sent is possible The type int is used to support scanf redirection from compiler LIB. More...
 
void udi_cdc_multi_ctrl_signal_dcd (uint8_t port, bool b_set)
 Notify a state change of DCD signal. More...
 
void udi_cdc_multi_ctrl_signal_dsr (uint8_t port, bool b_set)
 Notify a state change of DSR signal. More...
 
iram_size_t udi_cdc_multi_get_free_tx_buffer (uint8_t port)
 Gets the number of free byte in TX buffer. More...
 
iram_size_t udi_cdc_multi_get_nb_received_data (uint8_t port)
 Gets the number of byte received. More...
 
int udi_cdc_multi_getc (uint8_t port)
 Waits and gets a value on CDC line. More...
 
bool udi_cdc_multi_is_rx_ready (uint8_t port)
 This function checks if a character has been received on the CDC line. More...
 
bool udi_cdc_multi_is_tx_ready (uint8_t port)
 This function checks if a new character sent is possible The type int is used to support scanf redirection from compiler LIB. More...
 
int udi_cdc_multi_putc (uint8_t port, int value)
 Puts a byte on CDC line The type int is used to support printf redirection from compiler LIB. More...
 
iram_size_t udi_cdc_multi_read_buf (uint8_t port, void *buf, iram_size_t size)
 Reads a RAM buffer on CDC line. More...
 
iram_size_t udi_cdc_multi_read_no_polling (uint8_t port, void *buf, iram_size_t size)
 Non polling reads of a up to 'size' data from CDC line. More...
 
void udi_cdc_multi_signal_framing_error (uint8_t port)
 Notify a framing error. More...
 
void udi_cdc_multi_signal_overrun (uint8_t port)
 Notify a overrun. More...
 
void udi_cdc_multi_signal_parity_error (uint8_t port)
 Notify a parity error. More...
 
iram_size_t udi_cdc_multi_write_buf (uint8_t port, const void *buf, iram_size_t size)
 Writes a RAM buffer on CDC line. More...
 
int udi_cdc_putc (int value)
 Puts a byte on CDC line The type int is used to support printf redirection from compiler LIB. More...
 
iram_size_t udi_cdc_read_buf (void *buf, iram_size_t size)
 Reads a RAM buffer on CDC line. More...
 
iram_size_t udi_cdc_read_no_polling (void *buf, iram_size_t size)
 Non polling reads of a up to 'size' data from CDC line. More...
 
void udi_cdc_signal_framing_error (void)
 Notify a framing error. More...
 
void udi_cdc_signal_overrun (void)
 Notify a overrun. More...
 
void udi_cdc_signal_parity_error (void)
 Notify a parity error. More...
 
iram_size_t udi_cdc_write_buf (const void *buf, iram_size_t size)
 Writes a RAM buffer on CDC line. More...
 
Routines to control serial line
static uint8_t udi_cdc_setup_to_port (void)
 Returns the port number corresponding at current setup request. More...
 
static void udi_cdc_line_coding_received (void)
 Sends line coding to application. More...
 
static void udi_cdc_ctrl_state_change (uint8_t port, bool b_set, le16_t bit_mask)
 Records new state. More...
 
static void udi_cdc_ctrl_state_notify (uint8_t port, udd_ep_id_t ep)
 Check and eventually notify the USB host of new state. More...
 
static void udi_cdc_serial_state_msg_sent (udd_ep_status_t status, iram_size_t n, udd_ep_id_t ep)
 Ack sent of serial state message Callback called after serial state message sent. More...
 
Routines to process data transfer
static bool udi_cdc_rx_start (uint8_t port)
 Enable the reception of data from the USB host. More...
 
static void udi_cdc_data_received (udd_ep_status_t status, iram_size_t n, udd_ep_id_t ep)
 Update rx buffer management with a new data Callback called after data reception on USB line. More...
 
static void udi_cdc_data_sent (udd_ep_status_t status, iram_size_t n, udd_ep_id_t ep)
 Ack sent of tx buffer Callback called after data transfer on USB line. More...
 
static void udi_cdc_tx_send (uint8_t port)
 Send buffer on line or wait a SOF event. More...
 

Variables

UDC_DESC_STORAGE udi_api_t udi_api_cdc_comm
 Global structure which contains standard UDI API for UDC. More...
 
UDC_DESC_STORAGE udi_api_t udi_api_cdc_data
 
Information about configuration of communication line
static COMPILER_WORD_ALIGNED
usb_cdc_line_coding_t 
udi_cdc_line_coding [UDI_CDC_PORT_NB]
 
static bool udi_cdc_serial_state_msg_ongoing [UDI_CDC_PORT_NB]
 
static volatile le16_t udi_cdc_state [UDI_CDC_PORT_NB]
 
static COMPILER_WORD_ALIGNED
usb_cdc_notify_serial_state_t 
uid_cdc_state_msg [UDI_CDC_PORT_NB]
 
static volatile uint8_t udi_cdc_nb_comm_enabled = 0
 Status of CDC COMM interfaces. More...
 

Variables to manage RX/TX transfer requests

Two buffers for each sense are used to optimize the speed.

#define UDI_CDC_TRANS_HALTED   2
 Define a transfer halted. More...
 
static volatile uint8_t udi_cdc_nb_data_enabled = 0
 Status of CDC DATA interfaces. More...
 
static volatile bool udi_cdc_data_running = false
 
static COMPILER_WORD_ALIGNED
uint8_t 
udi_cdc_rx_buf [UDI_CDC_PORT_NB][2][UDI_CDC_RX_BUFFERS]
 Buffer to receive data. More...
 
static volatile uint16_t udi_cdc_rx_buf_nb [UDI_CDC_PORT_NB][2]
 Data available in RX buffers. More...
 
static volatile uint8_t udi_cdc_rx_buf_sel [UDI_CDC_PORT_NB]
 Give the current RX buffer used (rx0 if 0, rx1 if 1) More...
 
static volatile uint16_t udi_cdc_rx_pos [UDI_CDC_PORT_NB]
 Read position in current RX buffer. More...
 
static volatile bool udi_cdc_rx_trans_ongoing [UDI_CDC_PORT_NB]
 Signal a transfer on-going. More...
 
static COMPILER_WORD_ALIGNED
uint8_t 
udi_cdc_tx_buf [UDI_CDC_PORT_NB][2][UDI_CDC_TX_BUFFERS]
 Buffer to send data. More...
 
static uint16_t udi_cdc_tx_buf_nb [UDI_CDC_PORT_NB][2]
 Data available in TX buffers. More...
 
static volatile uint8_t udi_cdc_tx_buf_sel [UDI_CDC_PORT_NB]
 Give current TX buffer used (tx0 if 0, tx1 if 1) More...
 
static uint16_t udi_cdc_tx_sof_num [UDI_CDC_PORT_NB]
 Value of SOF during last TX transfer. More...
 
static volatile bool udi_cdc_tx_trans_ongoing [UDI_CDC_PORT_NB]
 Signal a transfer on-going. More...
 
static volatile bool udi_cdc_tx_both_buf_to_send [UDI_CDC_PORT_NB]
 Signal that both buffer content data to send. More...
 

#define UDI_CDC_DATA_EP_IN_TO_PORT (   index,
  unused 
)
Value:
case UDI_CDC_DATA_EP_IN_##index: \
port = index; \
break;

Referenced by udi_cdc_data_sent().

#define UDI_CDC_DATA_EP_OUT_TO_PORT (   index,
  unused 
)
Value:
case UDI_CDC_DATA_EP_OUT_##index: \
port = index; \
break;

Referenced by udi_cdc_data_received().

#define UDI_CDC_GET_PORT_FROM_COMM_EP (   iface,
  unused 
)
Value:
case UDI_CDC_COMM_EP_##iface: \
port = iface; \
break;

Referenced by udi_cdc_serial_state_msg_sent().

#define UDI_CDC_IFACE_COMM_TO_PORT (   iface,
  unused 
)
Value:
case UDI_CDC_COMM_IFACE_NUMBER_##iface: \
port = iface; \
break;

Referenced by udi_cdc_setup_to_port().

#define UDI_CDC_PORT_TO_COMM_EP (   index,
  unused 
)
Value:
case index: \
ep_comm = UDI_CDC_COMM_EP_##index; \
break;

Referenced by udi_cdc_ctrl_state_change().

#define UDI_CDC_PORT_TO_DATA_EP_IN (   index,
  unused 
)
Value:
case index: \
ep = UDI_CDC_DATA_EP_IN_##index; \
break;

Referenced by udi_cdc_tx_send().

#define UDI_CDC_PORT_TO_DATA_EP_OUT (   index,
  unused 
)
Value:
case index: \
ep = UDI_CDC_DATA_EP_OUT_##index; \
break;

Referenced by udi_cdc_rx_start().

#define UDI_CDC_PORT_TO_IFACE_COMM (   index,
  unused 
)
Value:
case index: \
iface_comm_num = UDI_CDC_COMM_IFACE_NUMBER_##index; \
break;

Referenced by udi_cdc_comm_enable().

#define UDI_CDC_RX_BUFFERS   (UDI_CDC_DATA_EPS_FS_SIZE)
#define UDI_CDC_TRANS_HALTED   2

Define a transfer halted.

volatile uint8_t udi_cdc_nb_comm_enabled = 0
static

Status of CDC COMM interfaces.

Referenced by udi_cdc_comm_disable(), and udi_cdc_comm_enable().

volatile uint8_t udi_cdc_nb_data_enabled = 0
static

Status of CDC DATA interfaces.

Referenced by udi_cdc_data_disable(), and udi_cdc_data_enable().

volatile uint8_t udi_cdc_rx_buf_sel[UDI_CDC_PORT_NB]
static
volatile bool udi_cdc_rx_trans_ongoing[UDI_CDC_PORT_NB]
static

Signal a transfer on-going.

Referenced by udi_cdc_data_enable(), udi_cdc_data_received(), and udi_cdc_rx_start().

bool udi_cdc_serial_state_msg_ongoing[UDI_CDC_PORT_NB]
static
volatile bool udi_cdc_tx_both_buf_to_send[UDI_CDC_PORT_NB]
static

Signal that both buffer content data to send.

Referenced by udi_cdc_data_enable(), udi_cdc_data_sent(), udi_cdc_multi_get_free_tx_buffer(), and udi_cdc_tx_send().

COMPILER_WORD_ALIGNED uint8_t udi_cdc_tx_buf[UDI_CDC_PORT_NB][2][UDI_CDC_TX_BUFFERS]
static

Buffer to send data.

Referenced by udi_cdc_multi_putc(), udi_cdc_multi_write_buf(), and udi_cdc_tx_send().

volatile uint8_t udi_cdc_tx_buf_sel[UDI_CDC_PORT_NB]
static
uint16_t udi_cdc_tx_sof_num[UDI_CDC_PORT_NB]
static

Value of SOF during last TX transfer.

Referenced by udi_cdc_data_enable(), and udi_cdc_tx_send().

volatile bool udi_cdc_tx_trans_ongoing[UDI_CDC_PORT_NB]
static