From dc087c5fecaaa29a4b3a55e6976e7ba7ee9d13ab Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Fri, 15 May 2015 09:41:24 +0000 Subject: Improved standalone RT and NIL demos. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@7984 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- demos/various/RT-ARMCM4-GENERIC/main.c | 41 ++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) (limited to 'demos/various/RT-ARMCM4-GENERIC') diff --git a/demos/various/RT-ARMCM4-GENERIC/main.c b/demos/various/RT-ARMCM4-GENERIC/main.c index fd6b6558e..2cc543d51 100644 --- a/demos/various/RT-ARMCM4-GENERIC/main.c +++ b/demos/various/RT-ARMCM4-GENERIC/main.c @@ -16,18 +16,40 @@ #include "ch.h" +#if !defined(SYSTEM_CLOCK) +#define SYSTEM_CLOCK 8000000U +#endif + /* - * This is a periodic thread that does absolutely nothing except sleeping. + * @brief System Timer handler. + */ +CH_IRQ_HANDLER(SysTick_Handler) { + + CH_IRQ_PROLOGUE(); + + chSysLockFromISR(); + chSysTimerHandlerI(); + chSysUnlockFromISR(); + + CH_IRQ_EPILOGUE(); +} + +static uint32_t seconds_counter; +static uint32_t minutes_counter; + +/* + * Seconds counter thread. */ static THD_WORKING_AREA(waThread1, 128); static THD_FUNCTION(Thread1, arg) { (void)arg; - chRegSetThreadName("sleeper"); + chRegSetThreadName("counter"); while (true) { chThdSleepMilliseconds(1000); + seconds_counter++; } } @@ -36,6 +58,15 @@ static THD_FUNCTION(Thread1, arg) { */ int main(void) { + /* + * Hardware initialization, in this simple demo just the systick timer is + * initialized. + */ + SysTick->LOAD = SYSTEM_CLOCK / CH_CFG_ST_FREQUENCY - (systime_t)1; + SysTick->VAL = (uint32_t)0; + SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk | + SysTick_CTRL_ENABLE_Msk; + /* * System initializations. * - Kernel initialization, the main() function becomes a thread and the @@ -49,9 +80,11 @@ int main(void) { (void) chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); /* - * Normal main() thread activity, in this demo it just sleeps. + * Normal main() thread activity, in this demo it does nothing except + * increasing the minutes counter. */ while (true) { - chThdSleepMilliseconds(1000); + chThdSleepSeconds(60); + minutes_counter++; } } -- cgit v1.2.3