summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsakumisu <[email protected]>2022-01-29 23:15:10 +0800
committersakumisu <[email protected]>2022-01-29 23:15:10 +0800
commitf24997db449f48f48273682708757f18232c42fa (patch)
treea3268fa1413dff4e068e338f60e0952dab21229c
parentf1c21d2782fcc55cb19e5388f3664e0a6da0fab0 (diff)
update osal api
-rw-r--r--osal/usb_osal.h12
-rw-r--r--osal/usb_osal_freertos.c60
-rw-r--r--osal/usb_osal_rtthread.c20
3 files changed, 62 insertions, 30 deletions
diff --git a/osal/usb_osal.h b/osal/usb_osal.h
index 753867ab..04703c80 100644
--- a/osal/usb_osal.h
+++ b/osal/usb_osal.h
@@ -25,25 +25,33 @@
#include <stdint.h>
+#define USB_OSAL_MS2TICK(ms)
+
typedef void *usb_osal_thread_t;
typedef void *usb_osal_sem_t;
typedef void *usb_osal_mutex_t;
typedef void (*usb_thread_entry_t)(void *argument);
-usb_osal_thread_t usb_osal_thread_create(const char *name, uint32_t stack_size, uint32_t prio, usb_thread_entry_t entry);
+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);
void usb_osal_thread_delete(usb_osal_thread_t thread);
+void usb_osal_thread_suspend(usb_osal_thread_t thread);
+void usb_osal_thread_resume(usb_osal_thread_t thread);
usb_osal_sem_t usb_osal_sem_create(uint32_t initial_count);
+void usb_osal_sem_delete(usb_osal_sem_t sem);
int usb_osal_sem_take(usb_osal_sem_t sem);
int usb_osal_sem_give(usb_osal_sem_t sem);
usb_osal_mutex_t usb_osal_mutex_create(void);
+void usb_osal_mutex_delete(usb_osal_mutex_t mutex);
int usb_osal_mutex_take(usb_osal_mutex_t mutex);
int usb_osal_mutex_give(usb_osal_mutex_t mutex);
uint32_t usb_osal_enter_critical_section(void);
void usb_osal_leave_critical_section(uint32_t flag);
-void usb_osal_delay_ms(uint32_t delay);
+void usb_osal_msleep(uint32_t delay);
+
+uint32_t usb_osal_get_tick(void);
#endif \ No newline at end of file
diff --git a/osal/usb_osal_freertos.c b/osal/usb_osal_freertos.c
index c8118625..ece24eb0 100644
--- a/osal/usb_osal_freertos.c
+++ b/osal/usb_osal_freertos.c
@@ -24,19 +24,34 @@
#include <FreeRTOS.h>
#include "semphr.h"
-usb_osal_thread_t usb_osal_thread_create(const char *name, uint32_t stack_size, uint32_t prio, usb_thread_entry_t entry)
+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)
{
TaskHandle_t htask = NULL;
stack_size /= sizeof(StackType_t);
- xTaskCreate(entry, name, stack_size, NULL, prio, &htask);
+ xTaskCreate(entry, name, stack_size, args, prio, &htask);
return (usb_osal_thread_t)htask;
}
+void usb_osal_thread_suspend(usb_osal_thread_t thread)
+{
+ vTaskSuspend(thread);
+}
+
+void usb_osal_thread_resume(usb_osal_thread_t thread)
+{
+ vTaskResume(thread);
+}
+
usb_osal_sem_t usb_osal_sem_create(uint32_t initial_count)
{
return (usb_osal_sem_t)xSemaphoreCreateCounting(1, initial_count);
}
+void usb_osal_sem_delete(usb_osal_sem_t sem)
+{
+ vSemaphoreDelete((SemaphoreHandle_t)sem);
+}
+
int usb_osal_sem_take(usb_osal_sem_t sem)
{
return (xSemaphoreTake((SemaphoreHandle_t)sem, portMAX_DELAY) == pdPASS) ? 0 : -1;
@@ -44,16 +59,25 @@ int usb_osal_sem_take(usb_osal_sem_t sem)
int usb_osal_sem_give(usb_osal_sem_t sem)
{
- return (xSemaphoreGive((SemaphoreHandle_t)sem) == pdPASS) ? 0 : -1;
+ BaseType_t xHigherPriorityTaskWoken = pdFALSE;
+ uint32_t intstatus = 1;
+ int ret;
+ /* Obtain the level of the currently executing interrupt. */
+// __asm volatile("csrr %0, mintstatus"
+// : "=r"(intstatus)::"memory");
+ /* Obtain the number of the currently executing interrupt. */
+// __asm volatile ( "mrs %0, ipsr" : "=r" ( intstatus )::"memory" );
- // BaseType_t xHigherPriorityTaskWoken = pdFALSE;
+ if (intstatus == 0) {
+ ret = xSemaphoreGive((SemaphoreHandle_t)sem);
+ } else {
+ ret = xSemaphoreGiveFromISR((SemaphoreHandle_t)sem, &xHigherPriorityTaskWoken);
+ if (ret == pdPASS) {
+ portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
+ }
+ }
- // int ret = xSemaphoreGiveFromISR((SemaphoreHandle_t)sem, &xHigherPriorityTaskWoken);
-
- // if (ret == pdPASS) {
- // portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
- // }
- // return (ret == pdPASS) ? 0 : -1;
+ return (ret == pdPASS) ? 0 : -1;
}
usb_osal_mutex_t usb_osal_mutex_create(void)
@@ -61,6 +85,11 @@ usb_osal_mutex_t usb_osal_mutex_create(void)
return (usb_osal_mutex_t)xSemaphoreCreateMutex();
}
+void usb_osal_mutex_delete(usb_osal_mutex_t mutex)
+{
+ vSemaphoreDelete((SemaphoreHandle_t)mutex);
+}
+
int usb_osal_mutex_take(usb_osal_mutex_t mutex)
{
return (xSemaphoreTake((SemaphoreHandle_t)mutex, portMAX_DELAY) == pdPASS) ? 0 : -1;
@@ -82,7 +111,12 @@ void usb_osal_leave_critical_section(uint32_t flag)
taskEXIT_CRITICAL();
}
-void usb_osal_delay_ms(uint32_t delay)
+void usb_osal_msleep(uint32_t delay)
{
- vTaskDelay(delay);
-} \ No newline at end of file
+ vTaskDelay(pdMS_TO_TICKS(delay));
+}
+
+uint32_t usb_osal_get_tick(void)
+{
+ return xTaskGetTickCount();
+}
diff --git a/osal/usb_osal_rtthread.c b/osal/usb_osal_rtthread.c
index 30b075e0..c71774e8 100644
--- a/osal/usb_osal_rtthread.c
+++ b/osal/usb_osal_rtthread.c
@@ -23,22 +23,17 @@
#include "usb_osal.h"
#include <rtthread.h>
-usb_osal_thread_t usb_osal_thread_create(const char *name, uint32_t stack_size, uint32_t prio, usb_thread_entry_t entry)
+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)
{
rt_thread_t htask;
- htask = rt_thread_create(name, entry, NULL, stack_size, prio, 10);
+ htask = rt_thread_create(name, entry, args, stack_size, prio, 10);
rt_thread_startup(htask);
return (usb_osal_thread_t)htask;
}
usb_osal_sem_t usb_osal_sem_create(uint32_t initial_count)
{
- static uint16_t index = 0;
- char str[16];
-
- sprintf(str, "usbh_sem%u", index);
- index++;
- return (usb_osal_sem_t)rt_sem_create(str, initial_count, RT_IPC_FLAG_FIFO);
+ return (usb_osal_sem_t)rt_sem_create("usbh_sem", initial_count, RT_IPC_FLAG_FIFO);
}
int usb_osal_sem_take(usb_osal_sem_t sem)
@@ -53,12 +48,7 @@ int usb_osal_sem_give(usb_osal_sem_t sem)
usb_osal_mutex_t usb_osal_mutex_create(void)
{
- static uint16_t index = 0;
- char str[16];
-
- sprintf(str, "usbh_mutex%u", index);
- index++;
- return (usb_osal_mutex_t)rt_mutex_create(str, RT_IPC_FLAG_FIFO);
+ return (usb_osal_mutex_t)rt_mutex_create("usbh_mutex", RT_IPC_FLAG_FIFO);
}
int usb_osal_mutex_take(usb_osal_mutex_t mutex)
@@ -82,7 +72,7 @@ void usb_osal_leave_critical_section(uint32_t flag)
rt_exit_critical();
}
-void usb_osal_delay_ms(uint32_t delay)
+void usb_osal_msleep(uint32_t delay)
{
rt_thread_mdelay(delay);
} \ No newline at end of file