Skip to content

Commit c0fa1f3

Browse files
authored
Merge pull request #513 from tyler-potyondy/openthread
OpenThread Updates/Fixes
2 parents 9a1b6d2 + ec04262 commit c0fa1f3

File tree

2 files changed

+40
-31
lines changed

2 files changed

+40
-31
lines changed

libopenthread/platform/flash.c

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,63 @@
1-
#include <storage/nonvolatile_storage.h>
2-
#include <libtock-sync/storage/nonvolatile_storage.h>
1+
#include <storage/isolated_nonvolatile_storage.h>
2+
#include <libtock-sync/storage/isolated_nonvolatile_storage.h>
33

44
#include <openthread/platform/flash.h>
55

66
#include <stdio.h>
77

8-
const uint32_t SWAP_SIZE = 1024;
8+
// TODO: The kernel currently has a 512 byte buffer
9+
// for isolated nonvolatile storage. This means that we can only
10+
// allow 512 bytes. 2x 512B swaps seems to be enough for openthread
11+
// but we may need to revist this in the future.
12+
const uint32_t SWAP_SIZE = 512;
913
const uint8_t SWAP_NUM = 2;
1014

11-
uint32_t otPlatFlashGetSwapSize(otInstance *aInstance){
15+
uint32_t otPlatFlashGetSwapSize(otInstance *aInstance) {
1216
OT_UNUSED_VARIABLE(aInstance);
1317
return SWAP_SIZE;
1418
}
1519

16-
void otPlatFlashInit(otInstance *aInstance) {
20+
void otPlatFlashInit(otInstance *aInstance) {
1721
OT_UNUSED_VARIABLE(aInstance);
18-
}
1922

20-
void otPlatFlashErase(otInstance *aInstance, uint8_t aSwapIndex) {
21-
OT_UNUSED_VARIABLE(aInstance);
23+
// Confirm we have enough space for the 2 swaps.
24+
uint64_t num_bytes;
25+
libtocksync_isolated_nonvolatile_storage_get_number_bytes(&num_bytes);
2226

23-
uint32_t num_bytes;
24-
libtock_nonvolatile_storage_get_number_bytes(&num_bytes);
27+
assert(num_bytes >= SWAP_SIZE * SWAP_NUM);
28+
}
2529

26-
// Write all zeroes to flash
27-
uint8_t zeroes[SWAP_SIZE];
30+
void otPlatFlashErase(otInstance *aInstance, uint8_t aSwapIndex) {
31+
uint8_t overwrite[SWAP_SIZE];
2832

29-
otPlatFlashWrite(aInstance, aSwapIndex, 0, zeroes, num_bytes);
33+
// Fill the swap area with 0xFF to erase it.
34+
for (uint32_t i = 0; i < SWAP_SIZE; i++) {
35+
overwrite[i] = 0xFF;
36+
}
3037

38+
otPlatFlashWrite(aInstance, aSwapIndex, 0, overwrite, SWAP_SIZE);
3139
}
3240

3341
void otPlatFlashWrite(otInstance *aInstance, uint8_t aSwapIndex, uint32_t aOffset,
3442
const void *aData, uint32_t aSize) {
3543
OT_UNUSED_VARIABLE(aInstance);
36-
OT_UNUSED_VARIABLE(aSwapIndex);
37-
int ret;
3844

3945
assert(aSwapIndex < SWAP_NUM);
46+
assert(aOffset + aSize <= SWAP_SIZE);
4047
uint32_t offset = aSwapIndex ? SWAP_SIZE : 0;
4148
offset += aOffset;
4249

43-
int _written;
44-
ret = libtocksync_nonvolatile_storage_write(offset, aSize, (uint8_t*)aData, aSize, &_written);
45-
if (ret != RETURNCODE_SUCCESS) {
46-
return;
47-
}
50+
libtocksync_isolated_nonvolatile_storage_write(offset, (uint8_t*)aData, aSize);
4851
}
4952

5053
void otPlatFlashRead(otInstance *aInstance, uint8_t aSwapIndex, uint32_t aOffset, void *aData,
5154
uint32_t aSize) {
5255
OT_UNUSED_VARIABLE(aInstance);
53-
OT_UNUSED_VARIABLE(aSwapIndex);
54-
int ret;
55-
56+
5657
assert(aSwapIndex < SWAP_NUM);
58+
assert(aOffset + aSize <= SWAP_SIZE);
5759
uint32_t offset = aSwapIndex ? SWAP_SIZE : 0;
5860
offset += aOffset;
59-
60-
int _read;
61-
ret = libtocksync_nonvolatile_storage_read(offset, aSize, (uint8_t*)aData, aSize, &_read);
62-
if (ret != RETURNCODE_SUCCESS) {
63-
return;
64-
}
61+
62+
libtocksync_isolated_nonvolatile_storage_read(offset, (uint8_t*)aData, aSize);
6563
}

libopenthread/platform/radio.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
#define ACK_SIZE 3
1313

14+
returncode_t ieee802154_set_channel_and_commit(uint8_t channel);
15+
1416
static uint8_t tx_mPsdu[OT_RADIO_FRAME_MAX_SIZE];
1517
static otRadioFrame transmitFrame = {
1618
.mPsdu = tx_mPsdu,
@@ -51,6 +53,15 @@ void reset_pending_tx_done_callback(void) {
5153
pending_tx_done_callback.flag = false;
5254
}
5355

56+
// Helper method for setting radio channel and calling config commit.
57+
returncode_t ieee802154_set_channel_and_commit(uint8_t channel) {
58+
returncode_t retCode = libtock_ieee802154_set_channel(channel);
59+
if (retCode != RETURNCODE_SUCCESS) {
60+
return retCode;
61+
}
62+
return libtock_ieee802154_config_commit();
63+
}
64+
5465
void otPlatRadioGetIeeeEui64(otInstance *aInstance, uint8_t *aIeeeEui64) {
5566
OT_UNUSED_VARIABLE(aInstance);
5667
uint64_t eui64;
@@ -137,7 +148,7 @@ otError otPlatRadioReceive(otInstance *aInstance, uint8_t aChannel) {
137148
otPlatRadioEnable(aInstance);
138149
}
139150

140-
int retCode = libtock_ieee802154_set_channel(aChannel);
151+
int retCode = ieee802154_set_channel_and_commit(aChannel);
141152
if (retCode != RETURNCODE_SUCCESS) {
142153
return OT_ERROR_FAILED;
143154
}
@@ -156,7 +167,7 @@ otError otPlatRadioTransmit(otInstance *aInstance, otRadioFrame *aFrame) {
156167
// final two bytes.
157168
aFrame->mLength = aFrame->mLength - 2;
158169

159-
int retCode = libtock_ieee802154_set_channel(aFrame->mChannel);
170+
int retCode = ieee802154_set_channel_and_commit(aFrame->mChannel);
160171
if (retCode != RETURNCODE_SUCCESS) {
161172
return OT_ERROR_FAILED;
162173
}

0 commit comments

Comments
 (0)