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

zedboard中断main

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

标签:

//Description:         Zed LED DimmerExample

//Revision:            Oct 25, 2013: 1.00Initial version

//----------------------------------------------------------------------------

/*****************************Include Files *********************************/

#include"xparameters.h"

#include"xil_io.h"

#include"xstatus.h"

//这些都是静态的,必须添加到我们的中断安装例程映射到SCUGIC定义驱动程序调用。

#include"xscugic.h"//SCUGIC的驱动//该文件包含配置驱动程序以及 GIC 的使用范围

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

 

/**************************Constant Definitions *****************************/

/*

 * The following constant maps to the name ofthe hardware instances that

 * were created in the EDK XPS system.

 */

#define PWM_BASE_ADDRESS0x43C00000

/* The followingdefinitions 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//报错:未定义

#defineXPAR_FABRIC_PWM_W_INT_0_INTERRUPT_OUT_INTR 61//因为报错,自己添加的

#defineINTC_PWM_INTERRUPT_ID XPAR_FABRIC_PWM_W_INT_0_INTERRUPT_OUT_INTR

#define INTCXScuGic

#defineINTC_HANDLER XScuGic_InterruptHandler

#defineINTC_DEVICE_ID XPAR_PS7_SCUGIC_0_DEVICE_ID

/**************************Variable Definitions *****************************/

/*

 * The following are declared globally so theyare zeroed and so they are

 * easily accessible from a debugger

 */

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

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

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

 

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

volatile u32brightness;

/* The Instanceof the Interrupt Controller Driver */

static INTCIntc;

//这将作为调用的硬件时,回调的中断服务程序。

/**************************Main Code Entry **********************************/

void PWMIsr(void*InstancePtr)

{

/* Inform theuser 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

* PWM controllerin order to clear the pending interrupt. */

brightness = 0;

Xil_Out32(PWM_BASE_ADDRESS,brightness);

}

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

/**

* This functionsets up the interrupt system for the PWM dimmer controller.

* The processingcontained in this function assumes the hardware system was

* built with aninterrupt controller.

*

* @param None.

*

* @return Astatus indicating XST_SUCCESS or a value that is contained in

* xstatus.h.

*

* @note None.

*

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

intSetupInterruptSystem()

{

int result;

INTC*IntcInstancePtr = &Intc;

XScuGic_Config*IntcConfig;

/* Initializethe interrupt controller driver so that it is ready to

* use. */

IntcConfig =XScuGic_LookupConfig(INTC_DEVICE_ID);

if (IntcConfig== NULL)

{

returnXST_FAILURE;

}

/* Initializethe 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);

/* Connect theinterrupt handler that will be called when an

* interruptoccurs for the device. */

result =XScuGic_Connect(IntcInstancePtr, INTC_PWM_INTERRUPT_ID,

(Xil_ExceptionHandler)PWMIsr, 0);

if (result !=XST_SUCCESS)

{

return result;

}

/* Enable theinterrupt for the PWM controller device. */

XScuGic_Enable(IntcInstancePtr,INTC_PWM_INTERRUPT_ID);

/* Initializethe exception table and register the interrupt controller

* handler withthe exception table. */

Xil_ExceptionInit();

Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT,

(Xil_ExceptionHandler)INTC_HANDLER,IntcInstancePtr);

/* Enablenon-critical exceptions */

Xil_ExceptionEnable();

returnXST_SUCCESS;

}

int main(void)

{

      //printf("HelloWorld\n");

    int status = XST_SUCCESS;

    u32 value = 0;

    u32 period = 0;

    brightness = 0; // u32 brightness = 0;

 

    /* Initialize the LED Dimmer controller toa safe PWM value. */

    Xil_Out32(PWM_BASE_ADDRESS, 0);

 

    /* Now that the hardware has beeninitialized, continuously loop while

     * prompting the user for updates to thebrightness level. */

    while (1)

    {

        /* Prompt the user to select abrightness value ranging from

         * 0 to 9. */

        print("Select a Brightness between0 and 9\n\r");

 

        /* Read an input value from theconsole. */

        value = inbyte();

 

        /* Convert the input ASCII character toan integer value. */

        period = value - 0x30;

 

        /* Print the input value back to theconsole to provide some

         * feedback to the user. */

        xil_printf("Brightness Level %dselected\n\r", period);

 

        /* Since the LED width is 1e6 clkcycles, we need to normalize

         * the period to that clk.  Since we accept values 0-9, that will

         * scale period from 0-999,000.  0 turns off LEDs, 999,000 is full

         * brightness. */

        brightness = period * 110000;

 

        /* Write the duty_cycle width (Period)out to the PL PWM

         * peripheral. */

        Xil_Out32(PWM_BASE_ADDRESS,brightness);

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

        /* Setup the interrupts such thatinterrupt processing can occur. If an

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

        status = SetupInterruptSystem();

        if (status != XST_SUCCESS)

        {

        return XST_FAILURE;

        }

    }

 

    return status;

}

 

 

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

zedboard中断main

标签:

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

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