Exemple #1
0
/*
** ===================================================================
**     Method      :  CDC1_App_Callback (component FSL_USB_CDC_Device)
**     Description :
**         Method to handle class callbacks from USB
**     Parameters  :
**         NAME            - DESCRIPTION
**         controller_ID   - controller ID
**         event_type      - value of the event
**         val             - gives the configuration value
**     Returns     : Nothing
** ===================================================================
*/
void CDC1_App_Callback(uint8_t controller_ID, uint8_t event_type, void *val)
{
  UNUSED(controller_ID);
  UNUSED(val);
  if (event_type == USB_APP_BUS_RESET) {
    start_app = FALSE;
  } else if (event_type == USB_APP_ENUM_COMPLETE) {
#if HIGH_SPEED_DEVICE
    /* prepare for the next receive event */
    USB_Class_CDC_Interface_DIC_Recv_Data(&controller_ID,
                                           (uint_8_ptr)g_cdcBuffer,
                                           DIC_BULK_OUT_ENDP_PACKET_SIZE);
#else
    (void)USB_Class_CDC_Interface_DIC_Recv_Data(CONTROLLER_ID, NULL, 0);
#endif
    start_app = TRUE;
  } else if ((event_type==USB_APP_DATA_RECEIVED) && (start_transactions==TRUE)) {
    /* Copy Received Data buffer to Application Buffer */
    USB_PACKET_SIZE BytesToBeCopied;
    APP_DATA_STRUCT *dp_rcv = (APP_DATA_STRUCT*)val;
    uint_8 index;

    BytesToBeCopied = (USB_PACKET_SIZE)((dp_rcv->data_size>CDC1_DATA_BUFF_SIZE) ? CDC1_DATA_BUFF_SIZE:dp_rcv->data_size);
    for(index = 0; index<BytesToBeCopied ; index++) {
      if (Rx1_Put(dp_rcv->data_ptr[index])!=ERR_OK) {
        /* Failed to put byte into buffer. Is the buffer to small? Then increase the Rx buffer.
           Otherwise not much we could do here, so we are loosing byte here.
         */
        /* Enable OnError() event so this event will be called here */
      }
    }
    (void)USB_Class_CDC_Interface_DIC_Recv_Data(CONTROLLER_ID, NULL, 0); /* see http://eprints.utar.edu.my/143/1/BI-2011-0708672-1.pdf, page 131 */
  } else if ((event_type==USB_APP_SEND_COMPLETE) && (start_transactions==TRUE)) {
    transactionOngoing = FALSE;
    /* Previous Send is complete. Queue next receive */
#if HIGH_SPEED_DEVICE
    //(void)USB_Class_CDC_Interface_DIC_Recv_Data(CONTROLLER_ID, g_cdcBuffer, 0);
#else
    //(void)USB_Class_CDC_Interface_DIC_Recv_Data(CONTROLLER_ID, NULL, 0);
#endif
  } else if (event_type == USB_APP_ERROR) { /* detach? */
    start_app = FALSE;
    start_transactions = FALSE;
  }
}
Exemple #2
0
/*
*  LPLD_USB_QueueData
*  从USB的内存中恢复接收到的数据到用户内存中
*  接收成功后调用此函数
*  无
*  无
*/
void LPLD_USB_QueueData(void)
{
  (void)USB_Class_CDC_Interface_DIC_Recv_Data(CONTROLLER_ID, NULL, 0);
}