1515// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1616
1717/*! \file
18- * Define the standard fx2 interrupts. For int2 and int4 autovector
18+ * Define the standard FX2 interrupts. For INT2 and INT4 autovector
1919 * interrupts see \ref autovector.h
2020 *
2121 * To enable an interrupt, simply define an interrupt handler function
3838
3939
4040/**
41- * \brief interrupt numbers for standard fx2 interrupts
42-
41+ * \brief Interrupt numbers for standard FX2 interrupts.
4342 **/
4443typedef enum {
4544 IE0_ISR = 0 , ///< External interrupt 0
@@ -50,29 +49,66 @@ typedef enum {
5049 TF2_ISR , ///< Timer 2 interrupt
5150 RESUME_ISR , ///< Resume interrupt
5251 TI_1_ISR , ///< Serial port 1 transmit or receive interrupt
53- USBINT_ISR , ///< Usb Interrupt. An interrupt handler for this should only be used if not using auto vectored interrupts with int2
52+ USBINT_ISR , ///< USB Interrupt. An interrupt handler for this should only be used if not using auto vectored interrupts with INT2
5453 I2CINT_ISR , ///< I2C Bus interrupt
55- IE4_ISR , ///< External interrupt 4. An interrupt handler for this should only be used if not using auto vectored interrupts with int4
54+ IE4_ISR , ///< External interrupt 4. An interrupt handler for this should only be used if not using auto vectored interrupts with INT4
5655 IE5_ISR , ///< External interrupt 5
5756 IE6_ISR , ///< External interrupt 6
57+ // Better names for the USART interrupts
58+ USART0_ISR = TI_0_ISR , ///< Better name for USART0 interrupt
59+ USART1_ISR = TI_1_ISR , ///< Better name for USART1 interrupt
5860} FX2_ISR ;
5961
62+ /**
63+ * \brief Interrupt high priority.
64+ **/
65+ #define INTERRUPT_HIGH_PRIO 1
66+ /**
67+ * \brief Interrupt low priority.
68+ **/
69+ #define INTERRUPT_LOW_PRIO 0
70+
71+
72+ // TIMER0
73+ // =======================================================================
6074
6175/**
6276 * \brief Enable the timer 0 interrupt.
6377 *
64- * There is not CLEAR_TIMER0 because the timer interrupt flag
65- * is automatically cleared when the isr is called.
78+ * CLEAR_TIMER0() is a NOP because the timer interrupt flag is automatically
79+ * cleared when the ISR is called.
6680 **/
6781#define ENABLE_TIMER0 () ET0=1
6882
83+ /**
84+ * \brief Clear timer 0 interrupt
85+ *
86+ * CLEAR_TIMER0() is a NOP because the timer interrupt flag is automatically
87+ * cleared when the ISR is called.
88+ **/
89+ #define CLEAR_TIMER0 ()
90+
91+ // TIMER1
92+ // =======================================================================
93+
6994/**
7095 * \brief Enable timer 1 interrupt
71- * There is no CLEAR_TIMER1 because the timer interrupt flag
72- * is automatically cleared when the isr is called.
96+ *
97+ * CLEAR_TIMER1() is a NOP because the timer interrupt flag is automatically
98+ * cleared when the ISR is called.
7399 **/
74100#define ENABLE_TIMER1 () ET1=1
75101
102+ /**
103+ * \brief Clear timer 1 interrupt
104+ *
105+ * CLEAR_TIMER1() is a NOP because the timer interrupt flag is automatically
106+ * cleared when the ISR is called.
107+ **/
108+ #define CLEAR_TIMER1 ()
109+
110+ // TIMER2 and external EXF2 interrupt
111+ // =======================================================================
76112
77113/**
78114 * \brief Enable timer 2 interrupt
@@ -82,12 +118,18 @@ typedef enum {
82118 **/
83119#define ENABLE_TIMER2 () ET2=1
84120/**
85- * \brief Clear timer 2 interrupt
121+ * \brief Clear timer 2 interrupt
86122 *
87- * Clears both the TF2 AND EXF2 flag
123+ * Clears both the TF2 AND EXF2 flag
88124 **/
89125#define CLEAR_TIMER2 () TF2=0;EXF2=0;
90126
127+ // Resume interrupt
128+ // =======================================================================
129+ // After the FX2 has entered its idle state, it responds to an external signal
130+ // on its WAKEUP/WU2 pins or resumption of USB bus activity by restarting its
131+ // oscillator and resuming firmware execution.
132+
91133/**
92134 * \brief Enable the Resume Interrupt. Requires EA=1 separately.
93135 **/
@@ -99,18 +141,138 @@ typedef enum {
99141 **/
100142#define CLEAR_RESUME () RESI=0
101143
144+ // Interrupt 4 - Autovectored FIFO / GPIF or External interrupt 4
145+ // =======================================================================
102146
103- #define ENABLE_INT4 ()
147+ //#define ENABLE_INT4()
148+
149+ // External Interrupt 5
150+ // =======================================================================
104151
105152/**
106153 * \brief
107- * Enable external interupt for int5 #
154+ * Enable external interrupt for INT5 #
108155 **/
109156#define ENABLE_INT5 () EIEX5=1
110157
111158/**
112159 * \brief
113- * Clear int5# interrupt
160+ * Clear INT5# interrupt
161+ **/
162+ #define CLEAR_INT5 () \
163+ EXIF &= ~bmIE5
164+
165+ // USART0
166+ // =======================================================================
167+
168+ /**
169+ * \brief Set the USART 0 interrupt priority.
170+ *
171+ * Does *not* enable the interrupt.
172+ *
173+ * \code
174+ * SET_USART0_ISR_PRIO(INTERRUPT_HIGH_PRIO); // Set USART0 to high priority
175+ * SET_USART0_ISR_PRIO(INTERRUPT_LOW_PRIO); // Set USART0 to low priority
176+ * \endcode
177+ **/
178+ #define SET_USART0_ISR_PRIORITY (p ) \
179+ PS0 = p
180+ /**
181+ * \brief Enable the USART 0 interrupt.
182+ *
183+ * Requires enabling global interrupts (EA=1) separately.
184+ *
185+ * The USART interrupt fires for both *receive* (RX) and *transmit* (TX)
186+ * completing, the interrupt must clear *both*.
187+ **/
188+ #define ENABLE_USART0 () \
189+ ES0 = 1;
190+ /**
191+ * \brief Clear USART 0 RX bit.
114192 **/
115- #define CLEAR_INT5 () EXIF &= ~0x80
193+ #define CLEAR_USART0_RX () \
194+ RI = 0;
195+ /**
196+ * \brief Clear USART 0 TX bit.
197+ **/
198+ #define CLEAR_USART0_TX () \
199+ TI = 0;
200+ /**
201+ * \brief Clear USART 0 both TX & RX bit.
202+ **/
203+ #define CLEAR_USART0 () \
204+ CLEAR_USART0_RX(); \
205+ CLEAR_USART0_TX();
116206
207+ // USART1
208+ // =======================================================================
209+
210+ /**
211+ * \brief Set the USART 1 interrupt priority.
212+ *
213+ * Does *not* enable the interrupt.
214+ *
215+ * \code
216+ * SET_USART1_ISR_PRIO(INTERRUPT_HIGH_PRIO); // Set USART1 to high priority
217+ * SET_USART1_ISR_PRIO(INTERRUPT_LOW_PRIO); // Set USART1 to low priority
218+ * \endcode
219+ **/
220+ #define SET_USART1_ISR_PRIORITY (p ) \
221+ PS1 = p
222+ /**
223+ * \brief Enable the USART 1 interrupt.
224+ *
225+ * Requires enabling global interrupts (EA=1) separately.
226+ *
227+ * The USART interrupt fires for both *receive* (RX) and *transmit* (TX)
228+ * completing, the interrupt must clear *both*.
229+ **/
230+ #define ENABLE_USART1 () \
231+ ES1 = 1;
232+ /**
233+ * \brief Clear USART 1 receive (RI1) bit.
234+ **/
235+ #define CLEAR_USART1_RX () \
236+ RI1 = 0;
237+ /**
238+ * \brief Clear USART 1 transmit (TI1) bit.
239+ **/
240+ #define CLEAR_USART1_TX () \
241+ TI1 = 0;
242+ /**
243+ * \brief Clear USART 1 both TX & RX bits.
244+ **/
245+ #define CLEAR_USART1 () \
246+ CLEAR_USART1_RX(); \
247+ CLEAR_USART1_TX();
248+
249+ // I2C Interrupt
250+ // =======================================================================
251+
252+ /**
253+ * \brief Set the I2C interrupt priority.
254+ *
255+ * Does *not* enable the interrupt.
256+ *
257+ * \code
258+ * SET_I2C_ISR_PRIO(INTERRUPT_HIGH_PRIO) // Set I2C to high priority
259+ * SET_I2C_ISR_PRIO(INTERRUPT_LOW_PRIO) // Set I2C to low priority
260+ * \endcode
261+ **/
262+ #define SET_I2C_ISR_PRIORITY (p ) \
263+ PI2C = p
264+ /**
265+ * \brief Enable the I2C interrupt.
266+ *
267+ * Requires enabling global interrupts (EA=1) separately.
268+ *
269+ * The USART interrupt fires for both *receive* (RX) and *transmit* (TX)
270+ * completing, the interrupt must clear *both*.
271+ **/
272+ #define ENABLE_I2C () \
273+ EI2C = 1;
274+ /**
275+ * \brief Clear I2C interrupt.
276+ **/
277+ #define CLEAR_I2C () \
278+ EXIF &= ~bmI2CINT;
0 commit comments