cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
Adventurer
Adventurer
431 Views
Registered: ‎01-23-2018

How to handle PL generated Interrupts

Hello,

I am writing a simple test design in which I have an IP that performs a matrix-vector multiplication in programmable logic.
With this IP I would like to perform performance benchmarks compared to a software version,
then I need to start a timer when the IP starts its computation (when ap_start becomes one) and finally this timer will be stopped when the PS7 receives an interrupt. For this reason I have connected IRQ_F2P with ap_done.

Schermata da 2018-11-20 13-08-04.png

This is the ARM C code that I wrote, where I used xmv.h (for controling the HLS IP) and xscugic.h for initializing the GIC controller.

The code does not returns errors, but the interruptHandler() does not execute. Could you give some hints to solve this issue?

 

#include <stdio.h>
#include <stdlib.h>
#include <xmv.h>

#include "platform.h"
#include "xil_printf.h"
#include "xscugic.h"
#include "xparameters.h"

#define INTC_INTERRUPT_ID 68  // IRQ [0]

int A [] = { 16, 2, 3, 13, 5, 11, 10, 8, 9, 7, 6, 12, 4, 14, 15, 1 };
int b [] = { 1, 2, 3, 4 };

XScuGic InterruptController;
XScuGic_Config *GicConfig;


void interruptHandler() {

	printf("Interrupt ricevuto\n");
}

int SetUpInterruptSystem(XScuGic *XScuGicInstancePtr) {

	/*
	 * Connect the interrupt controller interrupt handler to the hardware
	 * interrupt handling logic in the ARM processor.
	 */
	Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT, (Xil_ExceptionHandler) XScuGic_InterruptHandler, XScuGicInstancePtr);

	/*
	 * Enable interrupts in the ARM
	 */
	Xil_ExceptionEnable();

	return XST_SUCCESS;
}


int ScuGicInterrupt_Init(u16 DeviceId) {

	int Status;
	/*
	 * Initialize the interrupt controller driver so that it is ready to
	 * use.
	 * */
	GicConfig = XScuGic_LookupConfig(DeviceId);
	if (NULL == GicConfig) {
		printf("Error: XScuGic_LookupConfig()\n");
		return XST_FAILURE;
	}
	Status = XScuGic_CfgInitialize(&InterruptController, GicConfig, GicConfig->CpuBaseAddress);
	if (Status != XST_SUCCESS) {
		printf("Error: XScuGic_CfgInitialize()\n");
		return XST_FAILURE;
	}
	/*
	* Setup the Interrupt System
	* */
	Status = SetUpInterruptSystem(&InterruptController);
	if (Status != XST_SUCCESS) {
		printf("Error: SetUpInterruptSystem()\n");
		return XST_FAILURE;
	}
	/*
	* Connect a device driver handler that will be called when an
	* interrupt for the device occurs, the device driver handler performs
	* the specific interrupt processing for the device
	*/
	Status = XScuGic_Connect(&InterruptController, INTC_INTERRUPT_ID, (Xil_ExceptionHandler)interruptHandler, 0);
	if (Status != XST_SUCCESS) {
		printf("Error: XScuGic_Connect()\n");
		return XST_FAILURE;
	}
	/*
	* Enable the interrupt for the device and then cause (simulate) an
	* interrupt so the handlers will be called
	*/
	XScuGic_Enable(&InterruptController, INTC_INTERRUPT_ID);

	printf("GIC Initialization success\n");

	return XST_SUCCESS;
}


int main() {

    init_platform();

    ScuGicInterrupt_Init(XPAR_PS7_SCUGIC_0_DEVICE_ID);

    int n  = 4;
    int *c = (int*)malloc(n*sizeof(int));

    XMv doMV;
    XMv_Initialize(&doMV, 0);

    // fa partire il modulo
    Xil_Out8(0x41200000, 1);

    // imposta i parametri sulla periferica hardware
    XMv_Set_elem(&doMV, 4);
    XMv_Write_A_Words(&doMV, 0, A, n*n);
    XMv_Write_b_Words(&doMV, 0, b, n);

    // legge i parametri in uscita
    XMv_Read_c_Words(&doMV, 0, c, n);

    printf("c = [\n");
    for(int i = 0; i < n; ++i){
    	printf("\t%d\n", c[i]);
    }
    printf("]\n");

    free(c);

    cleanup_platform();

    return 0;
}

 

 

0 Kudos
Reply
1 Reply
Highlighted
Xilinx Employee
Xilinx Employee
374 Views
Registered: ‎09-01-2014

please refer to the following example design
https://www.xilinx.com/support/answers/50572.html
0 Kudos
Reply