usb_core.h
Go to the documentation of this file.
1 
28 /* Define to prevent recursive inclusion -------------------------------------*/
29 #ifndef __USB_CORE_H__
30 #define __USB_CORE_H__
31 
32 /* Includes ------------------------------------------------------------------*/
33 #include "usb_conf.h"
34 #include "usb_regs.h"
35 #include "usb_defines.h"
36 
37 
52 #define USB_OTG_EP0_IDLE 0
53 #define USB_OTG_EP0_SETUP 1
54 #define USB_OTG_EP0_DATA_IN 2
55 #define USB_OTG_EP0_DATA_OUT 3
56 #define USB_OTG_EP0_STATUS_IN 4
57 #define USB_OTG_EP0_STATUS_OUT 5
58 #define USB_OTG_EP0_STALL 6
59 
60 #define USB_OTG_EP_TX_DIS 0x0000
61 #define USB_OTG_EP_TX_STALL 0x0010
62 #define USB_OTG_EP_TX_NAK 0x0020
63 #define USB_OTG_EP_TX_VALID 0x0030
64 
65 #define USB_OTG_EP_RX_DIS 0x0000
66 #define USB_OTG_EP_RX_STALL 0x1000
67 #define USB_OTG_EP_RX_NAK 0x2000
68 #define USB_OTG_EP_RX_VALID 0x3000
69 
72 #define MAX_DATA_LENGTH 0x200
73 
79 typedef enum {
83 
84 typedef enum {
85  HC_IDLE = 0,
94 }HC_STATUS;
95 
96 typedef enum {
97  URB_IDLE = 0,
102 }URB_STATE;
103 
104 typedef enum {
114 }CTRL_STATUS;
115 
116 
117 typedef struct USB_OTG_hc
118 {
119  uint8_t dev_addr ;
120  uint8_t ep_num;
121  uint8_t ep_is_in;
122  uint8_t speed;
123  uint8_t do_ping;
124  uint8_t ep_type;
125  uint16_t max_packet;
126  uint8_t data_pid;
127  uint8_t *xfer_buff;
128  uint32_t xfer_len;
129  uint32_t xfer_count;
130  uint8_t toggle_in;
131  uint8_t toggle_out;
132  uint32_t dma_addr;
133 }
135 
136 typedef struct USB_OTG_ep
137 {
138  uint8_t num;
139  uint8_t is_in;
140  uint8_t is_stall;
141  uint8_t type;
142  uint8_t data_pid_start;
143  uint8_t even_odd_frame;
144  uint16_t tx_fifo_num;
145  uint32_t maxpacket;
146  /* transaction level variables*/
147  uint8_t *xfer_buff;
148  uint32_t dma_addr;
149  uint32_t xfer_len;
150  uint32_t xfer_count;
151  /* Transfer level variables*/
152  uint32_t rem_data_len;
153  uint32_t total_data_len;
154  uint32_t ctl_data_len;
155 
156 }
157 
159 
160 
161 
162 typedef struct USB_OTG_core_cfg
163 {
164  uint8_t host_channels;
165  uint8_t dev_endpoints;
166  uint8_t speed;
167  uint8_t dma_enable;
168  uint16_t mps;
169  uint16_t TotalFifoSize;
170  uint8_t phy_itface;
171  uint8_t Sof_output;
172  uint8_t low_power;
173  uint8_t coreID;
174 
175 }
177 
178 
179 
180 typedef struct usb_setup_req {
181 
182  uint8_t bmRequest;
183  uint8_t bRequest;
184  uint16_t wValue;
185  uint16_t wIndex;
186  uint16_t wLength;
187 } USB_SETUP_REQ;
188 
189 typedef struct _Device_TypeDef
190 {
191  uint8_t *(*GetDeviceDescriptor)( uint8_t speed , uint16_t *length);
192  uint8_t *(*GetLangIDStrDescriptor)( uint8_t speed , uint16_t *length);
193  uint8_t *(*GetManufacturerStrDescriptor)( uint8_t speed , uint16_t *length);
194  uint8_t *(*GetProductStrDescriptor)( uint8_t speed , uint16_t *length);
195  uint8_t *(*GetSerialStrDescriptor)( uint8_t speed , uint16_t *length);
196  uint8_t *(*GetConfigurationStrDescriptor)( uint8_t speed , uint16_t *length);
197  uint8_t *(*GetInterfaceStrDescriptor)( uint8_t speed , uint16_t *length);
198 
200 
201 typedef struct _Device_cb
202 {
203  uint8_t (*Init) (void *pdev , uint8_t cfgidx);
204  uint8_t (*DeInit) (void *pdev , uint8_t cfgidx);
205  /* Control Endpoints*/
206  uint8_t (*Setup) (void *pdev , USB_SETUP_REQ *req);
207  uint8_t (*EP0_TxSent) (void *pdev );
208  uint8_t (*EP0_RxReady) (void *pdev );
209  /* Class Specific Endpoints*/
210  uint8_t (*DataIn) (void *pdev , uint8_t epnum);
211  uint8_t (*DataOut) (void *pdev , uint8_t epnum);
212  uint8_t (*SOF) (void *pdev);
213  uint8_t (*IsoINIncomplete) (void *pdev);
214  uint8_t (*IsoOUTIncomplete) (void *pdev);
215 
216  uint8_t *(*GetConfigDescriptor)( uint8_t speed , uint16_t *length);
217 #ifdef USB_OTG_HS_CORE
218  uint8_t *(*GetOtherConfigDescriptor)( uint8_t speed , uint16_t *length);
219 #endif
220 
221 #ifdef USB_SUPPORT_USER_STRING_DESC
222  uint8_t *(*GetUsrStrDescriptor)( uint8_t speed ,uint8_t index, uint16_t *length);
223 #endif
224 
226 
227 
228 
229 typedef struct _USBD_USR_PROP
230 {
231  void (*Init)(void);
232  void (*DeviceReset)(uint8_t speed);
233  void (*DeviceConfigured)(void);
234  void (*DeviceSuspended)(void);
235  void (*DeviceResumed)(void);
236 
237  void (*DeviceConnected)(void);
238  void (*DeviceDisconnected)(void);
239 
240 }
242 
243 typedef struct _DCD
244 {
245  uint8_t device_config;
246  uint8_t device_state;
247  uint8_t device_status;
249  uint8_t device_address;
251  uint8_t test_mode;
252  uint32_t DevRemoteWakeup;
255  uint8_t setup_packet [8*3];
260  }
261 DCD_DEV , *DCD_PDEV;
262 
263 
264 typedef struct _HCD
265 {
266  uint8_t Rx_Buffer [MAX_DATA_LENGTH];
267  __IO uint32_t ConnSts;
268  __IO uint32_t PortEnabled;
269  __IO uint32_t ErrCnt[USB_OTG_MAX_TX_FIFOS];
270  __IO uint32_t XferCnt[USB_OTG_MAX_TX_FIFOS];
274  uint16_t channel [USB_OTG_MAX_TX_FIFOS];
275 }
277 
278 
279 typedef struct _OTG
280 {
281  uint8_t OTG_State;
282  uint8_t OTG_PrevState;
283  uint8_t OTG_Mode;
284 }
286 
287 typedef struct USB_OTG_handle
288 {
291 #ifdef USE_DEVICE_MODE
292  DCD_DEV dev;
293 #endif
294 #ifdef USE_HOST_MODE
295  HCD_DEV host;
296 #endif
297 #ifdef USE_OTG_MODE
298  OTG_DEV otg;
299 #endif
300 }
302 
330  USB_OTG_CORE_ID_TypeDef coreID);
334  uint8_t *dest,
335  uint16_t len);
337  uint8_t *src,
338  uint8_t ch_ep_num,
339  uint16_t len);
342 
344 uint32_t USB_OTG_ReadOtgItr (USB_OTG_CORE_HANDLE *pdev);
347 uint32_t USB_OTG_GetMode (USB_OTG_CORE_HANDLE *pdev);
350  uint8_t mode);
351 
352 /*********************** HOST APIs ********************************************/
353 #ifdef USE_HOST_MODE
354 USB_OTG_STS USB_OTG_CoreInitHost (USB_OTG_CORE_HANDLE *pdev);
355 USB_OTG_STS USB_OTG_EnableHostInt (USB_OTG_CORE_HANDLE *pdev);
356 USB_OTG_STS USB_OTG_HC_Init (USB_OTG_CORE_HANDLE *pdev, uint8_t hc_num);
357 USB_OTG_STS USB_OTG_HC_Halt (USB_OTG_CORE_HANDLE *pdev, uint8_t hc_num);
358 USB_OTG_STS USB_OTG_HC_StartXfer (USB_OTG_CORE_HANDLE *pdev, uint8_t hc_num);
359 USB_OTG_STS USB_OTG_HC_DoPing (USB_OTG_CORE_HANDLE *pdev , uint8_t hc_num);
360 uint32_t USB_OTG_ReadHostAllChannels_intr (USB_OTG_CORE_HANDLE *pdev);
361 uint32_t USB_OTG_ResetPort (USB_OTG_CORE_HANDLE *pdev);
362 uint32_t USB_OTG_ReadHPRT0 (USB_OTG_CORE_HANDLE *pdev);
363 void USB_OTG_DriveVbus (USB_OTG_CORE_HANDLE *pdev, uint8_t state);
364 void USB_OTG_InitFSLSPClkSel (USB_OTG_CORE_HANDLE *pdev ,uint8_t freq);
365 uint8_t USB_OTG_IsEvenFrame (USB_OTG_CORE_HANDLE *pdev) ;
366 void USB_OTG_StopHost (USB_OTG_CORE_HANDLE *pdev);
367 #endif
368 /********************* DEVICE APIs ********************************************/
369 #ifdef USE_DEVICE_MODE
370 USB_OTG_STS USB_OTG_CoreInitDev (USB_OTG_CORE_HANDLE *pdev);
371 USB_OTG_STS USB_OTG_EnableDevInt (USB_OTG_CORE_HANDLE *pdev);
372 uint32_t USB_OTG_ReadDevAllInEPItr (USB_OTG_CORE_HANDLE *pdev);
373 enum USB_OTG_SPEED USB_OTG_GetDeviceSpeed (USB_OTG_CORE_HANDLE *pdev);
374 USB_OTG_STS USB_OTG_EP0Activate (USB_OTG_CORE_HANDLE *pdev);
375 USB_OTG_STS USB_OTG_EPActivate (USB_OTG_CORE_HANDLE *pdev , USB_OTG_EP *ep);
376 USB_OTG_STS USB_OTG_EPDeactivate(USB_OTG_CORE_HANDLE *pdev , USB_OTG_EP *ep);
377 USB_OTG_STS USB_OTG_EPStartXfer (USB_OTG_CORE_HANDLE *pdev , USB_OTG_EP *ep);
378 USB_OTG_STS USB_OTG_EP0StartXfer(USB_OTG_CORE_HANDLE *pdev , USB_OTG_EP *ep);
379 USB_OTG_STS USB_OTG_EPSetStall (USB_OTG_CORE_HANDLE *pdev , USB_OTG_EP *ep);
380 USB_OTG_STS USB_OTG_EPClearStall (USB_OTG_CORE_HANDLE *pdev , USB_OTG_EP *ep);
381 uint32_t USB_OTG_ReadDevAllOutEp_itr (USB_OTG_CORE_HANDLE *pdev);
382 uint32_t USB_OTG_ReadDevOutEP_itr (USB_OTG_CORE_HANDLE *pdev , uint8_t epnum);
383 void USB_OTG_InitDevSpeed (USB_OTG_CORE_HANDLE *pdev , uint8_t speed);
384 uint8_t USBH_IsEvenFrame (USB_OTG_CORE_HANDLE *pdev);
385 void USB_OTG_EP0_OutStart(USB_OTG_CORE_HANDLE *pdev);
386 void USB_OTG_ActiveRemoteWakeup(USB_OTG_CORE_HANDLE *pdev);
387 void USB_OTG_UngateClock(USB_OTG_CORE_HANDLE *pdev);
388 void USB_OTG_StopDevice(USB_OTG_CORE_HANDLE *pdev);
389 void USB_OTG_SetEPStatus (USB_OTG_CORE_HANDLE *pdev , USB_OTG_EP *ep , uint32_t Status);
390 uint32_t USB_OTG_GetEPStatus(USB_OTG_CORE_HANDLE *pdev ,USB_OTG_EP *ep);
391 #endif
392 
396 #endif /* __USB_CORE_H__ */
397 
398 
406 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
407 
struct _Device_TypeDef * pUSBD_DEVICE
uint8_t * pConfig_descriptor
Definition: usb_core.h:259
struct USB_OTG_hc USB_OTG_HC
USB_OTG_STS USB_OTG_PhyInit(USB_OTG_CORE_HANDLE *pdev)
uint8_t do_ping
Definition: usb_core.h:123
struct _OTG OTG_DEV
static uint8_t DeInit(uint32_t options)
DeInit Free all resources used by low layer and stops audio-play function.
struct USB_OTG_ep USB_OTG_EP
USB_OTG_STS USB_OTG_SetCurrentMode(USB_OTG_CORE_HANDLE *pdev, uint8_t mode)
USB_OTG_SetCurrentMode : Set ID line.
Definition: usb_core.c:541
__IO uint32_t PortEnabled
Definition: usb_core.h:268
uint8_t phy_itface
Definition: usb_core.h:170
uint8_t data_pid
Definition: usb_core.h:126
static uint8_t Init(uint32_t AudioFreq, uint32_t Volume, uint32_t options)
Init Initialize and configures all required resources for audio play function.
uint8_t num
Definition: usb_core.h:138
USB_OTG_SPEED
Definition: usb_defines.h:233
uint32_t ctl_data_len
Definition: usb_core.h:154
uint32_t DevRemoteWakeup
Definition: usb_core.h:252
#define USB_OTG_MAX_TX_FIFOS
Definition: usb_regs.h:67
uint16_t TotalFifoSize
Definition: usb_core.h:169
USB_OTG_STS USB_OTG_DisableGlobalInt(USB_OTG_CORE_HANDLE *pdev)
USB_OTG_DisableGlobalInt Enables the controller's Global Int in the AHB Config reg.
Definition: usb_core.c:464
USBD_DEVICE * usr_device
Definition: usb_core.h:258
struct USB_OTG_hc * PUSB_OTG_HC
uint32_t xfer_count
Definition: usb_core.h:129
uint8_t speed
Definition: usb_core.h:122
uint32_t dma_addr
Definition: usb_core.h:148
struct _HCD * USB_OTG_USBH_PDEV
USB_OTG_CORE_ID_TypeDef
Definition: usb_defines.h:190
struct _DCD DCD_DEV
Definition: usb_core.h:243
Definition: usb_core.h:264
uint8_t ep_type
Definition: usb_core.h:124
uint32_t dma_addr
Definition: usb_core.h:132
USB_OTG_STS USB_OTG_FlushRxFifo(USB_OTG_CORE_HANDLE *pdev)
USB_OTG_FlushRxFifo : Flush a Rx FIFO.
Definition: usb_core.c:511
uint8_t device_state
Definition: usb_core.h:246
USB_OTG_STS
Definition: usb_core.h:79
uint8_t dev_endpoints
Definition: usb_core.h:165
uint8_t OTG_PrevState
Definition: usb_core.h:282
uint8_t test_mode
Definition: usb_core.h:251
USB_OTG_CORE_CFGS cfg
Definition: usb_core.h:289
uint16_t mps
Definition: usb_core.h:168
uint8_t speed
Definition: usb_core.h:166
struct _HCD HCD_DEV
uint16_t max_packet
Definition: usb_core.h:125
hardware registers
uint8_t even_odd_frame
Definition: usb_core.h:143
uint8_t data_pid_start
Definition: usb_core.h:142
uint8_t OTG_State
Definition: usb_core.h:281
uint8_t host_channels
Definition: usb_core.h:164
#define __IO
Definition: core_cm0.h:198
uint16_t wIndex
Definition: usb_core.h:185
uint8_t device_config
Definition: usb_core.h:245
uint8_t * xfer_buff
Definition: usb_core.h:147
uint32_t xfer_len
Definition: usb_core.h:149
uint8_t type
Definition: usb_core.h:141
uint8_t device_old_status
Definition: usb_core.h:248
USB_OTG_STS USB_OTG_FlushTxFifo(USB_OTG_CORE_HANDLE *pdev, uint32_t num)
USB_OTG_FlushTxFifo : Flush a Tx FIFO.
Definition: usb_core.c:481
USB_OTG_STS USB_OTG_SelectCore(USB_OTG_CORE_HANDLE *pdev, USB_OTG_CORE_ID_TypeDef coreID)
USB_OTG_SelectCore Initialize core registers address.
Definition: usb_core.c:222
struct USB_OTG_core_cfg * PUSB_OTG_CORE_CFGS
uint8_t bmRequest
Definition: usb_core.h:182
uint8_t toggle_in
Definition: usb_core.h:130
void * USB_OTG_ReadPacket(USB_OTG_CORE_HANDLE *pdev, uint8_t *dest, uint16_t len)
USB_OTG_ReadPacket : Reads a packet from the Rx FIFO.
Definition: usb_core.c:198
uint8_t Sof_output
Definition: usb_core.h:171
uint32_t USB_OTG_GetMode(USB_OTG_CORE_HANDLE *pdev)
USB_OTG_GetMode : Get current mode.
Definition: usb_core.c:576
static uint8_t EP0_TxSent(void *pdev)
EP0_TxSent Handles the DFU control endpoint data IN stage.
uint8_t toggle_out
Definition: usb_core.h:131
uint8_t connection_status
Definition: usb_core.h:250
uint8_t dma_enable
Definition: usb_core.h:167
uint32_t USB_OTG_ReadOtgItr(USB_OTG_CORE_HANDLE *pdev)
USB_OTG_ReadOtgItr : returns the USB_OTG Interrupt register.
Definition: usb_core.c:623
USBD_Usr_cb_TypeDef * usr_cb
Definition: usb_core.h:257
uint32_t maxpacket
Definition: usb_core.h:145
struct _USBD_USR_PROP USBD_Usr_cb_TypeDef
uint16_t tx_fifo_num
Definition: usb_core.h:144
uint32_t rem_data_len
Definition: usb_core.h:152
uint32_t USB_OTG_ReadCoreItr(USB_OTG_CORE_HANDLE *pdev)
USB_OTG_ReadCoreItr : returns the Core Interrupt register.
Definition: usb_core.c:609
URB_STATE
Definition: usb_core.h:96
struct USB_OTG_handle USB_OTG_CORE_HANDLE
struct _Device_TypeDef USBD_DEVICE
USB_OTG_STS USB_OTG_EnableGlobalInt(USB_OTG_CORE_HANDLE *pdev)
USB_OTG_EnableGlobalInt Enables the controller's Global Int in the AHB Config reg.
Definition: usb_core.c:446
Header of the Core Layer.
struct USB_OTG_core_cfg USB_OTG_CORE_CFGS
uint16_t wLength
Definition: usb_core.h:186
Definition: usb_core.h:279
uint8_t bRequest
Definition: usb_core.h:183
struct _DCD * DCD_PDEV
uint8_t dev_addr
Definition: usb_core.h:119
uint8_t coreID
Definition: usb_core.h:173
uint8_t device_status
Definition: usb_core.h:247
uint32_t total_data_len
Definition: usb_core.h:153
uint8_t ep_is_in
Definition: usb_core.h:121
uint8_t device_address
Definition: usb_core.h:249
General low level driver configuration.
struct _Device_cb USBD_Class_cb_TypeDef
uint8_t * xfer_buff
Definition: usb_core.h:127
#define MAX_DATA_LENGTH
Definition: usb_core.h:72
static uint8_t EP0_RxReady(void *pdev)
EP0_RxReady Handles the DFU control endpoint data OUT stage.
CTRL_STATUS
Definition: usb_core.h:104
USBD_Class_cb_TypeDef * class_cb
Definition: usb_core.h:256
HC_STATUS
Definition: usb_core.h:84
uint8_t is_stall
Definition: usb_core.h:140
uint8_t USB_OTG_IsDeviceMode(USB_OTG_CORE_HANDLE *pdev)
USB_OTG_IsDeviceMode : Check if it is device mode.
Definition: usb_core.c:587
__IO uint32_t ConnSts
Definition: usb_core.h:267
uint8_t low_power
Definition: usb_core.h:172
uint8_t USB_OTG_IsHostMode(USB_OTG_CORE_HANDLE *pdev)
USB_OTG_IsHostMode : Check if it is host mode.
Definition: usb_core.c:598
uint8_t is_in
Definition: usb_core.h:139
struct USB_OTG_ep * PUSB_OTG_EP
USB_OTG_CORE_REGS regs
Definition: usb_core.h:290
struct usb_setup_req USB_SETUP_REQ
struct USB_OTG_handle * PUSB_OTG_CORE_HANDLE
struct _OTG * USB_OTG_USBO_PDEV
uint32_t xfer_len
Definition: usb_core.h:128
uint16_t wValue
Definition: usb_core.h:184
USB_OTG_STS USB_OTG_CoreInit(USB_OTG_CORE_HANDLE *pdev)
USB_OTG_CoreInit Initializes the USB_OTG controller registers and prepares the core device mode or ho...
Definition: usb_core.c:329
uint32_t xfer_count
Definition: usb_core.h:150
uint8_t ep_num
Definition: usb_core.h:120
USB_OTG_STS USB_OTG_WritePacket(USB_OTG_CORE_HANDLE *pdev, uint8_t *src, uint8_t ch_ep_num, uint16_t len)
USB_OTG_WritePacket : Writes a packet into the Tx FIFO associated with the EP.
Definition: usb_core.c:168
uint8_t OTG_Mode
Definition: usb_core.h:283


rosflight_firmware
Author(s): Daniel Koch , James Jackson
autogenerated on Thu Oct 24 2019 03:17:20