main.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. /*
  16. * Thread 1.
  17. */
  18. THD_WORKING_AREA(waThread1, 128);
  19. THD_FUNCTION(Thread1, arg) {
  20. (void)arg;
  21. while (true) {
  22. palSetPad(GPIOB, GPIOB_LED_GREEN);
  23. chThdSleepMilliseconds(250);
  24. palClearPad(GPIOB, GPIOB_LED_GREEN);
  25. chThdSleepMilliseconds(250);
  26. }
  27. }
  28. /*
  29. * Thread 2.
  30. */
  31. THD_WORKING_AREA(waThread2, 128);
  32. THD_FUNCTION(Thread2, arg) {
  33. (void)arg;
  34. sdStart(&SD2, NULL);
  35. while (true) {
  36. chnWrite(&SD2, (const uint8_t *)"Hello World!\r\n", 14);
  37. chThdSleepMilliseconds(2000);
  38. }
  39. }
  40. /*
  41. * Threads static table, one entry per thread. The number of entries must
  42. * match NIL_CFG_NUM_THREADS.
  43. */
  44. THD_TABLE_BEGIN
  45. THD_TABLE_ENTRY(waThread1, "blinker", Thread1, NULL)
  46. THD_TABLE_ENTRY(waThread2, "hello", Thread2, NULL)
  47. THD_TABLE_END
  48. /*
  49. * Application entry point.
  50. */
  51. int main(void) {
  52. /*
  53. * System initializations.
  54. * - HAL initialization, this also initializes the configured device drivers
  55. * and performs the board-specific initializations.
  56. * - Kernel initialization, the main() function becomes a thread and the
  57. * RTOS is active.
  58. */
  59. halInit();
  60. chSysInit();
  61. /* This is now the idle thread loop, you may perform here a low priority
  62. task but you must never try to sleep or wait in this loop. Note that
  63. this tasks runs at the lowest priority level so any instruction added
  64. here will be executed after all other tasks have been started.*/
  65. while (true) {
  66. }
  67. }