Skip to content

Commit d590eab

Browse files
authored
Moved execution environment to top for most APIs, and removed... (#30)
* Moved execution environment to top for most APIs, and removed function from the GPIO documentation. * Removed mention of wasm_exec_env_t from the messaging docs
1 parent 8c02991 commit d590eab

6 files changed

Lines changed: 35 additions & 94 deletions

File tree

docs/reference/apis/container-api/gpio.md

Lines changed: 1 addition & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,6 @@ A function that will be called when a GPIO pin's state changes.
7979
typedef void (*ocre_gpio_callback_t)(int pin, ocre_gpio_pin_state_t state);
8080
```
8181
82-
### Execution Environment
83-
84-
All GPIO functions have an internal `wasm_exec_env_t` parameter that is used by the Ocre runtime. This parameter is NOT needed when calling these functions from within a container. Container applications should omit this parameter.
85-
8682
---
8783
8884
## Methods
@@ -231,28 +227,6 @@ int ocre_gpio_unregister_callback(int pin);
231227
| `0` | on success |
232228
| negative value | on error |
233229

234-
### Get Pin ID
235-
236-
Calculates a pin ID from port and pin numbers.
237-
238-
```c
239-
int get_pin_id(int port, int pin);
240-
```
241-
242-
**Parameters**:
243-
244-
| Name | Type | Description |
245-
| ------ | ------ | ----------- |
246-
| `port` | *int* | GPIO port number |
247-
| `pin` | *int* | Pin number within the port |
248-
249-
**Returns**:
250-
251-
| Value | Description |
252-
| ------ | ----------- |
253-
| positive value (pin ID) | on success |
254-
| `-1` | on error |
255-
256230
---
257231

258232
## Error Handling
@@ -380,52 +354,6 @@ int main() {
380354
}
381355
```
382356
383-
### Using Port and Pin Mapping
384-
385-
```c
386-
#include <stdio.h>
387-
#include "ocre_gpio.h"
388-
389-
#define GPIO_PORT_A 0
390-
#define GPIO_PIN_5 5
391-
392-
int main() {
393-
// Initialize GPIO subsystem
394-
if (ocre_gpio_init() != 0) {
395-
printf("Failed to initialize GPIO\n");
396-
return -1;
397-
}
398-
399-
// Calculate pin ID from port and pin
400-
int pin_id = get_pin_id(GPIO_PORT_A, GPIO_PIN_5);
401-
if (pin_id < 0) {
402-
printf("Invalid port or pin\n");
403-
return -1;
404-
}
405-
406-
// Configure the pin as output
407-
ocre_gpio_config_t config;
408-
config.pin = pin_id;
409-
config.direction = OCRE_GPIO_DIR_OUTPUT;
410-
411-
if (ocre_gpio_configure(&config) != 0) {
412-
printf("Failed to configure GPIO pin\n");
413-
return -1;
414-
}
415-
416-
// Toggle the pin 10 times
417-
for (int i = 0; i < 10; i++) {
418-
ocre_gpio_pin_toggle(pin_id);
419-
printf("Pin toggled\n");
420-
421-
// Delay (implementation-specific)
422-
for (volatile int j = 0; j < 500000; j++);
423-
}
424-
425-
return 0;
426-
}
427-
```
428-
429357
---
430358
431359
## Reference
@@ -438,5 +366,4 @@ int main() {
438366
| [`ocre_gpio_pin_get`](#get-gpio-pin-state) | Gets a GPIO pin state | `pin`: GPIO pin number | `OCRE_GPIO_PIN_SET`/`OCRE_GPIO_PIN_RESET` or negative error code | `ENODEV`, `EINVAL` |
439367
| [`ocre_gpio_pin_toggle`](#toggle-gpio-pin) | Toggles a GPIO pin state | `pin`: GPIO pin number | `0` on success, negative on error | `ENODEV`, `EINVAL` |
440368
| [`ocre_gpio_register_callback`](#register-gpio-callback) | Registers callback for GPIO changes | `pin`: GPIO pin number<br/>`callback`: Callback function | `0` on success, negative on error | `ENODEV`, `EINVAL` |
441-
| [`ocre_gpio_unregister_callback`](#unregister-gpio-callback) | Removes GPIO callback | `pin`: GPIO pin number | `0` on success, negative on error | `ENODEV`, `EINVAL` |
442-
| [`get_pin_id`](#get-pin-id) | Calculates pin ID from port and pin | `port`: GPIO port number<br/>`pin`: Pin number within port | Pin ID or `-1` on invalid Pin | N/A |
369+
| [`ocre_gpio_unregister_callback`](#unregister-gpio-callback) | Removes GPIO callback | `pin`: GPIO pin number | `0` on success, negative on error | `ENODEV`, `EINVAL` |

docs/reference/apis/container-api/index.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,25 @@ Below are the core APIs available for Ocre containers. Each API includes detaile
1616

1717
### Communication
1818

19+
Communication APIs enable containers to interact with each other and with external systems.
20+
1921
| API | Description|
2022
|-----|-------------|
2123
| **[Inter-Container Messaging](inter-container-messaging)** | Enable secure communication between containers |
2224

23-
### System Interaction
25+
## Hardware
26+
27+
Hardware APIs provide direct access to physical devices and sensors attached to the system.
2428

2529
| API | Description |
2630
|-----|-------------|
2731
| **[GPIO](gpio)** | Control digital pins for input/output operations with hardware peripherals and external components |
2832
| **[Sensors](sensors)** | Interface with hardware sensors for environmental and motion data |
33+
34+
### Time Management
35+
36+
Time management APIs enable precise timing operations for container applications.
37+
38+
| API | Description |
39+
|-----|-------------|
2940
| **[Timers](timers)** | Create and manage timed events with millisecond precision |

docs/reference/apis/container-api/inter-container-messaging.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ Navigate this comprehensive API reference using the links below.
3636

3737
---
3838

39+
40+
## Execution Environment
41+
42+
All messaging functions have an internal `wasm_exec_env_t` parameter that is used by the Ocre runtime. This parameter is NOT needed when calling these functions from within a container. Container applications should omit this parameter.
43+
44+
---
45+
3946
## Types
4047

4148
### Message Structure
@@ -72,7 +79,7 @@ void ocre_msg_system_init(void);
7279
Publishes a message to the specified topic.
7380
7481
```c
75-
int ocre_publish_message(wasm_exec_env_t exec_env, char *topic, char *content_type, void *payload, int payload_len);
82+
int ocre_publish_message(char *topic, char *content_type, void *payload, int payload_len);
7683
```
7784

7885
Fails if the messaging system is not initialized, if `topic`, `content_type`, or `payload` is `NULL`/empty, if `payload_len` is `0`, or if the message queue is full.
@@ -81,7 +88,6 @@ Fails if the messaging system is not initialized, if `topic`, `content_type`, or
8188

8289
| Name | Type | Description |
8390
| ---- | ---- | ----------- |
84-
| `exec_env` | *wasm_exec_env_t* | Currently unused but required for compatibility with WebAssembly runtime |
8591
| `topic` | *char* | Topic name to publish the message to |
8692
| `content_type` | *char* | Content type of the message (`MIME` type recommended) |
8793
| `payload` | *void* | Pointer to the **message payload buffer** |
@@ -99,14 +105,13 @@ Fails if the messaging system is not initialized, if `topic`, `content_type`, or
99105
Subscribes to a topic to receive messages.
100106

101107
```c
102-
int ocre_subscribe_message(wasm_exec_env_t exec_env, char *topic, char *handler_name);
108+
int ocre_subscribe_message(char *topic, char *handler_name);
103109
```
104110
105111
**Parameters**:
106112
107113
| Name | Type | Description |
108114
| ---- | ---- | ----------- |
109-
| `exec_env` | *wasm_exec_env_t* | WebAssembly execution environment used to locate the callback function in the WebAssembly module. |
110115
| `topic` | *char* | Topic name to subscribe to |
111116
| `handler_name` | *char* | Name of the callback function to be called when a message is received |
112117
@@ -144,11 +149,6 @@ The following example demonstrates how to use the Inter-Container Messaging API
144149
- The **[Publisher Container](#publisher-container)** sends JSON-formatted temperature readings to the `sensors/temperature` topic every 500 milliseconds.
145150
- The **[Subscriber Container](#subscriber-container)** subscribes to this topic and processes incoming messages.
146151
147-
**Notes**:
148-
- The `wasm_exec_env_t` parameter is required for WebAssembly function signatures but may be unused in some cases (e.g., publishing). In real applications, it is provided by the WASM runtime.
149-
- Use `ocre_sleep` instead of POSIX `sleep`.
150-
- The messaging system automatically handles memory allocation and deallocation for messages passed to callback functions.
151-
152152
---
153153
154154
### Publisher Container
@@ -218,7 +218,7 @@ int main(void) {
218218
// Message handler function (exported for WASM)
219219
__attribute__((export_name("temperature_handler")))
220220

221-
void temperature_handler(wasm_exec_env_t exec_env, ocre_msg_t *msg) {
221+
void temperature_handler(ocre_msg_t *msg) {
222222
printf("Received message on topic: %s\n", msg->topic);
223223
printf("Content type: %s\n", msg->content_type);
224224
printf("Payload: %s\n", (char *)msg->payload);

docs/reference/apis/container-api/sensors.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ Navigate this comprehensive API reference using the links below.
3535

3636
---
3737

38+
## Execution Environment
39+
40+
All sensor functions have an internal `wasm_exec_env_t` parameter that is used by the Ocre runtime. This parameter is NOT needed when calling these functions from within a container. Container applications should omit this parameter.
41+
42+
---
43+
3844
## Types
3945

4046
### Sensor Callback Function
@@ -127,10 +133,6 @@ typedef enum {
127133
} ocre_sensors_status_t;
128134
```
129135

130-
### Execution Environment
131-
132-
All sensor functions have an internal `wasm_exec_env_t` parameter that is used by the Ocre runtime. This parameter is NOT needed when calling these functions from within a container. Container applications should omit this parameter.
133-
134136
---
135137

136138
## Methods

docs/reference/apis/container-api/timers.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ Navigate this comprehensive API reference using the links below.
3535

3636
---
3737

38+
## Execution Environment
39+
40+
All timer functions have an internal `wasm_exec_env_t` parameter that is used by the Ocre runtime. This parameter is NOT needed when calling these functions from within a container. Container applications should omit this parameter.
41+
42+
---
43+
3844
## Types
3945

4046
### Timer Callback Function
@@ -53,10 +59,6 @@ typedef int ocre_timer_t;
5359

5460
Each timer is assigned a unique ID between `1` and `MAX_TIMERS`, which is used to reference the timer in all operations after creation. The timer handle is an opaque identifier that abstracts the underlying timer implementation.
5561

56-
### Execution Environment
57-
58-
All timer functions have an internal `wasm_exec_env_t` parameter that is used by the Ocre runtime. This parameter is NOT needed when calling these functions from within a container. Container applications should omit this parameter.
59-
6062
---
6163

6264
## Methods

docs/reference/apis/index.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ Ocre provides *two* primary categories of APIs:
1919

2020
2. **[Container Runtime API:](../apis/runtime-api)** The API for managing the Ocre container runtime environment itself, including container lifecycle operations. The Runtime API is intended for system implementors and integrators looking to incorporate the Ocre runtime into their own solutions.
2121

22-
2322
---
2423

2524
## Next Steps

0 commit comments

Comments
 (0)