version 4.1.0 from http://fpga4u.epfl.ch/wiki/FX2
[fx2fw-sdcc] / fx2 / syncdelay.h
1 /* -*- c++ -*- */\r
2 \r
3 /*-----------------------------------------------------------------------------\r
4 \r
5  * Synchronization delay for FX2 access to specific registers\r
6 \r
7  *-----------------------------------------------------------------------------\r
8 \r
9  * Code taken from USRP2 firmware (GNU Radio Project), version 3.0.2,\r
10 \r
11  * Copyright 2003 Free Software Foundation, Inc.\r
12 \r
13  *-----------------------------------------------------------------------------\r
14 \r
15  * This code is part of usbjtag. usbjtag is free software; you can redistribute\r
16 \r
17  * it and/or modify it under the terms of the GNU General Public License as\r
18 \r
19  * published by the Free Software Foundation; either version 2 of the License,\r
20 \r
21  * or (at your option) any later version. usbjtag is distributed in the hope\r
22 \r
23  * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied\r
24 \r
25  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
26 \r
27  * GNU General Public License for more details.  You should have received a\r
28 \r
29  * copy of the GNU General Public License along with this program in the file\r
30 \r
31  * COPYING; if not, write to the Free Software Foundation, Inc., 51 Franklin\r
32 \r
33  * St, Fifth Floor, Boston, MA  02110-1301  USA\r
34 \r
35  *-----------------------------------------------------------------------------\r
36 \r
37  */\r
38 \r
39 \r
40 \r
41 #ifndef _SYNCDELAY_H_\r
42 \r
43 #define _SYNCDELAY_H_\r
44 \r
45 \r
46 \r
47 /*\r
48 \r
49  * Magic delay required between access to certain xdata registers (TRM page 15-106).\r
50 \r
51  * For our configuration, 48 MHz FX2 / 48 MHz IFCLK, we need three cycles.  Each\r
52 \r
53  * NOP is a single cycle....\r
54 \r
55  *\r
56 \r
57  * From TRM page 15-105:\r
58 \r
59  *\r
60 \r
61  * Under certain conditions, some read and write access to the FX2 registers must\r
62 \r
63  * be separated by a "synchronization delay".  The delay is necessary only under the\r
64 \r
65  * following conditions:\r
66 \r
67  *\r
68 \r
69  *   - between a write to any register in the 0xE600 - 0xE6FF range and a write to one\r
70 \r
71  *     of the registers listed below.\r
72 \r
73  *\r
74 \r
75  *   - between a write to one of the registers listed below and a read from any register\r
76 \r
77  *     in the 0xE600 - 0xE6FF range.\r
78 \r
79  *\r
80 \r
81  *   Registers which require a synchronization delay:\r
82 \r
83  *\r
84 \r
85  *      FIFORESET                       FIFOPINPOLAR\r
86 \r
87  *      INPKTEND                        EPxBCH:L\r
88 \r
89  *      EPxFIFOPFH:L                    EPxAUTOINLENH:L\r
90 \r
91  *      EPxFIFOCFG                      EPxGPIFFLGSEL\r
92 \r
93  *      PINFLAGSAB                      PINFLAGSCD\r
94 \r
95  *      EPxFIFOIE                       EPxFIFOIRQ\r
96 \r
97  *      GPIFIE                          GPIFIRQ\r
98 \r
99  *      UDMACRCH:L                      GPIFADRH:L\r
100 \r
101  *      GPIFTRIG                        EPxGPIFTRIG\r
102 \r
103  *      OUTPKTEND                       REVCTL\r
104 \r
105  *      GPIFTCB3                        GPIFTCB2\r
106 \r
107  *      GPIFTCB1                        GPIFTCB0\r
108 \r
109  */\r
110 \r
111 \r
112 \r
113 /*\r
114 \r
115  * FIXME ensure that the peep hole optimizer isn't screwing us\r
116 \r
117  */\r
118 \r
119 #define SYNCDELAY       _asm nop; nop; nop; _endasm\r
120 \r
121 #define NOP             _asm nop; _endasm\r
122 \r
123 \r
124 \r
125 \r
126 \r
127 #endif /* _SYNCDELAY_H_ */\r
128 \r