Skip to main content
The device manager maintains a registry of up to 32 hardware devices. Each entry records a numeric ID, a device type drawn from a fixed enumeration, a human-readable name (up to 27 characters), and an online flag indicating whether the device is currently active. You interact with the registry through the five functions described below.

Constants

Types

device_type_t

An enumeration of all recognised device classes.

device_info_t

A snapshot of a single registered device.
uint32_t
A kernel-assigned identifier that is unique for the lifetime of the registry. IDs are assigned sequentially starting from 0 and are never reused within a single boot.
device_type_t
The device class. Use device_type_name() to convert this value to a printable string.
uint8_t
1 if the device is online and available; 0 if it has been registered but is not yet active or has failed.
char[28]
A null-terminated UTF-8 display name supplied at registration time. Maximum usable length is 27 characters.

Functions

device_manager_init

Initialise the device manager. You must call this function exactly once during kernel startup, before calling any other device API function. Calling it a second time resets the registry and discards all previously registered devices.

device_register

Register a new device with the given name, type, and initial online state.
const char *
required
A null-terminated display name for the device. The name is copied into the registry; you do not need to keep the pointer alive after the call. Maximum length is 27 characters — longer names are truncated to fit DEVICE_NAME_MAX.
device_type_t
required
The device class. Must be one of the device_type_t enumerators listed above.
uint8_t
required
Pass 1 to mark the device as online immediately, or 0 to register it in an offline state.
int
Returns 0 on success. Returns -1 if the registry is full (i.e. DEVICE_MAX devices are already registered).

device_count

Return the number of devices currently registered.
uint32_t
The number of entries in the registry, in the range [0, DEVICE_MAX].

device_list

Copy registered device records into a caller-supplied array.
device_info_t *
required
Pointer to an array of device_info_t that will receive the device records. The array must be large enough to hold at least capacity elements.
uint32_t
required
The maximum number of records to write. Pass DEVICE_MAX to guarantee that every registered device is captured.
uint32_t
The number of records written to devices. This is min(device_count(), capacity).

device_type_name

Return a human-readable string for a device type enumerator.
device_type_t
required
Any device_type_t value.
const char *
A pointer to a null-terminated string such as "CPU", "INTERRUPT", "TIMER", "INPUT", "DISPLAY", "SERIAL", "CLOCK", "BUS", or "FILESYSTEM". The pointer refers to a static string — do not free or modify it. Returns "UNKNOWN" for unrecognised values.

Shell Command

The built-in devices shell command prints a formatted table of every registered device, including its ID, type, name, and online state:

Example

The following example registers two custom devices, then iterates the registry and prints each entry.