From 29e075b8b968806c4a9ebffdbdfacbd9b01cf029 Mon Sep 17 00:00:00 2001 From: hathach Date: Sat, 23 Mar 2019 22:31:07 +0700 Subject: [PATCH] clean up bsp, adde board_millis() --- examples/device/cdc_msc_hid/src/main.c | 4 +-- .../device/cdc_msc_hid_freertos/src/main.c | 7 +++--- hw/bsp/board.h | 25 +++++++++++++++++-- hw/bsp/ea4088qs/board_ea4088qs.c | 8 +----- hw/bsp/ea4357/board_ea4357.c | 8 +----- .../lpcxpresso11u68/board_lpcxpresso11u68.c | 6 +---- hw/bsp/lpcxpresso1347/board_lpcxpresso1347.c | 10 +------- hw/bsp/lpcxpresso1769/board_lpcxpresso1769.c | 8 +----- hw/bsp/mcb1800/board_mcb1800.c | 9 +------ .../metro_m0_express/board_metro_m0_express.c | 4 +-- .../metro_m4_express/board_metro_m4_express.c | 4 +-- hw/bsp/pca10056/board_pca10056.c | 5 +--- hw/bsp/stm32f303disc/board_stm32f303disc.c | 3 +-- .../stm32f407g_disc1/board_stm32f407g_disc1.c | 4 +-- 14 files changed, 40 insertions(+), 65 deletions(-) diff --git a/examples/device/cdc_msc_hid/src/main.c b/examples/device/cdc_msc_hid/src/main.c index 06a99711..75d9a31d 100644 --- a/examples/device/cdc_msc_hid/src/main.c +++ b/examples/device/cdc_msc_hid/src/main.c @@ -124,7 +124,7 @@ void usb_hid_task(void) const uint32_t interval_ms = 10; static uint32_t start_ms = 0; - if ( board_noos_millis() < start_ms + interval_ms) return; // not enough time + if ( board_millis() < start_ms + interval_ms) return; // not enough time start_ms += interval_ms; uint32_t const btn = board_buttons(); @@ -200,7 +200,7 @@ void led_blinking_task(void) static bool led_state = false; // Blink every 1000 ms - if ( board_noos_millis() < start_ms + interval_ms) return; // not enough time + if ( board_millis() < start_ms + interval_ms) return; // not enough time start_ms += interval_ms; board_led_control(led_state); diff --git a/examples/device/cdc_msc_hid_freertos/src/main.c b/examples/device/cdc_msc_hid_freertos/src/main.c index 5705c165..b5d5cf79 100644 --- a/examples/device/cdc_msc_hid_freertos/src/main.c +++ b/examples/device/cdc_msc_hid_freertos/src/main.c @@ -150,10 +150,11 @@ void usb_hid_task(void* params) (void) params; // Poll every 10ms - static tu_timeout_t tm = { .start = 0, .interval = 10 }; + const uint32_t interval_ms = 10; + static uint32_t start_ms = 0; - if ( !tu_timeout_expired(&tm) ) return; // not enough time - tu_timeout_reset(&tm); + if ( board_millis() < start_ms + interval_ms) return; // not enough time + start_ms += interval_ms; uint32_t const btn = board_buttons(); diff --git a/hw/bsp/board.h b/hw/bsp/board.h index 44dba7ec..ea0f3152 100644 --- a/hw/bsp/board.h +++ b/hw/bsp/board.h @@ -40,7 +40,10 @@ #include "ansi_escape.h" +#include "tusb.h" + #define CFG_UART_BAUDRATE 115200 + #define BOARD_TICKS_HZ 1000 #define board_tick2ms(tck) ( ( ((uint64_t)(tck)) * 1000) / BOARD_TICKS_HZ ) @@ -64,8 +67,26 @@ int board_uart_read(uint8_t* buf, int len); // Send characters to UART int board_uart_write(void const * buf, int len); -// Get current milliseconds with no rtos configure (TUSB_CFG_OS = OPT_OS_NONE) -uint32_t board_noos_millis(void); +#if CFG_TUSB_OS == OPT_OS_NONE + +// Get current milliseconds, must be implemented in board.c when no OS is used +uint32_t board_millis(void); + +#elif CFG_TUSB_OS == OPT_OS_FREERTOS + +static inline uint32_t board_millis(void) +{ + return ( ( ((uint64_t) xTaskGetTickCount()) * 1000) / configTICK_RATE_HZ ); +} + +#elif CFG_TUSB_OS == OPT_OS_MYNEWT + +static inline uint32_t board_millis(void) +{ + return os_time_ticks_to_ms32( os_time_get() ); +} + +#endif //--------------------------------------------------------------------+ // Helper functions diff --git a/hw/bsp/ea4088qs/board_ea4088qs.c b/hw/bsp/ea4088qs/board_ea4088qs.c index e4b006c7..11b3a7eb 100644 --- a/hw/bsp/ea4088qs/board_ea4088qs.c +++ b/hw/bsp/ea4088qs/board_ea4088qs.c @@ -24,13 +24,9 @@ * This file is part of the TinyUSB stack. */ -#ifdef BOARD_EA4088QS - #include "chip.h" #include "../board.h" -#include "tusb_option.h" - #define LED_PORT 2 #define LED_PIN 19 @@ -175,11 +171,9 @@ uint32_t tusb_hal_millis(void) return board_tick2ms(system_ticks); } -uint32_t board_noos_millis(void) +uint32_t board_millis(void) { return system_ticks; } #endif - -#endif diff --git a/hw/bsp/ea4357/board_ea4357.c b/hw/bsp/ea4357/board_ea4357.c index 3bb846cc..e5e93033 100644 --- a/hw/bsp/ea4357/board_ea4357.c +++ b/hw/bsp/ea4357/board_ea4357.c @@ -24,14 +24,10 @@ * This file is part of the TinyUSB stack. */ -#ifdef BOARD_EA4357 - #include "chip.h" #include "../board.h" #include "pca9532.h" -#include "tusb_option.h" - #define BOARD_UART_PORT LPC_USART0 #define BOARD_UART_PIN_PORT 0x0f #define BOARD_UART_PIN_TX 10 // PF.10 : UART0_TXD @@ -74,7 +70,7 @@ uint32_t tusb_hal_millis(void) return board_tick2ms(system_ticks); } -uint32_t board_noos_millis(void) +uint32_t board_millis(void) { return system_ticks; } @@ -305,5 +301,3 @@ int board_uart_write(void const * buf, int len) (void) len; return 0; } - -#endif diff --git a/hw/bsp/lpcxpresso11u68/board_lpcxpresso11u68.c b/hw/bsp/lpcxpresso11u68/board_lpcxpresso11u68.c index ca7e699c..d3883be5 100644 --- a/hw/bsp/lpcxpresso11u68/board_lpcxpresso11u68.c +++ b/hw/bsp/lpcxpresso11u68/board_lpcxpresso11u68.c @@ -24,8 +24,6 @@ * This file is part of the TinyUSB stack. */ -#ifdef BOARD_LPCXPRESSO11U68 - #include "chip.h" #include "../board.h" @@ -110,7 +108,7 @@ uint32_t tusb_hal_millis(void) return board_tick2ms(system_ticks); } -uint32_t board_noos_millis(void) +uint32_t board_millis(void) { return system_ticks; } @@ -153,5 +151,3 @@ int board_uart_write(void const * buf, int len) (void) len; return 0; } - -#endif diff --git a/hw/bsp/lpcxpresso1347/board_lpcxpresso1347.c b/hw/bsp/lpcxpresso1347/board_lpcxpresso1347.c index 18853c5f..20b82cd6 100644 --- a/hw/bsp/lpcxpresso1347/board_lpcxpresso1347.c +++ b/hw/bsp/lpcxpresso1347/board_lpcxpresso1347.c @@ -24,8 +24,6 @@ * This file is part of the TinyUSB stack. */ -#ifdef BOARD_LPCXPRESSO1347 - #include "chip.h" #include "../board.h" @@ -83,10 +81,6 @@ void board_init(void) { SystemCoreClockUpdate(); -#if CFG_TUSB_OS == OPT_OS_NONE - SysTick_Config(SystemCoreClock / BOARD_TICKS_HZ); // 1 msec tick timer -#endif - #if CFG_TUSB_OS == OPT_OS_NONE // 1ms tick timer SysTick_Config(SystemCoreClock / 1000); @@ -127,7 +121,7 @@ uint32_t tusb_hal_millis(void) return board_tick2ms(system_ticks); } -uint32_t board_noos_millis(void) +uint32_t board_millis(void) { return system_ticks; } @@ -181,5 +175,3 @@ int board_uart_write(void const * buf, int len) (void) len; return 0; } - -#endif diff --git a/hw/bsp/lpcxpresso1769/board_lpcxpresso1769.c b/hw/bsp/lpcxpresso1769/board_lpcxpresso1769.c index 5578ae5d..0b7e7a1b 100644 --- a/hw/bsp/lpcxpresso1769/board_lpcxpresso1769.c +++ b/hw/bsp/lpcxpresso1769/board_lpcxpresso1769.c @@ -24,13 +24,9 @@ * This file is part of the TinyUSB stack. */ -#ifdef BOARD_LPCXPRESSO1769 - #include "chip.h" #include "../board.h" -#include "tusb_option.h" - #define LED_PORT 0 #define LED_PIN 22 @@ -163,7 +159,7 @@ uint32_t tusb_hal_millis(void) return board_tick2ms(system_ticks); } -uint32_t board_noos_millis(void) +uint32_t board_millis(void) { return system_ticks; } @@ -217,5 +213,3 @@ int board_uart_write(void const * buf, int len) (void) len; return 0; } - -#endif diff --git a/hw/bsp/mcb1800/board_mcb1800.c b/hw/bsp/mcb1800/board_mcb1800.c index d6b45090..7ace1a0e 100644 --- a/hw/bsp/mcb1800/board_mcb1800.c +++ b/hw/bsp/mcb1800/board_mcb1800.c @@ -24,13 +24,9 @@ * This file is part of the TinyUSB stack. */ -#ifdef BOARD_MCB1800 - #include "chip.h" #include "../board.h" -#include "tusb_option.h" - #define LED_PORT 6 #define LED_PIN 24 @@ -241,12 +237,9 @@ uint32_t tusb_hal_millis(void) return board_tick2ms(system_ticks); } -uint32_t board_noos_millis(void) +uint32_t board_millis(void) { return system_ticks; } #endif - -#endif - diff --git a/hw/bsp/metro_m0_express/board_metro_m0_express.c b/hw/bsp/metro_m0_express/board_metro_m0_express.c index 06d8407a..48b8a15e 100644 --- a/hw/bsp/metro_m0_express/board_metro_m0_express.c +++ b/hw/bsp/metro_m0_express/board_metro_m0_express.c @@ -35,8 +35,6 @@ #include "hpl_pm_config.h" #include "hpl/pm/hpl_pm_base.h" -#include "tusb_option.h" - //--------------------------------------------------------------------+ // MACRO TYPEDEF CONSTANT ENUM DECLARATION //--------------------------------------------------------------------+ @@ -120,7 +118,7 @@ uint32_t tusb_hal_millis(void) return board_tick2ms(system_ticks); } -uint32_t board_noos_millis(void) +uint32_t board_millis(void) { return system_ticks; } diff --git a/hw/bsp/metro_m4_express/board_metro_m4_express.c b/hw/bsp/metro_m4_express/board_metro_m4_express.c index d20a0453..ad86b54d 100644 --- a/hw/bsp/metro_m4_express/board_metro_m4_express.c +++ b/hw/bsp/metro_m4_express/board_metro_m4_express.c @@ -32,8 +32,6 @@ #include "hpl/gclk/hpl_gclk_base.h" #include "hpl_mclk_config.h" -#include "tusb_option.h" - //--------------------------------------------------------------------+ // MACRO TYPEDEF CONSTANT ENUM DECLARATION //--------------------------------------------------------------------+ @@ -109,7 +107,7 @@ uint32_t tusb_hal_millis(void) return board_tick2ms(system_ticks); } -uint32_t board_noos_millis(void) +uint32_t board_millis(void) { return system_ticks; } diff --git a/hw/bsp/pca10056/board_pca10056.c b/hw/bsp/pca10056/board_pca10056.c index 179b22dc..70662d9d 100644 --- a/hw/bsp/pca10056/board_pca10056.c +++ b/hw/bsp/pca10056/board_pca10056.c @@ -23,7 +23,6 @@ * * This file is part of the TinyUSB stack. */ -#ifdef BOARD_PCA10056 #include "bsp/board.h" @@ -66,7 +65,7 @@ uint32_t tusb_hal_millis(void) return board_tick2ms(system_ticks); } -uint32_t board_noos_millis(void) +uint32_t board_millis(void) { return system_ticks; } @@ -209,5 +208,3 @@ void nrf_error_cb(uint32_t id, uint32_t pc, uint32_t info) (void) info; } #endif - -#endif diff --git a/hw/bsp/stm32f303disc/board_stm32f303disc.c b/hw/bsp/stm32f303disc/board_stm32f303disc.c index e1cc8c68..b7fbb392 100644 --- a/hw/bsp/stm32f303disc/board_stm32f303disc.c +++ b/hw/bsp/stm32f303disc/board_stm32f303disc.c @@ -25,7 +25,6 @@ */ #include "../board.h" -#include "tusb_option.h" #include "stm32f3xx.h" #include "stm32f3xx_hal_conf.h" @@ -114,7 +113,7 @@ uint32_t tusb_hal_millis(void) return board_tick2ms(system_ticks); } -uint32_t board_noos_millis(void) +uint32_t board_millis(void) { return system_ticks; } diff --git a/hw/bsp/stm32f407g_disc1/board_stm32f407g_disc1.c b/hw/bsp/stm32f407g_disc1/board_stm32f407g_disc1.c index ddafa42b..08fc6bd6 100644 --- a/hw/bsp/stm32f407g_disc1/board_stm32f407g_disc1.c +++ b/hw/bsp/stm32f407g_disc1/board_stm32f407g_disc1.c @@ -28,8 +28,6 @@ #include "stm32f4xx.h" -#include "tusb_option.h" - void board_init(void) { // Init the LED on PD14 @@ -110,7 +108,7 @@ uint32_t tusb_hal_millis(void) return board_tick2ms(system_ticks); } -uint32_t board_noos_millis(void) +uint32_t board_millis(void) { return system_ticks; }