Zephyr API Documentation 4.3.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
uhc.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
11
12#ifndef ZEPHYR_INCLUDE_UHC_H
13#define ZEPHYR_INCLUDE_UHC_H
14
15#include <zephyr/kernel.h>
16#include <zephyr/device.h>
17#include <zephyr/net_buf.h>
19#include <zephyr/usb/usb_ch9.h>
20#include <zephyr/sys/dlist.h>
21
30
38
54
55#define UHC_INTERFACES_MAX 32
56
65
69};
70
100
109
155
184
193struct uhc_event {
198 union {
203 };
205 const struct device *dev;
206};
207
219typedef int (*uhc_event_cb_t)(const struct device *dev,
220 const struct uhc_event *const event);
221
230};
231
235#define UHC_STATUS_INITIALIZED 0
239#define UHC_STATUS_ENABLED 1
240
265
273static inline bool uhc_is_initialized(const struct device *dev)
274{
275 struct uhc_data *data = dev->data;
276
278}
279
287static inline bool uhc_is_enabled(const struct device *dev)
288{
289 struct uhc_data *data = dev->data;
290
292}
293
297struct uhc_api {
298 int (*lock)(const struct device *dev);
299 int (*unlock)(const struct device *dev);
300
301 int (*init)(const struct device *dev);
302 int (*enable)(const struct device *dev);
303 int (*disable)(const struct device *dev);
304 int (*shutdown)(const struct device *dev);
305
306 int (*bus_reset)(const struct device *dev);
307 int (*sof_enable)(const struct device *dev);
308 int (*bus_suspend)(const struct device *dev);
309 int (*bus_resume)(const struct device *dev);
310
311 int (*ep_enqueue)(const struct device *dev,
312 struct uhc_transfer *const xfer);
313 int (*ep_dequeue)(const struct device *dev,
314 struct uhc_transfer *const xfer);
315};
319
331static inline int uhc_bus_reset(const struct device *dev)
332{
333 const struct uhc_api *api = dev->api;
334 int ret;
335
336 api->lock(dev);
337 ret = api->bus_reset(dev);
338 api->unlock(dev);
339
340 return ret;
341}
342
353static inline int uhc_sof_enable(const struct device *dev)
354{
355 const struct uhc_api *api = dev->api;
356 int ret;
357
358 api->lock(dev);
359 ret = api->sof_enable(dev);
360 api->unlock(dev);
361
362 return ret;
363}
364
376static inline int uhc_bus_suspend(const struct device *dev)
377{
378 const struct uhc_api *api = dev->api;
379 int ret;
380
381 api->lock(dev);
382 ret = api->bus_suspend(dev);
383 api->unlock(dev);
384
385 return ret;
386}
387
399static inline int uhc_bus_resume(const struct device *dev)
400{
401 const struct uhc_api *api = dev->api;
402 int ret;
403
404 api->lock(dev);
405 ret = api->bus_resume(dev);
406 api->unlock(dev);
407
408 return ret;
409}
410
426struct uhc_transfer *uhc_xfer_alloc(const struct device *dev,
427 const uint8_t ep,
428 struct usb_device *const udev,
429 void *const cb,
430 void *const cb_priv);
431
447 const uint8_t ep,
448 struct usb_device *const udev,
449 void *const cb,
450 void *const cb_priv,
451 size_t size);
452
463int uhc_xfer_free(const struct device *dev,
464 struct uhc_transfer *const xfer);
465
477int uhc_xfer_buf_add(const struct device *dev,
478 struct uhc_transfer *const xfer,
479 struct net_buf *buf);
491struct net_buf *uhc_xfer_buf_alloc(const struct device *dev,
492 const size_t size);
493
502void uhc_xfer_buf_free(const struct device *dev, struct net_buf *const buf);
503
516int uhc_ep_enqueue(const struct device *dev, struct uhc_transfer *const xfer);
517
529int uhc_ep_dequeue(const struct device *dev, struct uhc_transfer *const xfer);
530
544int uhc_init(const struct device *dev,
545 uhc_event_cb_t event_cb, const void *const event_ctx);
546
559int uhc_enable(const struct device *dev);
560
571int uhc_disable(const struct device *dev);
572
584int uhc_shutdown(const struct device *dev);
585
596static inline struct uhc_device_caps uhc_caps(const struct device *dev)
597{
598 struct uhc_data *data = dev->data;
599
600 return data->caps;
601}
602
613static inline const void *uhc_get_event_ctx(const struct device *dev)
614{
615 struct uhc_data *data = dev->data;
616
617 return data->event_ctx;
618}
619
623
624#endif /* ZEPHYR_INCLUDE_UHC_H */
long atomic_t
Definition atomic_types.h:15
static _Bool atomic_test_bit(const atomic_t *target, int bit)
Atomically get and test a bit.
Definition atomic.h:129
struct _dnode sys_dnode_t
Doubly-linked list node structure.
Definition dlist.h:54
struct _dnode sys_dlist_t
Doubly-linked list structure.
Definition dlist.h:50
struct _snode sys_snode_t
Single-linked list node structure.
Definition slist.h:39
#define UHC_STATUS_INITIALIZED
Controller is initialized by uhc_init().
Definition uhc.h:235
static bool uhc_is_enabled(const struct device *dev)
Checks whether the controller is enabled.
Definition uhc.h:287
#define UHC_INTERFACES_MAX
Definition uhc.h:55
#define UHC_STATUS_ENABLED
Controller is enabled and all API functions are available.
Definition uhc.h:239
static bool uhc_is_initialized(const struct device *dev)
Checks whether the controller is initialized.
Definition uhc.h:273
int(* uhc_event_cb_t)(const struct device *dev, const struct uhc_event *const event)
Callback to submit UHC event to higher layer.
Definition uhc.h:219
static const void * uhc_get_event_ctx(const struct device *dev)
Get pointer to higher layer context.
Definition uhc.h:613
static int uhc_bus_reset(const struct device *dev)
Reset USB bus.
Definition uhc.h:331
usb_device_speed
USB device operating speed.
Definition uhc.h:42
static int uhc_bus_resume(const struct device *dev)
Resume USB bus.
Definition uhc.h:399
usb_device_state
USB device state.
Definition uhc.h:32
struct uhc_transfer * uhc_xfer_alloc_with_buf(const struct device *dev, const uint8_t ep, struct usb_device *const udev, void *const cb, void *const cb_priv, size_t size)
Allocate UHC transfer with buffer.
int uhc_xfer_buf_add(const struct device *dev, struct uhc_transfer *const xfer, struct net_buf *buf)
Add UHC transfer buffer.
int uhc_ep_enqueue(const struct device *dev, struct uhc_transfer *const xfer)
Queue USB host controller transfer.
int uhc_ep_dequeue(const struct device *dev, struct uhc_transfer *const xfer)
Remove a USB host controller transfers from queue.
static struct uhc_device_caps uhc_caps(const struct device *dev)
Get USB host controller capabilities.
Definition uhc.h:596
static int uhc_bus_suspend(const struct device *dev)
Suspend USB bus.
Definition uhc.h:376
int uhc_init(const struct device *dev, uhc_event_cb_t event_cb, const void *const event_ctx)
Initialize USB host controller.
int uhc_disable(const struct device *dev)
Disable USB host controller.
int uhc_xfer_free(const struct device *dev, struct uhc_transfer *const xfer)
Free UHC transfer and any buffers.
struct net_buf * uhc_xfer_buf_alloc(const struct device *dev, const size_t size)
Allocate UHC transfer buffer.
struct uhc_transfer * uhc_xfer_alloc(const struct device *dev, const uint8_t ep, struct usb_device *const udev, void *const cb, void *const cb_priv)
Allocate UHC transfer.
uhc_event_type
USB host controller event types.
Definition uhc.h:159
void uhc_xfer_buf_free(const struct device *dev, struct net_buf *const buf)
Free UHC request buffer.
int uhc_shutdown(const struct device *dev)
Poweroff USB host controller.
uhc_control_stage
USB control transfer stage.
Definition uhc.h:104
static int uhc_sof_enable(const struct device *dev)
Enable Start of Frame generator.
Definition uhc.h:353
int uhc_enable(const struct device *dev)
Enable USB host controller.
@ USB_SPEED_SPEED_SS
Super speed.
Definition uhc.h:52
@ USB_SPEED_SPEED_LS
Low speed.
Definition uhc.h:46
@ USB_SPEED_SPEED_FS
Full speed.
Definition uhc.h:48
@ USB_SPEED_SPEED_HS
High speed.
Definition uhc.h:50
@ USB_SPEED_UNKNOWN
Device is probably not connected.
Definition uhc.h:44
@ USB_STATE_CONFIGURED
Definition uhc.h:36
@ USB_STATE_NOTCONNECTED
Definition uhc.h:33
@ USB_STATE_DEFAULT
Definition uhc.h:34
@ USB_STATE_ADDRESSED
Definition uhc.h:35
@ UHC_EVT_EP_REQUEST
Endpoint request result event.
Definition uhc.h:177
@ UHC_EVT_DEV_CONNECTED_HS
High speed device connected.
Definition uhc.h:165
@ UHC_EVT_DEV_CONNECTED_FS
Full speed device connected.
Definition uhc.h:163
@ UHC_EVT_RWUP
Remote wakeup signal.
Definition uhc.h:175
@ UHC_EVT_SUSPENDED
Bus suspend operation finished.
Definition uhc.h:171
@ UHC_EVT_DEV_REMOVED
Device (peripheral) removed.
Definition uhc.h:167
@ UHC_EVT_RESUMED
Bus resume operation finished.
Definition uhc.h:173
@ UHC_EVT_DEV_CONNECTED_LS
Low speed device connected.
Definition uhc.h:161
@ UHC_EVT_ERROR
Non-correctable error event, requires attention from higher levels or application.
Definition uhc.h:182
@ UHC_EVT_RESETED
Bus reset operation finished.
Definition uhc.h:169
@ UHC_CONTROL_STAGE_DATA
Definition uhc.h:106
@ UHC_CONTROL_STAGE_SETUP
Definition uhc.h:105
@ UHC_CONTROL_STAGE_STATUS
Definition uhc.h:107
Public kernel APIs.
Buffer management.
int shutdown(int sock, int how)
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
Runtime device structure (in ROM) per driver instance.
Definition device.h:513
void * data
Address of the device instance private data.
Definition device.h:523
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:519
Mutex Structure.
Definition kernel.h:3402
Network buffer representation.
Definition net_buf.h:1006
uint16_t size
Amount of data that this buffer can store.
Definition net_buf.h:1038
Common UHC driver data structure.
Definition uhc.h:247
struct k_mutex mutex
Driver access mutex.
Definition uhc.h:251
atomic_t status
USB host controller status.
Definition uhc.h:261
void * priv
Driver private data.
Definition uhc.h:263
sys_dlist_t ctrl_xfers
dlist for control transfers
Definition uhc.h:253
const void * event_ctx
Opaque pointer to store higher layer context.
Definition uhc.h:259
struct uhc_device_caps caps
Controller capabilities.
Definition uhc.h:249
sys_dlist_t bulk_xfers
dlist for bulk transfers
Definition uhc.h:255
uhc_event_cb_t event_cb
Callback to submit an UHC event to upper layer.
Definition uhc.h:257
USB host controller capabilities.
Definition uhc.h:227
uint32_t hs
USB high speed capable controller.
Definition uhc.h:229
USB host controller event.
Definition uhc.h:193
struct uhc_transfer * xfer
Pointer to request used only for UHC_EVT_EP_REQUEST.
Definition uhc.h:202
const struct device * dev
Pointer to controller's device struct.
Definition uhc.h:205
enum uhc_event_type type
Event type.
Definition uhc.h:197
int status
Event status value, if any.
Definition uhc.h:200
sys_snode_t node
slist node for the message queue
Definition uhc.h:195
UHC endpoint buffer info.
Definition uhc.h:120
void * priv
Pointer to completion callback private data.
Definition uhc.h:151
int err
Transfer result, 0 on success, other values on error.
Definition uhc.h:153
struct net_buf * buf
Transfer data buffer.
Definition uhc.h:126
uint16_t start_frame
Start frame, used for periodic transfers only.
Definition uhc.h:136
unsigned int no_status
The status stage of the control transfer will be omitted.
Definition uhc.h:145
uint16_t mps
Maximum packet size.
Definition uhc.h:132
struct usb_device * udev
Pointer to USB device.
Definition uhc.h:147
unsigned int stage
Control stage status, up to the driver to use it or not.
Definition uhc.h:140
uint8_t ep
Endpoint to which request is associated.
Definition uhc.h:128
unsigned int queued
Flag marks request buffer is queued.
Definition uhc.h:138
void * cb
Pointer to transfer completion callback (opaque for the UHC).
Definition uhc.h:149
uint8_t type
Endpoint type.
Definition uhc.h:130
sys_dnode_t node
dlist node
Definition uhc.h:122
uint8_t setup_pkt[8]
Control transfer setup packet.
Definition uhc.h:124
uint16_t interval
Interval, used for periodic transfers only.
Definition uhc.h:134
USB Association Descriptor defined in USB 3 spec.
Definition usb_ch9.h:465
Header of a USB descriptor.
Definition usb_ch9.h:284
USB Standard Device Descriptor.
Definition usb_ch9.h:304
Host representation of a USB device.
Definition uhc.h:74
sys_dnode_t node
dlist node
Definition uhc.h:76
uint8_t actual_cfg
Actual active device configuration.
Definition uhc.h:88
enum usb_device_speed speed
Device speed.
Definition uhc.h:86
struct usb_device_descriptor dev_desc
USB device descriptor.
Definition uhc.h:82
struct k_mutex mutex
Device mutex.
Definition uhc.h:80
struct usb_host_interface ifaces[32+1]
Pointers to device interfaces.
Definition uhc.h:94
struct usb_host_ep ep_out[16]
Pointers to device OUT endpoints.
Definition uhc.h:96
void * ctx
An opaque pointer to the host context to which this device belongs.
Definition uhc.h:78
enum usb_device_state state
Device state.
Definition uhc.h:84
uint8_t addr
Device address.
Definition uhc.h:90
void * cfg_desc
Pointer to actual device configuration descriptor.
Definition uhc.h:92
struct usb_host_ep ep_in[16]
Pointers to device IN endpoints.
Definition uhc.h:98
USB Standard Endpoint Descriptor.
Definition usb_ch9.h:431
Definition uhc.h:66
struct usb_ep_descriptor * desc
Pointer to the endpoint descriptor.
Definition uhc.h:68
Definition uhc.h:57
uint8_t alternate
Alternate setting selected for this interface.
Definition uhc.h:63
struct usb_association_descriptor * iad
Pointer to the association interface descriptor, if any.
Definition uhc.h:61
struct usb_desc_header * dhp
Pointer to the interface descriptor.
Definition uhc.h:59
Buffers for USB device support.
USB Chapter 9 structures and definitions.