vidoda设计
和gpio_mio实验硬件相同
PS-PL Configuration ->general
SDK设计
#include <stdio.h>
#include "xparameters.h"
#include "xgpiops.h"
#include "xstatus.h"
#include "xplatform_info.h"
#include <xil_printf.h>
#include "sleep.h"
#include "xscutimer.h"
#include "xscugic.h"#define GPIO_DEVICE_ID XPAR_XGPIOPS_0_DEVICE_ID
#define MIO7_LED 7 //ps端LED
#define LED_DELAY 10000000
#define TIMER_DEVICE_ID XPAR_XSCUTIMER_0_DEVICE_ID
#define TIMER_IRPT_INTR XPAR_SCUTIMER_INTR#define TIMER_LOAD_VALUE 0x3F83C3F //0.2s 闪烁一次,0.2*1000_000_000/(1000/333) - 1 = 3F83C3F
#define INTC_DEVICE_ID XPAR_SCUGIC_SINGLE_DEVICE_IDXGpioPs Gpio; /* The driver instance for GPIO Device. */
XScuTimer TimerInstance;
XScuGic IntcInstance;// 中断处理函数
void TimerIntrHandler(void *CallBackRef)
{//LED 状态,用于控制 LED 灯状态翻转static int led_state = 0;XScuTimer *timer_ptr = (XScuTimer *) CallBackRef;if(led_state == 0)led_state = 1;elseled_state = 0;//向指定引脚写入数据: 0 或 1XGpioPs_WritePin(&Gpio, MIO7_LED,led_state);//清除定时器中断标志XScuTimer_ClearInterruptStatus(timer_ptr);
}
// mio初始化
void mio_init()
{XGpioPs_Config *ConfigPtr;//初始化gpio驱动//根据器件id,查找器件配置信息ConfigPtr = XGpioPs_LookupConfig(GPIO_DEVICE_ID);//初始化gpio参数XGpioPs_CfgInitialize(&Gpio, ConfigPtr,ConfigPtr->BaseAddr);//gpio方向设置为输出(0:输入、1:输出)XGpioPs_SetDirectionPin(&Gpio, MIO7_LED, 1);
// XGpioPs_SetDirectionPin(&Gpio, 50, 0);//设置输出使能(0:关闭、1:打开)XGpioPs_SetOutputEnablePin(&Gpio, MIO7_LED, 1);
// XGpioPs_WritePin(&Gpio, MIO7_LED, 0x0);
}
// 定时器中断初始化
void TimerSetupIntrSystem(XScuGic *IntcInstancePtr, XScuTimer *TimerInstancePtr, u16 TimerIntrId)
{XScuGic_Config *IntcConfig;
// 定时器中断初始化IntcConfig = XScuGic_LookupConfig(INTC_DEVICE_ID);XScuGic_CfgInitialize(IntcInstancePtr, IntcConfig,IntcConfig->CpuBaseAddress);Xil_ExceptionInit();
// 关联中断函数Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_IRQ_INT,(Xil_ExceptionHandler)XScuGic_InterruptHandler,IntcInstancePtr);
// 关联中断函数XScuGic_Connect(IntcInstancePtr, TimerIntrId,(Xil_ExceptionHandler)TimerIntrHandler,(void *)TimerInstancePtr);
// 使能GIC定时器中断XScuGic_Enable(IntcInstancePtr, TimerIntrId);
// 使能定时器中断XScuTimer_EnableInterrupt(TimerInstancePtr);Xil_ExceptionEnable();
}// 定时器初始化
int timer_init(XScuGic *IntcInstancePtr, XScuTimer * TimerInstancePtr, u16 TimerDeviceId, u16 TimerIntrId)
{int Status;
// int LastTimerExpired = 0;XScuTimer_Config *ConfigPtr;
// 初始化私有定时器ConfigPtr = XScuTimer_LookupConfig(TimerDeviceId);XScuTimer_CfgInitialize(TimerInstancePtr, ConfigPtr,ConfigPtr->BaseAddr);
// 硬件自测Status = XScuTimer_SelfTest(TimerInstancePtr);if (Status != XST_SUCCESS) {return XST_FAILURE;}
// 设置中断系统TimerSetupIntrSystem(IntcInstancePtr,TimerInstancePtr, TimerIntrId);
// 使能自动重下载模式XScuTimer_EnableAutoReload(TimerInstancePtr);
// 加载定时器计数器XScuTimer_LoadTimer(TimerInstancePtr, TIMER_LOAD_VALUE);
// 开始定时器计数XScuTimer_Start(TimerInstancePtr);return 0;
}int main()
{
// u32 Data;printf("***hello,hello,hello,hello,hello,hello***\r\n");mio_init();timer_init(&IntcInstance, &TimerInstance,TIMER_DEVICE_ID, TIMER_IRPT_INTR);XScuTimer_Start(&TimerInstance); //启动定时器return 0;
}