From d588167a39fd01e5cea718deb1917e74c6a801ab Mon Sep 17 00:00:00 2001 From: pete-pjb Date: Wed, 30 Nov 2022 11:33:24 +0000 Subject: [PATCH 1/7] Modify FreeRTOS integration to allow non-static allocation. --- src/osal/osal_freertos.h | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/osal/osal_freertos.h b/src/osal/osal_freertos.h index 52db336f..a2b0573f 100644 --- a/src/osal/osal_freertos.h +++ b/src/osal/osal_freertos.h @@ -62,12 +62,20 @@ TU_ATTR_ALWAYS_INLINE static inline void osal_task_delay(uint32_t msec) //--------------------------------------------------------------------+ // Semaphore API //--------------------------------------------------------------------+ +#if configSUPPORT_STATIC_ALLOCATION == 1 typedef StaticSemaphore_t osal_semaphore_def_t; +#else +typedef SemaphoreHandle_t osal_semaphore_def_t; +#endif typedef SemaphoreHandle_t osal_semaphore_t; TU_ATTR_ALWAYS_INLINE static inline osal_semaphore_t osal_semaphore_create(osal_semaphore_def_t* semdef) { +#if configSUPPORT_STATIC_ALLOCATION == 1 return xSemaphoreCreateBinaryStatic(semdef); +#else + return xSemaphoreCreateBinary(); +#endif } TU_ATTR_ALWAYS_INLINE static inline bool osal_semaphore_post(osal_semaphore_t sem_hdl, bool in_isr) @@ -105,12 +113,21 @@ TU_ATTR_ALWAYS_INLINE static inline void osal_semaphore_reset(osal_semaphore_t c //--------------------------------------------------------------------+ // MUTEX API (priority inheritance) //--------------------------------------------------------------------+ +#if configSUPPORT_STATIC_ALLOCATION == 1 typedef StaticSemaphore_t osal_mutex_def_t; +#else +typedef SemaphoreHandle_t osal_mutex_def_t; +#endif typedef SemaphoreHandle_t osal_mutex_t; TU_ATTR_ALWAYS_INLINE static inline osal_mutex_t osal_mutex_create(osal_mutex_def_t* mdef) { +#if configSUPPORT_STATIC_ALLOCATION == 1 return xSemaphoreCreateMutexStatic(mdef); +#else + return xSemaphoreCreateMutex(); +#endif + } TU_ATTR_ALWAYS_INLINE static inline bool osal_mutex_lock (osal_mutex_t mutex_hdl, uint32_t msec) @@ -145,7 +162,11 @@ typedef QueueHandle_t osal_queue_t; TU_ATTR_ALWAYS_INLINE static inline osal_queue_t osal_queue_create(osal_queue_def_t* qdef) { - return xQueueCreateStatic(qdef->depth, qdef->item_sz, (uint8_t*) qdef->buf, &qdef->sq); +#if configSUPPORT_STATIC_ALLOCATION == 1 + return xQueueCreateStatic(qdef->depth, qdef->item_sz, (uint8_t*) qdef->buf, &qdef->sq); +#else + return xQueueCreate(qdef->depth, qdef->item_sz); +#endif } TU_ATTR_ALWAYS_INLINE static inline bool osal_queue_receive(osal_queue_t qhdl, void* data, uint32_t msec) From 25abb10de17ed868b2189ae5038a7c47aab19ae5 Mon Sep 17 00:00:00 2001 From: pete-pjb Date: Wed, 30 Nov 2022 13:26:59 +0000 Subject: [PATCH 2/7] Fix white space issue. --- src/osal/osal_freertos.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/osal/osal_freertos.h b/src/osal/osal_freertos.h index a2b0573f..fed70400 100644 --- a/src/osal/osal_freertos.h +++ b/src/osal/osal_freertos.h @@ -62,7 +62,7 @@ TU_ATTR_ALWAYS_INLINE static inline void osal_task_delay(uint32_t msec) //--------------------------------------------------------------------+ // Semaphore API //--------------------------------------------------------------------+ -#if configSUPPORT_STATIC_ALLOCATION == 1 +#if configSUPPORT_STATIC_ALLOCATION == 1 typedef StaticSemaphore_t osal_semaphore_def_t; #else typedef SemaphoreHandle_t osal_semaphore_def_t; @@ -71,7 +71,7 @@ typedef SemaphoreHandle_t osal_semaphore_t; TU_ATTR_ALWAYS_INLINE static inline osal_semaphore_t osal_semaphore_create(osal_semaphore_def_t* semdef) { -#if configSUPPORT_STATIC_ALLOCATION == 1 +#if configSUPPORT_STATIC_ALLOCATION == 1 return xSemaphoreCreateBinaryStatic(semdef); #else return xSemaphoreCreateBinary(); @@ -113,7 +113,7 @@ TU_ATTR_ALWAYS_INLINE static inline void osal_semaphore_reset(osal_semaphore_t c //--------------------------------------------------------------------+ // MUTEX API (priority inheritance) //--------------------------------------------------------------------+ -#if configSUPPORT_STATIC_ALLOCATION == 1 +#if configSUPPORT_STATIC_ALLOCATION == 1 typedef StaticSemaphore_t osal_mutex_def_t; #else typedef SemaphoreHandle_t osal_mutex_def_t; @@ -122,7 +122,7 @@ typedef SemaphoreHandle_t osal_mutex_t; TU_ATTR_ALWAYS_INLINE static inline osal_mutex_t osal_mutex_create(osal_mutex_def_t* mdef) { -#if configSUPPORT_STATIC_ALLOCATION == 1 +#if configSUPPORT_STATIC_ALLOCATION == 1 return xSemaphoreCreateMutexStatic(mdef); #else return xSemaphoreCreateMutex(); @@ -162,7 +162,7 @@ typedef QueueHandle_t osal_queue_t; TU_ATTR_ALWAYS_INLINE static inline osal_queue_t osal_queue_create(osal_queue_def_t* qdef) { -#if configSUPPORT_STATIC_ALLOCATION == 1 +#if configSUPPORT_STATIC_ALLOCATION == 1 return xQueueCreateStatic(qdef->depth, qdef->item_sz, (uint8_t*) qdef->buf, &qdef->sq); #else return xQueueCreate(qdef->depth, qdef->item_sz); From ae588d796e1b035c7efd582a4e4f3fc28b3a5ac0 Mon Sep 17 00:00:00 2001 From: PeterB Date: Thu, 1 Dec 2022 16:06:15 +0000 Subject: [PATCH 3/7] Alter tuh_task_ext() function so no need to return when using FreeRTOS --- src/host/usbh.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/host/usbh.c b/src/host/usbh.c index d97b160c..a90b5492 100644 --- a/src/host/usbh.c +++ b/src/host/usbh.c @@ -509,7 +509,7 @@ void tuh_task_ext(uint32_t timeout_ms, bool in_isr) default: break; } -#if CFG_TUSB_OS != OPT_OS_NONE && CFG_TUSB_OS != OPT_OS_PICO +#if CFG_TUSB_OS != OPT_OS_NONE && CFG_TUSB_OS != OPT_OS_PICO && CFG_TUSB_OS != OPT_OS_FREERTOS // return if there is no more events, for application to run other background if (osal_queue_empty(_usbh_q)) return; #endif From c31b95c91652f58b8b991a5481c9f7c37be7f09a Mon Sep 17 00:00:00 2001 From: pete-pjb Date: Thu, 1 Dec 2022 17:53:35 +0000 Subject: [PATCH 4/7] Added CFG_TUSB_MEM_SECTION define to struct _ctrl_xfer in usbh.c --- src/host/usbh.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/host/usbh.c b/src/host/usbh.c index a90b5492..f28554b8 100644 --- a/src/host/usbh.c +++ b/src/host/usbh.c @@ -246,8 +246,8 @@ static uint8_t _usbh_ctrl_buf[CFG_TUH_ENUMERATION_BUFSIZE]; // Control transfer: since most controller does not support multiple control transfer // on multiple devices concurrently. And control transfer is not used much except enumeration -// We will only execute control transfer one at a time. -struct +// We will only execute control transfer one at a time.CFG_TUSB_MEM_SECTION TU_ATTR_ALIGNED(4096) +CFG_TUSB_MEM_SECTION struct { tusb_control_request_t request TU_ATTR_ALIGNED(4); uint8_t* buffer; From 3816869fce15509fd43eb5a6d14de76478f86cf1 Mon Sep 17 00:00:00 2001 From: pete-pjb Date: Fri, 2 Dec 2022 10:00:19 +0000 Subject: [PATCH 5/7] Some reverts and changes after discussion. --- src/host/usbh.c | 6 +++--- src/osal/osal_freertos.h | 5 ++++- src/portable/ehci/ehci.c | 3 ++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/host/usbh.c b/src/host/usbh.c index f28554b8..d97b160c 100644 --- a/src/host/usbh.c +++ b/src/host/usbh.c @@ -246,8 +246,8 @@ static uint8_t _usbh_ctrl_buf[CFG_TUH_ENUMERATION_BUFSIZE]; // Control transfer: since most controller does not support multiple control transfer // on multiple devices concurrently. And control transfer is not used much except enumeration -// We will only execute control transfer one at a time.CFG_TUSB_MEM_SECTION TU_ATTR_ALIGNED(4096) -CFG_TUSB_MEM_SECTION struct +// We will only execute control transfer one at a time. +struct { tusb_control_request_t request TU_ATTR_ALIGNED(4); uint8_t* buffer; @@ -509,7 +509,7 @@ void tuh_task_ext(uint32_t timeout_ms, bool in_isr) default: break; } -#if CFG_TUSB_OS != OPT_OS_NONE && CFG_TUSB_OS != OPT_OS_PICO && CFG_TUSB_OS != OPT_OS_FREERTOS +#if CFG_TUSB_OS != OPT_OS_NONE && CFG_TUSB_OS != OPT_OS_PICO // return if there is no more events, for application to run other background if (osal_queue_empty(_usbh_q)) return; #endif diff --git a/src/osal/osal_freertos.h b/src/osal/osal_freertos.h index fed70400..ccb98cc9 100644 --- a/src/osal/osal_freertos.h +++ b/src/osal/osal_freertos.h @@ -74,6 +74,7 @@ TU_ATTR_ALWAYS_INLINE static inline osal_semaphore_t osal_semaphore_create(osal_ #if configSUPPORT_STATIC_ALLOCATION == 1 return xSemaphoreCreateBinaryStatic(semdef); #else + (void)(semdef); return xSemaphoreCreateBinary(); #endif } @@ -125,6 +126,7 @@ TU_ATTR_ALWAYS_INLINE static inline osal_mutex_t osal_mutex_create(osal_mutex_de #if configSUPPORT_STATIC_ALLOCATION == 1 return xSemaphoreCreateMutexStatic(mdef); #else + (void)(mdef); return xSemaphoreCreateMutex(); #endif @@ -154,8 +156,9 @@ typedef struct uint16_t depth; uint16_t item_sz; void* buf; - +#if configSUPPORT_STATIC_ALLOCATION == 1 StaticQueue_t sq; +#endif }osal_queue_def_t; typedef QueueHandle_t osal_queue_t; diff --git a/src/portable/ehci/ehci.c b/src/portable/ehci/ehci.c index 76ba2a92..0af8c3b2 100644 --- a/src/portable/ehci/ehci.c +++ b/src/portable/ehci/ehci.c @@ -193,7 +193,8 @@ static void list_remove_qhd_by_addr(ehci_link_t* list_head, uint8_t dev_addr) { // TODO check type for ISO iTD and siTD // TODO Suppress cast-align warning - #pragma GCC diagnostic push + if( prev == NULL ) break; + #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wcast-align" ehci_qhd_t* qhd = (ehci_qhd_t*) list_next(prev); #pragma GCC diagnostic pop From 52261ac02dfbe58f35f959be852f0949cc0744cd Mon Sep 17 00:00:00 2001 From: pete-pjb Date: Fri, 2 Dec 2022 10:13:35 +0000 Subject: [PATCH 6/7] Back out another of my changes I am still investigating. --- src/portable/ehci/ehci.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/portable/ehci/ehci.c b/src/portable/ehci/ehci.c index 0af8c3b2..36101596 100644 --- a/src/portable/ehci/ehci.c +++ b/src/portable/ehci/ehci.c @@ -193,7 +193,6 @@ static void list_remove_qhd_by_addr(ehci_link_t* list_head, uint8_t dev_addr) { // TODO check type for ISO iTD and siTD // TODO Suppress cast-align warning - if( prev == NULL ) break; #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wcast-align" ehci_qhd_t* qhd = (ehci_qhd_t*) list_next(prev); From de5a67bf3b8737a580539c5fbc6a054c90e4a084 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 5 Dec 2022 12:09:41 +0700 Subject: [PATCH 7/7] clean osal_freertos, update freertos examples to work with configSUPPORT_DYNAMIC_ALLOCATION only note: for example to build with configSUPPORT_STATIC_ALLOCATION = 0, one of heap_n.c must be included in makefile/cmake --- examples/device/cdc_msc_freertos/Makefile | 11 ++- .../src/FreeRTOSConfig/FreeRTOSConfig.h | 2 +- examples/device/cdc_msc_freertos/src/main.c | 24 ++++-- .../device/hid_composite_freertos/Makefile | 11 ++- .../src/FreeRTOSConfig/FreeRTOSConfig.h | 7 +- .../device/hid_composite_freertos/src/main.c | 24 ++++-- src/osal/osal_freertos.h | 84 ++++++++++--------- src/portable/ehci/ehci.c | 2 +- 8 files changed, 100 insertions(+), 65 deletions(-) diff --git a/examples/device/cdc_msc_freertos/Makefile b/examples/device/cdc_msc_freertos/Makefile index 3352dd37..ff4b4110 100644 --- a/examples/device/cdc_msc_freertos/Makefile +++ b/examples/device/cdc_msc_freertos/Makefile @@ -29,8 +29,15 @@ SRC_C += \ $(FREERTOS_SRC)/timers.c \ $(subst ../../../,,$(wildcard ../../../$(FREERTOS_SRC)/portable/GCC/$(FREERTOS_PORT)/*.c)) -# Suppress FreeRTOS warnings -CFLAGS += -Wno-error=cast-qual -Wno-error=redundant-decls +# include heap manage if configSUPPORT_DYNAMIC_ALLOCATION = 1 +# SRC_C += $(FREERTOS_SRC)/portable/MemMang/heap_1.c +# CFLAGS += -Wno-error=sign-compare + +# Suppress FreeRTOSConfig.h warnings +CFLAGS += -Wno-error=redundant-decls + +# Suppress FreeRTOS source warnings +CFLAGS += -Wno-error=cast-qual # FreeRTOS (lto + Os) linker issue LDFLAGS += -Wl,--undefined=vTaskSwitchContext diff --git a/examples/device/cdc_msc_freertos/src/FreeRTOSConfig/FreeRTOSConfig.h b/examples/device/cdc_msc_freertos/src/FreeRTOSConfig/FreeRTOSConfig.h index 6a3630db..968c5974 100644 --- a/examples/device/cdc_msc_freertos/src/FreeRTOSConfig/FreeRTOSConfig.h +++ b/examples/device/cdc_msc_freertos/src/FreeRTOSConfig/FreeRTOSConfig.h @@ -69,7 +69,7 @@ #define configTICK_RATE_HZ ( 1000 ) #define configMAX_PRIORITIES ( 5 ) #define configMINIMAL_STACK_SIZE ( 128 ) -#define configTOTAL_HEAP_SIZE ( 0*1024 ) // dynamic is not used +#define configTOTAL_HEAP_SIZE ( configSUPPORT_DYNAMIC_ALLOCATION*4*1024 ) #define configMAX_TASK_NAME_LEN 16 #define configUSE_16_BIT_TICKS 0 #define configIDLE_SHOULD_YIELD 1 diff --git a/examples/device/cdc_msc_freertos/src/main.c b/examples/device/cdc_msc_freertos/src/main.c index 755220c1..cfb14aa2 100644 --- a/examples/device/cdc_msc_freertos/src/main.c +++ b/examples/device/cdc_msc_freertos/src/main.c @@ -51,6 +51,8 @@ #define USBD_STACK_SIZE (3*configMINIMAL_STACK_SIZE/2) * (CFG_TUSB_DEBUG ? 2 : 1) #endif +#define CDC_STACK_SZIE configMINIMAL_STACK_SIZE + //--------------------------------------------------------------------+ // MACRO CONSTANT TYPEDEF PROTYPES //--------------------------------------------------------------------+ @@ -66,19 +68,18 @@ enum { BLINK_SUSPENDED = 2500, }; -// static timer +// static timer & task +#if configSUPPORT_STATIC_ALLOCATION StaticTimer_t blinky_tmdef; -TimerHandle_t blinky_tm; -// static task StackType_t usb_device_stack[USBD_STACK_SIZE]; StaticTask_t usb_device_taskdef; -// static task for cdc -#define CDC_STACK_SZIE configMINIMAL_STACK_SIZE StackType_t cdc_stack[CDC_STACK_SZIE]; StaticTask_t cdc_taskdef; +#endif +TimerHandle_t blinky_tm; void led_blinky_cb(TimerHandle_t xTimer); void usb_device_task(void* param); @@ -92,15 +93,22 @@ int main(void) { board_init(); +#if configSUPPORT_STATIC_ALLOCATION // soft timer for blinky blinky_tm = xTimerCreateStatic(NULL, pdMS_TO_TICKS(BLINK_NOT_MOUNTED), true, NULL, led_blinky_cb, &blinky_tmdef); - xTimerStart(blinky_tm, 0); // Create a task for tinyusb device stack - (void) xTaskCreateStatic( usb_device_task, "usbd", USBD_STACK_SIZE, NULL, configMAX_PRIORITIES-1, usb_device_stack, &usb_device_taskdef); + xTaskCreateStatic(usb_device_task, "usbd", USBD_STACK_SIZE, NULL, configMAX_PRIORITIES-1, usb_device_stack, &usb_device_taskdef); // Create CDC task - (void) xTaskCreateStatic( cdc_task, "cdc", CDC_STACK_SZIE, NULL, configMAX_PRIORITIES-2, cdc_stack, &cdc_taskdef); + xTaskCreateStatic(cdc_task, "cdc", CDC_STACK_SZIE, NULL, configMAX_PRIORITIES-2, cdc_stack, &cdc_taskdef); +#else + blinky_tm = xTimerCreate(NULL, pdMS_TO_TICKS(BLINK_NOT_MOUNTED), true, NULL, led_blinky_cb); + xTaskCreate( usb_device_task, "usbd", USBD_STACK_SIZE, NULL, configMAX_PRIORITIES-1, NULL); + xTaskCreate( cdc_task, "cdc", CDC_STACK_SZIE, NULL, configMAX_PRIORITIES-2, NULL); +#endif + + xTimerStart(blinky_tm, 0); // skip starting scheduler (and return) for ESP32-S2 or ESP32-S3 #if !TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3) diff --git a/examples/device/hid_composite_freertos/Makefile b/examples/device/hid_composite_freertos/Makefile index 6c8c43dd..9c66b896 100644 --- a/examples/device/hid_composite_freertos/Makefile +++ b/examples/device/hid_composite_freertos/Makefile @@ -28,8 +28,15 @@ SRC_C += \ $(FREERTOS_SRC)/timers.c \ $(subst ../../../,,$(wildcard ../../../$(FREERTOS_SRC)/portable/GCC/$(FREERTOS_PORT)/*.c)) -# Suppress FreeRTOS warnings -CFLAGS += -Wno-error=cast-qual -Wno-error=redundant-decls +# include heap manage if configSUPPORT_DYNAMIC_ALLOCATION = 1 +# SRC_C += $(FREERTOS_SRC)/portable/MemMang/heap_1.c +# CFLAGS += -Wno-error=sign-compare + +# Suppress FreeRTOSConfig.h warnings +CFLAGS += -Wno-error=redundant-decls + +# Suppress FreeRTOS source warnings +CFLAGS += -Wno-error=cast-qual # FreeRTOS (lto + Os) linker issue LDFLAGS += -Wl,--undefined=vTaskSwitchContext diff --git a/examples/device/hid_composite_freertos/src/FreeRTOSConfig/FreeRTOSConfig.h b/examples/device/hid_composite_freertos/src/FreeRTOSConfig/FreeRTOSConfig.h index bfdf1e92..968c5974 100644 --- a/examples/device/hid_composite_freertos/src/FreeRTOSConfig/FreeRTOSConfig.h +++ b/examples/device/hid_composite_freertos/src/FreeRTOSConfig/FreeRTOSConfig.h @@ -46,13 +46,14 @@ #include "bsp/board_mcu.h" #if CFG_TUSB_MCU == OPT_MCU_ESP32S2 || CFG_TUSB_MCU == OPT_MCU_ESP32S3 -#error "ESP32-Sx should use IDF's FreeRTOSConfig.h" + #error "ESP32-Sx should use IDF's FreeRTOSConfig.h" #endif +// TODO fix later #if CFG_TUSB_MCU == OPT_MCU_MM32F327X - // TODO fix/remove later extern u32 SystemCoreClock; #else + // FIXME cause redundant-decls warnings extern uint32_t SystemCoreClock; #endif @@ -68,7 +69,7 @@ #define configTICK_RATE_HZ ( 1000 ) #define configMAX_PRIORITIES ( 5 ) #define configMINIMAL_STACK_SIZE ( 128 ) -#define configTOTAL_HEAP_SIZE ( 0*1024 ) // dynamic is not used +#define configTOTAL_HEAP_SIZE ( configSUPPORT_DYNAMIC_ALLOCATION*4*1024 ) #define configMAX_TASK_NAME_LEN 16 #define configUSE_16_BIT_TICKS 0 #define configIDLE_SHOULD_YIELD 1 diff --git a/examples/device/hid_composite_freertos/src/main.c b/examples/device/hid_composite_freertos/src/main.c index b67c1093..fb0d6925 100644 --- a/examples/device/hid_composite_freertos/src/main.c +++ b/examples/device/hid_composite_freertos/src/main.c @@ -53,6 +53,8 @@ #define USBD_STACK_SIZE (3*configMINIMAL_STACK_SIZE/2) * (CFG_TUSB_DEBUG ? 2 : 1) #endif +#define HID_STACK_SZIE configMINIMAL_STACK_SIZE + //--------------------------------------------------------------------+ // MACRO CONSTANT TYPEDEF PROTYPES //--------------------------------------------------------------------+ @@ -68,19 +70,18 @@ enum { BLINK_SUSPENDED = 2500, }; -// static timer +// static timer & task +#if configSUPPORT_STATIC_ALLOCATION StaticTimer_t blinky_tmdef; -TimerHandle_t blinky_tm; -// static task StackType_t usb_device_stack[USBD_STACK_SIZE]; StaticTask_t usb_device_taskdef; -// static task for hid -#define HID_STACK_SZIE configMINIMAL_STACK_SIZE StackType_t hid_stack[HID_STACK_SZIE]; StaticTask_t hid_taskdef; +#endif +TimerHandle_t blinky_tm; void led_blinky_cb(TimerHandle_t xTimer); void usb_device_task(void* param); @@ -94,15 +95,22 @@ int main(void) { board_init(); +#if configSUPPORT_STATIC_ALLOCATION // soft timer for blinky blinky_tm = xTimerCreateStatic(NULL, pdMS_TO_TICKS(BLINK_NOT_MOUNTED), true, NULL, led_blinky_cb, &blinky_tmdef); - xTimerStart(blinky_tm, 0); // Create a task for tinyusb device stack - (void) xTaskCreateStatic( usb_device_task, "usbd", USBD_STACK_SIZE, NULL, configMAX_PRIORITIES-1, usb_device_stack, &usb_device_taskdef); + xTaskCreateStatic(usb_device_task, "usbd", USBD_STACK_SIZE, NULL, configMAX_PRIORITIES-1, usb_device_stack, &usb_device_taskdef); // Create HID task - (void) xTaskCreateStatic( hid_task, "hid", HID_STACK_SZIE, NULL, configMAX_PRIORITIES-2, hid_stack, &hid_taskdef); + xTaskCreateStatic(hid_task, "hid", HID_STACK_SZIE, NULL, configMAX_PRIORITIES-2, hid_stack, &hid_taskdef); +#else + blinky_tm = xTimerCreate(NULL, pdMS_TO_TICKS(BLINK_NOT_MOUNTED), true, NULL, led_blinky_cb); + xTaskCreate(usb_device_task, "usbd", USBD_STACK_SIZE, NULL, configMAX_PRIORITIES-1, NULL); + xTaskCreate(hid_task, "hid", HID_STACK_SZIE, NULL, configMAX_PRIORITIES-2, NULL); +#endif + + xTimerStart(blinky_tm, 0); // skip starting scheduler (and return) for ESP32-S2 or ESP32-S3 #if !TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3) diff --git a/src/osal/osal_freertos.h b/src/osal/osal_freertos.h index ccb98cc9..327aa997 100644 --- a/src/osal/osal_freertos.h +++ b/src/osal/osal_freertos.h @@ -37,6 +37,43 @@ extern "C" { #endif +//--------------------------------------------------------------------+ +// MACRO CONSTANT TYPEDEF PROTYPES +//--------------------------------------------------------------------+ + +#if configSUPPORT_STATIC_ALLOCATION + typedef StaticSemaphore_t osal_semaphore_def_t; + typedef StaticSemaphore_t osal_mutex_def_t; +#else + // not used therefore defined to smallest possible type to save space + typedef uint8_t osal_semaphore_def_t; + typedef uint8_t osal_mutex_def_t; +#endif + +typedef SemaphoreHandle_t osal_semaphore_t; +typedef SemaphoreHandle_t osal_mutex_t; + +// _int_set is not used with an RTOS +#define OSAL_QUEUE_DEF(_int_set, _name, _depth, _type) \ + static _type _name##_##buf[_depth];\ + osal_queue_def_t _name = { .depth = _depth, .item_sz = sizeof(_type), .buf = _name##_##buf }; + +typedef struct +{ + uint16_t depth; + uint16_t item_sz; + void* buf; +#if configSUPPORT_STATIC_ALLOCATION + StaticQueue_t sq; +#endif +}osal_queue_def_t; + +typedef QueueHandle_t osal_queue_t; + +//--------------------------------------------------------------------+ +// TASK API +//--------------------------------------------------------------------+ + TU_ATTR_ALWAYS_INLINE static inline uint32_t _osal_ms2tick(uint32_t msec) { if (msec == OSAL_TIMEOUT_WAIT_FOREVER) return portMAX_DELAY; @@ -51,9 +88,6 @@ TU_ATTR_ALWAYS_INLINE static inline uint32_t _osal_ms2tick(uint32_t msec) return ticks; } -//--------------------------------------------------------------------+ -// TASK API -//--------------------------------------------------------------------+ TU_ATTR_ALWAYS_INLINE static inline void osal_task_delay(uint32_t msec) { vTaskDelay( pdMS_TO_TICKS(msec) ); @@ -62,19 +96,13 @@ TU_ATTR_ALWAYS_INLINE static inline void osal_task_delay(uint32_t msec) //--------------------------------------------------------------------+ // Semaphore API //--------------------------------------------------------------------+ -#if configSUPPORT_STATIC_ALLOCATION == 1 -typedef StaticSemaphore_t osal_semaphore_def_t; -#else -typedef SemaphoreHandle_t osal_semaphore_def_t; -#endif -typedef SemaphoreHandle_t osal_semaphore_t; TU_ATTR_ALWAYS_INLINE static inline osal_semaphore_t osal_semaphore_create(osal_semaphore_def_t* semdef) { -#if configSUPPORT_STATIC_ALLOCATION == 1 +#if configSUPPORT_STATIC_ALLOCATION return xSemaphoreCreateBinaryStatic(semdef); #else - (void)(semdef); + (void) semdef; return xSemaphoreCreateBinary(); #endif } @@ -101,7 +129,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) +TU_ATTR_ALWAYS_INLINE static inline bool osal_semaphore_wait(osal_semaphore_t sem_hdl, uint32_t msec) { return xSemaphoreTake(sem_hdl, _osal_ms2tick(msec)); } @@ -114,25 +142,18 @@ TU_ATTR_ALWAYS_INLINE static inline void osal_semaphore_reset(osal_semaphore_t c //--------------------------------------------------------------------+ // MUTEX API (priority inheritance) //--------------------------------------------------------------------+ -#if configSUPPORT_STATIC_ALLOCATION == 1 -typedef StaticSemaphore_t osal_mutex_def_t; -#else -typedef SemaphoreHandle_t osal_mutex_def_t; -#endif -typedef SemaphoreHandle_t osal_mutex_t; TU_ATTR_ALWAYS_INLINE static inline osal_mutex_t osal_mutex_create(osal_mutex_def_t* mdef) { -#if configSUPPORT_STATIC_ALLOCATION == 1 +#if configSUPPORT_STATIC_ALLOCATION return xSemaphoreCreateMutexStatic(mdef); #else - (void)(mdef); + (void) mdef; return xSemaphoreCreateMutex(); #endif - } -TU_ATTR_ALWAYS_INLINE static inline bool osal_mutex_lock (osal_mutex_t mutex_hdl, uint32_t msec) +TU_ATTR_ALWAYS_INLINE static inline bool osal_mutex_lock(osal_mutex_t mutex_hdl, uint32_t msec) { return osal_semaphore_wait(mutex_hdl, msec); } @@ -146,26 +167,9 @@ TU_ATTR_ALWAYS_INLINE static inline bool osal_mutex_unlock(osal_mutex_t mutex_hd // QUEUE API //--------------------------------------------------------------------+ -// _int_set is not used with an RTOS -#define OSAL_QUEUE_DEF(_int_set, _name, _depth, _type) \ - static _type _name##_##buf[_depth];\ - osal_queue_def_t _name = { .depth = _depth, .item_sz = sizeof(_type), .buf = _name##_##buf }; - -typedef struct -{ - uint16_t depth; - uint16_t item_sz; - void* buf; -#if configSUPPORT_STATIC_ALLOCATION == 1 - StaticQueue_t sq; -#endif -}osal_queue_def_t; - -typedef QueueHandle_t osal_queue_t; - TU_ATTR_ALWAYS_INLINE static inline osal_queue_t osal_queue_create(osal_queue_def_t* qdef) { -#if configSUPPORT_STATIC_ALLOCATION == 1 +#if configSUPPORT_STATIC_ALLOCATION return xQueueCreateStatic(qdef->depth, qdef->item_sz, (uint8_t*) qdef->buf, &qdef->sq); #else return xQueueCreate(qdef->depth, qdef->item_sz); diff --git a/src/portable/ehci/ehci.c b/src/portable/ehci/ehci.c index 36101596..76ba2a92 100644 --- a/src/portable/ehci/ehci.c +++ b/src/portable/ehci/ehci.c @@ -193,7 +193,7 @@ static void list_remove_qhd_by_addr(ehci_link_t* list_head, uint8_t dev_addr) { // TODO check type for ISO iTD and siTD // TODO Suppress cast-align warning - #pragma GCC diagnostic push + #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wcast-align" ehci_qhd_t* qhd = (ehci_qhd_t*) list_next(prev); #pragma GCC diagnostic pop