Kernel improvements (#485)

* **New Features**
  * Added public accessors for querying module/device start and ready state.

* **Refactor**
  * Internal state moved to opaque internal objects; module/device/driver initializers now explicitly initialize internal pointers.
  * Lifecycle handling updated to construct/destruct internal state and use accessors.

* **Tests**
  * Tests updated to use public accessors and explicit construct/destruct lifecycle calls.

* **Chores**
  * Test build/include paths and small metadata updated.
This commit is contained in:
Ken Van Hoeylandt
2026-02-06 16:32:30 +01:00
committed by GitHub
parent 1757af859c
commit 79e43b093a
105 changed files with 338 additions and 331 deletions
@@ -18,12 +18,10 @@ struct Mutex {
};
inline static void mutex_construct(struct Mutex* mutex) {
assert(mutex->handle == NULL);
mutex->handle = xSemaphoreCreateMutex();
}
inline static void mutex_destruct(struct Mutex* mutex) {
assert(mutex->handle != NULL);
vPortAssertIfInISR();
vSemaphoreDelete(mutex->handle);
mutex->handle = NULL;
+11 -20
View File
@@ -16,39 +16,30 @@ extern "C" {
#endif
struct Driver;
struct DevicePrivate;
struct DeviceInternal;
/** Enables discovering devices of the same type */
struct DeviceType {
/* Placeholder because empty structs have a different size with C vs C++ compilers */
uint8_t _;
const char* name;
};
/** Represents a piece of hardware */
struct Device {
/** The name of the device. Valid characters: a-z a-Z 0-9 - _ . */
const char* name;
/** The configuration data for the device's driver */
const void* config;
/** The parent device that this device belongs to. Can be NULL, but only the root device should have a NULL parent. */
struct Device* parent;
/** Internal data */
struct {
/** Address of the API exposed by the device instance. */
struct Driver* driver;
/** The driver data for this device (e.g. a mutex) */
void* driver_data;
/** The mutex for device operations */
struct Mutex mutex;
/** The device state */
struct {
int start_result;
bool started : 1;
bool added : 1;
} state;
/** Private data */
struct DevicePrivate* device_private;
} internal;
/**
* Internal state managed by the kernel.
* Device implementers should initialize this to NULL.
* Do not access or modify directly; use device_* functions.
*/
struct DeviceInternal* internal;
};
/**
+7 -3
View File
@@ -12,7 +12,7 @@ extern "C" {
struct Device;
struct DeviceType;
struct Module;
struct DriverPrivate;
struct DriverInternal;
struct Driver {
/** The driver name */
@@ -29,8 +29,12 @@ struct Driver {
const struct DeviceType* device_type;
/** The module that owns this driver. When it is NULL, the system owns the driver and it cannot be removed from registration. */
const struct Module* owner;
/** Internal data */
struct DriverPrivate* driver_private;
/**
* Internal state managed by the kernel.
* Driver implementers should initialize this to NULL.
* Do not access or modify directly; use driver_* functions.
*/
struct DriverInternal* internal;
};
/**
+8 -7
View File
@@ -25,6 +25,8 @@ struct ModuleSymbol {
const void* symbol;
};
struct ModuleInternal;
/**
* A module is a collection of drivers or other functionality that can be loaded and unloaded at runtime.
*/
@@ -36,7 +38,6 @@ struct Module {
* Desirable format "platform-esp32", "lilygo-tdeck", etc.
*/
const char* name;
/**
* A function to initialize the module.
* Should never be NULL.
@@ -44,24 +45,24 @@ struct Module {
* @return ERROR_NONE if successful
*/
error_t (*start)(void);
/**
* Deinitializes the module.
* Should never be NULL.
* @return ERROR_NONE if successful
*/
error_t (*stop)(void);
/**
* A list of symbols exported by the module.
* Should be terminated by MODULE_SYMBOL_TERMINATOR.
* Can be a NULL value.
*/
const struct ModuleSymbol* symbols;
struct {
bool started;
} internal;
/**
* Internal state managed by the kernel.
* Module implementers should initialize this to NULL.
* Do not access or modify directly; use module_* functions.
*/
struct ModuleInternal* internal;
};
/**