1.20.4 MIPS Core Timer (CORETIMER)
The core timer is built into the MIPS CPU and it is a free running 32-bit timer that increments at half the system clock frequency (SYSCLK). This timer is implemented in the form of two co-processor registers called Count register and Compare register. When the Count register matches the Compare register, an interrupt is signaled. Core timer is not a periodic timer as the Count register does not reset on a compare match. The incrementing of Count can be optionally suspended during Debug mode.
Using The Library
The core timer peripheral library can be used to generate periodic callback in interrupt mode or create blocking delay function.
Periodic Callback in Interrupt mode
This example demonstrates how to use Core Timer to generate periodic callback. The time period is configured using MHC or the period set API.
/* This function is called at specified periodic interval */ void CORETIMER_EventHandler(uintptr_t context) { /* Toggle LED */ LED_Toggle(); } int main(void) { /* Initialize all modules */ SYS_Initialize ( NULL ); /* Register Callback */ CORETIMER_CallbackSet(CORETIMER_EventHandler, (uintptr_t) NULL); /* Start the Timer */ CORETIMER_Start(); }
Library Interface
MIPS Core Timer peripheral library provides the following interfaces:
Functions
Name | Description |
---|---|
CORETIMER_Initialize | Initializes given instance of CORETIMER |
CORETIMER_Start | Starts the Core Timer |
CORETIMER_Stop | Stops the Core Timer counter |
CORETIMER_PeriodSet | Sets the period value of a Core timer |
CORETIMER_CompareSet | Sets the compare value of a Core timer |
CORETIMER_CounterGet | Reads the Core timer counter value |
CORETIMER_FrequencyGet | Provides the given Core timer's counter-increment frequency |
CORETIMER_CallbackSet | Sets the callback_fn function for an match |
CORETIMER_DelayMs | Generates blocking delay in milliseconds |
CORETIMER_DelayUs | Generates blocking delay in microseconds |
Data types and constants
Name | Type | Description |
---|---|---|
CORETIMER_CALLBACK | Typedef | Defines the function pointer data type and function signature for the CORETIMER callback function |