ZYNQ TTC使用方法

目录

  • 前言
  • 平台
  • Features
  • Block Diagram
  • 直接上应用代码
    • 定时器初始化
    • 注册中断函数

前言

计时器是嵌入式编程中最常使用的模块了,本文介绍下ZYNQ中定时器的使用,大部分内容参照官方手册ug1085

平台

Vivado 2017.4
Windows 10
ZCU102开发板

Features

ZYNQ TTC使用方法_第1张图片

Block Diagram

ZYNQ TTC使用方法_第2张图片

直接上应用代码

定时器初始化

int XTtcPs_Init(XTtcPs * TimerPtr,u16 DeviceId ,u16 rate_hz)
{
	int Status;
	XTtcPs_Config *Config;

	XInterval Interval;
	u8 Prescaler;

	Config = XTtcPs_LookupConfig(DeviceId);  // 查找设备

	Status = XTtcPs_CfgInitialize(TimerPtr, Config, Config->BaseAddress);

	if (Status != XST_SUCCESS) {
		xil_printf("In %s:\t XTtcPs %d initialization Failed...\r\n",
				__func__,DeviceId);
		return XST_FAILURE;
	}
	else
	{
		xil_printf("In %s:\t XTtcPs %d initialization Success...\r\n",
				__func__,DeviceId);
	}
	XTtcPs_SetOptions(TimerPtr, XTTCPS_OPTION_INTERVAL_MODE | XTTCPS_OPTION_WAVE_DISABLE);
	XTtcPs_CalcIntervalFromFreq(TimerPtr, rate_hz, &Interval, &Prescaler);
	XTtcPs_SetInterval(TimerPtr, Interval);
	XTtcPs_SetPrescaler(TimerPtr, Prescaler);
	//XTtcPs_Start(TimerPtr);
	return Status;
}

注册中断函数

要注意,中断函数里尽量快进快出,以免出现不必要的问题。

	XScuGic_SetPriorityTriggerType(ScuGicInstancePtr, XPAR_XTTCPS_2_DEVICE_ID,0x10, 0x3); //设置优先级
	XScuGic_Connect(&ScuGicInstance, XPAR_XTTCPS_2_INTR,(Xil_InterruptHandler)XTtcPs2_ScTick_callback,
			(void *)&XTtcPs2_ScTick);
	XScuGic_Enable(&ScuGicInstance, XPAR_XTTCPS_2_INTR);
	XTtcPs_EnableInterrupts(&XTtcPs2_ScTick, XTTCPS_IXR_INTERVAL_MASK);

你可能感兴趣的:(ZYNQ,ZYNQ,定时器)