diff --git a/examples/obsolete/device/src/tusb_config.h b/examples/obsolete/device/src/tusb_config.h index 7d32350ff..f33fb46ba 100644 --- a/examples/obsolete/device/src/tusb_config.h +++ b/examples/obsolete/device/src/tusb_config.h @@ -70,7 +70,6 @@ //#define TUSB_CFG_OS TUSB_OS_NONE // be passed from IDE/command line for easy project switching //#define TUSB_CFG_OS_TASK_PRIO 0 // be passed from IDE/command line for easy project switching -#define TUSB_CFG_TICKS_HZ 1000 //--------------------------------------------------------------------+ // USB RAM PLACEMENT diff --git a/examples/obsolete/host/src/tusb_config.h b/examples/obsolete/host/src/tusb_config.h index 04fd7e889..be1d5c7ed 100644 --- a/examples/obsolete/host/src/tusb_config.h +++ b/examples/obsolete/host/src/tusb_config.h @@ -71,8 +71,6 @@ //#define TUSB_CFG_OS TUSB_OS_NONE // defined using eclipse build //#define TUSB_CFG_OS_TASK_PRIO 0 // defined using eclipse build -#define TUSB_CFG_TICKS_HZ 1000 - //--------------------------------------------------------------------+ // USB RAM PLACEMENT //--------------------------------------------------------------------+ diff --git a/hw/bsp/board.h b/hw/bsp/board.h index aaedf27d6..2c566bb11 100644 --- a/hw/bsp/board.h +++ b/hw/bsp/board.h @@ -121,6 +121,8 @@ //--------------------------------------------------------------------+ #define CFG_UART_BAUDRATE 115200 ///< Baudrate for UART +#define BOARD_TICKS_HZ 1000 + //--------------------------------------------------------------------+ // Board Common API //--------------------------------------------------------------------+ diff --git a/hw/bsp/ea4357/board_ea4357.c b/hw/bsp/ea4357/board_ea4357.c index bfd100e1e..963e7629c 100644 --- a/hw/bsp/ea4357/board_ea4357.c +++ b/hw/bsp/ea4357/board_ea4357.c @@ -65,12 +65,34 @@ enum { BOARD_BUTTON_COUNT = sizeof(buttons) / sizeof(buttons[0]) }; +/*------------------------------------------------------------------*/ +/* TUSB HAL MILLISECOND + *------------------------------------------------------------------*/ +#if TUSB_CFG_OS == TUSB_OS_NONE + +volatile uint32_t system_ticks = 0; + +void SysTick_Handler (void) +{ + system_ticks++; +} + +uint32_t tusb_hal_millis(void) +{ + return (system_ticks*1000) / BOARD_TICKS_HZ; +} + +#endif + +/*------------------------------------------------------------------*/ +/* BOARD API + *------------------------------------------------------------------*/ void board_init(void) { CGU_Init(); #if TUSB_CFG_OS == TUSB_OS_NONE // TODO may move to main.c - SysTick_Config(CGU_GetPCLKFrequency(CGU_PERIPHERAL_M4CORE) / TUSB_CFG_TICKS_HZ); // 1 msec tick timer + SysTick_Config(CGU_GetPCLKFrequency(CGU_PERIPHERAL_M4CORE) / BOARD_TICKS_HZ); // 1 msec tick timer #endif //------------- USB -------------// diff --git a/hw/bsp/hitex/board_hitex4350.c b/hw/bsp/hitex/board_hitex4350.c index 4811f02f0..23e070a92 100644 --- a/hw/bsp/hitex/board_hitex4350.c +++ b/hw/bsp/hitex/board_hitex4350.c @@ -54,7 +54,7 @@ void board_init(void) { CGU_Init(); - SysTick_Config(CGU_GetPCLKFrequency(CGU_PERIPHERAL_M4CORE) / TUSB_CFG_TICKS_HZ); // 1 msec tick timer + SysTick_Config(CGU_GetPCLKFrequency(CGU_PERIPHERAL_M4CORE) / BOARD_TICKS_HZ); // 1 msec tick timer //------------- USB Bus power HOST ONLY-------------// // Hitex VBUS0 is P2_3 diff --git a/hw/bsp/keil/board_mcb4300.c b/hw/bsp/keil/board_mcb4300.c index 6addfb252..b9a3f4144 100644 --- a/hw/bsp/keil/board_mcb4300.c +++ b/hw/bsp/keil/board_mcb4300.c @@ -75,7 +75,7 @@ void board_init(void) CGU_Init(); #if TUSB_CFG_OS == TUSB_OS_NONE // TODO may move to main.c - SysTick_Config(CGU_GetPCLKFrequency(CGU_PERIPHERAL_M4CORE) / TUSB_CFG_TICKS_HZ); // 1 msec tick timer + SysTick_Config(CGU_GetPCLKFrequency(CGU_PERIPHERAL_M4CORE) / BOARD_TICKS_HZ); // 1 msec tick timer #endif //------------- USB Bus power HOST ONLY-------------// diff --git a/hw/bsp/lpcxpresso/board_lpclink2.c b/hw/bsp/lpcxpresso/board_lpclink2.c index d59b211fb..5f6f18cb6 100644 --- a/hw/bsp/lpcxpresso/board_lpclink2.c +++ b/hw/bsp/lpcxpresso/board_lpclink2.c @@ -57,7 +57,7 @@ void board_init(void) CGU_Init(); #if TUSB_CFG_OS == TUSB_OS_NONE // TODO may move to main.c - SysTick_Config(CGU_GetPCLKFrequency(CGU_PERIPHERAL_M4CORE) / TUSB_CFG_TICKS_HZ); // 1 msec tick timer + SysTick_Config(CGU_GetPCLKFrequency(CGU_PERIPHERAL_M4CORE) / BOARD_TICKS_HZ); // 1 msec tick timer #endif //------------- USB -------------// diff --git a/hw/bsp/lpcxpresso/board_lpcxpresso11u14.c b/hw/bsp/lpcxpresso/board_lpcxpresso11u14.c index eb8c39eda..79df45a36 100644 --- a/hw/bsp/lpcxpresso/board_lpcxpresso11u14.c +++ b/hw/bsp/lpcxpresso/board_lpcxpresso11u14.c @@ -68,7 +68,7 @@ void board_init(void) SystemInit(); #if TUSB_CFG_OS == TUSB_OS_NONE // TODO may move to main.c - SysTick_Config(SystemCoreClock / TUSB_CFG_TICKS_HZ); // 1 msec tick timer + SysTick_Config(SystemCoreClock / BOARD_TICKS_HZ); // 1 msec tick timer #endif GPIOInit(); diff --git a/hw/bsp/lpcxpresso11u68/board_lpcxpresso11u68.c b/hw/bsp/lpcxpresso11u68/board_lpcxpresso11u68.c index ffdbc2706..5796c2341 100644 --- a/hw/bsp/lpcxpresso11u68/board_lpcxpresso11u68.c +++ b/hw/bsp/lpcxpresso11u68/board_lpcxpresso11u68.c @@ -59,7 +59,7 @@ void board_init(void) SystemInit(); #if TUSB_CFG_OS == TUSB_OS_NONE // TODO may move to main.c - SysTick_Config(SystemCoreClock / TUSB_CFG_TICKS_HZ); // 1 msec tick timer + SysTick_Config(SystemCoreClock / BOARD_TICKS_HZ); // 1 msec tick timer #endif GPIOInit(); diff --git a/hw/bsp/lpcxpresso1347/board_lpcxpresso1347.c b/hw/bsp/lpcxpresso1347/board_lpcxpresso1347.c index a0a615edc..c0a870d7e 100644 --- a/hw/bsp/lpcxpresso1347/board_lpcxpresso1347.c +++ b/hw/bsp/lpcxpresso1347/board_lpcxpresso1347.c @@ -69,7 +69,7 @@ void board_init(void) SystemInit(); #if TUSB_CFG_OS == TUSB_OS_NONE // TODO may move to main.c - SysTick_Config(SystemCoreClock / TUSB_CFG_TICKS_HZ); // 1 msec tick timer + SysTick_Config(SystemCoreClock / BOARD_TICKS_HZ); // 1 msec tick timer #endif GPIOInit(); diff --git a/hw/bsp/lpcxpresso1769/board_lpcxpresso1769.c b/hw/bsp/lpcxpresso1769/board_lpcxpresso1769.c index 39d669886..7aceb87f4 100644 --- a/hw/bsp/lpcxpresso1769/board_lpcxpresso1769.c +++ b/hw/bsp/lpcxpresso1769/board_lpcxpresso1769.c @@ -68,7 +68,7 @@ void board_init(void) SystemInit(); #if TUSB_CFG_OS == TUSB_OS_NONE // TODO may move to main.c - SysTick_Config(SystemCoreClock / TUSB_CFG_TICKS_HZ); // 1 msec tick timer + SysTick_Config(SystemCoreClock / BOARD_TICKS_HZ); // 1 msec tick timer #endif //------------- LED -------------// diff --git a/hw/bsp/ngx/board_ngx4330.c b/hw/bsp/ngx/board_ngx4330.c index 88212146f..63c72756e 100644 --- a/hw/bsp/ngx/board_ngx4330.c +++ b/hw/bsp/ngx/board_ngx4330.c @@ -71,7 +71,7 @@ void board_init(void) CGU_Init(); #if TUSB_CFG_OS == TUSB_OS_NONE // TODO may move to main.c - SysTick_Config( CGU_GetPCLKFrequency(CGU_PERIPHERAL_M4CORE)/TUSB_CFG_TICKS_HZ ); /* 1 ms Timer */ + SysTick_Config( CGU_GetPCLKFrequency(CGU_PERIPHERAL_M4CORE)/BOARD_TICKS_HZ ); /* 1 ms Timer */ #endif //------------- USB Bus power HOST ONLY-------------// diff --git a/tinyusb/common/timeout_timer.h b/tinyusb/common/timeout_timer.h index 2de71ded3..f504cc91f 100644 --- a/tinyusb/common/timeout_timer.h +++ b/tinyusb/common/timeout_timer.h @@ -55,17 +55,15 @@ typedef struct { uint32_t interval; }timeout_timer_t; -static inline void timeout_set(timeout_timer_t* tt, uint32_t msec) ATTR_ALWAYS_INLINE; static inline void timeout_set(timeout_timer_t* tt, uint32_t msec) { - tt->interval = osal_tick_from_msec(msec); - tt->start = osal_tick_get(); + tt->interval = msec; + tt->start = osal_millis(); } -static inline bool timeout_expired(timeout_timer_t* tt) ATTR_ALWAYS_INLINE; static inline bool timeout_expired(timeout_timer_t* tt) { - return ( osal_tick_get() - tt->start ) >= tt->interval; + return ( osal_millis() - tt->start ) >= tt->interval; } #ifdef __cplusplus diff --git a/tinyusb/osal/osal_common.h b/tinyusb/osal/osal_common.h index 2d35e74b4..42ed6e77b 100644 --- a/tinyusb/osal/osal_common.h +++ b/tinyusb/osal/osal_common.h @@ -55,12 +55,6 @@ enum OSAL_TIMEOUT_WAIT_FOREVER = 0xFFFFFFFF }; -static inline uint32_t osal_tick_from_msec(uint32_t msec) ATTR_CONST ATTR_ALWAYS_INLINE; -static inline uint32_t osal_tick_from_msec(uint32_t msec) -{ - return (msec * TUSB_CFG_TICKS_HZ)/1000; -} - #ifdef __cplusplus } #endif diff --git a/tinyusb/osal/osal_freeRTOS.h b/tinyusb/osal/osal_freeRTOS.h index befad3fd0..f2fe668ae 100644 --- a/tinyusb/osal/osal_freeRTOS.h +++ b/tinyusb/osal/osal_freeRTOS.h @@ -59,7 +59,7 @@ extern "C" { //--------------------------------------------------------------------+ // TICK API //--------------------------------------------------------------------+ -#define osal_tick_get xTaskGetTickCount +#define osal_millis xTaskGetTickCount //--------------------------------------------------------------------+ // TASK API @@ -76,7 +76,7 @@ static inline osal_task_t osal_task_create(osal_func_t code, const char* name, u static inline void osal_task_delay(uint32_t msec) { - vTaskDelay( (TUSB_CFG_TICKS_HZ * msec) / 1000 ); + vTaskDelay( pdMS_TO_TICKS(msec) ); } //--------------------------------------------------------------------+ @@ -91,7 +91,7 @@ static inline osal_queue_t osal_queue_create(uint32_t depth, uint32_t item_size) static inline void osal_queue_receive (osal_queue_t const queue_hdl, void *p_data, uint32_t msec, tusb_error_t *p_error) { - uint32_t const ticks = (msec == OSAL_TIMEOUT_WAIT_FOREVER) ? portMAX_DELAY : osal_tick_from_msec(msec); + uint32_t const ticks = (msec == OSAL_TIMEOUT_WAIT_FOREVER) ? portMAX_DELAY : pdMS_TO_TICKS(msec); portBASE_TYPE result = (SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk) ? xQueueReceiveFromISR(queue_hdl, p_data, NULL) : xQueueReceive(queue_hdl, p_data, ticks); (*p_error) = ( result == pdPASS ) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_TIMEOUT; @@ -137,7 +137,7 @@ static inline bool osal_semaphore_post(osal_semaphore_t sem_hdl) 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); + uint32_t const ticks = (msec == OSAL_TIMEOUT_WAIT_FOREVER) ? portMAX_DELAY : pdMS_TO_TICKS(msec); BaseType_t result; diff --git a/tinyusb/osal/osal_none.h b/tinyusb/osal/osal_none.h index f150d5c34..0b73de4e9 100644 --- a/tinyusb/osal/osal_none.h +++ b/tinyusb/osal/osal_none.h @@ -53,7 +53,7 @@ //--------------------------------------------------------------------+ // TICK API //--------------------------------------------------------------------+ -#define osal_tick_get tusb_hal_tick_get +#define osal_millis tusb_hal_millis //--------------------------------------------------------------------+ // TASK API @@ -97,9 +97,9 @@ static inline osal_task_t osal_task_create(osal_func_t code, const char* name, u #define osal_task_delay(msec) \ do {\ - _timeout = osal_tick_get();\ + _timeout = osal_millis();\ _state = __LINE__; case __LINE__:\ - if ( _timeout + osal_tick_from_msec(msec) > osal_tick_get() ) \ + if ( _timeout + msec > osal_millis() ) \ return TUSB_ERROR_OSAL_WAITING;\ }while(0) @@ -164,10 +164,10 @@ static inline void osal_queue_flush(osal_queue_t const queue_hdl) #define osal_queue_receive(queue_hdl, p_data, msec, p_error) \ do {\ - _timeout = osal_tick_get();\ + _timeout = osal_millis();\ _state = __LINE__; case __LINE__:\ if( queue_hdl->count == 0 ) {\ - if ( (msec != OSAL_TIMEOUT_WAIT_FOREVER) && ( _timeout + osal_tick_from_msec(msec) <= osal_tick_get() )) /* time out */ \ + if ( (msec != OSAL_TIMEOUT_WAIT_FOREVER) && ( _timeout + msec <= osal_millis()) ) /* time out */ \ *(p_error) = TUSB_ERROR_OSAL_TIMEOUT;\ else\ return TUSB_ERROR_OSAL_WAITING;\ @@ -218,10 +218,10 @@ static inline void osal_semaphore_reset(osal_semaphore_t sem_hdl) #define osal_semaphore_wait(sem_hdl, msec, p_error) \ do {\ - _timeout = osal_tick_get();\ + _timeout = osal_millis();\ _state = __LINE__; case __LINE__:\ if( sem_hdl->count == 0 ) {\ - if ( ( ((uint32_t) (msec)) != OSAL_TIMEOUT_WAIT_FOREVER) && (_timeout + osal_tick_from_msec(msec) <= osal_tick_get()) ) /* time out */ \ + if ( (msec != OSAL_TIMEOUT_WAIT_FOREVER) && (_timeout + msec <= osal_millis()) ) /* time out */ \ *(p_error) = TUSB_ERROR_OSAL_TIMEOUT;\ else\ return TUSB_ERROR_OSAL_WAITING;\ diff --git a/tinyusb/portable/nordic/nrf5x/hal_nrf5x.c b/tinyusb/portable/nordic/nrf5x/hal_nrf5x.c index 073f4ac36..4cb7f076e 100644 --- a/tinyusb/portable/nordic/nrf5x/hal_nrf5x.c +++ b/tinyusb/portable/nordic/nrf5x/hal_nrf5x.c @@ -81,7 +81,7 @@ void tusb_hal_int_disable(uint8_t rhport) NVIC_DisableIRQ(USBD_IRQn); } -uint32_t tusb_hal_tick_get(void) +uint32_t tusb_hal_millis(void) { //#define tick2ms(tck) ( ( ((uint64_t)(tck)) * 1000) / configTICK_RATE_HZ ) //return tick2ms( app_timer_cnt_get() ); diff --git a/tinyusb/portable/nxp/lpc43xx_lpc18xx/hal_lpc43xx.c b/tinyusb/portable/nxp/lpc43xx_lpc18xx/hal_lpc43xx.c index ff7d32a3f..31481b742 100644 --- a/tinyusb/portable/nxp/lpc43xx_lpc18xx/hal_lpc43xx.c +++ b/tinyusb/portable/nxp/lpc43xx_lpc18xx/hal_lpc43xx.c @@ -53,22 +53,6 @@ enum { LPC43XX_USBMODE_VBUS_HIGH = 1 }; -#if TUSB_CFG_OS == TUSB_OS_NONE - -volatile uint32_t system_ticks = 0; - -void SysTick_Handler (void) -{ - system_ticks++; -} - -uint32_t tusb_hal_tick_get(void) -{ - return system_ticks; -} - -#endif - void tusb_hal_int_enable(uint8_t rhport) { NVIC_EnableIRQ(rhport ? USB1_IRQn : USB0_IRQn); diff --git a/tinyusb/tusb_hal.h b/tinyusb/tusb_hal.h index 98ec79f97..0025bf844 100644 --- a/tinyusb/tusb_hal.h +++ b/tinyusb/tusb_hal.h @@ -75,7 +75,7 @@ void tusb_hal_int_enable(uint8_t rhport); */ void tusb_hal_int_disable(uint8_t rhport); -uint32_t tusb_hal_tick_get(void); +uint32_t tusb_hal_millis(void); #ifdef __cplusplus }