https://www.xilinx.com/support/answers/50572.html
をベースにGPIOを組み合わせた
/* * Pl_timer_intr_test.c * * Created on: 2012-6-8 * Author: yzhang */ #include <stdio.h> //#include "platform.h" #include "xil_types.h" #include "xtmrctr.h" #include "xparameters.h" #include "xil_io.h" #include "xil_exception.h" #include "xscugic.h" #include "xgpio.h" #include <stdbool.h> #define LED_DEVICE_ID XPAR_AXI_GPIO_0_DEVICE_ID XGpio LEDInst; static bool flag = false; XScuGic InterruptController; /* Instance of the Interrupt Controller */ static XScuGic_Config *GicConfig;/* The configuration parameters of the controller */ //void print(char *str); extern char inbyte(void); void Timer_InterruptHandler(void *data, u8 TmrCtrNumber) { print(" Interrupt acknowledged \n \r "); print("\r\n"); print("\r\n"); if(flag){ XGpio_DiscreteWrite(&LEDInst, 1, 0x0F); // 2つ目の引数は1. Pmod 下段だけON } else { XGpio_DiscreteWrite(&LEDInst, 1, 0x00); // 2つ目の引数は1. Pmod 下段だけON } flag = !flag; XTmrCtr_Stop(data,TmrCtrNumber); XTmrCtr_Reset(data,TmrCtrNumber); XTmrCtr_Start(data,TmrCtrNumber); } 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,XTmrCtr *TimerInstancePtr) { int Status; /* * Initialize the interrupt controller driver so that it is ready to * use. * */ GicConfig = XScuGic_LookupConfig(DeviceId); if (NULL == GicConfig) { return XST_FAILURE; } Status = XScuGic_CfgInitialize(&InterruptController, GicConfig, GicConfig->CpuBaseAddress); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Setup the Interrupt System * */ Status = SetUpInterruptSystem(&InterruptController); if (Status != XST_SUCCESS) { 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, XPAR_FABRIC_AXI_TIMER_0_INTERRUPT_INTR, (Xil_ExceptionHandler)XTmrCtr_InterruptHandler, (void *)TimerInstancePtr); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Enable the interrupt for the device and then cause (simulate) an * interrupt so the handlers will be called */ XScuGic_Enable(&InterruptController, XPAR_FABRIC_AXI_TIMER_0_INTERRUPT_INTR); return XST_SUCCESS; } int main() { XTmrCtr TimerInstancePtr; int xStatus; print("##### Application Starts #####\n\r"); print("\r\n"); xStatus = XTmrCtr_Initialize(&TimerInstancePtr,XPAR_AXI_TIMER_0_DEVICE_ID); if(XST_SUCCESS != xStatus) print("TIMER INIT FAILED \n\r"); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //Set Timer Handler //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ XTmrCtr_SetHandler(&TimerInstancePtr, Timer_InterruptHandler, &TimerInstancePtr); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //Setting timer Reset Value //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ XTmrCtr_SetResetValue(&TimerInstancePtr, 0, //Change with generic value 0xf8000000); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //Setting timer Option (Interrupt Mode And Auto Reload ) //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ XTmrCtr_SetOptions(&TimerInstancePtr, XPAR_AXI_TIMER_0_DEVICE_ID, (XTC_INT_MODE_OPTION | XTC_AUTO_RELOAD_OPTION )); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //SCUGIC interrupt controller Intialization //Registration of the Timer ISR //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ xStatus=ScuGicInterrupt_Init(XPAR_PS7_SCUGIC_0_DEVICE_ID,&TimerInstancePtr); if(XST_SUCCESS != xStatus) print(" :( SCUGIC INIT FAILED \n\r"); //Start Timer xStatus = XGpio_Initialize(&LEDInst, LED_DEVICE_ID); if (xStatus != XST_SUCCESS) { print("PMOD GPIO initialize failure\r\n"); return -1; } XGpio_SetDataDirection(&LEDInst, 1, 0); // 2つ目の引数は1 XTmrCtr_Start(&TimerInstancePtr,0); print("timer start \n\r"); //Wait For interrupt; print("Wait for the Timer interrupt to tigger \r\n"); print("########################################\r\n"); print(" \r\n"); while(1) { } cleanup_platform(); return 0; }