USBD ROM Stack  1.0
ROM based USB device stack
mw_usbd/mw_usbd_core.h
Go to the documentation of this file.
00001 /***********************************************************************
00002 * $Id:: mw_usbd_core.h 331 2012-08-09 18:54:34Z usb10131                      $
00003 *
00004 * Project: USB device ROM Stack
00005 *
00006 * Description:
00007 *     USB core controller structure definitions and function prototypes.
00008 *
00009 ***********************************************************************
00010 *   Copyright(C) 2011, NXP Semiconductor
00011 *   All rights reserved.
00012 *
00013 * Software that is described herein is for illustrative purposes only
00014 * which provides customers with programming information regarding the
00015 * products. This software is supplied "AS IS" without any warranties.
00016 * NXP Semiconductors assumes no responsibility or liability for the
00017 * use of the software, conveys no license or title under any patent,
00018 * copyright, or mask work right to the product. NXP Semiconductors
00019 * reserves the right to make changes in the software without
00020 * notification. NXP Semiconductors also make no representation or
00021 * warranty that such application will be suitable for the specified
00022 * use without further testing or modification.
00023 **********************************************************************/
00024 #ifndef __MW_USBD_CORE_H__
00025 #define __MW_USBD_CORE_H__
00026 
00027 #include "error.h"
00028 #include "mw_usbd.h"
00029 #include "app_usbd_cfg.h"
00030 
00048 /* function pointer types */
00049 
00064 typedef ErrorCode_t (*USB_CB_T) (USBD_HANDLE_T hUsb);
00065 
00081 typedef ErrorCode_t (*USB_PARAM_CB_T) (USBD_HANDLE_T hUsb, uint32_t param1);
00082 
00106 typedef ErrorCode_t (*USB_EP_HANDLER_T)(USBD_HANDLE_T hUsb, void* data, uint32_t event);
00107 
00108 
00121 typedef struct _USB_CORE_DESCS_T
00122 {
00123   uint8_t *device_desc; 
00124   uint8_t *string_desc; 
00125   uint8_t *full_speed_desc; 
00128   uint8_t *high_speed_desc; 
00133   uint8_t *device_qualifier; 
00137 } USB_CORE_DESCS_T;
00138 
00146 typedef struct USBD_API_INIT_PARAM
00147 {
00148   uint32_t usb_reg_base; 
00149   uint32_t mem_base;  
00154   uint32_t mem_size;  
00157   uint8_t max_num_ep; 
00161   uint8_t pad0[3];
00162   /* USB Device Events Callback Functions */
00171   USB_CB_T USB_Reset_Event;
00172 
00180   USB_CB_T USB_Suspend_Event;
00181 
00191   USB_CB_T USB_Resume_Event;
00192 
00194   USB_CB_T reserved_sbz;
00195 
00208   USB_CB_T USB_SOF_Event;
00209 
00225   USB_PARAM_CB_T USB_WakeUpCfg;
00226 
00228   USB_PARAM_CB_T USB_Power_Event;
00229 
00238   USB_PARAM_CB_T USB_Error_Event;
00239 
00240   /* USB Core Events Callback Functions */
00250   USB_CB_T USB_Configure_Event;
00251 
00261   USB_CB_T USB_Interface_Event;
00262 
00272  USB_CB_T USB_Feature_Event;
00273 
00274   /* cache and MMU translation functions */
00276   uint32_t (* virt_to_phys)(void* vaddr);
00278   void (* cache_flush)(uint32_t* start_adr, uint32_t* end_adr);
00279 
00280 } USBD_API_INIT_PARAM_T;
00281 
00282 
00294 typedef struct USBD_CORE_API 
00295 {
00316   ErrorCode_t (*RegisterClassHandler)(USBD_HANDLE_T hUsb, USB_EP_HANDLER_T pfn, void* data);
00317 
00340   ErrorCode_t (*RegisterEpHandler)(USBD_HANDLE_T hUsb, uint32_t ep_index, USB_EP_HANDLER_T pfn, void* data);
00341   
00358   void (*SetupStage )(USBD_HANDLE_T hUsb); 
00359   
00376   void (*DataInStage)(USBD_HANDLE_T hUsb);
00377 
00394   void (*DataOutStage)(USBD_HANDLE_T hUsb); 
00395 
00412   void (*StatusInStage)(USBD_HANDLE_T hUsb); 
00429   void (*StatusOutStage)(USBD_HANDLE_T hUsb);
00430 
00447   void (*StallEp0)(USBD_HANDLE_T hUsb);
00448 
00449 } USBD_CORE_API_T;
00450 
00451 /*-----------------------------------------------------------------------------
00452  *  Private functions & structures prototypes
00453  *-----------------------------------------------------------------------------*/
00454 
00457 /* forward declaration */
00458 struct _USB_CORE_CTRL_T;
00459 typedef struct _USB_CORE_CTRL_T  USB_CORE_CTRL_T;
00460 
00461 /* USB device Speed status defines */
00462 #define USB_FULL_SPEED    0
00463 #define USB_HIGH_SPEED    1
00464 
00465 /* USB Endpoint Data Structure */
00466 typedef struct _USB_EP_DATA
00467 {
00468   uint8_t  *pData;
00469   uint16_t   Count;
00470   uint16_t pad0;
00471 } USB_EP_DATA;
00472 
00473 
00474 /* USB core controller data structure */
00475 struct _USB_CORE_CTRL_T
00476 {
00477   /* override-able function pointers ~ c++ style virtual functions*/
00478   USB_CB_T USB_EvtSetupHandler;
00479   USB_CB_T USB_EvtOutHandler;
00480   USB_PARAM_CB_T USB_ReqVendor;
00481   USB_CB_T USB_ReqGetStatus;
00482   USB_CB_T USB_ReqGetDescriptor;
00483   USB_CB_T USB_ReqGetConfiguration;
00484   USB_CB_T USB_ReqSetConfiguration;
00485   USB_CB_T USB_ReqGetInterface;
00486   USB_CB_T USB_ReqSetInterface;
00487   USB_PARAM_CB_T USB_ReqSetClrFeature;
00488 
00489   /* USB Device Events Callback Functions */
00490   USB_CB_T USB_Reset_Event;
00491   USB_CB_T USB_Suspend_Event;
00492   USB_CB_T USB_Resume_Event;
00493   USB_CB_T USB_SOF_Event;
00494   USB_PARAM_CB_T USB_Power_Event;
00495   USB_PARAM_CB_T USB_Error_Event;
00496   USB_PARAM_CB_T USB_WakeUpCfg;
00497 
00498   /* USB Core Events Callback Functions */
00499   USB_CB_T USB_Configure_Event;
00500   USB_CB_T USB_Interface_Event;
00501   USB_CB_T USB_Feature_Event;
00502 
00503   /* cache and MMU translation functions */
00504   uint32_t (* virt_to_phys)(void* vaddr);
00505   void (* cache_flush)(uint32_t* start_adr, uint32_t* end_adr);
00506 
00507   /* event handlers for endpoints. */
00508   USB_EP_HANDLER_T  ep_event_hdlr[2 * USB_MAX_EP_NUM];
00509   void*  ep_hdlr_data[2 * USB_MAX_EP_NUM];
00510 
00511   /* USB class handlers */
00512   USB_EP_HANDLER_T  ep0_hdlr_cb[USB_MAX_IF_NUM];
00513   void*  ep0_cb_data[USB_MAX_IF_NUM];
00514   uint8_t num_ep0_hdlrs;
00515   /* USB Core data Variables */
00516   uint8_t max_num_ep; /* max number of endpoints supported by the HW */
00517   uint8_t device_speed;
00518   uint8_t  num_interfaces;
00519   uint8_t  device_addr;
00520   uint8_t  config_value;
00521   uint16_t device_status;
00522   uint8_t *device_desc;
00523   uint8_t *string_desc;
00524   uint8_t *full_speed_desc;
00525   uint8_t *high_speed_desc;
00526   uint8_t *device_qualifier;
00527   uint32_t ep_mask;
00528   uint32_t ep_halt;
00529   uint32_t ep_stall;
00530   uint8_t  alt_setting[USB_MAX_IF_NUM];
00531   /* HW driver data pointer */
00532   void* hw_data;
00533 
00534   /* USB Endpoint 0 Data Info */
00535   USB_EP_DATA EP0Data;
00536 
00537   /* USB Endpoint 0 Buffer */
00538   //ALIGNED(4)
00539   uint8_t  EP0Buf[64];
00540 
00541   /* USB Setup Packet */
00542   //ALIGNED(4)
00543   USB_SETUP_PACKET SetupPacket;
00544 
00545 };
00546 
00547 /* USB Core Functions */
00548 extern void mwUSB_InitCore(USB_CORE_CTRL_T* pCtrl, USB_CORE_DESCS_T* pdescr, USBD_API_INIT_PARAM_T* param);
00549 extern void mwUSB_ResetCore(USBD_HANDLE_T hUsb);
00550 
00551 /* inline functions */
00552 __inline void USB_SetSpeedMode(USB_CORE_CTRL_T* pCtrl, uint8_t mode)
00553 {
00554   pCtrl->device_speed = mode;   
00555 }
00556 
00558 /* midleware API */
00559 extern ErrorCode_t mwUSB_RegisterClassHandler(USBD_HANDLE_T hUsb, USB_EP_HANDLER_T pfn, void* data);
00560 extern ErrorCode_t mwUSB_RegisterEpHandler(USBD_HANDLE_T hUsb, uint32_t ep_index, USB_EP_HANDLER_T pfn, void* data);
00561 extern void mwUSB_SetupStage (USBD_HANDLE_T hUsb); 
00562 extern void mwUSB_DataInStage(USBD_HANDLE_T hUsb);
00563 extern void mwUSB_DataOutStage(USBD_HANDLE_T hUsb); 
00564 extern void mwUSB_StatusInStage(USBD_HANDLE_T hUsb); 
00565 extern void mwUSB_StatusOutStage(USBD_HANDLE_T hUsb);
00566 extern void mwUSB_StallEp0(USBD_HANDLE_T hUsb);
00567 extern ErrorCode_t mwUSB_RegisterClassHandler(USBD_HANDLE_T hUsb, USB_EP_HANDLER_T pfn, void* data);
00568 extern ErrorCode_t mwUSB_RegisterEpHandler(USBD_HANDLE_T hUsb, uint32_t ep_index, USB_EP_HANDLER_T pfn, void* data);
00569 extern void mwUSB_SetupStage (USBD_HANDLE_T hUsb); 
00570 extern void mwUSB_DataInStage(USBD_HANDLE_T hUsb);
00571 extern void mwUSB_DataOutStage(USBD_HANDLE_T hUsb); 
00572 extern void mwUSB_StatusInStage(USBD_HANDLE_T hUsb); 
00573 extern void mwUSB_StatusOutStage(USBD_HANDLE_T hUsb);
00574 extern void mwUSB_StallEp0(USBD_HANDLE_T hUsb);
00579 #endif  /* __MW_USBD_CORE_H__ */