main.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. ChibiOS - Copyright (C) 2016..2018 Theodore Ateba
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. #include "ch.h"
  14. #include "hal.h"
  15. #include "chprintf.h"
  16. BaseSequentialStream *chp = (BaseSequentialStream *) &SD1;
  17. /*
  18. * Watchdog dealine set to one second.
  19. */
  20. static const WDGConfig wdgcfg = {
  21. false, /* WDT use period mode, set true for window mode. */
  22. WDT_PER_1KCLK_gc, /* Normal timeout period of 1 second. */
  23. WDT_WPER_1KCLK_gc /* Closed timeout period of 1 second. */
  24. };
  25. /*
  26. * Application entry point.
  27. */
  28. int main(void) {
  29. /*
  30. * System initializations.
  31. * - HAL initialization, this also initializes the configured device drivers
  32. * and performs the board-specific initializations.
  33. * - Kernel initialization, the main() function becomes a thread and the
  34. * RTOS is active.
  35. */
  36. halInit();
  37. chSysInit();
  38. /*
  39. * Configure TX (PINC3) and RX (PIN2) for the USART1.
  40. */
  41. palSetPadMode(IOPORT3, PIN3, PAL_MODE_OUTPUT_PUSHPULL);
  42. palSetPadMode(IOPORT3, PIN2, PAL_MODE_INPUT_PULLUP);
  43. /*
  44. * Start the Serial driver 1.
  45. */
  46. sdStart(&SD1, NULL);
  47. /*
  48. * Starting the watchdog driver.
  49. */
  50. wdgStart(&WDTD1, &wdgcfg);
  51. chprintf(chp, "Watchdog driver test program.\r\n");
  52. /*
  53. * Normal main() thread activity, it resets the watchdog.
  54. */
  55. while (TRUE) {
  56. chprintf(chp, "Watchdog reset by software.\r\n");
  57. wdgReset(&WDTD1); // TODO: Rebuild whit this line commented.
  58. // It will shows you if the board is rebooted
  59. // by the watchdog.
  60. palTogglePad(IOPORT5, PORTE_LED);
  61. chThdSleepMilliseconds(500); // Use for example 2 second of delay to see if the watchdog reset the board every second.
  62. }
  63. return 0;
  64. }