]> sigrok.org Git - sigrok-firmware-fx2lafw.git/blob - fx2lib/include/eputils.h
Add Hantek PSO2020 firmware support
[sigrok-firmware-fx2lafw.git] / fx2lib / include / eputils.h
1 // Copyright (C) 2009 Ubixum, Inc. 
2 // 
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 // 
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 // 
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, see <http://www.gnu.org/licenses/>.
15
16 /*! \file 
17  *  Functions and macros for working with endpoints.
18  * */
19
20 #ifndef EPUTILS_H
21 #define EPUTILS_H
22
23 #include "fx2types.h"
24
25 /**
26  * NOTE you can't use these unless you define SYNCDELAY 
27  * as a macro or function.  The reason is that SYNCDELAY
28  * needs to be longer or shorter depending on your IFCONFIG
29  * settings.  
30  * See delay.h
31  *
32  * Example:
33  * \code
34  *  #define SYNCDELAY() SYNCDELAY4 // SYNCDELAY4 from delay.h
35  * \endcode
36  *
37  *
38  **/
39
40 /**
41  * Stalls EP0.
42  **/
43 #define STALLEP0() EP0CS |= bmEPSTALL
44
45 /**
46  * \brief Reset the toggle on an endpoint.
47  * To use this, the endpoint needs bit 8 to be IN=1,OUT=0
48  **/
49 #define RESETTOGGLE(ep) TOGCTL = (ep&0x0F) + ((ep&0x80)>>3); TOGCTL |= bmRESETTOGGLE
50
51
52 /**
53  * RESETFIFO should not use 0x80|epnum for IN endpoints
54  * Only use 0x02, 0x04, 0x06, 0x06 for ep value
55  **/
56 #define RESETFIFO(ep) {FIFORESET=0x80; SYNCDELAY();\
57                        FIFORESET=ep; SYNCDELAY();\
58                        FIFORESET=0x00; SYNCDELAY();}
59 /**
60  * Quickly reset all endpoint FIFOS.
61  **/
62 #define RESETFIFOS() {FIFORESET=0x80; SYNCDELAY();\
63                      FIFORESET=0x02; SYNCDELAY();\
64                      FIFORESET=0x04; SYNCDELAY();\
65                      FIFORESET=0x06; SYNCDELAY();\
66                      FIFORESET=0x08; SYNCDELAY();\
67                      FIFORESET=0x00; SYNCDELAY();}
68
69 /**
70  * Continually read available bytes from endpoint0 into dst, wait
71  * until more bytes are available, and loop until len bytes have 
72  * been read.
73  **/
74 void readep0( BYTE* dst, WORD len );
75
76
77 /**
78  * Write bytes from src to ep0, allowing host to transfer data
79  * between 64 byte blocks.
80  **/
81 void writeep0 ( BYTE* src, WORD len );
82
83
84
85 #endif