main.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. ChibiOS - Copyright (C) 2017 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. /*
  16. * UART 1 configuration structure.
  17. */
  18. const UARTConfig uartConf = {
  19. NULL, /* UART transmission buffer callback. */
  20. NULL, /* UART physical end of transmission callback. */
  21. NULL, /* UART Receiver receiver filled callback. */
  22. NULL, /* UART caracter received callback. */
  23. NULL, /* UART received error callback. */
  24. 38400, /* UART baudrate. */
  25. };
  26. /*
  27. * LED blinker thread, times are in milliseconds.
  28. */
  29. static THD_WORKING_AREA(waThread1, 32);
  30. static THD_FUNCTION(Thread1, arg) {
  31. (void)arg;
  32. chRegSetThreadName("Blinker");
  33. while (true) {
  34. palTogglePad(IOPORT2, PORTB_LED1);
  35. uartStartSend(&UARTD1, 30, (const void *) "ChibiOS PORT on ATtiny-167!.\n\r");
  36. chThdSleepMilliseconds(1000);
  37. }
  38. }
  39. /*
  40. * Application entry point.
  41. */
  42. int main(void) {
  43. /*
  44. * System initializations.
  45. * - HAL initialization, this also initializes the configured device drivers
  46. * and performs the board-specific initializations.
  47. * - Kernel initialization, the main() function becomes a thread and the
  48. * RTOS is active.
  49. */
  50. halInit();
  51. chSysInit();
  52. /*
  53. * Initialize the UART interface.
  54. */
  55. uartInit();
  56. /*
  57. * Start the Uart 1 interface.
  58. */
  59. uartStart(&UARTD1, &uartConf);
  60. /*
  61. * Send an message via the UART 1 interface.
  62. */
  63. uartStartSend(&UARTD1, 15, (const void *) "Hello world!.\n\r");
  64. /*
  65. * Starts the LED blinker thread.
  66. */
  67. chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
  68. while (true) {
  69. chThdSleepMilliseconds(1000);
  70. }
  71. }