diff options
author | marcoveeneman <marco-veeneman@hotmail.com> | 2016-04-06 21:26:50 +0200 |
---|---|---|
committer | marcoveeneman <marco-veeneman@hotmail.com> | 2016-04-06 21:26:50 +0200 |
commit | 6a3337160e7e316acd3e4ff6cf7983da251ac0c2 (patch) | |
tree | 3023093b4b24059baba6888303cc7acabfd1b120 /testhal/TIVA/TM4C123x/WDG/main.c | |
parent | eb960077b892b07d004629ff9d9d7b114a658264 (diff) | |
download | ChibiOS-Contrib-6a3337160e7e316acd3e4ff6cf7983da251ac0c2.tar.gz ChibiOS-Contrib-6a3337160e7e316acd3e4ff6cf7983da251ac0c2.tar.bz2 ChibiOS-Contrib-6a3337160e7e316acd3e4ff6cf7983da251ac0c2.zip |
Tiva. WDG. Added testhal demo for Watchdog driver.
Diffstat (limited to 'testhal/TIVA/TM4C123x/WDG/main.c')
-rw-r--r-- | testhal/TIVA/TM4C123x/WDG/main.c | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/testhal/TIVA/TM4C123x/WDG/main.c b/testhal/TIVA/TM4C123x/WDG/main.c new file mode 100644 index 0000000..3aa8a07 --- /dev/null +++ b/testhal/TIVA/TM4C123x/WDG/main.c @@ -0,0 +1,79 @@ +/* + Copyright (C) 2014 Marco Veeneman + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +#include "ch.h" +#include "hal.h" + +static bool watchdog_timeout(WDGDriver *wdgp) +{ + (void)wdgp; + + palSetPad(GPIOF, GPIOF_LED_RED); + + return true; +} + +/* + * Watchdog deadline set to more than one second (LSI=40000 / (64 * 1000)). + */ +static const WDGConfig wdgcfg = +{ + 80000000, + watchdog_timeout, + TEST_STALL +}; + +/* + * Application entry point. + */ +int main(void) { + + /* + * System initializations. + * - HAL initialization, this also initializes the configured device drivers + * and performs the board-specific initializations. + * - Kernel initialization, the main() function becomes a thread and the + * RTOS is active. + */ + halInit(); + chSysInit(); + + palSetPadMode(GPIOF, GPIOF_LED_RED, PAL_MODE_OUTPUT_PUSHPULL); + palSetPadMode(GPIOF, GPIOF_LED_BLUE, PAL_MODE_OUTPUT_PUSHPULL); + + palSetPadMode(GPIOF, GPIOF_SW1, PAL_MODE_INPUT_PULLUP); + palSetPadMode(GPIOF, GPIOF_SW2, PAL_MODE_INPUT_PULLUP); + + /* + * Starting the watchdog driver. + */ + wdgStart(&WDGD1, &wdgcfg); + + /* + * Normal main() thread activity, it resets the watchdog. + */ + while (true) { + if (palReadPad(GPIOF, GPIOF_SW1)) { + wdgReset(&WDGD1); + palClearPad(GPIOF, GPIOF_LED_RED); + } + + palTogglePad(GPIOF, GPIOF_LED_BLUE); + + chThdSleepMilliseconds(500); + } + return 0; +} |