Exemplo n.º 1
0
/**************************************************************************//*!
 *
 * @name  _usb_device_init
 *
 * @brief The function initializes the Device and Controller layer
 *
 * @param device_number       : USB Device controller to initialize
 * @param handle              : pointer to USB Device handle
 * @param number_of_endpoints : Endpoint count of the application
 *
 * @return status
 *         USB_OK                              : When Successfull
 *         USBERR_INVALID_NUM_OF_ENDPOINTS     : When endpoints > max Supported
 ******************************************************************************
 * This function initializes the Device layer and the Controller layer of the
 * S08 USB stack. It initializes the variables used for this layer and then
 * calls the controller layer initialize function
 *****************************************************************************/
uint_8 _usb_device_init (
    uint_8    device_number,			/* [IN] USB Device controller to initialize */
    _usb_device_handle _PTR_  handle,	/* [IN] Pointer to USB Device handle */
    uint_8    number_of_endpoints,		/* [IN] Number of endpoints to initialize */
    uint_8    bVregEn        			/* Enables or disables internal regulator */
)
{
	UNUSED(handle);

    /* validate endpoints param */
    if((number_of_endpoints > MAX_SUPPORTED_ENDPOINTS) ||
      (number_of_endpoints < MIN_SUPPORTED_ENDPOINTS))
    {
        return USBERR_INVALID_NUM_OF_ENDPOINTS;
    }

    /* init variables */
    g_EPn_max = (uint_8)(number_of_endpoints - 1);

    USB_Device_Init_Params();

#ifdef MULTIPLE_DEVICES
    /* Initialize all services to null value */
    Clear_Mem((uint_8_ptr)g_usb_CB,
        (uint_32)(sizeof(USB_SERVICE_CALLBACK) * USB_SERVICE_MAX), (uint_8)0);
#endif
    /* Call controller layer initialization function */
    return USB_DCI_Init(device_number, bVregEn);

}
Exemplo n.º 2
0
/******************************************************************************
 * Function:        void USB_Bus_Reset_Handler(void)
 *
 * Input:           None
 * Output:          None
 *
 * Overview:        Once a USB bus reset is received from the host, this
 *                  function should be called. It resets the device address to
 *                  zero, disables all non-EP0 endpoints, initializes EP0 to
 *                  be ready for default communication, clears all USB
 *                  interrupt flags, unmasks applicable USB interrupts, and
 *                  reinitializes internal state-machine.
 *****************************************************************************/
void USB_Bus_Reset_Handler(void)
{
    ERRSTAT = 0xFF;                 /* clear USB error flag*/
    
    CTL = 0x02;                     /*Reset all ping-pong buffer, and SIE logic*/

    while(INTSTAT_TOKDNEF )         /* Flush any pending transactions because 4 status buffer*/
        INTSTAT = 0xBF;              
   
    CTL = 0x01;

    ADDR = 0x00;                    /* reset to default address*/
  
    Clear_Mem((byte*)&EPCTL0,7);    /* disable all endpoints */
    EPCTL0 = EP_CTRL|HSHK_EN;       /* enable endpoint 0*/

 
    USB_Prepare_Next_Trf();         /*prepare to receive the setup packet*/
  	
    Usb_Stat.BitCtl.RemoteWakeup = 0;       /* default status flag to disable*/
    Usb_Active_Cfg = 0;                    

   
    Usb_Device_State = DEFAULT_STATE;
    Old_Usb_State = DEFAULT_STATE ;
    
    
    ERRENB = 0xBF;                  /* disable all USB error interrupt sources*/
    #ifdef ENABLE_SOF_INT
   	INTENB = 0x9F;                  /* enable all interrupts except RESUME*/
   	#else
   	INTENB = 0x9B; 
   	#endif
    
}
Exemplo n.º 3
0
/*
** ===================================================================
**     Method      :  usb_device__usb_device_init (component USB_DEVICE_STACK)
**     Description :
**         This function initializes the Device layer and the
**         Controller layer of the S08 USB stack. It initialised the
**         variables used for this layer and then calls the controller
**         layer initialize function
**     Parameters  :
**         NAME            - DESCRIPTION
**         device_number   - [IN] USB Device
**                           controller to initialize
**       * handle          - [IN] Pointer to USB Device handle
**         number_of_endpoints - [IN]
**                           Number of endpoints to initialize
**     Returns     :
**         ---             - Error code
** ===================================================================
*/
uint_8  _usb_device_init(uint_8 device_number, _usb_device_handle _PTR_ handle, uint_8 number_of_endpoints)
{
    UNUSED(handle);

    /* validate endpoints param */
    if((number_of_endpoints > MAX_SUPPORTED_ENDPOINTS) ||
       (number_of_endpoints < MIN_SUPPORTED_ENDPOINTS))
    {
        return USBERR_INVALID_NUM_OF_ENDPOINTS;
    }

    /*init variables */
    g_EPn_max = (uint_8)(number_of_endpoints - 1);

    USB_Device_Init_Params();

    /* Initialize all services to null value */
    Clear_Mem((uint_8_ptr)g_usb_CB,
        (sizeof(USB_SERVICE_CALLBACK) * USB_SERVICE_MAX), (uint_8)NULL);
    /* Call controller layer initialization function */
    return USB_DCI_Init(device_number);
}