1 // Copyright (C) 2009 Ubixum, Inc.
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.
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.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 * Macros for simple common tasks in fx2 firmware.
27 #define MSB(addr) (BYTE)(((WORD)(addr) >> 8) & 0xff)
28 #define LSB(addr) (BYTE)((WORD)(addr) & 0xff)
29 #define MAKEWORD(msb,lsb) (((WORD)msb << 8) | lsb)
31 #define MSW(dword) (WORD)((dword >> 16) & 0xffff)
32 #define LSW(dword) (WORD)(dword & 0xffff)
33 #define MAKEDWORD(msw,lsw) (((DWORD)msw << 16) | lsw)
38 * \brief Used for getting and setting the CPU clock speed.
40 typedef enum { CLK_12M
=0, CLK_24M
, CLK_48M
} CLK_SPD
;
43 * \brief Evaluates to a CLK_SPD enum.
45 #define CPUFREQ (CLK_SPD)((CPUCS & bmCLKSPD) >> 3)
47 * \brief Sets the cpu to operate at a specific
50 #define SETCPUFREQ(SPD) CPUCS = (CPUCS & ~bmCLKSPD) | (SPD << 3)
53 * \brief Evaluates to a DWORD value representing
54 * the clock speed in cycles per second.
63 #define XTAL (CPUFREQ==CLK_12M ? 12000000L :\
64 CPUFREQ==CLK_24M ? 24000000L : 48000000L)
68 * \brief Evaluates to the i2c bus frequency in cyles per
77 #define I2CFREQ ((I2CTL & bm400KHZ) ? 400000L : 100000L)
80 #define IFFREQ (IFCONFIG & bm3048MHZ ? 48000000L : 30000000L)
81 #define SETIF30MHZ() IFCONFIG &= ~bm3048MHZ
82 #define SETIF48MHZ() IFCONFIG |= bm3048MHZ
86 #define EEPROM_TWO_BYTE (I2CS & bmBIT4)
89 * \brief Cause the device to disconnect and reconnect to USB. This macro
90 * unconditionally renumerates the device no matter how the firmware is loaded.
92 * <b>NOTE</b> Windows really doesn't like this if the firmware is loaded
93 * from an eeprom. You'll see information messages about the device not
94 * working properly. On the other hand, if you are changing the device
95 * descriptor, e.g., the vendor and product id, when downloading firmware to the device,
96 * you'll need to use this macro instead of the
97 * standard RENUMERATE macro.
99 #define RENUMERATE_UNCOND() USBCS|=bmDISCON|bmRENUM;delay(1500);USBCS&=~bmDISCON
101 * \brief Cause the device to disconnect and reconnect to the USB bus. This macro
102 * doesn't do anything if the firmware is loaded from an eeprom.
104 #define RENUMERATE() if(!(USBCS&bmRENUM)) {USBCS|=bmDISCON|bmRENUM;delay(1500);USBCS &= ~bmDISCON;}
108 // USB interrupts are in usbjt.h
114 * \brief TRUE if the FX2 has transitioned to high speed on the USB bus..
116 #define HISPEED (USBCS&bmHSM)
122 * \brief Evaluates to TRUE if a remote wakeup event has occurred.
124 #define REMOTE_WAKEUP() (((WAKEUPCS & bmWU) && (WAKEUPCS & bmWUEN)) || ((WAKEUPCS & bmWU2) && (WAKEUPCS & bmWU2EN)))