cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
Observer
Observer
7,832 Views
Registered: ‎01-13-2010

Microblaze MCS and PIT sample code

I spent way more time that should have been required to figure out how to make the PIT work. A required #define (XIN_IOMODULE_PIT_1_INTERRUPT_INTR) doesn't have a single hit on google. I knew I was close, as the ISR was running just once. I kept thinking that meant I needed to ack or re-enable in the ISR. But instead, the problem was the PIT peripheral defaults to a single run and an option must be set to make it auto-reload. This clue came courtesy of the PIT control register in DS866

 

So, here's to have the first instance of the XIN_IOMODULE_PIT_1_INTERRUPT_INTR on google. Hopefully this helps someone. 

 

 

#include <xil_exception.h>
#include <xparameters.h>
#include <xiomodule.h>
#include "platform.h"

XIOModule Timer;
XIOModule System;
volatile u32 Ticks = 0;

void timerTick(void* ref)
{
	Ticks++;
}


int main()
{
    init_platform();

    XIOModule_Initialize(&System, XPAR_IOMODULE_0_DEVICE_ID);
    microblaze_register_handler(XIOModule_DeviceInterruptHandler, XPAR_IOMODULE_0_DEVICE_ID);
    XIOModule_Start(&System);

    // Set the interval of the PIT. Default counter clock is system clock.
    XIOModule_SetResetValue(&System, 0, 500);

    // Register interrupt handler
    XIOModule_Connect(&System, XIN_IOMODULE_PIT_1_INTERRUPT_INTR, timerTick, NULL);

    // Enable interrupts
    XIOModule_Enable(&System, XIN_IOMODULE_PIT_1_INTERRUPT_INTR);
    
    // Specify PIT is to automatically reload. Without this, ISR runs once
    XIOModule_Timer_SetOptions(&System, 0, XTC_AUTO_RELOAD_OPTION);

    XIOModule_Timer_Start(&System, 0);

    microblaze_enable_interrupts();


    while (1)
    {
    	
    }

    return 0;
}

 

2 Replies
Highlighted
Newbie
Newbie
7,082 Views
Registered: ‎03-26-2015

You Sir are a true gentleman.

 

Thank you for the sample as it works perfectly!

0 Kudos
Highlighted
Observer
Observer
2,797 Views
Registered: ‎06-02-2008

Hi all,

I've created a design with the Microblaze MCS core completed with the PIT from the LogiCORE IP.

I've tried this code based on the Xillib library and its works with my design.

I'm looking for the same code (using PIT1 as a periodic timer generating a periodic interrupt) in pure C language (and inline ASM for ISR surely). I would like to use this piece of code for trying to port a RTOS (for the tick timer).

In the PG111 guide (https://www.xilinx.com/support/documentation/ip_documentation/iomodule/v3_1/pg111-iomodule.pdf), it's not clear how works the Interrupt Address Vector Register (IRQ_VECTOR_x) (x=3 for PIT1?). Should we write the base address of the ISR routine in the IRQ_VECTOR_3 register for PIT1 interrupts?

Cheers;

0 Kudos