summaryrefslogtreecommitdiff
path: root/src/osal
diff options
context:
space:
mode:
authorhathach <[email protected]>2026-03-05 13:00:45 +0700
committerhathach <[email protected]>2026-03-05 13:00:45 +0700
commit0427fcfd02e6d6b8939b54984f58c3711d806ddd (patch)
tree5d86bb047dc306cf383fc7258074294d343c6ae2 /src/osal
parent6e675da608b063e2ea7db1d700d788d6a247f9ec (diff)
parentce8a073a31307d65e3337a2f69a5ea1b9b507ea5 (diff)
Merge branch 'master' into fork/armusin/threadx_osal
Diffstat (limited to 'src/osal')
-rw-r--r--src/osal/osal.h2
-rw-r--r--src/osal/osal_freertos.h4
-rw-r--r--src/osal/osal_mynewt.h4
-rw-r--r--src/osal/osal_none.h6
-rw-r--r--src/osal/osal_pico.h4
-rw-r--r--src/osal/osal_rtthread.h4
-rw-r--r--src/osal/osal_rtx4.h4
-rw-r--r--src/osal/osal_zephyr.h4
8 files changed, 30 insertions, 2 deletions
diff --git a/src/osal/osal.h b/src/osal/osal.h
index 7311fc962..4840463f3 100644
--- a/src/osal/osal.h
+++ b/src/osal/osal.h
@@ -76,6 +76,8 @@ typedef void (*osal_task_func_t)(void* param);
/*--------------------------------------------------------------------
OSAL Porting API
Should be implemented as static inline function in osal_port.h header
+ uint32_t osal_time_millis(void);
+
void osal_spin_init(osal_spinlock_t *ctx);
void osal_spin_lock(osal_spinlock_t *ctx, bool in_isr)
void osal_spin_unlock(osal_spinlock_t *ctx, bool in_isr);
diff --git a/src/osal/osal_freertos.h b/src/osal/osal_freertos.h
index 9aeda4d01..32ee2d55c 100644
--- a/src/osal/osal_freertos.h
+++ b/src/osal/osal_freertos.h
@@ -99,6 +99,10 @@ TU_ATTR_ALWAYS_INLINE static inline void osal_task_delay(uint32_t msec) {
vTaskDelay(pdMS_TO_TICKS(msec));
}
+TU_ATTR_ALWAYS_INLINE static inline uint32_t osal_time_millis(void) {
+ return pdTICKS_TO_MS(xTaskGetTickCount());
+}
+
//--------------------------------------------------------------------+
// Spinlock API
//--------------------------------------------------------------------+
diff --git a/src/osal/osal_mynewt.h b/src/osal/osal_mynewt.h
index 6d51f8ec3..94124ca81 100644
--- a/src/osal/osal_mynewt.h
+++ b/src/osal/osal_mynewt.h
@@ -40,6 +40,10 @@ TU_ATTR_ALWAYS_INLINE static inline void osal_task_delay(uint32_t msec) {
os_time_delay( os_time_ms_to_ticks32(msec) );
}
+TU_ATTR_ALWAYS_INLINE static inline uint32_t osal_time_millis(void) {
+ return os_time_ticks_to_ms32(os_time_get());
+}
+
//--------------------------------------------------------------------+
// Spinlock API
//--------------------------------------------------------------------+
diff --git a/src/osal/osal_none.h b/src/osal/osal_none.h
index 6ab18ace8..7bf6029d6 100644
--- a/src/osal/osal_none.h
+++ b/src/osal/osal_none.h
@@ -31,6 +31,8 @@
extern "C" {
#endif
+// osal_time_millis() is not provided, tusb_time_millis_api() must be implemented by user application
+
//--------------------------------------------------------------------+
// Spinlock API
//--------------------------------------------------------------------+
@@ -184,7 +186,7 @@ TU_ATTR_ALWAYS_INLINE static inline bool osal_queue_receive(osal_queue_t qhdl, v
(void) msec; // not used, always behave as msec = 0
qhdl->interrupt_set(false);
- const bool success = tu_fifo_read_n(&qhdl->ff, data, qhdl->item_size);
+ const bool success = (tu_fifo_read_n(&qhdl->ff, data, qhdl->item_size) > 0);
qhdl->interrupt_set(true);
return success;
@@ -195,7 +197,7 @@ TU_ATTR_ALWAYS_INLINE static inline bool osal_queue_send(osal_queue_t qhdl, void
qhdl->interrupt_set(false);
}
- const bool success = tu_fifo_write_n(&qhdl->ff, data, qhdl->item_size);
+ const bool success = (tu_fifo_write_n(&qhdl->ff, data, qhdl->item_size) > 0);
if (!in_isr) {
qhdl->interrupt_set(true);
diff --git a/src/osal/osal_pico.h b/src/osal/osal_pico.h
index 79b728e9a..6a0a21bb3 100644
--- a/src/osal/osal_pico.h
+++ b/src/osal/osal_pico.h
@@ -43,6 +43,10 @@ TU_ATTR_ALWAYS_INLINE static inline void osal_task_delay(uint32_t msec) {
sleep_ms(msec);
}
+TU_ATTR_ALWAYS_INLINE static inline uint32_t osal_time_millis(void) {
+ return to_ms_since_boot(get_absolute_time());
+}
+
//--------------------------------------------------------------------+
// Spinlock API
//--------------------------------------------------------------------+
diff --git a/src/osal/osal_rtthread.h b/src/osal/osal_rtthread.h
index a778f5425..f560281c5 100644
--- a/src/osal/osal_rtthread.h
+++ b/src/osal/osal_rtthread.h
@@ -42,6 +42,10 @@ TU_ATTR_ALWAYS_INLINE static inline void osal_task_delay(uint32_t msec) {
rt_thread_mdelay(msec);
}
+TU_ATTR_ALWAYS_INLINE static inline uint32_t osal_time_millis(void) {
+ return (uint32_t)((((uint64_t)rt_tick_get()) * 1000) / RT_TICK_PER_SECOND);
+}
+
//--------------------------------------------------------------------+
// Spinlock API
//--------------------------------------------------------------------+
diff --git a/src/osal/osal_rtx4.h b/src/osal/osal_rtx4.h
index 35860ddd5..e1930c96c 100644
--- a/src/osal/osal_rtx4.h
+++ b/src/osal/osal_rtx4.h
@@ -46,6 +46,10 @@ TU_ATTR_ALWAYS_INLINE static inline void osal_task_delay(uint32_t msec) {
os_dly_wait(lo);
}
+TU_ATTR_ALWAYS_INLINE static inline uint32_t osal_time_millis(void) {
+ return os_time_get();
+}
+
TU_ATTR_ALWAYS_INLINE static inline uint16_t msec2wait(uint32_t msec) {
if (msec == OSAL_TIMEOUT_WAIT_FOREVER) {
return 0xFFFF;
diff --git a/src/osal/osal_zephyr.h b/src/osal/osal_zephyr.h
index 91f225f79..900ac786c 100644
--- a/src/osal/osal_zephyr.h
+++ b/src/osal/osal_zephyr.h
@@ -35,6 +35,10 @@ TU_ATTR_ALWAYS_INLINE static inline void osal_task_delay(uint32_t msec) {
k_msleep(msec);
}
+TU_ATTR_ALWAYS_INLINE static inline uint32_t osal_time_millis(void) {
+ return k_uptime_get_32();
+}
+
//--------------------------------------------------------------------+
// Spinlock API
//--------------------------------------------------------------------+