From 89e92a2fe1699880d6df7725015fd13d11e9af5f Mon Sep 17 00:00:00 2001 From: lyon1998 Date: Thu, 10 Feb 2022 20:27:12 +0800 Subject: [PATCH] add __run_demo.sh --- port/qemu/__run_demo.sh | 30 +++++++++++++++++++++++++++++ port/qemu/demos/printf_demo/main.c | 25 +++++++++++++++++++----- port/qemu/demos/systick/main.c | 1 + port/qemu/run.sh | 31 +----------------------------- 4 files changed, 52 insertions(+), 35 deletions(-) create mode 100644 port/qemu/__run_demo.sh diff --git a/port/qemu/__run_demo.sh b/port/qemu/__run_demo.sh new file mode 100644 index 000000000..12dd237b4 --- /dev/null +++ b/port/qemu/__run_demo.sh @@ -0,0 +1,30 @@ +# config +OUT_NAME=result.txt + +# clear +rm $OUT_NAME + +# make the project +make clean >/dev/null +make $1_ALL >/dev/null + +# launch qemu service +make $1_QEMURUN_TEL > qemu.out 2>&1 & echo $! > qemu.pid +sleep 1 +# launch netcat client +nc -d 0.0.0.0 7777 > $OUT_NAME 2>&1 & echo $! > nc.pid +sleep 1 + +# kill the processes +kill `cat nc.pid` +kill `cat qemu.pid` +rm nc.pid +rm qemu.pid +rm qemu.out + +# print the result +echo ====================================== +echo [info]: qemu benchmark output +echo -------------------------------------- +cat $OUT_NAME +echo ====================================== diff --git a/port/qemu/demos/printf_demo/main.c b/port/qemu/demos/printf_demo/main.c index 6af3764da..08bc05a9f 100644 --- a/port/qemu/demos/printf_demo/main.c +++ b/port/qemu/demos/printf_demo/main.c @@ -11,7 +11,7 @@ void sleep() { /* redirect printf to myprintf */ #define printf myprintf -static void prime_number_100_c() { +static void prime_number_100_c(void) { int num = 0; num = 0; /* run */ @@ -32,6 +32,22 @@ static void prime_number_100_c() { } } +void systick_init(void) { + uint32_t hclk_ticks_per_sec, ext_clock_ticks_per_sec; + hclk_ticks_per_sec = SystemCoreClock; + ext_clock_ticks_per_sec = hclk_ticks_per_sec / 8; + if (SysTick_Config(ext_clock_ticks_per_sec)) { + /* If SysTick_Config returns 1, that means the number ticks exceeds the + * limit. */ + while (1) + ; + } +} + +void SysTick_Handler(void) { + GPIOC->ODR ^= 0x00001000; +} + int main(void) { uint8_t b; int32_t num1 = 0x1234; @@ -40,9 +56,8 @@ int main(void) { // first init myprintf device(usart2) myprintf_init(); + systick_init(); + uint32_t tic = SysTick->VAL; prime_number_100_c(); - while (1) { - myprintf("test num %d=0x%x str %s ch %c\n", num1, num1, str1, ch1); - sleep(); - } + myprintf("SysTick spend: %d\n", tic - (uint32_t)SysTick->VAL); } diff --git a/port/qemu/demos/systick/main.c b/port/qemu/demos/systick/main.c index dba0e5f45..7f343258e 100644 --- a/port/qemu/demos/systick/main.c +++ b/port/qemu/demos/systick/main.c @@ -36,5 +36,6 @@ int main(void) { last_button_state = GPIOA->IDR & 0x00000001; while (1) { SysTick->CTRL ^= SysTick_CTRL_CLKSOURCE_Msk; + SysTick->VAL; } } diff --git a/port/qemu/run.sh b/port/qemu/run.sh index 725d390ca..0e8b4bff5 100644 --- a/port/qemu/run.sh +++ b/port/qemu/run.sh @@ -1,30 +1 @@ -# config -OUT_NAME=result.txt - -# clear -rm $OUT_NAME - -# make the project -make clean -make printf_demo_ALL - -# launch qemu service -make printf_demo_QEMURUN_TEL > qemu.out 2>&1 & echo $! > qemu.pid -sleep 1 -# launch netcat client -nc -d 0.0.0.0 7777 > $OUT_NAME 2>&1 & echo $! > nc.pid -sleep 1 - -# kill the processes -kill `cat nc.pid` -kill `cat qemu.pid` -rm nc.pid -rm qemu.pid -rm qemu.out - -# print the result -echo ====================================== -echo [info]: qemu benchmark output -echo -------------------------------------- -cat $OUT_NAME -echo ====================================== +sh __run_demo.sh printf_demo