aboutsummaryrefslogtreecommitdiff
path: root/lib/chibios/demos/various/NIL-ARMCM4-GENERIC/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chibios/demos/various/NIL-ARMCM4-GENERIC/main.c')
-rw-r--r--lib/chibios/demos/various/NIL-ARMCM4-GENERIC/main.c103
1 files changed, 103 insertions, 0 deletions
diff --git a/lib/chibios/demos/various/NIL-ARMCM4-GENERIC/main.c b/lib/chibios/demos/various/NIL-ARMCM4-GENERIC/main.c
new file mode 100644
index 000000000..c4ee399f2
--- /dev/null
+++ b/lib/chibios/demos/various/NIL-ARMCM4-GENERIC/main.c
@@ -0,0 +1,103 @@
1/*
2 ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17#include "ch.h"
18
19#if !defined(SYSTEM_CLOCK)
20#define SYSTEM_CLOCK 8000000U
21#endif
22
23/*
24 * @brief System Timer handler.
25 */
26CH_IRQ_HANDLER(SysTick_Handler) {
27
28 CH_IRQ_PROLOGUE();
29
30 chSysLockFromISR();
31 chSysTimerHandlerI();
32 chSysUnlockFromISR();
33
34 CH_IRQ_EPILOGUE();
35}
36
37static uint32_t seconds_counter;
38static uint32_t minutes_counter;
39
40/*
41 * Seconds counter thread.
42 */
43static THD_WORKING_AREA(waThread1, 128);
44static THD_FUNCTION(Thread1, arg) {
45
46 (void)arg;
47
48 while (true) {
49 chThdSleepMilliseconds(1000);
50 seconds_counter++;
51 }
52}
53
54/*
55 * Minutes counter thread.
56 */
57static THD_WORKING_AREA(waThread2, 128);
58static THD_FUNCTION(Thread2, arg) {
59
60 (void)arg;
61
62 while (true) {
63 chThdSleepSeconds(60);
64 minutes_counter++;
65 }
66}
67
68/*
69 * Threads creation table, one entry per thread.
70 */
71THD_TABLE_BEGIN
72 THD_TABLE_THREAD(0, "counter1", waThread1, Thread1, NULL)
73 THD_TABLE_THREAD(1, "counter2", waThread2, Thread2, NULL)
74THD_TABLE_END
75
76/*
77 * Application entry point.
78 */
79int main(void) {
80
81 /*
82 * Hardware initialization, in this simple demo just the systick timer is
83 * initialized.
84 */
85 SysTick->LOAD = SYSTEM_CLOCK / CH_CFG_ST_FREQUENCY - (systime_t)1;
86 SysTick->VAL = (uint32_t)0;
87 SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk |
88 SysTick_CTRL_TICKINT_Msk;
89
90 /*
91 * System initializations.
92 * - Kernel initialization, the main() function becomes a thread and the
93 * RTOS is active.
94 */
95 chSysInit();
96
97 /* This is now the idle thread loop, you may perform here a low priority
98 task but you must never try to sleep or wait in this loop. Note that
99 this tasks runs at the lowest priority level so any instruction added
100 here will be executed after all other tasks have been started.*/
101 while (true) {
102 }
103}