summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhathach <[email protected]>2022-04-20 14:37:42 +0700
committerhathach <[email protected]>2022-04-20 14:37:42 +0700
commit669e36d674d4b67b56127d8b41928a6dd3bdca7b (patch)
tree4b14bbc69722ef3e85ce17c26dc047bcbe8545ec
parenta90839688c11338451729838e45ae3aaa58864fe (diff)
fix freertos issue when 1 tick > 1 ms
-rw-r--r--examples/device/cdc_msc_freertos/src/main.c6
-rw-r--r--src/osal/osal_freertos.h20
2 files changed, 18 insertions, 8 deletions
diff --git a/examples/device/cdc_msc_freertos/src/main.c b/examples/device/cdc_msc_freertos/src/main.c
index 0a1c964ae..c0fc722f4 100644
--- a/examples/device/cdc_msc_freertos/src/main.c
+++ b/examples/device/cdc_msc_freertos/src/main.c
@@ -132,6 +132,8 @@ void usb_device_task(void* param)
{
// tinyusb device task
tud_task();
+
+ tud_cdc_write_flush();
}
}
@@ -194,12 +196,8 @@ void cdc_task(void* params)
// for throughput test e.g
// $ dd if=/dev/zero of=/dev/ttyACM0 count=10000
tud_cdc_write(buf, count);
- tud_cdc_write_flush();
}
}
-
- // For ESP32-S2 this delay is essential to allow idle how to run and reset wdt
- vTaskDelay(pdMS_TO_TICKS(10));
}
}
diff --git a/src/osal/osal_freertos.h b/src/osal/osal_freertos.h
index c3a0756e1..52db336f5 100644
--- a/src/osal/osal_freertos.h
+++ b/src/osal/osal_freertos.h
@@ -37,6 +37,20 @@
extern "C" {
#endif
+TU_ATTR_ALWAYS_INLINE static inline uint32_t _osal_ms2tick(uint32_t msec)
+{
+ if (msec == OSAL_TIMEOUT_WAIT_FOREVER) return portMAX_DELAY;
+ if (msec == 0) return 0;
+
+ uint32_t ticks = pdMS_TO_TICKS(msec);
+
+ // configTICK_RATE_HZ is less than 1000 and 1 tick > 1 ms
+ // we still need to delay at least 1 tick
+ if (ticks == 0) ticks =1 ;
+
+ return ticks;
+}
+
//--------------------------------------------------------------------+
// TASK API
//--------------------------------------------------------------------+
@@ -80,8 +94,7 @@ TU_ATTR_ALWAYS_INLINE static inline bool osal_semaphore_post(osal_semaphore_t se
TU_ATTR_ALWAYS_INLINE static inline bool osal_semaphore_wait (osal_semaphore_t sem_hdl, uint32_t msec)
{
- uint32_t const ticks = (msec == OSAL_TIMEOUT_WAIT_FOREVER) ? portMAX_DELAY : pdMS_TO_TICKS(msec);
- return xSemaphoreTake(sem_hdl, ticks);
+ return xSemaphoreTake(sem_hdl, _osal_ms2tick(msec));
}
TU_ATTR_ALWAYS_INLINE static inline void osal_semaphore_reset(osal_semaphore_t const sem_hdl)
@@ -137,8 +150,7 @@ TU_ATTR_ALWAYS_INLINE static inline osal_queue_t osal_queue_create(osal_queue_de
TU_ATTR_ALWAYS_INLINE static inline bool osal_queue_receive(osal_queue_t qhdl, void* data, uint32_t msec)
{
- uint32_t const ticks = (msec == OSAL_TIMEOUT_WAIT_FOREVER) ? portMAX_DELAY : pdMS_TO_TICKS(msec);
- return xQueueReceive(qhdl, data, ticks);
+ return xQueueReceive(qhdl, data, _osal_ms2tick(msec));
}
TU_ATTR_ALWAYS_INLINE static inline bool osal_queue_send(osal_queue_t qhdl, void const * data, bool in_isr)