Skip to content

Commit d0b59ea

Browse files
committed
ywf: lora_phy
1 parent b1f222a commit d0b59ea

File tree

4 files changed

+46
-21
lines changed

4 files changed

+46
-21
lines changed

libtock-sync/net/lora_phy.c

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,39 @@
11
#include "lora_phy.h"
22

3-
struct lora_phy_spi_data {
4-
bool fired;
5-
returncode_t ret;
6-
};
7-
8-
static struct lora_phy_spi_data result = {.fired = false};
9-
10-
static void lora_phy_spi_cb(returncode_t ret) {
11-
result.fired = true;
12-
result.ret = ret;
13-
}
14-
153
returncode_t libtocksync_lora_phy_write(const uint8_t* write,
164
uint32_t len) {
17-
result.fired = false;
185
returncode_t ret;
196

20-
ret = libtock_lora_phy_write(write, len, lora_phy_spi_cb);
7+
ret = libtock_lora_phy_set_readonly_allow_master_write_buffer(buf, len);
218
if (ret != RETURNCODE_SUCCESS) return ret;
9+
defer { libtock_lora_phy_set_readonly_allow_master_write_buffer(NULL, 0);
10+
};
2211

23-
yield_for(&result.fired);
24-
return result.ret;
12+
ret = libtock_lora_phy_command_read_write(len);
13+
if (ret != RETURNCODE_SUCCESS) return ret;
14+
15+
ret = libtocksync_lora_phy_yield_wait_for();
16+
return ret;
2517
}
2618

2719
returncode_t libtocksync_lora_phy_read_write(const uint8_t* write,
2820
uint8_t* read,
2921
uint32_t len) {
30-
result.fired = false;
3122
returncode_t ret;
3223

33-
ret = libtock_lora_phy_read_write(write, read, len, lora_phy_spi_cb);
24+
ret = libtock_lora_phy_set_readwrite_allow_master_read_buffer(read, len);
25+
if (ret != RETURNCODE_SUCCESS) return ret;
26+
defer { libtock_lora_phy_set_readwrite_allow_master_read_buffer(NULL, 0);
27+
};
28+
29+
ret = libtock_lora_phy_set_readonly_allow_master_write_buffer(buf, len);
30+
if (ret != RETURNCODE_SUCCESS) return ret;
31+
defer { libtock_lora_phy_set_readonly_allow_master_write_buffer(NULL, 0);
32+
};
33+
34+
ret = libtock_lora_phy_command_read_write(len);
3435
if (ret != RETURNCODE_SUCCESS) return ret;
3536

36-
yield_for(&result.fired);
37-
return result.ret;
37+
ret = libtocksync_lora_phy_yield_wait_for();
38+
return ret;
3839
}

libtock-sync/net/lora_phy.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#pragma once
22

3-
#include <libtock/net/lora_phy.h>
43
#include <libtock/tock.h>
54

65
#ifdef __cplusplus
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <libtock/net/syscalls/lora_phy_syscalls.h>
2+
3+
#include "lora_phy_syscalls.h"
4+
5+
6+
returncode_t libtocksync_lora_phy_yield_wait_for(void) {
7+
yield_waitfor_return_t ret;
8+
ret = yield_wait_for(DRIVER_NUM_LORA_PHY_SPI, 0);
9+
10+
return RETURNCODE_SUCCESS;
11+
}
12+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#pragma once
2+
3+
#include <libtock/tock.h>
4+
5+
#ifdef __cplusplus
6+
extern "C" {
7+
#endif
8+
9+
returncode_t libtocksync_lora_phy_yield_wait_for(void);
10+
11+
#ifdef __cplusplus
12+
}
13+
#endif

0 commit comments

Comments
 (0)