Skip to content
Merged
28 changes: 22 additions & 6 deletions doc/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,13 @@ There must be a function to check for syscall driver existence.
Signature:

```
bool libtock_[name]_exists(void);
bool libtock_[name]_driver_exists(void);
```

Example:

```c
bool libtock_[name]_exists(void) {
bool libtock_[name]_driver_exists(void) {
return driver_exists(DRIVER_NUM_[NAME]);
}
```
Expand All @@ -202,7 +202,6 @@ The `[name].h` header file must look like:
#pragma once

#include "../tock.h"
#include "syscalls/[name]_syscalls.h"

#ifdef __cplusplus
extern "C" {
Expand All @@ -215,7 +214,8 @@ extern "C" {
#endif
```

The `[name].h` header file must include the syscalls header.
The `[name].h` header file must NOT include the syscalls header. Applications
wanting to use the syscalls directly must include the syscalls header.

### Defining a Callback for Asynchronous Operations

Expand All @@ -236,6 +236,24 @@ they should have the last argument be a callback function pointer.
returncode_t libtock_[name]_[desc](<arguments>, libtock_[name]_callback_[desc] cb);
```

#### Exists

There must be a function to check for syscall driver existence.

Signature:

```
bool libtock_[name]_exists(void);
```

Example:

```c
bool libtock_[name]_exists(void) {
return libtock_[name]_driver_exists();
}
```

### Example:


Expand Down Expand Up @@ -309,7 +327,6 @@ file is used in a C++ app.
#pragma once

#include <libtock/tock.h>
#include <libtock/[category]/syscalls/[name]_syscalls.h>

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -379,7 +396,6 @@ The libtock-sync `[name].h` header file must look like:
```c
#pragma once

#include "syscalls/temperature_syscalls.h"
#include <libtock/tock.h>

#ifdef __cplusplus
Expand Down
1 change: 1 addition & 0 deletions examples/lvgl/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <libtock-sync/display/screen.h>
#include <libtock-sync/services/alarm.h>
#include <libtock/peripherals/syscalls/alarm_syscalls.h>

#include "lvgl_driver.h"

Expand Down
18 changes: 9 additions & 9 deletions examples/sensors/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ int main(void) {
printf("[Sensors] All available sensors on the platform will be sampled.\n");

/* *INDENT-OFF* */
light = libtock_ambient_light_exists();
temperature = libtock_temperature_exists();
humidity = libtock_humidity_exists();
ninedof = libtock_ninedof_exists();
proximity = libtock_proximity_exists();
sound_pressure = libtock_sound_pressure_exists();
moisture = libtock_moisture_exists();
rainfall = libtock_rainfall_exists();
light = libtocksync_ambient_light_exists();
temperature = libtocksync_temperature_exists();
humidity = libtocksync_humidity_exists();
ninedof = libtocksync_ninedof_exists();
proximity = libtocksync_proximity_exists();
sound_pressure = libtocksync_sound_pressure_exists();
moisture = libtocksync_moisture_exists();
rainfall = libtocksync_rainfall_exists();
/* *INDENT-ON* */

if (ninedof) {
Expand All @@ -103,7 +103,7 @@ int main(void) {
/* *INDENT-ON* */

if (sound_pressure) {
libtock_sound_pressure_command_enable();
libtocksync_sound_pressure_enable();
}

// Setup periodic alarm to sample the sensors.
Expand Down
6 changes: 3 additions & 3 deletions examples/services/ble-env-sense/test-with-sensors/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ static void do_sensing_cb(__attribute__ ((unused)) uint32_t now,
int temp = 0;
int humi = 0;

if (driver_exists(DRIVER_NUM_AMBIENT_LIGHT)) {
if (libtocksync_ambient_light_exists()) {
libtocksync_ambient_light_read_intensity(&light);

update->type = SENSOR_IRRADIANCE;
Expand All @@ -55,7 +55,7 @@ static void do_sensing_cb(__attribute__ ((unused)) uint32_t now,
yield_for(&_ipc_done);
}

if (driver_exists(DRIVER_NUM_TEMPERATURE)) {
if (libtocksync_temperature_exists()) {
libtocksync_temperature_read(&temp);

update->type = SENSOR_TEMPERATURE;
Expand All @@ -65,7 +65,7 @@ static void do_sensing_cb(__attribute__ ((unused)) uint32_t now,
yield_for(&_ipc_done);
}

if (driver_exists(DRIVER_NUM_HUMIDITY)) {
if (libtocksync_humidity_exists()) {
libtocksync_humidity_read(&humi);

update->type = SENSOR_HUMIDITY;
Expand Down
4 changes: 2 additions & 2 deletions examples/servo/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
#include <stdlib.h>

#include <libtock-sync/services/alarm.h>
#include <libtock/interface/syscalls/servo_syscalls.h>
#include <libtock/tock.h>

#include "../../libtock/interface/syscalls/servo_syscalls.h"

int main(void) {
// Checks if the driver exists and, if not, returns -1.
if (!libtock_servo_exists()) {
if (!libtock_servo_driver_exists()) {
printf("There is no available servo\n");
return -1;
}
Expand Down
1 change: 1 addition & 0 deletions examples/tests/adc/adc/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <libtock-sync/peripherals/adc.h>
#include <libtock-sync/services/alarm.h>
#include <libtock/interface/console.h>
#include <libtock/peripherals/syscalls/adc_syscalls.h>
#include <libtock/tock.h>

int reference_voltage;
Expand Down
1 change: 1 addition & 0 deletions examples/tests/aes/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <string.h>

#include <libtock/crypto/aes.h>
#include <libtock/crypto/syscalls/aes_syscalls.h>

#define KEY_LEN 16
#define IV_LEN 16
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <stdlib.h>

#include <libtock-sync/services/alarm.h>
#include <libtock/peripherals/syscalls/alarm_syscalls.h>

static void event_cb(uint32_t now, uint32_t expiration, void* ud) {
int i = (int)ud;
Expand Down
1 change: 1 addition & 0 deletions examples/tests/analog_comparator/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <libtock-sync/services/alarm.h>
#include <libtock/peripherals/analog_comparator.h>
#include <libtock/peripherals/syscalls/analog_comparator_syscalls.h>
#include <libtock/tock.h>

static int callback_channel;
Expand Down
1 change: 1 addition & 0 deletions examples/tests/callback_remove_test01/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <stdlib.h>

#include <libtock-sync/services/alarm.h>
#include <libtock/peripherals/syscalls/alarm_syscalls.h>

volatile int a = 0;
int b = 0;
Expand Down
2 changes: 1 addition & 1 deletion examples/tests/hmac/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ int main(void) {
returncode_t ret;
printf("[TEST] HMAC\r\n");

if (!libtock_hmac_exists()) {
if (!libtocksync_hmac_exists()) {
printf("No HMAC driver.\n");
return -2;
}
Expand Down
1 change: 1 addition & 0 deletions examples/tests/i2c/i2c_master_slave_ping_pong/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <libtock-sync/services/alarm.h>
#include <libtock/interface/button.h>
#include <libtock/interface/syscalls/button_syscalls.h>
#include <libtock/peripherals/i2c_master_slave.h>

#define BUF_SIZE 16
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <stdlib.h>

#include <libtock-sync/storage/isolated_nonvolatile_storage.h>
#include <libtock/storage/syscalls/isolated_nonvolatile_storage_syscalls.h>



Expand Down
1 change: 1 addition & 0 deletions examples/tests/kv/kv_system/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <libtock/interface/console.h>
#include <libtock/storage/kv.h>
#include <libtock/storage/syscalls/kv_syscalls.h>

#define KEY_LEN 16
#define DATA_LEN 32
Expand Down
4 changes: 2 additions & 2 deletions examples/tests/lr1110/lorawan/main_lorawan.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,8 @@ static void on_modem_alarm(void) {

printf("[Sensors] Sampling Temperature and Humidity sensors once.\n");

bool temperature_available = driver_exists(DRIVER_NUM_TEMPERATURE);
bool humidity_available = driver_exists(DRIVER_NUM_HUMIDITY);
bool temperature_available = libtocksync_temperature_exists();
bool humidity_available = libtocksync_temperature_exists();
int temp = 0;
int humi = 0;
if (temperature_available) {
Expand Down
2 changes: 1 addition & 1 deletion examples/tests/microbit_v2/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ int main(void) {
printf("Set up button callbacks!\n");

// Enable sound pressure sensor
check_err(libtock_sound_pressure_command_enable(), "libtock_sound_pressure_command_enable");
check_err(libtock_sound_pressure_enable(), "libtock_sound_pressure_command_enable");
printf("Enabled sound pressure!\n");

// Setup P8, P9, P16
Expand Down
2 changes: 1 addition & 1 deletion examples/tests/temperature/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
int main(void) {
returncode_t ret;

if (!libtock_temperature_exists()) {
if (!libtocksync_temperature_exists()) {
printf("[Temperature] No temperature sensor found.\n");
exit(-1);
}
Expand Down
2 changes: 2 additions & 0 deletions examples/tests/udp/udp_rx/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <libtock-sync/services/alarm.h>
#include <libtock/interface/led.h>
#include <libtock/net/ieee802154.h>
#include <libtock/net/syscalls/ieee802154_syscalls.h>
#include <libtock/net/syscalls/udp_syscalls.h>
#include <libtock/net/udp.h>

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ static uint16_t process_menu_get_item_count(void* data) {
UNUSED(data);

uint32_t count;
libtock_process_info_command_get_process_count(&count);
libtock_process_info_get_process_count(&count);
return count + 1; // +1 for back
}

Expand Down
1 change: 1 addition & 0 deletions examples/tutorials/hotp/hotp_milestone_one/step0.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <libtock-sync/interface/usb_keyboard_hid.h>
#include <libtock/crypto/hmac.h>
#include <libtock/crypto/syscalls/hmac_syscalls.h>
#include <libtock/interface/button.h>
#include <libtock/interface/led.h>

Expand Down
1 change: 1 addition & 0 deletions examples/tutorials/hotp/hotp_starter/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <libtock-sync/interface/usb_keyboard_hid.h>
#include <libtock-sync/services/alarm.h>
#include <libtock/crypto/hmac.h>
#include <libtock/crypto/syscalls/hmac_syscalls.h>
#include <libtock/interface/button.h>
#include <libtock/interface/console.h>
#include <libtock/interface/led.h>
Expand Down
1 change: 1 addition & 0 deletions examples/unit_tests/nrf52840dk-test/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <libtock-sync/services/unit_test.h>
#include <libtock/interface/button.h>
#include <libtock/interface/led.h>
#include <libtock/interface/syscalls/button_syscalls.h>
#include <libtock/peripherals/gpio.h>


Expand Down
5 changes: 5 additions & 0 deletions libtock-sync/crypto/hmac.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#include <libtock/crypto/syscalls/hmac_syscalls.h>
#include <libtock/defer.h>

#include "hmac.h"

bool libtocksync_hmac_exists(void) {
return libtock_hmac_driver_exists();
}

returncode_t libtocksync_hmac_simple(libtock_hmac_algorithm_t hmac_type,
uint8_t* key_buffer, uint32_t key_length,
uint8_t* input_buffer, uint32_t input_length,
Expand Down
3 changes: 3 additions & 0 deletions libtock-sync/crypto/hmac.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
extern "C" {
#endif


bool libtocksync_hmac_exists(void);

// Compute an HMAC on the given buffer.
returncode_t libtocksync_hmac_simple(libtock_hmac_algorithm_t hmac_type,
uint8_t* key_buffer, uint32_t key_length,
Expand Down
6 changes: 6 additions & 0 deletions libtock-sync/crypto/sha.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <libtock/crypto/syscalls/sha_syscalls.h>

#include "sha.h"

struct sha_data {
Expand All @@ -12,6 +14,10 @@ static void sha_cb_hash(returncode_t ret) {
result.ret = ret;
}

bool libtocksync_sha_exists(void) {
return libtock_sha_driver_exists();
}

returncode_t libtocksync_sha_simple_hash(libtock_sha_algorithm_t hash_type,
uint8_t* input_buffer, uint32_t input_length,
uint8_t* hash_buffer, uint32_t hash_length) {
Expand Down
3 changes: 3 additions & 0 deletions libtock-sync/crypto/sha.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
extern "C" {
#endif


bool libtocksync_sha_exists(void);

// Compute a SHA hash on the given buffer.
returncode_t libtocksync_sha_simple_hash(libtock_sha_algorithm_t hash_type,
uint8_t* input_buffer, uint32_t input_length,
Expand Down
6 changes: 6 additions & 0 deletions libtock-sync/display/screen.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <libtock/display/syscalls/screen_syscalls.h>

#include "screen.h"

struct screen_done {
Expand Down Expand Up @@ -37,6 +39,10 @@ static void screen_cb_rotation(returncode_t ret, libtock_screen_rotation_t rotat
result_rotation.fired = true;
}

bool libtocksync_screen_exists(void) {
return libtock_screen_driver_exists();
}

returncode_t libtocksync_screen_set_brightness(uint32_t brightness) {
returncode_t ret;

Expand Down
2 changes: 2 additions & 0 deletions libtock-sync/display/screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
extern "C" {
#endif

bool libtocksync_screen_exists(void);

// Set the screen brightness.
returncode_t libtocksync_screen_set_brightness(uint32_t brightness);

Expand Down
6 changes: 6 additions & 0 deletions libtock-sync/display/text_screen.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <libtock/display/syscalls/text_screen_syscalls.h>

#include "text_screen.h"

struct text_screen_data {
Expand Down Expand Up @@ -38,6 +40,10 @@ static returncode_t text_screen_op(returncode_t (*op)(void (*)(returncode_t))) {
return result.ret;
}

bool libtocksync_text_screen_exists(void) {
return libtock_text_screen_driver_exists();
}

returncode_t libtocksync_text_screen_display_on(void) {
return text_screen_op(libtock_text_screen_display_on);
}
Expand Down
Loading