Fx2lib  0.2
Defines | Enumerations | Functions
include/eputils.h File Reference
#include <assert.h>
#include "fx2types.h"
#include "fx2macros.h"

Go to the source code of this file.

Defines

#define STALLEP0()   EP0CS |= bmEPSTALL
#define RESETTOGGLE(ep)
 Reset the toggle on an endpoint. To use this, the endpoint needs bit 8 to be IN=1,OUT=0.
#define RESETFIFO(ep)
#define RESETFIFOS()
#define ep0_load_sudptr(src)
#define ep0_mode(mode_data, mode_length)
#define ep0_busywait()   while (EP0CS & bmEPBUSY) printf("w\n");
#define ep0_load_length(len)   LOADWORD(EP0BC, len);
#define ep0_arm()   ep0_load_length(0);
#define ep0_get_length()   EP0BCL

Enumerations

enum  ep0_mode_data { EP0_DATA_AUTO = 0, EP0_DATA_MANUAL = 1 }
enum  ep0_mode_length { EP0_LENGTH_AUTO = 1, EP0_LENGTH_MANUAL = 0 }

Functions

void readep0 (BYTE *dst, WORD len)
void writeep0 (BYTE *src, WORD len)
void ep0_send_auto (__xdata BYTE *src, WORD len)
void ep0_send_byte (BYTE data)
void ep0_send_word (WORD data)
BYTE ep0_recv ()

Detailed Description

Functions and macros for working with endpoints.

Definition in file eputils.h.


Define Documentation

#define ep0_arm ( )    ep0_load_length(0);

Definition at line 130 of file eputils.h.

#define ep0_busywait ( )    while (EP0CS & bmEPBUSY) printf("w\n");

Definition at line 124 of file eputils.h.

#define ep0_get_length ( )    EP0BCL

Definition at line 134 of file eputils.h.

#define ep0_load_length (   len)    LOADWORD(EP0BC, len);

Definition at line 127 of file eputils.h.

#define ep0_load_sudptr (   src)
Value:
assert( \
                (((WORD)src) <= 0x3FFF) || \
                (((WORD)src) >= 0xE000 && ((WORD)src) <= 0xE1FF)); \
        assert(!(LSB(src) & bmBIT0)); \
        LOADWORD(SUDPTR, src);

Definition at line 96 of file eputils.h.

#define ep0_mode (   mode_data,
  mode_length 
)
Value:
assert(!(mode_data & mode_length)); \
        SUDPTRCTL = mode_data | mode_length;

Definition at line 120 of file eputils.h.

#define RESETFIFO (   ep)
Value:
{FIFORESET=0x80; SYNCDELAY;\
                       FIFORESET=0x80 | ep; SYNCDELAY;\
                       FIFORESET=0x00; SYNCDELAY;}

RESETFIFO should not use 0x80|epnum for IN endpoints Only use 0x02, 0x04, 0x06, 0x06 for ep value

Definition at line 66 of file eputils.h.

#define RESETFIFOS ( )
Value:
{FIFORESET=0x80; SYNCDELAY;\
                     FIFORESET=0x82; SYNCDELAY;\
                     FIFORESET=0x84; SYNCDELAY;\
                     FIFORESET=0x86; SYNCDELAY;\
                     FIFORESET=0x88; SYNCDELAY;\
                     FIFORESET=0x00; SYNCDELAY;}

Quickly reset all endpoint FIFOS.

Definition at line 72 of file eputils.h.

#define RESETTOGGLE (   ep)
Value:
do {\
        BYTE x = ep; \
        if (x&0x80) { x |= 0x10; } \
        x &= 0x1F; \
        TOGCTL = x; \
        TOGCTL = x | bmRESETTOGGLE; \
} while (0)

Reset the toggle on an endpoint. To use this, the endpoint needs bit 8 to be IN=1,OUT=0.

Definition at line 53 of file eputils.h.

#define STALLEP0 ( )    EP0CS |= bmEPSTALL

NOTE you can't use these unless you define SYNCDELAY as a macro or function. The reason is that SYNCDELAY needs to be longer or shorter depending on your IFCONFIG settings. See delay.h

Example:

  #define SYNCDELAY SYNCDELAY4 // SYNCDELAY4 from delay.h

Stalls EP0.

Definition at line 47 of file eputils.h.


Enumeration Type Documentation

Enumerator:
EP0_DATA_AUTO 
EP0_DATA_MANUAL 

Definition at line 111 of file eputils.h.

Enumerator:
EP0_LENGTH_AUTO 
EP0_LENGTH_MANUAL 

Definition at line 115 of file eputils.h.


Function Documentation

void ep0_send_auto ( __xdata BYTE src,
WORD  len 
)
void ep0_send_byte ( BYTE  data)
void ep0_send_word ( WORD  data)
void readep0 ( BYTE dst,
WORD  len 
)

Continually read available bytes from endpoint0 into dst, wait until more bytes are available, and loop until len bytes have been read.

void writeep0 ( BYTE src,
WORD  len 
)

Write bytes from src to ep0, allowing host to transfer data between 64 byte blocks.