description:zed LED Dimmerexample
REVISION:OCT, 2013:1.00initial version
//----------------------------------------------------------------------------
/*****************************include Files *********************************/
#include "Xparameters.h"
#include "xil_io.h"
#include "Xstatus.h"
These are static and must be added to our interrupt installation routines to map to the Scugic definition driver call.
#include "xscugic.h"//scugic driver//This file contains the configuration driver and the scope of use of GIC
Driver package for #include "Xil_exception.h"//exceptionhandlerd
/**************************constant Definitions *****************************/
/*
* The following constant maps to the name ofthe hardware instances
* were created in the EDK XPS system.
*/
#define PWM_BASE_ADDRESS0X43C00000
/* The followingdefinitions is 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//Error: undefined
#defineXPAR_FABRIC_PWM_W_INT_0_INTERRUPT_OUT_INTR 61//because of the error, he added
#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 is declared globally so theyare zeroed and so they is
* Easily accessible from a debugger
*/
These variable declarations are copied to the source code variable declarations section. The brightness variable is now globally declared, making it visible to
The ISR will be added later. The INTC variable is used to set a static definition used to set the Scugic driver.
These variable declarations are copied to the source code variable declaration
/* Ledbrightness level are now global to make are visble to the ISR. */
Volatile u32brightness;
/* The instanceof the Interrupt Controller Driver */
Static INTCINTC;
This will act as the calling hardware when the callback is interrupted by the service program.
/**************************main Code Entry **********************************/
void Pwmisr (VOID*INSTANCEPTR)
{
/* Inform theuser that an invalid value is 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's contained in
* Xstatus.h.
*
* @note None.
*
*****************************************************************************/
Intsetupinterruptsystem ()
{
int result;
Intc*intcinstanceptr = &Intc;
Xscugic_config*intcconfig;
/* Initializethe Interrupt Controller driver so it's 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'll be called if 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 the hardware have 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 A input value from Theconsole. */
Value = Inbyte ();
/* Convert the input ASCII character Toan integer value. */
period = value-0x30;
/* Print The input value 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 would
* 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);
This call enables the interrupt and ISR to be interrupted before the interrupt is processed
/* Setup The interrupts such thatinterrupt processing can occur. If an
* error occurs while setting upinterrupts and then exit the application. */
Status = Setupinterruptsystem ();
if (Status! = xst_success)
{
return xst_failure;
}
}
return status;
}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Zedboard Interrupt Main