Aplicaciones del temporizador
1, la interrupción del reloj. Taiwán antes y después del programa
2, para lograr un retraso.
3, contador contador
1 hora mundial de lucha contra
2 CPU temporizador privada
2.1 timer_loader
2.2 timer_counter
2.3 timer_control
get prescaler
15: 8 bits
]
conjunto escalador
La división de 0 a 225
- Leer el valor inicial,
- El bit correspondiente se pone a 0 y ~
- | Nuevo valor << 8 Bit 15: 8 se establece en un nuevo valor
permitir interrupción
permitir autoreload
activar el temporizador
temporizador de inicio
permitir bit = 1
reiniciar
carga re
cambiar el valor del contador simutaniously
2.4 timer_interrupt_state
3 TTC
4 código
Globales 4,1 horas
s32 usleep(u32 useconds)
{
XTime tEnd, tCur;
XTime_GetTime(&tCur);
tEnd = tCur + (((XTime) useconds) * COUNTS_PER_USECOND);
do
{
XTime_GetTime(&tCur);
} while (tCur < tEnd);
return 0;
}
La idea es llegar a alcanzar el momento presente TCUR, después de calcular el tiempo de retardo después tienden useconds, después de pedir constantemente temporizador de tiempo actual, con el tiempo, va a alcanzar o superar tienden, en este tiempo de retardo que se considere completa, se puede dejar de fumar. Aquí XTime_GetTime leer el reloj mundial, dijo más tarde detalle.
4.2 temporizador privada
static XScuGic GIC; //GIC
static XScuTimer Timer;//timer
(1) GIC inicialización y se vuelven de hardware
Esta sección generalmente sin cambios
1) carga GIC cfg
使用
XScuGic_CfgInitialize (GIC, IntcConfig,
IntcConfig-> CpuBaseAddress);
variable intermedia requiere XScuGic_Config * IntcConfig ;, IntcConfig = XScuGic_LookupConfig (INTC_DEVICE_ID);
2) IRQ abierta lanzador de hardware
Xil_ExceptionRegisterHandler(5,
(Xil_ExceptionHandler)XScuGic_InterruptHandler,
(void *)IntcInstancePtr);
Xil_ExceptionEnable();
int Init_Intr_System(XScuGic * IntcInstancePtr) //一般不需要修改
{
int Status;
XScuGic_Config *IntcConfig;
/*
* Initialize the interrupt controller driver so that it is ready to
* use.
*/
IntcConfig = XScuGic_LookupConfig(INTC_DEVICE_ID);
if (NULL == IntcConfig) {
return XST_FAILURE;
}
Status = XScuGic_CfgInitialize(IntcInstancePtr, IntcConfig,
IntcConfig->CpuBaseAddress);
if (Status != XST_SUCCESS) {
return XST_FAILURE;
}
/* Enable interrupts from the hardware */
Xil_ExceptionInit();
Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT,
(Xil_ExceptionHandler)XScuGic_InterruptHandler,
(void *)IntcInstancePtr);
Xil_ExceptionEnable();
return XST_SUCCESS;
}
(2) temporizador conectado GIC, y permite GIC
1) conexión GIC, y proporciona una transacción después de la interrupción del temporizador lanzador TimerIntrHandler
XScuGic_Connect (GicInstancePtr, TimerIntrId,
(Xil_ExceptionHandler) TimerIntrHandler, // configurar el temporizador de interrupción
(* void) TimerInstancePtr);
static void TimerIntrHandler(void *CallBackRef)
{
XScuTimer *TimerInstancePtr = (XScuTimer *) CallBackRef;
XScuTimer_ClearInterruptStatus(TimerInstancePtr);
sec++;
printf("seconds is %d \n",sec);
}
2) Activar el GIC, y priorizar
XScuGic_Enable(GicInstancePtr, TimerIntrId);//enable the interrupt for the Timer at GIC
XScuGic_SetPriorityTriggerType(GicInstancePtr, TimerIntrId, 0XA0 , 3 ) ;
void Timer_Setup_Intr_System(XScuGic *GicInstancePtr,XScuTimer *TimerInstancePtr, u16 TimerIntrId)//29号
{
XScuGic_Connect(GicInstancePtr, TimerIntrId,
(Xil_ExceptionHandler)TimerIntrHandler,//set up the timer interrupt
(void *)TimerInstancePtr);
XScuGic_Enable(GicInstancePtr, TimerIntrId);//enable the interrupt for the Timer at GIC
XScuGic_SetPriorityTriggerType(GicInstancePtr, TimerIntrId, 0XA0 , 3 ) ;
}
(3) los ajustes del temporizador y permitir interrupción
1) inicialización TimerPtr
variable de cfg medio XScuTimer_Config * TMRConfigPtr; // temporizador config
2) cuatro operaciones
Conjunto de frecuencia, el valor de recuento se carga automáticamente recarga, habilitar las interrupciones
XScuTimer_SetPrescaler(TimerPtr, PrescalerValue) ;
XScuTimer_LoadTimer(TimerPtr, Load_Value);
XScuTimer_EnableAutoReload(TimerPtr);
XScuTimer_EnableInterrupt(TimerPtr);//enable interrupt on the timer
int Timer_init(XScuTimer *TimerPtr, u8 PrescalerValue , u32 Load_Value,u32 DeviceId)
{
XScuTimer_Config *TMRConfigPtr; //timer config
TMRConfigPtr = XScuTimer_LookupConfig(DeviceId);
XScuTimer_CfgInitialize(TimerPtr, TMRConfigPtr,TMRConfigPtr->BaseAddr);
XScuTimer_SetPrescaler(TimerPtr, PrescalerValue) ;
XScuTimer_LoadTimer(TimerPtr, Load_Value);
XScuTimer_EnableAutoReload(TimerPtr);
XScuTimer_EnableInterrupt(TimerPtr);//enable interrupt on the timer
return 1;
}
(4) temporizador empieza a contar
XScuTimer_Start(TimerPtr);