diff options
| author | sakumisu <[email protected]> | 2024-08-15 17:51:54 +0800 |
|---|---|---|
| committer | sakumisu <[email protected]> | 2024-08-15 17:51:54 +0800 |
| commit | 03f8711b205e934c205e13ee01732c2920a87531 (patch) | |
| tree | 6af0417030f38d8e8f022a10121345895734a3cc | |
| parent | 393756f111d18e92e48268b09e0d7f4ed37de636 (diff) | |
update(cherrymp): rename to cherrymp
| -rw-r--r-- | cherryusb.cmake | 16 | ||||
| -rw-r--r-- | third_party/cherrymp/chry_mempool.c | 60 | ||||
| -rw-r--r-- | third_party/cherrymp/chry_mempool.h | 19 | ||||
| -rw-r--r-- | third_party/cherrymp/usbh_uvc_queue.c (renamed from third_party/cherrypool/usbh_uvc_queue.c) | 15 | ||||
| -rw-r--r-- | third_party/cherrymp/usbh_uvc_queue.h (renamed from third_party/cherrypool/usbh_uvc_queue.h) | 2 | ||||
| -rw-r--r-- | third_party/cherrypool/chry_pool.c | 49 | ||||
| -rw-r--r-- | third_party/cherrypool/chry_pool.h | 19 |
7 files changed, 98 insertions, 82 deletions
diff --git a/cherryusb.cmake b/cherryusb.cmake index a95deece..91b6c3d2 100644 --- a/cherryusb.cmake +++ b/cherryusb.cmake @@ -146,11 +146,6 @@ if(CONFIG_CHERRYUSB_HOST) endif() if(CONFIG_CHERRYUSB_HOST_VIDEO) list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/class/video/usbh_video.c) - list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/third_party/cherryrb/chry_ringbuffer.c) - list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/third_party/cherrypool/chry_pool.c) - list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/third_party/cherrypool/usbh_uvc_queue.c) - list(APPEND cherryusb_incs ${CMAKE_CURRENT_LIST_DIR}/third_party/cherryrb) - list(APPEND cherryusb_incs ${CMAKE_CURRENT_LIST_DIR}/third_party/cherrypool) endif() if(CONFIG_CHERRYUSB_HOST_AUDIO) list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/class/audio/usbh_audio.c) @@ -268,4 +263,15 @@ if(DEFINED CONFIG_CHERRYUSB_OSAL) list(APPEND cherryusb_incs ${CMAKE_CURRENT_LIST_DIR}/osal/idf) list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/osal/idf/usb_osal_idf.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_srcs ${CMAKE_CURRENT_LIST_DIR}/third_party/cherrymp/usbh_uvc_queue.c) +list(APPEND cherryusb_incs ${CMAKE_CURRENT_LIST_DIR}/third_party/cherrymp) endif()
\ No newline at end of file diff --git a/third_party/cherrymp/chry_mempool.c b/third_party/cherrymp/chry_mempool.c new file mode 100644 index 00000000..7ed0a2eb --- /dev/null +++ b/third_party/cherrymp/chry_mempool.c @@ -0,0 +1,60 @@ +#include "chry_mempool.h" + +int chry_mempool_create(struct chry_mempool *pool, void *block, uint32_t block_size, uint32_t block_count) +{ + uintptr_t addr; + uint8_t *ringbuf; + + ringbuf = usb_osal_malloc(sizeof(uintptr_t) * block_count); + memset(ringbuf, 0, sizeof(uintptr_t) * block_count); + + chry_ringbuffer_init(&pool->rb, ringbuf, sizeof(uintptr_t) * block_count); + + for (uint32_t i = 0; i < block_count; i++) { + addr = ((uintptr_t)block + i * block_size); + chry_ringbuffer_write(&pool->rb, &addr, sizeof(uintptr_t)); + } + pool->mq = usb_osal_mq_create(block_count); + if (pool->mq == NULL) { + return -1; + } + return 0; +} + +void chry_mempool_delete(struct chry_mempool *pool) +{ + usb_osal_mq_delete(pool->mq); + chry_ringbuffer_reset(&pool->rb); + usb_osal_free(pool->rb.pool); +} + +uintptr_t *chry_mempool_alloc(struct chry_mempool *pool) +{ + uintptr_t *addr; + bool ret; + + ret = chry_ringbuffer_read(&pool->rb, (uintptr_t *)&addr, sizeof(uintptr_t)); + if (ret == false) { + 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->rb, &addr, sizeof(uintptr_t)); +} + +int chry_mempool_send(struct chry_mempool *pool, uintptr_t *item) +{ + return usb_osal_mq_send(pool->mq, (uintptr_t)item); +} + +int chry_mempool_recv(struct chry_mempool *pool, uintptr_t **item, uint32_t timeout) +{ + return usb_osal_mq_recv(pool->mq, (uintptr_t *)item, timeout); +}
\ No newline at end of file diff --git a/third_party/cherrymp/chry_mempool.h b/third_party/cherrymp/chry_mempool.h new file mode 100644 index 00000000..daebdd37 --- /dev/null +++ b/third_party/cherrymp/chry_mempool.h @@ -0,0 +1,19 @@ +#ifndef CHRY_MEMPOOL_H +#define CHRY_MEMPOOL_H + +#include "usb_config.h" +#include "usb_osal.h" +#include "chry_ringbuffer.h" + +struct chry_mempool { + chry_ringbuffer_t rb; + usb_osal_mq_t mq; +}; + +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); + +#endif
\ No newline at end of file diff --git a/third_party/cherrypool/usbh_uvc_queue.c b/third_party/cherrymp/usbh_uvc_queue.c index 0736f9b2..b7962ed3 100644 --- a/third_party/cherrypool/usbh_uvc_queue.c +++ b/third_party/cherrymp/usbh_uvc_queue.c @@ -1,32 +1,31 @@ #include "usbh_uvc_queue.h" -#include "chry_pool.h" +#include "chry_mempool.h" -struct chry_pool usbh_uvc_pool; -uint32_t usbh_uvc_pool_buf[10]; +struct chry_mempool usbh_uvc_pool; int usbh_uvc_frame_create(struct usbh_videoframe *frame, uint32_t count) { - return chry_pool_create(&usbh_uvc_pool, usbh_uvc_pool_buf, frame, sizeof(struct usbh_videoframe), count); + return chry_mempool_create(&usbh_uvc_pool, frame, sizeof(struct usbh_videoframe), count); } struct usbh_videoframe *usbh_uvc_frame_alloc(void) { - return (struct usbh_videoframe *)chry_pool_item_alloc(&usbh_uvc_pool); + return (struct usbh_videoframe *)chry_mempool_alloc(&usbh_uvc_pool); } int usbh_uvc_frame_free(struct usbh_videoframe *frame) { - return chry_pool_item_free(&usbh_uvc_pool, (uintptr_t *)frame); + return chry_mempool_free(&usbh_uvc_pool, (uintptr_t *)frame); } int usbh_uvc_frame_send(struct usbh_videoframe *frame) { - return chry_pool_item_send(&usbh_uvc_pool, (uintptr_t *)frame); + return chry_mempool_send(&usbh_uvc_pool, (uintptr_t *)frame); } int usbh_uvc_frame_recv(struct usbh_videoframe **frame, uint32_t timeout) { - return chry_pool_item_recv(&usbh_uvc_pool, (uintptr_t **)frame, timeout); + return chry_mempool_recv(&usbh_uvc_pool, (uintptr_t **)frame, timeout); } uint8_t frame_buffer1[1]; /* just for test */ diff --git a/third_party/cherrypool/usbh_uvc_queue.h b/third_party/cherrymp/usbh_uvc_queue.h index 3a6c4782..26da9caf 100644 --- a/third_party/cherrypool/usbh_uvc_queue.h +++ b/third_party/cherrymp/usbh_uvc_queue.h @@ -1,7 +1,7 @@ #ifndef USBH_UVC_QUEUE_H #define USBH_UVC_QUEUE_H -#include "chry_pool.h" +#include "chry_mempool.h" #include "usbh_core.h" #include "usbh_video.h" diff --git a/third_party/cherrypool/chry_pool.c b/third_party/cherrypool/chry_pool.c deleted file mode 100644 index b7d562dc..00000000 --- a/third_party/cherrypool/chry_pool.c +++ /dev/null @@ -1,49 +0,0 @@ -#include "chry_pool.h" - -int chry_pool_create(struct chry_pool *pool, uint32_t *ringbuf, void *item, uint32_t item_size, uint32_t item_count) -{ - uintptr_t addr; - - chry_ringbuffer_init(&pool->rb, ringbuf, sizeof(uintptr_t) * item_count); - - for (uint32_t i = 0; i < item_count; i++) { - addr = ((uintptr_t)item + i * item_size); - chry_ringbuffer_write(&pool->rb, &addr, sizeof(uintptr_t)); - } - pool->mq = usb_osal_mq_create(item_count); - if (pool->mq == NULL) { - return -1; - } - return 0; -} - -uintptr_t *chry_pool_item_alloc(struct chry_pool *pool) -{ - uintptr_t *addr; - bool ret; - - ret = chry_ringbuffer_read(&pool->rb, (uintptr_t *)&addr, sizeof(uintptr_t)); - if (ret == false) { - return NULL; - } else { - return addr; - } -} - -int chry_pool_item_free(struct chry_pool *pool, uintptr_t *item) -{ - uintptr_t addr; - - addr = (uintptr_t)item; - return chry_ringbuffer_write(&pool->rb, &addr, sizeof(uintptr_t)); -} - -int chry_pool_item_send(struct chry_pool *pool, uintptr_t *frame) -{ - return usb_osal_mq_send(pool->mq, (uintptr_t)frame); -} - -int chry_pool_item_recv(struct chry_pool *pool, uintptr_t **frame, uint32_t timeout) -{ - return usb_osal_mq_recv(pool->mq, (uintptr_t *)frame, timeout); -}
\ No newline at end of file diff --git a/third_party/cherrypool/chry_pool.h b/third_party/cherrypool/chry_pool.h deleted file mode 100644 index 953732b2..00000000 --- a/third_party/cherrypool/chry_pool.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef CHRY_POOL_H -#define CHRY_POOL_H - -#include "usb_config.h" -#include "usb_osal.h" -#include "chry_ringbuffer.h" - -struct chry_pool { - chry_ringbuffer_t rb; - usb_osal_mq_t mq; -}; - -int chry_pool_create(struct chry_pool *pool, uint32_t *ringbuf, void *item, uint32_t item_size, uint32_t item_count); -uintptr_t *chry_pool_item_alloc(struct chry_pool *pool); -int chry_pool_item_free(struct chry_pool *pool, uintptr_t *item); -int chry_pool_item_send(struct chry_pool *pool, uintptr_t *frame); -int chry_pool_item_recv(struct chry_pool *pool, uintptr_t **frame, uint32_t timeout); - -#endif
\ No newline at end of file |
