Imported Upstream version 3.0.4
[debian/gnuradio] / usrp / firmware / src / usrp2 / board_specific.c
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2004 Free Software Foundation, Inc.
4  * 
5  * This file is part of GNU Radio
6  * 
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  * 
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with GNU Radio; see the file COPYING.  If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22
23 #include "usrp_common.h"
24 #include "spi.h"
25
26 void
27 set_led_0 (unsigned char on)
28 {
29   if (!on)                      // active low
30     USRP_PC |= bmPC_LED0;
31   else
32     USRP_PC &= ~bmPC_LED0;
33 }
34
35 void 
36 set_led_1 (unsigned char on)
37 {
38   if (!on)                      // active low
39     USRP_PC |= bmPC_LED1;
40   else
41     USRP_PC &= ~bmPC_LED1;
42 }
43
44 void
45 toggle_led_0 (void)
46 {
47   USRP_PC ^= bmPC_LED0;
48 }
49
50 void
51 toggle_led_1 (void)
52 {
53   USRP_PC ^= bmPC_LED1;
54 }
55
56 void
57 la_trace_init (void)
58 {
59 }
60
61 void
62 set_sleep_bits (unsigned char bits, unsigned char mask)
63 {
64   // NOP on usrp1
65 }
66
67 static xdata unsigned char xbuf[1];
68
69 void
70 write_9862 (unsigned char which, unsigned char regno, unsigned char value)
71 {
72   xbuf[0] = value;
73   
74   spi_write (0, regno & 0x3f,
75              which == 0 ? SPI_ENABLE_CODEC_A : SPI_ENABLE_CODEC_B,
76              SPI_FMT_MSB | SPI_FMT_HDR_1,
77              xbuf, 1);
78 }
79
80 void
81 write_both_9862s (unsigned char regno, unsigned char value)
82 {
83   xbuf[0] = value;
84   
85   spi_write (0, regno & 0x3f,
86              SPI_ENABLE_CODEC_A | SPI_ENABLE_CODEC_B,
87              SPI_FMT_MSB | SPI_FMT_HDR_1,
88              xbuf, 1);
89 }
90
91 #define REG_RX_PWR_DN            1
92 #define REG_TX_PWR_DN            8
93 #define REG_TX_MODULATOR        20
94
95 static void
96 power_down_9862s (void)
97 {
98   write_both_9862s (REG_RX_PWR_DN,    0x01);
99   write_both_9862s (REG_TX_PWR_DN,    0x0f);    // pwr dn digital and analog_both
100   write_both_9862s (REG_TX_MODULATOR, 0x00);    // coarse & fine modulators disabled
101 }
102
103 void
104 init_board (void)
105 {
106   la_trace_init ();
107   init_spi ();
108
109   USRP_PC &= ~bmPC_nRESET;      // active low reset
110   USRP_PC |= bmPC_nRESET;
111
112   power_down_9862s ();
113 }