Fx2lib  0.2
Defines | Enumerations
include/fx2macros.h File Reference
#include "fx2regs.h"
#include "fx2types.h"

Go to the source code of this file.

Defines

#define MSB(addr)   (BYTE)(((WORD)(addr) >> 8) & 0xff)
#define LSB(addr)   (BYTE)((WORD)(addr) & 0xff)
#define MAKEWORD(msb, lsb)   (((WORD)msb << 8) | lsb)
#define MSW(dword)   (WORD)((dword >> 16) & 0xffff)
#define LSW(dword)   (WORD)(dword & 0xffff)
#define MAKEDWORD(msw, lsw)   (((DWORD)msw << 16) | lsw)
#define LOADWORD(reg, value)
#define CPUFREQ   (CLK_SPD)((CPUCS & bmCLKSPD) >> 3)
 Evaluates to a CLK_SPD enum.
#define SETCPUFREQ(SPD)   CPUCS = (CPUCS & ~bmCLKSPD) | (SPD << 3)
 Sets the cpu to operate at a specific clock speed.
#define XTAL
 Evaluates to a DWORD value representing the clock speed in cycles per second.
#define I2CFREQ   ((I2CTL & bm400KHZ) ? 400000L : 100000L)
 Evaluates to the i2c bus frequency in cyles per second.
#define IFFREQ   (IFCONFIG & bm3048MHZ ? 48000000L : 30000000L)
#define SETIF30MHZ()   IFCONFIG &= ~bm3048MHZ
#define SETIF48MHZ()   IFCONFIG |= bm3048MHZ
#define EEPROM_TWO_BYTE   (I2CS & bmBIT4)
#define RENUMERATE_UNCOND()   USBCS|=bmDISCON|bmRENUM;delay(1500);USBCS&=~bmDISCON
 Cause the device to disconnect and reconnect to USB. This macro unconditionally renumerates the device no matter how the firmware is loaded.
#define RENUMERATE()   if(!(USBCS&bmRENUM)) {USBCS|=bmDISCON|bmRENUM;delay(1500);USBCS &= ~bmDISCON;}
 Cause the device to disconnect and reconnect to the USB bus. This macro doesn't do anything if the firmware is loaded from an eeprom.
#define HISPEED   (USBCS&bmHSM)
 TRUE if the FX2 has transitioned to high speed on the USB bus..
#define REMOTE_WAKEUP()   (((WAKEUPCS & bmWU) && (WAKEUPCS & bmWUEN)) || ((WAKEUPCS & bmWU2) && (WAKEUPCS & bmWU2EN)))
 Evaluates to TRUE if a remote wakeup event has occurred.

Enumerations

enum  CLK_SPD { CLK_12M = 0, CLK_24M, CLK_48M }
 Used for getting and setting the CPU clock speed. More...

Detailed Description

Macros for simple common tasks in fx2 firmware.

Definition in file fx2macros.h.


Define Documentation

#define CPUFREQ   (CLK_SPD)((CPUCS & bmCLKSPD) >> 3)

Evaluates to a CLK_SPD enum.

Definition at line 52 of file fx2macros.h.

#define EEPROM_TWO_BYTE   (I2CS & bmBIT4)

Definition at line 93 of file fx2macros.h.

#define HISPEED   (USBCS&bmHSM)

TRUE if the FX2 has transitioned to high speed on the USB bus..

Definition at line 123 of file fx2macros.h.

#define I2CFREQ   ((I2CTL & bm400KHZ) ? 400000L : 100000L)

Evaluates to the i2c bus frequency in cyles per second.

Speeds:

  • 400000L
  • 100000L

Definition at line 84 of file fx2macros.h.

#define IFFREQ   (IFCONFIG & bm3048MHZ ? 48000000L : 30000000L)

Definition at line 87 of file fx2macros.h.

#define LOADWORD (   reg,
  value 
)
Value:
reg ## H = MSB(value); \
    reg ## L = LSB(value);

Load a word register (such as the data pointers), high byte then low byte.

Definition at line 38 of file fx2macros.h.

#define LSB (   addr)    (BYTE)((WORD)(addr) & 0xff)

Definition at line 28 of file fx2macros.h.

#define LSW (   dword)    (WORD)(dword & 0xffff)

Definition at line 32 of file fx2macros.h.

#define MAKEDWORD (   msw,
  lsw 
)    (((DWORD)msw << 16) | lsw)

Definition at line 33 of file fx2macros.h.

#define MAKEWORD (   msb,
  lsb 
)    (((WORD)msb << 8) | lsb)

Definition at line 29 of file fx2macros.h.

#define MSB (   addr)    (BYTE)(((WORD)(addr) >> 8) & 0xff)

Definition at line 27 of file fx2macros.h.

#define MSW (   dword)    (WORD)((dword >> 16) & 0xffff)

Definition at line 31 of file fx2macros.h.

#define REMOTE_WAKEUP ( )    (((WAKEUPCS & bmWU) && (WAKEUPCS & bmWUEN)) || ((WAKEUPCS & bmWU2) && (WAKEUPCS & bmWU2EN)))

Evaluates to TRUE if a remote wakeup event has occurred.

Examples:
fw.c.

Definition at line 131 of file fx2macros.h.

#define RENUMERATE ( )    if(!(USBCS&bmRENUM)) {USBCS|=bmDISCON|bmRENUM;delay(1500);USBCS &= ~bmDISCON;}

Cause the device to disconnect and reconnect to the USB bus. This macro doesn't do anything if the firmware is loaded from an eeprom.

Examples:
fw.c.

Definition at line 111 of file fx2macros.h.

Cause the device to disconnect and reconnect to USB. This macro unconditionally renumerates the device no matter how the firmware is loaded.

NOTE Windows really doesn't like this if the firmware is loaded from an eeprom. You'll see information messages about the device not working properly. On the other hand, if you are changing the device descriptor, e.g., the vendor and product id, when downloading firmware to the device, you'll need to use this macro instead of the standard RENUMERATE macro.

Definition at line 106 of file fx2macros.h.

#define SETCPUFREQ (   SPD)    CPUCS = (CPUCS & ~bmCLKSPD) | (SPD << 3)

Sets the cpu to operate at a specific clock speed.

Examples:
fw.c.

Definition at line 57 of file fx2macros.h.

#define SETIF30MHZ ( )    IFCONFIG &= ~bm3048MHZ

Definition at line 88 of file fx2macros.h.

#define SETIF48MHZ ( )    IFCONFIG |= bm3048MHZ

Definition at line 89 of file fx2macros.h.

#define XTAL
Value:
(CPUFREQ==CLK_12M ? 12000000L :\
              CPUFREQ==CLK_24M ? 24000000L : 48000000L)

Evaluates to a DWORD value representing the clock speed in cycles per second.

Speeds:

  • 12000000L
  • 24000000L
  • 48000000L

Definition at line 70 of file fx2macros.h.


Enumeration Type Documentation

enum CLK_SPD

Used for getting and setting the CPU clock speed.

Enumerator:
CLK_12M 
CLK_24M 
CLK_48M 

Definition at line 47 of file fx2macros.h.