3 * Copyright 2007,2008 Free Software Foundation, Inc.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 // conditionalized on HAL_IO_USES_DBOARD_PINS && HAL_IO_USES_UART
22 #include "memory_map.h"
30 * ========================================================================
32 * ========================================================================
35 hal_gpio_set_ddr(int bank, int value, int mask)
39 if (bank == GPIO_TX_BANK){ // tx in top half
48 int ei = hal_disable_ints();
49 gpio_base->ddr = (gpio_base->ddr & ~mask) | (value & mask);
54 code_to_int(char code, int *val)
57 case 's': *val = GPIO_SEL_SW; return true;
58 case 'a': *val = GPIO_SEL_ATR; return true;
59 case '0': *val = GPIO_SEL_DEBUG_0; return true;
60 case '1': *val = GPIO_SEL_DEBUG_1; return true;
68 hal_gpio_set_sel(int bank, int bitno, char code)
73 if (!code_to_int(code, &t))
76 int val = t << (2 * bitno);
77 int mask = 0x3 << (2 * bitno);
79 volatile uint32_t *sel = bank == GPIO_TX_BANK ? &gpio_base->tx_sel : &gpio_base->rx_sel;
80 int ei = hal_disable_ints();
81 int v = (*sel & ~mask) | (val & mask);
86 printf("hal_gpio_set_sel(bank=%d, bitno=%d, code=%c) *sel = 0x%x\n",
87 bank, bitno, code, v);
91 hal_gpio_set_sels(int bank, char *codes)
93 //assert(strlen(codes) == 16);
99 for (i = 15; i >= 0; i--){
103 if (code_to_int(codes[i], &t)){
109 volatile uint32_t *sel = bank == GPIO_TX_BANK ? &gpio_base->tx_sel : &gpio_base->rx_sel;
110 int ei = hal_disable_ints();
111 *sel = (*sel & ~mask) | (val & mask);
112 hal_restore_ints(ei);
117 * \brief write \p value to gpio pins specified by \p mask.
120 hal_gpio_write(int bank, int value, int mask)
122 static uint32_t _gpio_io_shadow;
126 if (bank == GPIO_TX_BANK){ // tx in top half
135 //int ei = hal_disable_ints();
136 _gpio_io_shadow = (_gpio_io_shadow & ~mask) | (value & mask);
137 gpio_base->io = _gpio_io_shadow;
138 //hal_restore_ints(ei);
143 * \brief read GPIO bits
146 hal_gpio_read(int bank)
149 int r = gpio_base->io;
150 if (bank == GPIO_TX_BANK)
157 * ========================================================================
159 * ========================================================================
162 static unsigned long leds_shadow = 0;
165 hal_set_leds(int value, int mask)
167 int ei = hal_disable_ints();
168 leds_shadow = (leds_shadow & ~mask) | (value & mask);
169 output_regs->leds = leds_shadow;
170 hal_restore_ints(ei);
174 hal_toggle_leds(int mask)
176 int ei = hal_disable_ints();
178 output_regs->leds = leds_shadow;
179 hal_restore_ints(ei);
183 // ================================================================
185 // ================================================================
187 #if defined(HAL_IO_USES_DBOARD_PINS)
189 // Does i/o using high 9-bits of rx daughterboard pins.
192 // 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
193 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
195 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
198 // Asserts W when writing char
206 // make high 9 bits of tx daughterboard outputs
207 hal_gpio_set_rx_mode(15, 7, GPIOM_OUTPUT);
209 // and set them to zero
210 hal_gpio_set_rx(0x0000, 0xff80);
216 volatile unsigned long *p = (unsigned long *) 0xC2F0;
224 hal_gpio_set_rx((s << 8) | W, 0xff80);
225 hal_gpio_set_rx(0, 0xff80);
229 #elif defined(HAL_IO_USES_UART)
253 return hal_uart_getc();
283 // ================================================================
284 // (slightly) higher level functions
286 // These are here so we can inline the calls to putchar.
287 // The rest of the stuff was moved to nonstdio.c
288 // ================================================================
298 putstr(const char *s)