Statistics
| Branch: | Tag: | Revision:

root / firmware / fx2 / b100 / usrp_common.c @ 10a4d951

History | View | Annotate | Download (3.79 KB)

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 3 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, external clk en
36
  IFCONFIG = bmIFCLKSRC | bm3048MHZ | bmIFCLKOE;
37
  SYNCDELAY;
38

    
39
  // configure IO ports (B and D are used by slave FIFO)
40
  IOA = bmPORT_A_INITIAL;        // Port A initial state
41
  OEA = bmPORT_A_OUTPUTS;        // Port A direction register
42

    
43
  IOC = bmPORT_C_INITIAL;        // Port C initial state
44
  OEC = bmPORT_C_OUTPUTS;        // Port C direction register
45

    
46
  IOE = bmPORT_E_INITIAL;        // Port E initial state
47
  OEE = bmPORT_E_OUTPUTS;        // Port E direction register
48

    
49

    
50
  //REVCTL = bmDYN_OUT | bmENH_PKT;                        // highly recommended by docs
51
  // SYNCDELAY;
52
  
53
  // configure end points
54
  EP1OUTCFG = bmVALID | bmBULK;                                SYNCDELAY;
55
  EP1INCFG  = bmVALID | bmBULK | bmIN;                        SYNCDELAY;
56

    
57
  EP2CFG    = bmVALID | bmBULK | bmDOUBLEBUF;                SYNCDELAY;        // 512 dbl bulk OUT
58
  EP4CFG    = bmVALID | bmBULK | bmDOUBLEBUF;                SYNCDELAY;        // 512 dbl bulk OUT
59
  EP6CFG    = bmVALID | bmBULK | bmDOUBLEBUF | bmIN;        SYNCDELAY;        // 512 dbl bulk IN
60
  EP8CFG    = bmVALID | bmBULK | bmDOUBLEBUF | bmIN;        SYNCDELAY;        // 512 dbl bulk IN
61

    
62
  // reset FIFOs
63
  FIFORESET = bmNAKALL;                                        SYNCDELAY;
64
  FIFORESET = 2;                                        SYNCDELAY;
65
  FIFORESET = 4;                                        SYNCDELAY;
66
  FIFORESET = 6;                                        SYNCDELAY;
67
  FIFORESET = 8;                                        SYNCDELAY;
68
  FIFORESET = 0;                                        SYNCDELAY;
69
  
70
  // configure end point FIFOs
71
  // let core see 0 to 1 transistion of autoin/out bit
72
  EP2FIFOCFG =             bmWORDWIDE;                        SYNCDELAY;
73
  EP2FIFOCFG = bmAUTOOUT | bmWORDWIDE;                        SYNCDELAY;
74
  EP6FIFOCFG = bmZEROLENIN            | bmWORDWIDE;                        SYNCDELAY;
75
  EP6FIFOCFG = bmZEROLENIN | bmAUTOIN | bmWORDWIDE;                        SYNCDELAY;
76
  EP4FIFOCFG =             bmWORDWIDE;      SYNCDELAY;
77
  EP4FIFOCFG = bmAUTOOUT | bmWORDWIDE;      SYNCDELAY;
78
  EP8FIFOCFG = bmZEROLENIN |            bmWORDWIDE;      SYNCDELAY;
79
  EP8FIFOCFG = bmZEROLENIN | bmAUTOIN | bmWORDWIDE;      SYNCDELAY;
80

    
81
  EP0BCH = 0;                        SYNCDELAY;
82
  // arm EP1OUT so we can receive "out" packets (TRM pg 8-8)
83
  EP1OUTBC = 0;                        SYNCDELAY;
84

    
85
  // set autoin length for EP6/EP8
86
  EP6AUTOINLENH = (512) >> 8;        SYNCDELAY;  // this is the length for high speed
87
  EP6AUTOINLENL = (512) & 0xff; SYNCDELAY;
88
  EP8AUTOINLENH = (32) >> 8; SYNCDELAY;
89
  EP8AUTOINLENL = (32) & 0xff; SYNCDELAY;
90

    
91
  //set FLAGA, FLAGB, FLAGC, FLAGD to be EP2EF, EP4EF, EP6PF, EP8PF
92
  PINFLAGSAB = (bmEP2EF) | (bmEP4EF << 4);
93
  PINFLAGSCD = (bmEP6PF) | (bmEP8PF << 4);
94

    
95
  //ok as far as i can tell, DECIS is reversed compared to the FX2 TRM.
96
  //p15.34 says DECIS high implements [assert when (fill > level)], observed opposite
97
  EP6FIFOPFH = 0x09;
98
  SYNCDELAY;
99
  EP6FIFOPFL = 0xFD;
100
  SYNCDELAY;
101

    
102
//  EP2FIFOPFH = 0x08;
103
//  SYNCDELAY;
104
// EP2FIFOPFL = 0x00;
105
//  SYNCDELAY;
106

    
107
  //assert FIFOEMPTY one cycle sooner so we get it in time at the FPGA
108
  EP2FIFOCFG |= bmBIT5; 
109
  
110
  //set FIFOPINPOLAR to normal (active low) mode
111
  FIFOPINPOLAR = 0x00;
112
  SYNCDELAY;
113
  PORTACFG = 0x80;
114

    
115
  init_board ();
116
}
117