From 65a5f6e4639ddbce03e2aa4f384d29beb2a2e9f3 Mon Sep 17 00:00:00 2001 From: YuzukiTsuru Date: Thu, 11 Jan 2024 22:06:13 +0800 Subject: [PATCH] [fix] timer count --- board/100ask-t113i/CMakeLists.txt | 4 ++- board/100ask-t113i/os_test/CMakeLists.txt | 5 +++ board/100ask-t113i/os_test/main.c | 43 +++++++++++++++++++++++ src/arch/arm32/timer.c | 16 +++------ 4 files changed, 56 insertions(+), 12 deletions(-) create mode 100644 board/100ask-t113i/os_test/CMakeLists.txt create mode 100644 board/100ask-t113i/os_test/main.c diff --git a/board/100ask-t113i/CMakeLists.txt b/board/100ask-t113i/CMakeLists.txt index f7d914a2..63ac0a4d 100644 --- a/board/100ask-t113i/CMakeLists.txt +++ b/board/100ask-t113i/CMakeLists.txt @@ -10,4 +10,6 @@ add_subdirectory(sys_info) add_subdirectory(syter_boot) -add_subdirectory(load_c906) \ No newline at end of file +add_subdirectory(load_c906) + +add_subdirectory(os_test) diff --git a/board/100ask-t113i/os_test/CMakeLists.txt b/board/100ask-t113i/os_test/CMakeLists.txt new file mode 100644 index 00000000..b54c6d0d --- /dev/null +++ b/board/100ask-t113i/os_test/CMakeLists.txt @@ -0,0 +1,5 @@ +# SPDX-License-Identifier: Apache-2.0 + +add_syterkit_app(os_test + main.c +) \ No newline at end of file diff --git a/board/100ask-t113i/os_test/main.c b/board/100ask-t113i/os_test/main.c new file mode 100644 index 00000000..d1b8d957 --- /dev/null +++ b/board/100ask-t113i/os_test/main.c @@ -0,0 +1,43 @@ +/* SPDX-License-Identifier: Apache-2.0 */ + +#include +#include +#include +#include + +#include +#include +#include + +extern sunxi_serial_t uart_dbg; + +static void timer_500ms_cb(void *arg, uint32_t event) { + printk(LOG_LEVEL_INFO, "Timer 500ms callback\n"); +} + +static void timer_1500ms_run2_cb(void *arg, uint32_t event) { + printk(LOG_LEVEL_INFO, "Timer 500ms run 2 times callback\n"); +} + +int main(void) { + sunxi_serial_init(&uart_dbg); + + sunxi_clk_init(); + + printk(LOG_LEVEL_INFO, "Hello World!\n"); + + timer_t timer_500ms; + timer_create(&timer_500ms, timer_500ms_cb, NULL); + timer_start(&timer_500ms, TIMER_ALWAYS_RUN, 500); + + timer_t timer_1500ms_run2; + timer_create(&timer_1500ms_run2, timer_1500ms_run2_cb, NULL); + timer_start(&timer_1500ms_run2, 2, 1500); + + while (1) { + timer_handle(); + mdelay(1); + } + + return 0; +} \ No newline at end of file diff --git a/src/arch/arm32/timer.c b/src/arch/arm32/timer.c index ea40f388..85667704 100644 --- a/src/arch/arm32/timer.c +++ b/src/arch/arm32/timer.c @@ -45,20 +45,14 @@ uint64_t time_us(void) { } void udelay(uint64_t us) { - uint64_t now; - - now = time_us(); - while (time_us() - now < us) { - }; + volatile uint32_t counter = us * 8; + sdelay(counter); } void mdelay(uint32_t ms) { - udelay(ms * 1000); - uint32_t now; - - now = time_ms(); - while (time_ms() - now < ms) { - }; + while (ms--) { + udelay(1000); + } } void sdelay(uint32_t loops) {