3 * Copyright 2007 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 #ifndef INCLUDED_HAL_IO_H
20 #define INCLUDED_HAL_IO_H
22 #include "memory_map.h"
24 void hal_io_init(void);
29 * ------------------------------------------------------------------------
30 * The GPIO pins are organized into two banks of 16-bits.
31 * Bank 0 goes to the Tx daughterboard, Bank 1 goes to the Rx daughterboard.
33 * Each pin may be configured as an input or an output from the FPGA.
34 * For output pins, there are four signals which may be routed to the
35 * pin. The four signals are the value written by s/w, the output of
36 * the ATR controller, or two different sources of debug info from the
38 * ------------------------------------------------------------------------
41 #define GPIO_TX_BANK 0 // pins that connect to the Tx daughterboard
42 #define GPIO_RX_BANK 1 // pins that connect to the Rx daughterboard
46 * \brief Set the data direction for GPIO pins
48 * If the bit is set, it's an output from the FPGA.
49 * \param value is a 16-bit bitmask of values
50 * \param mask is a 16-bit bitmask of which bits to effect.
52 void hal_gpio_set_ddr(int bank, int value, int mask);
55 * \brief Select the source of the signal for an output pin.
57 * \param code is is one of 's', 'a', '0', '1'
58 * where 's' selects software output, 'a' selects ATR output, '0' selects
59 * debug 0, '1' selects debug 1.
61 void hal_gpio_set_sel(int bank, int bitno, char code);
64 * \brief Select the source of the signal for the output pins.
66 * \param codes is is a string of 16 characters composed of '.', 's',
67 * 'a', '0', or '1' where '.' means "don't change", 's' selects
68 * software output, 'a' selects ATR output, '0' selects debug 0, '1'
71 void hal_gpio_set_sels(int bank, char *codes);
75 * \brief write \p value to gpio pins specified by \p mask.
77 void hal_gpio_write(int bank, int value, int mask);
80 * \brief read GPIO bits
82 int hal_gpio_read(int bank);
86 * ------------------------------------------------------------------------
89 * Low 4-bits are the general purpose leds on the board
90 * The next bit is the led on the ethernet connector
91 * ------------------------------------------------------------------------
94 void hal_set_leds(int value, int mask);
95 void hal_set_led_src(int value, int mask);
96 void hal_toggle_leds(int mask);
99 * ------------------------------------------------------------------------
101 * ------------------------------------------------------------------------
107 hal_set_timeout(int delta_ticks)
109 int t = timer_regs->time + delta_ticks;
110 if (t == 0) // kills timer
112 timer_regs->time = t;
116 * ------------------------------------------------------------------------
117 * interrupt enable/disable
118 * ------------------------------------------------------------------------
122 * \brief Disable interrupts and return previous interrupt enable state.
123 * [Microblaze specific]
126 hal_disable_ints(void)
130 asm volatile("mfs %0, rmsr \n\
131 andni %1, %0, 0x2 \n\
133 : "=r" (result), "=r" (t0));
138 * \brief Enable interrupts and return previous interrupt enable state.
139 * [Microblaze specific]
142 hal_enable_ints(void)
146 asm volatile("mfs %0, rmsr \n\
149 : "=r" (result), "=r" (t0));
154 * \brief Set interrupt enable state to \p prev_state.
155 * [Microblaze specific]
158 hal_restore_ints(int prev_state)
161 asm volatile("andi %0, %2, 0x2 \n\
163 andni %1, %1, 0x2 \n\
166 : "=r" (t0), "=r"(t1) : "r" (prev_state));
169 #endif /* INCLUDED_HAL_IO_H */