⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cd_class.c

📁 NXP LPC系列AMR7的开发程序源码(LCD
💻 C
📖 第 1 页 / 共 2 页
字号:
      break;

#if CDC_DEVICE_SUPPORT_BREAK > 0
    case SEND_BREAK:
#if CDC_DEVICE_SUPPORT_LINE_STATE > 0
      BreakCntr = CdcReqPacket.wValue.Word;
      LineStateDelta = TRUE;
      if(BreakCntr != 0 && BreakCntr != 0xFFFF)
      {
        // Stop Timer 0
        T0TCR_bit.CE = 0;
        // Set mach period
        T0MR0 = T0TC + BreakCntr;
        // Start Timer 0
        T0TCR_bit.CE = 1;
      }
#endif // CDC_DEVICE_SUPPORT_LINE_STATE > 0
      return((void*)UsbPass);
#endif // CDC_DEVICE_SUPPORT_BREAK > 0
    }
  }
  CdcReqPacket.wLength.Word = 0;
  return((void *)UsbFault);
}

/*************************************************************************
 * 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*)UsbPass);
  }
   return((void*)UsbFault);
}

/*************************************************************************
 * 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;
Int32U 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++];
      }
      save = __get_interrupt_state();
      __disable_interrupt();
      if(CDC_ReceiveIndxHold == CDC_ReceiveIndx)
      {
        if (USB_CDC_OutEpBufferNotEmpty)
        {
          USB_CDC_OutEpBufferNotEmpty = FALSE;
          CurrReadSize = sizeof(CDC_ReceiveBuffer);
          USB_EpRead((USB_Endpoint_t)CommOutEp,
                     CDC_ReceiveBuffer,
                     &CurrReadSize);
        #ifdef CDC_OUT_EP_SING_BUFFERED
          USB_EpValidate((USB_Endpoint_t)CommOutEp);
        #endif // CDC_OUT_EP_SING_BUFFERED
          CDC_ReceiveIndx = CurrReadSize;
        }
        else
        {
          CDC_ReceiveIndx = 0;
        }
        CDC_ReceiveIndxHold = 0;
      }
      __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;
Int32U CurrWriteSize;
Int32U save;

  if((Status = !UsbCdcIsSendProgess()) == TRUE)
  {
    save = __get_interrupt_state();
    __disable_interrupt();
    pCDC_TransmitUserBuffer = pBuffer;
    CurrWriteSize = Size;
    USB_EpWrite((USB_Endpoint_t)CommInEp,pBuffer,&CurrWriteSize);
    CDC_TransmitSize = Size - CurrWriteSize;
    pCDC_TransmitUserBuffer += CurrWriteSize;
    __set_interrupt_state(save);
    while(UsbCdcIsSendProgess());
  }
  return(Status);
}

/*************************************************************************
 * Function Name: UsbCdcIsSendProgess
 * Parameters:  none
 *
 * Return: Boolean
 *
 * Description: Is all data send?
 *
 *************************************************************************/
Boolean UsbCdcIsSendProgess (void)
{
  return(CDC_TransmitSize != 0);
}

/*************************************************************************
 * 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;
Int32U Size;
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_DATA_INTERFACE_IND;
  SerialStatePacket.UsbSetupPacket.wLength.Word = sizeof(SerialState_t);
  SerialStatePacket.SerialState = SerialState;

  SerialStateDelta = TRUE;
  Size = sizeof(SerialStatePacket_t);
  // Disable interrupt and save current state of the interrupt flags
  save = __get_interrupt_state();
  __disable_interrupt();
  USB_EpWrite((USB_Endpoint_t)ReportEp,(pInt8U)&SerialStatePacket,&Size);
  __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 + -