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

Subversion Repositories usb_fpga_2_14

[/] [usb_fpga_2_14/] [trunk/] [examples/] [mmio/] [mmio-2_16.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 2.16
3
   Copyright (C) 2009-2017 ZTEX GmbH.
4
   http://www.ztex.de
5
 
6
   Licensed under the Apache License, Version 2.0 (the "License");
7
   you may not use this file except in compliance with the License.
8
   You may obtain a copy of the License at
9
 
10
       http://www.apache.org/licenses/LICENSE-2.0
11
 
12
   Unless required by applicable law or agreed to in writing, software
13
   distributed under the License is distributed on an "AS IS" BASIS,
14
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
   See the License for the specific language governing permissions and
16
   limitations under the License.
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 2.16 as target (required for FPGA configuration)
27
IDENTITY_UFM_2_16(10.16.0.0,0);
28
 
29
// enables high speed FPGA configuration, (re)use EP 4
30
ENABLE_HS_FPGA_CONF(4);
31
 
32
// this product string is also used for identification by the host software
33
#define[PRODUCT_STRING]["mmio example for UFM 2.16"]
34
 
35
__xdata BYTE run;
36
 
37
#define[PRE_FPGA_RESET][PRE_FPGA_RESET
38
    run = 0;
39
]
40
 
41
#define[POST_FPGA_CONFIG][POST_FPGA_CONFIG
42
    REVCTL = 0x0;       // reset 
43
    SYNCDELAY;
44
 
45
    IFCONFIG = bmBIT7;          // internel 30MHz clock, drive IFCLK ouput, slave FIFO interface
46
    SYNCDELAY;
47
 
48
    EP2CS &= ~bmBIT0;   // stall = 0
49
    SYNCDELAY;
50
    EP4CS &= ~bmBIT0;   // stall = 0
51
    SYNCDELAY;          // first two packages are waste
52
 
53
    EP2FIFOCFG = 0;
54
    SYNCDELAY;
55
    EP4FIFOCFG = 0;
56
    SYNCDELAY;
57
 
58
    FIFORESET = 0x80;   // NAK-ALL
59
    SYNCDELAY;
60
    FIFORESET = 0x84;   // reset EP4
61
    SYNCDELAY;
62
    FIFORESET = 0x02;   // reset EP2, clear EP memory (no NAK bit)
63
    SYNCDELAY;
64
    FIFORESET = 0x00;   // release NAK-ALL
65
    SYNCDELAY;
66
 
67
    EP4BCL = 0x80;      // skip packet, (re)arm EP4
68
    SYNCDELAY;
69
    EP4BCL = 0x80;      // skip packet, (re)arm EP4
70
 
71
    run = 1;
72
]
73
 
74
// include the main part of the firmware kit, define the descriptors, ...
75
#include[ztex.h]
76
 
77
 
78
__xdata __at 0x5001 volatile BYTE OUT_REG;      // FPGA register where the data is written to
79
__xdata __at 0x5002 volatile BYTE IN_REG;       // FPGA register where the result is read from
80
 
81
 
82
void main(void)
83
{
84
    WORD i,size;
85
 
86
// init everything
87
    init_USB();
88
 
89
    while (1) {
90
        if ( run & !(EP4CS & bmBIT2) ) {        // EP4 is not empty
91
            size = (EP4BCH << 8) | EP4BCL;
92
            if ( size>0 && size<=512 && !(EP2CS & bmBIT3)) {     // EP2 is not full
93
                for ( i=0; i<size; i++ ) {
94
                    OUT_REG = EP4FIFOBUF[i];    // data from EP4 is converted to uppercase by the FPGA ...
95
                    EP2FIFOBUF[i] = IN_REG;     // ... and written back to EP2 buffer
96
                }
97
                EP2BCH = size >> 8;
98
                SYNCDELAY;
99
                EP2BCL = size & 255;            // arm EP2
100
                SYNCDELAY;
101
                INPKTEND = 0x2;
102
            }
103
            SYNCDELAY;
104
            EP4BCL = 0x80;                      // (re)arm EP4
105
        }
106
    }
107
}

powered by: WebSVN 2.1.0

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