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-utils.h] - 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
   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
   Various utility routines
21
*/
22
 
23
#ifndef[ZTEX_UTILS_H]
24
#define[ZTEX_UTILS_H]
25
 
26
#define[bmBIT0][1]
27
#define[bmBIT1][2]
28
#define[bmBIT2][4]
29
#define[bmBIT3][8]
30
#define[bmBIT4][16]
31
#define[bmBIT5][32]
32
#define[bmBIT6][64]
33
#define[bmBIT7][128]
34
 
35
#define[NOP;][_asm 
36
        nop
37
    _endasm;
38
]
39
 
40
#define[MSB(][)][((BYTE)(((unsigned short)($0)) >> 8))]
41
#define[LSB(][)][((BYTE)($0))]
42
#define[HI(][)][((BYTE)(((unsigned short)($0)) >> 8))]
43
#define[LO(][)][((BYTE)($0))]
44
 
45
typedef unsigned char BYTE;
46
typedef unsigned short WORD;
47
typedef unsigned long DWORD;
48
 
49 3 ZTEX
#include[ezregs.h]
50
#include[ezintavecs.h]
51 2 ZTEX
/* *********************************************************************
52 3 ZTEX
   ***** global variables **********************************************
53 2 ZTEX
   ********************************************************************* */
54 3 ZTEX
/*
55
    The following two variables are used to control HSNAK bit.
56
 
57
    ep0_payload_remaining is set to the length field of of the Setup Data
58
    structure (in SUDAV_ISR). At the begin of each payload data transfer (in
59
    SUDAV_ISR, EP0IN_ISR and EP0OUT_ISR) the amount of payload of the current
60
    transfer s calculated (<=64 bytes) and subtracted from
61
    ep0_payload_remaining. For Vendor Commands HSNAK bit is cleared
62
    automatically (at the end of EP0OUT_ISR) ifep0_payload_remaining == 0.
63
    For Vendor Requests HSNAK bit is always cleared at the end of SUDAV_ISR.
64
*/
65 2 ZTEX
 
66 3 ZTEX
xdata WORD ep0_payload_remaining = 0;            // remaining amount of ep0 payload data (excluding the data of the current transfer)
67
xdata BYTE ep0_payload_transfer = 0;             // transfer
68
 
69 2 ZTEX
/* *********************************************************************
70 3 ZTEX
   *********************************************************************
71
   ***** basic functions ***********************************************
72
   *********************************************************************
73
   ********************************************************************* */
74
 
75
/* *********************************************************************
76 2 ZTEX
   ***** wait **********************************************************
77
   ********************************************************************* */
78
void wait(WORD short ms) {        // wait in ms 
79
    WORD i,j;
80
    for (j=0; j<ms; j++)
81
        for (i=0; i<1200; i++);
82
}
83
 
84
 
85
/* *********************************************************************
86
   ***** uwait *********************************************************
87
   ********************************************************************* */
88
void uwait(WORD short us) {       // wait in 10µs steps
89
    WORD i,j;
90
    for (j=0; j<us; j++)
91 3 ZTEX
        for (i=0; i<10; i++);
92 2 ZTEX
}
93
 
94
 
95
/* *********************************************************************
96
   ***** MEM_COPY ******************************************************
97
   ********************************************************************* */
98
// copies 1..256 bytes 
99
void MEM_COPY1_int() __naked {
100
        _asm
101
020001$:
102
            mov         _AUTOPTRSETUP,#0x07
103
            mov         dptr,#_XAUTODAT1
104
            movx        a,@dptr
105
            mov         dptr,#_XAUTODAT2
106
            movx        @dptr,a
107
            djnz        r2, 020001$
108
            ret
109
        _endasm;
110
}
111
 
112
/*
113
    ! no spaces before/after commas allowed !
114
 
115
    This will work too:
116
        MEM_COPY1(fpga_checksum,EP0BUF+1,6);
117
*/
118
 
119
#define[MEM_COPY1(][,$1,$2);][{
120
        _asm
121 3 ZTEX
                push    ar2
122 2 ZTEX
                mov     _AUTOPTRL1,#(_$0)
123
                mov     _AUTOPTRH1,#((_$0) >> 8)
124
                mov     _AUTOPTRL2,#(_$1)
125
                mov     _AUTOPTRH2,#((_$1) >> 8)
126
                mov     r2,#($2);
127 3 ZTEX
                lcall   _MEM_COPY1_int
128
                pop     ar2
129 2 ZTEX
        _endasm;
130
}]
131
 
132
 
133
#endif // ZTEX_UTILS_H

powered by: WebSVN 2.1.0

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