]>
Commit | Line | Data |
---|---|---|
3608c106 UH |
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, write to the Free Software | |
15 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
16 | ||
17 | /*! \file | |
18 | * Macros for simple common tasks in fx2 firmware. | |
19 | * */ | |
20 | ||
21 | #ifndef FX2MACROS_H | |
22 | #define FX2MACROS_H | |
23 | ||
24 | #include "fx2regs.h" | |
25 | #include "fx2types.h" | |
26 | ||
27 | #define MSB(addr) (BYTE)((addr >> 8) & 0xff) | |
28 | #define LSB(addr) (BYTE)(addr & 0xff) | |
29 | #define MAKEWORD(msb,lsb) (((WORD)msb << 8) | lsb) | |
30 | ||
31 | #define MSW(dword) (WORD)((dword >> 16) & 0xffff) | |
32 | #define LSW(dword) (WORD)(dword & 0xffff) | |
33 | #define MAKEDWORD(msw,lsw) (((DWORD)msw << 16) | lsw) | |
34 | ||
35 | // clock stuff | |
36 | ||
37 | /** | |
38 | * \brief Used for getting and setting the CPU clock speed. | |
39 | **/ | |
40 | typedef enum { CLK_12M =0, CLK_24M, CLK_48M} CLK_SPD; | |
41 | ||
42 | /** | |
43 | * \brief Evaluates to a CLK_SPD enum. | |
44 | **/ | |
45 | #define CPUFREQ (CLK_SPD)((CPUCS & bmCLKSPD) >> 3) | |
46 | /** | |
47 | * \brief Sets the cpu to operate at a specific | |
48 | * clock speed. | |
49 | **/ | |
50 | #define SETCPUFREQ(SPD) CPUCS = (CPUCS & ~bmCLKSPD) | (SPD << 3) | |
51 | ||
52 | /** | |
53 | * \brief Evaluates to a DWORD value representing | |
54 | * the clock speed in cycles per second. | |
55 | * | |
56 | * Speeds: | |
57 | * | |
58 | * \li 12000000L | |
59 | * \li 24000000L | |
60 | * \li 48000000L | |
61 | * | |
62 | **/ | |
63 | #define XTAL (CPUFREQ==CLK_12M ? 12000000L :\ | |
64 | CPUFREQ==CLK_24M ? 24000000L : 48000000L) | |
65 | ||
66 | ||
67 | /** | |
68 | * \brief Evaluates to the i2c bus frequency in cyles per | |
69 | * second. | |
70 | * | |
71 | * Speeds: | |
72 | * | |
73 | * \li 400000L | |
74 | * \li 100000L | |
75 | * | |
76 | **/ | |
77 | #define I2CFREQ ((I2CTL & bm400KHZ) ? 400000L : 100000L) | |
78 | ||
79 | ||
80 | #define IFFREQ (IFCONFIG & bm3048MHZ ? 48000000L : 30000000L) | |
81 | #define SETIF30MHZ() IFCONFIG &= ~bm3048MHZ | |
82 | #define SETIF48MHZ() IFCONFIG |= bm3048MHZ | |
83 | ||
84 | ||
85 | // eeprom stuff | |
86 | #define EEPROM_TWO_BYTE (I2CS & bmBIT4) | |
87 | ||
88 | /** | |
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. | |
91 | * | |
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. | |
98 | **/ | |
99 | #define RENUMERATE_UNCOND() USBCS|=bmDISCON|bmRENUM;delay(1500);USBCS&=~bmDISCON | |
100 | /** | |
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. | |
103 | **/ | |
104 | #define RENUMERATE() if(!(USBCS&bmRENUM)) {USBCS|=bmDISCON|bmRENUM;delay(1500);USBCS &= ~bmDISCON;} | |
105 | ||
106 | ||
107 | // interrupts | |
108 | // USB interrupts are in usbjt.h | |
109 | ||
110 | ||
111 | ||
112 | ||
113 | /** | |
114 | * \brief TRUE if the FX2 has transitioned to high speed on the USB bus.. | |
115 | **/ | |
116 | #define HISPEED (USBCS&bmHSM) | |
117 | ||
118 | ||
119 | ||
120 | ||
121 | /** | |
122 | * \brief Evaluates to TRUE if a remote wakeup event has occurred. | |
123 | **/ | |
124 | #define REMOTE_WAKEUP() (((WAKEUPCS & bmWU) && (WAKEUPCS & bmWUEN)) || ((WAKEUPCS & bmWU2) && (WAKEUPCS & bmWU2EN))) | |
125 | ||
126 | ||
127 | #endif |