rename tusb_hal_tick_get to tusb_hal_millis

rename TUSB_CFG_TICKS_HZ to BOARD_TICKS_HZ
This commit is contained in:
hathach
2018-03-29 18:03:04 +07:00
parent 43bf760f81
commit e2f9744369
19 changed files with 49 additions and 52 deletions

View File

@@ -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 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_OS_TASK_PRIO 0 // be passed from IDE/command line for easy project switching
#define TUSB_CFG_TICKS_HZ 1000
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// USB RAM PLACEMENT // USB RAM PLACEMENT

View File

@@ -71,8 +71,6 @@
//#define TUSB_CFG_OS TUSB_OS_NONE // defined using eclipse build //#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_OS_TASK_PRIO 0 // defined using eclipse build
#define TUSB_CFG_TICKS_HZ 1000
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// USB RAM PLACEMENT // USB RAM PLACEMENT
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+

View File

@@ -121,6 +121,8 @@
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
#define CFG_UART_BAUDRATE 115200 ///< Baudrate for UART #define CFG_UART_BAUDRATE 115200 ///< Baudrate for UART
#define BOARD_TICKS_HZ 1000
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// Board Common API // Board Common API
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+

View File

@@ -65,12 +65,34 @@ enum {
BOARD_BUTTON_COUNT = sizeof(buttons) / sizeof(buttons[0]) 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) void board_init(void)
{ {
CGU_Init(); CGU_Init();
#if TUSB_CFG_OS == TUSB_OS_NONE // TODO may move to main.c #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 #endif
//------------- USB -------------// //------------- USB -------------//

View File

@@ -54,7 +54,7 @@
void board_init(void) void board_init(void)
{ {
CGU_Init(); 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-------------// //------------- USB Bus power HOST ONLY-------------//
// Hitex VBUS0 is P2_3 // Hitex VBUS0 is P2_3

View File

@@ -75,7 +75,7 @@ void board_init(void)
CGU_Init(); CGU_Init();
#if TUSB_CFG_OS == TUSB_OS_NONE // TODO may move to main.c #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 #endif
//------------- USB Bus power HOST ONLY-------------// //------------- USB Bus power HOST ONLY-------------//

View File

@@ -57,7 +57,7 @@ void board_init(void)
CGU_Init(); CGU_Init();
#if TUSB_CFG_OS == TUSB_OS_NONE // TODO may move to main.c #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 #endif
//------------- USB -------------// //------------- USB -------------//

View File

@@ -68,7 +68,7 @@ void board_init(void)
SystemInit(); SystemInit();
#if TUSB_CFG_OS == TUSB_OS_NONE // TODO may move to main.c #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 #endif
GPIOInit(); GPIOInit();

View File

@@ -59,7 +59,7 @@ void board_init(void)
SystemInit(); SystemInit();
#if TUSB_CFG_OS == TUSB_OS_NONE // TODO may move to main.c #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 #endif
GPIOInit(); GPIOInit();

View File

@@ -69,7 +69,7 @@ void board_init(void)
SystemInit(); SystemInit();
#if TUSB_CFG_OS == TUSB_OS_NONE // TODO may move to main.c #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 #endif
GPIOInit(); GPIOInit();

View File

@@ -68,7 +68,7 @@ void board_init(void)
SystemInit(); SystemInit();
#if TUSB_CFG_OS == TUSB_OS_NONE // TODO may move to main.c #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 #endif
//------------- LED -------------// //------------- LED -------------//

View File

@@ -71,7 +71,7 @@ void board_init(void)
CGU_Init(); CGU_Init();
#if TUSB_CFG_OS == TUSB_OS_NONE // TODO may move to main.c #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 #endif
//------------- USB Bus power HOST ONLY-------------// //------------- USB Bus power HOST ONLY-------------//

View File

@@ -55,17 +55,15 @@ typedef struct {
uint32_t interval; uint32_t interval;
}timeout_timer_t; }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) static inline void timeout_set(timeout_timer_t* tt, uint32_t msec)
{ {
tt->interval = osal_tick_from_msec(msec); tt->interval = msec;
tt->start = osal_tick_get(); 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) 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 #ifdef __cplusplus

View File

@@ -55,12 +55,6 @@ enum
OSAL_TIMEOUT_WAIT_FOREVER = 0xFFFFFFFF 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 #ifdef __cplusplus
} }
#endif #endif

View File

@@ -59,7 +59,7 @@ extern "C" {
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// TICK API // TICK API
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
#define osal_tick_get xTaskGetTickCount #define osal_millis xTaskGetTickCount
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// TASK API // 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) 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) 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); 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; (*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) 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; BaseType_t result;

View File

@@ -53,7 +53,7 @@
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// TICK API // TICK API
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
#define osal_tick_get tusb_hal_tick_get #define osal_millis tusb_hal_millis
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// TASK API // 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) \ #define osal_task_delay(msec) \
do {\ do {\
_timeout = osal_tick_get();\ _timeout = osal_millis();\
_state = __LINE__; case __LINE__:\ _state = __LINE__; case __LINE__:\
if ( _timeout + osal_tick_from_msec(msec) > osal_tick_get() ) \ if ( _timeout + msec > osal_millis() ) \
return TUSB_ERROR_OSAL_WAITING;\ return TUSB_ERROR_OSAL_WAITING;\
}while(0) }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) \ #define osal_queue_receive(queue_hdl, p_data, msec, p_error) \
do {\ do {\
_timeout = osal_tick_get();\ _timeout = osal_millis();\
_state = __LINE__; case __LINE__:\ _state = __LINE__; case __LINE__:\
if( queue_hdl->count == 0 ) {\ 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;\ *(p_error) = TUSB_ERROR_OSAL_TIMEOUT;\
else\ else\
return TUSB_ERROR_OSAL_WAITING;\ 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) \ #define osal_semaphore_wait(sem_hdl, msec, p_error) \
do {\ do {\
_timeout = osal_tick_get();\ _timeout = osal_millis();\
_state = __LINE__; case __LINE__:\ _state = __LINE__; case __LINE__:\
if( sem_hdl->count == 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 */ \ if ( (msec != OSAL_TIMEOUT_WAIT_FOREVER) && (_timeout + msec <= osal_millis()) ) /* time out */ \
*(p_error) = TUSB_ERROR_OSAL_TIMEOUT;\ *(p_error) = TUSB_ERROR_OSAL_TIMEOUT;\
else\ else\
return TUSB_ERROR_OSAL_WAITING;\ return TUSB_ERROR_OSAL_WAITING;\

View File

@@ -81,7 +81,7 @@ void tusb_hal_int_disable(uint8_t rhport)
NVIC_DisableIRQ(USBD_IRQn); 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 ) //#define tick2ms(tck) ( ( ((uint64_t)(tck)) * 1000) / configTICK_RATE_HZ )
//return tick2ms( app_timer_cnt_get() ); //return tick2ms( app_timer_cnt_get() );

View File

@@ -53,22 +53,6 @@ enum {
LPC43XX_USBMODE_VBUS_HIGH = 1 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) void tusb_hal_int_enable(uint8_t rhport)
{ {
NVIC_EnableIRQ(rhport ? USB1_IRQn : USB0_IRQn); NVIC_EnableIRQ(rhport ? USB1_IRQn : USB0_IRQn);

View File

@@ -75,7 +75,7 @@ void tusb_hal_int_enable(uint8_t rhport);
*/ */
void tusb_hal_int_disable(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 #ifdef __cplusplus
} }