OCEOS/oceos kernel/timer

From wiki
Jump to navigation Jump to search

OCEOS System Time

Introduction

SPARC

In OCEOS for SPARC system time is based on two chained 32-bit timers.
No interrupts are involved, the current system time is obtained by reading the two timer counter registers (in an atomic way) and then inverting the values since the timers count down.
The scaler associated with the timers is configured based on the system clock frequency to decrement the low order timer every microsecond. This decrements the high order timer when it rolls over, every 71.6 minutes approximately. The 64-bit time range is very long, over 584,000 years.
The system time is reset to 0 by oceos_init().

User must define BSP_SYSFREQ. The example can be found in OCEOS demo projects.

#define BSP_SYSFREQ 100 
const unsigned int __oceos_bsp_sysfreq = BSP_SYSFREQ * 1000 * 1000;

Variable __oceos_bsp_sysfreq is used by OCEOS to set scaler for timer block.

User must define OCEOS_SYS_TIME_GPTIMER_ADDRESS. It is start address of timer unit.

#define OCEOS_SYS_TIME_GPTIMER_ADDRESS          0x80003000 
const U32_t __oceos_bsp_sys_time_handler = OCEOS_SYS_TIME_GPTIMER_ADDRESS;

__oceos_bsp_sys_time_handler is used by OCEOS to configure two timers to be used for system time.

Timer index in Timer unit starts from 1. In timer chain, timer with smaller index is timer lowest, decrements to zero and then decrements the timer highest. User must specify index of timer highest in timer unit. This must be 2 or higher, depends on number of timers in timer unit. In the case where the index is 2, timer lowest is index 1 and timer highest is index 2.

#define SYS_TIME_TIMER_INDEX                    2  // System time is using two chained timers. This index is higher timer index
...
 /*
  * Create the application configuration structure
  */
struct application_configuration           app_config = {0};
app_config.sys_time_timer_index          = SYS_TIME_TIMER_INDEX;          // 0 and 1 => invalid index

ARM Cortex-M