main.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. palSetLine(LINE_LED1);
  27. chThdSleepMilliseconds(50);
  28. palSetLine(LINE_LED2);
  29. chThdSleepMilliseconds(50);
  30. palSetLine(LINE_LED3);
  31. chThdSleepMilliseconds(200);
  32. palClearLine(LINE_LED1);
  33. chThdSleepMilliseconds(50);
  34. palClearLine(LINE_LED2);
  35. chThdSleepMilliseconds(50);
  36. palClearLine(LINE_LED3);
  37. chThdSleepMilliseconds(200);
  38. }
  39. }
  40. /*
  41. * Application entry point.
  42. */
  43. int main(void) {
  44. /*
  45. * System initializations.
  46. * - HAL initialization, this also initializes the configured device drivers
  47. * and performs the board-specific initializations.
  48. * - Kernel initialization, the main() function becomes a thread and the
  49. * RTOS is active.
  50. */
  51. halInit();
  52. chSysInit();
  53. /*
  54. * Activates the serial driver 3 using the driver default configuration.
  55. */
  56. sdStart(&SD3, NULL);
  57. /*
  58. * Creates the example thread.
  59. */
  60. chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO + 1, Thread1, NULL);
  61. /*
  62. * Normal main() thread activity, in this demo it does nothing except
  63. * sleeping in a loop and check the button state.
  64. */
  65. while (true) {
  66. if (palReadLine(LINE_BUTTON)) {
  67. test_execute((BaseSequentialStream *)&SD3, &rt_test_suite);
  68. test_execute((BaseSequentialStream *)&SD3, &oslib_test_suite);
  69. }
  70. chThdSleepMilliseconds(500);
  71. }
  72. }