Skip to content

Commit 66c44f5

Browse files
srberardArturSirSorinOlari
authored
Multi container fixes plus initial GPIO support (#27) (#57)
* Multi container fixes plus initial GPIO support (#27) * Fix multi container issues * Added memory check feature * Initial GPIO support * Fix for container ID in thread create * Fix for container update * Clean up mechanism for timers * Fix for ocre sensors * Fix for app updates --------- Co-authored-by: ArturSir <artur@atym.io> Co-authored-by: SorinOlari <sorin.olari2@gmail.com> * Fixed GPIO configuration parameter Signed-off-by: Stephen Berard <stephen.berard@outlook.com> * Fixed config issue Signed-off-by: Stephen Berard <stephen.berard@outlook.com> * Fix Cmake issue with regard to GPIO Signed-off-by: Stephen Berard <stephen.berard@outlook.com> * Fixed conditional compile issue with GPIO Signed-off-by: Stephen Berard <stephen.berard@outlook.com> * Fixed syntax issue Signed-off-by: Stephen Berard <stephen.berard@outlook.com> --------- Signed-off-by: Stephen Berard <stephen.berard@outlook.com> Co-authored-by: ArturSir <artur@atym.io> Co-authored-by: SorinOlari <sorin.olari2@gmail.com>
1 parent 0a2f841 commit 66c44f5

16 files changed

Lines changed: 1286 additions & 41 deletions

File tree

CMakeLists.txt

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,25 @@ set(lib_sources
114114
)
115115

116116
# Compile in sensors framework if enabled.
117-
if(DEFINED CONFIG_SENSOR)
117+
if(CONFIG_OCRE_SENSORS)
118+
set(ocre_sources ${ocre_sources} ${OCRE_ROOT_DIR}/src/ocre/ocre_sensors/ocre_sensors.c)
119+
endif()
120+
121+
# Compile random sensor if enabled.
122+
if(CONFIG_RNG_SENSOR)
123+
set(ocre_sources ${ocre_sources} ${OCRE_ROOT_DIR}/src/ocre/ocre_sensors/rng_sensor.c)
124+
endif()
125+
126+
if(DEFINED CONFIG_OCRE_GPIO)
118127
set(lib_sources ${lib_sources}
119-
src/ocre/ocre_sensors/ocre_sensors.c
120-
src/ocre/ocre_sensors/rng_sensor.c
128+
src/ocre/ocre_gpio/ocre_gpio.c
121129
)
122130
endif()
123131

132+
# Compile container messaging if enabled.
133+
if(CONFIG_OCRE_CONTAINER_MESSAGING)
134+
set(lib_sources ${lib_sources} src/ocre/container_messaging/messaging.c)
135+
endif()
124136

125137
set(component_sources
126138
# Component support

Kconfig

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,17 @@ source "subsys/logging/Kconfig.template.log_config"
6565

6666
endif
6767

68+
config OCRE_SENSORS
69+
bool "Enable OCRE Sensors support"
70+
default n
71+
depends on SENSOR
72+
help
73+
Enable support for OCRE sensors
74+
6875
config RNG_SENSOR
6976
bool "RNG Sensor"
7077
default n
71-
depends on SENSOR
78+
depends on OCRE_SENSORS
7279
help
7380
Enable support for the custom RNG sensor.
7481

@@ -109,6 +116,50 @@ config MAX_CHANNELS_PER_SENSOR
109116
help
110117
Defines the maximum number of channels that each sensor can have.
111118

119+
config OCRE_MEMORY_CHECK_ENABLED
120+
bool "Enable memory availability checking for containers"
121+
default y
122+
help
123+
Enable runtime memory checks before creating containers
124+
125+
126+
config OCRE_GPIO
127+
bool "OCRE GPIO Driver"
128+
default y
129+
help
130+
Enable the OCRE GPIO driver that provides a portable API layer
131+
for GPIO operations across different hardware platforms.
132+
133+
config OCRE_GPIO_MAX_PINS
134+
int "Maximum number of GPIO pins"
135+
default 32
136+
help
137+
Maximum number of GPIO pins that can be managed by the OCRE GPIO driver.
138+
139+
config OCRE_GPIO_MAX_PORTS
140+
int "Maximum number of GPIO ports"
141+
default 4
142+
help
143+
Maximum number of GPIO port devices that can be used by the OCRE GPIO driver.
144+
145+
config OCRE_GPIO_PINS_PER_PORT
146+
int "Number of pins per GPIO port"
147+
default 32
148+
help
149+
Number of pins available on each GPIO port. This is used to map the
150+
logical pin numbers to physical port and pin numbers.
151+
152+
config OCRE_CONTAINER_MESSAGING
153+
bool "Enable OCRE Container Messaging support"
154+
default n
155+
help
156+
Enable support for OCRE Container Messaging
157+
158+
config MESSAGING_MAX_SUBSCRIPTIONS
159+
int "Number of maximum subscriptions for Container Messaging"
160+
default 10
161+
depends on OCRE_CONTAINER_MESSAGING
162+
help
163+
Number of maximum subscriptions for Container Messaging
112164

113-
114165
endmenu

boards/b_u585i_iot02a.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ CONFIG_NET_L2_ETHERNET=y
1010
# hts221 sensor config
1111
CONFIG_I2C=y
1212
CONFIG_SENSOR=y
13-
CONFIG_CBPRINTF_FP_SUPPORT=y
13+
CONFIG_CBPRINTF_FP_SUPPORT=y

boards/native_sim.overlay

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
zephyr,uart-mcumgr = &uart0;
66
};
77

8+
aliases {
9+
rng0 = &rng_device;
10+
};
11+
812
devices{
913
rng_device: rng_0 {
1014
compatible = "custom,rng-sensor";

prj.conf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ CONFIG_LOG_TRACE_SHORT_TIMESTAMP=y
7373
CONFIG_SENSOR=y
7474
CONFIG_RNG_SENSOR=y
7575

76+
CONFIG_OCRE_CONTAINER_MESSAGING=y
77+
CONFIG_MESSAGING_MAX_SUBSCRIPTIONS=10
78+
7679
CONFIG_DEVICE_DT_METADATA=y
7780
CONFIG_DEVICE_DEPS=y
7881

@@ -81,5 +84,6 @@ CONFIG_MAX_TIMERS=5
8184
CONFIG_MAX_SENSORS=10
8285
CONFIG_MAX_CHANNELS_PER_SENSOR=5
8386

84-
87+
CONFIG_OCRE_MEMORY_CHECK_ENABLED=n
88+
CONFIG_OCRE_GPIO=n
8589

src/ocre/api/ocre_api.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include "ocre_api.h"
2020
#include "../ocre_timers/ocre_timer.h"
2121
#include "../ocre_sensors/ocre_sensors.h"
22+
#include "../ocre_gpio/ocre_gpio.h"
23+
#include "../container_messaging/messaging.h"
2224

2325
int _ocre_posix_uname(wasm_exec_env_t exec_env, struct _ocre_posix_utsname *name) {
2426
struct utsname info;
@@ -82,6 +84,15 @@ NativeSymbol ocre_api_table[] = {
8284

8385
{"ocre_sleep", ocre_sleep, "(i)i", NULL},
8486

87+
// Container Messaging API
88+
#ifdef CONFIG_OCRE_CONTAINER_MESSAGING
89+
{"ocre_msg_system_init", ocre_msg_system_init, "()", NULL},
90+
{"ocre_publish_message", ocre_publish_message, "(***i)i", NULL},
91+
{"ocre_subscribe_message", ocre_subscribe_message, "(**)i", NULL},
92+
#endif
93+
94+
// Sensor API
95+
#ifdef CONFIG_OCRE_SENSORS
8596
// Sensor API
8697
{"ocre_sensors_init", ocre_sensors_init, "()i", NULL},
8798
{"ocre_sensors_discover", ocre_sensors_discover, "()i", NULL},
@@ -90,7 +101,7 @@ NativeSymbol ocre_api_table[] = {
90101
{"ocre_sensors_get_channel_count", ocre_sensors_get_channel_count, "(i)i", NULL},
91102
{"ocre_sensors_get_channel_type", ocre_sensors_get_channel_type, "(ii)i", NULL},
92103
{"ocre_sensors_read", ocre_sensors_read, "(ii)i", NULL},
93-
104+
#endif
94105
// Timer API
95106
{"ocre_timer_create", ocre_timer_create, "(i)i", NULL},
96107
{"ocre_timer_start", ocre_timer_start, "(iii)i", NULL},
@@ -99,6 +110,16 @@ NativeSymbol ocre_api_table[] = {
99110
{"ocre_timer_get_remaining", ocre_timer_get_remaining, "(i)i", NULL},
100111
{"ocre_timer_set_dispatcher", ocre_timer_set_dispatcher, "(i)v", NULL},
101112

113+
#ifdef CONFIG_OCRE_GPIO
114+
// GPIO API
115+
{"ocre_gpio_init", ocre_gpio_wasm_init, "()i", NULL},
116+
{"ocre_gpio_configure", ocre_gpio_wasm_configure, "(iii)i", NULL},
117+
{"ocre_gpio_set", ocre_gpio_wasm_set, "(iii)i", NULL},
118+
{"ocre_gpio_get", ocre_gpio_wasm_get, "(ii)i", NULL},
119+
{"ocre_gpio_toggle", ocre_gpio_wasm_toggle, "(ii)i", NULL},
120+
{"ocre_gpio_register_callback", ocre_gpio_wasm_register_callback, "(ii)i", NULL},
121+
{"ocre_gpio_unregister_callback", ocre_gpio_wasm_unregister_callback, "(ii)i", NULL},
122+
#endif
102123
};
103124

104125
int ocre_api_table_size = sizeof(ocre_api_table) / sizeof(NativeSymbol);

src/ocre/components/container_supervisor/cs_sm.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ static void runtime_uninitialized_run(void *o) {
3636

3737
switch (msg->event) {
3838
case EVENT_CS_INITIALIZE:
39+
LOG_INF("Transitioning from state STATE_RUNTIME_UNINITIALIZED_RUN to state STATE_RUNTIME_RUNNING");
3940
sm_transition(&ocre_cs_state_machine, STATE_RUNTIME_RUNNING);
4041
break;
4142

@@ -47,10 +48,6 @@ static void runtime_uninitialized_run(void *o) {
4748
SM_MARK_EVENT_HANDLED(o);
4849
}
4950

50-
// void callbackFcn(void) {
51-
// LOG_INF("CALLBACK CALLED");
52-
// }
53-
5451
static void runtime_running_entry(void *o) {
5552
#if OCRE_CS_DEBUG_ON
5653
LOG_INF("HELLO runtime_running_entry");
@@ -75,6 +72,7 @@ static void runtime_running_run(void *o) {
7572
break;
7673
}
7774
case EVENT_RUN_CONTAINER: {
75+
LOG_INF("EVENT_RUN_CONTAINER");
7876
if (CS_run_container(ctx, &msg->containerId) == CONTAINER_STATUS_RUNNING) {
7977
LOG_INF("Started container in slot:%d", msg->containerId);
8078
} else {
@@ -83,18 +81,22 @@ static void runtime_running_run(void *o) {
8381
break;
8482
}
8583
case EVENT_STOP_CONTAINER: {
84+
LOG_INF("EVENT_STOP_CONTAINER");
8685
CS_stop_container(ctx, msg->containerId, callback);
8786
break;
8887
}
8988
case EVENT_DESTROY_CONTAINER: {
89+
LOG_INF("EVENT_DESTROY_CONTAINER");
9090
CS_destroy_container(ctx, msg->containerId, callback);
9191
break;
9292
}
9393
case EVENT_RESTART_CONTAINER: {
94+
LOG_INF("EVENT_RESTART_CONTAINER");
9495
CS_restart_container(ctx, msg->containerId, callback);
9596
break;
9697
}
9798
case EVENT_CS_DESTROY:
99+
LOG_INF("EVENT_CS_DESTROY");
98100
sm_transition(&ocre_cs_state_machine, STATE_RUNTIME_UNINITIALIZED);
99101
break;
100102
default:

0 commit comments

Comments
 (0)