Nexus Embedded Platform 1.0.0
Statically assembled reusable embedded mechanisms
Loading...
Searching...
No Matches
usb_device.h
Go to the documentation of this file.
1
6#ifndef NEXUS_USB_DEVICE_H
7#define NEXUS_USB_DEVICE_H
9#include "nexus/io/wake.h"
10#ifdef __cplusplus
11extern "C" {
12#endif
14typedef struct {
16 const uint8_t* in;
17 uint8_t* out;
18 size_t length;
19 uint64_t control_epoch;
22typedef struct {
23 uint8_t request_type;
24 uint8_t request;
25 uint16_t value;
26 uint16_t index;
27 uint16_t length;
28 uint64_t epoch;
43typedef struct {
45 uint64_t epoch;
46 uint64_t lost_events;
47 bool started;
48 bool closing;
51 uint8_t address;
53
63
64typedef struct {
66 nx_result_t (*read_events)(void*, nx_usb_event_t*, size_t, size_t*);
68 nx_result_t (*address)(void*, uint64_t, uint8_t);
69 nx_result_t (*attach_wake)(void*, const nx_irq_wake_t*, uint8_t);
70 nx_result_t (*stop)(void*);
72typedef struct {
74 void* context;
76
86nx_result_t nx_usb_in_prepare(nx_usb_request_t* request, const uint8_t* bytes,
87 size_t length, nx_usb_stage_t stage,
88 uint64_t epoch, nx_time_us_t deadline);
100 size_t capacity, nx_usb_stage_t stage,
101 uint64_t epoch, nx_time_us_t deadline);
111 nx_usb_request_t* request);
122 nx_usb_request_t* request);
130 bool stalled);
147 nx_usb_event_t* events, size_t capacity,
148 size_t* count);
157 nx_usb_device_state_t* state);
166 uint64_t epoch, uint8_t address);
176 const nx_irq_wake_t* wake,
177 uint8_t syscall_ceiling);
188#ifdef __cplusplus
189}
190#endif
191#endif
Caller-owned admission, borrow, settlement and stable cancellation.
nx_result_t
Operation result; success at submission means admission only.
Definition status.h:21
Optional immutable wake target borrowed by an IRQ provider.
Definition wake.h:26
Caller-owned request metadata, without payload or callbacks.
Definition request.h:38
Controller identity remains separate from endpoint identities.
Definition usb_device.h:64
nx_result_t(* address)(void *, uint64_t, uint8_t)
Definition usb_device.h:68
nx_result_t(* service)(void *)
Definition usb_device.h:65
nx_result_t(* read_events)(void *, nx_usb_event_t *, size_t, size_t *)
Definition usb_device.h:66
nx_result_t(* attach_wake)(void *, const nx_irq_wake_t *, uint8_t)
Definition usb_device.h:69
nx_result_t(* stop)(void *)
Definition usb_device.h:70
nx_result_t(* state)(void *, nx_usb_device_state_t *)
Definition usb_device.h:67
const nx_usb_device_ops_t * ops
Definition usb_device.h:73
nx_usb_setup_t setup
Definition usb_device.h:44
Shared readonly packet methods; context is a selected endpoint.
Definition usb_device.h:54
nx_result_t(* stall)(void *, bool)
Definition usb_device.h:57
nx_result_t(* submit)(void *, nx_usb_request_t *)
Definition usb_device.h:55
nx_result_t(* cancel)(void *, nx_usb_request_t *)
Definition usb_device.h:56
const nx_usb_endpoint_ops_t * ops
Definition usb_device.h:60
nx_usb_event_kind_t kind
Definition usb_device.h:41
nx_time_us_t timestamp_us
Definition usb_device.h:39
uint64_t lost
Definition usb_device.h:40
nx_usb_setup_t setup
Definition usb_device.h:38
const uint8_t * in
Definition usb_device.h:16
uint8_t * out
Definition usb_device.h:17
nx_request_t base
Definition usb_device.h:15
uint64_t control_epoch
Definition usb_device.h:19
nx_usb_stage_t stage
Definition usb_device.h:20
uint8_t request
Definition usb_device.h:24
uint16_t value
Definition usb_device.h:25
uint16_t index
Definition usb_device.h:26
uint16_t length
Definition usb_device.h:27
uint64_t epoch
Definition usb_device.h:28
uint8_t request_type
Definition usb_device.h:23
uint64_t nx_time_us_t
Microseconds in one boot/clock domain; no wall-clock semantics.
Definition time.h:20
nx_result_t nx_usb_device_service(const nx_usb_device_port_t *port)
Task-only bounded progress; deadline never depends on USB SOF.
nx_result_t nx_usb_device_state(const nx_usb_device_port_t *port, nx_usb_device_state_t *state)
Task-only authoritative snapshot, independent of event-ring space.
nx_result_t nx_usb_device_stop(const nx_usb_device_port_t *port)
Disconnect, disable, drain, detach IRQs, then release clock consumer.
nx_result_t nx_usb_device_attach_wake(const nx_usb_device_port_t *port, const nx_irq_wake_t *wake, uint8_t syscall_ceiling)
Attach/detach a borrowed task/IRQ-compatible wake hint.
nx_usb_event_kind_t
Definition usb_device.h:30
@ NX_USB_EVENT_LOSS
Definition usb_device.h:35
@ NX_USB_EVENT_RESET
Definition usb_device.h:32
@ NX_USB_EVENT_SETUP
Definition usb_device.h:31
@ NX_USB_EVENT_RESUME
Definition usb_device.h:34
@ NX_USB_EVENT_SUSPEND
Definition usb_device.h:33
nx_result_t nx_usb_endpoint_cancel(const nx_usb_endpoint_port_t *port, nx_usb_request_t *request)
Request endpoint disable/drain without revoking a buffer loan.
nx_result_t nx_usb_endpoint_submit(const nx_usb_endpoint_port_t *port, nx_usb_request_t *request)
Admit one packet, never a hidden queue or complete USB transaction.
nx_result_t nx_usb_in_prepare(nx_usb_request_t *request, const uint8_t *bytes, size_t length, nx_usb_stage_t stage, uint64_t epoch, nx_time_us_t deadline)
Prepare one IN packet without reading or borrowing its bytes.
nx_result_t nx_usb_endpoint_stall(const nx_usb_endpoint_port_t *port, bool stalled)
Set/clear STALL only after the endpoint has no live transfer.
nx_result_t nx_usb_device_address(const nx_usb_device_port_t *port, uint64_t epoch, uint8_t address)
Stage SET_ADDRESS for the matching zero-data standard SETUP.
nx_usb_stage_t
Definition usb_device.h:13
@ NX_USB_STATUS
Definition usb_device.h:13
@ NX_USB_DATA
Definition usb_device.h:13
nx_result_t nx_usb_device_read_events(const nx_usb_device_port_t *port, nx_usb_event_t *events, size_t capacity, size_t *count)
Consume bounded value events; output is never retained.
nx_result_t nx_usb_out_prepare(nx_usb_request_t *request, uint8_t *bytes, size_t capacity, nx_usb_stage_t stage, uint64_t epoch, nx_time_us_t deadline)
Prepare an OUT packet capacity without modifying its storage.
Explicit borrowed IRQ wake target and syscall-ceiling check.