main.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. #define BOTH_BUTTONS (PAL_PORT_BIT(PA_BUTTON1) | PAL_PORT_BIT(PA_BUTTON2))
  18. /*
  19. * Red LEDs blinker thread, times are in milliseconds.
  20. */
  21. static THD_WORKING_AREA(waThread1, 128);
  22. static THD_FUNCTION(Thread1, arg) {
  23. (void)arg;
  24. chRegSetThreadName("blinker1");
  25. while (true) {
  26. palClearPort(IOPORT1, PAL_PORT_BIT(PA_LED2));
  27. chThdSleepMilliseconds(200);
  28. palSetPort(IOPORT1, PAL_PORT_BIT(PA_LED1) | PAL_PORT_BIT(PA_LED2));
  29. chThdSleepMilliseconds(800);
  30. palClearPort(IOPORT1, PAL_PORT_BIT(PA_LED1));
  31. chThdSleepMilliseconds(200);
  32. palSetPort(IOPORT1, PAL_PORT_BIT(PA_LED1) | PAL_PORT_BIT(PA_LED2));
  33. chThdSleepMilliseconds(800);
  34. }
  35. }
  36. /*
  37. * Yellow LED blinker thread, times are in milliseconds.
  38. */
  39. static THD_WORKING_AREA(waThread2, 128);
  40. static THD_FUNCTION(Thread2, arg) {
  41. (void)arg;
  42. chRegSetThreadName("blinker2");
  43. while (true) {
  44. palClearPad(IOPORT1, PA_LEDUSB);
  45. chThdSleepMilliseconds(200);
  46. palSetPad(IOPORT1, PA_LEDUSB);
  47. chThdSleepMilliseconds(300);
  48. }
  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. * Activates the serial driver 1 using the driver default configuration.
  65. */
  66. sdStart(&SD1, NULL);
  67. /*
  68. * Creating blinkers threads.
  69. */
  70. chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
  71. chThdCreateStatic(waThread2, sizeof(waThread2), NORMALPRIO, Thread2, NULL);
  72. /*
  73. * Normal main() thread activity, in this demo it does nothing except
  74. * sleeping in a loop and check the buttons state and run test procedure.
  75. */
  76. while (true) {
  77. if (!palReadPad(IOPORT1, PA_BUTTON1))
  78. sdWrite(&SD1, (uint8_t *)"Hello World!\r\n", 14);
  79. if (!palReadPad(IOPORT1, PA_BUTTON2)) {
  80. test_execute((BaseSequentialStream *)&SD1, &rt_test_suite);
  81. test_execute((BaseSequentialStream *)&SD1, &oslib_test_suite);
  82. }
  83. chThdSleepMilliseconds(500);
  84. }
  85. return 0;
  86. }