码迷,mamicode.com
首页 > 数据库 > 详细

zedboard中断实现

时间:2015-08-05 22:30:44      阅读:337      评论:0      收藏:0      [点我收藏+]

标签:

关于zedboard中断的博客

http://m.blog.csdn.net/blog/oxp7085915/17378687

http://www.tuicool.com/articles/mY3qIvi

在系统编程的中断处理程序,也称为中断服务例程(ISR),在微控制器固件,操作系统回调子例程,或设备驱动器,其执行是由一个硬件中断的接收触发。中断处理程序中有大量的功能,这些功能的基础上的原因而变化的中断生成和速度时,中断处理程序完成其任务。

中断处理程序是事件处理程序的一个低级别的对应。这些处理程序通常通过硬件中断发起,并且用于维护的硬件设备和操作的保护模式,如系统调用之间的转换。

在实验8中,我们使用的SDK导入功能导入一些现有的代码到一个空白应用程序项目。我们将执行相同的步骤在这个实验中,但只是从一个启动已知良好的代码库访问了一块定制的硬件内置到系统中。从这一点来说,我们将修改应用程序代码到中断响应由自定义的硬件平台时产生一个不正确的PWM值被写入PWM控制器。

在这个实验中所指的LED并不是MicroZed内实施可编程逻辑设计到用户连接的LED PL。只有PWM IP块在PL实现。由于采用独立模式MicroZed(未插入载板)不具有连接至PL I / O引脚的任何的LED,则留作为额外锻炼学生MicroZed连接到载板,并添加I / O引脚针对LED引脚顶级硬件设计上的限制,如果需要的。然而,这个实验是旨在集中后中断功能,并且可以成功地与完成或者没有实际的PL I / O连接到LED的实施。

 

用到的中断函数

int XScuGic_CfgInitialize
(XScuGic *InstancePtr,
XScuGic_Config *ConfigPtr,
u32 EffectiveAddr)

初始化特定中断控制器实例/驱动。  

·该函数初始化XscuGic结构和初始矢量表的字段存根函数调用。 

·在初始化时中断源都是禁用的。

int XScuGic_Connect
(XScuGic *InstancePtr,
u32 Int_Id,
Xil_InterruptHandler Handler,
void *CallBackRef)

当中断时,确保int-id和相关的处理函数之间的联系
void XScuGic_Enable
(XScuGic *InstancePtr,
u32 Int_Id)

?使能提供作为参数Int_Id中断源。

?这个函数被调用后,任何挂起的中断如果被Int_Id 指定会发生
· Enables the interrupt source provided as the argument Int_Id.
· Any pending interrupt condition for the specified Int_Id will occurafter this function is called

void XScuGic_SetPriorityTriggerType
(XScuGic *InstancePtr,
u32 Int_Id,
u8 Priority,
u8 Trigger)

指定中断优先级和触发类型指定的IRQ中断源。

XScuGic_Config * XScuGic_LookupConfig (u16DeviceId)

?look up基于所述唯一的设备ID的设备配置。

?列表中包含系统中的每个设备的配置信息。
void XScuGic_InterruptHandler (XScuGic *InstancePtr)
?This功能是主中断处理程序的驱动程序。

?It必须连接到中断源,使得它被调用时中断控制器的中断被激活。

?It将解决哪些中断处于激活并启用,并调用相应的中断处理程序

voidXScuGic_Disable(XScuGic* InstancePtr,U32 Int_Id)

禁止提供作为参数Int_Id中断源。

Void XScuGic_GetPriorityTriggerType

(XScuGic*InstancePtr,U32 Int_Id, u8 *Priority,u8 *Trigger)

获取中断优先级和触发类型指定的IRQ中断源。

INT XScuGic_SelfTest(XScuGic* InstancePtr)

运行的驱动程序和相关的硬件设备自检。

此功能清除所有的中断使能位。

当此功能完成后所有中断将被禁用

1

#include "xscugic.h"//SCUGIC的驱动

#include "xil_exception.h"//ExceptionHandlerd的驱动包

将它们插入复制这些定义到源代码在PWM_BASE_ADDRESS定义的下面。这些都是静态的

必须添加到我们的中断安装例程映射到SCUGIC定义驱动程序调用。

2

/* Thefollowing definitions are related to handling interrupts from the

* PWMcontroller. */

#defineXPAR_PS7_SCUGIC_0_DEVICE_ID 0

#defineINTC_PWM_INTERRUPT_ID XPAR_FABRIC_PWM_W_INT_0_INTERRUPT_OUT_INTR

#defineINTC XScuGic

#defineINTC_HANDLER XScuGic_InterruptHandler

#defineINTC_DEVICE_ID XPAR_PS7_SCUGIC_0_DEVICE_ID

3

这些变量声明复制到源代码变量声明部分。亮度可变现在全局声明的,使其对可见光

ISR将在以后添加。该INTC变量是用来设置一个静态的定义用于设置SCUGIC驱动程序。

这些变量声明复制到源代码变量声明

/* LEDbrightness level is now global to make is visble to the ISR. */

volatile u32brightness;

/* TheInstance of the Interrupt Controller Driver */

static INTC Intc;

4

把此ISR插入到到源代码77行,它在步骤4中插入变量声明上面。这将作为调用的硬件时,回调的中断服务程序。

void PWMIsr(void*InstancePtr)

{

/* Informthe user that an invalid value was detected by the PWM

*controller. */

print("PWMValue exceeded, brightness reset to zero. Enter new value: \r\n");

/* Set thebrightness value to a safe value and write it to the

* PWMcontroller in order to clear the pending interrupt. */

brightness =0;

Xil_Out32(PWM_BASE_ADDRESS,brightness);

}
5

添加这个功能设置到源代码下面的ISR节插入它只是接近上述步骤5中插入ISR代码如下行89
此代码提供所需,使PWM中断是设置识别并附加PWMIsr(),为中断处理程序。

/****************************************************************************/

/**

* Thisfunction sets up the interrupt system for the PWM dimmer controller.

* Theprocessing contained in this function assumes the hardware system was

* builtwith an interrupt controller.

*

* @paramNone.

*

* @returnA status indicating XST_SUCCESS or a value that is contained in

*xstatus.h.

*

* @noteNone.

*

*****************************************************************************/

int SetupInterruptSystem()

{

intresult;

INTC*IntcInstancePtr = &Intc;

XScuGic_Config*IntcConfig;

/*Initialize the interrupt controller driver so that it is ready to

* use. */

IntcConfig =XScuGic_LookupConfig(INTC_DEVICE_ID);

if(IntcConfig == NULL)

{

returnXST_FAILURE;

}

/*Initialize the SCU and GIC to enable the desired interrupt

*configuration. */

result =XScuGic_CfgInitialize(IntcInstancePtr, IntcConfig,

IntcConfig->CpuBaseAddress);

if(result != XST_SUCCESS)

{

returnXST_FAILURE;

}

XScuGic_SetPriorityTriggerType(IntcInstancePtr,INTC_PWM_INTERRUPT_ID,

0xA0, 0x3);

/* Connectthe interrupt handler that will be called when an

*interrupt occurs for the device. */

result =XScuGic_Connect(IntcInstancePtr, INTC_PWM_INTERRUPT_ID,

(Xil_ExceptionHandler)PWMIsr, 0);

if(result != XST_SUCCESS)

{

returnresult;

}

/* Enablethe interrupt for the PWM controller device. */

XScuGic_Enable(IntcInstancePtr,INTC_PWM_INTERRUPT_ID);

/*Initialize the exception table and register the interrupt controller

* handlerwith the exception table. */

Xil_ExceptionInit();

Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT,

(Xil_ExceptionHandler)INTC_HANDLER,IntcInstancePtr);

/* Enablenon-critical exceptions */

Xil_ExceptionEnable();

returnXST_SUCCESS;

}

6

替代160行附近的亮度变量声明与此分配初始化亮度零值。

brightness = 0;

7添加代码

//这个调用,使能了中断和ISR,在中断处理之前

        /* Setupthe interrupts such that interrupt processing can occur. If an

        * error occurs while setting upinterrupts, then exit the application. */

        status = SetupInterruptSystem();

        if(status != XST_SUCCESS)

        {

        returnXST_FAILURE;

       }

代码修改完毕,保存更新的源文件。SDK将检测的源代码,并改变自动重建应用程序项目,该没有错误报道在SDK控制台。

 

版权声明:本文为博主原创文章,未经博主允许不得转载。

zedboard中断实现

标签:

原文地址:http://blog.csdn.net/kobesdu/article/details/47302679

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!