main.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. #include "rt_test_root.h"
  16. #include "oslib_test_root.h"
  17. /*
  18. * Blue LED blinker thread, times are in milliseconds.
  19. */
  20. static THD_WORKING_AREA(waThread1, 128);
  21. static THD_FUNCTION(Thread1, arg) {
  22. (void)arg;
  23. chRegSetThreadName("blinker1");
  24. while (true) {
  25. palClearPad(GPIOC, GPIOC_LED_BLUE);
  26. chThdSleepMilliseconds(500);
  27. palSetPad(GPIOC, GPIOC_LED_BLUE);
  28. chThdSleepMilliseconds(500);
  29. }
  30. }
  31. /*
  32. * Green LED blinker thread, times are in milliseconds.
  33. */
  34. static THD_WORKING_AREA(waThread2, 128);
  35. static THD_FUNCTION(Thread2, arg) {
  36. (void)arg;
  37. chRegSetThreadName("blinker2");
  38. while (true) {
  39. palClearPad(GPIOC, GPIOC_LED_GREEN);
  40. chThdSleepMilliseconds(250);
  41. palSetPad(GPIOC, GPIOC_LED_GREEN);
  42. chThdSleepMilliseconds(250);
  43. }
  44. }
  45. /*
  46. * Application entry point.
  47. */
  48. int main(void) {
  49. /*
  50. * System initializations.
  51. * - HAL initialization, this also initializes the configured device drivers
  52. * and performs the board-specific initializations.
  53. * - Kernel initialization, the main() function becomes a thread and the
  54. * RTOS is active.
  55. */
  56. halInit();
  57. chSysInit();
  58. /*
  59. * Activates the serial driver 1 using the driver default configuration.
  60. * PA9 and PA10 are routed to USART1.
  61. */
  62. sdStart(&SD1, NULL);
  63. palSetPadMode(GPIOA, 9, PAL_MODE_ALTERNATE(1)); /* USART1 TX. */
  64. palSetPadMode(GPIOA, 10, PAL_MODE_ALTERNATE(1)); /* USART1 RX. */
  65. /*
  66. * Creates the blinker threads.
  67. */
  68. chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
  69. chThdCreateStatic(waThread2, sizeof(waThread2), NORMALPRIO, Thread2, NULL);
  70. /*
  71. * Normal main() thread activity, in this demo it does nothing except
  72. * sleeping in a loop and check the button state, when the button is
  73. * pressed the test procedure is launched with output on the serial
  74. * driver 1.
  75. */
  76. while (true) {
  77. if (palReadPad(GPIOA, GPIOA_BUTTON)) {
  78. test_execute((BaseSequentialStream *)&SD1, &rt_test_suite);
  79. test_execute((BaseSequentialStream *)&SD1, &oslib_test_suite);
  80. }
  81. chThdSleepMilliseconds(500);
  82. }
  83. }