board.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. /**
  15. * @brief PAL setup.
  16. * @details Digital I/O ports static configuration as defined in @p board.h.
  17. * This variable is used by the HAL when initializing the PAL driver.
  18. */
  19. #if HAL_USE_PAL || defined(__DOXYGEN__)
  20. const PALConfig pal_default_config =
  21. {
  22. #if defined(PORTA)
  23. {VAL_PORTA, VAL_DDRA},
  24. #endif
  25. #if defined(PORTB)
  26. {VAL_PORTB, VAL_DDRB},
  27. #endif
  28. #if defined(PORTC)
  29. {VAL_PORTC, VAL_DDRC},
  30. #endif
  31. #if defined(PORTD)
  32. {VAL_PORTD, VAL_DDRD},
  33. #endif
  34. #if defined(PORTE)
  35. {VAL_PORTE, VAL_DDRE},
  36. #endif
  37. #if defined(PORTF)
  38. {VAL_PORTF, VAL_DDRF},
  39. #endif
  40. #if defined(PORTG)
  41. {VAL_PORTG, VAL_DDRG},
  42. #endif
  43. };
  44. #endif /* HAL_USE_PAL */
  45. CH_IRQ_HANDLER(TIMER0_COMP_vect) {
  46. CH_IRQ_PROLOGUE();
  47. chSysLockFromIsr();
  48. chSysTimerHandlerI();
  49. chSysUnlockFromIsr();
  50. CH_IRQ_EPILOGUE();
  51. }
  52. /*
  53. * Board-specific initialization code.
  54. */
  55. void boardInit(void) {
  56. /*
  57. * External interrupts setup, all disabled initially.
  58. */
  59. EICRA = 0x00;
  60. EICRB = 0x00;
  61. EIMSK = 0x00;
  62. /*
  63. * Enables Idle mode for SLEEP instruction.
  64. */
  65. SMCR = (1 << SE);
  66. /*
  67. * Timer 0 setup.
  68. */
  69. TCCR0A = (1 << WGM01) | (0 << WGM00) | /* CTC mode. */
  70. (0 << COM0A1) | (0 << COM0A0) | /* OC0A disabled. */
  71. (0 << CS02) | (1 << CS01) | (1 << CS00); /* CLK/64 clock. */
  72. OCR0A = F_CPU / 64 / CH_FREQUENCY - 1;
  73. TCNT0 = 0; /* Reset counter. */
  74. TIFR0 = (1 << OCF0A); /* Reset pending. */
  75. TIMSK0 = (1 << OCIE0A); /* IRQ on compare. */
  76. }