aboutsummaryrefslogtreecommitdiff
path: root/lib/chibios/os/hal/boards/STUDIEL_AT91SAM7A3_EK/board.c
diff options
context:
space:
mode:
authorAkshay <[email protected]>2022-04-10 12:13:40 +0100
committerAkshay <[email protected]>2022-04-10 12:13:40 +0100
commitdc90387ce7d8ba7b607d9c48540bf6d8b560f14d (patch)
tree4ccb8fa5886b66fa9d480edef74236c27f035e16 /lib/chibios/os/hal/boards/STUDIEL_AT91SAM7A3_EK/board.c
Diffstat (limited to 'lib/chibios/os/hal/boards/STUDIEL_AT91SAM7A3_EK/board.c')
-rw-r--r--lib/chibios/os/hal/boards/STUDIEL_AT91SAM7A3_EK/board.c108
1 files changed, 108 insertions, 0 deletions
diff --git a/lib/chibios/os/hal/boards/STUDIEL_AT91SAM7A3_EK/board.c b/lib/chibios/os/hal/boards/STUDIEL_AT91SAM7A3_EK/board.c
new file mode 100644
index 000000000..68420d231
--- /dev/null
+++ b/lib/chibios/os/hal/boards/STUDIEL_AT91SAM7A3_EK/board.c
@@ -0,0 +1,108 @@
1/*
2 ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17#include "hal.h"
18
19/**
20 * @brief PAL setup.
21 * @details Digital I/O ports static configuration as defined in @p board.h.
22 * This variable is used by the HAL when initializing the PAL driver.
23 */
24#if HAL_USE_PAL || defined(__DOXYGEN__)
25const PALConfig pal_default_config =
26{
27 {VAL_PIOA_ODSR, VAL_PIOA_OSR, VAL_PIOA_PUSR},
28#if (SAM7_PLATFORM == SAM7X128) || (SAM7_PLATFORM == SAM7X256) || \
29 (SAM7_PLATFORM == SAM7X512) || (SAM7_PLATFORM == SAM7A3)
30 {VAL_PIOB_ODSR, VAL_PIOB_OSR, VAL_PIOB_PUSR}
31#endif
32};
33#endif
34
35/*
36 * SYS IRQ handling here.
37 */
38static CH_IRQ_HANDLER(SYSIrqHandler) {
39
40 CH_IRQ_PROLOGUE();
41
42 if (AT91C_BASE_PITC->PITC_PISR & AT91C_PITC_PITS) {
43 (void) AT91C_BASE_PITC->PITC_PIVR;
44 chSysLockFromIsr();
45 chSysTimerHandlerI();
46 chSysUnlockFromIsr();
47 }
48
49#if USE_SAM7_DBGU_UART
50 if (AT91C_BASE_DBGU->DBGU_CSR &
51 (AT91C_US_RXRDY | AT91C_US_TXRDY | AT91C_US_PARE | AT91C_US_FRAME | AT91C_US_OVRE | AT91C_US_RXBRK)) {
52 sd_lld_serve_interrupt(&SDDBG);
53 }
54#endif
55 AT91C_BASE_AIC->AIC_EOICR = 0;
56 CH_IRQ_EPILOGUE();
57}
58
59/*
60 * Early initialization code.
61 * This initialization must be performed just after stack setup and before
62 * any other initialization.
63 */
64void __early_init(void) {
65
66 /* Watchdog disabled.*/
67 AT91C_BASE_WDTC->WDTC_WDMR = AT91C_WDTC_WDDIS;
68
69 at91sam7_clock_init();
70}
71
72#if HAL_USE_MMC_SPI
73/* Board-related functions related to the MMC_SPI driver.*/
74bool mmc_lld_is_card_inserted(MMCDriver *mmcp) {
75
76 (void)mmcp;
77 return !palReadPad(IOPORT2, PIOB_MMC_CP);
78}
79
80bool mmc_lld_is_write_protected(MMCDriver *mmcp) {
81
82 (void)mmcp;
83 return palReadPad(IOPORT2, PIOB_MMC_WP);
84}
85#endif
86
87/*
88 * Board-specific initialization code.
89 */
90void boardInit(void) {
91
92 /*
93 * PIT Initialization.
94 */
95 AIC_ConfigureIT(AT91C_ID_SYS,
96 AT91C_AIC_SRCTYPE_HIGH_LEVEL | (AT91C_AIC_PRIOR_HIGHEST - 1),
97 SYSIrqHandler);
98 AIC_EnableIT(AT91C_ID_SYS);
99 AT91C_BASE_PITC->PITC_PIMR = (MCK / 16 / CH_FREQUENCY) - 1;
100 AT91C_BASE_PITC->PITC_PIMR |= AT91C_PITC_PITEN | AT91C_PITC_PITIEN;
101
102 /*
103 * RTS/CTS pins enabled for USART0 only.
104 */
105 AT91C_BASE_PIOA->PIO_PDR = AT91C_PA3_RTS0 | AT91C_PA4_CTS0;
106 AT91C_BASE_PIOA->PIO_ASR = AT91C_PIO_PA3 | AT91C_PIO_PA4;
107 AT91C_BASE_PIOA->PIO_PPUDR = AT91C_PIO_PA3 | AT91C_PIO_PA4;
108}