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 9

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
/** private flag to signal, that the GPIF receives data from the FPGA */
81
volatile static uint8_t flGPIF;
82
 
83
 
84
 
85
/**
86
 * \brief exectuted when the gpif wafeform terminates
87
 */
88
void
89
isr_gpif_done (void) interrupt
90
{
91
  ISR_DEBUG_PORT |= bmGPIF_DONE;
92
 
93
  clear_fifo_gpif_irq();
94
 
95
  if((flGPIF & bmGPIF_PENDING_DATA) == bmGPIF_PENDING_DATA) {
96
    flGPIF &= ~bmGPIF_PENDING_DATA;
97
    gpif_trigger_write();
98
  }
99
  else {
100
    INPKTEND = 0x06;
101
    gpif_trigger_read();
102
  }
103
 
104
  ISR_DEBUG_PORT &= ~bmGPIF_DONE;
105
}
106
 
107
 
108
/**
109
 * \brief exectuted when data is available in the OUT endpoint
110
 */
111
void
112
isr_endpoint_out_data (void) interrupt
113
{
114
  ISR_DEBUG_PORT |= bmFIFO_PF;
115
 
116
  clear_fifo_gpif_irq();
117
 
118
  if((GPIFIDLECTL & bmBIT3) == bmBIT3) {
119
    flGPIF |= bmGPIF_PENDING_DATA;
120
  }
121
  else {
122
    EA = 0;              /* disable all interrupts */
123
    GPIFABORT = 0xFF;
124
    SYNCDELAY;
125
    EA = 1;             /* global interrupt enable */
126
 
127
    gpif_trigger_write();
128
  }
129
 
130
  ISR_DEBUG_PORT &= ~bmFIFO_PF;
131
}
132
 
133
 
134
/** \brief initialize GPIF system */
135
void init_gpif (void)
136
{
137
  uint8_t i;
138
 
139
#ifdef GECKO3MAIN
140
  /* IFCLK is generated internally and runs at 48 MHz; GPIF "master mode" */
141
  IFCONFIG = bmIFCLKSRC | bm3048MHZ | bmIFCLKOE | bmGSTATE | bmIFGPIF;
142
  SYNCDELAY;
143
 
144
  /* we have to commit the currently processed packet BEFORE we switch to auto out mode */
145
  OUTPKTEND = bmSKIP | USB_TMC_EP_OUT;
146
 
147
  /*FIXME  only here for testing */
148
  EP6AUTOINLENH = (20) >> 8;       SYNCDELAY;  /* this is the length for high speed */
149
  EP6AUTOINLENL = (20) & 0xff;  SYNCDELAY;
150
 
151
  /* enable autoout and autoin feature of the endpoints */
152
  EP2FIFOCFG |= bmAUTOOUT;
153
  SYNCDELAY;
154
  EP6FIFOCFG |= bmAUTOIN;
155
  SYNCDELAY;
156
 
157
  /* set endpoint 2 fifo (out) programmable flag to "higher or equal 3"
158
   * we use the programmable flag as interrupt source to detect if data for the FPGA
159
   * is available and as GPIF flag to stop the flowstate, for this the flag has to change
160
   * one cycle before the FIFO is completly empty, else we transfer one word too much */
161
  EP2FIFOPFH = bmDECIS;
162
  EP2FIFOPFL = 1;
163
  SYNCDELAY;
164
 
165
  EP2GPIFFLGSEL = bmFLAG_PROGRAMMABLE;
166
  // EP2GPIFFLGSEL = bmFLAG_EMPTY;
167
  SYNCDELAY;
168
  EP6GPIFFLGSEL = bmFLAG_FULL;
169
  SYNCDELAY;
170
 
171
  EP2GPIFPFSTOP = 0;
172
  EP6GPIFPFSTOP = 0;
173
 
174
#endif
175
 
176
  GPIFABORT = 0xFF;  /* abort any waveforms pending */
177
  SYNCDELAY;
178
 
179
  GPIFREADYCFG = InitData[ 0 ];
180
  GPIFCTLCFG = InitData[ 1 ];
181
  GPIFIDLECS = InitData[ 2 ];
182
  GPIFIDLECTL = InitData[ 3 ];
183
  /* Hmmm, what's InitData[ 4 ] ... */
184
  GPIFWFSELECT = InitData[ 5 ];
185
  /* GPIFREADYSTAT = InitData[ 6 ]; */  /* I think this register is read only... */
186
 
187
  for (i = 0; i < 128; i++){
188
    GPIF_WAVE_DATA[i] = WaveData[i];
189
  }
190
 
191
  setup_flowstate_common();
192
 
193
  FLOWSTATE = 0;         /* ensure it's off */
194
 
195
  GPIFREADYCFG |= bmINTRDY; /* set the internal ready signal */
196
 
197
  /* unset gpif flags */
198
  flGPIF = 0;
199
 
200
 
201
  EA = 0;                /* disable all interrupts */
202
 
203
  /* hook gpif interupt services */
204
 
205
  /* due to big problems with the done interrupt, we use the WAVEFORM interrupt
206
     to signal the firmware that the GPIF is done */
207
  hook_fgv(FGV_GPIFWF,(unsigned short) isr_gpif_done);
208
  hook_fgv(FGV_EP2PF,(unsigned short) isr_endpoint_out_data);
209
 
210
  EP2FIFOIE = bmFIFO_PF;
211
  GPIFIE = bmGPIFWF;
212
 
213
  EA = 1;               /* global interrupt enable */
214
 
215
 
216
  /* start gpif read, default state of the gpif to wait for fpga data */
217
  gpif_trigger_read();
218
 
219
}
220
 
221
 
222
/** \brief aborts any gpif running gpif transaction  */
223
void abort_gpif(void) {
224
 
225
#ifdef GECKO3MAIN
226
 
227
  /* signal an abort condition to the FPGA */
228
  //if(!(GPIFTRIG & bmGPIF_IDLE)) {
229
  //GPIFREADYCFG &= ~bmINTRDY;
230
  //udelay(10);
231
  //}
232
#endif
233
  EA = 0;                /* disable all interrupts */
234
 
235
  flGPIF = 0;
236
 
237
  GPIFABORT = 0xFF;
238
  SYNCDELAY;
239
  while(!(GPIFTRIG & bmGPIF_IDLE));
240
  print_info("gpif aborted\n");
241
 
242
  EA = 1;               /* global interrupt enable */
243
 
244
 
245
  gpif_trigger_read();
246
}
247
 
248
 
249
/** \brief disables gpif system */
250
void deactivate_gpif(void) {
251
 
252
#ifdef GECKO3MAIN
253
 
254
  /* signal an abort condition to the FPGA */
255
  //if(!(GPIFTRIG & bmGPIF_IDLE)) {
256
  //GPIFREADYCFG &= ~bmINTRDY;
257
  //udelay(10);
258
  //}
259
#endif
260
 
261
 
262
  EA = 0;                /* disable all interrupts */
263
 
264
  EP2FIFOIE = 0;  /* disable FIFO interrupt */
265
  SYNCDELAY;
266
  GPIFIE = 0;     /* disable all GPIF interrupts */
267
  SYNCDELAY;
268
 
269
  GPIFTCB0 = 0x00;
270
  EP2GPIFPFSTOP = 1;
271
  EP6GPIFPFSTOP = 1;
272
 
273
  GPIFABORT = 0xFF; /* abort pending GPIF transaction */
274
  SYNCDELAY;
275
 
276
  flGPIF = 0;  /* unset all internal GPIF flags */
277
 
278
#ifdef GECKO3MAIN
279
  //EP2FIFOCFG &= ~bmOEP;
280
  EP2FIFOCFG &= ~bmAUTOOUT;  /* disable AutoOUT feature */
281
  SYNCDELAY;
282
  //EP6FIFOCFG &= ~bmINFM;
283
  EP6FIFOCFG &= ~bmAUTOIN;   /* disable AutoIN feature */
284
 
285
#endif
286
 
287
  EA = 1;               /* global interrupt enable */
288
 
289
 
290
  print_info("gpif deactivated\n");
291
}

powered by: WebSVN 2.1.0

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