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;
163
static unsigned long led_src_shadow = 0;
166
hal_set_leds(int value, int mask)
168
int ei = hal_disable_ints();
169
leds_shadow = (leds_shadow & ~mask) | (value & mask);
170
output_regs->leds = leds_shadow;
171
hal_restore_ints(ei);
174
// Allow hardware control over leds. 1 = hardware, 0 = software
176
hal_set_led_src(int value, int mask)
178
int ei = hal_disable_ints();
179
led_src_shadow = (led_src_shadow & ~mask) | (value & mask);
180
output_regs->led_src = led_src_shadow;
181
hal_restore_ints(ei);
185
hal_toggle_leds(int mask)
187
int ei = hal_disable_ints();
189
output_regs->leds = leds_shadow;
190
hal_restore_ints(ei);
194
// ================================================================
196
// ================================================================
198
#if defined(HAL_IO_USES_DBOARD_PINS)
200
// Does i/o using high 9-bits of rx daughterboard pins.
203
// 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
204
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
206
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
209
// Asserts W when writing char
217
// make high 9 bits of tx daughterboard outputs
218
hal_gpio_set_rx_mode(15, 7, GPIOM_OUTPUT);
220
// and set them to zero
221
hal_gpio_set_rx(0x0000, 0xff80);
227
volatile unsigned long *p = (unsigned long *) 0xC2F0;
235
hal_gpio_set_rx((s << 8) | W, 0xff80);
236
hal_gpio_set_rx(0, 0xff80);
240
#elif defined(HAL_IO_USES_UART)
264
return hal_uart_getc();
294
// ================================================================
295
// (slightly) higher level functions
297
// These are here so we can inline the calls to putchar.
298
// The rest of the stuff was moved to nonstdio.c
299
// ================================================================
309
putstr(const char *s)