main.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. ChibiOS - Copyright (C) 2016..2018 Theodore Ateba
  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. BaseSequentialStream *chp = (BaseSequentialStream *) &SD1;
  17. uint16_t cpt = 0; /* Counter for serial print. */
  18. /**
  19. * @brief Blink thread.
  20. */
  21. static THD_WORKING_AREA(waThread1, 32);
  22. static THD_FUNCTION(Thread1, arg) {
  23. (void)arg;
  24. chRegSetThreadName("Blinker");
  25. while (true) {
  26. palClearPad(IOPORT5, PORTE_LED);
  27. chThdSleepMilliseconds(1000);
  28. palSetPad(IOPORT5, PORTE_LED);
  29. chThdSleepMilliseconds(100);
  30. }
  31. }
  32. /*
  33. * Application entry point.
  34. */
  35. int main(void) {
  36. /*
  37. * System initializations.
  38. * - HAL initialization, this also initializes the configured device drivers
  39. * and performs the board-specific initializations.
  40. * - Kernel initialization, the main() function becomes a thread and the
  41. * RTOS is active.
  42. */
  43. halInit();
  44. chSysInit();
  45. palClearPad(IOPORT5, PORTE_LED);
  46. /*
  47. * Configure TX (PINC3) and RX (PIN2) for the USART1.
  48. */
  49. palSetPadMode(IOPORT3, PIN3, PAL_MODE_OUTPUT_PUSHPULL);
  50. palSetPadMode(IOPORT3, PIN2, PAL_MODE_INPUT_PULLUP);
  51. /*
  52. * Start the Serial driver 1 by using the default configuration.
  53. */
  54. sdStart(&SD1, NULL);
  55. /*
  56. * Starts the LED blinker thread.
  57. */
  58. chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
  59. while(TRUE) {
  60. chprintf(chp, "Hello world %i.\r\n", cpt++);
  61. chThdSleepMilliseconds(100);
  62. }
  63. return 0;
  64. }