diff options
Diffstat (limited to 'lib/chibios-contrib/testhal/TIVA/TM4C123x/WDG/main.c')
-rw-r--r-- | lib/chibios-contrib/testhal/TIVA/TM4C123x/WDG/main.c | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/lib/chibios-contrib/testhal/TIVA/TM4C123x/WDG/main.c b/lib/chibios-contrib/testhal/TIVA/TM4C123x/WDG/main.c new file mode 100644 index 000000000..73c2d6157 --- /dev/null +++ b/lib/chibios-contrib/testhal/TIVA/TM4C123x/WDG/main.c | |||
@@ -0,0 +1,82 @@ | |||
1 | /* | ||
2 | Copyright (C) 2014..2017 Marco Veeneman | ||
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 | #include "hal.h" | ||
19 | |||
20 | static bool watchdog_timeout(WDGDriver *wdgp) | ||
21 | { | ||
22 | (void)wdgp; | ||
23 | |||
24 | palSetLine(LINE_LED_RED); | ||
25 | |||
26 | /* Return true to prevent a reset on the next timeout.*/ | ||
27 | return true; | ||
28 | } | ||
29 | |||
30 | /* | ||
31 | * Watchdog deadline set to one second. | ||
32 | * Use callback on first timeout. | ||
33 | * Stall timer if paused by debugger. | ||
34 | */ | ||
35 | static const WDGConfig wdgcfg = | ||
36 | { | ||
37 | TIVA_SYSCLK, | ||
38 | watchdog_timeout, | ||
39 | WDT_TEST_STALL | ||
40 | }; | ||
41 | |||
42 | /* | ||
43 | * Application entry point. | ||
44 | */ | ||
45 | int main(void) { | ||
46 | |||
47 | /* | ||
48 | * System initializations. | ||
49 | * - HAL initialization, this also initializes the configured device drivers | ||
50 | * and performs the board-specific initializations. | ||
51 | * - Kernel initialization, the main() function becomes a thread and the | ||
52 | * RTOS is active. | ||
53 | */ | ||
54 | halInit(); | ||
55 | chSysInit(); | ||
56 | |||
57 | palSetLineMode(LINE_LED_RED, PAL_MODE_OUTPUT_PUSHPULL); | ||
58 | palSetLineMode(LINE_LED_BLUE, PAL_MODE_OUTPUT_PUSHPULL); | ||
59 | |||
60 | palSetLineMode(LINE_SW1, PAL_MODE_INPUT_PULLUP); | ||
61 | |||
62 | /* | ||
63 | * Starting the watchdog driver. | ||
64 | */ | ||
65 | wdgStart(&WDGD1, &wdgcfg); | ||
66 | |||
67 | /* | ||
68 | * Normal main() thread activity, it resets the watchdog. | ||
69 | */ | ||
70 | while (true) { | ||
71 | if (palReadLine(LINE_SW1)) { | ||
72 | /* Only reset the watchdog if the button is not pressed */ | ||
73 | wdgReset(&WDGD1); | ||
74 | palClearLine(LINE_LED_RED); | ||
75 | } | ||
76 | |||
77 | palToggleLine(LINE_LED_BLUE); | ||
78 | |||
79 | chThdSleepMilliseconds(500); | ||
80 | } | ||
81 | return 0; | ||
82 | } | ||