aboutsummaryrefslogtreecommitdiffstats
path: root/demos/various
diff options
context:
space:
mode:
authorGiovanni Di Sirio <gdisirio@gmail.com>2015-05-15 09:41:24 +0000
committerGiovanni Di Sirio <gdisirio@gmail.com>2015-05-15 09:41:24 +0000
commitdc087c5fecaaa29a4b3a55e6976e7ba7ee9d13ab (patch)
tree87863e17152fbc2006b4c9df4a47b162ef4f3b37 /demos/various
parentf3c7490379150c1c1abb9db9ff9035f54b62320e (diff)
downloadChibiOS-dc087c5fecaaa29a4b3a55e6976e7ba7ee9d13ab.tar.gz
ChibiOS-dc087c5fecaaa29a4b3a55e6976e7ba7ee9d13ab.tar.bz2
ChibiOS-dc087c5fecaaa29a4b3a55e6976e7ba7ee9d13ab.zip
Improved standalone RT and NIL demos.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@7984 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'demos/various')
-rw-r--r--demos/various/NIL-ARMCM0-GENERIC/main.c50
-rw-r--r--demos/various/NIL-ARMCM0-GENERIC/nilconf.h2
-rw-r--r--demos/various/NIL-ARMCM4-GENERIC/main.c50
-rw-r--r--demos/various/NIL-ARMCM4-GENERIC/nilconf.h2
-rw-r--r--demos/various/RT-ARMCM0-GENERIC/main.c41
-rw-r--r--demos/various/RT-ARMCM4-GENERIC/main.c41
6 files changed, 172 insertions, 14 deletions
diff --git a/demos/various/NIL-ARMCM0-GENERIC/main.c b/demos/various/NIL-ARMCM0-GENERIC/main.c
index 20af5d493..023db0b8c 100644
--- a/demos/various/NIL-ARMCM0-GENERIC/main.c
+++ b/demos/various/NIL-ARMCM0-GENERIC/main.c
@@ -16,8 +16,29 @@
#include "nil.h"
+#if !defined(SYSTEM_CLOCK)
+#define SYSTEM_CLOCK 8000000U
+#endif
+
/*
- * Blinker thread #1.
+ * @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) {
@@ -26,6 +47,21 @@ static THD_FUNCTION(Thread1, arg) {
while (true) {
chThdSleepMilliseconds(1000);
+ seconds_counter++;
+ }
+}
+
+/*
+ * Minutes counter thread.
+ */
+static THD_WORKING_AREA(waThread2, 128);
+static THD_FUNCTION(Thread2, arg) {
+
+ (void)arg;
+
+ while (true) {
+ chThdSleepSeconds(60);
+ minutes_counter++;
}
}
@@ -34,7 +70,8 @@ static THD_FUNCTION(Thread1, arg) {
* match NIL_CFG_NUM_THREADS.
*/
THD_TABLE_BEGIN
- THD_TABLE_ENTRY(waThread1, "sleeper", Thread1, NULL)
+THD_TABLE_ENTRY(waThread1, "counter1", Thread1, NULL)
+THD_TABLE_ENTRY(waThread2, "counter2", Thread2, NULL)
THD_TABLE_END
/*
@@ -43,6 +80,15 @@ THD_TABLE_END
int main(void) {
/*
+ * Hardware initialization, in this simple demo just the systick timer is
+ * initialized.
+ */
+ SysTick->LOAD = SYSTEM_CLOCK / NIL_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
* RTOS is active.
diff --git a/demos/various/NIL-ARMCM0-GENERIC/nilconf.h b/demos/various/NIL-ARMCM0-GENERIC/nilconf.h
index 6718e19ff..27b6bac60 100644
--- a/demos/various/NIL-ARMCM0-GENERIC/nilconf.h
+++ b/demos/various/NIL-ARMCM0-GENERIC/nilconf.h
@@ -40,7 +40,7 @@
* @note This number is not inclusive of the idle thread which is
* Implicitly handled.
*/
-#define NIL_CFG_NUM_THREADS 1
+#define NIL_CFG_NUM_THREADS 2
/** @} */
diff --git a/demos/various/NIL-ARMCM4-GENERIC/main.c b/demos/various/NIL-ARMCM4-GENERIC/main.c
index 20af5d493..023db0b8c 100644
--- a/demos/various/NIL-ARMCM4-GENERIC/main.c
+++ b/demos/various/NIL-ARMCM4-GENERIC/main.c
@@ -16,8 +16,29 @@
#include "nil.h"
+#if !defined(SYSTEM_CLOCK)
+#define SYSTEM_CLOCK 8000000U
+#endif
+
/*
- * Blinker thread #1.
+ * @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) {
@@ -26,6 +47,21 @@ static THD_FUNCTION(Thread1, arg) {
while (true) {
chThdSleepMilliseconds(1000);
+ seconds_counter++;
+ }
+}
+
+/*
+ * Minutes counter thread.
+ */
+static THD_WORKING_AREA(waThread2, 128);
+static THD_FUNCTION(Thread2, arg) {
+
+ (void)arg;
+
+ while (true) {
+ chThdSleepSeconds(60);
+ minutes_counter++;
}
}
@@ -34,7 +70,8 @@ static THD_FUNCTION(Thread1, arg) {
* match NIL_CFG_NUM_THREADS.
*/
THD_TABLE_BEGIN
- THD_TABLE_ENTRY(waThread1, "sleeper", Thread1, NULL)
+THD_TABLE_ENTRY(waThread1, "counter1", Thread1, NULL)
+THD_TABLE_ENTRY(waThread2, "counter2", Thread2, NULL)
THD_TABLE_END
/*
@@ -43,6 +80,15 @@ THD_TABLE_END
int main(void) {
/*
+ * Hardware initialization, in this simple demo just the systick timer is
+ * initialized.
+ */
+ SysTick->LOAD = SYSTEM_CLOCK / NIL_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
* RTOS is active.
diff --git a/demos/various/NIL-ARMCM4-GENERIC/nilconf.h b/demos/various/NIL-ARMCM4-GENERIC/nilconf.h
index 6718e19ff..27b6bac60 100644
--- a/demos/various/NIL-ARMCM4-GENERIC/nilconf.h
+++ b/demos/various/NIL-ARMCM4-GENERIC/nilconf.h
@@ -40,7 +40,7 @@
* @note This number is not inclusive of the idle thread which is
* Implicitly handled.
*/
-#define NIL_CFG_NUM_THREADS 1
+#define NIL_CFG_NUM_THREADS 2
/** @} */
diff --git a/demos/various/RT-ARMCM0-GENERIC/main.c b/demos/various/RT-ARMCM0-GENERIC/main.c
index fd6b6558e..2cc543d51 100644
--- a/demos/various/RT-ARMCM0-GENERIC/main.c
+++ b/demos/various/RT-ARMCM0-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++;
}
}
@@ -37,6 +59,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
* RTOS is active.
@@ -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++;
}
}
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++;
}
}
@@ -37,6 +59,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
* RTOS is active.
@@ -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++;
}
}