aboutsummaryrefslogtreecommitdiff
path: root/lib/chibios/os/hal/boards/OLIMEX_SAM7_P256/board.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chibios/os/hal/boards/OLIMEX_SAM7_P256/board.c')
-rw-r--r--lib/chibios/os/hal/boards/OLIMEX_SAM7_P256/board.c116
1 files changed, 116 insertions, 0 deletions
diff --git a/lib/chibios/os/hal/boards/OLIMEX_SAM7_P256/board.c b/lib/chibios/os/hal/boards/OLIMEX_SAM7_P256/board.c
new file mode 100644
index 000000000..43d37472d
--- /dev/null
+++ b/lib/chibios/os/hal/boards/OLIMEX_SAM7_P256/board.c
@@ -0,0 +1,116 @@
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 AT91C_BASE_AIC->AIC_EOICR = 0;
49
50 CH_IRQ_EPILOGUE();
51}
52
53/*
54 * Early initialization code.
55 * This initialization must be performed just after stack setup and before
56 * any other initialization.
57 */
58void __early_init(void) {
59
60 /* Watchdog disabled.*/
61 AT91C_BASE_WDTC->WDTC_WDMR = AT91C_WDTC_WDDIS;
62
63 at91sam7_clock_init();
64}
65
66#if HAL_USE_MMC_SPI
67/* Board-related functions related to the MMC_SPI driver.*/
68bool mmc_lld_is_card_inserted(MMCDriver *mmcp) {
69
70 (void)mmcp;
71 return !palReadPad(IOPORT1, PIOA_MMC_CP);
72}
73
74bool mmc_lld_is_write_protected(MMCDriver *mmcp) {
75
76 (void)mmcp;
77 return palReadPad(IOPORT1, PIOA_MMC_WP);
78}
79#endif
80
81/*
82 * Board-specific initialization code.
83 */
84void boardInit(void) {
85
86 /*
87 * LED pins setup.
88 */
89 palClearPad(IOPORT1, PIOA_LED1);
90 palSetPadMode(IOPORT1, PIOA_LED1, PAL_MODE_OUTPUT_PUSHPULL);
91 palClearPad(IOPORT1, PIOA_LED2);
92 palSetPadMode(IOPORT1, PIOA_LED2, PAL_MODE_OUTPUT_PUSHPULL);
93
94 /*
95 * buttons setup.
96 */
97 palSetGroupMode(IOPORT1, PIOA_B1_MASK | PIOA_B2_MASK, 0, PAL_MODE_INPUT);
98
99 /*
100 * MMC/SD slot setup.
101 */
102 palSetGroupMode(IOPORT1,
103 PIOA_MMC_WP_MASK | PIOA_MMC_CP_MASK,
104 0,
105 PAL_MODE_INPUT);
106
107 /*
108 * PIT Initialization.
109 */
110 AIC_ConfigureIT(AT91C_ID_SYS,
111 AT91C_AIC_SRCTYPE_HIGH_LEVEL | (AT91C_AIC_PRIOR_HIGHEST - 1),
112 SYSIrqHandler);
113 AIC_EnableIT(AT91C_ID_SYS);
114 AT91C_BASE_PITC->PITC_PIMR = (MCK / 16 / CH_FREQUENCY) - 1;
115 AT91C_BASE_PITC->PITC_PIMR |= AT91C_PITC_PITEN | AT91C_PITC_PITIEN;
116}