📄 cd_class.c
字号:
// Reset Timer 0 counter
TIMER_Reset(TIMER0);
// Set action - match module CH0
TIMER_SetMatchAction(TIMER0, CH0, TimerAction_Interrupt | TimerAction_StopTimer,
BreakCntr, CDC_BreakCallBack, NULL, DONOTHING);
// Start Timer 1
TIMER_Start(TIMER0);
}
#endif // CDC_DEVICE_SUPPORT_LINE_STATE > 0
return((void*)UsbUserSendAckn);
#endif // CDC_DEVICE_SUPPORT_BREAK > 0
}
}
CdcReqPacket.wLength.Word = 0;
return((void *)UsbUserStallCtrlEp);
}
/*************************************************************************
* Function Name: UsbCdcData
* Parameters: void * pArg
*
* Return: void *
*
* Description: USB Communication Device Class Data receive
*
*************************************************************************/
void * UsbCdcData (void * pArg)
{
if ((CdcReqPacket.bRequest == SET_LINE_CODING) &&
(CdcReqPacket.wLength.Word != 0))
{
#if CDC_DEVICE_SUPPORT_LINE_CODING > 0
LineCodingDelta = TRUE;
#endif // CDC_DEVICE_SUPPORT_LINE_CODING > 0
return((void*)UsbUserSendAckn);
}
return((void*)UsbUserStallCtrlEp);
}
/*************************************************************************
* Function Name: UsbCdcRead
* Parameters: pInt8U pBuffer, Int32U Size
*
* Return: Int32U
*
* Description: USB Communication Device Class data read. Return number
* of received the bytes.
*
*************************************************************************/
Int32U UsbCdcRead (pInt8U pBuffer, Int32U Size)
{
Int32U ReadSize = 0, CurrReadSize = 0, Counter, save;
while(Size)
{
if(CDC_ReceiveIndx)
{
CurrReadSize = MIN((CDC_ReceiveIndx - CDC_ReceiveIndxHold), Size);
Size -= CurrReadSize;
ReadSize += CurrReadSize;
for(Counter = 0; Counter < CurrReadSize; ++Counter)
{
*pBuffer++ = CDC_ReceiveBuffer[CDC_ReceiveIndxHold++];
}
if(CDC_ReceiveIndxHold == CDC_ReceiveIndx)
{
CDC_ReceiveIndxHold = 0;
if (USB_CDC_OutEpBufferNotEmpty)
{
save = __get_interrupt_state();
__disable_interrupt();
CDC_ReceiveIndx = USB_EpRead((USB_Endpoint_t)CommOutEp,
(pInt32U)CDC_ReceiveBuffer,
CommOutEpMaxSize);
USB_CDC_OutEpBufferNotEmpty = FALSE;
__set_interrupt_state(save);
}
else
{
CDC_ReceiveIndx = 0;
}
}
}
else if (USB_CDC_OutEpBufferNotEmpty)
{
save = __get_interrupt_state();
__disable_interrupt();
CDC_ReceiveIndx = USB_EpRead((USB_Endpoint_t)CommOutEp,
(pInt32U)CDC_ReceiveBuffer,
CommOutEpMaxSize);
USB_CDC_OutEpBufferNotEmpty = FALSE;
__set_interrupt_state(save);
}
else
{
break;
}
}
return(ReadSize);
}
/*************************************************************************
* Function Name: UsbCdcWrite
* Parameters: pInt8U pBuffer, Int32U Size
*
* Return: CdcStatus_t
*
* Description: USB Communication Device Class data send.
*
*************************************************************************/
Boolean UsbCdcWrite (pInt8U pBuffer, Int32U Size)
{
Boolean Status = !UsbCdcIsSendProgess();
Int32U Counter, CurrWriteSize, save;
if(Status == TRUE)
{
pCDC_TransmitUserBuffer = pBuffer;
CDC_TransmitSize = Size;
CurrWriteSize = MIN(CDC_TransmitSize,CommInEpMaxSize);
for(Counter = 0; Counter < CurrWriteSize; ++Counter)
{
CDC_TransmitBuffer[Counter] = *pCDC_TransmitUserBuffer++;
}
CDC_TransmitSize -= CurrWriteSize;
save = __get_interrupt_state();
__disable_interrupt();
USB_EpWrite((USB_Endpoint_t)CommInEp,(pInt32U)CDC_TransmitBuffer,CurrWriteSize);
__set_interrupt_state(save);
}
return(Status);
}
/*************************************************************************
* Function Name: UsbCdcIsSendProgess
* Parameters: none
*
* Return: Boolean
*
* Description: Is all data send?
*
*************************************************************************/
Boolean UsbCdcIsSendProgess (void)
{
return(pCDC_TransmitUserBuffer != NULL);
}
/*************************************************************************
* Function Name: UsbCdcIsCdcConfigure
* Parameters: none
*
* Return: Boolean
*
* Description: Is CDC configure yet?
*
*************************************************************************/
Boolean UsbCdcIsCdcConfigure (void)
{
return(CDC_Configure);
}
#if CDC_DEVICE_SUPPORT_LINE_STATE > 0
/*************************************************************************
* Function Name: UsbCdcIsNewLineStateSettings
* Parameters: none
*
* Return: Boolean
*
* Description: Is there a new modem settings received?
* RTS and DTR signals
*
*************************************************************************/
Boolean UsbCdcIsNewLineStateSettings(void)
{
Boolean StateHold;
StateHold = (AtomicExchange(FALSE,(pInt32U)&LineStateDelta) != 0);
return(StateHold);
}
/*************************************************************************
* Function Name: UsbCdcGetLineStateSettings
* Parameters: none
*
* Return: CDC_LineState_t
*
* Description: Return the Line Signals states structure
* RTS and DTR signals
*
*************************************************************************/
CDC_LineState_t UsbCdcGetLineStateSettings(void)
{
return(CDC_LineState);
}
/*************************************************************************
* Function Name: UsbCdcReportSerialCommState
* Parameters: SerialState_t SerialState
*
* Return: none
*
* Description: Report the current state of serial communication channel
* Overrun Error, Parity Error, Framing Error, Ring Signal, Break,
* Tx Carrier, Rx Carrier
*
*************************************************************************/
void UsbCdcReportSerialCommState(SerialState_t SerialState)
{
Int32U save;
SerialStatePacket_t SerialStatePacket;
if(CDC_Configure == FALSE)
{
return;
}
SerialStatePacket.UsbSetupPacket.mRequestType.mRequestTypeData = 0xA1;
SerialStatePacket.UsbSetupPacket.bRequest = SERIAL_STATE;
SerialStatePacket.UsbSetupPacket.wValue.Word = 0;
SerialStatePacket.UsbSetupPacket.wIndex.Word = CDC_CTRL_INTERFACE_IND;
//SerialStatePacket.UsbSetupPacket.wIndex.Word = CDC_DATA_INTERFACE_IND;
SerialStatePacket.UsbSetupPacket.wLength.Word = sizeof(SerialState_t);
SerialStatePacket.SerialState = SerialState;
SerialStateDelta = TRUE;
// Disable interrupt and save current state of the interrupt flags
save = __get_interrupt_state();
__disable_interrupt();
USB_EpWrite((USB_Endpoint_t)ReportEp,(pInt32U)&SerialStatePacket,sizeof(SerialStatePacket_t));
__set_interrupt_state(save);
while(SerialStateDelta);
}
#endif // CDC_DEVICE_SUPPORT_LINE_STATE > 0
#if CDC_DEVICE_SUPPORT_BREAK > 0
/*************************************************************************
* Function Name: CDC_BreakCallBack
* Parameters: void* arg
*
* Return: none
*
* Description: Break Timer callback routine that is called form the timer
* interrupt routine after expire of break period.
*
*************************************************************************/
void CDC_BreakCallBack (void* arg)
{
BreakCntr = 0;
}
/*************************************************************************
* Function Name: UsbCdcGetBreakState
* Parameters: none
*
* Return: Boolean
*
* Description: Return Break event state
*
*************************************************************************/
Boolean UsbCdcGetBreakState(void)
{
return(BreakCntr != 0);
}
#endif // CDC_DEVICE_SUPPORT_BREAK > 0
#if CDC_DEVICE_SUPPORT_LINE_CODING > 0
/*************************************************************************
* Function Name: UsbCdcIsNewLineCtrlSettings
* Parameters: none
*
* Return: Boolean
*
* Description: Is there a new line settings received?
* Baud rate, Data bits, Stop bits and Parity
*
*************************************************************************/
Boolean UsbCdcIsNewLineCodingSettings(void)
{
Boolean StateHold;
StateHold = (AtomicExchange(FALSE,(pInt32U)&LineCodingDelta) != 0);
return(StateHold);
}
/*************************************************************************
* Function Name: UsbCdcGetLineCodingSettings
* Parameters: none
*
* Return: CDC_LineCoding_t
*
* Description: Return the Line Coding structure
* Baud rate, Data bits, Stop bits and Parity
*
*************************************************************************/
CDC_LineCoding_t UsbCdcGetLineCodingSettings(void)
{
return(CDC_LineCoding);
}
#endif // CDC_DEVICE_SUPPORT_LINE_CODING > 0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -