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

Subversion Repositories usb_fpga_2_13

[/] [usb_fpga_2_13/] [trunk/] [examples/] [usb-xmega-1.0/] [ucecho/] [ucecho.c] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 ZTEX
/*!
2
   ucecho -- uppercase conversion example for ZTEX USB-XMEGA Module 1.0
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-XMEGA Module 1.0 as target
27
IDENTITY_UXM_1_0(10.30.0.0,0);
28
 
29
// this product string is also used for identification by the host software
30
#define[PRODUCT_STRING]["ucecho example for USB-XMEGA Modules"]
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;
38
 
39
// init everything
40
    init_USB();
41
 
42
    OEB = 0;             // PORT B is input
43
    OED = 255;          // PORT D is output
44
 
45
    EP2CS &= ~bmBIT0;   // stall = 0
46
    SYNCDELAY;
47
    EP4CS &= ~bmBIT0;   // stall = 0
48
 
49
    SYNCDELAY;          // first two packages are waste
50
    EP4BCL = 0x80;      // skip package, (re)arm EP4
51
    SYNCDELAY;
52
    EP4BCL = 0x80;      // skip package, (re)arm EP4
53
 
54
    FIFORESET = 0x80;   // reset FIFO
55
    SYNCDELAY;
56
    FIFORESET = 2;
57
    SYNCDELAY;
58
    FIFORESET = 0x00;
59
    SYNCDELAY;
60
 
61
    while (1) {
62
        if ( !(EP4CS & bmBIT2) ) {                              // EP4 is not empty
63
            size = (EP4BCH << 8) | EP4BCL;
64
            if ( size>0 && size<=512 && !(EP2CS & bmBIT3)) {     // EP2 is not full
65
                for ( i=0; i<size; i++ ) {
66
                    IOD = EP4FIFOBUF[i];        // data from EP4 is converted to uppercase by the XMEGA ...
67
                    uwait(1);                   // wait 10µs
68
                    EP2FIFOBUF[i] = IOB;        // ... and written back to EP2 buffer
69
                }
70
                EP2BCH = size >> 8;
71
                SYNCDELAY;
72
                EP2BCL = size & 255;            // arm EP2
73
            }
74
            SYNCDELAY;
75
            EP4BCL = 0x80;                      // skip package, (re)arm EP4
76
        }
77
    }
78
}
79
 

powered by: WebSVN 2.1.0

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