Buscar este blog

martes, 25 de noviembre de 2014

PRACTICA # 4 TIMER TTC

  • En esta practica se desarrollara el uso del TTC (Triple Timer Counter) de 32 bits.
  • El objetivo es encencer los 8 leds de la zedboard de acuerdo al Timer TCC programado cada segundo. Para esto se habilitara la interrupcion y el manejador de la misma en el SDK.



ESQUEMA EN EL DIAGRAMA DE BLOQUES



  • SOLO NECESITAMOS HABILITAR UART1 Y TCC


  • ESPECIFICACION DE RELOJ DEL TTC0


  • SOFTWARE SDK

#include <stdio.h>



#include "Xscugic.h"
#include "xttcps.h"
#include "xgpio.h"


#define TTC_DEVICE_ID       XPAR_XTTCPS_0_DEVICE_ID
#define TTC_INTR_ID                     XPAR_XTTCPS_0_INTR
#define INTC_DEVICE_ID              XPAR_SCUGIC_SINGLE_DEVICE_ID

#define GPIO_EXAMPLE_DEVICE_ID  XPAR_AXI_GPIO_0_DEVICE_ID

#define LED_CHANNEL 1

typedef struct
{
            u32 OutputHz;           /* Output frequency */
            u16 Interval;           /* Interval value */
            u8 Prescaler;           /* Prescaler value */
            u16 Options;            /* Option settings */
} TmrCntrSetup;

static TmrCntrSetup SettingsTable[1] =
{
            {1, 0, 0, 0},           /* Ticker timer counter initial setup, only output freq */
};

static XScuGic Intc; //GIC
XGpio Gpio;        // The Instance of the GPIO Driver

int cnt = 0;

static void SetupInterruptSystem(XScuGic *GicInstancePtr, XTtcPs *TtcPsInt);
static void TickHandler(void *CallBackRef);


int main()
{

            long int delay, ust_limit = 83333323;
            int i, Status;

            XTtcPs_Config *Config;
            XTtcPs Timer;
            TmrCntrSetup *TimerSetup;

            TimerSetup = &SettingsTable[TTC_DEVICE_ID];
            XTtcPs_Stop(&Timer);

            printf("Microcarsil Timer TCC \n\r");

            //initialise the timer
            Config = XTtcPs_LookupConfig(TTC_DEVICE_ID);
            XTtcPs_CfgInitialize(&Timer, Config, Config->BaseAddress);

            TimerSetup->Options |= (XTTCPS_OPTION_INTERVAL_MODE | XTTCPS_OPTION_WAVE_DISABLE);

            XTtcPs_SetOptions(&Timer, TimerSetup->Options);
            XTtcPs_CalcIntervalFromFreq(&Timer, TimerSetup->OutputHz,&(TimerSetup->Interval), &(TimerSetup->Prescaler));

            XTtcPs_SetInterval(&Timer, TimerSetup->Interval);
            XTtcPs_SetPrescaler(&Timer, TimerSetup->Prescaler);

            SetupInterruptSystem(&Intc, &Timer);

            printf("Start TIMER \n\r");

            // Initialize the GPIO driver

            Status = XGpio_Initialize(&Gpio, GPIO_EXAMPLE_DEVICE_ID);
            if (Status != XST_SUCCESS) {
            return XST_FAILURE;
            }

            // Clear the LEDs
            XGpio_DiscreteWrite(&Gpio, LED_CHANNEL, 0);

            while(1)
            {
                        /*for(i=0;i<255;i++)
                        {
                              XGpio_DiscreteWrite(&Gpio, LED_CHANNEL, i);
                              for(delay=0;delay<ust_limit;delay++){};
                        }*/
    }

            return 0;
}

static void SetupInterruptSystem(XScuGic *GicInstancePtr, XTtcPs *TtcPsInt)
{

                        XScuGic_Config *IntcConfig; //GIC config
                        Xil_ExceptionInit();

                        //initialise the GIC
                        IntcConfig = XScuGic_LookupConfig(INTC_DEVICE_ID);

                        XScuGic_CfgInitialize(GicInstancePtr, IntcConfig, IntcConfig->CpuBaseAddress);

                //connect to the hardware
                        Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT,          (Xil_ExceptionHandler)XScuGic_InterruptHandler, GicInstancePtr);

                        XScuGic_Connect(GicInstancePtr, TTC_INTR_ID,(Xil_ExceptionHandler)TickHandler, (void *)TtcPsInt);


                        XScuGic_Enable(GicInstancePtr, TTC_INTR_ID);
                        XTtcPs_EnableInterrupts(TtcPsInt, XTTCPS_IXR_INTERVAL_MASK);

                        XTtcPs_Start(TtcPsInt);

                        // Enable interrupts in the Processor.
                        Xil_ExceptionEnableMask(XIL_EXCEPTION_IRQ);
}

static void TickHandler(void *CallBackRef)
{
            u32 StatusEvent;

            StatusEvent = XTtcPs_GetInterruptStatus((XTtcPs *)CallBackRef);
            XTtcPs_ClearInterruptStatus((XTtcPs *)CallBackRef, StatusEvent);

            printf("cnt = %d\n\r", cnt++);
            XGpio_DiscreteWrite(&Gpio, LED_CHANNEL, cnt);

}


  • ECLIPSE FUNCIONANDO


  • ZEDBOARD FUNCIONANDO








No hay comentarios.:

Publicar un comentario