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

Subversion Repositories usb_fpga_1_2

[/] [usb_fpga_1_2/] [trunk/] [examples/] [usb-fpga-1.2/] [ucecho/] [ucecho.c] - Blame information for rev 3

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

Line No. Rev Author Line
1 2 ZTEX
/*!
2
   ucecho -- example for ZTEX USB FPGA Module 1.2
3
   Copyright (C) 2008-2009 ZTEX e.K.
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
// Cypress vendor ID and product ID may only (!) be used for experimental purposes
23
SET_VPID(0x4b4,0x8613);
24
 
25
// define endpoints 2 and 4, both belong to interface 0 (in/out are from the point of view of the host)
26
EP_CONFIG(2,0,BULK,IN,512,2);
27
EP_CONFIG(4,0,BULK,OUT,512,2);
28
 
29 3 ZTEX
// select ZTEX USB FPGA Module 1.2 as target  (Important for FPGA configuration)
30
IDENTITY_UFM_1_2(10.11.0.0,0);
31 2 ZTEX
 
32
// give them a nice name
33
#define[PRODUCT_STRING]["ucecho for USB FPGA MODULE 1.2"]
34
 
35
// this is called automatically after FPGA configuration
36
#define[POST_FPGA_CONFIG][POST_FPGA_CONFIG
37
        OEC = 255;
38
]
39
 
40
// include the main part of the firmware kit, define the descriptors, ...
41
#include[ztex.h]
42
 
43
 
44
void main(void)
45
{
46
    WORD i,size;
47
 
48
// init everything
49
    init_USB();
50
 
51
    EP2CS &= ~bmBIT0;   // stall = 0
52
    SYNCDELAY;
53
    EP4CS &= ~bmBIT0;   // stall = 0
54
 
55
    SYNCDELAY;          // first two packages are waste
56
    EP4BCL = 0x80;      // skip package, (re)arm EP4
57
    SYNCDELAY;
58
    EP4BCL = 0x80;      // skip package, (re)arm EP4
59
 
60
    while (1) {
61
        if ( !(EP4CS & bmBIT2) ) {                              // EP4 is not empty
62
            size = (EP4BCH << 8) | EP4BCL;
63
            if ( size>0 && size<=512 && !(EP2CS & bmBIT3)) {     // EP2 is not full
64
                for ( i=0; i<size; i++ ) {
65
                    IOC = EP4FIFOBUF[i];        // data from EP4 is converted to uppercase by the FPGA ...
66
                    EP2FIFOBUF[i] = IOB;        // ... and written back to EP2 buffer
67
                }
68
                EP2BCH = size >> 8;
69
                SYNCDELAY;
70
                EP2BCL = size & 255;            // arm EP2
71
            }
72
            SYNCDELAY;
73
            EP4BCL = 0x80;                      // skip package, (re)arm EP4
74
        }
75
    }
76
}
77
 

powered by: WebSVN 2.1.0

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