Interrupt & Interrupt Service Routine MOD5270

Discussion to talk about software related topics only.
Post Reply
santosh33
Posts: 5
Joined: Wed Dec 11, 2013 9:51 pm

Interrupt & Interrupt Service Routine MOD5270

Post by santosh33 »

Hi All,
I want to call an ISR when an Interrupt is triggered in MOD5270. Right now I am not able to call ISR. Please help me I am a newbie. Below is my code

#include "predef.h"
#include <stdio.h>
#include <ctype.h>
#include <startnet.h>
#include <autoupdate.h>
#include <serial.h>
#include <pins.h>
#include <qspi.h>
#include <ucos.h>
#include <cfinter.h>
#include <utils.h>
#include <..\MOD5270\system\sim5270.h>



extern "C" {
void UserMain(void * pd);

void SetIntc(long func, int vector, int level, int prio);

}

const char * AppName="UART1";

volatile BOOL IRQ7_Fired = false;

INTERRUPT(My_ISR, 0x2700)
{

IRQ7_Fired = true;
sim.eport.epfr = 0x20;

}

void UserMain(void * pd) {
InitializeStack();
OSChangePrio(MAIN_PRIO);
EnableAutoUpdate();


iprintf("Application started\n");
// Initialize pins needed for Interrupt
J2[48].function(PINJ2_48_IRQ7_FET);


// sim.eport.epier |= IRQ_7_INTERRUPT_ENABLE_BIT;
SetIntc((long) &My_ISR, 7 , 7, 7);
sim.eport.epier = 0x22; // 0000 0010 - Enable IRQ7

while (1) {
if( IRQ7_Fired ){
iprintf("The IRQ7 is fired\r\n");
IRQ7_Fired = false;
}
OSTimeDly(20);
}


}
roland.ames

Re: Interrupt & Interrupt Service Routine MOD5270

Post by roland.ames »

it looks to me like you are writing the wrong value to epier, it should be 0x80.

I suggest looking at the SetPinIrq function. described in NetBurnerRunTimeLibraries.pdf chapter 10
santosh33
Posts: 5
Joined: Wed Dec 11, 2013 9:51 pm

Re: Interrupt & Interrupt Service Routine MOD5270

Post by santosh33 »

Hi Roland,
I did tried reading that pdf but nothing helped and also tried epier value to 0x80, even then ISR was not called. Can you tell me how to calculate the epier value??? Thanks
Ridgeglider
Posts: 513
Joined: Sat Apr 26, 2008 7:14 am

Re: Interrupt & Interrupt Service Routine MOD5270

Post by Ridgeglider »

Level 7 IRQs are really the least frequently used, and because they're non-maskable, the SetIntc() function and the INTERRUPT macro don't apply. Level 7 IRQs require assembly language coding, so as a newbie, I'd probably steer clear and choose an IRQ level from 1-6 if possible. Take a look at http://www.netburner.com/support/docume ... rupts/file. It includes an appnote on IRQs, and some demo code for level 1-6, and even a level 7 IRQ.
roland.ames

Re: Interrupt & Interrupt Service Routine MOD5270

Post by roland.ames »

I got my information directly from the Freescale manual (MCF5271RM.pdf section 15.4.1.3) but I haven't used IRQ7 myself only IRQ1-6, so you should follow Ridgeglider's advice about the difference between IRQ7 and the other IRQs.
santosh33
Posts: 5
Joined: Wed Dec 11, 2013 9:51 pm

Re: Interrupt & Interrupt Service Routine MOD5270

Post by santosh33 »

Thank you very much.. But i want to execute the above mentioned code. I tried with different IRQ line except IRQ7 but still the ISR was not called. Can you help in executing the above code?? Thanks
Ridgeglider
Posts: 513
Joined: Sat Apr 26, 2008 7:14 am

Re: Interrupt & Interrupt Service Routine MOD5270

Post by Ridgeglider »

Santosh: Not sure I understand your response. The pdf explains how to set up IRQs from levels 1-6, and even level 7 on the 5270. This applies to IRQs from many sources. The code supplied in the link works with the external IRQs. One small issue is that it's written to support the DEV100 board, not the DEV70 board. The code below is setup to handle the Dev70 board and additionally has quite a few explanatory comments:

Code: Select all

/******************************************************************************
 *	This code is based on the code presented in the
 *	NetBurner Mod5270 Interrupts PDF appnote.
 *
 *	The code is modified slightly so that it runs on the DEV70 board, instead
 *	of the DEV100 that it originally supported.
 *
 *	To highlight the differences, the original code is commented out,
 *	not just deleted. That way you can follow the code by reading the appnote.
 *
 *	LOOK AT THIS COSE IN CONJUNCTION WITH THE NB APPNOTE:
 *	NB AppNote - Mod5270-Interrupts
 *
 *
 *	DESCRIPTION:	A simple demo showing how to use interrupts on the Mod5270.
 *	The code uses a pushbutton switch wired to J2[43]. That input is configured
 *	to generate interrupts on falling edges. The Interrupt Service Routine, the
 *	ISR posts a semaphore to UserMain which is pending on the same semaphore.
 *	Upon receipt of the semaphore, UserMain increments a count variable and
 *	prints a message to STDIO.
 *
 *
 * TO RUN THIS DEMO:
 * 1) Wire the pushbutton switch assembly according to the details in the
 * 		the handout "Adding a Switch to J2.PDF." To make things easier,
 * 		you will use an assembly that connects the switch & resistor to
 * 		a small set of header pins. All you will need to do is to connect
 * 		Vcc, Gnd, and the signal pins. If you do not have that assembly,
 * 		you could follow steps 2-5 with your own pushbutton and 1K
 * 		pullup resistor instead. You will need step 6 in either case.
 *
 *--------------------------------------------------------------------------
 * 2) Connect J2-43 to one side of a SPST NO momentary-contact switch.
 * 		That is: a Single Pole, Single Throw, Normally Open,
 * 		Momentary Contact switch, also called a
 * 		N.O. pushbutton switch.
 * 3) Connect the other side of the switch to Ground. This means the switch
 * 		input line J2[43] will be active low, or 0 when switch is pressed.
 * 4) In addition, also connect J2-43 to one side of a 1K ohm
 * 		resistor.
 * 5) Connect the other side of the 1K ohm resistor to
 * 		the 3.3V "Vcc" rail.
 *--------------------------------------------------------------------------
 *
 * 6) Connect a serial port between the NetBurner UART0 port and a
 * 		known COM port on your PC. Open MTTTY and set the terminal
 * 		settings for that port (on the PC) and:
 * 			115200 baud, No Parity, 8 data bits, and 1 stop bit
 *
 ******************************************************************************/
#include "predef.h" 
#include <stdio.h>
#include <ctype.h>
#include <startnet.h>
#include <autoupdate.h>

#include <../mod5270/system/sim5270.h>	// access to registers need to configure & clear IRQs
#include <cfinter.h>					// The INTERRUPT() macro

/* An interrupt setup helper defined in bsp.c */
extern "C" 
{
	void UserMain(void * pd);

	// This function sets up the 5270 interrupt controller
	void SetIntc(long func, int vector, int level, int prio );
}

const char * AppName="4.4_NBexample_IRQ1-6";

OS_SEM IrqPostSem;  // Define a Semaphore to communicate
					// between the IRQ1 ISR and UserMain().



// Define the ISR, the Interrupt Service Routine:
INTERRUPT(out_irq1_pin_isr, 0x2100 )
{
//  WARNING WARNING WARNING
//  Only a very limited set of RTOS functions can be called from
//  within an interrupt service routine.
//
//  Basically, only OS POST functions and LED functions should be used
//  No I/O (read, write or printf may be called), since they can block.
	
  sim.eport.epfr=0x02;	//Clear the IRQ by clearing the EPF1 bit in the EPFR register.
  	  	  	  	  	  	// Note that in tis case we CKEAR by writing 1 to the EPF1 bit!!!
  	  	  	  	  	  	// See Freescale Ref Manual 15.4.1.6

  OSSemPost(&IrqPostSem);	//Send semaphore signaling the ISR ran.
}



void UserMain(void * pd) {
	InitializeStack();
	OSChangePrio(MAIN_PRIO);
	EnableAutoUpdate();

	DWORD isr_count = 0;	//Count indicating how many times the switch was hit.

	//Initialize the semaphore used to communicate between the ISR and UserMain().
	OSSemInit(&IrqPostSem, 0);

	// First set up the Eport module to use IRQ1 as a falling-edge active IRQ pin.
	// (See the 5270 UM chapter 15).
	// Set the pin assignment register irq1 pin to be falling edge sensitive.
	sim.eport.epier = 0x00;	// 1st disable IRQ during setup. See UM 15.4.1.3

	sim.eport.eppar = 0x0008;	// 0000-0000-0000-1000  see table 15-3 in UM and
								// section 15.4.1.1 . EPPA1 = 10
								// to trigger on FALLING edges.

	sim.eport.epddr = 0x0000;	// All edge port pins as inputs: EPDDR = 0.
						   	   	// See UM section 15.4.1.2

	sim.eport.epier = 0x02; 	// Enable IRQ1 only 0000-0010. Set EPIE1 bit in
								// EPIER register. See 15.4.1.3

	//Now enable the actual interrupt controller. See users manual chapter 10 for
	//more information. We are going to use the BSP helper function declared above and
	//implemented in BSP.c
	SetIntc((long) &out_irq1_pin_isr, //	Our interrupt ISR function.
			1,	// The vector number from the users manual table 10-13.
				// This is IRQ1, so the vector is also 1.

			1,	// Set LEVEL to 1 but any value from 1 to 6 would be valid.

			1 	// The priority: for external IRQs (ie: IRQ1-6) any
				// 	  value you give will be overwritten with the prio
				//    of "3-4". Since this is IRQ1, one of the EXTERNAL
				// IRQs, this value can be 0-7, but really does not matter.
			);

	iprintf("Application started: %s\n", AppName);
	iprintf("Press the switch wired to J2[43], IRQ1.\n");
	while (1) {
		OSSemPend(&IrqPostSem, 0 /* Wait forever */);
		//----------------------------------------------------------------------
		// The original Appnote code included the following line which displayed
		// the count on a numeric display. The Dev70 board doesn't have that
		// hardware, so comment the line...

		//PutDispDecimal(++isr_count,true);

		//----------------------------------------------------------------------
		// Instead, show a binary representation of the count on the 8 LEDs
		// included on the DEV70 board:
		putleds(++isr_count);

		iprintf("The interrupt Switch was hit %ld times\r\n", isr_count);
	}
}
 

santosh33
Posts: 5
Joined: Wed Dec 11, 2013 9:51 pm

Re: Interrupt & Interrupt Service Routine MOD5270

Post by santosh33 »

Hello Ridgeglider,
Thanks a lot.. It was really helpful to me :) Thank yo so much
Post Reply