summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhathach <[email protected]>2019-03-23 22:31:07 +0700
committerhathach <[email protected]>2019-03-23 22:31:07 +0700
commit29e075b8b968806c4a9ebffdbdfacbd9b01cf029 (patch)
tree03941d6899d47015d850bba4152fb63f0c44048f
parentd866999bf0f41b0d3db0354c599d014c66dc6870 (diff)
clean up bsp, adde board_millis()
-rw-r--r--examples/device/cdc_msc_hid/src/main.c4
-rw-r--r--examples/device/cdc_msc_hid_freertos/src/main.c7
-rw-r--r--hw/bsp/board.h25
-rw-r--r--hw/bsp/ea4088qs/board_ea4088qs.c8
-rw-r--r--hw/bsp/ea4357/board_ea4357.c8
-rw-r--r--hw/bsp/lpcxpresso11u68/board_lpcxpresso11u68.c6
-rw-r--r--hw/bsp/lpcxpresso1347/board_lpcxpresso1347.c10
-rw-r--r--hw/bsp/lpcxpresso1769/board_lpcxpresso1769.c8
-rw-r--r--hw/bsp/mcb1800/board_mcb1800.c9
-rw-r--r--hw/bsp/metro_m0_express/board_metro_m0_express.c4
-rw-r--r--hw/bsp/metro_m4_express/board_metro_m4_express.c4
-rw-r--r--hw/bsp/pca10056/board_pca10056.c5
-rw-r--r--hw/bsp/stm32f303disc/board_stm32f303disc.c3
-rw-r--r--hw/bsp/stm32f407g_disc1/board_stm32f407g_disc1.c4
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 06a99711f..75d9a31dc 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 5705c1657..b5d5cf790 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 44dba7ecf..ea0f3152c 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 e4b006c74..11b3a7eb8 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 3bb846cc1..e5e93033d 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 ca7e699c0..d3883be54 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 18853c5fb..20b82cd62 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"
@@ -84,10 +82,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);
#elif CFG_TUSB_OS == OPT_OS_FREERTOS
@@ -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 5578ae5d6..0b7e7a1bd 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 d6b45090d..7ace1a0ee 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 06d8407ab..48b8a15ef 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 d20a04537..ad86b54d7 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 179b22dcc..70662d9dd 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 e1cc8c689..b7fbb3927 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 ddafa42b2..08fc6bd66 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;
}