OpenCores
URL https://opencores.org/ocsvn/gecko3/gecko3/trunk

Subversion Repositories gecko3

[/] [gecko3/] [trunk/] [GECKO3COM/] [gecko3com-fw/] [firmware/] [src/] [gecko3com_gpif.c] - Blame information for rev 20

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 9 nussgipfel
/* GECKO3COM
2
 *
3
 * Copyright (C) 2008 by
4
 *   ___    ____  _   _
5
 *  (  _`\ (  __)( ) ( )
6
 *  | (_) )| (_  | |_| |   Bern University of Applied Sciences
7
 *  |  _ <'|  _) |  _  |   School of Engineering and
8
 *  | (_) )| |   | | | |   Information Technology
9
 *  (____/'(_)   (_) (_)
10
 *
11
 *
12
 * This program is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU General Public License as published by
14
 * the Free Software Foundation, either version 3 of the License, or
15
 * (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU General Public License for more details.
21
 * You should have received a copy of the GNU General Public License
22
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23
 */
24
 
25
/*********************************************************************/
26
/** \file     gecko3com_gpif.c
27
 *********************************************************************
28
 * \brief     project specific functions to handle the GPIF
29
 *
30
 *
31
 *
32
 * \author    GNUradio team, Christoph Zimmermann bfh.ch
33
 * \date      2009-4-16
34
 *
35
 * \note Comments from the original GNU radio source: \n
36
 * The GPIF Designer tool is kind of screwed up, in that it doesn't
37
 * configure some of the ports correctly.  We just use their tables and
38
 * handle the initialization ourselves.  They also declare that their
39
 * static initialized data is in xdata, which screws us too.
40
 *
41
*/
42
 
43
#include <stdint.h>
44
#include "gecko3com_gpif.h"
45
#include "gpif_data.h"
46
#include "isr.h"
47
#include "delay.h"
48
#include "fx2regs.h"
49
#include "gecko3com_regs.h"
50
#include "gecko3com_interfaces.h"
51
#include "syncdelay.h"
52
#include "debugprint.h"
53
 
54
 
55
/* These are the tables generated by the Cypress GPIF Designer */
56
 
57
/** \brief Waveform data generated by the Cypress GPIF Designer
58
 *
59
 *  this table is defined in the gpif_data.c file. provide the
60
 *  desired file for your board
61
 */
62
extern const char WaveData[128];
63
 
64
/** \brief Flowstate data generated by the Cypress GPIF Designer
65
 *
66
 *  this table is defined in the gpif_data.c file. provide the
67
 *  desired file for your board
68
 */
69
extern const char FlowStates[36];
70
 
71
/** \brief Init values generated by the Cypress GPIF Designer
72
 *  and the edit-gpif script
73
 *
74
 *  this table is defined in the gpif_data.h file. provide the
75
 *  desired file for your board
76
 */
77
extern const char InitData[7];
78
 
79
 
80 19 nussgipfel
//** private flag to signal, that the GPIF receives data from the FPGA */
81
//volatile static uint8_t flGPIF;
82 9 nussgipfel
 
83
 
84
 
85
/**
86 20 nussgipfel
 * \brief exectuted when the gpif waveform terminates
87 9 nussgipfel
 */
88
void
89
isr_gpif_done (void) interrupt
90
{
91
  ISR_DEBUG_PORT |= bmGPIF_DONE;
92
 
93 20 nussgipfel
  /* check if this is a end of a IN transfer */
94
  if((flGPIF & bmGPIF_READ_IN_PROGRESS) == bmGPIF_READ_IN_PROGRESS){
95
    INPKTEND = USB_TMC_EP_IN;
96
  }
97
 
98
  while(!(GPIFTRIG & bmGPIF_IDLE));
99
 
100 18 nussgipfel
  /* check if there is data available for an OUT transfer */
101 20 nussgipfel
  if((flGPIF & bmGPIF_PENDING_DATA) == bmGPIF_PENDING_DATA) {
102 19 nussgipfel
    //if(!(EP2468STAT & bmEP2EMPTY)) {
103 9 nussgipfel
    flGPIF &= ~bmGPIF_PENDING_DATA;
104 20 nussgipfel
 
105 9 nussgipfel
    gpif_trigger_write();
106 20 nussgipfel
    flGPIF &= ~bmGPIF_READ_IN_PROGRESS;
107 9 nussgipfel
  }
108 20 nussgipfel
  else {
109
    gpif_trigger_read();
110
    flGPIF |= bmGPIF_READ_IN_PROGRESS;
111 9 nussgipfel
  }
112 19 nussgipfel
 
113
  clear_fifo_gpif_irq();
114 18 nussgipfel
 
115 9 nussgipfel
  ISR_DEBUG_PORT &= ~bmGPIF_DONE;
116
}
117
 
118
 
119
/**
120
 * \brief exectuted when data is available in the OUT endpoint
121
 */
122
void
123
isr_endpoint_out_data (void) interrupt
124
{
125
  ISR_DEBUG_PORT |= bmFIFO_PF;
126
 
127 17 nussgipfel
  /* check if there is a active IN transfer */
128 20 nussgipfel
  if((GPIFREADYSTAT & bmWRX) == bmWRX) {
129 9 nussgipfel
    flGPIF |= bmGPIF_PENDING_DATA;
130
  }
131 20 nussgipfel
  else {
132 9 nussgipfel
    GPIFABORT = 0xFF;
133
    SYNCDELAY;
134 19 nussgipfel
    while(!(GPIFTRIG & bmGPIF_IDLE));
135 9 nussgipfel
    gpif_trigger_write();
136 20 nussgipfel
    flGPIF &= ~bmGPIF_READ_IN_PROGRESS;
137 9 nussgipfel
  }
138
 
139 19 nussgipfel
  clear_fifo_gpif_irq();
140
 
141 9 nussgipfel
  ISR_DEBUG_PORT &= ~bmFIFO_PF;
142
}
143
 
144
 
145
/** \brief initialize GPIF system */
146
void init_gpif (void)
147
{
148
  uint8_t i;
149
 
150
#ifdef GECKO3MAIN
151 19 nussgipfel
  /* IFCLK is generated internally and runs at 30 MHz; GPIF "master mode" */
152
  //IFCONFIG = bmIFCLKSRC | bm3048MHZ | bmIFCLKOE | bmGSTATE | bmIFGPIF;
153
  IFCONFIG = bmIFCLKSRC | bmIFCLKOE | bmGSTATE | bmIFGPIF;
154 9 nussgipfel
  SYNCDELAY;
155
 
156
  /* we have to commit the currently processed packet BEFORE we switch to auto out mode */
157
  OUTPKTEND = bmSKIP | USB_TMC_EP_OUT;
158
 
159
  /*FIXME  only here for testing */
160 17 nussgipfel
  //EP6AUTOINLENH = (20) >> 8;     SYNCDELAY;  /* this is the length for high speed */
161
  //EP6AUTOINLENL = (20) & 0xff;  SYNCDELAY;
162
 
163 9 nussgipfel
  /* enable autoout and autoin feature of the endpoints */
164
  EP2FIFOCFG |= bmAUTOOUT;
165
  SYNCDELAY;
166
  EP6FIFOCFG |= bmAUTOIN;
167
  SYNCDELAY;
168
 
169
  /* set endpoint 2 fifo (out) programmable flag to "higher or equal 3"
170 18 nussgipfel
   * we use the programmable flag as interrupt source to detect if data for the
171
   * FPGA is available and as GPIF flag to stop the flowstate, for this the
172
   * flag has to change one cycle before the FIFO is completly empty, else we
173
   * transfer one word too much */
174 9 nussgipfel
  EP2FIFOPFH = bmDECIS;
175 19 nussgipfel
  EP2FIFOPFL = 4;
176 9 nussgipfel
  SYNCDELAY;
177
 
178 19 nussgipfel
  EP2GPIFFLGSEL = bmFLAG_PROGRAMMABLE;
179
  //EP2GPIFFLGSEL = bmFLAG_EMPTY;
180 9 nussgipfel
  SYNCDELAY;
181
  EP6GPIFFLGSEL = bmFLAG_FULL;
182
  SYNCDELAY;
183
 
184
  EP2GPIFPFSTOP = 0;
185
  EP6GPIFPFSTOP = 0;
186
 
187
#endif
188
 
189
  GPIFABORT = 0xFF;  /* abort any waveforms pending */
190
  SYNCDELAY;
191
 
192
  GPIFREADYCFG = InitData[ 0 ];
193
  GPIFCTLCFG = InitData[ 1 ];
194
  GPIFIDLECS = InitData[ 2 ];
195
  GPIFIDLECTL = InitData[ 3 ];
196
  /* Hmmm, what's InitData[ 4 ] ... */
197
  GPIFWFSELECT = InitData[ 5 ];
198
  /* GPIFREADYSTAT = InitData[ 6 ]; */  /* I think this register is read only... */
199
 
200
  for (i = 0; i < 128; i++){
201
    GPIF_WAVE_DATA[i] = WaveData[i];
202
  }
203
 
204
  setup_flowstate_common();
205
 
206
  FLOWSTATE = 0;         /* ensure it's off */
207
 
208
  GPIFREADYCFG |= bmINTRDY; /* set the internal ready signal */
209
 
210
  /* unset gpif flags */
211
  flGPIF = 0;
212
 
213
 
214
  EA = 0;                /* disable all interrupts */
215
 
216
  /* hook gpif interupt services */
217
 
218
  /* due to big problems with the done interrupt, we use the WAVEFORM interrupt
219
     to signal the firmware that the GPIF is done */
220
  hook_fgv(FGV_GPIFWF,(unsigned short) isr_gpif_done);
221
  hook_fgv(FGV_EP2PF,(unsigned short) isr_endpoint_out_data);
222
 
223
  EP2FIFOIE = bmFIFO_PF;
224
  GPIFIE = bmGPIFWF;
225
 
226
  EA = 1;               /* global interrupt enable */
227
 
228
 
229
  /* start gpif read, default state of the gpif to wait for fpga data */
230
  gpif_trigger_read();
231
 
232
}
233
 
234
 
235
/** \brief aborts any gpif running gpif transaction  */
236
void abort_gpif(void) {
237
 
238
  EA = 0;                /* disable all interrupts */
239
 
240
  flGPIF = 0;
241
 
242 20 nussgipfel
  /* abort the current GPIF waveform */
243 9 nussgipfel
  GPIFABORT = 0xFF;
244
  SYNCDELAY;
245
  while(!(GPIFTRIG & bmGPIF_IDLE));
246
 
247
  EA = 1;               /* global interrupt enable */
248
 
249 20 nussgipfel
  //print_info("gpif aborted\n");
250 9 nussgipfel
 
251 20 nussgipfel
#ifdef GECKO3MAIN
252
  /* signal an abort condition to the FPGA (both WRU and RDYU high) */
253
  GPIFIDLECTL |= bmRDYU | bmWRU;
254
  udelay(10);
255
  GPIFIDLECTL = InitData[ 3 ]; /* restore original state */
256
#endif
257
 
258 9 nussgipfel
  gpif_trigger_read();
259 20 nussgipfel
  flGPIF |= bmGPIF_READ_IN_PROGRESS;
260 9 nussgipfel
}
261
 
262
 
263
/** \brief disables gpif system */
264
void deactivate_gpif(void) {
265
 
266 20 nussgipfel
  EA = 0;          /* disable all interrupts */
267 9 nussgipfel
 
268
  EP2FIFOIE = 0;  /* disable FIFO interrupt */
269
  SYNCDELAY;
270
  GPIFIE = 0;     /* disable all GPIF interrupts */
271
  SYNCDELAY;
272
 
273
  GPIFTCB0 = 0x00;
274
  EP2GPIFPFSTOP = 1;
275
  EP6GPIFPFSTOP = 1;
276
 
277
  GPIFABORT = 0xFF; /* abort pending GPIF transaction */
278
  SYNCDELAY;
279
 
280
  flGPIF = 0;  /* unset all internal GPIF flags */
281
 
282 20 nussgipfel
  EA = 1;               /* global interrupt enable */
283 17 nussgipfel
 
284 20 nussgipfel
  while(!(GPIFTRIG & bmGPIF_IDLE));
285
 
286 9 nussgipfel
#ifdef GECKO3MAIN
287 20 nussgipfel
  /* signal an abort condition to the FPGA (both WRU and RDYU high) */
288
  GPIFIDLECTL |= bmRDYU | bmWRU;
289
  udelay(10);
290
  GPIFIDLECTL = InitData[ 3 ]; /* restore original state */
291
 
292 9 nussgipfel
  EP2FIFOCFG &= ~bmAUTOOUT;  /* disable AutoOUT feature */
293
  SYNCDELAY;
294
  //EP6FIFOCFG &= ~bmINFM;
295
  EP6FIFOCFG &= ~bmAUTOIN;   /* disable AutoIN feature */
296
#endif
297
 
298 18 nussgipfel
  //print_info("gpif deactivated\n");
299 9 nussgipfel
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.