aboutsummaryrefslogtreecommitdiff
path: root/lib/chibios-contrib/testhal/KINETIS/KL27Z/BLINK/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chibios-contrib/testhal/KINETIS/KL27Z/BLINK/main.c')
-rw-r--r--lib/chibios-contrib/testhal/KINETIS/KL27Z/BLINK/main.c94
1 files changed, 94 insertions, 0 deletions
diff --git a/lib/chibios-contrib/testhal/KINETIS/KL27Z/BLINK/main.c b/lib/chibios-contrib/testhal/KINETIS/KL27Z/BLINK/main.c
new file mode 100644
index 000000000..941be48fa
--- /dev/null
+++ b/lib/chibios-contrib/testhal/KINETIS/KL27Z/BLINK/main.c
@@ -0,0 +1,94 @@
1/*
2 ChibiOS/RT KL27 example - Copyright (C) 2015 flabbergast
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#include "hal.h"
17
18/*
19 * Blink thread
20 */
21static THD_WORKING_AREA(waBlinkThread, 128);
22static THD_FUNCTION(BlinkThread, arg) {
23 (void)arg;
24
25 while(TRUE) {
26 palTogglePad(GPIO_LED, PIN_LED);
27 chThdSleepMilliseconds(700);
28 }
29}
30
31/*
32 * Check button thread
33 */
34static THD_WORKING_AREA(waButtonThread, 128);
35static THD_FUNCTION(ButtonThread, arg) {
36 (void)arg;
37 chRegSetThreadName("buttonThread");
38
39 uint8_t newstate, state = PAL_HIGH;
40
41 while(true) {
42 if(palReadPad(GPIO_BUTTON, PIN_BUTTON) != state) {
43 chThdSleepMilliseconds(20); /* debounce */
44 newstate = palReadPad(GPIO_BUTTON, PIN_BUTTON);
45 if(newstate != state) {
46 state = newstate;
47 if(newstate == PAL_LOW) {
48 // palTogglePad(GPIO_LED, PIN_LED);
49 /* jump to bootloader */
50 /* force boot from ROM */
51 RCM->FM = RCM_FM_FORCEROM(2);
52 /* request RESET */
53 #define SCB_AIRCR_VECTKEY_WRITEMAGIC 0x05FA0000
54 SCB->AIRCR = SCB_AIRCR_VECTKEY_WRITEMAGIC | SCB_AIRCR_SYSRESETREQ_Msk;
55 }
56 }
57 }
58 chThdSleepMilliseconds(20);
59 }
60}
61
62/*
63 * Application entry point.
64 */
65int main(void) {
66 /*
67 * System initializations.
68 * - HAL initialization, this also initializes the configured device drivers
69 * and performs the board-specific initializations.
70 * - Kernel initialization, the main() function becomes a thread and the
71 * RTOS is active.
72 */
73 halInit();
74 chSysInit();
75
76 /*
77 * Create the blink thread.
78 */
79 chThdCreateStatic(waBlinkThread, sizeof(waBlinkThread), NORMALPRIO, BlinkThread, NULL);
80
81 /*
82 * Create the button check thread.
83 */
84 chThdCreateStatic(waButtonThread, sizeof(waButtonThread), NORMALPRIO, ButtonThread, NULL);
85
86 /*
87 * Normal main() thread activity, in this demo it does nothing.
88 */
89 while(TRUE) {
90 chThdSleepMilliseconds(500);
91 }
92
93 return 0;
94}