| USBD ROM Stack 1.0 ROM based USB device stack

mw_usbd_core.h
Go to the documentation of this file.
1 /***********************************************************************
2 * $Id:: mw_usbd_core.h 2520 2017-06-06 21:33:34Z usb00423 $
3 *
4 * Project: USB device ROM Stack
5 *
6 * Description:
7 * USB core controller structure definitions 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 "mw_usbd.h"
29 #include "usbd_cfg.h"
30
47 /* function pointer types */
48
63 typedef ErrorCode_t (*USB_CB_T) (USBD_HANDLE_T hUsb);
64
80 typedef ErrorCode_t (*USB_PARAM_CB_T) (USBD_HANDLE_T hUsb, uint32_t param1);
81
105 typedef ErrorCode_t (*USB_EP_HANDLER_T)(USBD_HANDLE_T hUsb, void *data, uint32_t event);
106
119 typedef struct _USB_CORE_DESCS_T {
120 uint8_t *device_desc;
121 uint8_t *string_desc;
122 uint8_t *full_speed_desc;
128 uint8_t *high_speed_desc;
136 uint8_t *device_qualifier;
140 uint8_t *bos_descriptor;
142 } USB_CORE_DESCS_T;
143
151 typedef struct USBD_API_INIT_PARAM {
152 uint32_t usb_reg_base;
153 uint32_t mem_base;
158 uint32_t mem_size;
161 uint8_t max_num_ep;
165 uint8_t high_speed_capable;
167 uint8_t double_buffer;
168 uint8_t pad0[1];
169 /* USB Device Events Callback Functions */
178 USB_CB_T USB_Reset_Event;
179
187 USB_CB_T USB_Suspend_Event;
188
198 USB_CB_T USB_Resume_Event;
199
201 USB_CB_T reserved_sbz;
202
215 USB_CB_T USB_SOF_Event;
216
232 USB_PARAM_CB_T USB_WakeUpCfg;
233
235 USB_PARAM_CB_T USB_Power_Event;
236
245 USB_PARAM_CB_T USB_Error_Event;
246
247 /* USB Core Events Callback Functions */
257 USB_CB_T USB_Configure_Event;
258
268 USB_CB_T USB_Interface_Event;
269
279 USB_CB_T USB_Feature_Event;
280
281 /* cache and MMU translation functions */
283 uint32_t (*virt_to_phys)(void *vaddr);
285 void (*cache_flush)(uint32_t *start_adr, uint32_t *end_adr);
286 uint32_t lpm_setting;
306 ErrorCode_t (*USB_ReqGetStringDesc)(USBD_HANDLE_T hUsb, USB_SETUP_PACKET* setupPacket, uint8_t** pD);
307 } USBD_API_INIT_PARAM_T;
308
320 typedef struct USBD_CORE_API {
341 ErrorCode_t (*RegisterClassHandler)(USBD_HANDLE_T hUsb, USB_EP_HANDLER_T pfn, void *data);
342
365 ErrorCode_t (*RegisterEpHandler)(USBD_HANDLE_T hUsb, uint32_t ep_index, USB_EP_HANDLER_T pfn, void *data);
366
383 void (*SetupStage )(USBD_HANDLE_T hUsb);
384
401 void (*DataInStage)(USBD_HANDLE_T hUsb);
402
419 void (*DataOutStage)(USBD_HANDLE_T hUsb);
420
437 void (*StatusInStage)(USBD_HANDLE_T hUsb);
454 void (*StatusOutStage)(USBD_HANDLE_T hUsb);
455
472 void (*StallEp0)(USBD_HANDLE_T hUsb);
473
493 ErrorCode_t (*GetEpHandler)(USBD_HANDLE_T hUsb, uint32_t ep_index, USB_EP_HANDLER_T *ep_handler, void * *data);
494
495 } USBD_CORE_API_T;
496
497 /*-----------------------------------------------------------------------------
498 * Private functions & structures prototypes
499 *-----------------------------------------------------------------------------*/
500
503 /* Abstract declaration to avoid circular includes */
504 struct _USB_CORE_CTRL_T;
505
506 typedef struct _USB_CORE_CTRL_T USB_CORE_CTRL_T;
507
508 /* For declaration below */
509 struct USBD_HW_API;
510
511 /* USB device Speed status defines */
512 #define USB_FULL_SPEED 0
513 #define USB_HIGH_SPEED 1
514
515 /* USB Endpoint Data Structure */
516 typedef struct _USB_EP_DATA {
517 uint8_t *pData;
518 uint16_t Count;
519 uint16_t pad0;
520 } USB_EP_DATA;
521
522 /* USB core controller data structure */
523 struct _USB_CORE_CTRL_T {
524 /* override-able function pointers ~ c++ style virtual functions*/
525 USB_CB_T USB_EvtSetupHandler;
526 USB_CB_T USB_EvtOutHandler;
527 USB_PARAM_CB_T USB_ReqVendor;
528 USB_CB_T USB_ReqGetStatus;
529 USB_CB_T USB_ReqGetDescriptor;
530 USB_CB_T USB_ReqGetConfiguration;
531 USB_CB_T USB_ReqSetConfiguration;
532 USB_CB_T USB_ReqGetInterface;
533 USB_CB_T USB_ReqSetInterface;
534 USB_PARAM_CB_T USB_ReqSetClrFeature;
535
536 /* USB Device Events Callback Functions */
537 USB_CB_T USB_Reset_Event;
538 USB_CB_T USB_Suspend_Event;
539 USB_CB_T USB_Resume_Event;
540 USB_CB_T USB_SOF_Event;
541 USB_PARAM_CB_T USB_Power_Event;
542 USB_PARAM_CB_T USB_Error_Event;
543 USB_PARAM_CB_T USB_WakeUpCfg;
544
545 /* USB Core Events Callback Functions */
546 USB_CB_T USB_Configure_Event;
547 USB_CB_T USB_Interface_Event;
548 USB_CB_T USB_Feature_Event;
549
550 /* cache and MMU translation functions */
551 uint32_t (*virt_to_phys)(void *vaddr);
552 void (*cache_flush)(uint32_t *start_adr, uint32_t *end_adr);
553
554 /* event handlers for endpoints. */
555 USB_EP_HANDLER_T ep_event_hdlr[2 * USB_MAX_EP_NUM];
556 void *ep_hdlr_data[2 * USB_MAX_EP_NUM];
557
558 /* USB class handlers */
559 USB_EP_HANDLER_T ep0_hdlr_cb[USB_MAX_IF_NUM];
560 void *ep0_cb_data[USB_MAX_IF_NUM];
561 uint8_t num_ep0_hdlrs;
562 /* USB Core data Variables */
563 uint8_t max_num_ep; /* max number of endpoints supported by the HW */
564 uint8_t device_speed;/* actually USB speed running on the bus after CHIRP. */
565 uint8_t num_interfaces;
566 uint8_t device_addr;
567 uint8_t config_value;
568 uint16_t device_status;
569 uint8_t *device_desc;
570 uint8_t *string_desc;
571 uint8_t *full_speed_desc;
572 uint8_t *high_speed_desc;
573 uint8_t *device_qualifier;
574 uint32_t ep_mask;
575 uint32_t ep_halt;
576 uint32_t ep_stall;
577 /* Current selected alt intf number. Upper 4 bits store number of alt interface present for given interface */
578 uint8_t alt_setting[USB_MAX_IF_NUM];
579 /* HW driver data pointer */
580 void *hw_data;
581
582 /* USB Endpoint 0 Data Info */
583 USB_EP_DATA EP0Data;
584
585 /* USB Endpoint 0 Buffer */
586 // ALIGNED(4)
587 uint8_t EP0Buf[64];
588
589 /* USB Setup Packet */
590 // ALIGNED(4)
591 USB_SETUP_PACKET SetupPacket;
592 uint32_t lpm_setting;
593 ErrorCode_t (*USB_ReqGetStringDesc)(USBD_HANDLE_T hUsb, USB_SETUP_PACKET* setupPacket, uint8_t** pData);
594 uint8_t *bos_descriptor;
595
596 const struct USBD_HW_API *hw_api;
597 };
598
599 /* USB Core Functions */
600 extern void mwUSB_InitCore(USB_CORE_CTRL_T *pCtrl, USB_CORE_DESCS_T *pdescr, USBD_API_INIT_PARAM_T *param);
601
602 extern void mwUSB_ResetCore(USBD_HANDLE_T hUsb);
603
604 /* inline functions */
605 static INLINE uint32_t USB_IsConfigured(USBD_HANDLE_T hUsb)
606 {
607 USB_CORE_CTRL_T *pCtrl = (USB_CORE_CTRL_T *) hUsb;
608 return (pCtrl->config_value != 0);
609 }
610
612 /* midleware API */
613 extern ErrorCode_t mwUSB_RegisterClassHandler(USBD_HANDLE_T hUsb, USB_EP_HANDLER_T pfn, void *data);
614
615 extern ErrorCode_t mwUSB_RegisterEpHandler(USBD_HANDLE_T hUsb, uint32_t ep_index, USB_EP_HANDLER_T pfn, void *data);
616
617 extern void mwUSB_SetupStage (USBD_HANDLE_T hUsb);
618
619 extern void mwUSB_DataInStage(USBD_HANDLE_T hUsb);
620
621 extern void mwUSB_DataOutStage(USBD_HANDLE_T hUsb);
622
623 extern void mwUSB_StatusInStage(USBD_HANDLE_T hUsb);
624
625 extern void mwUSB_StatusOutStage(USBD_HANDLE_T hUsb);
626
627 extern void mwUSB_StallEp0(USBD_HANDLE_T hUsb);
628
629 extern ErrorCode_t mwUSB_RegisterClassHandler(USBD_HANDLE_T hUsb, USB_EP_HANDLER_T pfn, void *data);
630
631 extern ErrorCode_t mwUSB_RegisterEpHandler(USBD_HANDLE_T hUsb, uint32_t ep_index, USB_EP_HANDLER_T pfn, void *data);
632
633 extern ErrorCode_t mwUSB_GetEpHandler(USBD_HANDLE_T hUsb, uint32_t ep_index, USB_EP_HANDLER_T *ep_handler,
634 void * *data);
635
636 extern void mwUSB_SetupStage (USBD_HANDLE_T hUsb);
637
638 extern void mwUSB_DataInStage(USBD_HANDLE_T hUsb);
639
640 extern void mwUSB_DataOutStage(USBD_HANDLE_T hUsb);
641
642 extern void mwUSB_StatusInStage(USBD_HANDLE_T hUsb);
643
644 extern void mwUSB_StatusOutStage(USBD_HANDLE_T hUsb);
645
646 extern void mwUSB_StallEp0(USBD_HANDLE_T hUsb);
647
652 #endif /* __MW_USBD_CORE_H__ */
ErrorCode_t
ErrorCode_t
Definition: error.h:38
USB_PARAM_CB_T
ErrorCode_t(* USB_PARAM_CB_T)(USBD_HANDLE_T hUsb, uint32_t param1)
USB device stack&#39;s event callback function type.
Definition: mw_usbd_core.h:80
USB_CORE_DESCS_T::full_speed_desc
uint8_t * full_speed_desc
Definition: mw_usbd_core.h:122
USBD_API_INIT_PARAM_T::USB_Feature_Event
USB_CB_T USB_Feature_Event
Definition: mw_usbd_core.h:279
USBD_API_INIT_PARAM_T::lpm_setting
uint32_t lpm_setting
Definition: mw_usbd_core.h:286
USBD_API_INIT_PARAM_T::mem_size
uint32_t mem_size
Definition: mw_usbd_core.h:158
USBD_API_INIT_PARAM_T::USB_Reset_Event
USB_CB_T USB_Reset_Event
Definition: mw_usbd_core.h:178
USB_CORE_DESCS_T
USB descriptors data structure.
Definition: mw_usbd_core.h:119
USBD_API_INIT_PARAM_T::high_speed_capable
uint8_t high_speed_capable
Definition: mw_usbd_core.h:165
error.h
Error code returned by Boot ROM drivers/library functions.This file contains unified error codes to b...
USBD_API_INIT_PARAM_T::USB_WakeUpCfg
USB_PARAM_CB_T USB_WakeUpCfg
Definition: mw_usbd_core.h:232
USB_CORE_DESCS_T::string_desc
uint8_t * string_desc
Definition: mw_usbd_core.h:121
USB_EP_HANDLER_T
ErrorCode_t(* USB_EP_HANDLER_T)(USBD_HANDLE_T hUsb, void *data, uint32_t event)
USBD setup request and endpoint event handler type.
Definition: mw_usbd_core.h:105
USBD_API_INIT_PARAM_T::USB_Power_Event
USB_PARAM_CB_T USB_Power_Event
Definition: mw_usbd_core.h:235
USBD_API_INIT_PARAM_T::mem_base
uint32_t mem_base
Definition: mw_usbd_core.h:153
USB_CB_T
ErrorCode_t(* USB_CB_T)(USBD_HANDLE_T hUsb)
USB device stack&#39;s event callback function type.
Definition: mw_usbd_core.h:63
USBD_CORE_API_T
USBD stack Core API functions structure.
Definition: mw_usbd_core.h:320
USBD_API_INIT_PARAM_T::reserved_sbz
USB_CB_T reserved_sbz
Definition: mw_usbd_core.h:201
USBD_API_INIT_PARAM_T::USB_Resume_Event
USB_CB_T USB_Resume_Event
Definition: mw_usbd_core.h:198
USBD_API_INIT_PARAM_T::USB_Configure_Event
USB_CB_T USB_Configure_Event
Definition: mw_usbd_core.h:257
USBD_API_INIT_PARAM_T::USB_SOF_Event
USB_CB_T USB_SOF_Event
Definition: mw_usbd_core.h:215
mw_usbd.h
Common definitions and declarations for the USB stack.
USB_CORE_DESCS_T::bos_descriptor
uint8_t * bos_descriptor
Definition: mw_usbd_core.h:140
USB_CORE_DESCS_T::device_desc
uint8_t * device_desc
Definition: mw_usbd_core.h:120
USB_CORE_DESCS_T::device_qualifier
uint8_t * device_qualifier
Definition: mw_usbd_core.h:136
USBD_API_INIT_PARAM_T::max_num_ep
uint8_t max_num_ep
Definition: mw_usbd_core.h:161
USBD_API_INIT_PARAM_T::USB_Error_Event
USB_PARAM_CB_T USB_Error_Event
Definition: mw_usbd_core.h:245
USBD_API_INIT_PARAM_T::usb_reg_base
uint32_t usb_reg_base
Definition: mw_usbd_core.h:152
USBD_API_INIT_PARAM_T::USB_Interface_Event
USB_CB_T USB_Interface_Event
Definition: mw_usbd_core.h:268
USBD_API_INIT_PARAM_T::double_buffer
uint8_t double_buffer
Definition: mw_usbd_core.h:167
USB_CORE_DESCS_T::high_speed_desc
uint8_t * high_speed_desc
Definition: mw_usbd_core.h:128
USBD_HANDLE_T
void * USBD_HANDLE_T
Definition: mw_usbd.h:704
USBD_API_INIT_PARAM_T
USB device stack initialization parameter data structure.
Definition: mw_usbd_core.h:151
USBD_API_INIT_PARAM_T::USB_Suspend_Event
USB_CB_T USB_Suspend_Event
Definition: mw_usbd_core.h:187