summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsakumisu <[email protected]>2025-11-05 20:40:47 +0800
committersakumisu <[email protected]>2025-11-05 20:40:47 +0800
commite453e72bf179c5e7869d6d45f6bea1902cca9cc6 (patch)
treef723a4c1f34d9db87a538362df204d33bb412a33
parent316c46e79768941df4c244c17efdb6ced9630f3a (diff)
fix(osal/usb_osal_threadx): delete self in another thread
Signed-off-by: sakumisu <[email protected]>
-rw-r--r--osal/usb_osal_threadx.c65
1 files changed, 45 insertions, 20 deletions
diff --git a/osal/usb_osal_threadx.c b/osal/usb_osal_threadx.c
index 33c34205..8d6d7c6b 100644
--- a/osal/usb_osal_threadx.c
+++ b/osal/usb_osal_threadx.c
@@ -9,12 +9,9 @@
#include "usb_log.h"
#include "tx_api.h"
-/* create bytepool in tx_application_define
- *
- * tx_byte_pool_create(&usb_byte_pool, "usb byte pool", memory_area, 65536);
- */
+extern TX_BYTE_POOL usb_byte_pool; // define usb_byte_pool and call usb_osal_init first
-extern TX_BYTE_POOL usb_byte_pool;
+usb_osal_mq_t usb_osal_mq;
usb_osal_thread_t usb_osal_thread_create(const char *name, uint32_t stack_size, uint32_t prio, usb_thread_entry_t entry, void *args)
{
@@ -27,7 +24,7 @@ usb_osal_thread_t usb_osal_thread_create(const char *name, uint32_t stack_size,
}
}
- tx_thread_create(thread_ptr, (CHAR *)name, (VOID (*)(ULONG))entry, (uintptr_t)args,
+ tx_thread_create(thread_ptr, (CHAR *)name, (VOID(*)(ULONG))entry, (uintptr_t)args,
((CHAR *)thread_ptr + USB_ALIGN_UP(sizeof(TX_THREAD), 4)), stack_size,
prio, prio, TX_NO_TIME_SLICE, TX_AUTO_START);
@@ -36,25 +33,17 @@ usb_osal_thread_t usb_osal_thread_create(const char *name, uint32_t stack_size,
void usb_osal_thread_delete(usb_osal_thread_t thread)
{
- TX_THREAD *thread_ptr = NULL;
-
if (thread == NULL) {
- /* Call the tx_thread_identify to get the control block pointer of the
- executing thread. */
- thread_ptr = tx_thread_identify();
+ thread = tx_thread_identify();
- /* Check if the current running thread pointer is not NULL */
- if (thread_ptr != NULL) {
- /* Call the tx_thread_terminate to terminates the specified application
- thread regardless of whether the thread is suspended or not. A thread
- may call this service to terminate itself. */
- tx_thread_terminate(thread_ptr);
- tx_byte_release(thread_ptr);
- }
+ usb_osal_mq_send(usb_osal_mq, (uintptr_t)thread);
+
+ tx_thread_terminate(thread);
return;
}
tx_thread_terminate(thread);
+ tx_thread_delete(thread);
tx_byte_release(thread);
}
@@ -296,4 +285,40 @@ void *usb_osal_malloc(size_t size)
void usb_osal_free(void *ptr)
{
tx_byte_release(ptr);
-} \ No newline at end of file
+}
+
+static void usb_osal_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV)
+{
+ int ret;
+ usb_osal_thread_t thread;
+
+ while (1) {
+ ret = usb_osal_mq_recv(usb_osal_mq, (uintptr_t *)&thread, TX_WAIT_FOREVER);
+ if (ret < 0) {
+ continue;
+ }
+ tx_thread_delete(thread);
+ tx_byte_release(thread);
+ }
+}
+
+void usb_osal_init(uint8_t *mem, uint32_t mem_size)
+{
+ usb_osal_thread_t thread;
+
+ tx_byte_pool_create(&usb_byte_pool, "usb byte pool", mem, mem_size);
+
+ thread = usb_osal_thread_create("usb_osal", 2048, 10, usb_osal_thread, NULL);
+ if (thread == NULL) {
+ USB_LOG_ERR("Create usb_osal_thread failed\r\n");
+ while (1) {
+ }
+ }
+
+ usb_osal_mq = usb_osal_mq_create(32);
+ if (usb_osal_mq == NULL) {
+ USB_LOG_ERR("Create usb_osal_mq failed\r\n");
+ while (1) {
+ }
+ }
+}