|
26 | 26 |
|
27 | 27 | #include "ocre/utils/utils.h" |
28 | 28 |
|
29 | | -#if defined(CONFIG_OCRE_TIMER) || defined(CONFIG_OCRE_GPIO) || defined(CONFIG_OCRE_SENSORS) || defined(CONFIG_OCRE_CONTAINER_MESSAGING) |
| 29 | +#if defined(CONFIG_OCRE_TIMER) || defined(CONFIG_OCRE_GPIO) || defined(CONFIG_OCRE_SENSORS) || \ |
| 30 | + defined(CONFIG_OCRE_CONTAINER_MESSAGING) |
30 | 31 | #include "ocre_common.h" |
31 | | -#endif |
| 32 | +#endif |
32 | 33 |
|
33 | 34 | #ifdef CONFIG_OCRE_SENSORS |
34 | 35 | #include "../ocre_sensors/ocre_sensors.h" |
|
42 | 43 | #include "../ocre_messaging/ocre_messaging.h" |
43 | 44 | #endif |
44 | 45 |
|
45 | | -int _ocre_posix_uname(wasm_exec_env_t exec_env, struct _ocre_posix_utsname *name) { |
46 | | - wasm_module_inst_t module_inst = wasm_runtime_get_module_inst(exec_env); |
47 | | - if (!module_inst) { |
48 | | - return -1; |
49 | | - } |
50 | | - if (!wasm_runtime_validate_native_addr(module_inst, name, sizeof(struct _ocre_posix_utsname))) { |
51 | | - return -1; |
52 | | - } |
| 46 | +int _ocre_posix_uname(wasm_exec_env_t exec_env, struct _ocre_posix_utsname *name) |
| 47 | +{ |
| 48 | + wasm_module_inst_t module_inst = wasm_runtime_get_module_inst(exec_env); |
| 49 | + if (!module_inst) { |
| 50 | + return -1; |
| 51 | + } |
| 52 | + if (!wasm_runtime_validate_native_addr(module_inst, name, sizeof(struct _ocre_posix_utsname))) { |
| 53 | + return -1; |
| 54 | + } |
53 | 55 |
|
54 | | - struct utsname info; |
55 | | - if (uname(&info) != 0) { |
56 | | - return -1; |
57 | | - } |
| 56 | + struct utsname info; |
| 57 | + if (uname(&info) != 0) { |
| 58 | + return -1; |
| 59 | + } |
58 | 60 |
|
59 | | - memset(name, 0, sizeof(struct _ocre_posix_utsname)); |
| 61 | + memset(name, 0, sizeof(struct _ocre_posix_utsname)); |
60 | 62 |
|
61 | | - snprintf(name->sysname, OCRE_API_POSIX_BUF_SIZE, "%s (%s)", OCRE_SYSTEM_NAME, info.sysname); |
62 | | - snprintf(name->release, OCRE_API_POSIX_BUF_SIZE, "%s (%s)", APP_VERSION_STRING, info.release); |
63 | | - snprintf(name->version, OCRE_API_POSIX_BUF_SIZE, "%s", info.version); |
| 63 | + snprintf(name->sysname, OCRE_API_POSIX_BUF_SIZE, "%s (%s)", OCRE_SYSTEM_NAME, info.sysname); |
| 64 | + snprintf(name->release, OCRE_API_POSIX_BUF_SIZE, "%s (%s)", APP_VERSION_STRING, info.release); |
| 65 | + snprintf(name->version, OCRE_API_POSIX_BUF_SIZE, "%s", info.version); |
64 | 66 |
|
65 | 67 | #ifdef CONFIG_ARM |
66 | 68 | #ifdef CONFIG_CPU_CORTEX_M0 |
67 | | - strlcat(name->machine, "ARM Cortex-M0", OCRE_API_POSIX_BUF_SIZE); |
| 69 | + strlcat(name->machine, "ARM Cortex-M0", OCRE_API_POSIX_BUF_SIZE); |
68 | 70 | #elif CONFIG_CPU_CORTEX_M3 |
69 | | - strlcat(name->machine, "ARM Cortex-M3", OCRE_API_POSIX_BUF_SIZE); |
| 71 | + strlcat(name->machine, "ARM Cortex-M3", OCRE_API_POSIX_BUF_SIZE); |
70 | 72 | #elif CONFIG_CPU_CORTEX_M4 |
71 | | - strlcat(name->machine, "ARM Cortex-M4", OCRE_API_POSIX_BUF_SIZE); |
| 73 | + strlcat(name->machine, "ARM Cortex-M4", OCRE_API_POSIX_BUF_SIZE); |
72 | 74 | #elif CONFIG_CPU_CORTEX_M7 |
73 | | - strlcat(name->machine, "ARM Cortex-M7", OCRE_API_POSIX_BUF_SIZE); |
| 75 | + strlcat(name->machine, "ARM Cortex-M7", OCRE_API_POSIX_BUF_SIZE); |
74 | 76 | #elif CONFIG_CPU_CORTEX_M33 |
75 | | - strlcat(name->machine, "ARM Cortex-M33", OCRE_API_POSIX_BUF_SIZE); |
| 77 | + strlcat(name->machine, "ARM Cortex-M33", OCRE_API_POSIX_BUF_SIZE); |
76 | 78 | #elif CONFIG_CPU_CORTEX_M23 |
77 | | - strlcat(name->machine, "ARM Cortex-M23", OCRE_API_POSIX_BUF_SIZE); |
| 79 | + strlcat(name->machine, "ARM Cortex-M23", OCRE_API_POSIX_BUF_SIZE); |
78 | 80 | #elif CONFIG_CPU_CORTEX_M55 |
79 | | - strlcat(name->machine, "ARM Cortex-M55", OCRE_API_POSIX_BUF_SIZE); |
| 81 | + strlcat(name->machine, "ARM Cortex-M55", OCRE_API_POSIX_BUF_SIZE); |
80 | 82 | #endif |
81 | 83 | #else |
82 | | - strlcat(name->machine, info.machine, OCRE_API_POSIX_BUF_SIZE); |
| 84 | + strlcat(name->machine, info.machine, OCRE_API_POSIX_BUF_SIZE); |
83 | 85 | #endif |
84 | 86 |
|
85 | | - strlcat(name->nodename, info.nodename, OCRE_API_POSIX_BUF_SIZE); |
| 87 | + strlcat(name->nodename, info.nodename, OCRE_API_POSIX_BUF_SIZE); |
86 | 88 |
|
87 | | - return 0; |
| 89 | + return 0; |
88 | 90 | } |
89 | 91 |
|
90 | | -int ocre_sleep(wasm_exec_env_t exec_env, int milliseconds) { |
91 | | - core_sleep_ms(milliseconds); |
92 | | - return 0; |
| 92 | +int ocre_sleep(wasm_exec_env_t exec_env, int milliseconds) |
| 93 | +{ |
| 94 | + core_sleep_ms(milliseconds); |
| 95 | + return 0; |
93 | 96 | } |
94 | 97 |
|
95 | 98 | // Ocre Runtime API |
96 | 99 | NativeSymbol ocre_api_table[] = { |
97 | | - {"uname", _ocre_posix_uname, "(*)i", NULL}, |
98 | | - {"ocre_sleep", ocre_sleep, "(i)i", NULL}, |
99 | | -#if defined(CONFIG_OCRE_TIMER) || defined(CONFIG_OCRE_GPIO) || defined(CONFIG_OCRE_SENSORS) || defined(CONFIG_OCRE_CONTAINER_MESSAGING) |
100 | | - {"ocre_get_event", ocre_get_event, "(iiiiii)i", NULL}, |
101 | | - {"ocre_register_dispatcher", ocre_register_dispatcher, "(i$)i", NULL}, |
102 | | -#endif |
| 100 | + {"uname", _ocre_posix_uname, "(*)i", NULL}, |
| 101 | + {"ocre_sleep", ocre_sleep, "(i)i", NULL}, |
| 102 | +#if defined(CONFIG_OCRE_TIMER) || defined(CONFIG_OCRE_GPIO) || defined(CONFIG_OCRE_SENSORS) || \ |
| 103 | + defined(CONFIG_OCRE_CONTAINER_MESSAGING) |
| 104 | + {"ocre_get_event", ocre_get_event, "(iiiiii)i", NULL}, |
| 105 | + {"ocre_register_dispatcher", ocre_register_dispatcher, "(i$)i", NULL}, |
| 106 | +#endif |
103 | 107 | // Container Messaging API |
104 | 108 | #ifdef CONFIG_OCRE_CONTAINER_MESSAGING |
105 | | - {"ocre_publish_message", ocre_messaging_publish, "(***i)i", NULL}, |
106 | | - {"ocre_subscribe_message", ocre_messaging_subscribe, "(*)i", NULL}, |
107 | | - {"ocre_messaging_free_module_event_data", ocre_messaging_free_module_event_data, "(iii)i", NULL}, |
| 109 | + {"ocre_publish_message", ocre_messaging_publish, "(***i)i", NULL}, |
| 110 | + {"ocre_subscribe_message", ocre_messaging_subscribe, "(*)i", NULL}, |
| 111 | + {"ocre_messaging_free_module_event_data", ocre_messaging_free_module_event_data, "(iii)i", NULL}, |
108 | 112 | #endif |
109 | 113 | // Sensor API |
110 | 114 | #ifdef CONFIG_OCRE_SENSORS |
111 | | - {"ocre_sensors_init", ocre_sensors_init, "()i", NULL}, |
112 | | - {"ocre_sensors_discover", ocre_sensors_discover, "()i", NULL}, |
113 | | - {"ocre_sensors_open", ocre_sensors_open, "(i)i", NULL}, |
114 | | - {"ocre_sensors_get_handle", ocre_sensors_get_handle, "(i)i", NULL}, |
115 | | - {"ocre_sensors_get_channel_count", ocre_sensors_get_channel_count, "(i)i", NULL}, |
116 | | - {"ocre_sensors_get_channel_type", ocre_sensors_get_channel_type, "(ii)i", NULL}, |
117 | | - {"ocre_sensors_read", ocre_sensors_read, "(ii)F", NULL}, |
118 | | - {"ocre_sensors_open_by_name", ocre_sensors_open_by_name, "($)i", NULL}, |
119 | | - {"ocre_sensors_get_handle_by_name", ocre_sensors_get_handle_by_name, "($)i", NULL}, |
120 | | - {"ocre_sensors_get_channel_count_by_name", ocre_sensors_get_channel_count_by_name, "($)i", NULL}, |
121 | | - {"ocre_sensors_get_channel_type_by_name", ocre_sensors_get_channel_type_by_name, "($i)i", NULL}, |
122 | | - {"ocre_sensors_read_by_name", ocre_sensors_read_by_name, "($i)F", NULL}, |
123 | | - {"ocre_sensors_get_list", ocre_sensors_get_list, "($i)i", NULL}, |
| 115 | + {"ocre_sensors_init", ocre_sensors_init, "()i", NULL}, |
| 116 | + {"ocre_sensors_discover", ocre_sensors_discover, "()i", NULL}, |
| 117 | + {"ocre_sensors_open", ocre_sensors_open, "(i)i", NULL}, |
| 118 | + {"ocre_sensors_get_handle", ocre_sensors_get_handle, "(i)i", NULL}, |
| 119 | + {"ocre_sensors_get_channel_count", ocre_sensors_get_channel_count, "(i)i", NULL}, |
| 120 | + {"ocre_sensors_get_channel_type", ocre_sensors_get_channel_type, "(ii)i", NULL}, |
| 121 | + {"ocre_sensors_read", ocre_sensors_read, "(ii)F", NULL}, |
| 122 | + {"ocre_sensors_open_by_name", ocre_sensors_open_by_name, "($)i", NULL}, |
| 123 | + {"ocre_sensors_get_handle_by_name", ocre_sensors_get_handle_by_name, "($)i", NULL}, |
| 124 | + {"ocre_sensors_get_channel_count_by_name", ocre_sensors_get_channel_count_by_name, "($)i", NULL}, |
| 125 | + {"ocre_sensors_get_channel_type_by_name", ocre_sensors_get_channel_type_by_name, "($i)i", NULL}, |
| 126 | + {"ocre_sensors_read_by_name", ocre_sensors_read_by_name, "($i)F", NULL}, |
| 127 | + {"ocre_sensors_get_list", ocre_sensors_get_list, "($i)i", NULL}, |
124 | 128 | #endif |
125 | 129 | // Timer API |
126 | 130 | #ifdef CONFIG_OCRE_TIMER |
127 | | - {"ocre_timer_create", ocre_timer_create, "(i)i", NULL}, |
128 | | - {"ocre_timer_start", ocre_timer_start, "(iii)i", NULL}, |
129 | | - {"ocre_timer_stop", ocre_timer_stop, "(i)i", NULL}, |
130 | | - {"ocre_timer_delete", ocre_timer_delete, "(i)i", NULL}, |
131 | | - {"ocre_timer_get_remaining", ocre_timer_get_remaining, "(i)i", NULL}, |
| 131 | + {"ocre_timer_create", ocre_timer_create, "(i)i", NULL}, |
| 132 | + {"ocre_timer_start", ocre_timer_start, "(iii)i", NULL}, |
| 133 | + {"ocre_timer_stop", ocre_timer_stop, "(i)i", NULL}, |
| 134 | + {"ocre_timer_delete", ocre_timer_delete, "(i)i", NULL}, |
| 135 | + {"ocre_timer_get_remaining", ocre_timer_get_remaining, "(i)i", NULL}, |
132 | 136 | #endif |
133 | 137 | // GPIO API |
134 | 138 | #ifdef CONFIG_OCRE_GPIO |
135 | | - {"ocre_gpio_init", ocre_gpio_wasm_init, "()i", NULL}, |
136 | | - {"ocre_gpio_configure", ocre_gpio_wasm_configure, "(iii)i", NULL}, |
137 | | - {"ocre_gpio_pin_set", ocre_gpio_wasm_set, "(iii)i", NULL}, |
138 | | - {"ocre_gpio_pin_get", ocre_gpio_wasm_get, "(ii)i", NULL}, |
139 | | - {"ocre_gpio_pin_toggle", ocre_gpio_wasm_toggle, "(ii)i", NULL}, |
140 | | - {"ocre_gpio_register_callback", ocre_gpio_wasm_register_callback, "(ii)i", NULL}, |
141 | | - {"ocre_gpio_unregister_callback", ocre_gpio_wasm_unregister_callback, "(ii)i", NULL}, |
142 | | - |
143 | | - {"ocre_gpio_configure_by_name", ocre_gpio_wasm_configure_by_name, "($i)i", NULL}, |
144 | | - {"ocre_gpio_set_by_name", ocre_gpio_wasm_set_by_name, "($i)i", NULL}, |
145 | | - {"ocre_gpio_get_by_name", ocre_gpio_wasm_get_by_name, "($)i", NULL}, |
146 | | - {"ocre_gpio_toggle_by_name", ocre_gpio_wasm_toggle_by_name, "($)i", NULL}, |
147 | | - {"ocre_gpio_register_callback_by_name", ocre_gpio_wasm_register_callback_by_name, "($)i", NULL}, |
148 | | - {"ocre_gpio_unregister_callback_by_name", ocre_gpio_wasm_unregister_callback_by_name, "($)i", NULL}, |
| 139 | + {"ocre_gpio_init", ocre_gpio_wasm_init, "()i", NULL}, |
| 140 | + {"ocre_gpio_configure", ocre_gpio_wasm_configure, "(iii)i", NULL}, |
| 141 | + {"ocre_gpio_pin_set", ocre_gpio_wasm_set, "(iii)i", NULL}, |
| 142 | + {"ocre_gpio_pin_get", ocre_gpio_wasm_get, "(ii)i", NULL}, |
| 143 | + {"ocre_gpio_pin_toggle", ocre_gpio_wasm_toggle, "(ii)i", NULL}, |
| 144 | + {"ocre_gpio_register_callback", ocre_gpio_wasm_register_callback, "(ii)i", NULL}, |
| 145 | + {"ocre_gpio_unregister_callback", ocre_gpio_wasm_unregister_callback, "(ii)i", NULL}, |
| 146 | + |
| 147 | + {"ocre_gpio_configure_by_name", ocre_gpio_wasm_configure_by_name, "($i)i", NULL}, |
| 148 | + {"ocre_gpio_set_by_name", ocre_gpio_wasm_set_by_name, "($i)i", NULL}, |
| 149 | + {"ocre_gpio_get_by_name", ocre_gpio_wasm_get_by_name, "($)i", NULL}, |
| 150 | + {"ocre_gpio_toggle_by_name", ocre_gpio_wasm_toggle_by_name, "($)i", NULL}, |
| 151 | + {"ocre_gpio_register_callback_by_name", ocre_gpio_wasm_register_callback_by_name, "($)i", NULL}, |
| 152 | + {"ocre_gpio_unregister_callback_by_name", ocre_gpio_wasm_unregister_callback_by_name, "($)i", NULL}, |
149 | 153 | #endif |
150 | 154 | }; |
151 | 155 |
|
|
0 commit comments