main.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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 "nil_test_root.h"
  16. #include "oslib_test_root.h"
  17. /*
  18. * LEDs blinker thread, times are in milliseconds.
  19. */
  20. static THD_WORKING_AREA(waThread1, 128);
  21. static THD_FUNCTION(Thread1, arg) {
  22. (void)arg;
  23. /*
  24. * Activates the serial driver 1 using the driver default configuration.
  25. */
  26. sdStart(&SD1, NULL);
  27. while (true) {
  28. unsigned i;
  29. for (i = 0; i < 4; i++) {
  30. palClearPad(PORT_E, PE_LED1);
  31. chThdSleepMilliseconds(100);
  32. palClearPad(PORT_E, PE_LED2);
  33. chThdSleepMilliseconds(100);
  34. palClearPad(PORT_E, PE_LED3);
  35. chThdSleepMilliseconds(100);
  36. palClearPad(PORT_E, PE_LED4);
  37. chThdSleepMilliseconds(100);
  38. palSetPad(PORT_E, PE_LED1);
  39. chThdSleepMilliseconds(100);
  40. palSetPad(PORT_E, PE_LED2);
  41. chThdSleepMilliseconds(100);
  42. palSetPad(PORT_E, PE_LED3);
  43. chThdSleepMilliseconds(100);
  44. palSetPad(PORT_E, PE_LED4);
  45. chThdSleepMilliseconds(300);
  46. }
  47. for (i = 0; i < 4; i++) {
  48. palTogglePort(PORT_E, PAL_PORT_BIT(PE_LED1) | PAL_PORT_BIT(PE_LED2) |
  49. PAL_PORT_BIT(PE_LED3) | PAL_PORT_BIT(PE_LED4));
  50. chThdSleepMilliseconds(500);
  51. palTogglePort(PORT_E, PAL_PORT_BIT(PE_LED1) | PAL_PORT_BIT(PE_LED2) |
  52. PAL_PORT_BIT(PE_LED3) | PAL_PORT_BIT(PE_LED4));
  53. chThdSleepMilliseconds(500);
  54. }
  55. for (i = 0; i < 4; i++) {
  56. palTogglePad(PORT_E, PE_LED1);
  57. chThdSleepMilliseconds(250);
  58. palTogglePad(PORT_E, PE_LED1);
  59. palTogglePad(PORT_E, PE_LED2);
  60. chThdSleepMilliseconds(250);
  61. palTogglePad(PORT_E, PE_LED2);
  62. palTogglePad(PORT_E, PE_LED3);
  63. chThdSleepMilliseconds(250);
  64. palTogglePad(PORT_E, PE_LED3);
  65. palTogglePad(PORT_E, PE_LED4);
  66. chThdSleepMilliseconds(250);
  67. palTogglePad(PORT_E, PE_LED4);
  68. }
  69. for (i = 0; i < 4; i++) {
  70. palClearPort(PORT_E, PAL_PORT_BIT(PE_LED1) | PAL_PORT_BIT(PE_LED3));
  71. palSetPort(PORT_E, PAL_PORT_BIT(PE_LED2) | PAL_PORT_BIT(PE_LED4));
  72. chThdSleepMilliseconds(500);
  73. palClearPort(PORT_E, PAL_PORT_BIT(PE_LED2) | PAL_PORT_BIT(PE_LED4));
  74. palSetPort(PORT_E, PAL_PORT_BIT(PE_LED1) | PAL_PORT_BIT(PE_LED3));
  75. chThdSleepMilliseconds(500);
  76. }
  77. palSetPort(PORT_E, PAL_PORT_BIT(PE_LED1) | PAL_PORT_BIT(PE_LED2) |
  78. PAL_PORT_BIT(PE_LED3) | PAL_PORT_BIT(PE_LED4));
  79. }
  80. }
  81. /*
  82. * Tester thread.
  83. */
  84. THD_WORKING_AREA(waThread2, 128);
  85. THD_FUNCTION(Thread2, arg) {
  86. (void)arg;
  87. /*
  88. * Activates the serial driver 1 using the driver default configuration.
  89. */
  90. sdStart(&SD1, NULL);
  91. /* Welcome message.*/
  92. chnWriteTimeout(&SD1, (uint8_t *)"Hello World!\r\n", 14, TIME_INFINITE);
  93. /* Waiting for button push and activation of the test suite.*/
  94. while (true) {
  95. if (palReadPad(PORT_E, PE_BUTTON1)) {
  96. test_execute((BaseSequentialStream *)&SD1, &nil_test_suite);
  97. test_execute((BaseSequentialStream *)&SD1, &oslib_test_suite);
  98. }
  99. chThdSleepMilliseconds(500);
  100. }
  101. }
  102. /*
  103. * Threads static table, one entry per thread. The number of entries must
  104. * match NIL_CFG_NUM_THREADS.
  105. */
  106. THD_TABLE_BEGIN
  107. THD_TABLE_ENTRY(waThread1, "blinker", Thread1, NULL)
  108. THD_TABLE_ENTRY(wa_test_support, "test_support", test_support, (void *)&nil.threads[2])
  109. THD_TABLE_ENTRY(waThread2, "tester", Thread2, NULL)
  110. THD_TABLE_END
  111. /*
  112. * Application entry point.
  113. */
  114. int main(void) {
  115. /*
  116. * System initializations.
  117. * - HAL initialization, this also initializes the configured device drivers
  118. * and performs the board-specific initializations.
  119. * - Kernel initialization, the main() function becomes a thread and the
  120. * RTOS is active.
  121. */
  122. halInit();
  123. chSysInit();
  124. /* This is now the idle thread loop, you may perform here a low priority
  125. task but you must never try to sleep or wait in this loop. Note that
  126. this tasks runs at the lowest priority level so any instruction added
  127. here will be executed after all other tasks have been started.*/
  128. while (true) {
  129. }
  130. }