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/] [fx2demo/] [fx2demo.c] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 ZTEX
/*%
2
   fx2demo -- Demonstrates common features of the FX2
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
// define 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
// thin initializes the debug helper with a 32 messages stack and 4 bytes per message
27
ENABLE_DEBUG(32,4);
28
 
29
// this product string is also used for identification by the host software
30
#define[PRODUCT_STRING]["fx2demo for EZ-USB devices"]
31
 
32
// include the main part of the firmware kit, define the descriptors, ...
33
#include[ztex.h]
34
 
35
void main(void)
36
{
37
    WORD i,size,j;
38
    BYTE b;
39
 
40
// init everything
41
    init_USB();
42
 
43
    REVCTL = 0x0;
44
    SYNCDELAY;
45
 
46
    IFCONFIG = bmBIT7;  // Internal source, 48MHz
47
    SYNCDELAY;
48
 
49
    EP2CS &= ~bmBIT0;   // stall = 0
50
    SYNCDELAY;
51
    EP4CS &= ~bmBIT0;   // stall = 0
52
    SYNCDELAY;
53
 
54
    EP2FIFOCFG = 0;
55
    SYNCDELAY;
56
    EP4FIFOCFG = 0;
57
    SYNCDELAY;
58
 
59
    FIFORESET = 0x80;   // NAK-ALL
60
    SYNCDELAY;
61
    FIFORESET = 0x84;   // reset EP4
62
    SYNCDELAY;
63
    FIFORESET = 0x02;   // reset EP2, clear EP memory (no NAK bit)
64
    SYNCDELAY;
65
    FIFORESET = 0x00;   // release NAK-ALL
66
    SYNCDELAY;
67
 
68
    EP4BCL = 0x80;      // skip package, (re)arm EP4
69
    SYNCDELAY;
70
    EP4BCL = 0x80;      // skip package, (re)arm EP4
71
    SYNCDELAY;
72
 
73
    while (1) {
74
        if ( !(EP4CS & bmBIT2) ) {                              // EP4 is not empty
75
            size = (EP4BCH << 8) | EP4BCL;
76
            if ( size>0 && size<=512 && !(EP2CS & bmBIT3)) {     // EP2 is not full
77
                j = 0;
78
                for ( i=0; i<size; i++ ) {
79
                    b = EP4FIFOBUF[i];          // data from EP4 ... 
80
                    if ( b>=(BYTE)'a' && b<=(BYTE)'z' ) {       // ... is converted to uppercase ...
81
                        b-=32;
82
                        j++;
83
                    }
84
                    EP2FIFOBUF[i] = b;          // ... and written back to EP2 buffer
85
                }
86
 
87
                debug_msg_buf[0] = size; // write statistics to the debug buffer
88
                debug_msg_buf[1] = size >> 8;
89
                debug_msg_buf[2] = j;
90
                debug_msg_buf[3] = j >> 8;
91
                debug_add_msg();
92
 
93
                EP2BCH = size >> 8;
94
                SYNCDELAY;
95
                EP2BCL = size & 255;            // arm EP2
96
            }
97
            SYNCDELAY;
98
            EP4BCL = 0x80;                      // skip package, (re)arm EP4
99
        }
100
    }
101
}
102
 
103
 

powered by: WebSVN 2.1.0

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