main.c 3.0 KB

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