main.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 "hal.h"
  14. #include "ch.h"
  15. #include "nil_test_root.h"
  16. #include "oslib_test_root.h"
  17. /*
  18. * Blinker thread #1.
  19. */
  20. static THD_WORKING_AREA(waThread1, 128);
  21. static THD_FUNCTION(Thread1, arg) {
  22. (void)arg;
  23. while (true) {
  24. palSetPad(GPIOE, GPIOE_LED3_RED);
  25. chThdSleepMilliseconds(125);
  26. palClearPad(GPIOE, GPIOE_LED3_RED);
  27. chThdSleepMilliseconds(125);
  28. palSetPad(GPIOE, GPIOE_LED7_GREEN);
  29. chThdSleepMilliseconds(125);
  30. palClearPad(GPIOE, GPIOE_LED7_GREEN);
  31. chThdSleepMilliseconds(125);
  32. palSetPad(GPIOE, GPIOE_LED10_RED);
  33. chThdSleepMilliseconds(125);
  34. palClearPad(GPIOE, GPIOE_LED10_RED);
  35. chThdSleepMilliseconds(125);
  36. palSetPad(GPIOE, GPIOE_LED6_GREEN);
  37. chThdSleepMilliseconds(125);
  38. palClearPad(GPIOE, GPIOE_LED6_GREEN);
  39. chThdSleepMilliseconds(125);
  40. }
  41. }
  42. /*
  43. * Blinker thread #2.
  44. */
  45. static THD_WORKING_AREA(waThread2, 128);
  46. static THD_FUNCTION(Thread2, arg) {
  47. (void)arg;
  48. while (true) {
  49. chThdSleepMilliseconds(125);
  50. palSetPad(GPIOE, GPIOE_LED5_ORANGE);
  51. chThdSleepMilliseconds(125);
  52. palClearPad(GPIOE, GPIOE_LED5_ORANGE);
  53. chThdSleepMilliseconds(125);
  54. palSetPad(GPIOE, GPIOE_LED9_BLUE);
  55. chThdSleepMilliseconds(125);
  56. palClearPad(GPIOE, GPIOE_LED9_BLUE);
  57. chThdSleepMilliseconds(125);
  58. palSetPad(GPIOE, GPIOE_LED8_ORANGE);
  59. chThdSleepMilliseconds(125);
  60. palClearPad(GPIOE, GPIOE_LED8_ORANGE);
  61. chThdSleepMilliseconds(125);
  62. palSetPad(GPIOE, GPIOE_LED4_BLUE);
  63. chThdSleepMilliseconds(125);
  64. palClearPad(GPIOE, GPIOE_LED4_BLUE);
  65. }
  66. }
  67. /*
  68. * Tester thread.
  69. */
  70. THD_WORKING_AREA(waThread3, 256);
  71. THD_FUNCTION(Thread3, arg) {
  72. (void)arg;
  73. /*
  74. * Activates the serial driver 1 using the driver default configuration.
  75. * PA9 and PA10 are routed to USART1.
  76. */
  77. sdStart(&SD1, NULL);
  78. palSetPadMode(GPIOA, 9, PAL_MODE_ALTERNATE(7)); /* USART1 TX. */
  79. palSetPadMode(GPIOA, 10, PAL_MODE_ALTERNATE(7)); /* USART1 RX. */
  80. /* Welcome message.*/
  81. chnWrite(&SD1, (const uint8_t *)"Hello World!\r\n", 14);
  82. /* Waiting for button push and activation of the test suite.*/
  83. while (true) {
  84. if (palReadLine(LINE_BUTTON)) {
  85. test_execute((BaseSequentialStream *)&SD1, &nil_test_suite);
  86. test_execute((BaseSequentialStream *)&SD1, &oslib_test_suite);
  87. }
  88. chThdSleepMilliseconds(500);
  89. }
  90. }
  91. /*
  92. * Threads static table, one entry per thread. The number of entries must
  93. * match NIL_CFG_NUM_THREADS.
  94. */
  95. THD_TABLE_BEGIN
  96. THD_TABLE_ENTRY(waThread1, "blinker1", Thread1, NULL)
  97. THD_TABLE_ENTRY(waThread2, "blinker2", Thread2, NULL)
  98. THD_TABLE_ENTRY(wa_test_support, "test_support", test_support, (void *)&nil.threads[3])
  99. THD_TABLE_ENTRY(waThread3, "tester", Thread3, NULL)
  100. THD_TABLE_END
  101. /*
  102. * Application entry point.
  103. */
  104. int main(void) {
  105. /*
  106. * System initializations.
  107. * - HAL initialization, this also initializes the configured device drivers
  108. * and performs the board-specific initializations.
  109. * - Kernel initialization, the main() function becomes a thread and the
  110. * RTOS is active.
  111. */
  112. halInit();
  113. chSysInit();
  114. /* This is now the idle thread loop, you may perform here a low priority
  115. task but you must never try to sleep or wait in this loop. Note that
  116. this tasks runs at the lowest priority level so any instruction added
  117. here will be executed after all other tasks have been started.*/
  118. while (true) {
  119. }
  120. }