Skip to content

Commit

Permalink
[fix] timer count
Browse files Browse the repository at this point in the history
  • Loading branch information
YuzukiTsuru committed Jan 11, 2024
1 parent ec0604a commit 65a5f6e
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 12 deletions.
4 changes: 3 additions & 1 deletion board/100ask-t113i/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ add_subdirectory(sys_info)

add_subdirectory(syter_boot)

add_subdirectory(load_c906)
add_subdirectory(load_c906)

add_subdirectory(os_test)
5 changes: 5 additions & 0 deletions board/100ask-t113i/os_test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# SPDX-License-Identifier: Apache-2.0

add_syterkit_app(os_test
main.c
)
43 changes: 43 additions & 0 deletions board/100ask-t113i/os_test/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* SPDX-License-Identifier: Apache-2.0 */

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <types.h>

#include <log.h>
#include <os.h>
#include <timer.h>

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;
}
16 changes: 5 additions & 11 deletions src/arch/arm32/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 65a5f6e

Please sign in to comment.