| LPCOpen Platform v1.03 LPCOpen Platform for NXP LPC Microcontrollers

- Main Page
- Modules
- Data Structures
- Files
- Related Pages

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
usbd_core.h
Go to the documentation of this file.
1 /***********************************************************************
2 * $Id: mw_usbd_core.h.rca 1.4 Tue Nov 1 11:45:07 2011 nlv09221 Experimental $
3 *
4 * Project: USB device ROM Stack
5 *
6 * Description:
7 * USB core controller structure defnitions and function prototypes.
8 *
9 ***********************************************************************
10 * Copyright(C) 2011, NXP Semiconductor
11 * All rights reserved.
12 *
13 * Software that is described herein is for illustrative purposes only
14 * which provides customers with programming information regarding the
15 * products. This software is supplied "AS IS" without any warranties.
16 * NXP Semiconductors assumes no responsibility or liability for the
17 * use of the software, conveys no license or title under any patent,
18 * copyright, or mask work right to the product. NXP Semiconductors
19 * reserves the right to make changes in the software without
20 * notification. NXP Semiconductors also make no representation or
21 * warranty that such application will be suitable for the specified
22 * use without further testing or modification.
23 **********************************************************************/
24 #ifndef __MW_USBD_CORE_H__
25 #define __MW_USBD_CORE_H__
26
27 #include "error.h"
28 #include "usbd.h"
29 #include "app_usbd_cfg.h"
30
48 /* function pointer types */
49
64 typedef ErrorCode_t (*USB_CB_T) (USBD_HANDLE_T hUsb);
65
81 typedef ErrorCode_t (*USB_PARAM_CB_T) (USBD_HANDLE_T hUsb, uint32_t param1);
82
106 typedef ErrorCode_t (*USB_EP_HANDLER_T)(USBD_HANDLE_T hUsb, void* data, uint32_t event);
107
108
121 typedef struct _USB_CORE_DESCS_T
122 {
123 uint8_t *device_desc;
124 uint8_t *string_desc;
125 uint8_t *full_speed_desc;
128 uint8_t *high_speed_desc;
133 uint8_t *device_qualifier;
137 } USB_CORE_DESCS_T;
138
146 typedef struct USBD_API_INIT_PARAM
147 {
148 uint32_t usb_reg_base;
149 uint32_t mem_base;
154 uint32_t mem_size;
157 uint8_t max_num_ep;
161 uint8_t pad0[3];
162 /* USB Device Events Callback Functions */
171 USB_CB_T USB_Reset_Event;
172
180 USB_CB_T USB_Suspend_Event;
181
191 USB_CB_T USB_Resume_Event;
192
194 USB_CB_T reserved_sbz;
195
208 USB_CB_T USB_SOF_Event;
209
225 USB_PARAM_CB_T USB_WakeUpCfg;
226
228 USB_PARAM_CB_T USB_Power_Event;
229
238 USB_PARAM_CB_T USB_Error_Event;
239
240 /* USB Core Events Callback Functions */
250 USB_CB_T USB_Configure_Event;
251
261 USB_CB_T USB_Interface_Event;
262
272 USB_CB_T USB_Feature_Event;
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
280 } USBD_API_INIT_PARAM_T;
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
445 } USBD_CORE_API_T;
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 uint16_t pad0;
467 } USB_EP_DATA;
468
469
470 /* USB core controller data structure */
471 struct _USB_CORE_CTRL_T
472 {
473 /* overridable function pointers ~ c++ style virtual functions*/
474 USB_CB_T USB_EvtSetupHandler;
475 USB_CB_T USB_EvtOutHandler;
476 USB_PARAM_CB_T USB_ReqVendor;
477 USB_CB_T USB_ReqGetStatus;
478 USB_CB_T USB_ReqGetDescriptor;
479 USB_CB_T USB_ReqGetConfiguration;
480 USB_CB_T USB_ReqSetConfiguration;
481 USB_CB_T USB_ReqGetInterface;
482 USB_CB_T USB_ReqSetInterface;
483 USB_PARAM_CB_T USB_ReqSetClrFeature;
484
485 /* USB Device Events Callback Functions */
486 USB_CB_T USB_Reset_Event;
487 USB_CB_T USB_Suspend_Event;
488 USB_CB_T USB_Resume_Event;
489 USB_CB_T USB_SOF_Event;
490 USB_PARAM_CB_T USB_Power_Event;
491 USB_PARAM_CB_T USB_Error_Event;
492 USB_PARAM_CB_T USB_WakeUpCfg;
493
494 /* USB Core Events Callback Functions */
495 USB_CB_T USB_Configure_Event;
496 USB_CB_T USB_Interface_Event;
497 USB_CB_T USB_Feature_Event;
498
499 /* cache and mmu translation functions */
500 uint32_t (* virt_to_phys)(void* vaddr);
501 void (* cache_flush)(uint32_t* start_adr, uint32_t* end_adr);
502
503 /* event handlers for endpoints. */
504 USB_EP_HANDLER_T ep_event_hdlr[2 * USB_MAX_EP_NUM];
505 void* ep_hdlr_data[2 * USB_MAX_EP_NUM];
506
507 /* USB class handlers */
508 USB_EP_HANDLER_T ep0_hdlr_cb[USB_MAX_IF_NUM];
509 void* ep0_cb_data[USB_MAX_IF_NUM];
510 uint8_t num_ep0_hdlrs;
511 /* USB Core data Variables */
512 uint8_t max_num_ep; /* max number of endpoints supported by the HW */
513 uint8_t device_speed;
514 uint8_t num_interfaces;
515 uint8_t device_addr;
516 uint8_t config_value;
517 uint16_t device_status;
518 uint8_t *device_desc;
519 uint8_t *string_desc;
520 uint8_t *full_speed_desc;
521 uint8_t *high_speed_desc;
522 uint8_t *device_qualifier;
523 uint32_t ep_mask;
524 uint32_t ep_halt;
525 uint32_t ep_stall;
526 uint8_t alt_setting[USB_MAX_IF_NUM];
527 /* HW driver data pointer */
528 void* hw_data;
529
530 /* USB Endpoint 0 Data Info */
531 USB_EP_DATA EP0Data;
532
533 /* USB Endpoint 0 Buffer */
534 //ALIGNED(4)
535 uint8_t EP0Buf[64];
536
537 /* USB Setup Packet */
538 //ALIGNED(4)
539 USB_SETUP_PACKET SetupPacket;
540
541 };
542
543 /* USB Core Functions */
544 extern void mwUSB_InitCore(USB_CORE_CTRL_T* pCtrl, USB_CORE_DESCS_T* pdescr, USBD_API_INIT_PARAM_T* param);
545 extern void mwUSB_ResetCore(USBD_HANDLE_T hUsb);
546
547 /* inline functions */
548 __inline void USB_SetSpeedMode(USB_CORE_CTRL_T* pCtrl, uint8_t mode)
549 {
550 pCtrl->device_speed = mode;
551 }
552
554 /* midleware API */
555 extern ErrorCode_t mwUSB_RegisterClassHandler(USBD_HANDLE_T hUsb, USB_EP_HANDLER_T pfn, void* data);
556 extern ErrorCode_t mwUSB_RegisterEpHandler(USBD_HANDLE_T hUsb, uint32_t ep_index, USB_EP_HANDLER_T pfn, void* data);
557 extern void mwUSB_SetupStage (USBD_HANDLE_T hUsb);
558 extern void mwUSB_DataInStage(USBD_HANDLE_T hUsb);
559 extern void mwUSB_DataOutStage(USBD_HANDLE_T hUsb);
560 extern void mwUSB_StatusInStage(USBD_HANDLE_T hUsb);
561 extern void mwUSB_StatusOutStage(USBD_HANDLE_T hUsb);
562 extern void mwUSB_StallEp0(USBD_HANDLE_T hUsb);
563 extern ErrorCode_t mwUSB_RegisterClassHandler(USBD_HANDLE_T hUsb, USB_EP_HANDLER_T pfn, void* data);
564 extern ErrorCode_t mwUSB_RegisterEpHandler(USBD_HANDLE_T hUsb, uint32_t ep_index, USB_EP_HANDLER_T pfn, void* data);
565 extern void mwUSB_SetupStage (USBD_HANDLE_T hUsb);
566 extern void mwUSB_DataInStage(USBD_HANDLE_T hUsb);
567 extern void mwUSB_DataOutStage(USBD_HANDLE_T hUsb);
568 extern void mwUSB_StatusInStage(USBD_HANDLE_T hUsb);
569 extern void mwUSB_StatusOutStage(USBD_HANDLE_T hUsb);
570 extern void mwUSB_StallEp0(USBD_HANDLE_T hUsb);
575 #endif /* __MW_USBD_CORE_H__ */