/*
 *----------------------------------------------------------------------
 *    micro T-Kernel
 *
 *    Copyright (C) 2006-2011 by Ken Sakamura. All rights reserved.
 *    micro T-Kernel is distributed under the micro T-License.
 *----------------------------------------------------------------------
 *
 *    Version:   1.01.01
 *    Released by T-Engine Forum(http://www.t-engine.org) at 2011/07/29.
 *
 *----------------------------------------------------------------------
 */

/*
 *	@(#)int.c (libtk/TWRK60N512)
 *
 *	Interrupt controller
 */

/*
 *  for MB9BF618T on FRK-FM3
 * 
 *   Copyright (C) by Y.Ishioka.
 */

#include <basic.h>
#include <tk/syslib.h>
#include <tk/sysdef.h>
#if 0 /* Y.Ishioka */
#include "MK60N512MD100.h"
#include "core_cm4.h"
#else
#include "mb9bf618t.h"
#include "core_cm3.h"
#endif

/*
 * Set interrupt mode 
 *	
 *	Sets the interrupt specified in 'intvec' to the mode specified
 *	in 'mode'.
 *	FIQ and IRQ interrupt can be specified.
 *	Interrupt controller level register and polarity register are set.
 *
 *	mode := (IM_LEVEL || IM_EDGE) | (IM_HI || IM_LOW)
 */
EXPORT void SetIntMode( INTVEC intvec, UINT mode )
{
}

/*
 * Enable interrupt 
 *	Enables the interrupt specified in intvec.
 *	FIQ and IRQ interrupt can be specified. 
 */
EXPORT void EnableInt( INTVEC intvec )
{
        /* Y.Ishioka */
	NVIC_EnableIRQ((IRQn_Type)(intvec-16));
}

/*
 * Disable interrupt 
 *	Disables the interrupt specified in intvec.
 *	FIQ and IRQ interrupt can be specified.
 */
EXPORT void DisableInt( INTVEC intvec )
{
	NVIC_DisableIRQ((IRQn_Type)(intvec-16));
}

/*
 * Clear interrupt request 
 *	Clears the intvec interrupt request.
 *	Valid only for edge trigger.
 *	For edge trigger, the interrupt must be cleared with an
 *	interrupt handler.
 *	FIQ and IRQ interrupt can be specified.
 */
EXPORT void ClearInt( INTVEC intvec )
{
	/* Y.Ishioka */
	NVIC_ClearPendingIRQ((IRQn_Type)(intvec-16));
}

/*
 * Check for interrupt requests 
 *	Checks for intvec interrupt  requests.
 *	If an interrupt request is found, returns TRUE (other than 0).
 *	FIQ and IRQ interrupt can be specified.
 */
EXPORT BOOL CheckInt( INTVEC intvec )
{
	/* Y.Ishioka */
	BOOL  ret ;

	if( NVIC_GetPendingIRQ((IRQn_Type)(intvec-16)) != 0 ) {
		ret = TRUE;
	} else {
		ret = FALSE;
	}

	return( ret ) ;
}

/*
 * Notify end of interrupt
 */
EXPORT void EndOfInt( INTVEC intvec )
{
}
