Skip to content

Commit afd47f7

Browse files
authored
Merge pull request #536 from tock/statuscode-to-returncode
Improve how we use returncode_t vs statuscode_t.
2 parents 6395c5d + fbedf58 commit afd47f7

File tree

26 files changed

+103
-99
lines changed

26 files changed

+103
-99
lines changed

doc/guide.md

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -251,12 +251,12 @@ typedef void (*libtock_sensor_callback_reading)(returncode_t, int);
251251
Define a upcall function to be passed to the kernel:
252252
253253
```c
254-
static void sensor_temp_upcall(int ret,
254+
static void sensor_temp_upcall(int status,
255255
int val,
256256
__attribute__ ((unused)) int unused0,
257257
void* opaque) {
258258
libtock_sensor_callback_reading cb = (libtock_sensor_callback_reading) opaque;
259-
cb(ret, val);
259+
cb(tock_status_to_returncode((statuscode_t) status), val);
260260
}
261261
```
262262

@@ -349,12 +349,15 @@ the function.
349349

350350
```c
351351
returncode_t libtocksync_[name]_yield_wait_for(int* value) {
352-
yield_waitfor_return_t ret;
353-
ret = yield_wait_for(DRIVER_NUM_[NAME], 0);
354-
if (ret.data0 != RETURNCODE_SUCCESS) return ret.data0;
352+
returncode_t ret;
353+
yield_waitfor_return_t ywf;
354+
355+
ywf = yield_wait_for(DRIVER_NUM_[NAME], 0);
356+
ret = tock_status_to_returncode(ywf.data0);
357+
if (ret != RETURNCODE_SUCCESS) return ret;
355358

356-
*value = (int) ret.data1;
357-
return RETURNCODE_SUCCESS;
359+
*value = (int) ywf.data1;
360+
return ret;
358361
}
359362
```
360363

@@ -400,13 +403,13 @@ space for the sync operation:
400403
#include "syscalls/temperature_syscalls.h"
401404

402405
returncode_t libtocksync_sensor_read(int* val) {
403-
returncode_t err;
406+
returncode_t ret;
404407

405-
err = libtock_sensor_command_read();
406-
if (err != RETURNCODE_SUCCESS) return err;
408+
ret = libtock_sensor_command_read();
409+
if (ret != RETURNCODE_SUCCESS) return ret;
407410

408411
// Wait for the operation to finish.
409-
err = libtock_temperature_yield_wait_for(val);
410-
return err;
412+
ret = libtock_temperature_yield_wait_for(val);
413+
return ret;
411414
}
412415
```

examples/lvgl/lvgl_driver.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ static void screen_lvgl_driver(lv_display_t* disp, const lv_area_t* area,
3232
lv_display_flush_ready(disp); /* Indicate you are ready with the flushing*/
3333
}
3434

35-
static void touch_event(int status, uint16_t x, uint16_t y) {
35+
static void touch_event(libtock_touch_status_t status, uint16_t x, uint16_t y) {
3636
touch_status = status;
3737
touch_x = x;
3838
touch_y = y;

examples/tests/touch/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
libtock_touch_event_t* multi_touch_buffer;
99

10-
static void touch_event(int status, uint16_t x, uint16_t y) {
10+
static void touch_event(libtock_touch_status_t status, uint16_t x, uint16_t y) {
1111
switch (status) {
1212
case LIBTOCK_TOUCH_STATUS_PRESSED: {
1313
printf("pressed ");

examples/tests/udp/udp_rx/main.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,9 @@ void print_ipv6(ipv6_addr_t* ipv6_addr) {
3030
printf("%02x%02x", ipv6_addr->addr[14], ipv6_addr->addr[15]);
3131
}
3232

33-
static void callback(statuscode_t status,
33+
static void callback(returncode_t ret,
3434
int payload_len) {
3535

36-
returncode_t ret = tock_status_to_returncode(status);
3736
if (ret != RETURNCODE_SUCCESS) {
3837
printf("Error in receiving packet: %d\n", ret);
3938
return;

examples/tests/udp/udp_virt_rx_tests/app1/main.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@ void print_ipv6(ipv6_addr_t* ipv6_addr) {
2828
printf("%02x%02x", ipv6_addr->addr[14], ipv6_addr->addr[15]);
2929
}
3030

31-
static void callback(statuscode_t status,
31+
static void callback(returncode_t ret,
3232
int payload_len) {
3333

34-
returncode_t ret = tock_status_to_returncode(status);
3534
if (ret != RETURNCODE_SUCCESS) {
3635
printf("Error in receiving packet: %d\n", ret);
3736
return;

examples/tests/udp/udp_virt_rx_tests/app2/main.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@ void print_ipv6(ipv6_addr_t* ipv6_addr) {
2828
printf("%02x%02x", ipv6_addr->addr[14], ipv6_addr->addr[15]);
2929
}
3030

31-
static void callback(statuscode_t status,
31+
static void callback(returncode_t ret,
3232
int payload_len) {
3333

34-
returncode_t ret = tock_status_to_returncode(status);
3534
if (ret != RETURNCODE_SUCCESS) {
3635
printf("Error in receiving packet: %d\n", ret);
3736
return;

libopenthread/platform/radio.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,22 @@ static otRadioFrame ackFrame_radio = {
3030
static struct pending_tx_done_callback {
3131
bool flag;
3232
bool acked;
33-
statuscode_t status;
34-
} pending_tx_done_callback = {false, false, TOCK_STATUSCODE_FAIL};
33+
returncode_t ret;
34+
} pending_tx_done_callback = {false, false, RETURNCODE_FAIL};
3535

36-
static void tx_done_callback(statuscode_t status, bool acked) {
36+
static void tx_done_callback(returncode_t ret, bool acked) {
3737
pending_tx_done_callback.flag = true;
3838
pending_tx_done_callback.acked = acked;
39-
pending_tx_done_callback.status = status;
39+
pending_tx_done_callback.ret = ret;
4040
}
4141

42-
bool pending_tx_done_callback_status(otRadioFrame *ackFrame, returncode_t *status, otRadioFrame *txFrame) {
42+
bool pending_tx_done_callback_status(otRadioFrame *ackFrame, returncode_t *ret, otRadioFrame *txFrame) {
4343
if (pending_tx_done_callback.flag) {
4444
*ackFrame = ackFrame_radio;
45-
*status = tock_status_to_returncode(pending_tx_done_callback.status);
45+
*ret = pending_tx_done_callback.ret;
4646
*txFrame = transmitFrame;
47-
}
48-
47+
}
48+
4949
return pending_tx_done_callback.flag;
5050
}
5151

libtock-sync/net/ieee802154.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ static struct ieee802154_receive_data receive_result = { .fired = false };
1616
struct ieee802154_send_data {
1717
bool fired;
1818
bool acked;
19-
statuscode_t status;
19+
returncode_t ret;
2020
};
2121

2222
static struct ieee802154_send_data send_result = { .fired = false };
@@ -29,16 +29,16 @@ static void ieee802154_receive_done_cb(int pan, int src_addr, int dest_addr) {
2929
receive_result.dest_addr = dest_addr;
3030
}
3131

32-
static void ieee802154_send_done_cb(statuscode_t status, bool acked) {
33-
send_result.fired = true;
34-
send_result.acked = acked;
35-
send_result.status = status;
32+
static void ieee802154_send_done_cb(returncode_t ret, bool acked) {
33+
send_result.fired = true;
34+
send_result.acked = acked;
35+
send_result.ret = ret;
3636
}
3737

38-
static void ieee802154_send_raw_done_cb(statuscode_t status, bool acked) {
39-
send_result_raw.fired = true;
40-
send_result_raw.acked = acked;
41-
send_result_raw.status = status;
38+
static void ieee802154_send_raw_done_cb(returncode_t ret, bool acked) {
39+
send_result_raw.fired = true;
40+
send_result_raw.acked = acked;
41+
send_result_raw.ret = ret;
4242
}
4343

4444
returncode_t libtocksync_ieee802154_send(uint16_t addr,
@@ -55,7 +55,7 @@ returncode_t libtocksync_ieee802154_send(uint16_t addr,
5555
// Wait for the frame to be sent
5656
yield_for(&send_result.fired);
5757

58-
return tock_status_to_returncode(send_result.status);
58+
return send_result.ret;
5959
}
6060

6161

@@ -69,7 +69,7 @@ returncode_t libtocksync_ieee802154_send_raw(
6969

7070
yield_for(&send_result_raw.fired);
7171

72-
return tock_status_to_returncode(send_result_raw.status);
72+
return send_result_raw.ret;
7373
}
7474

7575
returncode_t libtocksync_ieee802154_receive(const libtock_ieee802154_rxbuf* frame) {

libtock-sync/net/udp.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,26 @@
55
struct recv_data {
66
bool fired;
77
int val;
8-
statuscode_t status;
8+
returncode_t ret;
99
};
1010

1111
struct send_data {
1212
bool fired;
13-
statuscode_t status;
13+
returncode_t ret;
1414
};
1515

1616
static struct send_data send_sync_result = { .fired = false };
1717
static struct recv_data recv_sync_result = { .fired = false };
1818

19-
static void send_callback(statuscode_t ret) {
20-
send_sync_result.fired = true;
21-
send_sync_result.status = ret;
19+
static void send_callback(returncode_t ret) {
20+
send_sync_result.fired = true;
21+
send_sync_result.ret = ret;
2222
}
2323

24-
static void recv_callback(statuscode_t ret, int len) {
25-
recv_sync_result.val = len;
26-
recv_sync_result.fired = true;
27-
recv_sync_result.status = ret;
24+
static void recv_callback(returncode_t ret, int len) {
25+
recv_sync_result.val = len;
26+
recv_sync_result.fired = true;
27+
recv_sync_result.ret = ret;
2828
}
2929

3030
returncode_t libtocksync_udp_send(void* buf, size_t len,
@@ -36,7 +36,7 @@ returncode_t libtocksync_udp_send(void* buf, size_t len,
3636
if (ret != RETURNCODE_SUCCESS) return ret;
3737

3838
yield_for(&send_sync_result.fired);
39-
return tock_status_to_returncode(send_sync_result.status);
39+
return send_sync_result.ret;
4040
}
4141

4242
returncode_t libtocksync_udp_recv(void* buf, size_t len, size_t* received_len) {
@@ -49,5 +49,5 @@ returncode_t libtocksync_udp_recv(void* buf, size_t len, size_t* received_len) {
4949
yield_for(&recv_sync_result.fired);
5050

5151
*received_len = recv_sync_result.val;
52-
return tock_status_to_returncode(recv_sync_result.status);
52+
return recv_sync_result.ret;
5353
}

libtock/crypto/hmac.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ static void hmac_upcall(int ret,
44
__attribute__ ((unused)) int unused1,
55
__attribute__ ((unused)) int unused2, void* opaque) {
66
libtock_hmac_callback_hmac cb = (libtock_hmac_callback_hmac) opaque;
7-
cb((returncode_t) ret);
7+
cb(tock_status_to_returncode(ret));
88
}
99

1010

0 commit comments

Comments
 (0)