diff options
Diffstat (limited to 'lib/chibios-contrib/testhal/KINETIS/TEENSY_LC/BOOTLOADER/main.c')
-rw-r--r-- | lib/chibios-contrib/testhal/KINETIS/TEENSY_LC/BOOTLOADER/main.c | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/lib/chibios-contrib/testhal/KINETIS/TEENSY_LC/BOOTLOADER/main.c b/lib/chibios-contrib/testhal/KINETIS/TEENSY_LC/BOOTLOADER/main.c new file mode 100644 index 000000000..8615523cf --- /dev/null +++ b/lib/chibios-contrib/testhal/KINETIS/TEENSY_LC/BOOTLOADER/main.c | |||
@@ -0,0 +1,103 @@ | |||
1 | /* | ||
2 | (C) 2015-2016 flabbergast <[email protected]> | ||
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 | #define BTN_GPIO TEENSY_PIN2_IOPORT | ||
19 | #define BTN_PIN TEENSY_PIN2 | ||
20 | |||
21 | /* | ||
22 | * Jump to bootloader on ARM Teensies. | ||
23 | */ | ||
24 | |||
25 | static void jump_to_bootloader(void) { | ||
26 | /* __asm__ volatile("bkpt"); */ | ||
27 | /* Same as above, CMSIS notation: */ | ||
28 | __BKPT(0); | ||
29 | } | ||
30 | |||
31 | /* | ||
32 | * Blink thread. | ||
33 | */ | ||
34 | |||
35 | static THD_WORKING_AREA(waBlinkThread, 128); | ||
36 | static THD_FUNCTION(BlinkThread, arg) { | ||
37 | (void)arg; | ||
38 | uint8_t i; | ||
39 | |||
40 | // while(TRUE) { | ||
41 | for(i=0; i<5; i++) { | ||
42 | palSetPad(TEENSY_PIN13_IOPORT, TEENSY_PIN13); | ||
43 | chThdSleepMilliseconds(700); | ||
44 | palClearPad(TEENSY_PIN13_IOPORT, TEENSY_PIN13); | ||
45 | chThdSleepMilliseconds(700); | ||
46 | } | ||
47 | jump_to_bootloader(); | ||
48 | } | ||
49 | |||
50 | /* | ||
51 | * Button thread. | ||
52 | */ | ||
53 | |||
54 | static THD_WORKING_AREA(waButtonThread, 128); | ||
55 | static THD_FUNCTION(ButtonThread, arg) { | ||
56 | (void)arg; | ||
57 | |||
58 | while(TRUE) { | ||
59 | if(palReadPad(BTN_GPIO, BTN_PIN) == PAL_LOW) { | ||
60 | jump_to_bootloader(); | ||
61 | } | ||
62 | chThdSleepMilliseconds(50); | ||
63 | } | ||
64 | } | ||
65 | |||
66 | /* | ||
67 | * Application entry point. | ||
68 | */ | ||
69 | int main(void) { | ||
70 | /* | ||
71 | * System initializations. | ||
72 | * - HAL initialization, this also initializes the configured device drivers | ||
73 | * and performs the board-specific initializations. | ||
74 | * - Kernel initialization, the main() function becomes a thread and the | ||
75 | * RTOS is active. | ||
76 | */ | ||
77 | halInit(); | ||
78 | chSysInit(); | ||
79 | |||
80 | /* | ||
81 | * Button init. | ||
82 | */ | ||
83 | palSetPadMode(BTN_GPIO, BTN_PIN, PAL_MODE_INPUT_PULLUP); | ||
84 | |||
85 | /* | ||
86 | * Create the blink thread. | ||
87 | */ | ||
88 | chThdCreateStatic(waBlinkThread, sizeof(waBlinkThread), NORMALPRIO, BlinkThread, NULL); | ||
89 | |||
90 | /* | ||
91 | * Create the button thread. | ||
92 | */ | ||
93 | chThdCreateStatic(waButtonThread, sizeof(waButtonThread), NORMALPRIO, ButtonThread, NULL); | ||
94 | |||
95 | /* | ||
96 | * Normal main() thread activity, in this demo it does nothing. | ||
97 | */ | ||
98 | while(TRUE) { | ||
99 | chThdSleepMilliseconds(500); | ||
100 | } | ||
101 | |||
102 | return 0; | ||
103 | } | ||