OCEOS/oceos kernel/timer

From wiki
Jump to navigation Jump to search

OCEOS System Time

Introduction

SPARC

SPARC System Time Introduction

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().

SPARC System Time Configurations

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
Timer Unit


ARM Cortex-M

ARM Cortex-M System Time Introduction

In OCEOS for ARM Cortex-M, system time is based on SysTick.
The processor has a 24-bit system timer, SysTick, that counts down from the reload value to zero, reloads (wraps to) the value in the LOAD register on the next clock edge, then counts down on subsequent clocks.
When the processor is halted for debugging the counter does not decrement.
OCEOS initializes the timer to be driven from MCK and counting down to zero asserts SysTick exception request.
OCEOS has 64 bit counter which is increased by 0xFFFFFF value every time timer reloads.
OCEOS system time is in microseconds.

ARM Cortex-M System Time Configurations

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 calculate time in microseconds passed.

User must include OCEOS implemented SysTick handler oceos_SysTick_Handler() to the Vector table, so it is called every time SysTick exception request is asserted.

void oceos_SysTick_Handler(void);