Exemple #1
0
/*
** ===================================================================
**     Method      :  usb_mems_USB_Class_Mems_Send_Data (component USB_MEMS_CLASS)
**     Description :
**         This fucntion is used by Application to send data through
**         Mems class
**     Parameters  :
**         NAME            - DESCRIPTION
**         controller_ID   - 
**         ep_num          - 
**         app_buff        - 
**         size            - 
**     Returns     :
**         ---             - Error code
** ===================================================================
*/
uint_8 USB_Class_Mems_Send_Data(
uint_8 controller_ID,
uint_8 ep_num,
uint_8_ptr app_buff,
USB_PACKET_SIZE size
)
{
    uint_8 status = USB_OK;
    PTR_USB_CLASS_MEMS_QUEUE queue_tmp;
    uint_8 index;
    uint_8 producer, queue_num;

    USB_ENDPOINTS *usb_ep_data = (USB_ENDPOINTS *)
    USB_Desc_Get_Endpoints(controller_ID);

    /* map the endpoint num to the index of the endpoint structure */

    for(index = 0; index < usb_ep_data->count; index++)
    {
        if(usb_ep_data->ep[index].ep_num == ep_num)
        break;
    }

    producer = g_mems_endpoint_data.ep[index].bin_producer;
    queue_num = g_mems_endpoint_data.ep[index].queue_num;

    //if queue_num==1,there is already a queue,USB is busy
    //if queue_num!=1,there USB queue is empty
    if(MAX_QUEUE_ELEMS != queue_num) 
    {
        /* the bin is not full*/
        /* put all send request parameters in the endpoint data structure */
        queue_tmp = &(g_mems_endpoint_data.ep[index].queue[producer]);
        queue_tmp->controller_ID  = controller_ID;
        queue_tmp->channel        = ep_num;
        queue_tmp->app_buff       = app_buff;
        queue_tmp->size           = size;

        /* increment producer bin by 1*/
        if (producer == (MAX_QUEUE_ELEMS - 1))
        {
            g_mems_endpoint_data.ep[index].bin_producer = 0;
        }
        else
        {
            g_mems_endpoint_data.ep[index].bin_producer++;
        }
        g_mems_endpoint_data.ep[index].queue_num++;

        if(g_mems_endpoint_data.ep[index].queue_num == 1)
        {
            status = USB_Class_Send_Data(controller_ID, ep_num, app_buff,size);
        }
    }
    else /* bin is full */
    {
        status = USBERR_DEVICE_BUSY;
    }
    return status;
}
Exemple #2
0
/**************************************************************************//*!
 *
 * @name  USB_Service_Video_Isochronous
 *
 * @brief The funtion ic callback function of Video Isochronous IN endpoint 
 *
 * @param event
 *
 * @return None       
 *
 ****************************************************************************
 * The function is called in response to Isochronous IN Service  
 ******************************************************************************/
void USB_Service_Video_Isochronous(PTR_USB_DEV_EVENT_STRUCT event)
{

#if IMPLEMENT_QUEUING
	uint_8 index;
	uint_8 producer, consumer;
	/*Body*/

	USB_ENDPOINTS *usb_ep_data = (USB_ENDPOINTS *)
        		USB_Desc_Get_Endpoints(event->controller_ID);

	/* map the endpoint num to the index of the endpoint structure */
	for(index = 0; index < usb_ep_data->count; index++) 
	{
		if(usb_ep_data->ep[index].ep_num ==event->ep_num)
			break;
	}/*EndFor*/

	producer = g_video_endpoint_data.ep[index].bin_producer;	  
	/* if there are no errors de-queue the queue and decrement the no. of
       transfers left, else send the same data again */
	if(event->errors == 0)
	{
		/* de-queue if the send is complete without an error */
		if ((MAX_QUEUE_ELEMS-1) == g_video_endpoint_data.ep[index].bin_consumer)
		{
			g_video_endpoint_data.ep[index].bin_consumer = 0;
		} else {
			g_video_endpoint_data.ep[index].bin_consumer++;
		}/*EndIf*/
		g_video_endpoint_data.ep[index].queue_num--;
	}/*EndIf*/

	consumer = g_video_endpoint_data.ep[index].bin_consumer;

	if(0 != g_video_endpoint_data.ep[index].queue_num)
	{
		/*if bin is not empty */
		USB_CLASS_VIDEO_QUEUE queue;
		/* send the next packet in queue */
		queue = g_video_endpoint_data.ep[index].queue[consumer];

		(void)USB_Class_Send_Data(queue.controller_ID, queue.channel,
				queue.app_buff, queue.size);
	}/*EndIf*/
#endif    

	if(g_video_class_callback != NULL)
	{
		uint_8 event_type = USB_APP_SEND_COMPLETE;

		if(event->errors != 0)
		{
			event_type = USB_APP_ERROR;
		}/*EndIf*/
		g_video_class_callback(event->controller_ID, event_type,
				(uint_8*)(&(event->errors)));
	}/*EndIf*/
}/*EndBody*/
Exemple #3
0
/**************************************************************************//*!
 *
 * @name  USB_Class_CDC_Service_Dic_Bulk_In
 *
 * @brief The funtion is callback function of DIC Bulk In Endpoint
 *
 * @param event : Pointer to USB Event Structure
 *
 * @return None
 *
 ******************************************************************************
 * Called by Lower Layer when Data on DIC SEND Interface is sent
 *****************************************************************************/
static void USB_Class_CDC_Service_Dic_Bulk_In (
    PTR_USB_DEV_EVENT_STRUCT event /* [IN] Pointer to USB Event Structure */
)
{
    APP_DATA_STRUCT bulk_in_recv;

#if IMPLEMENT_QUEUING
    uint_8 index;
    uint_8 producer, consumer;
    USB_ENDPOINTS *usb_ep_data = (USB_ENDPOINTS *)
        USB_Desc_Get_Endpoints(event->controller_ID);

    USB_CLASS_CDC_QUEUE queue;

    bulk_in_recv.data_ptr = event->buffer_ptr;
    bulk_in_recv.data_size = event->len;

    /* map the endpoint num to the index of the endpoint structure */
    for(index = 0; index < usb_ep_data->count; index++)
    {
        if(usb_ep_data->ep[index].ep_num == event->ep_num)
        break;
    }

    producer = g_cdc_ep[index].bin_producer;

    /* if there are no errors de-queue the queue and decrement the no. of
       transfers left, else send the same data again */
    if(event->errors == 0)
    {
        g_cdc_ep[index].bin_consumer++;
    }

    consumer = g_cdc_ep[index].bin_consumer;

    if(consumer != producer)
    {/*if bin is not empty */

        queue = g_cdc_ep[index].queue[consumer%MAX_QUEUE_ELEMS];

        (void)USB_Class_Send_Data(queue.controller_ID, queue.channel,
            queue.app_data.data_ptr, queue.app_data.data_size);
    }
#endif
    if(g_cdc_class_callback != NULL)
    {
        if(event->errors != 0)
        {
            g_cdc_class_callback(event->controller_ID, USB_APP_ERROR,
                (uint_8*)(&(event->errors)));
        }
        else
        {
            g_cdc_class_callback(event->controller_ID, USB_APP_SEND_COMPLETE,
                (void*)&bulk_in_recv);
        }
    }
}
Exemple #4
0
/**************************************************************************//*!
 *
 * @name  USB_Class_CDC_Send_Data
 *
 * @brief This function is used to send data from CDC Class over send endpoints
 *
 * @param controller_ID : Controller ID
 * @param ep_num        : Endpoint number
 * @param app_buff      : Buffer to send
 * @param size          : Length of the transfer
 *
 * @return status
 *         USB_OK           : When Successfull
 *         Others           : Errors
 ******************************************************************************
 * Helper function. Sends DATA over CIC and DIC Interfaces to Host
 *****************************************************************************/
uint_8 USB_Class_CDC_Send_Data (
    uint_8 controller_ID,   /* [IN] Controller ID */
    uint_8 ep_num,          /* [IN] Endpoint Number */
    uint_8_ptr app_buff,    /* Pointer to Application Buffer */
    USB_PACKET_SIZE size    /* Size of Application Buffer */
)
{
    uint_8 status = USB_OK;

#if IMPLEMENT_QUEUING
    uint_8 index;
    uint_8 producer, consumer;

    USB_ENDPOINTS *usb_ep_data = (USB_ENDPOINTS *)
                                    USB_Desc_Get_Endpoints(controller_ID);

    /* map the endpoint num to the index of the endpoint structure */
    for(index = 0; index < usb_ep_data->count; index++)
    {
        if(usb_ep_data->ep[index].ep_num == ep_num)
        {
            break;
        }
    }

    producer = g_cdc_ep[index].bin_producer;
    consumer = g_cdc_ep[index].bin_consumer;

    if(((uint_8)(producer - consumer)) != (uint_8)(MAX_QUEUE_ELEMS))
    {
        /* the bin is not full*/

        uint_8 queue_num = (uint_8)(producer % MAX_QUEUE_ELEMS);

        /* put all send request parameters in the endpoint data structure */
        g_cdc_ep[index].queue[queue_num].controller_ID = controller_ID;
        g_cdc_ep[index].queue[queue_num].channel = ep_num;
        g_cdc_ep[index].queue[queue_num].app_data.data_ptr = app_buff;
        g_cdc_ep[index].queue[queue_num].app_data.data_size = size;

        /* increment producer bin by 1*/
        g_cdc_ep[index].bin_producer = ++producer;

        if((uint_8)(producer - consumer) == (uint_8)1)
        {
#endif
            status = USB_Class_Send_Data(controller_ID, ep_num, app_buff,size);
#if IMPLEMENT_QUEUING
        }
    }
    else /* bin is full */
    {
        status = USBERR_DEVICE_BUSY;
    }
#endif
    return status;
}
Exemple #5
0
/*
** ===================================================================
**     Method      :  USB_Service_Mems_Status_Interrupt (component USB_MEMS_CLASS)
**
**     Description :
**         The funtion is callback function of Mems Status Interrupt 
**         endpoint
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
static void USB_Service_Mems_Status_Interrupt(
PTR_USB_DEV_EVENT_STRUCT event
)
{
    uint_8 index;
    uint_8 producer, consumer;
    USB_ENDPOINTS *usb_ep_data = (USB_ENDPOINTS *)USB_Desc_Get_Endpoints(event->controller_ID);

    /* map the endpoint num to the index of the endpoint structure */
    for(index = 0; index < usb_ep_data->count; index++)
    {
        if(usb_ep_data->ep[index].ep_num == event->ep_num)
        break;
    }

    producer = g_mems_endpoint_data.ep[index].bin_producer;
    consumer = g_mems_endpoint_data.ep[index].bin_consumer;
    /* if there are no errors de-queue the queue and decrement the no. of
    transfers left, else send the same data again */
    if (event->errors == 0)
    {
        /* de-queue if the send is complete without an error */
        if((MAX_QUEUE_ELEMS-1) == consumer)
        {
            g_mems_endpoint_data.ep[index].bin_consumer = 0;
        }
        else
        {
            g_mems_endpoint_data.ep[index].bin_consumer++;
        }
    }

    consumer = g_mems_endpoint_data.ep[index].bin_consumer;
    g_mems_endpoint_data.ep[index].queue_num--;

    if(0 == g_mems_endpoint_data.ep[index].queue_num)
    {
        /*if bin is not empty */
        USB_CLASS_MEMS_QUEUE queue;
        /* send the next packet in queue */
        queue = g_mems_endpoint_data.ep[index].queue[consumer];
        (void)USB_Class_Send_Data(queue.controller_ID, queue.channel,
        queue.app_buff, queue.size);
    }

    if(g_param_callback != NULL)
    {
        uint_8 event_type = USB_APP_SEND_COMPLETE;
        if(event->errors != 0)
        {
            event_type = USB_APP_ERROR;
        }
        g_param_callback(event->controller_ID, event_type,
        (uint_8*)(&(event->errors)));
    }
}
Exemple #6
0
/**************************************************************************//*!
 *
 * @name  USB_Class_Video_Init
 *
 * @brief   The funtion initializes the Device and Controller layer
 *
 * @param   controller_ID               : Controller ID
 * @param   video_class_callback        : Video Class Callback
 * @param   vendor_req_callback         : Vendor Request Callback
 * @param   param_callback              : Class requests Callback
 *
 * @return status:
 *                        USB_OK        : When Successfull
 *                        Others        : When Error
 *
 ******************************************************************************
 *This function initializes the Video Class layer and layers it is dependent on
 *****************************************************************************/
uint_8 USB_Class_Video_Init (
		uint_8    controller_ID,                  /* [IN] Controller ID */
		USB_CLASS_CALLBACK video_class_callback,  /* [IN] Video Class Callback */
		USB_REQ_FUNC       vendor_req_callback,   /* [IN] Vendor Request Callback */
		USB_CLASS_CALLBACK param_callback         /* [ IN] Video Class requests Callback */
)
{
    uint_8 index;
    uint_8 status = USB_OK;
    USB_ENDPOINTS *ep_desc_data = (USB_ENDPOINTS *)
        USB_Desc_Get_Endpoints(controller_ID);

#ifndef COMPOSITE_DEV
    /* Initialize the device layer*/
    status = _usb_device_init(controller_ID,NULL,
        (uint_8)(ep_desc_data->count+1), TRUE);
    if(status == USB_OK)
    {
        /* Initialize the generic class functions */
        status = USB_Class_Init(controller_ID,USB_Class_Video_Event,
            USB_Other_Requests);

        if(status == USB_OK)
        {
#endif
            g_video_endpoint_data.count = ep_desc_data->count;

            for(index = 0; index < ep_desc_data->count; index++)
            {
                g_video_endpoint_data.ep[index].endpoint =
                    ep_desc_data->ep[index].ep_num;
                g_video_endpoint_data.ep[index].type =
                    ep_desc_data->ep[index].type;
                g_video_endpoint_data.ep[index].bin_consumer = 0x00;
                g_video_endpoint_data.ep[index].bin_producer = 0x00;
                g_video_endpoint_data.ep[index].queue_num    = 0x00;
            }

            /* save the video class callback pointer */
            g_video_class_callback = video_class_callback;

            /* save the vendor request callback pointer */
            g_vendor_req_callback = vendor_req_callback;

            /* Save the callback to ask application for class specific params*/
            g_param_callback = param_callback;
#ifndef COMPOSITE_DEV
        }
    }
#endif
    return status;
}
Exemple #7
0
/**************************************************************************//*!
 *
 * @name  USB_Class_CDC_Init
 *
 * @brief The function initializes the Device and Controller layer
 *
 * @param controller_ID:        Controller ID
 * @param cdc_class_callback:   CDC Class Callback
 * @param vendor_req_callback:  vendor specific class request callback
 * @param param_callback:       PSTN Callback
 *
 * @return status
 *         USB_OK           : When Successfull
 *         Others           : Errors
 ******************************************************************************
 * This function initializes the CDC Class layer and layers it is dependent upon
 *****************************************************************************/
uint_8 USB_Class_CDC_Init (
        uint_8                                  controller_ID,       /* [IN] Controller ID */
        USB_CLASS_CALLBACK              cdc_class_callback,  /* [IN] CDC Class Callback */
        USB_REQ_FUNC                    vendor_req_callback, /* [IN] Vendor Request Callback */
        USB_CLASS_CALLBACK              pstn_callback,       /* [IN] PSTN Callback */
        uint_8                          bVregEn              /* Enables or disables internal regulator */
)
{
    uint_8 index,status = USB_OK;
    USB_ENDPOINTS *usb_ep_data =
        (USB_ENDPOINTS *)USB_Desc_Get_Endpoints(controller_ID);
#ifndef COMPOSITE_DEV
    /* Initialize the device layer*/
    status = _usb_device_init(controller_ID, NULL,
        (uint_8)(usb_ep_data->count+1), bVregEn);
    /* +1 is for Control Endpoint */

    if(status == USB_OK)
    {
        /* Initialize the generic class functions */
        status = USB_Class_Init(controller_ID,USB_Class_CDC_Event,
            USB_Other_Requests);
#endif
#if IMPLEMENT_QUEUING
            for(index = 0; index < usb_ep_data->count; index++)
            {
                g_cdc_ep[index].endpoint = usb_ep_data->ep[index].ep_num;
                g_cdc_ep[index].type = usb_ep_data->ep[index].type;
                g_cdc_ep[index].bin_consumer = 0x00;
                g_cdc_ep[index].bin_producer = 0x00;
            }
#endif
#if PSTN_SUBCLASS_NOTIF_SUPPORT
        /* Initialize the pstn subclass functions */
        status = USB_Class_CDC_Pstn_Init(controller_ID,pstn_callback);
#endif
        if(status == USB_OK)
        {
           /* save the callback pointer */
           g_cdc_class_callback = cdc_class_callback;

           /* save the callback pointer */
           g_vendor_req_callback = vendor_req_callback;
        }
#ifndef COMPOSITE_DEV
    }
#endif
    return status;
}
Exemple #8
0
/*
** ===================================================================
**     Method      :  usb_device_USB_LDD_OnDeviceSof (component USB_DEVICE_STACK)
**
**     Description :
**         Called after the Sof is received, OnSof() event is enabled and 
**         USB module is enabled. See SetEventMask() and GetEventMask() 
**         methods. The event services the event of the inherited 
**         component and eventually invokes other events.
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
void USB_LDD_OnDeviceSof(LDD_TUserData *UserDataPtr, uint16_t FrameNumber)
{
  /* Write your code here ... */
	uint_8 queue_num,index;
	
	USB_ENDPOINTS *usb_ep_data = (USB_ENDPOINTS *)
	USB_Desc_Get_Endpoints(CONTROLLER_ID);

	//map the endpoint num to the index of the endpoint structure
    for(index = 0; index < usb_ep_data->count; index++)
	    {
	        if(usb_ep_data->ep[index].ep_num == 1)
	             break;
	    }
	
	//first send USB data
	if( ( G_FrameNumber == S_FrameNumber ) && ( first == 0 ) )
	    {
		    //tARMPtr->armStatus.isRequiringData = TRUE;
		    SwapARMDataBuffer();
		    TransmitMCUData();
		    tARMPtr->foreBuffer[6] = 0;//wait time:from preparing sending to real sending
		    S_FrameNumber += 100;
		    S_FrameNumber &= 0x3ff;
		    first = 1;
	    }
	
	if( G_FrameNumber <= 100 )
		flag = 0;
	
	if( ( G_FrameNumber == S_FrameNumber ) && ( first == 1 ) && ( flag == 0 ) )
		{   
		    //tARMPtr->armStatus.isRequiringData = TRUE;
		    //If the bin of USB is full,do not swap the buffer
		    queue_num = g_audio_endpoint_data.ep[index].queue_num;
		    if(MAX_QUEUE_ELEMS != queue_num)//the USB sending queue is empty(not full),we can swap the buffer
		    {
		    	SwapARMDataBuffer();
		    	TransmitMCUData();
		    	tARMPtr->foreBuffer[6] = 0;//wait time:from preparing sending to real sending
		    }
			S_FrameNumber += 100;
			S_FrameNumber &= 0x3ff;//when frame number more than 1024,reset it 0
			if( G_FrameNumber >= 924 )//when frame number loop,S_FrameNumber is a little value(eg:52),then the G_FrameNumber(>1000) is more than S_FrameNumber
				flag = 1;
		}
}
Exemple #9
0
/*
** ===================================================================
**     Method      :  USB_Class_Mems_Init (component USB_MEMS_CLASS)
**     Description :
**         The funtion initializes the Device and Controller layer
**     Parameters  :
**         NAME            - DESCRIPTION
**         controller_ID   - 
**         mems_class_callback - 
**         vendor_req_callback - 
**         param_callback  - 
**     Returns     :
**         ---             - Error code
** ===================================================================
*/
uint_8 USB_Class_Mems_Init(
uint_8 controller_ID,
USB_CLASS_CALLBACK mems_class_callback,
USB_REQ_FUNC vendor_req_callback,
USB_CLASS_CALLBACK param_callback
)
{
    uint_8 index;
    USB_ENDPOINTS *ep_desc_data = (USB_ENDPOINTS *)
    USB_Desc_Get_Endpoints(controller_ID);

    /* Initialize the device layer*/
    uint_8 status = _usb_device_init(controller_ID, NULL,
    (uint_8)(ep_desc_data->count+1));
    if(status == USB_OK)
    {
        /* Initialize the generic class functions */
        status = USB_Class_Init(controller_ID,USB_Class_Mems_Event,
        USB_Other_Requests);
        if(status == USB_OK)
        {
            g_mems_endpoint_data.count = ep_desc_data->count;
            for(index = 0; index < ep_desc_data->count; index++)
            {
                g_mems_endpoint_data.ep[index].endpoint =
                ep_desc_data->ep[index].ep_num;
                g_mems_endpoint_data.ep[index].type =
                ep_desc_data->ep[index].type;
                g_mems_endpoint_data.ep[index].bin_consumer = 0x00;
                g_mems_endpoint_data.ep[index].bin_producer = 0x00;
                g_mems_endpoint_data.ep[index].queue_num    = 0x00;
            }

            /* save the Mems class callback pointer */
            g_mems_class_callback = mems_class_callback;

            /* save the vendor request callback pointer */
            g_vendor_req_callback = vendor_req_callback;

            /* Save the callback to ask application for class specific params*/
            g_param_callback = param_callback;
        }
    }
    return status;
}
Exemple #10
0
/**************************************************************************//*!
 *
 * @name  USB_Service_Hid
 *
 * @brief The function is a callback function of HID endpoint
 *
 * @param event : Pointer to USB Event Structure
 *
 * @return None
 *
 ******************************************************************************
 * This function is called from lower layer when data is transfer is completed
 * on HID endpoint (non control endpoint)
 *****************************************************************************/
void USB_Service_Hid (
    PTR_USB_DEV_EVENT_STRUCT event /* [IN] Pointer to USB Event Structure */
)
{
    uint_8 index;
    uint_8 producer, consumer;
    USB_ENDPOINTS *ep_desc_data = (USB_ENDPOINTS *)
        USB_Desc_Get_Endpoints(event->controller_ID);

     /* map the endpoint num to the index of the endpoint structure */
    index = USB_Map_Ep_To_Struct_Index(event->controller_ID, event->ep_num);

    producer = g_hid_endpoint_data.ep[index].bin_producer;

    /* if there are no errors de-queue the queue and decrement the no. of
       transfers left, else send the same data again */
    if(event->errors == 0)
    {
        /* de-queue if the send is complete without an error */
        g_hid_endpoint_data.ep[index].bin_consumer++;
    }
    else
    {
        /* notify the application of the error */
        g_hid_class_callback(event->controller_ID, USB_APP_ERROR,
            (uint_8*)(&(event->errors)));
    }
    consumer = g_hid_endpoint_data.ep[index].bin_consumer;

    if(consumer != producer)
    {
        /*if bin is not empty */
        USB_CLASS_HID_QUEUE queue;
        /* send the next packet in queue */
        queue = g_hid_endpoint_data.ep[index].
            queue[consumer % MAX_QUEUE_ELEMS];

        (void)USB_Class_Send_Data(queue.controller_ID, queue.channel,
            queue.app_buff, queue.size);
    }

    /* notify the app of the send complete */
    g_hid_class_callback(event->controller_ID, USB_APP_SEND_COMPLETE, 0);
}
Exemple #11
0
 /**************************************************************************//*!
 *
 * @name  USB_Map_Ep_To_Struct_Index
 *
 * @brief The funtion maps the endpoint number to the index of the endpoint
 *        data structure
 *
 * @param controller_ID     : Controller ID
 * @param ep_num            : Endpoint number
 *
 * @return index            : mapped index
 *
 ******************************************************************************
 * Returns the index of the endpoint info array for the particular endpoint
 * number
 *****************************************************************************/
static uint_8 USB_Map_Ep_To_Struct_Index (
    uint_8 controller_ID,   /* [IN] Controller ID */
    uint_8 ep_num           /* Endpoint Number */
)
{
    uint_8 index = 0;

    USB_ENDPOINTS *ep_desc_data = (USB_ENDPOINTS *)
        USB_Desc_Get_Endpoints(controller_ID);

    /* map the endpoint num to the index of the endpoint structure */
    for(index = 0; index < ep_desc_data->count; index++)
    {
        if(ep_desc_data->ep[index].ep_num == ep_num)
        {
            break;
        }
    }

    return index;

}
Exemple #12
0
/**************************************************************************//*!
 *
 * @name  USB_Class_CDC_Service_Cic_Notify
 *
 * @brief The function is callback function of CIC Notification endpoint
 *
 * @param event : Pointer to USB Event Structure
 *
 * @return None
 *
 ******************************************************************************
 * Called by Lower layer when data on CIC Endpoint is sent
 *****************************************************************************/
void USB_Class_CDC_Service_Cic_Notify (
    PTR_USB_DEV_EVENT_STRUCT event  /* [IN] Pointer to USB Event Structure */
)
{
#if IMPLEMENT_QUEUING
    uint_8 index;
    uint_8 producer, consumer;
    USB_ENDPOINTS *usb_ep_data = (USB_ENDPOINTS *)
        USB_Desc_Get_Endpoints(event->controller_ID);

    USB_CLASS_CDC_QUEUE queue;

    /* map the endpoint num to the index of the endpoint structure */
    for(index = 0; index < usb_ep_data->count; index++)
    {
        if(usb_ep_data->ep[index].ep_num == event->ep_num)
        break;
    }

    producer = g_cdc_ep[index].bin_producer;

    /* if there are no errors de-queue the queue and decrement the no. of
       transfers left, else send the same data again */
    if(event->errors == 0)
    {
        g_cdc_ep[index].bin_consumer++;
    }

    consumer = g_cdc_ep[index].bin_consumer;

    if(consumer != producer)
    {/*if bin is not empty */

        queue = g_cdc_ep[index].queue[consumer%%MAX_QUEUE_ELEMS];

        (void)USB_Class_Send_Data(queue.controller_ID, queue.channel,
            queue.app_data.data_ptr, queue.app_data.data_size);
    }
Exemple #13
0
/**************************************************************************//*!
 *
 * @name  USB_Class_CDC_Event
 *
 * @brief The funtion initializes CDC endpoints
 *
 * @param controller_ID : Controller ID
 * @param event         : Event Type
 * @param val           : Pointer to configuration Value
 *
 * @return None
 *
 ******************************************************************************
 *
 *****************************************************************************/
static void USB_Class_CDC_Event (
    uint_8 controller_ID,   /* [IN] Controller ID */
    uint_8 event,           /* [IN] Event Type */
    void* val               /* [OUT] Pointer to configuration Value */
)
{
    uint_8 index;
    USB_ENDPOINTS *usb_ep_data = (USB_ENDPOINTS *)
        USB_Desc_Get_Endpoints(controller_ID);

    if(event == USB_APP_ENUM_COMPLETE)
    {
		uint_8 count;
		count = usb_ep_data->count; 
		/* deinitialize all endpoints in case they were initialized */
		while(count > 0) 
		{   
			USB_EP_STRUCT_PTR ep_struct_ptr= 
				(USB_EP_STRUCT_PTR) (&usb_ep_data->ep[count - 1]);
			(void)USB_Device_Deinit_EndPoint(controller_ID,
				ep_struct_ptr->ep_num, ep_struct_ptr->direction);
			 count--;   
		}
        
        /* intialize all non control endpoints */
        while(count < usb_ep_data->count)
        {
            USB_EP_STRUCT_PTR ep_struct=
                (USB_EP_STRUCT_PTR) (&usb_ep_data->ep[count]);

            (void)USB_Device_Init_EndPoint(controller_ID, ep_struct, FALSE);

            /* register callback service for Non Control EndPoints */
            switch(ep_struct->type)
            {
#if CIC_NOTIF_ELEM_SUPPORT
                case USB_INTERRUPT_PIPE :
                    (void)USB_Device_Register_Service(controller_ID,
                        (uint_8)(USB_SERVICE_EP0+ep_struct->ep_num),
                        USB_Class_CDC_Service_Cic_Notify);
                    break;
#endif
#if !DIC_ISOCHRONOUS_SETTING
                case USB_BULK_PIPE :
                    if(ep_struct->direction == USB_RECV)
                    {
                        (void)USB_Device_Register_Service(controller_ID,
                            (uint_8)(USB_SERVICE_EP0+ep_struct->ep_num),
                            USB_Class_CDC_Service_Dic_Bulk_Out);
                    }
                    else
                    {
                        (void)USB_Device_Register_Service(controller_ID,
                            (uint_8)(USB_SERVICE_EP0+ep_struct->ep_num),
                            USB_Class_CDC_Service_Dic_Bulk_In);
                    }
                    break;
#else
                case USB_ISOCHRONOUS_PIPE :
                    if(ep_struct->direction == USB_RECV)
                    {
                        (void)USB_Device_Register_Service(controller_ID,
                            (uint_8)(USB_SERVICE_EP0+ep_struct->ep_num),
                            USB_Class_CDC_Service_Dic_Iso_Out);
                    }
                    else
                    {
                        (void)USB_Device_Register_Service(controller_ID,
                            (uint_8)(USB_SERVICE_EP0+ep_struct->ep_num),
                            USB_Class_CDC_Service_Dic_Iso_In);
                    }
                    break;
#endif
                default: 
                    break;
            }
            /* set the EndPoint Status as Idle in the device layer */
            (void)USB_Device_Set_Status(controller_ID,
                (uint_8)(USB_STATUS_ENDPOINT | ep_struct->ep_num |
                (ep_struct->direction << USB_COMPONENT_DIRECTION_SHIFT)),
                (uint_8)USB_STATUS_IDLE);
            count++;
        }
    }
    else if(event == USB_APP_BUS_RESET)
    {
#if IMPLEMENT_QUEUING
        for(index = 0; index < usb_ep_data->count; index++)
        {
            g_cdc_ep[index].bin_consumer = 0x00;
            g_cdc_ep[index].bin_producer = 0x00;
        }
#endif
    }
    if(g_cdc_class_callback != NULL)
    {
        g_cdc_class_callback(controller_ID, event, val);
    }
}
Exemple #14
0
/**************************************************************************//*!
 *
 * @name  USB_Class_Video_Send_Data
 *
 * @brief This fucntion is used by Application to send data through Video class
 *
 * @param controller_ID     : Controller ID
 * @param ep_num            : Endpoint number
 * @param app_buff          : Buffer to send
 * @param size              : Length of the transfer
 *
 * @return status:
 *                        USB_OK        : When Successfull
 *                        Others        : When Error
 *
 ******************************************************************************
 * This fucntion is used by Application to send data through Video class
 *****************************************************************************/
uint_8 USB_Class_Video_Send_Data (
		uint_8 controller_ID,       /* [IN] Controller ID */
		uint_8 ep_num,              /* [IN] Endpoint Number */
		uint_8_ptr app_buff,        /* [IN] Buffer to Send */
		USB_PACKET_SIZE size        /* [IN] Length of the Transfer */
)
{
	uint_8 status = USB_OK;
	PTR_USB_CLASS_VIDEO_QUEUE queue_tmp;

#if IMPLEMENT_QUEUING
	uint_8 index;
	uint_8 producer, queue_num;

	USB_ENDPOINTS *usb_ep_data = (USB_ENDPOINTS *)
                                    		USB_Desc_Get_Endpoints(controller_ID);

	/*Body*/                                    
	/* map the endpoint num to the index of the endpoint structure */

	for(index = 0; index < usb_ep_data->count; index++) 
	{
		if(usb_ep_data->ep[index].ep_num == ep_num)
			break;
	}/*EndFor*/

	producer = g_video_endpoint_data.ep[index].bin_producer;
	queue_num = g_video_endpoint_data.ep[index].queue_num;

	if(MAX_QUEUE_ELEMS != queue_num)
	{
		/* the bin is not full*/
		/* put all send request parameters in the endpoint data structure */
		queue_tmp = &(g_video_endpoint_data.ep[index].queue[producer]);
		queue_tmp->controller_ID  = controller_ID;
		queue_tmp->channel        = ep_num;
		queue_tmp->app_buff       = app_buff;
		queue_tmp->size           = size;

		/* increment producer bin by 1*/
		if (producer == (MAX_QUEUE_ELEMS - 1))
		{
			g_video_endpoint_data.ep[index].bin_producer = 0;
		} /*Else*/
		else 
		{
			g_video_endpoint_data.ep[index].bin_producer++;
		}/*EndElse*/
		g_video_endpoint_data.ep[index].queue_num++;

		if(g_video_endpoint_data.ep[index].queue_num == 1)
		{
#endif
			status = USB_Class_Send_Data(controller_ID, ep_num, app_buff,size);
#if IMPLEMENT_QUEUING
		}/*EndIf*/
	}/*Else*/
	else /* bin is full */
	{
		status = USBERR_DEVICE_BUSY;
	}/*EndIf*/
#endif
	return status;
}/*EndBody*/
Exemple #15
0
/**************************************************************************//*!
 *
 * @name  USB_Class_Hid_Event
 *
 * @brief The function initializes HID endpoint
 *
 * @param controller_ID     : Controller ID
 * @param event             : Event Type
 * @param val               : Pointer to configuration Value
 *
 * @return None
 *
 ******************************************************************************
 * The funtion initializes the HID endpoints when Enumeration complete event is
 * received
 *****************************************************************************/
 void USB_Class_Hid_Event (
    uint_8 controller_ID,   /* [IN] Controller ID */
    uint_8 event,           /* [IN] Event Type */
    void* val               /* [IN] Pointer to configuration Value */
)
{
    uint_8 index;

    if(event == USB_APP_ENUM_COMPLETE)
    {
        uint_8 index_num = 0;
        uint_8 count = 0,ep_count = 0;
        USB_ENDPOINTS *ep_desc_data;  
        
#ifdef COMPOSITE_DEV
        DEV_ARCHITECTURE_STRUCT_PTR dev_arc_ptr;
        CLASS_ARC_STRUCT_PTR dev_class_ptr;   
        dev_arc_ptr = (DEV_ARCHITECTURE_STRUCT *)USB_Desc_Get_Class_Architecture(controller_ID);    
        for(count = 0; count < dev_arc_ptr->cl_count; count++)
        {
            dev_class_ptr = (CLASS_ARC_STRUCT_PTR)dev_arc_ptr->value[count];
            /* Initializes sub_classes */
            ep_count = dev_class_ptr->value[0];
            if(dev_class_ptr->class_type == 0x03/*HID_CC*/)
                break;
            index_num +=dev_class_ptr->value[0];
        }
        /* get the endpoints from the descriptor module */
        ep_desc_data = (USB_ENDPOINTS *)USB_Desc_Get_Endpoints(controller_ID); 
#else
        /* get the endpoints from the descriptor module */
        ep_desc_data = (USB_ENDPOINTS *)USB_Desc_Get_Endpoints(controller_ID); 
                    		    
		ep_count = ep_desc_data->count; 
#endif
		/* deinitialize all endpoints in case they were initialized */
		for(count=index_num;count<ep_count+index_num;count++) 
		{   
			USB_EP_STRUCT_PTR ep_struct_ptr= 
				(USB_EP_STRUCT_PTR) (&ep_desc_data->ep[count]);
			(void)_usb_device_deinit_endpoint(&controller_ID,
				ep_struct_ptr->ep_num, ep_struct_ptr->direction);  
		}

        /* intialize all non control endpoints */
        for(count=index_num;count<ep_count+index_num;count++)
        {
            USB_EP_STRUCT_PTR ep_struct=
                (USB_EP_STRUCT_PTR)&ep_desc_data->ep[count];

            (void)_usb_device_init_endpoint(&controller_ID, ep_struct->ep_num,
            		ep_struct->size, ep_struct->direction, ep_struct->type,
            		TRUE);

            /* register callback service for the endpoint */
            (void)_usb_device_register_service(controller_ID,
                                  (uint_8)(USB_SERVICE_EP0+ep_struct->ep_num),
                                                             USB_Service_Hid);


            /* set the EndPoint Status as Idle in the device layer */
            (void)_usb_device_set_status(&controller_ID,
                (uint_8)(USB_STATUS_ENDPOINT | HID_ENDPOINT |
                (ep_struct->direction << USB_COMPONENT_DIRECTION_SHIFT)),
                USB_STATUS_IDLE);
        }

    }
    else if((event == USB_APP_BUS_RESET) || (event == USB_APP_CONFIG_CHANGED))
    {
        /* clear producer and consumer on reset */
        for(index = 0; index < g_hid_endpoint_data.count; index++)
        {
            g_hid_endpoint_data.ep[index].bin_consumer = 0x00;
            g_hid_endpoint_data.ep[index].bin_producer = 0x00;
            g_hid_endpoint_data.ep[index].queue_num    = 0x00;
        }
    }

    if(g_hid_class_callback != NULL)
    {
        /* notify the application of the event */
        g_hid_class_callback(controller_ID, event, val);
    }

}
Exemple #16
0
/*
** ===================================================================
**     Method      :  USB_Class_Mems_Event (component USB_MEMS_CLASS)
**
**     Description :
**         The funtion initializes Mems endpoint
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
static void USB_Class_Mems_Event(
uint_8 controller_ID,
uint_8 event,
void* val
)
{
    uint_8 index;

    if(event == USB_APP_ENUM_COMPLETE)
    {
        uint_8 count;
        /* get the endpoints from the descriptor module */
        USB_ENDPOINTS *ep_desc_data = (USB_ENDPOINTS *)
        USB_Desc_Get_Endpoints(controller_ID);

        count = ep_desc_data->count;
        /* deinitialize all endpoints in case they were initialized */
        while(count > 0)
        {
            USB_EP_STRUCT_PTR ep_struct_ptr=
            (USB_EP_STRUCT_PTR) (&ep_desc_data->ep[count - 1]);
            (void)_usb_device_deinit_endpoint(&controller_ID,
            ep_struct_ptr->ep_num, ep_struct_ptr->direction);
            count--;
        }

        /* intialize all non control endpoints */
        while(count < ep_desc_data->count)
        {
            USB_EP_STRUCT_PTR ep_struct=
            (USB_EP_STRUCT_PTR)&ep_desc_data->ep[count];

            (void)_usb_device_init_endpoint(&controller_ID, ep_struct->ep_num,
            ep_struct->size, ep_struct->direction, ep_struct->type, TRUE);

            /* register callback service for the endpoint */
            switch(ep_struct->type)
            {
            case USB_INTERRUPT_PIPE:
                (void)_usb_device_register_service(controller_ID,
                (uint_8)(USB_SERVICE_EP0+ep_struct->ep_num),
                USB_Service_Mems_Status_Interrupt);
                break;       
                
            case USB_BULK_PIPE :
               if(ep_struct->direction == USB_RECV)
               {
                     (void)_usb_device_register_service(controller_ID,
                     (uint_8)(USB_SERVICE_EP0+ep_struct->ep_num),
                     USB_Class_MEMS_Service_Dic_Bulk_Out);
               }
               else
               {
                      (void)_usb_device_register_service(controller_ID,
                      (uint_8)(USB_SERVICE_EP0+ep_struct->ep_num),
                      USB_Class_MEMS_Service_Dic_Bulk_In);
               }
               break;
                                
            default:
                break;
            }
            /* set the EndPoint Status as Idle in the device layer */
            (void)_usb_device_set_status(&controller_ID,
            (uint_8)(USB_STATUS_ENDPOINT | 1|
            (ep_struct->direction << USB_COMPONENT_DIRECTION_SHIFT)),
            USB_STATUS_IDLE);
            count++;
        }
    }
    else if(event == USB_APP_BUS_RESET)
    {
        /* clear producer and consumer on reset */
        for(index = 0; index < g_mems_endpoint_data.count; index++)
        {
            g_mems_endpoint_data.ep[index].bin_consumer = 0x00;
            g_mems_endpoint_data.ep[index].bin_producer = 0x00;
            g_mems_endpoint_data.ep[index].queue_num    = 0x00;
        }
    }

    if(g_mems_class_callback != NULL)
    {
        /* notify the event to the application */
        g_mems_class_callback(controller_ID, event, val);
    }
}
Exemple #17
0
/**************************************************************************//*!
 *
 * @name  USB_Class_CDC_Event
 *
 * @brief The function initializes CDC endpoints
 *
 * @param controller_ID : Controller ID
 * @param event         : Event Type
 * @param val           : Pointer to configuration Value
 *
 * @return None
 *
 ******************************************************************************
 *
 *****************************************************************************/
void USB_Class_CDC_Event (
    uint_8 controller_ID,   /* [IN] Controller ID */
    uint_8 event,           /* [IN] Event Type */
    void* val               /* [OUT] Pointer to configuration Value */
)
{
    uint_8 index;
    USB_ENDPOINTS *usb_ep_data = (USB_ENDPOINTS *)
        USB_Desc_Get_Endpoints(controller_ID);

    if(event == USB_APP_ENUM_COMPLETE)
    {
        uint_8 count = 0,ep_count = 0;
        uint_8 index_num = 0;

#ifdef COMPOSITE_DEV
        DEV_ARCHITECTURE_STRUCT_PTR dev_arc_ptr;
        CLASS_ARC_STRUCT_PTR dev_class_ptr;
        dev_arc_ptr = (DEV_ARCHITECTURE_STRUCT *)USB_Desc_Get_Class_Architecture(controller_ID);
        for(count = 0; count < dev_arc_ptr->cl_count; count++)
        {
            dev_class_ptr = (CLASS_ARC_STRUCT_PTR)dev_arc_ptr->value[count];
            /* Initializes sub_classes */
            ep_count = dev_class_ptr->value[0];
            if(dev_class_ptr->class_type == 0x02/*CDC_CC*/)
                break;
            index_num +=dev_class_ptr->value[0];
        }
#else
                ep_count = usb_ep_data->count;
#endif

                for(count=index_num; count<ep_count+index_num; count++)
                {
                        USB_EP_STRUCT_PTR ep_struct_ptr=
                                (USB_EP_STRUCT_PTR) (&usb_ep_data->ep[count]);
                        (void)_usb_device_deinit_endpoint(&controller_ID,
                                ep_struct_ptr->ep_num, ep_struct_ptr->direction);
                }

        /* intialize all non control endpoints */
        for(count=index_num; count<ep_count+index_num; count++)
        {
            USB_EP_STRUCT_PTR ep_struct=
                (USB_EP_STRUCT_PTR) (&usb_ep_data->ep[count]);

            (void)_usb_device_init_endpoint(&controller_ID, ep_struct->ep_num,
                        ep_struct->size, ep_struct->direction, ep_struct->type, FALSE);

            /* register callback service for Non Control EndPoints */
            switch(ep_struct->type)
            {
#if CIC_NOTIF_ELEM_SUPPORT
                case USB_INTERRUPT_PIPE :
                    (void)_usb_device_register_service(controller_ID,
                        (uint_8)(USB_SERVICE_EP0+ep_struct->ep_num),
                        USB_Class_CDC_Service_Cic_Notify);
                    break;
#endif
#if !DIC_ISOCHRONOUS_SETTING
                case USB_BULK_PIPE :
#ifdef MULTIPLE_DEVICES
                    if(ep_struct->direction == USB_RECV)
                    {
                        (void)_usb_device_register_service(controller_ID,
                            (uint_8)(USB_SERVICE_EP0+ep_struct->ep_num),
                            USB_Class_CDC_Service_Dic_Bulk_Out);
                    }
                    else
                    {
                        (void)_usb_device_register_service(controller_ID,
                            (uint_8)(USB_SERVICE_EP0+ep_struct->ep_num),
                            USB_Class_CDC_Service_Dic_Bulk_In);
                    }
#endif
                    break;
#else
                case USB_ISOCHRONOUS_PIPE :
                    if(ep_struct->direction == USB_RECV)
                    {
                        (void)_usb_device_register_service(controller_ID,
                            (uint_8)(USB_SERVICE_EP0+ep_struct->ep_num),
                            USB_Class_CDC_Service_Dic_Iso_Out);
                    }
                    else
                    {
                        (void)_usb_device_register_service(controller_ID,
                            (uint_8)(USB_SERVICE_EP0+ep_struct->ep_num),
                            USB_Class_CDC_Service_Dic_Iso_In);
                    }
                    break;
#endif
                default:
                    break;
            }
            /* set the EndPoint Status as Idle in the device layer */
            (void)_usb_device_set_status(&controller_ID,
                (uint_8)(USB_STATUS_ENDPOINT | ep_struct->ep_num |
                (ep_struct->direction << USB_COMPONENT_DIRECTION_SHIFT)),
                (uint_8)USB_STATUS_IDLE);
        }
    }
    else if(event == USB_APP_BUS_RESET)
    {
#if IMPLEMENT_QUEUING
        for(index = 0; index < usb_ep_data->count; index++)
        {
            g_cdc_ep[index].bin_consumer = 0x00;
            g_cdc_ep[index].bin_producer = 0x00;
        }
#endif
    }
    if(g_cdc_class_callback != NULL)
    {
        g_cdc_class_callback(controller_ID, event, val);
    }
}