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

Subversion Repositories usb_fpga_2_04

[/] [usb_fpga_2_04/] [trunk/] [examples/] [usb-fpga-1.15/] [1.15d/] [mmio/] [ucecho.c] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 ZTEX
/*!
2
   mmio -- Memory mapped I/O example for ZTEX USB-FPGA Module 1.15d and 1.15x
3
   Copyright (C) 2009-2014 ZTEX GmbH.
4
   http://www.ztex.de
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 version 3 as
8
   published by the Free Software Foundation.
9
 
10
   This program is distributed in the hope that it will be useful, but
11
   WITHOUT ANY WARRANTY; without even the implied warranty of
12
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
   General Public License for more details.
14
 
15
   You should have received a copy of the GNU General Public License
16
   along with this program; if not, see http://www.gnu.org/licenses/.
17
!*/
18
 
19
#include[ztex-conf.h]   // Loads the configuration macros, see ztex-conf.h for the available macros
20
#include[ztex-utils.h]  // include basic functions
21
 
22
// configure endpoints 2 and 4, both belong to interface 0 (in/out are from the point of view of the host)
23
EP_CONFIG(2,0,BULK,IN,512,2);
24
EP_CONFIG(4,0,BULK,OUT,512,2);
25
 
26
// select ZTEX USB FPGA Module 1.15 as target (required for FPGA configuration)
27
IDENTITY_UFM_1_15(10.13.0.0,0);
28
ENABLE_UFM_1_15X_DETECTION;      // avoids some warnings
29
 
30
// enables high speed FPGA configuration, (re)use EP 4
31
ENABLE_HS_FPGA_CONF(4);
32
 
33
// this product string is also used for identification by the host software
34
#define[PRODUCT_STRING]["memeory mapping example for UFM 1.15"]
35
 
36
__xdata BYTE run;
37
 
38
#define[PRE_FPGA_RESET][PRE_FPGA_RESET
39
    run = 0;
40
]
41
 
42
#define[POST_FPGA_CONFIG][POST_FPGA_CONFIG
43
    IFCONFIG = bmBIT7;          // internel 30MHz clock, drive IFCLK ouput, slave FIFO interface
44
    SYNCDELAY;
45
    EP2FIFOCFG = 0;
46
    SYNCDELAY;
47
    EP4FIFOCFG = 0;
48
    SYNCDELAY;
49
 
50
    REVCTL = 0x0;       // reset 
51
    SYNCDELAY;
52
    EP2CS &= ~bmBIT0;   // stall = 0
53
    SYNCDELAY;
54
    EP4CS &= ~bmBIT0;   // stall = 0
55
 
56
    SYNCDELAY;          // first two packages are waste
57
    EP4BCL = 0x80;      // skip package, (re)arm EP4
58
    SYNCDELAY;
59
    EP4BCL = 0x80;      // skip package, (re)arm EP4
60
 
61
    FIFORESET = 0x80;   // reset FIFO
62
    SYNCDELAY;
63
    FIFORESET = 0x82;
64
    SYNCDELAY;
65
    FIFORESET = 0x00;
66
    SYNCDELAY;
67
 
68
    run = 1;
69
]
70
 
71
// include the main part of the firmware kit, define the descriptors, ...
72
#include[ztex.h]
73
 
74
 
75
__xdata __at 0x5001 volatile BYTE OUT_REG;      // FPGA register where the data is written to
76
__xdata __at 0x5002 volatile BYTE IN_REG;       // FPGA register where the result is read from
77
 
78
 
79
void main(void)
80
{
81
    WORD i,size;
82
 
83
// init everything
84
    init_USB();
85
 
86
    while (1) {
87
        if ( run & !(EP4CS & bmBIT2) ) {        // EP4 is not empty
88
            size = (EP4BCH << 8) | EP4BCL;
89
            if ( size>0 && size<=512 && !(EP2CS & bmBIT3)) {     // EP2 is not full
90
                for ( i=0; i<size; i++ ) {
91
                    OUT_REG = EP4FIFOBUF[i];    // data from EP4 is converted to uppercase by the FPGA ...
92
                    EP2FIFOBUF[i] = IN_REG;     // ... and written back to EP2 buffer
93
                }
94
                EP2BCH = size >> 8;
95
                SYNCDELAY;
96
                EP2BCL = size & 255;            // arm EP2
97
                SYNCDELAY;
98
                INPKTEND = 0x2;
99
            }
100
            SYNCDELAY;
101
            EP4BCL = 0x80;                      // (re)arm EP4
102
        }
103
    }
104
}

powered by: WebSVN 2.1.0

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