diff options
Diffstat (limited to 'lib/chibios/os/hal/boards/OLIMEX_SAM7_EX256/board.c')
-rw-r--r-- | lib/chibios/os/hal/boards/OLIMEX_SAM7_EX256/board.c | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/lib/chibios/os/hal/boards/OLIMEX_SAM7_EX256/board.c b/lib/chibios/os/hal/boards/OLIMEX_SAM7_EX256/board.c new file mode 100644 index 000000000..21ca13149 --- /dev/null +++ b/lib/chibios/os/hal/boards/OLIMEX_SAM7_EX256/board.c | |||
@@ -0,0 +1,136 @@ | |||
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__) | ||
25 | const 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 | */ | ||
38 | static 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 | | ||
52 | AT91C_US_OVRE | AT91C_US_RXBRK)) { | ||
53 | sd_lld_serve_interrupt(&SDDBG); | ||
54 | } | ||
55 | #endif | ||
56 | AT91C_BASE_AIC->AIC_EOICR = 0; | ||
57 | CH_IRQ_EPILOGUE(); | ||
58 | } | ||
59 | |||
60 | /* | ||
61 | * Early initialization code. | ||
62 | * This initialization must be performed just after stack setup and before | ||
63 | * any other initialization. | ||
64 | */ | ||
65 | void __early_init(void) { | ||
66 | |||
67 | /* Watchdog disabled.*/ | ||
68 | AT91C_BASE_WDTC->WDTC_WDMR = AT91C_WDTC_WDDIS; | ||
69 | |||
70 | at91sam7_clock_init(); | ||
71 | } | ||
72 | |||
73 | #if HAL_USE_MMC_SPI | ||
74 | /* Board-related functions related to the MMC_SPI driver.*/ | ||
75 | bool mmc_lld_is_card_inserted(MMCDriver *mmcp) { | ||
76 | |||
77 | (void)mmcp; | ||
78 | return !palReadPad(IOPORT2, PIOB_MMC_CP); | ||
79 | } | ||
80 | |||
81 | bool mmc_lld_is_write_protected(MMCDriver *mmcp) { | ||
82 | |||
83 | (void)mmcp; | ||
84 | return palReadPad(IOPORT2, PIOB_MMC_WP); | ||
85 | } | ||
86 | #endif | ||
87 | |||
88 | /* | ||
89 | * Board-specific initialization code. | ||
90 | */ | ||
91 | void boardInit(void) { | ||
92 | |||
93 | /* | ||
94 | * LCD pins setup. | ||
95 | */ | ||
96 | palClearPad(IOPORT2, PIOB_LCD_BL); | ||
97 | palSetPadMode(IOPORT2, PIOB_LCD_BL, PAL_MODE_OUTPUT_PUSHPULL); | ||
98 | |||
99 | palSetPad(IOPORT1, PIOA_LCD_RESET); | ||
100 | palSetPadMode(IOPORT1, PIOA_LCD_RESET, PAL_MODE_OUTPUT_PUSHPULL); | ||
101 | |||
102 | /* | ||
103 | * Joystick and buttons setup. | ||
104 | */ | ||
105 | palSetGroupMode(IOPORT1, | ||
106 | PIOA_B1_MASK | PIOA_B2_MASK | PIOA_B3_MASK | | ||
107 | PIOA_B4_MASK | PIOA_B5_MASK, | ||
108 | 0, | ||
109 | PAL_MODE_INPUT); | ||
110 | palSetGroupMode(IOPORT2, PIOB_SW1_MASK | PIOB_SW2_MASK, 0, PAL_MODE_INPUT); | ||
111 | |||
112 | /* | ||
113 | * MMC/SD slot setup. | ||
114 | */ | ||
115 | palSetGroupMode(IOPORT2, | ||
116 | PIOB_MMC_WP_MASK | PIOB_MMC_CP_MASK, | ||
117 | 0, | ||
118 | PAL_MODE_INPUT); | ||
119 | |||
120 | /* | ||
121 | * PIT Initialization. | ||
122 | */ | ||
123 | AIC_ConfigureIT(AT91C_ID_SYS, | ||
124 | AT91C_AIC_SRCTYPE_HIGH_LEVEL | (AT91C_AIC_PRIOR_HIGHEST - 1), | ||
125 | SYSIrqHandler); | ||
126 | AIC_EnableIT(AT91C_ID_SYS); | ||
127 | AT91C_BASE_PITC->PITC_PIMR = (MCK / 16 / CH_FREQUENCY) - 1; | ||
128 | AT91C_BASE_PITC->PITC_PIMR |= AT91C_PITC_PITEN | AT91C_PITC_PITIEN; | ||
129 | |||
130 | /* | ||
131 | * RTS/CTS pins enabled for USART0 only. | ||
132 | */ | ||
133 | AT91C_BASE_PIOA->PIO_PDR = AT91C_PA3_RTS0 | AT91C_PA4_CTS0; | ||
134 | AT91C_BASE_PIOA->PIO_ASR = AT91C_PIO_PA3 | AT91C_PIO_PA4; | ||
135 | AT91C_BASE_PIOA->PIO_PPUDR = AT91C_PIO_PA3 | AT91C_PIO_PA4; | ||
136 | } | ||