Fx2lib  0.2
include/fx2macros.h
Go to the documentation of this file.
00001 // Copyright (C) 2009 Ubixum, Inc. 
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License, or (at your option) any later version.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00016 
00021 #ifndef FX2MACROS_H
00022 #define FX2MACROS_H
00023 
00024 #include "fx2regs.h"
00025 #include "fx2types.h"
00026 
00027 #define MSB(addr) (BYTE)(((WORD)(addr) >> 8) & 0xff)
00028 #define LSB(addr) (BYTE)((WORD)(addr) & 0xff)
00029 #define MAKEWORD(msb,lsb) (((WORD)msb << 8) | lsb)
00030 
00031 #define MSW(dword) (WORD)((dword >> 16) & 0xffff)
00032 #define LSW(dword) (WORD)(dword & 0xffff)
00033 #define MAKEDWORD(msw,lsw) (((DWORD)msw << 16) | lsw)
00034 
00038 #define LOADWORD(reg, value) \
00039     reg ## H = MSB(value); \
00040     reg ## L = LSB(value);
00041 
00042 // clock stuff
00043 
00047 typedef enum { CLK_12M =0, CLK_24M, CLK_48M} CLK_SPD;
00048 
00052 #define CPUFREQ (CLK_SPD)((CPUCS & bmCLKSPD) >> 3)
00053 
00057 #define SETCPUFREQ(SPD) CPUCS = (CPUCS & ~bmCLKSPD) | (SPD << 3)
00058 
00070 #define XTAL (CPUFREQ==CLK_12M ? 12000000L :\
00071               CPUFREQ==CLK_24M ? 24000000L : 48000000L)
00072 
00073 
00084 #define I2CFREQ ((I2CTL & bm400KHZ) ? 400000L : 100000L)
00085 
00086 
00087 #define IFFREQ (IFCONFIG & bm3048MHZ ? 48000000L : 30000000L)
00088 #define SETIF30MHZ() IFCONFIG &= ~bm3048MHZ
00089 #define SETIF48MHZ() IFCONFIG |= bm3048MHZ
00090 
00091 
00092 // eeprom stuff
00093 #define EEPROM_TWO_BYTE (I2CS & bmBIT4)
00094 
00106 #define RENUMERATE_UNCOND() USBCS|=bmDISCON|bmRENUM;delay(1500);USBCS&=~bmDISCON
00107 
00111 #define RENUMERATE() if(!(USBCS&bmRENUM)) {USBCS|=bmDISCON|bmRENUM;delay(1500);USBCS &= ~bmDISCON;}
00112 
00113 
00114 // interrupts
00115 // USB interrupts are in usbjt.h
00116 
00117 
00118 
00119 
00123 #define HISPEED (USBCS&bmHSM)
00124 
00125 
00126 
00127 
00131 #define REMOTE_WAKEUP() (((WAKEUPCS & bmWU) && (WAKEUPCS & bmWUEN)) || ((WAKEUPCS & bmWU2) && (WAKEUPCS & bmWU2EN)))
00132 
00133 
00134 #endif