/* interrupt.h - HC12 interrupt handling support.
 * Copyright 2008 Colin D. Bennett <colin@gibibit.com>.
 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 *    This program is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 */
#ifndef DRAGON12_INTERRUPT_H_
#define DRAGON12_INTERRUPT_H_

static inline __attribute__((always_inline)) void
enable_interrupts(void)
{
	asm("cli");
}

static inline __attribute__((always_inline)) void 
disable_interrupts(void)
{
	asm("sei");
}

static inline __attribute__((always_inline)) void 
wait(void)
{
	asm("wai");  // Enter WAIT mode, will wake up when interrupt occurs.
}

/* Macro to define an interrupt service routine function.
 * The 'interrupt' attribute tells gcc to generate prologue/epilogue
 * code appropriate for an interrupt, particularly using RTI instead 
 * of RTC/RTS to return from the function. */
#define DECLARE_ISR(name) void name (void) __attribute__((interrupt))

/* Begin the definition of an interrupt service routine function. */
#define ISR(name) DECLARE_ISR(name); void name (void)

#endif /* DRAGON12_INTERRUPT_H_ */

