Specifications
Embedded System Tools Guide (EDK 6.2i) www.xilinx.com 339
UG111 (v1.4) January 30, 2004 1-800-255-7778
Example Systems for PowerPC
R
Example C Program
#include <xtmrctr_l.h>
#include <xgpio_l.h>
#include <xparameters.h>
/* Global variables: count is the count displayed using the 
 * LEDs, and timer_count is the interrupt frequency.
 */
unsigned int count = 1; /* default count */
unsigned int timer_count = 1; /* default timer_count */
/* timer interrupt service routine */
void timer_int_handler(void * baseaddr_p) {
unsigned int csr;
 unsigned int gpio_data;
 /* Read timer 0 CSR to see if it raised the interrupt */
 csr = XTmrCtr_mGetControlStatusReg(XPAR_MYTIMER_BASEADDR, 0);
 if (csr & XTC_CSR_INT_OCCURED_MASK) {
 /* Increment the count */
 if ((count <<= 1) > 8) {
 count = 1;
 }
 /* Write value to gpio. 0 means light up, hence count is negated */
 gpio_data = ~count;
 XGpio_mSetDataReg(XPAR_MYGPIO_BASEADDR, gpio_data);
 /* Clear the timer interrupt */
 XTmrCtr_mSetControlStatusReg(XPAR_MYTIMER_BASEADDR, 0, csr);
 } 
}
void
main() {
 unsigned int gpio_data;
/* Initialize exception handling */
 XExc_Init();
 /* Register external interrupt handler */
 XExc_RegisterHandler(XEXC_ID_NON_CRITICAL_INT, 
(XExceptionHandler)timer_int_handler, (void *)XPAR_MYTIMER_BASEADDR
);
/* Set the gpio as output on high 3 bits (LEDs)*/
 XGpio_mSetDataDirection(XPAR_MYGPIO_BASEADDR, 0x00);
 /* set the number of cycles the timer counts before interrupting */
 XTmrCtr_mSetLoadReg(XPAR_MYTIMER_BASEADDR, 0, 
(timer_count*timer_count+1) * 1000000);










