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/] [include/] [ztex.h] - Blame information for rev 2

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

Line No. Rev Author Line
1 2 ZTEX
/*!
2
   ZTEX Firmware Kit for EZ-USB Microcontrollers
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
/*
20
   Puts everything in the right order together.
21
*/
22
 
23
#ifndef[ZTEX_H]
24
#define[ZTEX_H]
25
 
26
/* *********************************************************************
27
   ***** include the basic functions ***********************************
28
   ********************************************************************* */
29
#include[ztex-utils.h]
30
 
31
 
32
/* *********************************************************************
33
   ***** Flash memory support ******************************************
34
   ********************************************************************* */
35
#ifeq[FLASH_ENABLED][1]
36
#ifeq[PRODUCT_IS][UFM-1_1]
37
#include[ztex-flash1.h]
38
#elifeq[PRODUCT_IS][UFM-1_2]
39
#include[ztex-flash1.h]
40
#else
41
#warning[FLASH option is not supported by this product]
42
#define[FLASH_ENABLED][0]
43
#endif
44
#endif
45
 
46
 
47
/* *********************************************************************
48
   ***** EEPROM support and some I2c helper functions ******************
49
   ********************************************************************* */
50
#ifneq[EEPROM_DISABLED][1]
51
#include[ztex-eeprom.h]
52
#endif
53
 
54
/* *********************************************************************
55
   ***** FPGA configuration support ************************************
56
   ********************************************************************* */
57
#ifeq[PRODUCT_IS][UFM-1_0]
58
#include[ztex-fpga.h]
59
#elifeq[PRODUCT_IS][UFM-1_1]
60
#include[ztex-fpga.h]
61
#elifeq[PRODUCT_IS][UFM-1_2]
62
#include[ztex-fpga.h]
63
#endif
64
 
65
/* *********************************************************************
66
   ***** define the descriptors and the interrupt routines *************
67
   ********************************************************************* */
68
#include[ztex-descriptors.h]
69
#include[ztex-isr.h]
70
 
71
 
72
/* *********************************************************************
73
   ***** init_USB ******************************************************
74
   ********************************************************************* */
75
#define[EPXCFG(][);][    EP$0CFG = 
76
#ifeq[EP$0_DIR][IN]
77
        bmBIT7 | bmBIT6
78
#elifeq[EP$0_DIR][OUT]
79
        bmBIT7
80
#else
81
 
82
#endif
83
#ifeq[EP$0_TYPE][BULK]
84
        | bmBIT5
85
#elifeq[EP$0_TYPE][ISO]
86
        | bmBIT4
87
#elifeq[EP$0_TYPE][INT]
88
        | bmBIT5 | bmBIT4
89
#endif
90
#ifeq[EP$0_SIZE][1024]
91
        | bmBIT3
92
#endif
93
#ifeq[EP$0_BUFFERS][2]
94
        | bmBIT1
95
#elifeq[EP$0_BUFFERS][3]
96
        | bmBIT1 | bmBIT0
97
#endif  
98
        ;
99
        SYNCDELAY;
100
]
101
 
102
#define[EP1XCFG(][);][#ifeq[EP$0_TYPE][BULK]
103
        EP$0CFG = bmBIT7 | bmBIT5;
104
#elifeq[EP$0_TYPE][ISO]
105
        EP$0CFG = bmBIT7 | bmBIT4;
106
#elifeq[EP$0_TYPE][INT]
107
        EP$0CFG = bmBIT7 | bmBIT5 | bmBIT4;
108
#else   
109
        EP$0CFG = 0;
110
#endif
111
        SYNCDELAY;
112
]
113
 
114
void init_USB ()
115
{
116
 
117
    CPUCS = bmBIT4 | bmBIT1;
118
    CKCON &= ~7;
119
 
120
    IOA1 = 1;
121
    OEA |= bmBIT1;
122
 
123
    EA = 0;
124
 
125
    ENABLE_AVUSB;
126
 
127
    INIT_INTERRUPT_VECTOR(INTVEC_SUDAV, SUDAV_ISR);
128
    INIT_INTERRUPT_VECTOR(INTVEC_SOF, SOF_ISR);
129
    INIT_INTERRUPT_VECTOR(INTVEC_SUTOK, SUTOK_ISR);
130
    INIT_INTERRUPT_VECTOR(INTVEC_SUSPEND, SUSP_ISR);
131
    INIT_INTERRUPT_VECTOR(INTVEC_USBRESET, URES_ISR);
132
    INIT_INTERRUPT_VECTOR(INTVEC_HISPEED, HSGRANT_ISR);
133
    INIT_INTERRUPT_VECTOR(INTVEC_EP0ACK, EP0ACK_ISR);
134
 
135
    INIT_INTERRUPT_VECTOR(INTVEC_EP0IN, EP0IN_ISR);
136
    INIT_INTERRUPT_VECTOR(INTVEC_EP0OUT, EP0OUT_ISR);
137
    INIT_INTERRUPT_VECTOR(INTVEC_EP1IN, EP1IN_ISR);
138
    INIT_INTERRUPT_VECTOR(INTVEC_EP1OUT, EP1OUT_ISR);
139
    INIT_INTERRUPT_VECTOR(INTVEC_EP2, EP2_ISR);
140
    INIT_INTERRUPT_VECTOR(INTVEC_EP4, EP4_ISR);
141
    INIT_INTERRUPT_VECTOR(INTVEC_EP6, EP6_ISR);
142
    INIT_INTERRUPT_VECTOR(INTVEC_EP8, EP8_ISR);
143
 
144
    EXIF &= ~bmBIT4;
145
    USBIRQ = 0x7f;
146
    USBIE |= 0x7f;
147
    EPIRQ = 0xff;
148
    EPIE = 0xff;
149
 
150
    EUSB = 1;
151
    EA = 1;
152
 
153
    USBCS |= 0x08;
154
    USBCS |= bmBIT7 | bmBIT1;
155
    wait(500);
156
    USBCS &= ~0x08;
157
    wait(500);
158
 
159
    EP1XCFG(1IN);
160
    EP1XCFG(1OUT);
161
    EPXCFG(2);
162
    EPXCFG(4);
163
    EPXCFG(6);
164
    EPXCFG(8);
165
}
166
 
167
#endif   /* ZTEX_H */

powered by: WebSVN 2.1.0

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