LPCOpen Platform
LPCOpen Platform for NXP LPC Microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
usbd_core.h
Go to the documentation of this file.
1 /*
2  * @brief Definition of functions exported by core layer of ROM based USB device stack
3  *
4  * @note
5  * Copyright(C) NXP Semiconductors, 2012
6  * All rights reserved.
7  *
8  * @par
9  * Software that is described herein is for illustrative purposes only
10  * which provides customers with programming information regarding the
11  * LPC products. This software is supplied "AS IS" without any warranties of
12  * any kind, and NXP Semiconductors and its licensor disclaim any and
13  * all warranties, express or implied, including all implied warranties of
14  * merchantability, fitness for a particular purpose and non-infringement of
15  * intellectual property rights. NXP Semiconductors assumes no responsibility
16  * or liability for the use of the software, conveys no license or rights under any
17  * patent, copyright, mask work right, or any other intellectual property rights in
18  * or to any products. NXP Semiconductors reserves the right to make changes
19  * in the software without notification. NXP Semiconductors also makes no
20  * representation or warranty that such application will be suitable for the
21  * specified use without further testing or modification.
22  *
23  * @par
24  * Permission to use, copy, modify, and distribute this software and its
25  * documentation is hereby granted, under NXP Semiconductors' and its
26  * licensor's relevant copyrights in the software, without fee, provided that it
27  * is used in conjunction with NXP Semiconductors microcontrollers. This
28  * copyright, permission, and disclaimer notice must appear in all copies of
29  * this code.
30  */
31 
32 #ifndef __MW_USBD_CORE_H__
33 #define __MW_USBD_CORE_H__
34 
35 #include "error.h"
36 #include "usbd.h"
37 #include "lpc_types.h"
38 
49 /* function pointer types */
50 
66 
83 
107 typedef ErrorCode_t (*USB_EP_HANDLER_T)(USBD_HANDLE_T hUsb, void* data, uint32_t event);
108 
109 
122 typedef struct _USB_CORE_DESCS_T
123 {
124  uint8_t *device_desc;
125  uint8_t *string_desc;
126  uint8_t *full_speed_desc;
129  uint8_t *high_speed_desc;
134  uint8_t *device_qualifier;
139 
147 typedef struct USBD_API_INIT_PARAM
148 {
150  uint32_t mem_base;
155  uint32_t mem_size;
158  uint8_t max_num_ep;
163  /* USB Device Events Callback Functions */
173 
182 
193 
196 
210 
226 
229 
239 
240  /* USB Core Events Callback Functions */
251 
262 
273 
274  /* cache and mmu translation functions */
276  uint32_t (* virt_to_phys)(void* vaddr);
278  void (* cache_flush)(uint32_t* start_adr, uint32_t* end_adr);
279 
281 
282 
294 typedef struct USBD_CORE_API
295 {
316  ErrorCode_t (*RegisterClassHandler)(USBD_HANDLE_T hUsb, USB_EP_HANDLER_T pfn, void* data);
317 
336  ErrorCode_t (*RegisterEpHandler)(USBD_HANDLE_T hUsb, uint32_t ep_index, USB_EP_HANDLER_T pfn, void* data);
337 
354  void (*SetupStage )(USBD_HANDLE_T hUsb);
355 
372  void (*DataInStage)(USBD_HANDLE_T hUsb);
373 
390  void (*DataOutStage)(USBD_HANDLE_T hUsb);
391 
408  void (*StatusInStage)(USBD_HANDLE_T hUsb);
425  void (*StatusOutStage)(USBD_HANDLE_T hUsb);
426 
443  void (*StallEp0)(USBD_HANDLE_T hUsb);
444 
446 
447 /*-----------------------------------------------------------------------------
448  * Private functions & structures prototypes
449  *-----------------------------------------------------------------------------*/
450 
453 /* forward declaration */
454 struct _USB_CORE_CTRL_T;
455 typedef struct _USB_CORE_CTRL_T USB_CORE_CTRL_T;
456 
457 /* USB device Speed status defines */
458 #define USB_FULL_SPEED 0
459 #define USB_HIGH_SPEED 1
460 
461 /* USB Endpoint Data Structure */
462 typedef struct _USB_EP_DATA
463 {
464  uint8_t *pData;
465  uint16_t Count;
466 } USB_EP_DATA;
467 
468 #define USB_MAX_IF_NUM 8
469 #define USB_MAX_EP_NUM 6
470 
471 /* USB core controller data structure */
472 struct _USB_CORE_CTRL_T
473 {
474  /* overridable function pointers ~ c++ style virtual functions*/
475  USB_CB_T USB_EvtSetupHandler;
476  USB_CB_T USB_EvtOutHandler;
477  USB_PARAM_CB_T USB_ReqVendor;
478  USB_CB_T USB_ReqGetStatus;
479  USB_CB_T USB_ReqGetDescriptor;
480  USB_CB_T USB_ReqGetConfiguration;
481  USB_CB_T USB_ReqSetConfiguration;
482  USB_CB_T USB_ReqGetInterface;
483  USB_CB_T USB_ReqSetInterface;
484  USB_PARAM_CB_T USB_ReqSetClrFeature;
485 
486  /* USB Device Events Callback Functions */
487  USB_CB_T USB_Reset_Event;
488  USB_CB_T USB_Suspend_Event;
489  USB_CB_T USB_Resume_Event;
490  USB_CB_T USB_SOF_Event;
491  USB_PARAM_CB_T USB_Power_Event;
492  USB_PARAM_CB_T USB_Error_Event;
493  USB_PARAM_CB_T USB_WakeUpCfg;
494 
495  /* USB Core Events Callback Functions */
496  USB_CB_T USB_Configure_Event;
498  USB_CB_T USB_Feature_Event;
499 
500  /* cache and mmu translation functions */
501  uint32_t (* virt_to_phys)(void* vaddr);
502  void (* cache_flush)(uint32_t* start_adr, uint32_t* end_adr);
503 
504  /* event handlers for endpoints. */
505  USB_EP_HANDLER_T ep_event_hdlr[2 * USB_MAX_EP_NUM];
506  void* ep_hdlr_data[2 * USB_MAX_EP_NUM];
507 
508  /* USB class handlers */
509  USB_EP_HANDLER_T ep0_hdlr_cb[USB_MAX_IF_NUM];
510  void* ep0_cb_data[USB_MAX_IF_NUM];
511  uint8_t num_ep0_hdlrs;
512  /* USB Core data Variables */
513  uint8_t max_num_ep; /* max number of endpoints supported by the HW */
514  uint8_t device_speed;
515  uint8_t num_interfaces;
516  uint8_t device_addr;
517  uint8_t config_value;
518  uint16_t device_status;
519  uint8_t *device_desc;
520  uint8_t *string_desc;
521  uint8_t *full_speed_desc;
522  uint8_t *high_speed_desc;
523  uint8_t *device_qualifier;
524  uint32_t ep_mask;
525  uint32_t ep_halt;
526  uint32_t ep_stall;
527  uint8_t alt_setting[USB_MAX_IF_NUM];
528  /* HW driver data pointer */
529  void* hw_data;
530 
531  /* USB Endpoint 0 Data Info */
532  USB_EP_DATA EP0Data;
533 
534  /* USB Endpoint 0 Buffer */
535  //ALIGNED(4)
536  uint8_t EP0Buf[64];
537 
538  /* USB Setup Packet */
539  //ALIGNED(4)
540  USB_SETUP_PACKET SetupPacket;
541 
542 };
543 
544 
545 static INLINE void USB_SetSpeedMode(USB_CORE_CTRL_T* pCtrl, uint8_t mode)
546 {
547  pCtrl->device_speed = mode;
548 }
551 #endif /* __MW_USBD_CORE_H__ */