GNU Radio 3.3.0 C++ API
hal_io.h
Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 2007 Free Software Foundation, Inc.
00004  *
00005  * This program is free software: you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation, either version 3 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00017  */
00018 
00019 #ifndef INCLUDED_HAL_IO_H
00020 #define INCLUDED_HAL_IO_H
00021 
00022 #include "memory_map.h"
00023 
00024 void hal_io_init(void);
00025 void hal_finish();
00026 
00027 
00028 /*
00029  * ------------------------------------------------------------------------
00030  * The GPIO pins are organized into two banks of 16-bits.
00031  * Bank 0 goes to the Tx daughterboard, Bank 1 goes to the Rx daughterboard.
00032  *
00033  * Each pin may be configured as an input or an output from the FPGA.
00034  * For output pins, there are four signals which may be routed to the
00035  * pin.  The four signals are the value written by s/w, the output of
00036  * the ATR controller, or two different sources of debug info from the
00037  * FPGA fabric.
00038  * ------------------------------------------------------------------------
00039  */
00040 
00041 #define GPIO_TX_BANK    0       // pins that connect to the Tx daughterboard
00042 #define GPIO_RX_BANK    1       // pins that connect to the Rx daughterboard
00043 
00044 
00045 /*!
00046  * \brief Set the data direction for GPIO pins
00047  *
00048  * If the bit is set, it's an output from the FPGA.
00049  * \param value is a 16-bit bitmask of values
00050  * \param mask is a 16-bit bitmask of which bits to effect.
00051  */ 
00052 void hal_gpio_set_ddr(int bank, int value, int mask);
00053 
00054 /*!
00055  * \brief Select the source of the signal for an output pin.
00056  *
00057  * \param code is is one of 's', 'a', '0', '1'
00058  *   where 's' selects software output, 'a' selects ATR output, '0' selects
00059  *   debug 0, '1' selects debug 1.
00060  */
00061 void hal_gpio_set_sel(int bank, int bitno, char code);
00062 
00063 /*!
00064  * \brief Select the source of the signal for the output pins.
00065  *
00066  * \param codes is is a string of 16 characters composed of '.', 's',
00067  * 'a', '0', or '1' where '.' means "don't change", 's' selects
00068  * software output, 'a' selects ATR output, '0' selects debug 0, '1'
00069  * selects debug 1.
00070  */
00071 void hal_gpio_set_sels(int bank, char *codes);
00072 
00073 
00074 /*!
00075  * \brief write \p value to gpio pins specified by \p mask.
00076  */
00077 void hal_gpio_write(int bank, int value, int mask);
00078 
00079 /*!
00080  * \brief read GPIO bits
00081  */
00082 int  hal_gpio_read(int bank);
00083 
00084 
00085 /*
00086  * ------------------------------------------------------------------------
00087  *                         control the leds
00088  *
00089  * Low 4-bits are the general purpose leds on the board
00090  * The next bit is the led on the ethernet connector
00091  * ------------------------------------------------------------------------
00092  */
00093 
00094 void hal_set_leds(int value, int mask);
00095 void hal_set_led_src(int value, int mask);
00096 void hal_toggle_leds(int mask);
00097 
00098 /*
00099  * ------------------------------------------------------------------------
00100  *                         simple timeouts
00101  * ------------------------------------------------------------------------
00102  */
00103 
00104 
00105 
00106 static inline void
00107 hal_set_timeout(int delta_ticks)
00108 {
00109   int t = timer_regs->time + delta_ticks;
00110   if (t == 0)                   // kills timer
00111     t = 1;
00112   timer_regs->time = t;
00113 }
00114 
00115 /*
00116  * ------------------------------------------------------------------------
00117  *                      interrupt enable/disable
00118  * ------------------------------------------------------------------------
00119  */
00120 
00121 /*!
00122  * \brief Disable interrupts and return previous interrupt enable state.
00123  * [Microblaze specific]
00124  */
00125 static inline int
00126 hal_disable_ints(void)
00127 {
00128   int result, t0;
00129 
00130   asm volatile("mfs   %0, rmsr       \n\
00131                 andni %1, %0, 0x2    \n\
00132                 mts   rmsr, %1"
00133                : "=r" (result), "=r" (t0));
00134   return result;
00135 }
00136 
00137 /*!
00138  * \brief Enable interrupts and return previous interrupt enable state.
00139  * [Microblaze specific]
00140  */
00141 static inline int
00142 hal_enable_ints(void)
00143 {
00144   int result, t0;
00145 
00146   asm volatile("mfs  %0, rmsr         \n\
00147                 ori  %1, %0, 0x2      \n\
00148                 mts  rmsr, %1"
00149                : "=r" (result), "=r" (t0));
00150   return result;
00151 }
00152 
00153 /*!
00154  * \brief Set interrupt enable state to \p prev_state.
00155  * [Microblaze specific]
00156  */
00157 static inline void
00158 hal_restore_ints(int prev_state)
00159 {
00160   int t0, t1;
00161   asm volatile("andi  %0, %2, 0x2       \n\
00162                 mfs   %1, rmsr          \n\
00163                 andni %1, %1, 0x2       \n\
00164                 or    %1, %1, %0        \n\
00165                 mts   rmsr, %1"
00166                : "=r" (t0), "=r"(t1) : "r" (prev_state));
00167 }
00168 
00169 #endif /* INCLUDED_HAL_IO_H */