aboutsummaryrefslogtreecommitdiff
path: root/lib/chibios/demos/various/RT-ARMCM4-GENERIC/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chibios/demos/various/RT-ARMCM4-GENERIC/main.c')
-rw-r--r--lib/chibios/demos/various/RT-ARMCM4-GENERIC/main.c93
1 files changed, 93 insertions, 0 deletions
diff --git a/lib/chibios/demos/various/RT-ARMCM4-GENERIC/main.c b/lib/chibios/demos/various/RT-ARMCM4-GENERIC/main.c
new file mode 100644
index 000000000..9ea0bccae
--- /dev/null
+++ b/lib/chibios/demos/various/RT-ARMCM4-GENERIC/main.c
@@ -0,0 +1,93 @@
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 chRegSetThreadName("counter");
49
50 while (true) {
51 chThdSleepMilliseconds(1000);
52 seconds_counter++;
53 }
54}
55
56/*
57 * Application entry point.
58 */
59int main(void) {
60
61 /*
62 * Hardware initialization, in this simple demo just the systick timer is
63 * initialized.
64 */
65 SysTick->LOAD = SYSTEM_CLOCK / CH_CFG_ST_FREQUENCY - (systime_t)1;
66 SysTick->VAL = (uint32_t)0;
67 SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk |
68 SysTick_CTRL_TICKINT_Msk;
69
70 /* IRQ enabled.*/
71 NVIC_SetPriority(SysTick_IRQn, 8);
72
73 /*
74 * System initializations.
75 * - Kernel initialization, the main() function becomes a thread and the
76 * RTOS is active.
77 */
78 chSysInit();
79
80 /*
81 * Creates the example thread.
82 */
83 (void) chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
84
85 /*
86 * Normal main() thread activity, in this demo it does nothing except
87 * increasing the minutes counter.
88 */
89 while (true) {
90 chThdSleepSeconds(60);
91 minutes_counter++;
92 }
93}