main.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 "nasa_osal_test_root.h"
  15. #include "osapi.h"
  16. /*
  17. * This is a periodic thread that does absolutely nothing except flashing
  18. * a LED.
  19. * Note, the working area is created using ChibiOS/RT macro because alignment
  20. * constraints.
  21. */
  22. static THD_WORKING_AREA(wa_blinker, 128);
  23. static void blinker(void) {
  24. OS_TaskRegister();
  25. while (true) {
  26. palSetLine(LINE_LED3); /* Orange. */
  27. OS_TaskDelay(500);
  28. palClearLine(LINE_LED3); /* Orange. */
  29. OS_TaskDelay(500);
  30. }
  31. }
  32. /*
  33. * Application entry point.
  34. */
  35. int main(void) {
  36. uint32 blinker_id;
  37. /* HAL initialization, this also initializes the configured device drivers
  38. and performs the board-specific initializations.*/
  39. halInit();
  40. /* OS initialization.*/
  41. (void) OS_API_Init();
  42. /* Activates the serial driver 2 using the driver default configuration.
  43. PA2(TX) and PA3(RX) are routed to USART2.*/
  44. sdStart(&SD2, NULL);
  45. palSetPadMode(GPIOA, 2, PAL_MODE_ALTERNATE(7));
  46. palSetPadMode(GPIOA, 3, PAL_MODE_ALTERNATE(7));
  47. /* Starting the blinker thread.*/
  48. (void) OS_TaskCreate(&blinker_id, "blinker", blinker,
  49. (uint32 *)wa_blinker, sizeof wa_blinker,
  50. 128, 0);
  51. /* In the ChibiOS/RT OSAL implementation the main() function is an
  52. usable thread with priority 128 (NORMALPRIO), here we just sleep
  53. waiting for a button event, then the test suite is executed.*/
  54. while (true) {
  55. if (palReadLine(LINE_BUTTON))
  56. test_execute((BaseSequentialStream *)&SD2, &nasa_osal_test_suite);
  57. OS_TaskDelay(500);
  58. }
  59. }