

#include "mcf5213.h"



void config_port(void);
void init_clock_config (void);
static void init_interrupt_controller (void);
void init_interrup_ext(void);

int  main (void) 
	{		
		config_port();
		init_clock_config();
		init_interrupt_controller();
		init_interrup_ext();

		asm_set_ipl(0);  	//habilita todas las interrupciones si es 0

		while(1)		// ciclo infinito esperando interrupción
		{

		}
		return 0;
	}


void config_port(void)
	{
		MCF_GPIO_PQSPAR=0;					// GPIO Propósito General
	  	MCF_GPIO_DDRQS = MCF_GPIO_DDRQS_DDRQS3;		// Direccion: Salida

		MCF_GPIO_PNQPAR = MCF_GPIO_PNQPAR_IRQ1_IRQ1;	// GPIO interrupcion
		MCF_GPIO_DDRNQ = 0;					// Direccion: Entrada
	}


void init_clock_config (void)
	{
		// Clock source is 7.3728 MHz external oscillator
	    	// Clock mode: External clock mode
		// Processor/Bus clock frequency = 7.37 MHz

	    	MCF_CLOCK_SYNCR = 0;  // usa el clock externo     		
	}




static void init_interrupt_controller (void)
{
   MCF_INTC_IMRL = MCF_INTC_IMRL_MASK31 |
                    MCF_INTC_IMRL_MASK30 |
                    MCF_INTC_IMRL_MASK29 |
                    MCF_INTC_IMRL_MASK28 |
                    MCF_INTC_IMRL_MASK27 |
                    MCF_INTC_IMRL_MASK26 |
                    MCF_INTC_IMRL_MASK25 |
                    MCF_INTC_IMRL_MASK24 |
                    MCF_INTC_IMRL_MASK23 |
                    MCF_INTC_IMRL_MASK22 |
                    MCF_INTC_IMRL_MASK21 |
                    MCF_INTC_IMRL_MASK20 |
                    MCF_INTC_IMRL_MASK19 |
                    MCF_INTC_IMRL_MASK18 |
                    MCF_INTC_IMRL_MASK17 |
                    MCF_INTC_IMRL_MASK16 |
                    MCF_INTC_IMRL_MASK15 |
                    MCF_INTC_IMRL_MASK14 |
                    MCF_INTC_IMRL_MASK13 |
                    MCF_INTC_IMRL_MASK12 |
                    MCF_INTC_IMRL_MASK11 |
                    MCF_INTC_IMRL_MASK10 |
                    MCF_INTC_IMRL_MASK9  |
                    MCF_INTC_IMRL_MASK8  |
                    MCF_INTC_IMRL_MASK7  |
                    MCF_INTC_IMRL_MASK6  |
                    MCF_INTC_IMRL_MASK5  |
                    MCF_INTC_IMRL_MASK4  |
                    MCF_INTC_IMRL_MASK3  |
                    	MCF_INTC_IMRL_MASK2;

	}

void init_interrup_ext(void)
	{
		MCF_EPORT_EPPAR = MCF_EPORT_EPPAR_FALLING; 	// Activar por flanco de bajada
		MCF_EPORT_EPDDR = ~MCF_EPORT_EPDDR_EPDD1;		// Pin configurado como entrada
		MCF_EPORT_EPIER =	MCF_EPORT_EPIER_EPIE1;		// Habilita interrupcion
	}


