main.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. * This is a periodic thread that does absolutely nothing except flashing
  19. * a LED.
  20. */
  21. static THD_WORKING_AREA(waThread1, 128);
  22. static THD_FUNCTION(Thread1, arg) {
  23. (void)arg;
  24. chRegSetThreadName("blinker");
  25. while (true) {
  26. palSetPad(GPIOD, GPIOD_LED3); /* Orange. */
  27. chThdSleepMilliseconds(500);
  28. palClearPad(GPIOD, GPIOD_LED3); /* Orange. */
  29. chThdSleepMilliseconds(500);
  30. }
  31. }
  32. /*
  33. * Application entry point.
  34. */
  35. int main(void) {
  36. /*
  37. * System initializations.
  38. * - HAL initialization, this also initializes the configured device drivers
  39. * and performs the board-specific initializations.
  40. * - Kernel initialization, the main() function becomes a thread and the
  41. * RTOS is active.
  42. */
  43. halInit();
  44. chSysInit();
  45. /*
  46. * Activates the serial driver 2 using the driver default configuration.
  47. * PA2(TX) and PA3(RX) are routed to USART2.
  48. */
  49. sdStart(&SD2, NULL);
  50. palSetPadMode(GPIOA, 2, PAL_MODE_ALTERNATE(7));
  51. palSetPadMode(GPIOA, 3, PAL_MODE_ALTERNATE(7));
  52. /*
  53. * Creates the example thread.
  54. */
  55. chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
  56. /*
  57. * Normal main() thread activity, in this demo it does nothing except
  58. * sleeping in a loop and check the button state.
  59. */
  60. while (true) {
  61. if (palReadPad(GPIOA, GPIOA_BUTTON)) {
  62. test_execute((BaseSequentialStream *)&SD2, &rt_test_suite);
  63. test_execute((BaseSequentialStream *)&SD2, &oslib_test_suite);
  64. }
  65. chThdSleepMilliseconds(500);
  66. }
  67. }