diff --git a/Kconfig b/Kconfig index 9424966e..a38b82d5 100644 --- a/Kconfig +++ b/Kconfig @@ -57,6 +57,24 @@ config OCRE_LOG_DEBUG help Enable Ocre debug logging +config OCRE_LOG_ERR + bool "Error logging" + default n + help + Enable Ocre debug logging + +config OCRE_LOG_WARN + bool "Warn logging" + default n + help + Enable Ocre debug logging + +config OCRE_LOG_INF + bool "Info logging" + default n + help + Enable Ocre debug logging + if OCRE module = OCRE @@ -96,7 +114,6 @@ config OCRE_CONTAINER_DEFAULT_STACK_SIZE default 2048 help The default value used for a container's stack size. - config MAX_TIMERS int "Maximum number of timers" @@ -162,4 +179,4 @@ config MESSAGING_MAX_SUBSCRIPTIONS help Number of maximum subscriptions for Container Messaging -endmenu \ No newline at end of file +endmenu diff --git a/prj.conf b/prj.conf index ce657741..480e0a91 100644 --- a/prj.conf +++ b/prj.conf @@ -65,8 +65,8 @@ CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=-1 # Ocre configuration CONFIG_OCRE_WAMR_HEAP_BUFFER_SIZE=512000 -CONFIG_OCRE_CONTAINER_DEFAULT_HEAP_SIZE=32768 -CONFIG_OCRE_CONTAINER_DEFAULT_STACK_SIZE=16384 +CONFIG_OCRE_CONTAINER_DEFAULT_HEAP_SIZE=4096 +CONFIG_OCRE_CONTAINER_DEFAULT_STACK_SIZE=4096 CONFIG_LOG_TRACE_SHORT_TIMESTAMP=y # Ocre Feature Options diff --git a/src/ocre/api/ocre_api.c b/src/ocre/api/ocre_api.c index 2794ef36..fb05514f 100644 --- a/src/ocre/api/ocre_api.c +++ b/src/ocre/api/ocre_api.c @@ -114,9 +114,9 @@ NativeSymbol ocre_api_table[] = { // GPIO API {"ocre_gpio_init", ocre_gpio_wasm_init, "()i", NULL}, {"ocre_gpio_configure", ocre_gpio_wasm_configure, "(iii)i", NULL}, - {"ocre_gpio_set", ocre_gpio_wasm_set, "(iii)i", NULL}, - {"ocre_gpio_get", ocre_gpio_wasm_get, "(ii)i", NULL}, - {"ocre_gpio_toggle", ocre_gpio_wasm_toggle, "(ii)i", NULL}, + {"ocre_gpio_pin_set", ocre_gpio_wasm_set, "(iii)i", NULL}, + {"ocre_gpio_pin_get", ocre_gpio_wasm_get, "(ii)i", NULL}, + {"ocre_gpio_pin_toggle", ocre_gpio_wasm_toggle, "(ii)i", NULL}, {"ocre_gpio_register_callback", ocre_gpio_wasm_register_callback, "(ii)i", NULL}, {"ocre_gpio_unregister_callback", ocre_gpio_wasm_unregister_callback, "(ii)i", NULL}, #endif diff --git a/src/ocre/container_messaging/messaging.h b/src/ocre/container_messaging/messaging.h index b3bfe66d..50dce18f 100644 --- a/src/ocre/container_messaging/messaging.h +++ b/src/ocre/container_messaging/messaging.h @@ -17,7 +17,7 @@ typedef struct ocre_msg { // payload format (MIME type??) char *content_type; - // payload of the request, currently only support attr_container_t type + // payload of the request void *payload; // length in bytes of the payload diff --git a/src/ocre/ocre_gpio/ocre_gpio.h b/src/ocre/ocre_gpio/ocre_gpio.h index 39788616..f722870e 100644 --- a/src/ocre/ocre_gpio/ocre_gpio.h +++ b/src/ocre/ocre_gpio/ocre_gpio.h @@ -12,9 +12,6 @@ #include #include "wasm_export.h" -#define CONFIG_BOARD_B_U585I_IOT02A -// #define CONFIG_BOARD_ESP32C3_DEVKITM - // Default configuration values if not provided by Kconfig #ifndef CONFIG_OCRE_GPIO_MAX_PINS #define CONFIG_OCRE_GPIO_MAX_PINS 32 diff --git a/src/ocre/ocre_sensors/ocre_sensors.c b/src/ocre/ocre_sensors/ocre_sensors.c index 00bc39de..43549a86 100644 --- a/src/ocre/ocre_sensors/ocre_sensors.c +++ b/src/ocre/ocre_sensors/ocre_sensors.c @@ -13,26 +13,18 @@ LOG_MODULE_DECLARE(ocre_sensors, OCRE_LOG_LEVEL); #include "ocre_sensors.h" -/* - * Build a list of device nodes from the devicetree if: - * 1. OCRE_SENSORS is enabled - * 2. The 'devices' node exists in the devicetree - * 3. The 'devices' node has at least one child - * 4. The 'devices' node has property label - */ #define DEVICE_NODE DT_PATH(devices) -#define HAS_DEVICE_NODES DT_NODE_EXISTS(DEVICE_NODE) && DT_CHILD_NUM(DEVICE_NODE) > 0 - +#define HAS_DEVICE_NODES DT_NODE_EXISTS(DEVICE_NODE) && DT_PROP_LEN(DEVICE_NODE, device_list) > 1 #if (CONFIG_OCRE_SENSORS) && (HAS_DEVICE_NODES) -#define DEVICE_NODES_LIST(node_id) COND_CODE_1(DT_NODE_HAS_PROP(node_id, label), (DT_PROP(node_id, label), ), ()) -static const char *device_nodes[] = {DT_FOREACH_CHILD(DEVICE_NODE, DEVICE_NODES_LIST)}; -#define DEVICE_NODES_COUNT (sizeof(device_nodes) / sizeof(device_nodes[0])) +#define EXTRACT_LABELS(node_id, prop, idx) DT_PROP_BY_PHANDLE_IDX_OR(node_id, prop, idx, label, "undefined") +static const char *sensor_discovery_names[] = { + DT_FOREACH_PROP_ELEM_SEP(DEVICE_NODE, device_list, EXTRACT_LABELS, (, ))}; +static int sensor_names_count = sizeof(sensor_discovery_names) / sizeof(sensor_discovery_names[0]); #else -static const char *device_nodes[] = {}; -#define DEVICE_NODES_COUNT 0 +static const char *sensor_discovery_names[] = {}; +static int sensor_names_count = 0; #endif -static const char *device_nodes[] = {DT_FOREACH_CHILD(DEVICE_NODE, DEVICE_NODES_LIST)}; typedef struct { const struct device *device; ocre_sensor_t info; @@ -43,20 +35,6 @@ static ocre_sensor_internal_t sensors[CONFIG_MAX_SENSORS] = {0}; static int sensor_count = 0; static char sensor_names[CONFIG_MAX_SENSORS][CONFIG_MAX_SENSOR_NAME_LENGTH]; -static bool is_custom_device(const struct device *dev) { - if (!dev) { - LOG_ERR("Device is NULL"); - return false; - } - - for (int i = 0; i < DEVICE_NODES_COUNT; i++) { - if (strcmp(dev->name, device_nodes[i]) == 0) { - return true; - } - } - return false; -} - static int set_opened_channels(const struct device *dev, sensor_channel_t *channels) { if (!channels) { LOG_ERR("Channels array is NULL"); @@ -104,7 +82,6 @@ int ocre_sensors_discover(wasm_exec_env_t exec_env) { LOG_ERR("Device list is NULL. Possible memory corruption!"); return -1; } - if (device_count == 0) { LOG_ERR("No static devices found"); return -1; @@ -112,33 +89,44 @@ int ocre_sensors_discover(wasm_exec_env_t exec_env) { LOG_INF("Total static devices found: %zu", device_count); - if (!device_nodes[0]) { - LOG_ERR("No devices found in DeviceTree!"); - return -1; - } - for (size_t i = 0; i < device_count && sensor_count < CONFIG_MAX_SENSORS; i++) { if (!dev[i].name) { LOG_ERR("Device %zu has NULL name, skipping!", i); continue; } - if (!is_custom_device(&dev[i])) { - LOG_WRN("Skipping non-custom device: %s", dev[i].name); - continue; - } + LOG_INF("Checking device: %s", dev[i].name); - if (!device_is_ready(&dev[i])) { - LOG_WRN("Device %s is not ready, skipping", dev[i].name); + // Check if device name is in the sensor discovery list + bool sensor_found = false; + for (int j = 0; j < sensor_names_count; j++) { + if (strcmp(dev[i].name, sensor_discovery_names[j]) == 0) { + sensor_found = true; + break; + } + } + if (!sensor_found) { + LOG_WRN("Skipping device, not in sensor list: %s", dev[i].name); continue; } + // if (!device_is_ready(&dev[i])) { + // LOG_WRN("Device %s is not ready, skipping", dev[i].name); + // continue; + // } + const struct sensor_driver_api *api = (const struct sensor_driver_api *)dev[i].api; if (!api || !api->channel_get) { LOG_WRN("Device %s does not support sensor API or channel_get, skipping", dev[i].name); continue; } + // Ensure we don't exceed sensor limit + if (sensor_count >= CONFIG_MAX_SENSORS) { + LOG_WRN("Max sensor limit reached, skipping device: %s", dev[i].name); + continue; + } + // Initialize the sensor ocre_sensor_internal_t *sensor = &sensors[sensor_count]; sensor->device = &dev[i]; @@ -156,7 +144,7 @@ int ocre_sensors_discover(wasm_exec_env_t exec_env) { continue; } - LOG_INF("Device %s has %d channels", sensor->info.sensor_name, sensor->info.num_channels); + LOG_INF("Device has %d channels", sensor->info.num_channels); sensor_count++; }