board.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. AT91C_BASE_AIC->AIC_EOICR = 0;
  41. CH_IRQ_EPILOGUE();
  42. }
  43. /*
  44. * Early initialization code.
  45. * This initialization must be performed just after stack setup and before
  46. * any other initialization.
  47. */
  48. void __early_init(void) {
  49. /* Watchdog disabled.*/
  50. AT91C_BASE_WDTC->WDTC_WDMR = AT91C_WDTC_WDDIS;
  51. at91sam7_clock_init();
  52. }
  53. #if HAL_USE_MMC_SPI
  54. /* Board-related functions related to the MMC_SPI driver.*/
  55. bool mmc_lld_is_card_inserted(MMCDriver *mmcp) {
  56. (void)mmcp;
  57. return !palReadPad(IOPORT1, PIOA_MMC_CP);
  58. }
  59. bool mmc_lld_is_write_protected(MMCDriver *mmcp) {
  60. (void)mmcp;
  61. return palReadPad(IOPORT1, PIOA_MMC_WP);
  62. }
  63. #endif
  64. /*
  65. * Board-specific initialization code.
  66. */
  67. void boardInit(void) {
  68. /*
  69. * LED pins setup.
  70. */
  71. palClearPad(IOPORT1, PIOA_LED1);
  72. palSetPadMode(IOPORT1, PIOA_LED1, PAL_MODE_OUTPUT_PUSHPULL);
  73. palClearPad(IOPORT1, PIOA_LED2);
  74. palSetPadMode(IOPORT1, PIOA_LED2, PAL_MODE_OUTPUT_PUSHPULL);
  75. /*
  76. * buttons setup.
  77. */
  78. palSetGroupMode(IOPORT1, PIOA_B1_MASK | PIOA_B2_MASK, 0, PAL_MODE_INPUT);
  79. /*
  80. * MMC/SD slot setup.
  81. */
  82. palSetGroupMode(IOPORT1,
  83. PIOA_MMC_WP_MASK | PIOA_MMC_CP_MASK,
  84. 0,
  85. PAL_MODE_INPUT);
  86. /*
  87. * PIT Initialization.
  88. */
  89. AIC_ConfigureIT(AT91C_ID_SYS,
  90. AT91C_AIC_SRCTYPE_HIGH_LEVEL | (AT91C_AIC_PRIOR_HIGHEST - 1),
  91. SYSIrqHandler);
  92. AIC_EnableIT(AT91C_ID_SYS);
  93. AT91C_BASE_PITC->PITC_PIMR = (MCK / 16 / CH_FREQUENCY) - 1;
  94. AT91C_BASE_PITC->PITC_PIMR |= AT91C_PITC_PITEN | AT91C_PITC_PITIEN;
  95. }