Zephyr API Documentation 3.7.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
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>
18#include <zephyr/usb/usb_ch9.h>
19#include <zephyr/sys/dlist.h>
20
36
75
104
113struct uhc_event {
118 union {
123 };
125 const struct device *dev;
126};
127
139typedef int (*uhc_event_cb_t)(const struct device *dev,
140 const struct uhc_event *const event);
141
150};
151
155#define UHC_STATUS_INITIALIZED 0
159#define UHC_STATUS_ENABLED 1
160
183
191static inline bool uhc_is_initialized(const struct device *dev)
192{
193 struct uhc_data *data = dev->data;
194
196}
197
205static inline bool uhc_is_enabled(const struct device *dev)
206{
207 struct uhc_data *data = dev->data;
208
210}
211
215struct uhc_api {
216 int (*lock)(const struct device *dev);
217 int (*unlock)(const struct device *dev);
218
219 int (*init)(const struct device *dev);
220 int (*enable)(const struct device *dev);
221 int (*disable)(const struct device *dev);
222 int (*shutdown)(const struct device *dev);
223
224 int (*bus_reset)(const struct device *dev);
225 int (*sof_enable)(const struct device *dev);
226 int (*bus_suspend)(const struct device *dev);
227 int (*bus_resume)(const struct device *dev);
228
229 int (*ep_enqueue)(const struct device *dev,
230 struct uhc_transfer *const xfer);
231 int (*ep_dequeue)(const struct device *dev,
232 struct uhc_transfer *const xfer);
233};
249static inline int uhc_bus_reset(const struct device *dev)
250{
251 const struct uhc_api *api = dev->api;
252 int ret;
253
254 api->lock(dev);
255 ret = api->bus_reset(dev);
256 api->unlock(dev);
257
258 return ret;
259}
260
271static inline int uhc_sof_enable(const struct device *dev)
272{
273 const struct uhc_api *api = dev->api;
274 int ret;
275
276 api->lock(dev);
277 ret = api->sof_enable(dev);
278 api->unlock(dev);
279
280 return ret;
281}
282
294static inline int uhc_bus_suspend(const struct device *dev)
295{
296 const struct uhc_api *api = dev->api;
297 int ret;
298
299 api->lock(dev);
300 ret = api->bus_suspend(dev);
301 api->unlock(dev);
302
303 return ret;
304}
305
317static inline int uhc_bus_resume(const struct device *dev)
318{
319 const struct uhc_api *api = dev->api;
320 int ret;
321
322 api->lock(dev);
323 ret = api->bus_resume(dev);
324 api->unlock(dev);
325
326 return ret;
327}
328
347struct uhc_transfer *uhc_xfer_alloc(const struct device *dev,
348 const uint8_t addr,
349 const uint8_t ep,
350 const uint8_t attrib,
351 const uint16_t mps,
352 const uint16_t timeout,
353 void *const udev,
354 void *const cb);
355
374 const uint8_t addr,
375 const uint8_t ep,
376 const uint8_t attrib,
377 const uint16_t mps,
378 const uint16_t timeout,
379 void *const udev,
380 void *const cb,
381 size_t size);
382
393int uhc_xfer_free(const struct device *dev,
394 struct uhc_transfer *const xfer);
395
407int uhc_xfer_buf_add(const struct device *dev,
408 struct uhc_transfer *const xfer,
409 struct net_buf *buf);
421struct net_buf *uhc_xfer_buf_alloc(const struct device *dev,
422 const size_t size);
423
432void uhc_xfer_buf_free(const struct device *dev, struct net_buf *const buf);
433
446int uhc_ep_enqueue(const struct device *dev, struct uhc_transfer *const xfer);
447
459int uhc_ep_dequeue(const struct device *dev, struct uhc_transfer *const xfer);
460
473int uhc_init(const struct device *dev, uhc_event_cb_t event_cb);
474
487int uhc_enable(const struct device *dev);
488
499int uhc_disable(const struct device *dev);
500
512int uhc_shutdown(const struct device *dev);
513
524static inline struct uhc_device_caps uhc_caps(const struct device *dev)
525{
526 struct uhc_data *data = dev->data;
527
528 return data->caps;
529}
530
535#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:127
static int shutdown(int sock, int how)
POSIX wrapper for zsock_shutdown.
Definition socket.h:889
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:155
static bool uhc_is_enabled(const struct device *dev)
Checks whether the controller is enabled.
Definition uhc.h:205
struct uhc_transfer * uhc_xfer_alloc(const struct device *dev, const uint8_t addr, const uint8_t ep, const uint8_t attrib, const uint16_t mps, const uint16_t timeout, void *const udev, void *const cb)
Allocate UHC transfer.
#define UHC_STATUS_ENABLED
Controller is enabled and all API functions are available.
Definition uhc.h:159
static bool uhc_is_initialized(const struct device *dev)
Checks whether the controller is initialized.
Definition uhc.h:191
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:139
static int uhc_bus_reset(const struct device *dev)
Reset USB bus.
Definition uhc.h:249
struct uhc_transfer * uhc_xfer_alloc_with_buf(const struct device *dev, const uint8_t addr, const uint8_t ep, const uint8_t attrib, const uint16_t mps, const uint16_t timeout, void *const udev, void *const cb, size_t size)
Allocate UHC transfer with buffer.
static int uhc_bus_resume(const struct device *dev)
Resume USB bus.
Definition uhc.h:317
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:524
static int uhc_bus_suspend(const struct device *dev)
Suspend USB bus.
Definition uhc.h:294
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.
uhc_event_type
USB host controller event types.
Definition uhc.h:79
int uhc_init(const struct device *dev, uhc_event_cb_t event_cb)
Initialize USB host controller.
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:31
static int uhc_sof_enable(const struct device *dev)
Enable Start of Frame generator.
Definition uhc.h:271
int uhc_enable(const struct device *dev)
Enable USB host controller.
@ UHC_EVT_EP_REQUEST
Endpoint request result event.
Definition uhc.h:97
@ UHC_EVT_DEV_CONNECTED_HS
High speed device connected.
Definition uhc.h:85
@ UHC_EVT_DEV_CONNECTED_FS
Full speed device connected.
Definition uhc.h:83
@ UHC_EVT_RWUP
Remote wakeup signal.
Definition uhc.h:95
@ UHC_EVT_SUSPENDED
Bus suspend operation finished.
Definition uhc.h:91
@ UHC_EVT_DEV_REMOVED
Device (peripheral) removed.
Definition uhc.h:87
@ UHC_EVT_RESUMED
Bus resume operation finished.
Definition uhc.h:93
@ UHC_EVT_DEV_CONNECTED_LS
Low speed device connected.
Definition uhc.h:81
@ UHC_EVT_ERROR
Non-correctable error event, requires attention from higher levels or application.
Definition uhc.h:102
@ UHC_EVT_RESETED
Bus reset operation finished.
Definition uhc.h:89
@ UHC_CONTROL_STAGE_DATA
Definition uhc.h:33
@ UHC_CONTROL_STAGE_SETUP
Definition uhc.h:32
@ UHC_CONTROL_STAGE_STATUS
Definition uhc.h:34
Public kernel APIs.
Buffer management.
__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:412
void * data
Address of the device instance private data.
Definition device.h:422
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:418
Mutex Structure.
Definition kernel.h:2994
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:167
struct k_mutex mutex
Driver access mutex.
Definition uhc.h:171
atomic_t status
USB host controller status.
Definition uhc.h:179
void * priv
Driver private data.
Definition uhc.h:181
sys_dlist_t ctrl_xfers
dlist for control transfers
Definition uhc.h:173
struct uhc_device_caps caps
Controller capabilities.
Definition uhc.h:169
sys_dlist_t bulk_xfers
dlist for bulk transfers
Definition uhc.h:175
uhc_event_cb_t event_cb
Callback to submit an UHC event to upper layer.
Definition uhc.h:177
USB host controller capabilities.
Definition uhc.h:147
uint32_t hs
USB high speed capable controller.
Definition uhc.h:149
USB host controller event.
Definition uhc.h:113
struct uhc_transfer * xfer
Pointer to request used only for UHC_EVT_EP_REQUEST.
Definition uhc.h:122
const struct device * dev
Pointer to controller's device struct.
Definition uhc.h:125
enum uhc_event_type type
Event type.
Definition uhc.h:117
int status
Event status value, if any.
Definition uhc.h:120
sys_snode_t node
slist node for the message queue
Definition uhc.h:115
UHC endpoint buffer info.
Definition uhc.h:47
void * udev
Pointer to USB device (opaque for the UHC)
Definition uhc.h:69
int err
Transfer result, 0 on success, other values on error.
Definition uhc.h:73
struct net_buf * buf
Transfer data buffer.
Definition uhc.h:53
uint8_t addr
Device (peripheral) address.
Definition uhc.h:55
uint16_t mps
Maximum packet size.
Definition uhc.h:61
uint16_t timeout
Timeout in number of frames.
Definition uhc.h:63
unsigned int stage
Control stage status, up to the driver to use it or not.
Definition uhc.h:67
uint8_t ep
Endpoint to which request is associated.
Definition uhc.h:57
unsigned int queued
Flag marks request buffer is queued.
Definition uhc.h:65
void * cb
Pointer to transfer completion callback (opaque for the UHC)
Definition uhc.h:71
uint8_t attrib
Endpoint attributes (TBD)
Definition uhc.h:59
sys_dnode_t node
dlist node
Definition uhc.h:49
uint8_t setup_pkt[8]
Control transfer setup packet.
Definition uhc.h:51
USB Chapter 9 structures and definitions.