summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsakumisu <[email protected]>2026-02-11 19:49:08 +0800
committersakumisu <[email protected]>2026-02-11 19:58:09 +0800
commit362fec943a386c8cf623108f5f9019904270156f (patch)
tree9c9258a1f0c47adf38817f0a249e2da068b7917d
parent081c87206fccb374d1f1926fe47a44f75ff7d67a (diff)
refactor: move cherryrb and cherrymp into common dir, rename with usb_ringbuffer and usb_mempool
Signed-off-by: sakumisu <[email protected]>
-rw-r--r--SConscript3
-rw-r--r--cherryusb.cmake15
-rw-r--r--class/serial/usbh_serial.c104
-rw-r--r--class/serial/usbh_serial.h9
-rw-r--r--class/vendor/display/usbd_display.c26
-rw-r--r--class/vendor/display/usbd_display.h12
-rw-r--r--common/usb_mempool.h148
-rw-r--r--common/usb_osal.h1
-rw-r--r--common/usb_ringbuffer.h (renamed from third_party/cherryrb/chry_ringbuffer.c)172
-rw-r--r--core/usbd_core.h2
-rw-r--r--core/usbh_core.h2
-rw-r--r--osal/idf/usb_osal_idf.c5
-rw-r--r--osal/usb_osal_freertos.c11
-rw-r--r--osal/usb_osal_liteos_m.c5
-rw-r--r--osal/usb_osal_nuttx.c5
-rw-r--r--osal/usb_osal_rtthread.c5
-rw-r--r--osal/usb_osal_threadx.c5
-rw-r--r--osal/usb_osal_zephyr.c14
-rw-r--r--third_party/cherrymp/LICENSE201
-rw-r--r--third_party/cherrymp/README.md3
-rw-r--r--third_party/cherrymp/chry_mempool.c243
-rw-r--r--third_party/cherrymp/chry_mempool.h58
-rw-r--r--third_party/cherrymp/chry_mempool_osal_freertos.c51
-rw-r--r--third_party/cherrymp/chry_mempool_osal_nonos.c26
-rw-r--r--third_party/cherrymp/chry_mempool_osal_rtthread.c44
-rw-r--r--third_party/cherryrb/CHANGELOG.md9
-rw-r--r--third_party/cherryrb/LICENSE201
-rw-r--r--third_party/cherryrb/README.md206
-rw-r--r--third_party/cherryrb/README_zh.md200
-rw-r--r--third_party/cherryrb/chry_ringbuffer.h56
30 files changed, 327 insertions, 1515 deletions
diff --git a/SConscript b/SConscript
index 7c8f2bd2..17f80e9e 100644
--- a/SConscript
+++ b/SConscript
@@ -140,9 +140,6 @@ if GetDepend(['PKG_CHERRYUSB_DEVICE']):
src += Glob('class/dfu/usbd_dfu.c')
if GetDepend(['PKG_CHERRYUSB_DEVICE_DISPLAY']):
src += Glob('class/vendor/display/usbd_display.c')
- src += Glob('third_party/cherrymp/chry_mempool.c')
- src += Glob('third_party/cherrymp/chry_mempool_osal_rtthread.c')
- path += [cwd + '/third_party/cherrymp']
if GetDepend(['PKG_CHERRYUSB_DEVICE_ADB']):
src += Glob('class/adb/usbd_adb.c')
src += Glob('platform/rtthread/usbd_adb_shell.c')
diff --git a/cherryusb.cmake b/cherryusb.cmake
index 3db0e167..b705e00f 100644
--- a/cherryusb.cmake
+++ b/cherryusb.cmake
@@ -380,18 +380,3 @@ if(DEFINED CONFIG_CHERRYUSB_OSAL)
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/osal/usb_osal_zephyr.c)
endif()
endif()
-
-if(CONFIG_CHERRYRB)
- list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/third_party/cherryrb/chry_ringbuffer.c)
- list(APPEND cherryusb_incs ${CMAKE_CURRENT_LIST_DIR}/third_party/cherryrb)
-endif()
-
-if(CONFIG_CHERRYMP)
- list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/third_party/cherrymp/chry_mempool.c)
- list(APPEND cherryusb_incs ${CMAKE_CURRENT_LIST_DIR}/third_party/cherrymp)
- if("${CONFIG_CHERRYUSB_OSAL}" STREQUAL "freertos")
- list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/third_party/cherrymp/chry_mempool_osal_freertos.c)
- elseif("${CONFIG_CHERRYUSB_OSAL}" STREQUAL "rtthread")
- list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/third_party/cherrymp/chry_mempool_osal_rtthread.c)
- endif()
-endif()
diff --git a/class/serial/usbh_serial.c b/class/serial/usbh_serial.c
index d6361b21..b0bedc3c 100644
--- a/class/serial/usbh_serial.c
+++ b/class/serial/usbh_serial.c
@@ -23,94 +23,6 @@ static uint32_t g_cdcacm_devinuse = 0;
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_serial_iobuffer[CONFIG_USBHOST_MAX_SERIAL_CLASS][USB_ALIGN_UP((USBH_SERIAL_RX2_NOCACHE_OFFSET + USBH_SERIAL_RX2_NOCACHE_SIZE), CONFIG_USB_ALIGN_SIZE)];
-/* refer to cherryrb */
-static int usbh_serial_ringbuffer_init(usbh_serial_ringbuf_t *rb, void *pool, uint32_t size)
-{
- if (NULL == rb) {
- return -1;
- }
-
- if (NULL == pool) {
- return -1;
- }
-
- if ((size < 2) || (size & (size - 1))) {
- return -1;
- }
-
- rb->in = 0;
- rb->out = 0;
- rb->mask = size - 1;
- rb->pool = pool;
-
- return 0;
-}
-
-static void usbh_serial_ringbuffer_reset(usbh_serial_ringbuf_t *rb)
-{
- rb->in = 0;
- rb->out = 0;
-}
-
-static uint32_t usbh_serial_ringbuffer_get_used(usbh_serial_ringbuf_t *rb)
-{
- return rb->in - rb->out;
-}
-
-static uint32_t usbh_serial_ringbuffer_write(usbh_serial_ringbuf_t *rb, void *data, uint32_t size)
-{
- uint32_t unused;
- uint32_t offset;
- uint32_t remain;
-
- unused = (rb->mask + 1) - (rb->in - rb->out);
-
- if (size > unused) {
- size = unused;
- }
-
- offset = rb->in & rb->mask;
-
- remain = rb->mask + 1 - offset;
- remain = remain > size ? size : remain;
-
- memcpy(((uint8_t *)(rb->pool)) + offset, data, remain);
- memcpy(rb->pool, (uint8_t *)data + remain, size - remain);
-
- rb->in += size;
-
- return size;
-}
-
-static uint32_t usbh_serial_ringbuffer_peek(usbh_serial_ringbuf_t *rb, void *data, uint32_t size)
-{
- uint32_t used;
- uint32_t offset;
- uint32_t remain;
-
- used = rb->in - rb->out;
- if (size > used) {
- size = used;
- }
-
- offset = rb->out & rb->mask;
-
- remain = rb->mask + 1 - offset;
- remain = remain > size ? size : remain;
-
- memcpy(data, ((uint8_t *)(rb->pool)) + offset, remain);
- memcpy((uint8_t *)data + remain, rb->pool, size - remain);
-
- return size;
-}
-
-static uint32_t usbh_serial_ringbuffer_read(usbh_serial_ringbuf_t *rb, void *data, uint32_t size)
-{
- size = usbh_serial_ringbuffer_peek(rb, data, size);
- rb->out += size;
- return size;
-}
-
static struct usbh_serial *usbh_serial_alloc(bool is_cdcacm)
{
uint8_t devno;
@@ -193,9 +105,9 @@ static void usbh_serial_callback(void *arg, int nbytes)
return;
}
- usbh_serial_ringbuffer_write(&serial->rx_rb,
- &serial->iobuffer[(serial->rx_buf_index ? USBH_SERIAL_RX2_NOCACHE_OFFSET : USBH_SERIAL_RX_NOCACHE_OFFSET) + serial->driver->ignore_rx_header],
- (nbytes - serial->driver->ignore_rx_header));
+ usb_ringbuffer_write(&serial->rx_rb,
+ &serial->iobuffer[(serial->rx_buf_index ? USBH_SERIAL_RX2_NOCACHE_OFFSET : USBH_SERIAL_RX_NOCACHE_OFFSET) + serial->driver->ignore_rx_header],
+ (nbytes - serial->driver->ignore_rx_header));
if (serial->rx_complete_callback) {
serial->rx_complete_callback(serial, nbytes - serial->driver->ignore_rx_header);
@@ -319,7 +231,7 @@ struct usbh_serial *usbh_serial_open(const char *devname, uint32_t open_flags)
}
}
- usbh_serial_ringbuffer_init(&serial->rx_rb, serial->rx_rb_pool, CONFIG_USBHOST_SERIAL_RX_SIZE);
+ usb_ringbuffer_init(&serial->rx_rb, serial->rx_rb_pool, CONFIG_USBHOST_SERIAL_RX_SIZE);
serial->ref_count++;
serial->open_flags = open_flags;
@@ -454,7 +366,7 @@ int usbh_serial_control(struct usbh_serial *serial, int cmd, void *arg)
return ret;
}
- usbh_serial_ringbuffer_reset(&serial->rx_rb);
+ usb_ringbuffer_reset(&serial->rx_rb);
usb_osal_sem_reset(serial->rx_complete_sem);
serial->rx_buf_index = 0;
usbh_bulk_urb_fill(&serial->bulkin_urb, serial->hport, serial->bulkin, &serial->iobuffer[serial->rx_buf_index ? USBH_SERIAL_RX2_NOCACHE_OFFSET : USBH_SERIAL_RX_NOCACHE_OFFSET], serial->bulkin->wMaxPacketSize,
@@ -561,9 +473,9 @@ int usbh_serial_read(struct usbh_serial *serial, void *buffer, uint32_t buflen)
}
if (serial->open_flags & USBH_SERIAL_O_NONBLOCK) {
- return usbh_serial_ringbuffer_read(&serial->rx_rb, buffer, buflen);
+ return usb_ringbuffer_read(&serial->rx_rb, buffer, buflen);
} else {
- if (usbh_serial_ringbuffer_get_used(&serial->rx_rb) == 0) {
+ if (usb_ringbuffer_get_used(&serial->rx_rb) == 0) {
ret = usb_osal_sem_take(serial->rx_complete_sem, serial->rx_timeout_ms == 0 ? USB_OSAL_WAITING_FOREVER : serial->rx_timeout_ms);
if (ret < 0) {
return ret;
@@ -572,7 +484,7 @@ int usbh_serial_read(struct usbh_serial *serial, void *buffer, uint32_t buflen)
return serial->rx_errorcode;
}
}
- return usbh_serial_ringbuffer_read(&serial->rx_rb, buffer, buflen);
+ return usb_ringbuffer_read(&serial->rx_rb, buffer, buflen);
}
}
diff --git a/class/serial/usbh_serial.h b/class/serial/usbh_serial.h
index 033ab705..06a31709 100644
--- a/class/serial/usbh_serial.h
+++ b/class/serial/usbh_serial.h
@@ -67,13 +67,6 @@
extern "C" {
#endif
-typedef struct {
- uint32_t in; /*!< Define the write pointer. */
- uint32_t out; /*!< Define the read pointer. */
- uint32_t mask; /*!< Define the write and read pointer mask. */
- void *pool; /*!< Define the memory pointer. */
-} usbh_serial_ringbuf_t;
-
/*
* Counters of the input lines (CTS, DSR, RI, CD) interrupts
*/
@@ -143,7 +136,7 @@ struct usbh_serial {
const struct usbh_serial_driver *driver;
- usbh_serial_ringbuf_t rx_rb;
+ usb_ringbuffer_t rx_rb;
uint8_t rx_rb_pool[CONFIG_USBHOST_SERIAL_RX_SIZE];
usb_osal_sem_t rx_complete_sem;
uint8_t rx_buf_index;
diff --git a/class/vendor/display/usbd_display.c b/class/vendor/display/usbd_display.c
index 2ad0f745..181da6e5 100644
--- a/class/vendor/display/usbd_display.c
+++ b/class/vendor/display/usbd_display.c
@@ -6,22 +6,9 @@
#include "usbd_core.h"
#include "usbd_display.h"
-#include "chry_mempool.h"
-
-struct usbd_disp_frame_header {
- uint16_t crc16; //payload crc16
- uint8_t type; //raw rgb,yuv,jpg,other
- uint8_t cmd;
- uint16_t x; //32bit
- uint16_t y;
- uint16_t width; //32bit
- uint16_t height;
- uint32_t frame_id : 10;
- uint32_t payload_total : 22; //payload max 4MB
-} __PACKED;
struct usbd_display_priv {
- struct chry_mempool pool;
+ struct usb_mempool pool;
struct usbd_endpoint out_ep;
struct usbd_endpoint in_ep;
struct usbd_display_frame *current_frame;
@@ -29,27 +16,27 @@ struct usbd_display_priv {
int usbd_display_frame_create(struct usbd_display_frame *frame, uint32_t count)
{
- return chry_mempool_create(&g_usbd_display.pool, frame, sizeof(struct usbd_display_frame), count);
+ return usb_mempool_create(&g_usbd_display.pool, frame, sizeof(struct usbd_display_frame), count);
}
struct usbd_display_frame *usbd_display_frame_alloc(void)
{
- return (struct usbd_display_frame *)chry_mempool_alloc(&g_usbd_display.pool);
+ return (struct usbd_display_frame *)usb_mempool_alloc(&g_usbd_display.pool);
}
int usbd_display_frame_free(struct usbd_display_frame *frame)
{
- return chry_mempool_free(&g_usbd_display.pool, (uintptr_t *)frame);
+ return usb_mempool_free(&g_usbd_display.pool, (uintptr_t *)frame);
}
int usbd_display_frame_send(struct usbd_display_frame *frame)
{
- return chry_mempool_send(&g_usbd_display.pool, (uintptr_t *)frame);
+ return usb_mempool_send(&g_usbd_display.pool, (uintptr_t *)frame);
}
int usbd_display_frame_recv(struct usbd_display_frame **frame, uint32_t timeout)
{
- return chry_mempool_recv(&g_usbd_display.pool, (uintptr_t **)frame, timeout);
+ return usb_mempool_recv(&g_usbd_display.pool, (uintptr_t **)frame, timeout);
}
uint8_t usb_dispay_dummy[512];
@@ -65,6 +52,7 @@ static void display_notify_handler(uint8_t busid, uint8_t event, void *arg)
usb_display_buf_offset = 0;
usb_display_ignore_frame = true;
g_usbd_display.current_frame = NULL;
+ usb_mempool_reset(&g_usbd_display.pool);
usbd_ep_start_read(busid, g_usbd_display.out_ep.ep_addr, usb_dispay_dummy, usbd_get_ep_mps(0, g_usbd_display.out_ep.ep_addr));
break;
default:
diff --git a/class/vendor/display/usbd_display.h b/class/vendor/display/usbd_display.h
index 9eac9903..9b7c47e1 100644
--- a/class/vendor/display/usbd_display.h
+++ b/class/vendor/display/usbd_display.h
@@ -11,6 +11,18 @@
#define USBD_DISPLAY_TYPE_YUV420 2
#define USBD_DISPLAY_TYPE_JPG 3
+struct usbd_disp_frame_header {
+ uint16_t crc16; //payload crc16
+ uint8_t type; //raw rgb,yuv,jpg,other
+ uint8_t cmd;
+ uint16_t x; //32bit
+ uint16_t y;
+ uint16_t width; //32bit
+ uint16_t height;
+ uint32_t frame_id : 10;
+ uint32_t payload_total : 22; //payload max 4MB
+} __PACKED;
+
struct usbd_display_frame {
uint8_t *frame_buf;
uint32_t frame_bufsize;
diff --git a/common/usb_mempool.h b/common/usb_mempool.h
new file mode 100644
index 00000000..d14d69d5
--- /dev/null
+++ b/common/usb_mempool.h
@@ -0,0 +1,148 @@
+/*
+ * Copyright (c) 2022, sakumisu
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+#ifndef USB_MEMPOOL_H
+#define USB_MEMPOOL_H
+
+#include "usb_osal.h"
+#include "usb_ringbuffer.h"
+
+#ifndef CONFIG_USB_MEMPOOL_MAX_BLOCK_COUNT
+#define CONFIG_USB_MEMPOOL_MAX_BLOCK_COUNT 16
+#endif
+
+struct usb_mempool {
+ usb_ringbuffer_t in;
+ usb_ringbuffer_t out;
+ usb_osal_sem_t out_sem;
+
+ void *block;
+ uint32_t block_size;
+ uint32_t block_count;
+ uint8_t in_buf[sizeof(uintptr_t) * CONFIG_USB_MEMPOOL_MAX_BLOCK_COUNT];
+ uint8_t out_buf[sizeof(uintptr_t) * CONFIG_USB_MEMPOOL_MAX_BLOCK_COUNT];
+};
+
+#define usb_mempool_osal_sem_create(max_count) usb_osal_sem_create_counting(max_count)
+#define usb_mempool_osal_sem_delete(sem) usb_osal_sem_delete(sem)
+#define usb_mempool_osal_sem_take(sem, timeout) usb_osal_sem_take(sem, timeout)
+#define usb_mempool_osal_sem_give(sem) usb_osal_sem_give(sem)
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+static inline int usb_mempool_create(struct usb_mempool *pool, void *block, uint32_t block_size, uint32_t block_count)
+{
+ uintptr_t *item;
+ uint32_t addr;
+
+ if (block_count > CONFIG_USB_MEMPOOL_MAX_BLOCK_COUNT) {
+ return -1;
+ }
+
+ if (block_size % 4) {
+ return -1;
+ }
+
+ if (usb_ringbuffer_init(&pool->in, pool->in_buf, sizeof(uintptr_t) * block_count) == -1) {
+ return -1;
+ }
+
+ if (usb_ringbuffer_init(&pool->out, pool->out_buf, sizeof(uintptr_t) * block_count) == -1) {
+ return -1;
+ }
+
+ pool->out_sem = usb_mempool_osal_sem_create(block_count);
+ if (pool->out_sem == NULL) {
+ return -1;
+ }
+
+ pool->block = block;
+ pool->block_size = block_size;
+ pool->block_count = block_count;
+
+ for (uint32_t i = 0; i < pool->block_count; i++) {
+ item = (uintptr_t *)((uint8_t *)pool->block + i * pool->block_size);
+ addr = (uintptr_t)item;
+ usb_ringbuffer_write(&pool->in, &addr, sizeof(uintptr_t));
+ }
+
+ return 0;
+}
+
+static inline void usb_mempool_delete(struct usb_mempool *pool)
+{
+ usb_ringbuffer_reset(&pool->in);
+ usb_ringbuffer_reset(&pool->out);
+ usb_mempool_osal_sem_delete(pool->out_sem);
+}
+
+static inline uintptr_t *usb_mempool_alloc(struct usb_mempool *pool)
+{
+ uintptr_t *addr;
+ uint32_t len;
+
+ len = usb_ringbuffer_read(&pool->in, (uintptr_t *)&addr, sizeof(uintptr_t));
+ if (len == 0) {
+ return NULL;
+ } else {
+ return addr;
+ }
+}
+
+static inline int usb_mempool_free(struct usb_mempool *pool, uintptr_t *item)
+{
+ uintptr_t addr;
+
+ addr = (uintptr_t)item;
+ return usb_ringbuffer_write(&pool->in, &addr, sizeof(uintptr_t));
+}
+
+static inline int usb_mempool_send(struct usb_mempool *pool, uintptr_t *item)
+{
+ uintptr_t addr;
+
+ addr = (uintptr_t)item;
+ usb_ringbuffer_write(&pool->out, &addr, sizeof(uintptr_t));
+ return usb_mempool_osal_sem_give(pool->out_sem);
+}
+
+static inline int usb_mempool_recv(struct usb_mempool *pool, uintptr_t **item, uint32_t timeout)
+{
+ uint32_t len;
+ int ret;
+
+ ret = usb_mempool_osal_sem_take(pool->out_sem, timeout);
+ if (ret < 0) {
+ return -1;
+ }
+
+ len = usb_ringbuffer_read(&pool->out, (uintptr_t *)item, sizeof(uintptr_t));
+ if (len == 0) {
+ return -1;
+ } else {
+ return 0;
+ }
+}
+
+static inline void usb_mempool_reset(struct usb_mempool *pool)
+{
+ uintptr_t *item;
+
+ usb_ringbuffer_reset(&pool->in);
+ usb_ringbuffer_reset(&pool->out);
+
+ for (uint32_t i = 0; i < pool->block_count; i++) {
+ item = (uintptr_t *)((uint8_t *)pool->block + i * pool->block_size);
+ usb_mempool_free(pool, item);
+ }
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/common/usb_osal.h b/common/usb_osal.h
index 1975f208..70e2afe7 100644
--- a/common/usb_osal.h
+++ b/common/usb_osal.h
@@ -45,6 +45,7 @@ void usb_osal_thread_delete(usb_osal_thread_t thread);
void usb_osal_thread_schedule_other(void);
usb_osal_sem_t usb_osal_sem_create(uint32_t initial_count);
+usb_osal_sem_t usb_osal_sem_create_counting(uint32_t max_count);
void usb_osal_sem_delete(usb_osal_sem_t sem);
int usb_osal_sem_take(usb_osal_sem_t sem, uint32_t timeout);
int usb_osal_sem_give(usb_osal_sem_t sem);
diff --git a/third_party/cherryrb/chry_ringbuffer.c b/common/usb_ringbuffer.h
index a5d06a0d..3a0afe92 100644
--- a/third_party/cherryrb/chry_ringbuffer.c
+++ b/common/usb_ringbuffer.h
@@ -3,21 +3,35 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
+#ifndef USB_RINGBUFFER_H
+#define USB_RINGBUFFER_H
+#include <stdint.h>
+#include <stdbool.h>
#include <string.h>
-#include "chry_ringbuffer.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct {
+ uint32_t in; /*!< Define the write pointer. */
+ uint32_t out; /*!< Define the read pointer. */
+ uint32_t mask; /*!< Define the write and read pointer mask. */
+ void *pool; /*!< Define the memory pointer. */
+} usb_ringbuffer_t;
/*****************************************************************************
* @brief init ringbuffer
-*
+*
* @param[in] rb ringbuffer instance
* @param[in] pool memory pool address
* @param[in] size memory size in byte,
* must be power of 2 !!!
-*
+*
* @retval int 0:Success -1:Error
*****************************************************************************/
-int chry_ringbuffer_init(chry_ringbuffer_t *rb, void *pool, uint32_t size)
+static inline int usb_ringbuffer_init(usb_ringbuffer_t *rb, void *pool, uint32_t size)
{
if (NULL == rb) {
return -1;
@@ -40,13 +54,13 @@ int chry_ringbuffer_init(chry_ringbuffer_t *rb, void *pool, uint32_t size)
}
/*****************************************************************************
-* @brief reset ringbuffer, clean all data,
+* @brief reset ringbuffer, clean all data,
* should be add lock in multithread
-*
+*
* @param[in] rb ringbuffer instance
-*
+*
*****************************************************************************/
-void chry_ringbuffer_reset(chry_ringbuffer_t *rb)
+static inline void usb_ringbuffer_reset(usb_ringbuffer_t *rb)
{
rb->in = 0;
rb->out = 0;
@@ -56,73 +70,73 @@ void chry_ringbuffer_reset(chry_ringbuffer_t *rb)
* @brief reset ringbuffer, clean all data,
* should be add lock in multithread,
* in single read thread not need lock
-*
+*
* @param[in] rb ringbuffer instance
-*
+*
*****************************************************************************/
-void chry_ringbuffer_reset_read(chry_ringbuffer_t *rb)
+static inline void usb_ringbuffer_reset_read(usb_ringbuffer_t *rb)
{
rb->out = rb->in;
}
/*****************************************************************************
* @brief get ringbuffer total size in byte
-*
+*
* @param[in] rb ringbuffer instance
-*
+*
* @retval uint32_t total size in byte
*****************************************************************************/
-uint32_t chry_ringbuffer_get_size(chry_ringbuffer_t *rb)
+static inline uint32_t usb_ringbuffer_get_size(usb_ringbuffer_t *rb)
{
return rb->mask + 1;
}
/*****************************************************************************
* @brief get ringbuffer used size in byte
-*
+*
* @param[in] rb ringbuffer instance
-*
+*
* @retval uint32_t used size in byte
*****************************************************************************/
-uint32_t chry_ringbuffer_get_used(chry_ringbuffer_t *rb)
+static inline uint32_t usb_ringbuffer_get_used(usb_ringbuffer_t *rb)
{
return rb->in - rb->out;
}
/*****************************************************************************
* @brief get ringbuffer free size in byte
-*
+*
* @param[in] rb ringbuffer instance
-*
+*
* @retval uint32_t free size in byte
*****************************************************************************/
-uint32_t chry_ringbuffer_get_free(chry_ringbuffer_t *rb)
+static inline uint32_t usb_ringbuffer_get_free(usb_ringbuffer_t *rb)
{
return (rb->mask + 1) - (rb->in - rb->out);
}
/*****************************************************************************
* @brief check if ringbuffer is full
-*
+*
* @param[in] rb ringbuffer instance
-*
+*
* @retval true full
* @retval false not full
*****************************************************************************/
-bool chry_ringbuffer_check_full(chry_ringbuffer_t *rb)
+static inline bool usb_ringbuffer_check_full(usb_ringbuffer_t *rb)
{
- return chry_ringbuffer_get_used(rb) > rb->mask;
+ return usb_ringbuffer_get_used(rb) > rb->mask;
}
/*****************************************************************************
* @brief check if ringbuffer is empty
-*
+*
* @param[in] rb ringbuffer instance
-*
+*
* @retval true empty
* @retval false not empty
*****************************************************************************/
-bool chry_ringbuffer_check_empty(chry_ringbuffer_t *rb)
+static inline bool usb_ringbuffer_check_empty(usb_ringbuffer_t *rb)
{
return rb->in == rb->out;
}
@@ -131,16 +145,16 @@ bool chry_ringbuffer_check_empty(chry_ringbuffer_t *rb)
* @brief write one byte to ringbuffer,
* should be add lock in multithread,
* in single write thread not need lock
-*
+*
* @param[in] rb ringbuffer instance
* @param[in] byte data
-*
+*
* @retval true Success
* @retval false ringbuffer is full
*****************************************************************************/
-bool chry_ringbuffer_write_byte(chry_ringbuffer_t *rb, uint8_t byte)
+static inline bool usb_ringbuffer_write_byte(usb_ringbuffer_t *rb, uint8_t byte)
{
- if (chry_ringbuffer_check_full(rb)) {
+ if (usb_ringbuffer_check_full(rb)) {
return false;
}
@@ -155,13 +169,13 @@ bool chry_ringbuffer_write_byte(chry_ringbuffer_t *rb, uint8_t byte)
*
* @param[in] rb ringbuffer instance
* @param[in] byte data
-*
+*
* @retval true Success
* @retval false always return true
*****************************************************************************/
-bool chry_ringbuffer_overwrite_byte(chry_ringbuffer_t *rb, uint8_t byte)
+static inline bool usb_ringbuffer_overwrite_byte(usb_ringbuffer_t *rb, uint8_t byte)
{
- if (chry_ringbuffer_check_full(rb)) {
+ if (usb_ringbuffer_check_full(rb)) {
rb->out++;
}
@@ -174,16 +188,16 @@ bool chry_ringbuffer_overwrite_byte(chry_ringbuffer_t *rb, uint8_t byte)
* @brief peek one byte from ringbuffer,
* should be add lock in multithread,
* in single read thread not need lock
-*
+*
* @param[in] rb ringbuffer instance
* @param[in] byte pointer to save data
-*
+*
* @retval true Success
* @retval false ringbuffer is empty
*****************************************************************************/
-bool chry_ringbuffer_peek_byte(chry_ringbuffer_t *rb, uint8_t *byte)
+static inline bool usb_ringbuffer_peek_byte(usb_ringbuffer_t *rb, uint8_t *byte)
{
- if (chry_ringbuffer_check_empty(rb)) {
+ if (usb_ringbuffer_check_empty(rb)) {
return false;
}
@@ -195,17 +209,17 @@ bool chry_ringbuffer_peek_byte(chry_ringbuffer_t *rb, uint8_t *byte)
* @brief read one byte from ringbuffer,
* should be add lock in multithread,
* in single read thread not need lock
-*
+*
* @param[in] rb ringbuffer instance
* @param[in] byte pointer to save data
-*
+*
* @retval true Success
* @retval false ringbuffer is empty
*****************************************************************************/
-bool chry_ringbuffer_read_byte(chry_ringbuffer_t *rb, uint8_t *byte)
+static inline bool usb_ringbuffer_read_byte(usb_ringbuffer_t *rb, uint8_t *byte)
{
bool ret;
- ret = chry_ringbuffer_peek_byte(rb, byte);
+ ret = usb_ringbuffer_peek_byte(rb, byte);
rb->out += ret;
return ret;
}
@@ -214,15 +228,15 @@ bool chry_ringbuffer_read_byte(chry_ringbuffer_t *rb, uint8_t *byte)
* @brief drop one byte from ringbuffer,
* should be add lock in multithread,
* in single read thread not need lock
-*
+*
* @param[in] rb ringbuffer instance
-*
+*
* @retval true Success
* @retval false ringbuffer is empty
*****************************************************************************/
-bool chry_ringbuffer_drop_byte(chry_ringbuffer_t *rb)
+static inline bool usb_ringbuffer_drop_byte(usb_ringbuffer_t *rb)
{
- if (chry_ringbuffer_check_empty(rb)) {
+ if (usb_ringbuffer_check_empty(rb)) {
return false;
}
@@ -234,14 +248,14 @@ bool chry_ringbuffer_drop_byte(chry_ringbuffer_t *rb)
* @brief write data to ringbuffer,
* should be add lock in multithread,
* in single write thread not need lock
-*
+*
* @param[in] rb ringbuffer instance
* @param[in] data data pointer
* @param[in] size size in byte
-*
+*
* @retval uint32_t actual write size in byte
*****************************************************************************/
-uint32_t chry_ringbuffer_write(chry_ringbuffer_t *rb, void *data, uint32_t size)
+static inline uint32_t usb_ringbuffer_write(usb_ringbuffer_t *rb, void *data, uint32_t size)
{
uint32_t unused;
uint32_t offset;
@@ -269,14 +283,14 @@ uint32_t chry_ringbuffer_write(chry_ringbuffer_t *rb, void *data, uint32_t size)
/*****************************************************************************
* @brief write data to ringbuffer,
* should be add lock always
-*
+*
* @param[in] rb ringbuffer instance
* @param[in] data data pointer
* @param[in] size size in byte
-*
+*
* @retval uint32_t actual write size in byte
*****************************************************************************/
-uint32_t chry_ringbuffer_overwrite(chry_ringbuffer_t *rb, void *data, uint32_t size)
+static inline uint32_t usb_ringbuffer_overwrite(usb_ringbuffer_t *rb, void *data, uint32_t size)
{
uint32_t unused;
uint32_t offset;
@@ -309,14 +323,14 @@ uint32_t chry_ringbuffer_overwrite(chry_ringbuffer_t *rb, void *data, uint32_t s
* @brief peek data from ringbuffer
* should be add lock in multithread,
* in single read thread not need lock
-*
+*
* @param[in] rb ringbuffer instance
* @param[in] data data pointer
* @param[in] size size in byte
-*
+*
* @retval uint32_t actual peek size in byte
*****************************************************************************/
-uint32_t chry_ringbuffer_peek(chry_ringbuffer_t *rb, void *data, uint32_t size)
+static inline uint32_t usb_ringbuffer_peek(usb_ringbuffer_t *rb, void *data, uint32_t size)
{
uint32_t used;
uint32_t offset;
@@ -342,16 +356,16 @@ uint32_t chry_ringbuffer_peek(chry_ringbuffer_t *rb, void *data, uint32_t size)
* @brief read data from ringbuffer
* should be add lock in multithread,
* in single read thread not need lock
-*
+*
* @param[in] rb ringbuffer instance
* @param[in] data data pointer
* @param[in] size size in byte
-*
+*
* @retval uint32_t actual read size in byte
*****************************************************************************/
-uint32_t chry_ringbuffer_read(chry_ringbuffer_t *rb, void *data, uint32_t size)
+static inline uint32_t usb_ringbuffer_read(usb_ringbuffer_t *rb, void *data, uint32_t size)
{
- size = chry_ringbuffer_peek(rb, data, size);
+ size = usb_ringbuffer_peek(rb, data, size);
rb->out += size;
return size;
}
@@ -360,13 +374,13 @@ uint32_t chry_ringbuffer_read(chry_ringbuffer_t *rb, void *data, uint32_t size)
* @brief drop data from ringbuffer
* should be add lock in multithread,
* in single read thread not need lock
-*
+*
* @param[in] rb ringbuffer instance
* @param[in] size size in byte
-*
+*
* @retval uint32_t actual drop size in byte
*****************************************************************************/
-uint32_t chry_ringbuffer_drop(chry_ringbuffer_t *rb, uint32_t size)
+static inline uint32_t usb_ringbuffer_drop(usb_ringbuffer_t *rb, uint32_t size)
{
uint32_t used;
@@ -381,13 +395,13 @@ uint32_t chry_ringbuffer_drop(chry_ringbuffer_t *rb, uint32_t size)
/*****************************************************************************
* @brief linear write setup, get write pointer and max linear size.
-*
+*
* @param[in] rb ringbuffer instance
* @param[in] size pointer to store max linear size in byte
-*
+*
* @retval void* write memory pointer
*****************************************************************************/
-void *chry_ringbuffer_linear_write_setup(chry_ringbuffer_t *rb, uint32_t *size)
+static inline void *usb_ringbuffer_linear_write_setup(usb_ringbuffer_t *rb, uint32_t *size)
{
uint32_t unused;
uint32_t offset;
@@ -411,13 +425,13 @@ void *chry_ringbuffer_linear_write_setup(chry_ringbuffer_t *rb, uint32_t *size)
/*****************************************************************************
* @brief linear read setup, get read pointer and max linear size.
-*
+*
* @param[in] rb ringbuffer instance
* @param[in] size pointer to store max linear size in byte
-*
-* @retval void*
+*
+* @retval void*
*****************************************************************************/
-void *chry_ringbuffer_linear_read_setup(chry_ringbuffer_t *rb, uint32_t *size)
+static inline void *usb_ringbuffer_linear_read_setup(usb_ringbuffer_t *rb, uint32_t *size)
{
uint32_t used;
uint32_t offset;
@@ -441,13 +455,13 @@ void *chry_ringbuffer_linear_read_setup(chry_ringbuffer_t *rb, uint32_t *size)
/*****************************************************************************
* @brief linear write done, add write pointer only
-*
+*
* @param[in] rb ringbuffer instance
* @param[in] size write size in byte
-*
+*
* @retval uint32_t actual write size in byte
*****************************************************************************/
-uint32_t chry_ringbuffer_linear_write_done(chry_ringbuffer_t *rb, uint32_t size)
+static inline uint32_t usb_ringbuffer_linear_write_done(usb_ringbuffer_t *rb, uint32_t size)
{
uint32_t unused;
@@ -462,13 +476,19 @@ uint32_t chry_ringbuffer_linear_write_done(chry_ringbuffer_t *rb, uint32_t size)
/*****************************************************************************
* @brief linear read done, add read pointer only
-*
+*
* @param[in] rb ringbuffer instance
* @param[in] size read size in byte
-*
+*
* @retval uint32_t actual read size in byte
*****************************************************************************/
-uint32_t chry_ringbuffer_linear_read_done(chry_ringbuffer_t *rb, uint32_t size)
+static inline uint32_t usb_ringbuffer_linear_read_done(usb_ringbuffer_t *rb, uint32_t size)
{
- return chry_ringbuffer_drop(rb, size);
+ return usb_ringbuffer_drop(rb, size);
}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/core/usbd_core.h b/core/usbd_core.h
index 314ccbec..ac9c58f1 100644
--- a/core/usbd_core.h
+++ b/core/usbd_core.h
@@ -24,6 +24,8 @@ extern "C" {
#include "usb_dc.h"
#include "usb_osal.h"
#include "usb_memcpy.h"
+#include "usb_ringbuffer.h"
+#include "usb_mempool.h"
#include "usb_dcache.h"
#include "usb_version.h"
diff --git a/core/usbh_core.h b/core/usbh_core.h
index 903ce14f..bc8eab8f 100644
--- a/core/usbh_core.h
+++ b/core/usbh_core.h
@@ -21,6 +21,8 @@
#include "usb_osal.h"
#include "usbh_hub.h"
#include "usb_memcpy.h"
+#include "usb_ringbuffer.h"
+#include "usb_mempool.h"
#include "usb_dcache.h"
#include "usb_version.h"
diff --git a/osal/idf/usb_osal_idf.c b/osal/idf/usb_osal_idf.c
index b87db74f..69f734e8 100644
--- a/osal/idf/usb_osal_idf.c
+++ b/osal/idf/usb_osal_idf.c
@@ -43,6 +43,11 @@ usb_osal_sem_t usb_osal_sem_create(uint32_t initial_count)
return (usb_osal_sem_t)xSemaphoreCreateCounting(1, initial_count);
}
+usb_osal_sem_t usb_osal_sem_create_counting(uint32_t max_count)
+{
+ return (usb_osal_sem_t)xSemaphoreCreateCounting(0, max_count);
+}
+
void usb_osal_sem_delete(usb_osal_sem_t sem)
{
vSemaphoreDelete((SemaphoreHandle_t)sem);
diff --git a/osal/usb_osal_freertos.c b/osal/usb_osal_freertos.c
index 6bdd883b..b30433cb 100644
--- a/osal/usb_osal_freertos.c
+++ b/osal/usb_osal_freertos.c
@@ -53,6 +53,17 @@ usb_osal_sem_t usb_osal_sem_create(uint32_t initial_count)
return sem;
}
+usb_osal_sem_t usb_osal_sem_create_counting(uint32_t max_count)
+{
+ usb_osal_sem_t sem = (usb_osal_sem_t)xSemaphoreCreateCounting(max_count, 0);
+ if (sem == NULL) {
+ USB_LOG_ERR("Create semaphore failed\r\n");
+ while (1) {
+ }
+ }
+ return sem;
+}
+
void usb_osal_sem_delete(usb_osal_sem_t sem)
{
vSemaphoreDelete((SemaphoreHandle_t)sem);
diff --git a/osal/usb_osal_liteos_m.c b/osal/usb_osal_liteos_m.c
index cda86665..6eaf76d9 100644
--- a/osal/usb_osal_liteos_m.c
+++ b/osal/usb_osal_liteos_m.c
@@ -81,6 +81,11 @@ usb_osal_sem_t usb_osal_sem_create(uint32_t initial_count)
return (usb_osal_sem_t)sem_handle;
}
+usb_osal_sem_t usb_osal_sem_create_counting(uint32_t max_count)
+{
+ return usb_osal_sem_create(0);
+}
+
void usb_osal_sem_delete(usb_osal_sem_t sem)
{
UINT32 sem_handle = (UINT32)sem;
diff --git a/osal/usb_osal_nuttx.c b/osal/usb_osal_nuttx.c
index 1a44fb48..36b53fa2 100644
--- a/osal/usb_osal_nuttx.c
+++ b/osal/usb_osal_nuttx.c
@@ -106,6 +106,11 @@ usb_osal_sem_t usb_osal_sem_create(uint32_t initial_count)
return (usb_osal_sem_t)sem;
}
+usb_osal_sem_t usb_osal_sem_create_counting(uint32_t max_count)
+{
+ return usb_osal_sem_create(0);
+}
+
void usb_osal_sem_delete(usb_osal_sem_t sem)
{
sem_t *__sem = (sem_t *)sem;
diff --git a/osal/usb_osal_rtthread.c b/osal/usb_osal_rtthread.c
index 8454283f..cf0e683e 100644
--- a/osal/usb_osal_rtthread.c
+++ b/osal/usb_osal_rtthread.c
@@ -62,6 +62,11 @@ usb_osal_sem_t usb_osal_sem_create(uint32_t initial_count)
return sem;
}
+usb_osal_sem_t usb_osal_sem_create_counting(uint32_t max_count)
+{
+ return usb_osal_sem_create(0);
+}
+
void usb_osal_sem_delete(usb_osal_sem_t sem)
{
rt_sem_delete((rt_sem_t)sem);
diff --git a/osal/usb_osal_threadx.c b/osal/usb_osal_threadx.c
index 8d6d7c6b..2a6d0057 100644
--- a/osal/usb_osal_threadx.c
+++ b/osal/usb_osal_threadx.c
@@ -74,6 +74,11 @@ usb_osal_sem_t usb_osal_sem_create(uint32_t initial_count)
return (usb_osal_sem_t)sem_ptr;
}
+usb_osal_sem_t usb_osal_sem_create_counting(uint32_t max_count)
+{
+ return usb_osal_sem_create(0);
+}
+
void usb_osal_sem_delete(usb_osal_sem_t sem)
{
tx_semaphore_delete((TX_SEMAPHORE *)sem);
diff --git a/osal/usb_osal_zephyr.c b/osal/usb_osal_zephyr.c
index ce214e6e..b65d7523 100644
--- a/osal/usb_osal_zephyr.c
+++ b/osal/usb_osal_zephyr.c
@@ -104,6 +104,20 @@ usb_osal_sem_t usb_osal_sem_create(uint32_t initial_count)
return (usb_osal_sem_t)sem;
}
+usb_osal_sem_t usb_osal_sem_create_counting(uint32_t max_count)
+{
+ struct k_sem *sem;
+
+ sem = k_malloc(sizeof(struct k_sem));
+ if (sem == NULL) {
+ USB_LOG_ERR("Create semaphore faild\r\n");
+ return NULL;
+ }
+ k_sem_init(sem, 0, max_count);
+
+ return (usb_osal_sem_t)sem;
+}
+
void usb_osal_sem_delete(usb_osal_sem_t sem)
{
while (k_sem_take((struct k_sem *)sem, K_NO_WAIT) != 0) {
diff --git a/third_party/cherrymp/LICENSE b/third_party/cherrymp/LICENSE
deleted file mode 100644
index 261eeb9e..00000000
--- a/third_party/cherrymp/LICENSE
+++ /dev/null
@@ -1,201 +0,0 @@
- Apache License
- Version 2.0, January 2004
- http://www.apache.org/licenses/
-
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
- 1. Definitions.
-
- "License" shall mean the terms and conditions for use, reproduction,
- and distribution as defined by Sections 1 through 9 of this document.
-
- "Licensor" shall mean the copyright owner or entity authorized by
- the copyright owner that is granting the License.
-
- "Legal Entity" shall mean the union of the acting entity and all
- other entities that control, are controlled by, or are under common
- control with that entity. For the purposes of this definition,
- "control" means (i) the power, direct or indirect, to cause the
- direction or management of such entity, whether by contract or
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
- outstanding shares, or (iii) beneficial ownership of such entity.
-
- "You" (or "Your") shall mean an individual or Legal Entity
- exercising permissions granted by this License.
-
- "Source" form shall mean the preferred form for making modifications,
- including but not limited to software source code, documentation
- source, and configuration files.
-
- "Object" form shall mean any form resulting from mechanical
- transformation or translation of a Source form, including but
- not limited to compiled object code, generated documentation,
- and conversions to other media types.
-
- "Work" shall mean the work of authorship, whether in Source or
- Object form, made available under the License, as indicated by a
- copyright notice that is included in or attached to the work
- (an example is provided in the Appendix below).
-
- "Derivative Works" shall mean any work, whether in Source or Object
- form, that is based on (or derived from) the Work and for which the
- editorial revisions, annotations, elaborations, or other modifications
- represent, as a whole, an original work of authorship. For the purposes
- of this License, Derivative Works shall not include works that remain
- separable from, or merely link (or bind by name) to the interfaces of,
- the Work and Derivative Works thereof.
-
- "Contribution" shall mean any work of authorship, including
- the original version of the Work and any modifications or additions
- to that Work or Derivative Works thereof, that is intentionally
- submitted to Licensor for inclusion in the Work by the copyright owner
- or by an individual or Legal Entity authorized to submit on behalf of
- the copyright owner. For the purposes of this definition, "submitted"
- means any form of electronic, verbal, or written communication sent
- to the Licensor or its representatives, including but not limited to
- communication on electronic mailing lists, source code control systems,
- and issue tracking systems that are managed by, or on behalf of, the
- Licensor for the purpose of discussing and improving the Work, but
- excluding communication that is conspicuously marked or otherwise
- designated in writing by the copyright owner as "Not a Contribution."
-
- "Contributor" shall mean Licensor and any individual or Legal Entity
- on behalf of whom a Contribution has been received by Licensor and
- subsequently incorporated within the Work.
-
- 2. Grant of Copyright License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- copyright license to reproduce, prepare Derivative Works of,
- publicly display, publicly perform, sublicense, and distribute the
- Work and such Derivative Works in Source or Object form.
-
- 3. Grant of Patent License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- (except as stated in this section) patent license to make, have made,
- use, offer to sell, sell, import, and otherwise transfer the Work,
- where such license applies only to those patent claims licensable
- by such Contributor that are necessarily infringed by their
- Contribution(s) alone or by combination of their Contribution(s)
- with the Work to which such Contribution(s) was submitted. If You
- institute patent litigation against any entity (including a
- cross-claim or counterclaim in a lawsuit) alleging that the Work
- or a Contribution incorporated within the Work constitutes direct
- or contributory patent infringement, then any patent licenses
- granted to You under this License for that Work shall terminate
- as of the date such litigation is filed.
-
- 4. Redistribution. You may reproduce and distribute copies of the
- Work or Derivative Works thereof in any medium, with or without
- modifications, and in Source or Object form, provided that You
- meet the following conditions:
-
- (a) You must give any other recipients of the Work or
- Derivative Works a copy of this License; and
-
- (b) You must cause any modified files to carry prominent notices
- stating that You changed the files; and
-
- (c) You must retain, in the Source form of any Derivative Works
- that You distribute, all copyright, patent, trademark, and
- attribution notices from the Source form of the Work,
- excluding those notices that do not pertain to any part of
- the Derivative Works; and
-
- (d) If the Work includes a "NOTICE" text file as part of its
- distribution, then any Derivative Works that You distribute must
- include a readable copy of the attribution notices contained
- within such NOTICE file, excluding those notices that do not
- pertain to any part of the Derivative Works, in at least one
- of the following places: within a NOTICE text file distributed
- as part of the Derivative Works; within the Source form or
- documentation, if provided along with the Derivative Works; or,
- within a display generated by the Derivative Works, if and
- wherever such third-party notices normally appear. The contents
- of the NOTICE file are for informational purposes only and
- do not modify the License. You may add Your own attribution
- notices within Derivative Works that You distribute, alongside
- or as an addendum to the NOTICE text from the Work, provided
- that such additional attribution notices cannot be construed
- as modifying the License.
-
- You may add Your own copyright statement to Your modifications and
- may provide additional or different license terms and conditions
- for use, reproduction, or distribution of Your modifications, or
- for any such Derivative Works as a whole, provided Your use,
- reproduction, and distribution of the Work otherwise complies with
- the conditions stated in this License.
-
- 5. Submission of Contributions. Unless You explicitly state otherwise,
- any Contribution intentionally submitted for inclusion in the Work
- by You to the Licensor shall be under the terms and conditions of
- this License, without any additional terms or conditions.
- Notwithstanding the above, nothing herein shall supersede or modify
- the terms of any separate license agreement you may have executed
- with Licensor regarding such Contributions.
-
- 6. Trademarks. This License does not grant permission to use the trade
- names, trademarks, service marks, or product names of the Licensor,
- except as required for reasonable and customary use in describing the
- origin of the Work and reproducing the content of the NOTICE file.
-
- 7. Disclaimer of Warranty. Unless required by applicable law or
- agreed to in writing, Licensor provides the Work (and each
- Contributor provides its Contributions) on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied, including, without limitation, any warranties or conditions
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- PARTICULAR PURPOSE. You are solely responsible for determining the
- appropriateness of using or redistributing the Work and assume any
- risks associated with Your exercise of permissions under this License.
-
- 8. Limitation of Liability. In no event and under no legal theory,
- whether in tort (including negligence), contract, or otherwise,
- unless required by applicable law (such as deliberate and grossly
- negligent acts) or agreed to in writing, shall any Contributor be
- liable to You for damages, including any direct, indirect, special,
- incidental, or consequential damages of any character arising as a
- result of this License or out of the use or inability to use the
- Work (including but not limited to damages for loss of goodwill,
- work stoppage, computer failure or malfunction, or any and all
- other commercial damages or losses), even if such Contributor
- has been advised of the possibility of such damages.
-
- 9. Accepting Warranty or Additional Liability. While redistributing
- the Work or Derivative Works thereof, You may choose to offer,
- and charge a fee for, acceptance of support, warranty, indemnity,
- or other liability obligations and/or rights consistent with this
- License. However, in accepting such obligations, You may act only
- on Your own behalf and on Your sole responsibility, not on behalf
- of any other Contributor, and only if You agree to indemnify,
- defend, and hold each Contributor harmless for any liability
- incurred by, or claims asserted against, such Contributor by reason
- of your accepting any such warranty or additional liability.
-
- END OF TERMS AND CONDITIONS
-
- APPENDIX: How to apply the Apache License to your work.
-
- To apply the Apache License to your work, attach the following
- boilerplate notice, with the fields enclosed by brackets "[]"
- replaced with your own identifying information. (Don't include
- the brackets!) The text should be enclosed in the appropriate
- comment syntax for the file format. We also recommend that a
- file or class name and description of purpose be included on the
- same "printed page" as the copyright notice for easier
- identification within third-party archives.
-
- Copyright [yyyy] [name of copyright owner]
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
diff --git a/third_party/cherrymp/README.md b/third_party/cherrymp/README.md
deleted file mode 100644
index 50e983c4..00000000
--- a/third_party/cherrymp/README.md
+++ /dev/null
@@ -1,3 +0,0 @@
-# CherryMempool
-
-CherryMempool is a tiny block memory pool based on CherryRB, support nonos or os(but we suggest you use in os).
diff --git a/third_party/cherrymp/chry_mempool.c b/third_party/cherrymp/chry_mempool.c
deleted file mode 100644
index 60da247c..00000000
--- a/third_party/cherrymp/chry_mempool.c
+++ /dev/null
@@ -1,243 +0,0 @@
-/*
- * Copyright (c) 2024, sakumisu
- *
- * SPDX-License-Identifier: Apache-2.0
- */
-#include "chry_mempool.h"
-
-/*****************************************************************************
-* @brief init ringbuffer
-*
-* @param[in] rb ringbuffer instance
-* @param[in] pool memory pool address
-* @param[in] size memory size in byte,
-* must be power of 2 !!!
-*
-* @retval int 0:Success -1:Error
-*****************************************************************************/
-static int __chry_ringbuffer_init(chry_mempool_ringbuffer_t *rb, void *pool, uint32_t size)
-{
- if (NULL == rb) {
- return -1;
- }
-
- if (NULL == pool) {
- return -1;
- }
-
- if ((size < 2) || (size & (size - 1))) {
- return -1;
- }
-
- rb->in = 0;
- rb->out = 0;
- rb->mask = size - 1;
- rb->pool = pool;
-
- return 0;
-}
-
-/*****************************************************************************
-* @brief reset ringbuffer, clean all data,
-* should be add lock in multithread
-*
-* @param[in] rb ringbuffer instance
-*
-*****************************************************************************/
-static void __chry_ringbuffer_reset(chry_mempool_ringbuffer_t *rb)
-{
- rb->in = 0;
- rb->out = 0;
-}
-
-/*****************************************************************************
-* @brief write data to ringbuffer,
-* should be add lock in multithread,
-* in single write thread not need lock
-*
-* @param[in] rb ringbuffer instance
-* @param[in] data data pointer
-* @param[in] size size in byte
-*
-* @retval uint32_t actual write size in byte
-*****************************************************************************/
-static uint32_t __chry_ringbuffer_write(chry_mempool_ringbuffer_t *rb, void *data, uint32_t size)
-{
- uint32_t unused;
- uint32_t offset;
- uint32_t remain;
-
- unused = (rb->mask + 1) - (rb->in - rb->out);
-
- if (size > unused) {
- size = unused;
- }
-
- offset = rb->in & rb->mask;
-
- remain = rb->mask + 1 - offset;
- remain = remain > size ? size : remain;
-
- memcpy(((uint8_t *)(rb->pool)) + offset, data, remain);
- memcpy(rb->pool, (uint8_t *)data + remain, size - remain);
-
- rb->in += size;
-
- return size;
-}
-
-/*****************************************************************************
-* @brief peek data from ringbuffer
-* should be add lock in multithread,
-* in single read thread not need lock
-*
-* @param[in] rb ringbuffer instance
-* @param[in] data data pointer
-* @param[in] size size in byte
-*
-* @retval uint32_t actual peek size in byte
-*****************************************************************************/
-static uint32_t __chry_ringbuffer_peek(chry_mempool_ringbuffer_t *rb, void *data, uint32_t size)
-{
- uint32_t used;
- uint32_t offset;
- uint32_t remain;
-
- used = rb->in - rb->out;
- if (size > used) {
- size = used;
- }
-
- offset = rb->out & rb->mask;
-
- remain = rb->mask + 1 - offset;
- remain = remain > size ? size : remain;
-
- memcpy(data, ((uint8_t *)(rb->pool)) + offset, remain);
- memcpy((uint8_t *)data + remain, rb->pool, size - remain);
-
- return size;
-}
-
-/*****************************************************************************
-* @brief read data from ringbuffer
-* should be add lock in multithread,
-* in single read thread not need lock
-*
-* @param[in] rb ringbuffer instance
-* @param[in] data data pointer
-* @param[in] size size in byte
-*
-* @retval uint32_t actual read size in byte
-*****************************************************************************/
-static uint32_t __chry_ringbuffer_read(chry_mempool_ringbuffer_t *rb, void *data, uint32_t size)
-{
- size = __chry_ringbuffer_peek(rb, data, size);
- rb->out += size;
- return size;
-}
-
-int chry_mempool_create(struct chry_mempool *pool, void *block, uint32_t block_size, uint32_t block_count)
-{
- uintptr_t *item;
-
- if (block_count > CONFIG_CHRY_MEMPOOL_MAX_BLOCK_COUNT) {
- return -1;
- }
-
- if (block_size % 4) {
- return -1;
- }
-
- if (__chry_ringbuffer_init(&pool->in, pool->in_buf, sizeof(uintptr_t) * block_count) == -1) {
- return -1;
- }
-
- if (__chry_ringbuffer_init(&pool->out, pool->out_buf, sizeof(uintptr_t) * block_count) == -1) {
- return -1;
- }
-
- pool->out_sem = chry_mempool_osal_sem_create(block_count);
- if (pool->out_sem == NULL) {
- return -1;
- }
-
- pool->block = block;
- pool->block_size = block_size;
- pool->block_count = block_count;
-
- for (uint32_t i = 0; i < pool->block_count; i++) {
- item = (uintptr_t *)((uint8_t *)pool->block + i * pool->block_size);
- chry_mempool_free(pool, item);
- }
-
- return 0;
-}
-
-void chry_mempool_delete(struct chry_mempool *pool)
-{
- __chry_ringbuffer_reset(&pool->in);
- __chry_ringbuffer_reset(&pool->out);
- chry_mempool_osal_sem_delete(pool->out_sem);
-}
-
-uintptr_t *chry_mempool_alloc(struct chry_mempool *pool)
-{
- uintptr_t *addr;
- uint32_t len;
-
- len = __chry_ringbuffer_read(&pool->in, (uintptr_t *)&addr, sizeof(uintptr_t));
- if (len == 0) {
- return NULL;
- } else {
- return addr;
- }
-}
-
-int chry_mempool_free(struct chry_mempool *pool, uintptr_t *item)
-{
- uintptr_t addr;
-
- addr = (uintptr_t)item;
- return __chry_ringbuffer_write(&pool->in, &addr, sizeof(uintptr_t));
-}
-
-int chry_mempool_send(struct chry_mempool *pool, uintptr_t *item)
-{
- uintptr_t addr;
-
- addr = (uintptr_t)item;
- __chry_ringbuffer_write(&pool->out, &addr, sizeof(uintptr_t));
- return chry_mempool_osal_sem_give(pool->out_sem);
-}
-
-int chry_mempool_recv(struct chry_mempool *pool, uintptr_t **item, uint32_t timeout)
-{
- uint32_t len;
- int ret;
-
- ret = chry_mempool_osal_sem_take(pool->out_sem, timeout);
- if (ret < 0) {
- return -1;
- }
-
- len = __chry_ringbuffer_read(&pool->out, (uintptr_t *)item, sizeof(uintptr_t));
- if (len == 0) {
- return -1;
- } else {
- return 0;
- }
-}
-
-void chry_mempool_reset(struct chry_mempool *pool)
-{
- uintptr_t *item;
-
- __chry_ringbuffer_reset(&pool->in);
- __chry_ringbuffer_reset(&pool->out);
-
- for (uint32_t i = 0; i < pool->block_count; i++) {
- item = (uintptr_t *)((uint8_t *)pool->block + i * pool->block_size);
- chry_mempool_free(pool, item);
- }
-} \ No newline at end of file
diff --git a/third_party/cherrymp/chry_mempool.h b/third_party/cherrymp/chry_mempool.h
deleted file mode 100644
index 1132454c..00000000
--- a/third_party/cherrymp/chry_mempool.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (c) 2024, sakumisu
- *
- * SPDX-License-Identifier: Apache-2.0
- */
-#ifndef CHRY_MEMPOOL_H
-#define CHRY_MEMPOOL_H
-
-#include <stdint.h>
-#include <string.h>
-#include <stdbool.h>
-
-typedef void *chry_mempool_osal_sem_t;
-
-#ifndef CONFIG_CHRY_MEMPOOL_MAX_BLOCK_COUNT
-#define CONFIG_CHRY_MEMPOOL_MAX_BLOCK_COUNT 128
-#endif
-
-typedef struct {
- uint32_t in; /*!< Define the write pointer. */
- uint32_t out; /*!< Define the read pointer. */
- uint32_t mask; /*!< Define the write and read pointer mask. */
- void *pool; /*!< Define the memory pointer. */
-} chry_mempool_ringbuffer_t;
-
-struct chry_mempool {
- chry_mempool_ringbuffer_t in;
- chry_mempool_ringbuffer_t out;
- chry_mempool_osal_sem_t out_sem;
-
- void *block;
- uint32_t block_size;
- uint32_t block_count;
- uint8_t in_buf[sizeof(uintptr_t) * CONFIG_CHRY_MEMPOOL_MAX_BLOCK_COUNT];
- uint8_t out_buf[sizeof(uintptr_t) * CONFIG_CHRY_MEMPOOL_MAX_BLOCK_COUNT];
-};
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-chry_mempool_osal_sem_t chry_mempool_osal_sem_create(uint32_t max_count);
-void chry_mempool_osal_sem_delete(chry_mempool_osal_sem_t sem);
-int chry_mempool_osal_sem_take(chry_mempool_osal_sem_t sem, uint32_t timeout);
-int chry_mempool_osal_sem_give(chry_mempool_osal_sem_t sem);
-
-int chry_mempool_create(struct chry_mempool *pool, void *block, uint32_t block_size, uint32_t block_count);
-uintptr_t *chry_mempool_alloc(struct chry_mempool *pool);
-int chry_mempool_free(struct chry_mempool *pool, uintptr_t *item);
-int chry_mempool_send(struct chry_mempool *pool, uintptr_t *item);
-int chry_mempool_recv(struct chry_mempool *pool, uintptr_t **item, uint32_t timeout);
-void chry_mempool_reset(struct chry_mempool *pool);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif \ No newline at end of file
diff --git a/third_party/cherrymp/chry_mempool_osal_freertos.c b/third_party/cherrymp/chry_mempool_osal_freertos.c
deleted file mode 100644
index 1db9aa54..00000000
--- a/third_party/cherrymp/chry_mempool_osal_freertos.c
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright (c) 2024, sakumisu
- *
- * SPDX-License-Identifier: Apache-2.0
- */
-#include "chry_mempool.h"
-#include <FreeRTOS.h>
-#include "semphr.h"
-
-chry_mempool_osal_sem_t chry_mempool_osal_sem_create(uint32_t max_count)
-{
- return (chry_mempool_osal_sem_t)xSemaphoreCreateCounting(max_count, 0);
-}
-
-void chry_mempool_osal_sem_delete(chry_mempool_osal_sem_t sem)
-{
- vSemaphoreDelete((SemaphoreHandle_t)sem);
-}
-
-int chry_mempool_osal_sem_take(chry_mempool_osal_sem_t sem, uint32_t timeout)
-{
- BaseType_t xHigherPriorityTaskWoken = pdFALSE;
- int ret;
-
- if (xPortIsInsideInterrupt()) {
- ret = xSemaphoreTakeFromISR((SemaphoreHandle_t)sem, &xHigherPriorityTaskWoken);
- if (ret == pdPASS) {
- portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
- }
- return (ret == pdPASS) ? 0 : -1;
- } else {
- return (xSemaphoreTake((SemaphoreHandle_t)sem, pdMS_TO_TICKS(timeout)) == pdPASS) ? 0 : -1;
- }
-}
-
-int chry_mempool_osal_sem_give(chry_mempool_osal_sem_t sem)
-{
- BaseType_t xHigherPriorityTaskWoken = pdFALSE;
- int ret;
-
- if (xPortIsInsideInterrupt()) {
- ret = xSemaphoreGiveFromISR((SemaphoreHandle_t)sem, &xHigherPriorityTaskWoken);
- if (ret == pdPASS) {
- portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
- }
- } else {
- ret = xSemaphoreGive((SemaphoreHandle_t)sem);
- }
-
- return (ret == pdPASS) ? 0 : -1;
-} \ No newline at end of file
diff --git a/third_party/cherrymp/chry_mempool_osal_nonos.c b/third_party/cherrymp/chry_mempool_osal_nonos.c
deleted file mode 100644
index 7bd319b3..00000000
--- a/third_party/cherrymp/chry_mempool_osal_nonos.c
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright (c) 2024, sakumisu
- *
- * SPDX-License-Identifier: Apache-2.0
- */
-#include "chry_mempool.h"
-#include "stdlib.h"
-
-chry_mempool_osal_sem_t chry_mempool_osal_sem_create(uint32_t max_count)
-{
- return (chry_mempool_osal_sem_t)1;
-}
-
-void chry_mempool_osal_sem_delete(chry_mempool_osal_sem_t sem)
-{
-}
-
-int chry_mempool_osal_sem_take(chry_mempool_osal_sem_t sem, uint32_t timeout)
-{
- return 0;
-}
-
-int chry_mempool_osal_sem_give(chry_mempool_osal_sem_t sem)
-{
- return 0;
-} \ No newline at end of file
diff --git a/third_party/cherrymp/chry_mempool_osal_rtthread.c b/third_party/cherrymp/chry_mempool_osal_rtthread.c
deleted file mode 100644
index 86042e29..00000000
--- a/third_party/cherrymp/chry_mempool_osal_rtthread.c
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (c) 2024, sakumisu
- *
- * SPDX-License-Identifier: Apache-2.0
- */
-#include "chry_mempool.h"
-#include <rtthread.h>
-#include <rthw.h>
-
-chry_mempool_osal_sem_t chry_mempool_osal_sem_create(uint32_t max_count)
-{
- return (chry_mempool_osal_sem_t)rt_sem_create("chry_mempoolh_sem", max_count, RT_IPC_FLAG_FIFO);
-}
-
-void chry_mempool_osal_sem_delete(chry_mempool_osal_sem_t sem)
-{
- rt_sem_delete((rt_sem_t)sem);
-}
-
-int chry_mempool_osal_sem_take(chry_mempool_osal_sem_t sem, uint32_t timeout)
-{
- int ret = 0;
- rt_err_t result = RT_EOK;
-
- if (timeout == 0xfffffff) {
- result = rt_sem_take((rt_sem_t)sem, RT_WAITING_FOREVER);
- } else {
- result = rt_sem_take((rt_sem_t)sem, rt_tick_from_millisecond(timeout));
- }
- if (result == -RT_ETIMEOUT) {
- ret = -1;
- } else if (result == -RT_ERROR) {
- ret = -1;
- } else {
- ret = 0;
- }
-
- return (int)ret;
-}
-
-int chry_mempool_osal_sem_give(chry_mempool_osal_sem_t sem)
-{
- return (int)rt_sem_release((rt_sem_t)sem);
-} \ No newline at end of file
diff --git a/third_party/cherryrb/CHANGELOG.md b/third_party/cherryrb/CHANGELOG.md
deleted file mode 100644
index 760cd5cc..00000000
--- a/third_party/cherryrb/CHANGELOG.md
+++ /dev/null
@@ -1,9 +0,0 @@
-# Change Log
-
-## [1.0.0] - 2023-06-28:
-
-All changes
-
-### Added
- - first commit
- - add linear r/w setup done api, for dma use \ No newline at end of file
diff --git a/third_party/cherryrb/LICENSE b/third_party/cherryrb/LICENSE
deleted file mode 100644
index 261eeb9e..00000000
--- a/third_party/cherryrb/LICENSE
+++ /dev/null
@@ -1,201 +0,0 @@
- Apache License
- Version 2.0, January 2004
- http://www.apache.org/licenses/
-
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
- 1. Definitions.
-
- "License" shall mean the terms and conditions for use, reproduction,
- and distribution as defined by Sections 1 through 9 of this document.
-
- "Licensor" shall mean the copyright owner or entity authorized by
- the copyright owner that is granting the License.
-
- "Legal Entity" shall mean the union of the acting entity and all
- other entities that control, are controlled by, or are under common
- control with that entity. For the purposes of this definition,
- "control" means (i) the power, direct or indirect, to cause the
- direction or management of such entity, whether by contract or
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
- outstanding shares, or (iii) beneficial ownership of such entity.
-
- "You" (or "Your") shall mean an individual or Legal Entity
- exercising permissions granted by this License.
-
- "Source" form shall mean the preferred form for making modifications,
- including but not limited to software source code, documentation
- source, and configuration files.
-
- "Object" form shall mean any form resulting from mechanical
- transformation or translation of a Source form, including but
- not limited to compiled object code, generated documentation,
- and conversions to other media types.
-
- "Work" shall mean the work of authorship, whether in Source or
- Object form, made available under the License, as indicated by a
- copyright notice that is included in or attached to the work
- (an example is provided in the Appendix below).
-
- "Derivative Works" shall mean any work, whether in Source or Object
- form, that is based on (or derived from) the Work and for which the
- editorial revisions, annotations, elaborations, or other modifications
- represent, as a whole, an original work of authorship. For the purposes
- of this License, Derivative Works shall not include works that remain
- separable from, or merely link (or bind by name) to the interfaces of,
- the Work and Derivative Works thereof.
-
- "Contribution" shall mean any work of authorship, including
- the original version of the Work and any modifications or additions
- to that Work or Derivative Works thereof, that is intentionally
- submitted to Licensor for inclusion in the Work by the copyright owner
- or by an individual or Legal Entity authorized to submit on behalf of
- the copyright owner. For the purposes of this definition, "submitted"
- means any form of electronic, verbal, or written communication sent
- to the Licensor or its representatives, including but not limited to
- communication on electronic mailing lists, source code control systems,
- and issue tracking systems that are managed by, or on behalf of, the
- Licensor for the purpose of discussing and improving the Work, but
- excluding communication that is conspicuously marked or otherwise
- designated in writing by the copyright owner as "Not a Contribution."
-
- "Contributor" shall mean Licensor and any individual or Legal Entity
- on behalf of whom a Contribution has been received by Licensor and
- subsequently incorporated within the Work.
-
- 2. Grant of Copyright License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- copyright license to reproduce, prepare Derivative Works of,
- publicly display, publicly perform, sublicense, and distribute the
- Work and such Derivative Works in Source or Object form.
-
- 3. Grant of Patent License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- (except as stated in this section) patent license to make, have made,
- use, offer to sell, sell, import, and otherwise transfer the Work,
- where such license applies only to those patent claims licensable
- by such Contributor that are necessarily infringed by their
- Contribution(s) alone or by combination of their Contribution(s)
- with the Work to which such Contribution(s) was submitted. If You
- institute patent litigation against any entity (including a
- cross-claim or counterclaim in a lawsuit) alleging that the Work
- or a Contribution incorporated within the Work constitutes direct
- or contributory patent infringement, then any patent licenses
- granted to You under this License for that Work shall terminate
- as of the date such litigation is filed.
-
- 4. Redistribution. You may reproduce and distribute copies of the
- Work or Derivative Works thereof in any medium, with or without
- modifications, and in Source or Object form, provided that You
- meet the following conditions:
-
- (a) You must give any other recipients of the Work or
- Derivative Works a copy of this License; and
-
- (b) You must cause any modified files to carry prominent notices
- stating that You changed the files; and
-
- (c) You must retain, in the Source form of any Derivative Works
- that You distribute, all copyright, patent, trademark, and
- attribution notices from the Source form of the Work,
- excluding those notices that do not pertain to any part of
- the Derivative Works; and
-
- (d) If the Work includes a "NOTICE" text file as part of its
- distribution, then any Derivative Works that You distribute must
- include a readable copy of the attribution notices contained
- within such NOTICE file, excluding those notices that do not
- pertain to any part of the Derivative Works, in at least one
- of the following places: within a NOTICE text file distributed
- as part of the Derivative Works; within the Source form or
- documentation, if provided along with the Derivative Works; or,
- within a display generated by the Derivative Works, if and
- wherever such third-party notices normally appear. The contents
- of the NOTICE file are for informational purposes only and
- do not modify the License. You may add Your own attribution
- notices within Derivative Works that You distribute, alongside
- or as an addendum to the NOTICE text from the Work, provided
- that such additional attribution notices cannot be construed
- as modifying the License.
-
- You may add Your own copyright statement to Your modifications and
- may provide additional or different license terms and conditions
- for use, reproduction, or distribution of Your modifications, or
- for any such Derivative Works as a whole, provided Your use,
- reproduction, and distribution of the Work otherwise complies with
- the conditions stated in this License.
-
- 5. Submission of Contributions. Unless You explicitly state otherwise,
- any Contribution intentionally submitted for inclusion in the Work
- by You to the Licensor shall be under the terms and conditions of
- this License, without any additional terms or conditions.
- Notwithstanding the above, nothing herein shall supersede or modify
- the terms of any separate license agreement you may have executed
- with Licensor regarding such Contributions.
-
- 6. Trademarks. This License does not grant permission to use the trade
- names, trademarks, service marks, or product names of the Licensor,
- except as required for reasonable and customary use in describing the
- origin of the Work and reproducing the content of the NOTICE file.
-
- 7. Disclaimer of Warranty. Unless required by applicable law or
- agreed to in writing, Licensor provides the Work (and each
- Contributor provides its Contributions) on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied, including, without limitation, any warranties or conditions
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- PARTICULAR PURPOSE. You are solely responsible for determining the
- appropriateness of using or redistributing the Work and assume any
- risks associated with Your exercise of permissions under this License.
-
- 8. Limitation of Liability. In no event and under no legal theory,
- whether in tort (including negligence), contract, or otherwise,
- unless required by applicable law (such as deliberate and grossly
- negligent acts) or agreed to in writing, shall any Contributor be
- liable to You for damages, including any direct, indirect, special,
- incidental, or consequential damages of any character arising as a
- result of this License or out of the use or inability to use the
- Work (including but not limited to damages for loss of goodwill,
- work stoppage, computer failure or malfunction, or any and all
- other commercial damages or losses), even if such Contributor
- has been advised of the possibility of such damages.
-
- 9. Accepting Warranty or Additional Liability. While redistributing
- the Work or Derivative Works thereof, You may choose to offer,
- and charge a fee for, acceptance of support, warranty, indemnity,
- or other liability obligations and/or rights consistent with this
- License. However, in accepting such obligations, You may act only
- on Your own behalf and on Your sole responsibility, not on behalf
- of any other Contributor, and only if You agree to indemnify,
- defend, and hold each Contributor harmless for any liability
- incurred by, or claims asserted against, such Contributor by reason
- of your accepting any such warranty or additional liability.
-
- END OF TERMS AND CONDITIONS
-
- APPENDIX: How to apply the Apache License to your work.
-
- To apply the Apache License to your work, attach the following
- boilerplate notice, with the fields enclosed by brackets "[]"
- replaced with your own identifying information. (Don't include
- the brackets!) The text should be enclosed in the appropriate
- comment syntax for the file format. We also recommend that a
- file or class name and description of purpose be included on the
- same "printed page" as the copyright notice for easier
- identification within third-party archives.
-
- Copyright [yyyy] [name of copyright owner]
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
diff --git a/third_party/cherryrb/README.md b/third_party/cherryrb/README.md
deleted file mode 100644
index df04502c..00000000
--- a/third_party/cherryrb/README.md
+++ /dev/null
@@ -1,206 +0,0 @@
-# CherryRingBuffer
-
-[中文版](./README_zh.md)
-
-CherryRingBuffer is an efficient and easy-to-use ringbuffer that is based on the same principle as kfifo.
-
-## Brief
-
-### 1.Create and initialize a RingBuffer
-```c
-chry_ringbuffer_t rb;
-uint8_t mempool[1024];
-
-int main(void)
-{
- /**
- * Note that the third parameter of the init function is
- * the size of the memory pool (in bytes)
- * It is also the depth of the ringbuffer,
- * which must be a power of 2 !!!
- * Example: 4, 16, 32, 64, 128, 1024, 8192, 65536, etc.
- */
- if(0==chry_ringbuffer_init(&rb, mempool, 1024)){
- printf("success\r\n");
- }else{
- printf("error\r\n");
- }
-
- return 0;
-}
-```
-
-### 2.Lock-free use of the producer-consumer model
-The read and write APIs, except for overwrite, do not require locking if they satisfy the requirement that the ringbuffer is read in only one thread and written in only one thread, because the read and write operations only operate on the read or write pointers separately.
-```c
-void thread_producer(void* param)
-{
- char *data = "hello world";
- while(1){
- uint32_t len = chry_ringbuffer_write(&rb, data, 11);
- if(11 == len){
- printf("[P] write success\r\n");
- }else{
- printf("[P] write faild, only write %d byte\r\n", len);
- }
- vTaskDelay(100);
- }
-}
-
-void thread_consumer(void* param)
-{
- char data[1024];
- while(1){
- uint32_t len =chry_ringbuffer_read(&rb, data, 11);
- if (len){
- printf("[C] read success, read %d byte\r\n",len);
- data[11]='\0';
- printf("%s\r\n",data);
- }else{
- printf("[C] read faild, no data in ringbuffer\r\n");
- }
- vTaskDelay(100);
- }
-}
-```
-
-### 3. API Introduction
-
-```c
-
- /**
- * Used to clear ringbuffer, while operating read and write pointers,
- * multi-threaded need to add lock
- */
- chry_ringbuffer_reset(&rb);
-
- /**
- * Used to clear ringbuffer, only operates on read pointers,
- * called without locking in the only read thread
- */
- chry_ringbuffer_reset_read(&rb);
-
- /**
- * Get the total ringbuffer size (bytes)
- */
- uint32_t size = chry_ringbuffer_get_size(&rb);
-
- /**
- * Get ringbuffer used size (bytes)
- */
- uint32_t used = chry_ringbuffer_get_used(&rb);
-
- /**
- * Get ringbuffer free size (bytes)
- */
- uint32_t free = chry_ringbuffer_get_free(&rb);
-
- /**
- * Check if ringbuffer is full, full returns true
- */
- bool is_full = chry_ringbuffer_check_full(&rb);
-
- /**
- * Check if ringbuffer is empty, empty returns true
- */
- bool is_empty = chry_ringbuffer_check_empty(&rb);
-
- uint8_t data = 0x55;
-
- /**
- * Write a byte
- * No locking on the only write thread call
- * Success returns true, full returns false
- */
- chry_ringbuffer_write_byte(&rb, data);
-
- /**
- * overwriting write one byte,
- * when ringbuffer is full will overwrite the earliest data
- * The non-full case is the same as chry_ringbuffer_write_byte
- * This API may operate on read and write pointers at the same time,
- * so multiple threads need to add locks
- * Always return true
- */
- chry_ringbuffer_overwrite_byte(&rb, data);
-
- /**
- * Peek one byte from ringbuffer
- * The data is still retained in the ringbuffer
- * No locking on the only read thread call
- * Success returns true, empty returns false
- */
- chry_ringbuffer_peek_byte(&rb, &data);
-
- /**
- * Read one byte from ringbuffer
- * Data retrieval from ringbuffer
- * No locking on the only read thread call
- * Success returns true, empty returns false
- */
- chry_ringbuffer_read_byte(&rb, &data);
-
- /**
- * Drop one byte from ringbuffer
- * Data retrieval from ringbuffer
- * No locking on the only read thread call
- * Success returns true, empty returns false
- */
- chry_ringbuffer_drop_byte(&rb);
-
- /**
- * Write multi-byte, otherwise same as single byte write
- * Returns the actual length of the write
- */
- chry_ringbuffer_write(&rb, data, 1);
-
- /**
- * Overwrite multi-byte, otherwise same as single byte overwrite
- * Returns the actual length of the write
- */
- chry_ringbuffer_overwrite(&rb, data, 1);
-
- /**
- * Peek multiple bytes, otherwise same as single byte peek
- * Returns the length of the actual peek
- */
- chry_ringbuffer_peek(&rb, data, 1);
-
- /**
- * Read multiple bytes, otherwise same as single byte read
- * Returns the length of the actual read
- */
- chry_ringbuffer_read(&rb, data, 1);
-
- /**
- * Drop multiple bytes, otherwise same as single byte Drop
- * Returns the length of the actual drop
- */
- chry_ringbuffer_drop(&rb, 1);
-
- void *pdata;
- uint32_t size;
-
- /**
- * For dma start, get read memory address and max linear read size
- */
- pdata = chry_ringbuffer_linear_read_setup(&rb, &size);
-
- /**
- * For dma done, add read pointer
- * Returns the length of the actual add
- */
- size = chry_ringbuffer_linear_read_done(&rb, 512);
-
- /**
- * For dma start, get write memory address and max linear write size
- */
- pdata = chry_ringbuffer_linear_write_setup(&rb, &size);
-
- /**
- * For dma done, add write pointer
- * Returns the length of the actual add
- */
- size = chry_ringbuffer_linear_write_done(&rb, 512);
-
-``` \ No newline at end of file
diff --git a/third_party/cherryrb/README_zh.md b/third_party/cherryrb/README_zh.md
deleted file mode 100644
index 16bda1ed..00000000
--- a/third_party/cherryrb/README_zh.md
+++ /dev/null
@@ -1,200 +0,0 @@
-# CherryRingBuffer
-
-[English](./README.md)
-
-CherryRingBuffer 是一个的高效、易用的环形缓冲区,其原理与kfifo一致。
-
-## 简介
-
-### 1.创建并初始化一个RingBuffer
-```c
-chry_ringbuffer_t rb;
-uint8_t mempool[1024];
-
-int main(void)
-{
- /**
- * 需要注意的点是,init 函数第三个参数是内存池的大小(字节为单位)
- * 也是ringbuffer的深度,必须为 2 的幂次!!!。
- * 例如 4、16、32、64、128、1024、8192、65536等
- */
- if(0 == chry_ringbuffer_init(&rb, mempool, 1024)){
- printf("success\r\n");
- }else{
- printf("error\r\n");
- }
-
- return 0;
-}
-```
-
-### 2.生产者消费者模型的无锁使用
-读和写的API除了overwrite外,如果满足ringbuffer只在一个线程里进行读,并且只在一个线程里面写,那么无须加锁,因为读和写操作只单独操作读或者写指针。
-```c
-void thread_producer(void* param)
-{
- char *data = "hello world";
- while(1){
- uint32_t len = chry_ringbuffer_write(&rb, data, 11);
- if(11 == len){
- printf("[P] write success\r\n");
- }else{
- printf("[P] write faild, only write %d byte\r\n", len);
- }
- vTaskDelay(100);
- }
-}
-
-void thread_consumer(void* param)
-{
- char data[1024];
- while(1){
- uint32_t len =chry_ringbuffer_read(&rb, data, 11);
- if (len){
- printf("[C] read success, read %d byte\r\n",len);
- data[11]='\0';
- printf("%s\r\n",data);
- }else{
- printf("[C] read faild, no data in ringbuffer\r\n");
- }
- vTaskDelay(100);
- }
-}
-```
-
-### 3. API简介
-
-```c
-
- /**
- * 用于清空,同时操作读写指针,多线程需要加锁
- */
- chry_ringbuffer_reset(&rb);
-
- /**
- * 用于清空,只操作读指针,在唯一的读线程调用无须加锁
- */
- chry_ringbuffer_reset_read(&rb);
-
- /**
- * 获取ringbuffer总大小(字节)
- */
- uint32_t size = chry_ringbuffer_get_size(&rb);
-
- /**
- * 获取ringbuffer使用大小(字节)
- */
- uint32_t used = chry_ringbuffer_get_used(&rb);
-
- /**
- * 获取ringbuffer空闲大小(字节)
- */
- uint32_t free = chry_ringbuffer_get_free(&rb);
-
- /**
- * 检查ringbuffer是否为满,满返回true
- */
- bool is_full = chry_ringbuffer_check_full(&rb);
-
- /**
- * 检查ringbuffer是否为空,空返回true
- */
- bool is_empty = chry_ringbuffer_check_empty(&rb);
-
- uint8_t data = 0x55;
-
- /**
- * 写一字节
- * 在唯一的写线程调用无须加锁
- * 写成功返回true,满返回false
- */
- chry_ringbuffer_write_byte(&rb, data);
-
- /**
- * 覆盖写一字节,当ringbuffer满的时候会覆盖最早的数据,
- * 非满情况与 chry_ringbuffer_write_byte 一致。
- * 此API可能会同时操作读写指针,所以多线程需要加锁
- * 始终返回true
- */
- chry_ringbuffer_overwrite_byte(&rb, data);
-
- /**
- * 从ringbuffer中复制出来一字节
- * 数据仍然保留在ringbuffer中
- * 在唯一的读线程调用无须加锁
- * 成功返回true,空返回false
- */
- chry_ringbuffer_peek_byte(&rb, &data);
-
- /**
- * 从ringbuffer中读取出来一字节
- * 数据从ringbuffer中取出
- * 在唯一的读线程调用无须加锁
- * 成功返回true,空返回false
- */
- chry_ringbuffer_read_byte(&rb, &data);
-
- /**
- * 丢弃ringbuffer中一字节
- * 数据从ringbuffer中取出
- * 在唯一的读线程调用无须加锁
- * 成功返回true,空返回false
- */
- chry_ringbuffer_drop_byte(&rb);
-
- /**
- * 写多字节,其他与单字节写相同
- * 返回实际写入的长度
- */
- chry_ringbuffer_write(&rb, data, 1);
-
- /**
- * 覆盖写多字节,其他与单字节覆盖写相同
- * 返回实际写入的长度
- */
- chry_ringbuffer_overwrite(&rb, data, 1);
-
- /**
- * 复制多字节,其他与单字节复制相同
- * 返回实际复制的长度
- */
- chry_ringbuffer_peek(&rb, data, 1);
-
- /**
- * 读取多字节,其他与单字节读取相同
- * 返回实际读取的长度
- */
- chry_ringbuffer_read(&rb, data, 1);
-
- /**
- * 丢弃多字节,其他与单字节丢弃相同
- * 返回实际丢弃的长度
- */
- chry_ringbuffer_drop(&rb, 1);
-
- void *pdata;
- uint32_t size;
-
- /**
- * 用于启动DMA,获取读取起始内存地址和最大线性可读取长度
- */
- pdata = chry_ringbuffer_linear_read_setup(&rb, &size);
-
- /**
- * 用于DMA完成,增加读指针
- * 返回实际增加长度
- */
- size = chry_ringbuffer_linear_read_done(&rb, 512);
-
- /**
- * 用于启动DMA,获取写入起始内存地址和最大线性可写入长度
- */
- pdata = chry_ringbuffer_linear_write_setup(&rb, &size);
-
- /**
- * 用于DMA完成,增加写指针
- * 返回实际增加长度
- */
- size = chry_ringbuffer_linear_write_done(&rb, 512);
-
-``` \ No newline at end of file
diff --git a/third_party/cherryrb/chry_ringbuffer.h b/third_party/cherryrb/chry_ringbuffer.h
deleted file mode 100644
index d40f74d2..00000000
--- a/third_party/cherryrb/chry_ringbuffer.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (c) 2022, Egahp
- *
- * SPDX-License-Identifier: Apache-2.0
- */
-
-#ifndef CHRY_RINGBUFFER_H
-#define CHRY_RINGBUFFER_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include <stdint.h>
-#include <stdbool.h>
-
-typedef struct {
- uint32_t in; /*!< Define the write pointer. */
- uint32_t out; /*!< Define the read pointer. */
- uint32_t mask; /*!< Define the write and read pointer mask. */
- void *pool; /*!< Define the memory pointer. */
-} chry_ringbuffer_t;
-
-extern int chry_ringbuffer_init(chry_ringbuffer_t *rb, void *pool, uint32_t size);
-extern void chry_ringbuffer_reset(chry_ringbuffer_t *rb);
-extern void chry_ringbuffer_reset_read(chry_ringbuffer_t *rb);
-
-extern uint32_t chry_ringbuffer_get_size(chry_ringbuffer_t *rb);
-extern uint32_t chry_ringbuffer_get_used(chry_ringbuffer_t *rb);
-extern uint32_t chry_ringbuffer_get_free(chry_ringbuffer_t *rb);
-
-extern bool chry_ringbuffer_check_full(chry_ringbuffer_t *rb);
-extern bool chry_ringbuffer_check_empty(chry_ringbuffer_t *rb);
-
-extern bool chry_ringbuffer_write_byte(chry_ringbuffer_t *rb, uint8_t byte);
-extern bool chry_ringbuffer_overwrite_byte(chry_ringbuffer_t *rb, uint8_t byte);
-extern bool chry_ringbuffer_peek_byte(chry_ringbuffer_t *rb, uint8_t *byte);
-extern bool chry_ringbuffer_read_byte(chry_ringbuffer_t *rb, uint8_t *byte);
-extern bool chry_ringbuffer_drop_byte(chry_ringbuffer_t *rb);
-
-extern uint32_t chry_ringbuffer_write(chry_ringbuffer_t *rb, void *data, uint32_t size);
-extern uint32_t chry_ringbuffer_overwrite(chry_ringbuffer_t *rb, void *data, uint32_t size);
-extern uint32_t chry_ringbuffer_peek(chry_ringbuffer_t *rb, void *data, uint32_t size);
-extern uint32_t chry_ringbuffer_read(chry_ringbuffer_t *rb, void *data, uint32_t size);
-extern uint32_t chry_ringbuffer_drop(chry_ringbuffer_t *rb, uint32_t size);
-
-extern void *chry_ringbuffer_linear_write_setup(chry_ringbuffer_t *rb, uint32_t *size);
-extern void *chry_ringbuffer_linear_read_setup(chry_ringbuffer_t *rb, uint32_t *size);
-extern uint32_t chry_ringbuffer_linear_write_done(chry_ringbuffer_t *rb, uint32_t size);
-extern uint32_t chry_ringbuffer_linear_read_done(chry_ringbuffer_t *rb, uint32_t size);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif