main.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. * LED blinker thread, times are in milliseconds.
  19. */
  20. static THD_WORKING_AREA(waThread1, 512);
  21. static THD_FUNCTION(Thread1, arg) {
  22. (void)arg;
  23. chRegSetThreadName("blinker");
  24. while (true) {
  25. palToggleLine(LINE_LED_BLUE);
  26. chThdSleepMilliseconds(80);
  27. palToggleLine(LINE_LED_BLUE);
  28. chThdSleepMilliseconds(120);
  29. palToggleLine(LINE_LED_BLUE);
  30. chThdSleepMilliseconds(120);
  31. palToggleLine(LINE_LED_BLUE);
  32. chThdSleepMilliseconds(120);
  33. palToggleLine(LINE_LED_BLUE);
  34. chThdSleepMilliseconds(160);
  35. palToggleLine(LINE_LED_BLUE);
  36. chThdSleepMilliseconds(600);
  37. }
  38. }
  39. static const SerialConfig sdcfg = {
  40. 115200,
  41. 0,
  42. UART_MR_PAR_NO
  43. };
  44. /*
  45. * Application entry point.
  46. */
  47. int main(void) {
  48. /*
  49. * System initializations.
  50. * - HAL initialization, this also initializes the configured device drivers
  51. * and performs the board-specific initializations.
  52. * - Kernel initialization, the main() function becomes a thread and the
  53. * RTOS is active.
  54. */
  55. halInit();
  56. chSysInit();
  57. /*
  58. * Activates the serial driver 1 using the driver default configuration.
  59. */
  60. sdStart(&SD1, &sdcfg);
  61. /*
  62. * Creates the blinker thread.
  63. */
  64. chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
  65. /*
  66. * Normal main() thread activity, in this demo it does nothing except
  67. * sleeping in a loop and check the button state.
  68. */
  69. while (true) {
  70. if(!palReadPad(PIOB, PIOB_USER_PB)) {
  71. test_execute((BaseSequentialStream *)&SD1, &rt_test_suite);
  72. test_execute((BaseSequentialStream *)&SD1, &oslib_test_suite);
  73. }
  74. chThdSleepMilliseconds(500);
  75. }
  76. }