main.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
  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. /*
  16. * GPT4 callback.
  17. */
  18. static void gpt4cb(GPTDriver *gptp) {
  19. (void)gptp;
  20. palSetPad(GPIOD, GPIOD_LED5);
  21. chSysLockFromISR();
  22. gptStartOneShotI(&GPTD3, 1000); /* 0.1 second pulse.*/
  23. chSysUnlockFromISR();
  24. }
  25. /*
  26. * GPT3 callback.
  27. */
  28. static void gpt3cb(GPTDriver *gptp) {
  29. (void)gptp;
  30. palClearPad(GPIOD, GPIOD_LED5);
  31. }
  32. /*
  33. * GPT4 configuration.
  34. */
  35. static const GPTConfig gpt4cfg = {
  36. 10000, /* 10kHz timer clock.*/
  37. gpt4cb, /* Timer callback.*/
  38. 0,
  39. 0
  40. };
  41. /*
  42. * GPT3 configuration.
  43. */
  44. static const GPTConfig gpt3cfg = {
  45. 10000, /* 10kHz timer clock.*/
  46. gpt3cb, /* Timer callback.*/
  47. 0,
  48. 0
  49. };
  50. /*
  51. * Application entry point.
  52. */
  53. int main(void) {
  54. /*
  55. * System initializations.
  56. * - HAL initialization, this also initializes the configured device drivers
  57. * and performs the board-specific initializations.
  58. * - Kernel initialization, the main() function becomes a thread and the
  59. * RTOS is active.
  60. */
  61. halInit();
  62. chSysInit();
  63. /*
  64. * Initializes the GPT drivers 4 and 3.
  65. */
  66. gptStart(&GPTD4, &gpt4cfg);
  67. gptPolledDelay(&GPTD4, 10); /* Small delay.*/
  68. gptStart(&GPTD3, &gpt3cfg);
  69. gptPolledDelay(&GPTD3, 10); /* Small delay.*/
  70. /*
  71. * Normal main() thread activity, it changes the GPT4 period every
  72. * five seconds.
  73. */
  74. while (true) {
  75. palSetPad(GPIOD, GPIOD_LED4);
  76. gptStartContinuous(&GPTD4, 5000);
  77. chThdSleepMilliseconds(5000);
  78. gptStopTimer(&GPTD4);
  79. palClearPad(GPIOD, GPIOD_LED4);
  80. gptStartContinuous(&GPTD4, 2500);
  81. chThdSleepMilliseconds(5000);
  82. gptStopTimer(&GPTD4);
  83. }
  84. }