Problem with PowerPC PIT interrupt

I'm working on a RTOS for the PowerPC chip on the Virtex-II XUP board. I need an interrupt to trigger so I run my scheduler at regular intervals, so I setup the PIT to trigger an interrupt at 1s (purely for testing reasons, I will be going down to around 5ms). The program seems to pause when I finally enable the interrupt and I see no signs that the handler has been run. I looked at several references and spent a day shifting around my code, to no avail. If someone could take a peek at my code below and offer assistance that would be great. Thanks.

#include "xparameters.h" #include "stdio.h" #include "xbasic_types.h" #include "gpio_header.h" #include "xexception_l.h" #include "xtime_l.h"

Xuint32 status;

void pit_InterruptHandler(void *dataPtr) { status = 55; XTime_PITClearInterrupt(); }

int main(void) { Xuint32 DataRead; XExc_Init(); XExc_RegisterHandler(XEXC_ID_PIT_INT, (XExceptionHandler)pit_InterruptHandler, (void*) 0); XTime_PITSetInterval(100000); XTime_PITEnableAutoReload(); XExc_mEnableExceptions(XEXC_NON_CRITICAL); print("-- Entering main() --\r\n"); print("\r\nRunning GpioOutputExample() for LEDs_4Bit...\r\n"); status = GpioOutputExample(XPAR_LEDS_4BIT_DEVICE_ID,4); if(status == 0) { print("GpioOutputExample PASSED.\r\n"); } else { print("GpioOutputExample FAILED.\r\n"); } XTime_PITClearInterrupt(); XTime_PITEnableInterrupt(); print("Here\r\n"); status = 0; while(status != 55) { ; } print("-- Exiting main() --\r\n"); return 0; }

---Matthew Hicks

Reply to
Matthew Hicks
Loading thread data ...

I don't know about the rest of the code, but this declaration needs to be volatile...

volatile Xuint32 status;

Otherwise the compiler optimises this to an infinite loop because it "knows" that nothing can make status == 55

Cheers, Martin

--
martin.j.thompson@trw.com 
TRW Conekt - Consultancy in Engineering, Knowledge and Technology
http://www.conekt.net/electronics.html
Reply to
Martin Thompson

Thanks for the tip, I forgot to add it after I went from a print statement that I was using. It still stalls though.

---Matthew Hicks

Reply to
Matthew Hicks

Removed code...

You may want to use volatile Xuint32 status;

since you are changing the variable behind the back of the main program.

The compiler doesn't know about what you do in interrupt routines so it may put this variable in a register and only read the memory once.

Alan Nishioka snipped-for-privacy@nishioka.com

Reply to
Alan Nishioka

Today I tried the FIT timer interrupt and the watchdog interrupt. Both did the same thing. The program would work fine until the interrupt occured, then the program would freeze and do nothing. The best I could do is have the watchdog timer reset the core when it saw that the previous watchdog interrupt wasn't handled, which worked great. Again, I would really appreciate if someone could help push me past this sticking point. I have attached the new code for reference:

volatile Xuint32 status;

void wdtHandler(void *dataPtr) { status = 55; XTime_WDTClearInterrupt(); }

int main(void) { Xuint32 DataRead; print("-- Entering main() --\r\n"); XExc_Init(); XExc_RegisterHandler(XEXC_ID_WATCHDOG_TIMER_INT, (XExceptionHandler)wdtHandler, (void*) 0); XTime_WDTSetPeriod(XREG_TCR_WDT_PERIOD_11 | XREG_TCR_WDT_RESET_CONTROL_01); XExc_mEnableExceptions(XEXC_ALL); status = 0; XTime_WDTClearInterrupt(); XTime_WDTEnableInterrupt(); while(status != 55) { DataRead = mfspr(0x10C); XExc_mDisableExceptions(XEXC_ALL); xil_printf("Timebase: %d\r\n", DataRead); XExc_mEnableExceptions(XEXC_ALL); } print("-- Exiting main() --\r\n"); return 0; }

---Matthew Hicks

Reply to
Matthew Hicks

Well, I found the solution. When I regenerate the linker script the program works 100% correctly. Forgive my newness to things like this (I come from the high-level land of windows application programming not embedded programming), but is this something that I should have done from the start?

---Matthew Hicks

Reply to
Matthew Hicks

programming),

I've never heard of this particular problem, but in general, intermediate files can get into unexpected states, so it is a good idea to periodically recompile everything from the beginning (ie. make clean).

This is true for hardware and software (and perhaps in life as well :-).

Alan Nishioka snipped-for-privacy@nishioka.com

Reply to
Alan Nishioka

I had similar problem in my project. I found that if you will not use autoreload option of the PIT and reset timer inside the interrupt handler, it's work fine. I saw this "autoreloadenable" is commented out inXilinx reference code. Probably for the same reason.

programming),

Reply to
leevv

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.