Skip to content

Commit 36f0cda

Browse files
committed
modules/openthread/platform: update to new ring_buffer API
Move to use new ring_buffer_api. Signed-off-by: Måns Ansgariusson <[email protected]>
1 parent 34dd194 commit 36f0cda

File tree

3 files changed

+14
-29
lines changed

3 files changed

+14
-29
lines changed

modules/openthread/Kconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,6 @@ config OPENTHREAD_MBEDTLS_LIB_NAME
206206
config OPENTHREAD_COPROCESSOR
207207
bool "OpenThread Co-Processor"
208208
select OPENTHREAD_MANUAL_START
209-
select RING_BUFFER
210209
select UART_INTERRUPT_DRIVEN
211210
help
212211
Enable Co-Processor in OpenThread stack.

modules/openthread/platform/ble.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ static uint8_t ot_plat_ble_msg_buf[PLAT_BLE_MSG_DATA_MAX];
5757

5858
static K_SEM_DEFINE(ot_plat_ble_init_semaphore, 0, 1);
5959
static K_SEM_DEFINE(ot_plat_ble_event_semaphore, 0, K_SEM_MAX_LIMIT);
60-
RING_BUF_DECLARE(ot_plat_ble_ring_buf, CONFIG_OPENTHREAD_BLE_TCAT_RING_BUF_SIZE);
60+
RING_BUFFER_DECLARE(ot_plat_ble_ring_buf, CONFIG_OPENTHREAD_BLE_TCAT_RING_BUF_SIZE);
6161
static K_THREAD_DEFINE(ot_plat_ble_tid, CONFIG_OPENTHREAD_BLE_TCAT_THREAD_STACK_SIZE,
6262
ot_plat_ble_thread, NULL, NULL, NULL, 5, 0, PLAT_BLE_THREAD_DEALY);
6363

@@ -126,11 +126,11 @@ static bool ot_plat_ble_queue_msg(const uint8_t *aData, uint16_t aLen, int8_t aR
126126

127127
len = sizeof(aLen) + sizeof(aRssi) + ((aLen <= PLAT_BLE_MSG_DATA_MAX) ? aLen : 0);
128128

129-
if (ring_buf_space_get(&ot_plat_ble_ring_buf) >= len) {
130-
ring_buf_put(&ot_plat_ble_ring_buf, (uint8_t *)&aLen, sizeof(aLen));
131-
ring_buf_put(&ot_plat_ble_ring_buf, &aRssi, sizeof(aRssi));
129+
if (ring_buffer_space(&ot_plat_ble_ring_buf) >= len) {
130+
ring_buffer_write(&ot_plat_ble_ring_buf, (uint8_t *)&aLen, sizeof(aLen));
131+
ring_buffer_write(&ot_plat_ble_ring_buf, &aRssi, sizeof(aRssi));
132132
if (aLen <= PLAT_BLE_MSG_DATA_MAX) {
133-
ring_buf_put(&ot_plat_ble_ring_buf, aData, aLen);
133+
ring_buffer_write(&ot_plat_ble_ring_buf, aData, aLen);
134134
}
135135
k_sem_give(&ot_plat_ble_event_semaphore);
136136
} else {
@@ -156,10 +156,10 @@ static void ot_plat_ble_thread(void *unused1, void *unused2, void *unused3)
156156

157157
while (1) {
158158
k_sem_take(&ot_plat_ble_event_semaphore, K_FOREVER);
159-
ring_buf_get(&ot_plat_ble_ring_buf, (uint8_t *)&len, sizeof(len));
160-
ring_buf_get(&ot_plat_ble_ring_buf, &rssi, sizeof(rssi));
159+
ring_buffer_read(&ot_plat_ble_ring_buf, (uint8_t *)&len, sizeof(len));
160+
ring_buffer_read(&ot_plat_ble_ring_buf, &rssi, sizeof(rssi));
161161
if (len <= PLAT_BLE_MSG_DATA_MAX) {
162-
ring_buf_get(&ot_plat_ble_ring_buf, ot_plat_ble_msg_buf, len);
162+
ring_buffer_read(&ot_plat_ble_ring_buf, ot_plat_ble_msg_buf, len);
163163
}
164164

165165
openthread_mutex_lock();

modules/openthread/platform/uart.c

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);
2828
#include "platform-zephyr.h"
2929

3030
struct openthread_uart {
31-
struct ring_buf *rx_ringbuf;
31+
struct ring_buffer *rx_ringbuf;
3232
const struct device *dev;
3333
atomic_t tx_busy;
3434
atomic_t tx_finished;
3535
};
3636

3737
#define OT_UART_DEFINE(_name, _ringbuf_size) \
38-
RING_BUF_DECLARE(_name##_rx_ringbuf, _ringbuf_size); \
38+
RING_BUFFER_DECLARE(_name##_rx_ringbuf, _ringbuf_size); \
3939
static struct openthread_uart _name = { \
4040
.rx_ringbuf = &_name##_rx_ringbuf, \
4141
}
@@ -56,19 +56,14 @@ static void uart_rx_handle(const struct device *dev)
5656
bool new_data = false;
5757

5858
do {
59-
len = ring_buf_put_claim(
60-
ot_uart.rx_ringbuf, &data,
61-
ot_uart.rx_ringbuf->size);
59+
len = ring_buffer_write_ptr(ot_uart.rx_ringbuf, &data);
6260
if (len > 0) {
6361
rd_len = uart_fifo_read(dev, data, len);
6462
if (rd_len > 0) {
6563
new_data = true;
6664
}
6765

68-
int err = ring_buf_put_finish(
69-
ot_uart.rx_ringbuf, rd_len);
70-
(void)err;
71-
__ASSERT_NO_MSG(err == 0);
66+
ring_buffer_commit(ot_uart.rx_ringbuf, rd_len);
7267
} else {
7368
uint8_t dummy;
7469

@@ -133,18 +128,9 @@ void platformUartProcess(otInstance *aInstance)
133128
const uint8_t *data;
134129

135130
/* Process UART RX */
136-
while ((len = ring_buf_get_claim(
137-
ot_uart.rx_ringbuf,
138-
(uint8_t **)&data,
139-
ot_uart.rx_ringbuf->size)) > 0) {
140-
int err;
141-
131+
while ((len = ring_buffer_write_ptr(ot_uart.rx_ringbuf, (uint8_t **)&data)) > 0) {
142132
otPlatUartReceived(data, len);
143-
err = ring_buf_get_finish(
144-
ot_uart.rx_ringbuf,
145-
len);
146-
(void)err;
147-
__ASSERT_NO_MSG(err == 0);
133+
ring_buffer_consume(ot_uart.rx_ringbuf, len);
148134
}
149135

150136
/* Process UART TX */

0 commit comments

Comments
 (0)