From a789fad4b7b23b8324e07ee4b9d08a145f5df0f9 Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 1 Mar 2018 11:17:11 +0700 Subject: [PATCH] clean up osal semaphore/queue/mutex --- demos/device/src/cdc_device_app.c | 6 +- demos/host/host_freertos/.cproject | 263 ++++++++++++++------------- demos/host/src/cdc_serial_host_app.c | 13 +- demos/host/src/cdc_serial_host_app.h | 2 +- demos/host/src/keyboard_host_app.c | 14 +- demos/host/src/keyboard_host_app.h | 2 +- demos/host/src/main.c | 1 - demos/host/src/mouse_host_app.c | 14 +- demos/host/src/mouse_host_app.h | 2 +- demos/host/src/msc_host_app.c | 8 +- demos/host/src/msc_host_app.h | 2 +- demos/host/src/rndis_host_app.c | 2 +- demos/host/src/rndis_host_app.h | 2 +- tinyusb/class/cdc_rndis_host.c | 2 +- tinyusb/class/msc_host.c | 5 +- tinyusb/device/usbd.c | 5 +- tinyusb/device/usbd.h | 2 +- tinyusb/host/usbh.c | 8 +- tinyusb/host/usbh.h | 2 +- tinyusb/host/usbh_hcd.h | 7 +- tinyusb/osal/osal.h | 3 - tinyusb/osal/osal_freeRTOS.h | 40 ++-- tinyusb/osal/osal_none.h | 67 ++++--- vendor/freertos/FreeRTOSConfig.h | 2 +- 24 files changed, 225 insertions(+), 249 deletions(-) diff --git a/demos/device/src/cdc_device_app.c b/demos/device/src/cdc_device_app.c index f7008585c..2319e01e9 100644 --- a/demos/device/src/cdc_device_app.c +++ b/demos/device/src/cdc_device_app.c @@ -51,9 +51,7 @@ enum { SERIAL_BUFFER_SIZE = 64 }; //--------------------------------------------------------------------+ // MACRO CONSTANT TYPEDEF //--------------------------------------------------------------------+ -OSAL_SEM_DEF(cdcd_semaphore); - -static osal_semaphore_handle_t sem_hdl; +static osal_semaphore_t sem_hdl; //--------------------------------------------------------------------+ // INTERNAL OBJECT & FUNCTION DECLARATION @@ -115,7 +113,7 @@ void tusbd_cdc_xfer_cb(uint8_t coreid, tusb_event_t event, cdc_pipeid_t pipe_id, //--------------------------------------------------------------------+ void cdcd_serial_app_init(void) { - sem_hdl = osal_semaphore_create( OSAL_SEM_REF(cdcd_semaphore) ); + sem_hdl = osal_semaphore_create(1, 0); ASSERT_PTR( sem_hdl, VOID_RETURN); osal_task_create(cdcd_serial_app_task, "cdc", 128, NULL, CDC_SERIAL_APP_TASK_PRIO, NULL); diff --git a/demos/host/host_freertos/.cproject b/demos/host/host_freertos/.cproject index 8f6fe06b2..2bbd2124e 100644 --- a/demos/host/host_freertos/.cproject +++ b/demos/host/host_freertos/.cproject @@ -4,20 +4,20 @@ - + + + - - @@ -53,7 +53,7 @@ - - + + + - - @@ -388,20 +391,20 @@ - + + + - - @@ -437,7 +440,7 @@ - - <?xml version="1.0" encoding="UTF-8"?> -<TargetConfig> -<Properties property_0="None" property_2="LPC18_43_SPIFI_4MB_64KB.cfx" property_3="NXP" property_4="LPC4330" property_count="5" version="70200"/> -<infoList vendor="NXP"><info chip="LPC4330" match_id="0x0" name="LPC4330" resetscript="LPC18LPC43ExternalFLASHBootResetscript.scp" stub="crt_emu_lpc18_43_nxp"><chip><name>LPC4330</name> -<family>LPC43xx</family> -<vendor>NXP (formerly Philips)</vendor> -<reset board="None" core="Real" sys="Real"/> -<clock changeable="TRUE" freq="20MHz" is_accurate="TRUE"/> -<memory can_program="true" id="Flash" is_ro="true" type="Flash"/> -<memory id="RAM" type="RAM"/> -<memory id="Periph" is_volatile="true" type="Peripheral"/> -<memoryInstance derived_from="Flash" edited="true" id="FlashSPIFI" location="0x14000000" size="0x40000"/> -<memoryInstance derived_from="RAM" edited="true" id="RamLoc128" location="0x10000000" size="0x20000"/> -<memoryInstance derived_from="RAM" edited="true" id="RamLoc72" location="0x10080000" size="0x12000"/> -<memoryInstance derived_from="RAM" edited="true" id="RamAHB32" location="0x20000000" size="0x8000"/> -<memoryInstance derived_from="RAM" edited="true" id="RamAHB16" location="0x20008000" size="0x4000"/> -<memoryInstance derived_from="RAM" edited="true" id="RamAHB_ETB16" location="0x2000c000" size="0x4000"/> -<peripheralInstance derived_from="V7M_MPU" id="MPU" location="0xe000ed90"/> -<peripheralInstance derived_from="V7M_NVIC" id="NVIC" location="0xe000e000"/> -<peripheralInstance derived_from="V7M_DCR" id="DCR" location="0xe000edf0"/> -<peripheralInstance derived_from="V7M_ITM" id="ITM" location="0xe0000000"/> -<peripheralInstance derived_from="SCT" id="SCT" location="0x40000000"/> -<peripheralInstance derived_from="GPDMA" id="GPDMA" location="0x40002000"/> -<peripheralInstance derived_from="SPIFI" id="SPIFI" location="0x40003000"/> -<peripheralInstance derived_from="SDMMC" id="SDMMC" location="0x40004000"/> -<peripheralInstance derived_from="EMC" id="EMC" location="0x40005000"/> -<peripheralInstance derived_from="USB0" id="USB0" location="0x40006000"/> -<peripheralInstance derived_from="USB1" id="USB1" location="0x40007000"/> -<peripheralInstance derived_from="EEPROM" id="EEPROM" location="0x4000e000"/> -<peripheralInstance derived_from="ETHERNET" id="ETHERNET" location="0x40010000"/> -<peripheralInstance derived_from="ATIMER" id="ATIMER" location="0x40040000"/> -<peripheralInstance derived_from="REGFILE" id="REGFILE" location="0x40041000"/> -<peripheralInstance derived_from="PMC" id="PMC" location="0x40042000"/> -<peripheralInstance derived_from="CREG" id="CREG" location="0x40043000"/> -<peripheralInstance derived_from="EVENTROUTER" id="EVENTROUTER" location="0x40044000"/> -<peripheralInstance derived_from="RTC" id="RTC" location="0x40046000"/> -<peripheralInstance derived_from="CGU" id="CGU" location="0x40050000"/> -<peripheralInstance derived_from="CCU1" id="CCU1" location="0x40051000"/> -<peripheralInstance derived_from="CCU2" id="CCU2" location="0x40052000"/> -<peripheralInstance derived_from="RGU" id="RGU" location="0x40053000"/> -<peripheralInstance derived_from="WWDT" id="WWDT" location="0x40080000"/> -<peripheralInstance derived_from="USART0" id="USART0" location="0x40081000"/> -<peripheralInstance derived_from="USART2" id="USART2" location="0x400c1000"/> -<peripheralInstance derived_from="USART3" id="USART3" location="0x400c2000"/> -<peripheralInstance derived_from="UART1" id="UART1" location="0x40082000"/> -<peripheralInstance derived_from="SSP0" id="SSP0" location="0x40083000"/> -<peripheralInstance derived_from="SSP1" id="SSP1" location="0x400c5000"/> -<peripheralInstance derived_from="TIMER0" id="TIMER0" location="0x40084000"/> -<peripheralInstance derived_from="TIMER1" id="TIMER1" location="0x40085000"/> -<peripheralInstance derived_from="TIMER2" id="TIMER2" location="0x400c3000"/> -<peripheralInstance derived_from="TIMER3" id="TIMER3" location="0x400c4000"/> -<peripheralInstance derived_from="SCU" id="SCU" location="0x40086000"/> -<peripheralInstance derived_from="GPIO-PIN-INT" id="GPIO-PIN-INT" location="0x40087000"/> -<peripheralInstance derived_from="GPIO-GROUP-INT0" id="GPIO-GROUP-INT0" location="0x40088000"/> -<peripheralInstance derived_from="GPIO-GROUP-INT1" id="GPIO-GROUP-INT1" location="0x40089000"/> -<peripheralInstance derived_from="MCPWM" id="MCPWM" location="0x400a0000"/> -<peripheralInstance derived_from="I2C0" id="I2C0" location="0x400a1000"/> -<peripheralInstance derived_from="I2C1" id="I2C1" location="0x400e0000"/> -<peripheralInstance derived_from="I2S0" id="I2S0" location="0x400a2000"/> -<peripheralInstance derived_from="I2S1" id="I2S1" location="0x400a3000"/> -<peripheralInstance derived_from="C-CAN1" id="C-CAN1" location="0x400a4000"/> -<peripheralInstance derived_from="RITIMER" id="RITIMER" location="0x400c0000"/> -<peripheralInstance derived_from="QEI" id="QEI" location="0x400c6000"/> -<peripheralInstance derived_from="GIMA" id="GIMA" location="0x400c7000"/> -<peripheralInstance derived_from="DAC" id="DAC" location="0x400e1000"/> -<peripheralInstance derived_from="C-CAN0" id="C-CAN0" location="0x400e2000"/> -<peripheralInstance derived_from="ADC0" id="ADC0" location="0x400e3000"/> -<peripheralInstance derived_from="ADC1" id="ADC1" location="0x400e4000"/> -<peripheralInstance derived_from="GPIO-PORT" id="GPIO-PORT" location="0x400f4000"/> -<peripheralInstance derived_from="SPI" id="SPI" location="0x40100000"/> -<peripheralInstance derived_from="SGPIO" id="SGPIO" location="0x40101000"/> -</chip> -<processor><name gcc_name="cortex-m4">Cortex-M4</name> -<family>Cortex-M</family> -</processor> -<link href="nxp_lpc43xx_peripheral.xme" show="embed" type="simple"/> -</info> -</infoList> + <?xml version="1.0" encoding="UTF-8"?> +<TargetConfig> +<Properties property_0="None" property_2="LPC18_43_SPIFI_4MB_64KB.cfx" property_3="NXP" property_4="LPC4330" property_count="5" version="70200"/> +<infoList vendor="NXP"><info chip="LPC4330" match_id="0x0" name="LPC4330" resetscript="LPC18LPC43ExternalFLASHBootResetscript.scp" stub="crt_emu_lpc18_43_nxp"><chip><name>LPC4330</name> +<family>LPC43xx</family> +<vendor>NXP (formerly Philips)</vendor> +<reset board="None" core="Real" sys="Real"/> +<clock changeable="TRUE" freq="20MHz" is_accurate="TRUE"/> +<memory can_program="true" id="Flash" is_ro="true" type="Flash"/> +<memory id="RAM" type="RAM"/> +<memory id="Periph" is_volatile="true" type="Peripheral"/> +<memoryInstance derived_from="Flash" edited="true" id="FlashSPIFI" location="0x14000000" size="0x40000"/> +<memoryInstance derived_from="RAM" edited="true" id="RamLoc128" location="0x10000000" size="0x20000"/> +<memoryInstance derived_from="RAM" edited="true" id="RamLoc72" location="0x10080000" size="0x12000"/> +<memoryInstance derived_from="RAM" edited="true" id="RamAHB32" location="0x20000000" size="0x8000"/> +<memoryInstance derived_from="RAM" edited="true" id="RamAHB16" location="0x20008000" size="0x4000"/> +<memoryInstance derived_from="RAM" edited="true" id="RamAHB_ETB16" location="0x2000c000" size="0x4000"/> +<peripheralInstance derived_from="V7M_MPU" id="MPU" location="0xe000ed90"/> +<peripheralInstance derived_from="V7M_NVIC" id="NVIC" location="0xe000e000"/> +<peripheralInstance derived_from="V7M_DCR" id="DCR" location="0xe000edf0"/> +<peripheralInstance derived_from="V7M_ITM" id="ITM" location="0xe0000000"/> +<peripheralInstance derived_from="SCT" id="SCT" location="0x40000000"/> +<peripheralInstance derived_from="GPDMA" id="GPDMA" location="0x40002000"/> +<peripheralInstance derived_from="SPIFI" id="SPIFI" location="0x40003000"/> +<peripheralInstance derived_from="SDMMC" id="SDMMC" location="0x40004000"/> +<peripheralInstance derived_from="EMC" id="EMC" location="0x40005000"/> +<peripheralInstance derived_from="USB0" id="USB0" location="0x40006000"/> +<peripheralInstance derived_from="USB1" id="USB1" location="0x40007000"/> +<peripheralInstance derived_from="EEPROM" id="EEPROM" location="0x4000e000"/> +<peripheralInstance derived_from="ETHERNET" id="ETHERNET" location="0x40010000"/> +<peripheralInstance derived_from="ATIMER" id="ATIMER" location="0x40040000"/> +<peripheralInstance derived_from="REGFILE" id="REGFILE" location="0x40041000"/> +<peripheralInstance derived_from="PMC" id="PMC" location="0x40042000"/> +<peripheralInstance derived_from="CREG" id="CREG" location="0x40043000"/> +<peripheralInstance derived_from="EVENTROUTER" id="EVENTROUTER" location="0x40044000"/> +<peripheralInstance derived_from="RTC" id="RTC" location="0x40046000"/> +<peripheralInstance derived_from="CGU" id="CGU" location="0x40050000"/> +<peripheralInstance derived_from="CCU1" id="CCU1" location="0x40051000"/> +<peripheralInstance derived_from="CCU2" id="CCU2" location="0x40052000"/> +<peripheralInstance derived_from="RGU" id="RGU" location="0x40053000"/> +<peripheralInstance derived_from="WWDT" id="WWDT" location="0x40080000"/> +<peripheralInstance derived_from="USART0" id="USART0" location="0x40081000"/> +<peripheralInstance derived_from="USART2" id="USART2" location="0x400c1000"/> +<peripheralInstance derived_from="USART3" id="USART3" location="0x400c2000"/> +<peripheralInstance derived_from="UART1" id="UART1" location="0x40082000"/> +<peripheralInstance derived_from="SSP0" id="SSP0" location="0x40083000"/> +<peripheralInstance derived_from="SSP1" id="SSP1" location="0x400c5000"/> +<peripheralInstance derived_from="TIMER0" id="TIMER0" location="0x40084000"/> +<peripheralInstance derived_from="TIMER1" id="TIMER1" location="0x40085000"/> +<peripheralInstance derived_from="TIMER2" id="TIMER2" location="0x400c3000"/> +<peripheralInstance derived_from="TIMER3" id="TIMER3" location="0x400c4000"/> +<peripheralInstance derived_from="SCU" id="SCU" location="0x40086000"/> +<peripheralInstance derived_from="GPIO-PIN-INT" id="GPIO-PIN-INT" location="0x40087000"/> +<peripheralInstance derived_from="GPIO-GROUP-INT0" id="GPIO-GROUP-INT0" location="0x40088000"/> +<peripheralInstance derived_from="GPIO-GROUP-INT1" id="GPIO-GROUP-INT1" location="0x40089000"/> +<peripheralInstance derived_from="MCPWM" id="MCPWM" location="0x400a0000"/> +<peripheralInstance derived_from="I2C0" id="I2C0" location="0x400a1000"/> +<peripheralInstance derived_from="I2C1" id="I2C1" location="0x400e0000"/> +<peripheralInstance derived_from="I2S0" id="I2S0" location="0x400a2000"/> +<peripheralInstance derived_from="I2S1" id="I2S1" location="0x400a3000"/> +<peripheralInstance derived_from="C-CAN1" id="C-CAN1" location="0x400a4000"/> +<peripheralInstance derived_from="RITIMER" id="RITIMER" location="0x400c0000"/> +<peripheralInstance derived_from="QEI" id="QEI" location="0x400c6000"/> +<peripheralInstance derived_from="GIMA" id="GIMA" location="0x400c7000"/> +<peripheralInstance derived_from="DAC" id="DAC" location="0x400e1000"/> +<peripheralInstance derived_from="C-CAN0" id="C-CAN0" location="0x400e2000"/> +<peripheralInstance derived_from="ADC0" id="ADC0" location="0x400e3000"/> +<peripheralInstance derived_from="ADC1" id="ADC1" location="0x400e4000"/> +<peripheralInstance derived_from="GPIO-PORT" id="GPIO-PORT" location="0x400f4000"/> +<peripheralInstance derived_from="SPI" id="SPI" location="0x40100000"/> +<peripheralInstance derived_from="SGPIO" id="SGPIO" location="0x40101000"/> +</chip> +<processor><name gcc_name="cortex-m4">Cortex-M4</name> +<family>Cortex-M</family> +</processor> +<link href="nxp_lpc43xx_peripheral.xme" show="embed" type="simple"/> +</info> +</infoList> </TargetConfig> @@ -1136,4 +1140,5 @@ + diff --git a/demos/host/src/cdc_serial_host_app.c b/demos/host/src/cdc_serial_host_app.c index 14b052739..62ed3e1ee 100644 --- a/demos/host/src/cdc_serial_host_app.c +++ b/demos/host/src/cdc_serial_host_app.c @@ -46,10 +46,7 @@ //--------------------------------------------------------------------+ // MACRO CONSTANT TYPEDEF //--------------------------------------------------------------------+ -OSAL_TASK_DEF(cdc_serial_host_app_task, 128, CDC_SERIAL_APP_TASK_PRIO); -OSAL_SEM_DEF(serial_semaphore); - -static osal_semaphore_handle_t sem_hdl; +static osal_semaphore_t sem_hdl; enum { SERIAL_BUFFER_SIZE = 64 }; TUSB_CFG_ATTR_USBRAM static uint8_t serial_in_buffer[SERIAL_BUFFER_SIZE]; @@ -115,16 +112,16 @@ void tuh_cdc_xfer_isr(uint8_t dev_addr, tusb_event_t event, cdc_pipeid_t pipe_id //--------------------------------------------------------------------+ void cdc_serial_host_app_init(void) { - sem_hdl = osal_semaphore_create( OSAL_SEM_REF(serial_semaphore) ); + sem_hdl = osal_semaphore_create(1, 0); ASSERT_PTR( sem_hdl, VOID_RETURN); - ASSERT( TUSB_ERROR_NONE == osal_task_create(OSAL_TASK_REF(cdc_serial_host_app_task)), VOID_RETURN); + VERIFY( osal_task_create(cdc_serial_host_app_task, "cdc", 128, NULL, CDC_SERIAL_APP_TASK_PRIO, NULL), ); } //------------- main task -------------// -OSAL_TASK_FUNCTION( cdc_serial_host_app_task, p_task_para) +void cdc_serial_host_app_task( void* param ) { - (void) p_task_para; + (void) param; OSAL_TASK_LOOP_BEGIN diff --git a/demos/host/src/cdc_serial_host_app.h b/demos/host/src/cdc_serial_host_app.h index f041b1467..78bdbdc24 100644 --- a/demos/host/src/cdc_serial_host_app.h +++ b/demos/host/src/cdc_serial_host_app.h @@ -56,7 +56,7 @@ #if TUSB_CFG_HOST_CDC void cdc_serial_host_app_init(void); -OSAL_TASK_FUNCTION( cdc_serial_host_app_task, p_task_para); +void cdc_serial_host_app_task(void* param); #else diff --git a/demos/host/src/keyboard_host_app.c b/demos/host/src/keyboard_host_app.c index 4c85d5d3b..d5d39d428 100644 --- a/demos/host/src/keyboard_host_app.c +++ b/demos/host/src/keyboard_host_app.c @@ -52,10 +52,7 @@ //--------------------------------------------------------------------+ // INTERNAL OBJECT & FUNCTION DECLARATION //--------------------------------------------------------------------+ -OSAL_TASK_DEF(keyboard_host_app_task, 128, KEYBOARD_APP_TASK_PRIO); -OSAL_QUEUE_DEF(queue_kbd_def, QUEUE_KEYBOARD_REPORT_DEPTH, hid_keyboard_report_t); - -static osal_queue_handle_t queue_kbd_hdl; +static osal_queue_t queue_kbd_hdl; TUSB_CFG_ATTR_USBRAM static hid_keyboard_report_t usb_keyboard_report; static inline uint8_t keycode_to_ascii(uint8_t modifier, uint8_t keycode) ATTR_CONST ATTR_ALWAYS_INLINE; @@ -105,17 +102,16 @@ void keyboard_host_app_init(void) { memclr_(&usb_keyboard_report, sizeof(hid_keyboard_report_t)); - queue_kbd_hdl = osal_queue_create( OSAL_QUEUE_REF(queue_kbd_def) ); + queue_kbd_hdl = osal_queue_create( QUEUE_KEYBOARD_REPORT_DEPTH, sizeof(hid_keyboard_report_t) ); ASSERT_PTR( queue_kbd_hdl, VOID_RETURN ); - ASSERT( TUSB_ERROR_NONE == osal_task_create( OSAL_TASK_REF(keyboard_host_app_task) ) , - VOID_RETURN); + VERIFY( osal_task_create(keyboard_host_app_task, "kbd", 128, NULL, KEYBOARD_APP_TASK_PRIO, NULL), ); } //------------- main task -------------// -OSAL_TASK_FUNCTION( keyboard_host_app_task, p_task_para) +void keyboard_host_app_task(void* param) { - (void) p_task_para; + (void) param; OSAL_TASK_LOOP_BEGIN diff --git a/demos/host/src/keyboard_host_app.h b/demos/host/src/keyboard_host_app.h index ec27d5d89..96deb15c1 100644 --- a/demos/host/src/keyboard_host_app.h +++ b/demos/host/src/keyboard_host_app.h @@ -62,7 +62,7 @@ #if TUSB_CFG_HOST_HID_KEYBOARD void keyboard_host_app_init(void); -OSAL_TASK_FUNCTION( keyboard_host_app_task, p_task_para); +void keyboard_host_app_task(void* param); #else diff --git a/demos/host/src/main.c b/demos/host/src/main.c index f7d3b1a7c..66ca6456c 100644 --- a/demos/host/src/main.c +++ b/demos/host/src/main.c @@ -123,7 +123,6 @@ void print_greeting(void) { [TUSB_OS_NONE] = "None", [TUSB_OS_FREERTOS] = "FreeRTOS", - [TUSB_OS_CMSIS_RTX] = "CMSIS-RTX" }; puts("\n\ diff --git a/demos/host/src/mouse_host_app.c b/demos/host/src/mouse_host_app.c index 23a3e9b5c..a68510f66 100644 --- a/demos/host/src/mouse_host_app.c +++ b/demos/host/src/mouse_host_app.c @@ -52,10 +52,7 @@ //--------------------------------------------------------------------+ // INTERNAL OBJECT & FUNCTION DECLARATION //--------------------------------------------------------------------+ -OSAL_TASK_DEF(mouse_host_app_task, 128, MOUSE_APP_TASK_PRIO); -OSAL_QUEUE_DEF(queue_mouse_def, QUEUE_MOUSE_REPORT_DEPTH, hid_mouse_report_t); - -static osal_queue_handle_t queue_mouse_hdl; +static osal_queue_t queue_mouse_hdl; TUSB_CFG_ATTR_USBRAM static hid_mouse_report_t usb_mouse_report; static inline void process_mouse_report(hid_mouse_report_t const * p_report); @@ -106,17 +103,16 @@ void mouse_host_app_init(void) { memclr_(&usb_mouse_report, sizeof(hid_mouse_report_t)); - queue_mouse_hdl = osal_queue_create( OSAL_QUEUE_REF(queue_mouse_def) ); + queue_mouse_hdl = osal_queue_create( QUEUE_MOUSE_REPORT_DEPTH, sizeof(hid_mouse_report_t) ); ASSERT_PTR( queue_mouse_hdl, VOID_RETURN); - ASSERT( TUSB_ERROR_NONE == osal_task_create( OSAL_TASK_REF(mouse_host_app_task) ), - VOID_RETURN ); + VERIFY( osal_task_create(mouse_host_app_task, "mouse", 128, NULL, MOUSE_APP_TASK_PRIO, NULL), ); } //------------- main task -------------// -OSAL_TASK_FUNCTION( mouse_host_app_task, p_task_para) +void mouse_host_app_task(void* param) { - (void) p_task_para; + (void) param; OSAL_TASK_LOOP_BEGIN diff --git a/demos/host/src/mouse_host_app.h b/demos/host/src/mouse_host_app.h index fdd697353..05f1541f9 100644 --- a/demos/host/src/mouse_host_app.h +++ b/demos/host/src/mouse_host_app.h @@ -65,7 +65,7 @@ #if TUSB_CFG_HOST_HID_MOUSE void mouse_host_app_init(void); -OSAL_TASK_FUNCTION( mouse_host_app_task, p_task_para); +void mouse_host_app_task(void* param); #else diff --git a/demos/host/src/msc_host_app.c b/demos/host/src/msc_host_app.c index d4fe001d1..59a17b1ad 100644 --- a/demos/host/src/msc_host_app.c +++ b/demos/host/src/msc_host_app.c @@ -55,8 +55,6 @@ //--------------------------------------------------------------------+ // INTERNAL OBJECT & FUNCTION DECLARATION //--------------------------------------------------------------------+ -OSAL_TASK_DEF(msc_host_app_task, 512, MSC_APP_TASK_PRIO); - TUSB_CFG_ATTR_USBRAM static FATFS fatfs[TUSB_CFG_HOST_DEVICE_MAX]; //--------------------------------------------------------------------+ @@ -143,14 +141,14 @@ void tuh_msc_isr(uint8_t dev_addr, tusb_event_t event, uint32_t xferred_bytes) //--------------------------------------------------------------------+ void msc_host_app_init(void) { - ASSERT( TUSB_ERROR_NONE == osal_task_create( OSAL_TASK_REF(msc_host_app_task) ), VOID_RETURN ); + osal_task_create( msc_host_app_task, "msc", 512, NULL, MSC_APP_TASK_PRIO, NULL); diskio_init(); } //------------- main task -------------// -OSAL_TASK_FUNCTION( msc_host_app_task, p_task_para) +void msc_host_app_task(void* param) { - (void) p_task_para; + (void) param;; OSAL_TASK_LOOP_BEGIN diff --git a/demos/host/src/msc_host_app.h b/demos/host/src/msc_host_app.h index 0a447be05..4736f33d4 100644 --- a/demos/host/src/msc_host_app.h +++ b/demos/host/src/msc_host_app.h @@ -57,7 +57,7 @@ #if TUSB_CFG_HOST_MSC void msc_host_app_init(void); -OSAL_TASK_FUNCTION( msc_host_app_task, p_task_para); +void msc_host_app_task(void* param); #else diff --git a/demos/host/src/rndis_host_app.c b/demos/host/src/rndis_host_app.c index 50d788a02..4b33144d8 100644 --- a/demos/host/src/rndis_host_app.c +++ b/demos/host/src/rndis_host_app.c @@ -67,7 +67,7 @@ void rndis_host_app_init(void) } -OSAL_TASK_FUNCTION( rndis_host_app_task, p_task_para) +void rndis_host_app_task(void* param) { OSAL_TASK_LOOP_BEGIN OSAL_TASK_LOOP_END diff --git a/demos/host/src/rndis_host_app.h b/demos/host/src/rndis_host_app.h index a7add847d..e4fcacf46 100644 --- a/demos/host/src/rndis_host_app.h +++ b/demos/host/src/rndis_host_app.h @@ -56,7 +56,7 @@ #if TUSB_CFG_HOST_CDC && TUSB_CFG_HOST_CDC_RNDIS void rndis_host_app_init(void); -OSAL_TASK_FUNCTION( rndis_host_app_task, p_task_para); +void rndis_host_app_task(void* param); #else diff --git a/tinyusb/class/cdc_rndis_host.c b/tinyusb/class/cdc_rndis_host.c index 0e31fcc9a..7f164fb48 100644 --- a/tinyusb/class/cdc_rndis_host.c +++ b/tinyusb/class/cdc_rndis_host.c @@ -89,7 +89,7 @@ tusb_error_t tusbh_cdc_rndis_get_mac_addr(uint8_t dev_addr, uint8_t mac_address[ // To enable the TASK_ASSERT style (quick return on false condition) in a real RTOS, a task must act as a wrapper // and is used mainly to call subtasks. Within a subtask return statement can be called freely, the task with // forever loop cannot have any return at all. -OSAL_TASK_FUNCTION(cdch_rndis_task) (void* p_task_para) +OSAL_TASK_FUNCTION(cdch_rndis_task) (void* param;) { OSAL_TASK_LOOP_BEGIN diff --git a/tinyusb/class/msc_host.c b/tinyusb/class/msc_host.c index 5dcc6f301..f4859c1eb 100644 --- a/tinyusb/class/msc_host.c +++ b/tinyusb/class/msc_host.c @@ -54,8 +54,7 @@ TUSB_CFG_ATTR_USBRAM STATIC_VAR msch_interface_t msch_data[TUSB_CFG_HOST_DEVICE_MAX]; //------------- Initalization Data -------------// -OSAL_SEM_DEF(msch_semaphore); -static osal_semaphore_handle_t msch_sem_hdl; +static osal_semaphore_t msch_sem_hdl; // buffer used to read scsi information when mounted, largest response data currently is inquiry TUSB_CFG_ATTR_USBRAM ATTR_ALIGNED(4) STATIC_VAR uint8_t msch_buffer[sizeof(scsi_inquiry_data_t)]; @@ -291,7 +290,7 @@ tusb_error_t tuh_msc_write10(uint8_t dev_addr, uint8_t lun, void const * p_buffe void msch_init(void) { memclr_(msch_data, sizeof(msch_interface_t)*TUSB_CFG_HOST_DEVICE_MAX); - msch_sem_hdl = osal_semaphore_create( OSAL_SEM_REF(msch_semaphore) ); + msch_sem_hdl = osal_semaphore_create(1, 0); } tusb_error_t msch_open_subtask(uint8_t dev_addr, tusb_descriptor_interface_t const *p_interface_desc, uint16_t *p_length) diff --git a/tinyusb/device/usbd.c b/tinyusb/device/usbd.c index c4552c3fc..790143320 100644 --- a/tinyusb/device/usbd.c +++ b/tinyusb/device/usbd.c @@ -147,10 +147,9 @@ STATIC_ASSERT(sizeof(usbd_task_event_t) <= 12, "size is not correct"); #define TUSB_CFG_OS_TASK_PRIO 0 #endif -OSAL_SEM_DEF(usbd_control_xfer_semaphore_def); static osal_queue_t usbd_queue_hdl; -/*static*/ osal_semaphore_handle_t usbd_control_xfer_sem_hdl; // TODO may need to change to static with wrapper function +/*static*/ osal_semaphore_t usbd_control_xfer_sem_hdl; // TODO may need to change to static with wrapper function //--------------------------------------------------------------------+ // IMPLEMENTATION @@ -166,7 +165,7 @@ tusb_error_t usbd_init (void) usbd_queue_hdl = osal_queue_create(USBD_TASK_QUEUE_DEPTH, sizeof(usbd_task_event_t)); ASSERT_PTR(usbd_queue_hdl, TUSB_ERROR_OSAL_QUEUE_FAILED); - usbd_control_xfer_sem_hdl = osal_semaphore_create( OSAL_SEM_REF(usbd_control_xfer_semaphore_def) ); + usbd_control_xfer_sem_hdl = osal_semaphore_create(1, 0); ASSERT_PTR(usbd_queue_hdl, TUSB_ERROR_OSAL_SEMAPHORE_FAILED); osal_task_t usbd_hdl; diff --git a/tinyusb/device/usbd.h b/tinyusb/device/usbd.h index c2c5c702b..1c7f1b79a 100644 --- a/tinyusb/device/usbd.h +++ b/tinyusb/device/usbd.h @@ -99,7 +99,7 @@ bool tusbd_is_configured(uint8_t coreid) ATTR_WARN_UNUSED_RESULT; //--------------------------------------------------------------------+ #ifdef _TINY_USB_SOURCE_FILE_ -extern osal_semaphore_handle_t usbd_control_xfer_sem_hdl; +extern osal_semaphore_t usbd_control_xfer_sem_hdl; tusb_error_t usbd_init(void); void usbd_task( void* param); diff --git a/tinyusb/host/usbh.c b/tinyusb/host/usbh.c index 8d19f5f15..3e242d82b 100644 --- a/tinyusb/host/usbh.c +++ b/tinyusb/host/usbh.c @@ -42,6 +42,10 @@ #define _TINY_USB_SOURCE_FILE_ +#ifndef TUSB_CFG_OS_TASK_PRIO +#define TUSB_CFG_OS_TASK_PRIO 0 +#endif + //--------------------------------------------------------------------+ // INCLUDE //--------------------------------------------------------------------+ @@ -153,10 +157,10 @@ tusb_error_t usbh_init(void) { usbh_device_info_t * const p_device = &usbh_devices[i]; - p_device->control.sem_hdl = osal_semaphore_create( OSAL_SEM_REF(p_device->control.semaphore) ); + p_device->control.sem_hdl = osal_semaphore_create(1, 0); ASSERT_PTR(p_device->control.sem_hdl, TUSB_ERROR_OSAL_SEMAPHORE_FAILED); - p_device->control.mutex_hdl = osal_mutex_create ( OSAL_MUTEX_REF(p_device->control.mutex) ); + p_device->control.mutex_hdl = osal_mutex_create(); ASSERT_PTR(p_device->control.mutex_hdl, TUSB_ERROR_OSAL_MUTEX_FAILED); } diff --git a/tinyusb/host/usbh.h b/tinyusb/host/usbh.h index 33e4e5a50..d7610888e 100644 --- a/tinyusb/host/usbh.h +++ b/tinyusb/host/usbh.h @@ -98,7 +98,7 @@ ATTR_WEAK void tuh_device_mount_failed_cb(tusb_error_t error, tusb_descriptor #ifdef _TINY_USB_SOURCE_FILE_ -OSAL_TASK_FUNCTION (usbh_enumeration_task, p_task_para); +void usbh_enumeration_task(void* param); tusb_error_t usbh_init(void); tusb_error_t usbh_control_xfer_subtask(uint8_t dev_addr, uint8_t bmRequestType, uint8_t bRequest, diff --git a/tinyusb/host/usbh_hcd.h b/tinyusb/host/usbh_hcd.h index 7e03e8764..0f96d4ddc 100644 --- a/tinyusb/host/usbh_hcd.h +++ b/tinyusb/host/usbh_hcd.h @@ -91,11 +91,8 @@ typedef struct { // uint8_t xferred_bytes; TODO not yet necessary tusb_control_request_t request; - OSAL_SEM_DEF(semaphore); // TODO move to semaphore pool ? - osal_semaphore_handle_t sem_hdl; // used to synchronize with HCD when control xfer complete - - OSAL_MUTEX_DEF(mutex); // TODO move to mutex pool ? - osal_mutex_handle_t mutex_hdl; // used to exclusively occupy control pipe + osal_semaphore_t sem_hdl; // used to synchronize with HCD when control xfer complete + osal_mutex_t mutex_hdl; // used to exclusively occupy control pipe } control; } usbh_device_info_t; diff --git a/tinyusb/osal/osal.h b/tinyusb/osal/osal.h index a3c9b65bd..5b9d12200 100644 --- a/tinyusb/osal/osal.h +++ b/tinyusb/osal/osal.h @@ -151,9 +151,6 @@ void osal_task_delay(uint32_t msec); typedef volatile uint8_t osal_semaphore_t; typedef osal_semaphore_t * osal_semaphore_handle_t; -#define OSAL_SEM_DEF(name) osal_semaphore_t name -#define OSAL_SEM_REF(name) &name - osal_semaphore_handle_t osal_semaphore_create(osal_semaphore_t * p_sem); void osal_semaphore_wait(osal_semaphore_handle_t sem_hdl, uint32_t msec, tusb_error_t *p_error); tusb_error_t osal_semaphore_post(osal_semaphore_handle_t sem_hdl); diff --git a/tinyusb/osal/osal_freeRTOS.h b/tinyusb/osal/osal_freeRTOS.h index 379f42bb4..f79829e58 100644 --- a/tinyusb/osal/osal_freeRTOS.h +++ b/tinyusb/osal/osal_freeRTOS.h @@ -77,29 +77,29 @@ static inline void osal_task_delay(uint32_t msec) //--------------------------------------------------------------------+ // Semaphore API //--------------------------------------------------------------------+ -#define OSAL_SEM_DEF(name) -#define OSAL_SEM_REF(name) -typedef xSemaphoreHandle osal_semaphore_handle_t; +typedef xSemaphoreHandle osal_semaphore_t; // create FreeRTOS binary semaphore with zero as init value TODO: omit semaphore take from vSemaphoreCreateBinary API, should double checks this -#define osal_semaphore_create(x) xSemaphoreCreateBinary() +//#define osal_semaphore_create(x) xSemaphoreCreateBinary() + +static inline osal_semaphore_t osal_semaphore_create(uint32_t max, uint32_t init) +{ + return xSemaphoreCreateCounting(max, init); +} // TODO add timeout (with instant return from ISR option) for semaphore post & queue send -static inline tusb_error_t osal_semaphore_post(osal_semaphore_handle_t const sem_hdl) ATTR_ALWAYS_INLINE; -static inline tusb_error_t osal_semaphore_post(osal_semaphore_handle_t const sem_hdl) +static inline tusb_error_t osal_semaphore_post(osal_semaphore_t sem_hdl) { return (xSemaphoreGive(sem_hdl) == pdTRUE) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_SEMAPHORE_FAILED; } -static inline void osal_semaphore_wait(osal_semaphore_handle_t const sem_hdl, uint32_t msec, tusb_error_t *p_error) ATTR_ALWAYS_INLINE; -static inline void osal_semaphore_wait(osal_semaphore_handle_t const sem_hdl, uint32_t msec, tusb_error_t *p_error) +static inline void osal_semaphore_wait(osal_semaphore_t sem_hdl, uint32_t msec, tusb_error_t *p_error) { uint32_t const ticks = (msec == OSAL_TIMEOUT_WAIT_FOREVER) ? portMAX_DELAY : osal_tick_from_msec(msec); (*p_error) = ( xSemaphoreTake(sem_hdl, ticks) == pdPASS ) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_TIMEOUT; } -static inline void osal_semaphore_reset(osal_semaphore_handle_t const sem_hdl) ATTR_ALWAYS_INLINE; -static inline void osal_semaphore_reset(osal_semaphore_handle_t const sem_hdl) +static inline void osal_semaphore_reset(osal_semaphore_t const sem_hdl) { (void) xSemaphoreTake(sem_hdl, 0); } @@ -107,27 +107,22 @@ static inline void osal_semaphore_reset(osal_semaphore_handle_t const sem_hdl) //--------------------------------------------------------------------+ // MUTEX API (priority inheritance) //--------------------------------------------------------------------+ -#define OSAL_MUTEX_DEF OSAL_SEM_DEF -#define OSAL_MUTEX_REF OSAL_SEM_REF -typedef xSemaphoreHandle osal_mutex_handle_t; +typedef xSemaphoreHandle osal_mutex_t; #define osal_mutex_create(x) xSemaphoreCreateMutex() -static inline tusb_error_t osal_mutex_release(osal_mutex_handle_t const mutex_hdl) ATTR_ALWAYS_INLINE; -static inline tusb_error_t osal_mutex_release(osal_mutex_handle_t const mutex_hdl) +static inline tusb_error_t osal_mutex_release(osal_mutex_t mutex_hdl) { - return (xSemaphoreGive(mutex_hdl) == pdPASS) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_MUTEX_FAILED; + return osal_semaphore_post(mutex_hdl); } -static inline void osal_mutex_wait(osal_mutex_handle_t const mutex_hdl, uint32_t msec, tusb_error_t *p_error) ATTR_ALWAYS_INLINE; -static inline void osal_mutex_wait(osal_mutex_handle_t const mutex_hdl, uint32_t msec, tusb_error_t *p_error) +static inline void osal_mutex_wait(osal_mutex_t mutex_hdl, uint32_t msec, tusb_error_t *p_error) { - uint32_t const ticks = (msec == OSAL_TIMEOUT_WAIT_FOREVER) ? portMAX_DELAY : osal_tick_from_msec(msec); - (*p_error) = ( xSemaphoreTake(mutex_hdl, ticks) == pdPASS ) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_TIMEOUT; + osal_semaphore_wait(mutex_hdl, msec, p_error); } -static inline void osal_mutex_reset(osal_mutex_handle_t const mutex_hdl) ATTR_ALWAYS_INLINE; -static inline void osal_mutex_reset(osal_mutex_handle_t const mutex_hdl) +// TOOD remove +static inline void osal_mutex_reset(osal_mutex_t mutex_hdl) { xSemaphoreGive(mutex_hdl); } @@ -137,7 +132,6 @@ static inline void osal_mutex_reset(osal_mutex_handle_t const mutex_hdl) //--------------------------------------------------------------------+ typedef xQueueHandle osal_queue_t; - static inline osal_queue_t osal_queue_create(uint32_t depth, uint32_t item_size) { return xQueueCreate(depth, item_size); diff --git a/tinyusb/osal/osal_none.h b/tinyusb/osal/osal_none.h index 1a833b07d..c1a426e49 100644 --- a/tinyusb/osal/osal_none.h +++ b/tinyusb/osal/osal_none.h @@ -150,43 +150,49 @@ static inline bool osal_task_create(osal_func_t code, const char* name, uint32_t //--------------------------------------------------------------------+ // Semaphore API //--------------------------------------------------------------------+ -typedef volatile uint8_t osal_semaphore_t; -typedef osal_semaphore_t * osal_semaphore_handle_t; - -#define OSAL_SEM_DEF(name) osal_semaphore_t name -#define OSAL_SEM_REF(name) &name - -static inline osal_semaphore_handle_t osal_semaphore_create(osal_semaphore_t * p_sem) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE; -static inline osal_semaphore_handle_t osal_semaphore_create(osal_semaphore_t * p_sem) +typedef struct { - (*p_sem) = 0; // TODO consider to have initial count parameter - return (osal_semaphore_handle_t) p_sem; + volatile uint16_t count; + uint16_t max_count; +}osal_semaphore_data_t; + +typedef osal_semaphore_data_t* osal_semaphore_t; + + +static inline osal_semaphore_t osal_semaphore_create(uint32_t max_count, uint32_t init) +{ + osal_semaphore_data_t* sem_data = (osal_semaphore_data_t*) tu_malloc( sizeof(osal_semaphore_data_t)); + VERIFY(sem_data, NULL); + + sem_data->count = init; + sem_data->max_count = max_count; + + return sem_data; } -static inline tusb_error_t osal_semaphore_post(osal_semaphore_handle_t sem_hdl) ATTR_ALWAYS_INLINE; -static inline tusb_error_t osal_semaphore_post(osal_semaphore_handle_t sem_hdl) +static inline tusb_error_t osal_semaphore_post(osal_semaphore_t sem_hdl) { - (*sem_hdl)++; + if (sem_hdl->count < sem_hdl->max_count ) sem_hdl->count++; + return TUSB_ERROR_NONE; } -static inline void osal_semaphore_reset(osal_semaphore_handle_t sem_hdl) ATTR_ALWAYS_INLINE; -static inline void osal_semaphore_reset(osal_semaphore_handle_t sem_hdl) +static inline void osal_semaphore_reset(osal_semaphore_t sem_hdl) { - (*sem_hdl) = 0; + sem_hdl->count = 0; } #define osal_semaphore_wait(sem_hdl, msec, p_error) \ do {\ timeout = osal_tick_get();\ state = __LINE__; case __LINE__:\ - if( *(sem_hdl) == 0 ) {\ + if( sem_hdl->count == 0 ) {\ if ( ( ((uint32_t) (msec)) != OSAL_TIMEOUT_WAIT_FOREVER) && (timeout + osal_tick_from_msec(msec) <= osal_tick_get()) ) /* time out */ \ *(p_error) = TUSB_ERROR_OSAL_TIMEOUT;\ else\ return TUSB_ERROR_OSAL_WAITING;\ } else{\ - (*(sem_hdl))--; /*TODO mutex hal_interrupt_disable consideration*/\ + if (sem_hdl->count) sem_hdl->count--; /*TODO mutex hal_interrupt_disable consideration*/\ *(p_error) = TUSB_ERROR_NONE;\ }\ }while(0) @@ -194,31 +200,22 @@ static inline void osal_semaphore_reset(osal_semaphore_handle_t sem_hdl) //--------------------------------------------------------------------+ // MUTEX API (priority inheritance) //--------------------------------------------------------------------+ -typedef osal_semaphore_t osal_mutex_t; -typedef osal_semaphore_handle_t osal_mutex_handle_t; +typedef osal_semaphore_t osal_mutex_t; -#define OSAL_MUTEX_DEF(name) osal_mutex_t name -#define OSAL_MUTEX_REF(name) &name - -static inline osal_mutex_handle_t osal_mutex_create(osal_mutex_t * p_mutex) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE; -static inline osal_mutex_handle_t osal_mutex_create(osal_mutex_t * p_mutex) +static inline osal_mutex_t osal_mutex_create(void) { - (*p_mutex) = 1; - return (osal_mutex_handle_t) p_mutex; + return osal_semaphore_create(1, 0); } -static inline tusb_error_t osal_mutex_release(osal_mutex_handle_t mutex_hdl) ATTR_ALWAYS_INLINE; -static inline tusb_error_t osal_mutex_release(osal_mutex_handle_t mutex_hdl) +static inline tusb_error_t osal_mutex_release(osal_mutex_t mutex_hdl) { - (*mutex_hdl) = 1; // mutex is a binary semaphore - - return TUSB_ERROR_NONE; + return osal_semaphore_post(mutex_hdl); } -static inline void osal_mutex_reset(osal_mutex_handle_t mutex_hdl) ATTR_ALWAYS_INLINE; -static inline void osal_mutex_reset(osal_mutex_handle_t mutex_hdl) +// TOOD remove +static inline void osal_mutex_reset(osal_mutex_t mutex_hdl) { - (*mutex_hdl) = 1; + osal_semaphore_reset(mutex_hdl); } #define osal_mutex_wait osal_semaphore_wait diff --git a/vendor/freertos/FreeRTOSConfig.h b/vendor/freertos/FreeRTOSConfig.h index 17a14a550..462549405 100644 --- a/vendor/freertos/FreeRTOSConfig.h +++ b/vendor/freertos/FreeRTOSConfig.h @@ -26,7 +26,7 @@ #define configIDLE_SHOULD_YIELD 1 #define configUSE_MUTEXES 1 #define configUSE_RECURSIVE_MUTEXES 0 -#define configUSE_COUNTING_SEMAPHORES 0 +#define configUSE_COUNTING_SEMAPHORES 1 #define configQUEUE_REGISTRY_SIZE 10 // used to name queue/semaphore with debugger /* Hook function related definitions. */