main.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 "chprintf.h"
  16. #include "shell.h"
  17. /*
  18. * Red LED blinker thread, times are in milliseconds.
  19. */
  20. static THD_WORKING_AREA(waThread1, 128);
  21. static THD_FUNCTION(Thread1, arg) {
  22. (void)arg;
  23. chRegSetThreadName("blinker1");
  24. while (true) {
  25. palSetPad(GPIOG, GPIOG_LED1);
  26. chThdSleepMilliseconds(50);
  27. palSetPad(GPIOD, GPIOD_LED2);
  28. chThdSleepMilliseconds(300);
  29. palClearPad(GPIOG, GPIOG_LED1);
  30. chThdSleepMilliseconds(50);
  31. palClearPad(GPIOD, GPIOD_LED2);
  32. chThdSleepMilliseconds(300);
  33. }
  34. }
  35. /*
  36. * Green LED blinker thread, times are in milliseconds.
  37. */
  38. static THD_WORKING_AREA(waThread2, 128);
  39. static THD_FUNCTION(Thread2, arg) {
  40. (void)arg;
  41. chRegSetThreadName("blinker2");
  42. while (true) {
  43. palSetPad(GPIOD, GPIOD_LED3);
  44. chThdSleepMilliseconds(50);
  45. palSetPad(GPIOK, GPIOK_LED4);
  46. chThdSleepMilliseconds(300);
  47. palClearPad(GPIOD, GPIOD_LED3);
  48. chThdSleepMilliseconds(50);
  49. palClearPad(GPIOK, GPIOK_LED4);
  50. chThdSleepMilliseconds(300);
  51. }
  52. }
  53. /*===========================================================================*/
  54. /* Command line related. */
  55. /*===========================================================================*/
  56. #define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(2048)
  57. static const ShellCommand commands[] = {
  58. {NULL, NULL}
  59. };
  60. static const ShellConfig shell_cfg1 = {
  61. (BaseSequentialStream *)&SD3,
  62. commands
  63. };
  64. /*===========================================================================*/
  65. /* Initialization and main thread. */
  66. /*===========================================================================*/
  67. /*
  68. * Application entry point.
  69. */
  70. int main(void) {
  71. /*
  72. * System initializations.
  73. * - HAL initialization, this also initializes the configured device drivers
  74. * and performs the board-specific initializations.
  75. * - Kernel initialization, the main() function becomes a thread and the
  76. * RTOS is active.
  77. */
  78. halInit();
  79. chSysInit();
  80. /*
  81. * Shell manager initialization.
  82. */
  83. shellInit();
  84. /*
  85. * Activates the serial driver 2 using the driver default configuration.
  86. */
  87. sdStart(&SD3, NULL);
  88. /*
  89. * Creating the blinker threads.
  90. */
  91. chThdCreateStatic(waThread1, sizeof(waThread1),
  92. NORMALPRIO + 10, Thread1, NULL);
  93. chThdSleepMilliseconds(100);
  94. chThdCreateStatic(waThread2, sizeof(waThread2),
  95. NORMALPRIO + 10, Thread2, NULL);
  96. /*
  97. * Normal main() thread activity, spawning shells.
  98. */
  99. while (true) {
  100. thread_t *shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE,
  101. "shell", NORMALPRIO + 1,
  102. shellThread, (void *)&shell_cfg1);
  103. chThdWait(shelltp); /* Waiting termination. */
  104. chThdSleepMilliseconds(1000);
  105. }
  106. }