USB Device ROM Stack API example program

Dependencies:   mbed

LPC1549のROM APIを使ったRAMディスクです。PCからはUSBメモリとして見えます。

参考:
http://docs.lpcware.com/usbromlib/v1.0/

Committer:
va009039
Date:
Fri Mar 14 09:14:16 2014 +0000
Revision:
0:ef2c0c52abc4
first commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
va009039 0:ef2c0c52abc4 1 #ifndef _USB_H_
va009039 0:ef2c0c52abc4 2 #define _USB_H_
va009039 0:ef2c0c52abc4 3
va009039 0:ef2c0c52abc4 4 typedef enum {
va009039 0:ef2c0c52abc4 5 LPC_OK=0,
va009039 0:ef2c0c52abc4 6 } ErrorCode_t;
va009039 0:ef2c0c52abc4 7
va009039 0:ef2c0c52abc4 8 typedef uint32_t USBD_HANDLE_T;
va009039 0:ef2c0c52abc4 9 typedef void* USB_CB_T;
va009039 0:ef2c0c52abc4 10 typedef void* USB_PARAM_CB_T;
va009039 0:ef2c0c52abc4 11
va009039 0:ef2c0c52abc4 12 typedef struct _USB_CORE_DESCS_T {
va009039 0:ef2c0c52abc4 13 const uint8_t *device_desc;
va009039 0:ef2c0c52abc4 14 const uint8_t *string_desc;
va009039 0:ef2c0c52abc4 15 const uint8_t *full_speed_desc;
va009039 0:ef2c0c52abc4 16 const uint8_t *high_speed_desc;
va009039 0:ef2c0c52abc4 17 const uint8_t *device_qualifier;
va009039 0:ef2c0c52abc4 18 } USB_CORE_DESCS_T;
va009039 0:ef2c0c52abc4 19
va009039 0:ef2c0c52abc4 20 typedef struct USBD_API_INIT_PARAM {
va009039 0:ef2c0c52abc4 21 uint32_t usb_reg_base;
va009039 0:ef2c0c52abc4 22 uint8_t* mem_base;
va009039 0:ef2c0c52abc4 23 uint32_t mem_size;
va009039 0:ef2c0c52abc4 24 uint8_t max_num_ep;
va009039 0:ef2c0c52abc4 25 uint8_t pad0[3];
va009039 0:ef2c0c52abc4 26 USB_CB_T USB_Reset_Event;
va009039 0:ef2c0c52abc4 27 USB_CB_T USB_Suspend_Event;
va009039 0:ef2c0c52abc4 28 USB_CB_T USB_Resume_Event;
va009039 0:ef2c0c52abc4 29 USB_CB_T reserved_sbz;
va009039 0:ef2c0c52abc4 30 USB_CB_T USB_SOF_Event;
va009039 0:ef2c0c52abc4 31 USB_PARAM_CB_T USB_WakeUpCfg;
va009039 0:ef2c0c52abc4 32 USB_PARAM_CB_T USB_Power_Event;
va009039 0:ef2c0c52abc4 33 USB_PARAM_CB_T USB_Error_Event;
va009039 0:ef2c0c52abc4 34 USB_CB_T USB_Configure_Event;
va009039 0:ef2c0c52abc4 35 USB_CB_T USB_Interface_Event;
va009039 0:ef2c0c52abc4 36 USB_CB_T USB_Feature_Event;
va009039 0:ef2c0c52abc4 37 uint32_t (* virt_to_phys)(void* vaddr);
va009039 0:ef2c0c52abc4 38 void (* cache_flush)(uint32_t* start_adr, uint32_t* end_adr);
va009039 0:ef2c0c52abc4 39 } USBD_API_INIT_PARAM_T;
va009039 0:ef2c0c52abc4 40
va009039 0:ef2c0c52abc4 41 typedef struct USBD_HW_API {
va009039 0:ef2c0c52abc4 42 uint32_t (*GetMemSize)(USBD_API_INIT_PARAM_T* param);
va009039 0:ef2c0c52abc4 43 ErrorCode_t (*Init)(USBD_HANDLE_T* phUsb, USB_CORE_DESCS_T* pDesc, USBD_API_INIT_PARAM_T* param);
va009039 0:ef2c0c52abc4 44 void (*Connect)(USBD_HANDLE_T hUsb, uint32_t con);
va009039 0:ef2c0c52abc4 45 void (*ISR)(USBD_HANDLE_T hUsb);
va009039 0:ef2c0c52abc4 46 } USBD_HW_API_T;
va009039 0:ef2c0c52abc4 47
va009039 0:ef2c0c52abc4 48 typedef struct USBD_CORE_API {
va009039 0:ef2c0c52abc4 49 void* dummy;
va009039 0:ef2c0c52abc4 50 //TODO
va009039 0:ef2c0c52abc4 51 } USBD_CORE_API_T;
va009039 0:ef2c0c52abc4 52
va009039 0:ef2c0c52abc4 53 typedef struct USBD_MSC_INIT_PARAM {
va009039 0:ef2c0c52abc4 54 uint8_t* mem_base;
va009039 0:ef2c0c52abc4 55 uint32_t mem_size;
va009039 0:ef2c0c52abc4 56 const uint8_t* InquiryStr;
va009039 0:ef2c0c52abc4 57 uint32_t BlockCount;
va009039 0:ef2c0c52abc4 58 uint32_t BlockSize;
va009039 0:ef2c0c52abc4 59 uint32_t MemorySize;
va009039 0:ef2c0c52abc4 60 const uint8_t* intf_desc;
va009039 0:ef2c0c52abc4 61 void (*MSC_Write)(uint32_t offset, uint8_t** src, uint32_t length, uint32_t high_offset);
va009039 0:ef2c0c52abc4 62 void (*MSC_Read)(uint32_t offset, uint8_t** dst, uint32_t length, uint32_t high_offset);
va009039 0:ef2c0c52abc4 63 ErrorCode_t (*MSC_Verify)(uint32_t offset, uint8_t buf[], uint32_t length, uint32_t high_offset);
va009039 0:ef2c0c52abc4 64 void (*MSC_GetWriteBuf)(uint32_t offset, uint8_t** buff_adr, uint32_t length, uint32_t high_offset);
va009039 0:ef2c0c52abc4 65 ErrorCode_t (*MSC_Ep0_Hdlr)(USBD_HANDLE_T hUsb, void* data, uint32_t event);
va009039 0:ef2c0c52abc4 66 uint64_t MemorySize64;
va009039 0:ef2c0c52abc4 67 } USBD_MSC_INIT_PARAM_T;
va009039 0:ef2c0c52abc4 68
va009039 0:ef2c0c52abc4 69 typedef struct USBD_MSC_API {
va009039 0:ef2c0c52abc4 70 uint32_t (*GetMemSize)(USBD_MSC_INIT_PARAM_T* param);
va009039 0:ef2c0c52abc4 71 ErrorCode_t (*init)(USBD_HANDLE_T hUsb, USBD_MSC_INIT_PARAM_T* param);
va009039 0:ef2c0c52abc4 72 } USBD_MSC_API_T;
va009039 0:ef2c0c52abc4 73
va009039 0:ef2c0c52abc4 74 typedef struct USBD_HID_API {
va009039 0:ef2c0c52abc4 75 void* dummy;
va009039 0:ef2c0c52abc4 76 // TODO
va009039 0:ef2c0c52abc4 77 } USBD_HID_API_T;
va009039 0:ef2c0c52abc4 78 typedef struct USBD_CDC_API {
va009039 0:ef2c0c52abc4 79 void* dummy;
va009039 0:ef2c0c52abc4 80 // TODO
va009039 0:ef2c0c52abc4 81 } USBD_CDC_API_T;
va009039 0:ef2c0c52abc4 82
va009039 0:ef2c0c52abc4 83 typedef struct USBD_API {
va009039 0:ef2c0c52abc4 84 const USBD_HW_API_T* hw;
va009039 0:ef2c0c52abc4 85 const USBD_CORE_API_T* core;
va009039 0:ef2c0c52abc4 86 const USBD_MSC_API_T* msc;
va009039 0:ef2c0c52abc4 87 const void* dfu;
va009039 0:ef2c0c52abc4 88 const USBD_HID_API_T* hid;
va009039 0:ef2c0c52abc4 89 const USBD_CDC_API_T* cdc;
va009039 0:ef2c0c52abc4 90 const uint32_t* reserved6;
va009039 0:ef2c0c52abc4 91 uint32_t version;
va009039 0:ef2c0c52abc4 92 } USBD_API_T;
va009039 0:ef2c0c52abc4 93
va009039 0:ef2c0c52abc4 94 typedef struct _ROM {
va009039 0:ef2c0c52abc4 95 const USBD_API_T * pUSBD;
va009039 0:ef2c0c52abc4 96 } ROM;
va009039 0:ef2c0c52abc4 97
va009039 0:ef2c0c52abc4 98 extern USBD_API_T* pUsbApi;
va009039 0:ef2c0c52abc4 99 extern USBD_HANDLE_T hUsb;
va009039 0:ef2c0c52abc4 100
va009039 0:ef2c0c52abc4 101 extern uint32_t USBD_MSC_MemorySize;
va009039 0:ef2c0c52abc4 102 extern uint32_t USBD_MSC_BlockSize;
va009039 0:ef2c0c52abc4 103 extern uint32_t USBD_MSC_BlockGroup;
va009039 0:ef2c0c52abc4 104 extern uint32_t USBD_MSC_BlockCount;
va009039 0:ef2c0c52abc4 105 extern uint8_t* USBD_MSC_BlockBuf;
va009039 0:ef2c0c52abc4 106 extern uint8_t USBD_MSC_MediaReady;
va009039 0:ef2c0c52abc4 107
va009039 0:ef2c0c52abc4 108 #endif // _USB_H_