96 #define CDC_BULK_EP_SIZE (USB_FS_BULK_EP_MAXSIZE)
97 #define CDC_USB_RX_BUF_SIZ CDC_BULK_EP_SIZE
98 #define CDC_USB_TX_BUF_SIZ 127
102 #define CDC_RX_TIMEOUT SL_MAX(10U, 50000 / (cdcLineCoding.dwDTERate))
122 static
void DmaSetup(
void);
126 static
void SerialPortInit(
void);
127 static
void UartRxTimeout(
void);
148 static const uint8_t *usbRxBuffer[ 2 ] = { usbRxBuffer0, usbRxBuffer1 };
149 static const uint8_t *uartRxBuffer[ 2 ] = { uartRxBuffer0, uartRxBuffer1 };
151 static int usbRxIndex, usbBytesReceived;
152 static int uartRxIndex, uartRxCount;
153 static int LastUsbTxCnt;
155 static bool dmaRxCompleted;
156 static bool usbRxActive, dmaTxActive;
157 static bool usbTxActive, dmaRxActive;
194 if ( ( setup->
wValue == 0 ) &&
195 ( setup->
wIndex == CDC_CTRL_INTERFACE_NO ) &&
200 USBD_Write(0, (
void*) &cdcLineCoding, 7, NULL);
207 if ( ( setup->
wValue == 0 ) &&
208 ( setup->
wIndex == CDC_CTRL_INTERFACE_NO ) &&
213 USBD_Read(0, (
void*) &cdcLineCoding, 7, LineCodingReceived);
220 if ( ( setup->
wIndex == CDC_CTRL_INTERFACE_NO ) &&
256 USBD_Read(CDC_EP_DATA_OUT, (
void*) usbRxBuffer[ usbRxIndex ],
257 CDC_USB_RX_BUF_SIZ, UsbDataReceived);
265 dmaRxCompleted =
true;
267 (
void *) uartRxBuffer[ uartRxIndex ],
268 (
void *) &(CDC_UART->RXDATA),
269 CDC_USB_TX_BUF_SIZ - 1);
279 DMA->CHENC = ( 1 << CDC_UART_TX_DMA_CHANNEL ) |
280 ( 1 << CDC_UART_RX_DMA_CHANNEL );
289 DMA->CHENC = ( 1 << CDC_UART_TX_DMA_CHANNEL ) |
290 ( 1 << CDC_UART_RX_DMA_CHANNEL );
321 (
void *) &(CDC_UART->TXDATA),
322 (
void *) usbRxBuffer[ usbRxIndex ^ 1 ],
326 USBD_Read(CDC_EP_DATA_OUT, (
void*) usbRxBuffer[ usbRxIndex ],
327 CDC_USB_RX_BUF_SIZ, UsbDataReceived);
333 usbBytesReceived = xferred;
346 static void DmaTxComplete(
unsigned int channel,
bool primary,
void *user)
363 (
void *) &(CDC_UART->TXDATA),
364 (
void *) usbRxBuffer[ usbRxIndex ^ 1 ],
365 usbBytesReceived - 1);
369 USBD_Read(CDC_EP_DATA_OUT, (
void*) usbRxBuffer[ usbRxIndex ],
370 CDC_USB_RX_BUF_SIZ, UsbDataReceived);
404 USBD_Write(CDC_EP_DATA_IN, (
void*) uartRxBuffer[ uartRxIndex ^ 1],
405 uartRxCount, UsbDataTransmitted);
406 LastUsbTxCnt = uartRxCount;
409 dmaRxCompleted =
true;
411 (
void *) uartRxBuffer[ uartRxIndex ],
412 (
void *) &(CDC_UART->RXDATA),
413 CDC_USB_TX_BUF_SIZ - 1);
433 static void DmaRxComplete(
unsigned int channel,
bool primary,
void *user)
450 uartRxCount = CDC_USB_TX_BUF_SIZ;
454 uartRxCount = CDC_USB_TX_BUF_SIZ - 1 -
463 USBD_Write(CDC_EP_DATA_IN, (
void*) uartRxBuffer[ uartRxIndex ^ 1],
464 uartRxCount, UsbDataTransmitted);
465 LastUsbTxCnt = uartRxCount;
468 dmaRxCompleted =
true;
470 (
void *) uartRxBuffer[ uartRxIndex ],
471 (
void *) &(CDC_UART->RXDATA),
472 CDC_USB_TX_BUF_SIZ - 1);
493 static void UartRxTimeout(
void)
498 dmaCtrl = dmaControlBlock[ 1 ].
CTRL;
506 cnt = CDC_USB_TX_BUF_SIZ - 1 -
509 if ((cnt == 0) && (LastUsbTxCnt == CDC_BULK_EP_SIZE))
516 DMA->CHENC = 1 << CDC_UART_RX_DMA_CHANNEL;
517 dmaRxCompleted =
false;
519 DmaRxComplete(CDC_UART_RX_DMA_CHANNEL,
true, NULL);
523 if ((cnt > 0) && (cnt == uartRxCount))
530 DMA->CHENC = 1 << CDC_UART_RX_DMA_CHANNEL;
531 dmaRxCompleted =
false;
533 DmaRxComplete(CDC_UART_RX_DMA_CHANNEL,
true, NULL);
565 if (cdcLineCoding.bDataBits == 5)
568 else if (cdcLineCoding.bDataBits == 6)
571 else if (cdcLineCoding.bDataBits == 7)
574 else if (cdcLineCoding.bDataBits == 8)
577 else if (cdcLineCoding.bDataBits == 16)
584 if (cdcLineCoding.bParityType == 0)
587 else if (cdcLineCoding.bParityType == 1)
590 else if (cdcLineCoding.bParityType == 2)
593 else if (cdcLineCoding.bParityType == 3)
596 else if (cdcLineCoding.bParityType == 4)
603 if (cdcLineCoding.bCharFormat == 0)
606 else if (cdcLineCoding.bCharFormat == 1)
609 else if (cdcLineCoding.bCharFormat == 2)
616 CDC_UART->FRAME = frame;
627 static void DmaSetup(
void)
642 DmaTxCallBack.
cbFunc = DmaTxComplete;
648 chnlCfgTx.
select = CDC_TX_DMA_SIGNAL;
649 chnlCfgTx.
cb = &DmaTxCallBack;
660 descrCfgTx.
hprot = 0;
663 DMA_CfgDescr(CDC_UART_TX_DMA_CHANNEL,
true, &descrCfgTx);
668 DmaRxCallBack.
cbFunc = DmaRxComplete;
674 chnlCfgRx.
select = CDC_RX_DMA_SIGNAL;
675 chnlCfgRx.
cb = &DmaRxCallBack;
686 descrCfgRx.
hprot = 0;
689 DMA_CfgDescr(CDC_UART_RX_DMA_CHANNEL,
true, &descrCfgRx);
695 static void SerialPortInit(
void)
706 CDC_ENABLE_DK_UART_SWITCH();
717 CDC_UART->ROUTE = CDC_UART_ROUTE;
Clock management unit (CMU) API.
#define USB_CDC_SETCTRLLINESTATE
#define _DMA_CTRL_N_MINUS_1_MASK
Board support package API definitions.
#define USART_FRAME_DATABITS_SEVEN
#define CORE_DECLARE_IRQ_STATE
#define _DMA_CTRL_N_MINUS_1_SHIFT
#define USB_CDC_SETLINECODING
DMA_ArbiterConfig_TypeDef arbRate
void USBTIMER_Stop(uint32_t id)
Stop a timer.
#define SL_PACK_END()
Macro for handling packed structs. Use this macro after the struct definition. With GCC...
DMA_DataInc_TypeDef dstInc
Callback structure that can be used to define DMA complete actions.
void CDC_Init(void)
CDC device initialization.
#define USART_FRAME_STOPBITS_TWO
DMA_CB_TypeDef * cb
User definable callback handling configuration.
#define DMA_CTRL_CYCLE_CTRL_INVALID
#define USB_CDC_GETLINECODING
CMSIS Cortex-M Peripheral Access Layer for Silicon Laboratories microcontroller devices.
#define SL_ALIGN(X)
Macro for aligning a variable. Use this macro before the variable definition. X denotes the stora...
#define USART_FRAME_PARITY_EVEN
Universal synchronous/asynchronous receiver/transmitter (USART/UART) peripheral API.
USART_Enable_TypeDef enable
General purpose utilities.
#define SL_PACK_START(x)
Macro for handling packed structs. Use this macro before the struct definition. X denotes the max...
void CDC_StateChangeEvent(USBD_State_TypeDef oldState, USBD_State_TypeDef newState)
Callback function called each time the USB device state is changed. Starts CDC operation when device ...
USB Setup request package.
void DMA_ActivateBasic(unsigned int channel, bool primary, bool useBurst, void *dst, const void *src, unsigned int nMinus1)
Activate DMA basic cycle (used for memory-peripheral transfers).
USBD_State_TypeDef
USB device state enumerator.
USB_Status_TypeDef
USB transfer status enumerator.
#define _DMA_CTRL_CYCLE_CTRL_MASK
#define CORE_ENTER_ATOMIC()
int CDC_SetupCmd(const USB_Setup_TypeDef *setup)
Handle USB setup commands. Implements CDC class specific commands.
void GPIO_PinModeSet(GPIO_Port_TypeDef port, unsigned int pin, GPIO_Mode_TypeDef mode, unsigned int out)
Set the mode for a GPIO pin.
General Purpose IO (GPIO) peripheral API.
void DMA_Init(DMA_Init_TypeDef *init)
Initializes DMA controller.
void DMA_CfgChannel(unsigned int channel, DMA_CfgChannel_TypeDef *cfg)
Configure a DMA channel.
#define SL_ATTRIBUTE_ALIGN(X)
GCC style macro for aligning a variable.
#define USART_FRAME_STOPBITS_ONE
USB protocol stack library API for EFM32/EZR32.
DMA_DataSize_TypeDef size
#define USART_FRAME_STOPBITS_ONEANDAHALF
#define USART_FRAME_PARITY_NONE
Core interrupt handling API.
void CMU_ClockEnable(CMU_Clock_TypeDef clock, bool enable)
Enable/disable a clock.
#define USB_SETUP_RECIPIENT_INTERFACE
#define USART_FRAME_DATABITS_SIX
DMA_DataInc_TypeDef srcInc
#define CORE_EXIT_ATOMIC()
DMA_DESCRIPTOR_TypeDef * controlBlock
int USBD_Write(int epAddr, void *data, int byteCount, USB_XferCompleteCb_TypeDef callback)
Start a write (IN) transfer on an endpoint.
#define USART_FRAME_DATABITS_SIXTEEN
#define USART_INITASYNC_DEFAULT
#define SL_ATTRIBUTE_PACKED
GCC style macro for handling packed structs.
DMA_FuncPtr_TypeDef cbFunc
USB Communication Device Class (CDC) driver.
#define USART_FRAME_DATABITS_FIVE
void USART_Enable(USART_TypeDef *usart, USART_Enable_TypeDef enable)
Enable/disable USART/UART receiver and/or transmitter.
#define USART_FRAME_DATABITS_EIGHT
void USART_InitAsync(USART_TypeDef *usart, const USART_InitAsync_TypeDef *init)
Init USART/UART for normal asynchronous mode.
#define USB_SETUP_TYPE_CLASS
#define USART_FRAME_PARITY_ODD
void USBTIMER_Start(uint32_t id, uint32_t timeout, USBTIMER_Callback_TypeDef callback)
Start a timer.
Direct memory access (DMA) API.
int USBD_Read(int epAddr, void *data, int byteCount, USB_XferCompleteCb_TypeDef callback)
Start a read (OUT) transfer on an endpoint.
#define STATIC_UBUF(x, y)
void DMA_CfgDescr(unsigned int channel, bool primary, DMA_CfgDescr_TypeDef *cfg)
Configure DMA descriptor for auto-request, basic or ping-pong DMA cycles.
void USART_BaudrateAsyncSet(USART_TypeDef *usart, uint32_t refFreq, uint32_t baudrate, USART_OVS_TypeDef ovs)
Configure USART/UART operating in asynchronous mode to use a given baudrate (or as close as possible ...