]> sigrok.org Git - sigrok-firmware-fx2lafw.git/blob - fx2lib/include/gpif.h
624a568f427f69f6b3c3201a155bea46f7c1b8ad
[sigrok-firmware-fx2lafw.git] / fx2lib / include / gpif.h
1 // Copyright (C) 2009 Ubixum, Inc. 
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, see <http://www.gnu.org/licenses/>.
15
16 /*! \file 
17  *
18  * These functions do the same thing that the Cypress gpif designer expored c file does.
19  * Instead of including their file directly in your project, you include just the
20  * generated waveform data.  The gpif2dat script in the utils folder will export your
21  * waveform data to a file that can be included in your project.
22  * */
23
24 #ifndef GPIF_H
25 #define GPIF_H
26
27 #include "fx2types.h"
28
29 #define GPIFDONE (GPIFTRIG&0x80)
30 #define GPIFTC16 (MAKEWORD(GPIFTCB1,GPIFTCB0))
31 #define GPIFTC32 (MAKEDWORD(MAKEWORD(GPIFTCB3,GPIFTCB2),MAKEWORD(GPIFTCB1,GPIFTCB0)))
32
33
34 /**
35  * Gpif designer generates a c file with waveform data.
36  * Copy the WaveData[128] array
37  * and the InitData[7] to your code somewhere
38  * Then this function is pretty much the reset of the generated
39  * code but ported to sdcc.
40  *
41  * uses syncdelay of 4 which might not be long enough if peripheral
42  * runs slower than 30mhz.  May not affect anything.
43  *
44  * IFCONFIG is set with IFCFG[1:0] = 10 for GPIF master but you still
45  * have to set the ifclk, polarity, and the rest of the bits
46  **/
47
48 void gpif_init( BYTE* waveform, BYTE* initdata );
49
50 /**
51  * Uses the correct bytes from your flowstates array.
52  * This may or may not be needed depending on whether
53  * your waveform data uses flowstates.  If you don't
54  * know if you need them or not, you probably don't.
55  *
56  * flowstates should have 36 elements.
57  * bank should be 0-3
58  **/
59 void gpif_setflowstate( BYTE* flowstates, BYTE bank);
60
61
62
63 //! These defines/functions pretty much out of the TRM 10.4
64 #define GPIFTRGWR 0
65 #define GPIFTRGRD 4
66 typedef enum {
67     GPIF_EP2 = 0,
68     GPIF_EP4 = 1,
69     GPIF_EP6 = 2,
70     GPIF_EP8 = 3
71 } GPIF_EP_NUM;
72
73 /**
74  * \brief Simple function to help set the transaction count for gpif
75  * transactions.
76  * \param tc 32 bit Transaction Count
77  **/
78 void gpif_set_tc32(DWORD tc);
79 /**
80  * \brief Simple function to set transaction count for gpif transactions.
81  * \param tc 16 bit Transaction Count
82  **/
83 void gpif_set_tc16(WORD tc);
84
85
86 /**
87  * Use the gpif to read a single word at a time.
88  * Read len words and store in res
89  *
90  * At least one EPxFIFOCFG has to have wordwide=1 or this
91  * functions won't transfer both bytes.
92  **/
93
94 void gpif_single_read16( WORD* res , WORD len);
95
96 /**
97  * Use the gpif to write a single word at a time.
98  * Write len words from data
99  *
100  * At leat one EPxFIFOCFG has to have wordwide=1 or this
101  * function won't transfer both bytes.
102  **/
103 void gpif_single_write16( WORD* __data, WORD len);
104
105 void gpif_fifo_read ( GPIF_EP_NUM ep_num );
106
107 void gpif_fifo_write( GPIF_EP_NUM ep_num );
108
109 #endif