Imported Upstream version 3.0
[debian/gnuradio] / usrp / firmware / src / common / usrp_common.c
1 /*
2  * USRP - Universal Software Radio Peripheral
3  *
4  * Copyright (C) 2003 Free Software Foundation, Inc.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Boston, MA  02110-1301  USA
19  */
20
21 /* 
22  * common code for USRP
23  */
24
25 #include "usrp_common.h"
26
27 void init_board (void);
28
29 void
30 init_usrp (void)
31 {
32   CPUCS = bmCLKSPD1;    // CPU runs @ 48 MHz
33   CKCON = 0;            // MOVX takes 2 cycles
34
35   // IFCLK is generated internally and runs at 48 MHz; GPIF "master mode"
36
37   IFCONFIG = bmIFCLKSRC | bm3048MHZ | bmIFCLKOE | bmIFCLKPOL | bmIFGPIF;
38   SYNCDELAY;
39
40   // configure IO ports (B and D are used by GPIF)
41
42   IOA = bmPORT_A_INITIAL;       // Port A initial state
43   OEA = bmPORT_A_OUTPUTS;       // Port A direction register
44
45   IOC = bmPORT_C_INITIAL;       // Port C initial state
46   OEC = bmPORT_C_OUTPUTS;       // Port C direction register
47
48   IOE = bmPORT_E_INITIAL;       // Port E initial state
49   OEE = bmPORT_E_OUTPUTS;       // Port E direction register
50
51
52   // REVCTL = bmDYN_OUT | bmENH_PKT;                    // highly recommended by docs
53   // SYNCDELAY;
54   
55   // configure end points
56
57   EP1OUTCFG = bmVALID | bmBULK;                         SYNCDELAY;
58   EP1INCFG  = bmVALID | bmBULK | bmIN;                  SYNCDELAY;
59
60   EP2CFG    = bmVALID | bmBULK | bmQUADBUF;             SYNCDELAY;      // 512 quad bulk OUT
61   EP4CFG    = 0;                                        SYNCDELAY;      // disabled
62   EP6CFG    = bmVALID | bmBULK | bmQUADBUF | bmIN;      SYNCDELAY;      // 512 quad bulk IN
63   EP8CFG    = 0;                                        SYNCDELAY;      // disabled
64
65   // reset FIFOs
66
67   FIFORESET = bmNAKALL;                                 SYNCDELAY;
68   FIFORESET = 2;                                        SYNCDELAY;
69   // FIFORESET = 4;                                     SYNCDELAY;
70   FIFORESET = 6;                                        SYNCDELAY;
71   // FIFORESET = 8;                                     SYNCDELAY;
72   FIFORESET = 0;                                        SYNCDELAY;
73   
74   // configure end point FIFOs
75
76   // let core see 0 to 1 transistion of autoout bit
77
78   EP2FIFOCFG =             bmWORDWIDE;                  SYNCDELAY;
79   EP2FIFOCFG = bmAUTOOUT | bmWORDWIDE;                  SYNCDELAY;
80   EP6FIFOCFG = bmAUTOIN  | bmWORDWIDE;                  SYNCDELAY;
81
82
83   // prime the pump 
84
85 #if 0
86   EP2BCL  = 0x80;               SYNCDELAY;
87   EP2BCL  = 0x80;               SYNCDELAY;
88   EP2BCL  = 0x80;               SYNCDELAY;
89   EP2BCL  = 0x80;               SYNCDELAY;
90 #endif
91
92   EP0BCH = 0;                   SYNCDELAY;
93
94   // arm EP1OUT so we can receive "out" packets (TRM pg 8-8)
95
96   EP1OUTBC = 0;                 SYNCDELAY;
97
98   EP2GPIFFLGSEL = 0x01;         SYNCDELAY; // For EP2OUT, GPIF uses EF flag
99   EP6GPIFFLGSEL = 0x02;         SYNCDELAY; // For EP6IN,  GPIF uses FF flag
100
101   // set autoin length for EP6
102   // FIXME should be f(enumeration)
103
104   EP6AUTOINLENH = (512) >> 8;   SYNCDELAY;  // this is the length for high speed
105   EP6AUTOINLENL = (512) & 0xff; SYNCDELAY;
106
107   init_board ();
108 }
109