board.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. {VAL_PIOA_ODSR, VAL_PIOA_OSR, VAL_PIOA_PUSR},
  23. #if (SAM7_PLATFORM == SAM7X128) || (SAM7_PLATFORM == SAM7X256) || \
  24. (SAM7_PLATFORM == SAM7X512) || (SAM7_PLATFORM == SAM7A3)
  25. {VAL_PIOB_ODSR, VAL_PIOB_OSR, VAL_PIOB_PUSR}
  26. #endif
  27. };
  28. #endif
  29. /*
  30. * SYS IRQ handling here.
  31. */
  32. static CH_IRQ_HANDLER(SYSIrqHandler) {
  33. CH_IRQ_PROLOGUE();
  34. if (AT91C_BASE_PITC->PITC_PISR & AT91C_PITC_PITS) {
  35. (void) AT91C_BASE_PITC->PITC_PIVR;
  36. chSysLockFromIsr();
  37. chSysTimerHandlerI();
  38. chSysUnlockFromIsr();
  39. }
  40. #if USE_SAM7_DBGU_UART
  41. if (AT91C_BASE_DBGU->DBGU_CSR &
  42. (AT91C_US_RXRDY | AT91C_US_TXRDY | AT91C_US_PARE | AT91C_US_FRAME | AT91C_US_OVRE | AT91C_US_RXBRK)) {
  43. sd_lld_serve_interrupt(&SDDBG);
  44. }
  45. #endif
  46. AT91C_BASE_AIC->AIC_EOICR = 0;
  47. CH_IRQ_EPILOGUE();
  48. }
  49. /*
  50. * Early initialization code.
  51. * This initialization must be performed just after stack setup and before
  52. * any other initialization.
  53. */
  54. void __early_init(void) {
  55. /* Watchdog disabled.*/
  56. AT91C_BASE_WDTC->WDTC_WDMR = AT91C_WDTC_WDDIS;
  57. at91sam7_clock_init();
  58. }
  59. #if HAL_USE_MMC_SPI
  60. /* Board-related functions related to the MMC_SPI driver.*/
  61. bool mmc_lld_is_card_inserted(MMCDriver *mmcp) {
  62. (void)mmcp;
  63. return !palReadPad(IOPORT2, PIOB_MMC_CP);
  64. }
  65. bool mmc_lld_is_write_protected(MMCDriver *mmcp) {
  66. (void)mmcp;
  67. return palReadPad(IOPORT2, PIOB_MMC_WP);
  68. }
  69. #endif
  70. /*
  71. * Board-specific initialization code.
  72. */
  73. void boardInit(void) {
  74. /*
  75. * PIT Initialization.
  76. */
  77. AIC_ConfigureIT(AT91C_ID_SYS,
  78. AT91C_AIC_SRCTYPE_HIGH_LEVEL | (AT91C_AIC_PRIOR_HIGHEST - 1),
  79. SYSIrqHandler);
  80. AIC_EnableIT(AT91C_ID_SYS);
  81. AT91C_BASE_PITC->PITC_PIMR = (MCK / 16 / CH_FREQUENCY) - 1;
  82. AT91C_BASE_PITC->PITC_PIMR |= AT91C_PITC_PITEN | AT91C_PITC_PITIEN;
  83. /*
  84. * RTS/CTS pins enabled for USART0 only.
  85. */
  86. AT91C_BASE_PIOA->PIO_PDR = AT91C_PA3_RTS0 | AT91C_PA4_CTS0;
  87. AT91C_BASE_PIOA->PIO_ASR = AT91C_PIO_PA3 | AT91C_PIO_PA4;
  88. AT91C_BASE_PIOA->PIO_PPUDR = AT91C_PIO_PA3 | AT91C_PIO_PA4;
  89. }