Difference between revisions of "OCEOS/oceos kernel/timer"

From wiki
Jump to navigation Jump to search
 
(10 intermediate revisions by the same user not shown)
Line 67: Line 67:
<syntaxhighlight lang="C">
<syntaxhighlight lang="C">
void oceos_SysTick_Handler(void);
void oceos_SysTick_Handler(void);
</syntaxhighlight>
<syntaxhighlight lang="C">
.extern oceos_SysTick_Handler
.extern oceos_PendSV_Handler
.section .isr_vector
.align 2
.globl __isr_vector
__isr_vector:
.long __StackTop          /*0: Top of Stack        */
.long Reset_Handler        /*1: Reset Handler      */
.long NMI_Handler          /*2: NMI Handler        */
.long HardFault_Handler    /*3: Hard Fault Handler  */
.long MemManage_Handler    /*4: MPU Fault Handler  */
.long BusFault_Handler      /*5: Bus Fault Handler  */
.long UsageFault_Handler    /*6: Usage Fault Handler */
.long 0 /* Reserved */      /*7: Reserved            */
.long 0 /* Reserved */      /*8: Reserved            */
.long 0 /* Reserved */      /*9: Reserved            */
.long 0 /* Reserved */      /*10: Reserved          */
.long SVC_Handler          /*11: SVCall Handler    */
.long 0 /* Reserved */      /*12: Debug Monitor Handler */
.long 0 /* Reserved */      /*13: Reserved          */
.long oceos_PendSV_Handler  /*14: PendSV Handler    */
.long oceos_SysTick_Handler /*15: SysTick Handler    */
</syntaxhighlight>
</syntaxhighlight>
</blockquote>
</blockquote>


==<span style="color:#0000ff">API Functions</span>==
{| class="wikitable"
|+ API Functions
|-
! Directive                                                                            !! Description              !! main !! task !! IRQ handler
|-
| [[OCEOS/oceos kernel/timer#oceos_time_sys_get64()|oceos_time_sys_get64()]]  || Get Current system time  || *    || *    || *
|-
| [[OCEOS/oceos kernel/timer#oceos_time_sys_get32()|oceos_time_sys_get32()]]  || Get Current system time  || *    || *    || *
|}
===<span style="color:#0000ff">oceos_time_sys_get64()</span>===
<blockquote style="border-left-style: none;">
<span style="color:#1b7ac2">'''Header File'''</span><br>
'''''oceos_timer.h'''''<br>
<span style="color:#1b7ac2">'''Description'''</span><br>
Get the current system time (64-bit). This directive can be called from main() after [[OCEOS/oceos kernel/initialisation#oceos_init()|oceos_init()]].
<span style="color:#1b7ac2">'''Prototype'''</span><br>
<syntaxhighlight lang="C">
U64_t                  oceos_time_sys_get64(void);
</syntaxhighlight>
<span style="color:#1b7ac2">'''Parameters'''</span><br>
{| class="wikitable"
|-
! Parameter !! Description
|-
|  ||
|}
<span style="color:#1b7ac2">'''Returns'''</span><br>
This function returns U64_t.<br>
{| class="wikitable"
|-
! U64_t          !! Description
|-
| >= 0 || 64-bit System time in microseconds
|}
<span style="color:#1b7ac2">'''Example Usage'''</span><br>
<syntaxhighlight lang="C">
U64_t time;
time = oceos_time_sys_get64();
</syntaxhighlight>
</blockquote>
===<span style="color:#0000ff">oceos_time_sys_get32()</span>===
<blockquote style="border-left-style: none;">
<span style="color:#1b7ac2">'''Header File'''</span><br>
'''''oceos_timer.h'''''<br>
<span style="color:#1b7ac2">'''Description'''</span><br>
Get the current system time (32-bit). This directive can be called from main() after [[OCEOS/oceos kernel/initialisation#oceos_init()|oceos_init()]].
<span style="color:#1b7ac2">'''Prototype'''</span><br>
<syntaxhighlight lang="C">
U32_t                  oceos_time_sys_get32(void);
</syntaxhighlight>
<span style="color:#1b7ac2">'''Parameters'''</span><br>
{| class="wikitable"
|-
! Parameter !! Description
|-
|  ||
|}
<span style="color:#1b7ac2">'''Returns'''</span><br>
This function returns U32_t.<br>
{| class="wikitable"
|-
! U32_t !! Description
|-
| >= 0 || 32-bit System time in microseconds
|}
<span style="color:#1b7ac2">'''Example Usage'''</span><br>
<syntaxhighlight lang="C">
U32_t time;
time = oceos_time_sys_get32(); 
</syntaxhighlight>
</blockquote>
[[Category:backup]]
[[Category:backup]]

Latest revision as of 14:23, 21 March 2022

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.

Note

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);
	.extern oceos_SysTick_Handler
	.extern oceos_PendSV_Handler
	.section .isr_vector
	.align	2
	.globl	__isr_vector
__isr_vector:
	.long	__StackTop          /*0: Top of Stack        */
	.long Reset_Handler         /*1: Reset Handler       */
	.long NMI_Handler           /*2: NMI Handler         */
	.long HardFault_Handler     /*3: Hard Fault Handler  */
	.long MemManage_Handler     /*4: MPU Fault Handler   */
	.long BusFault_Handler      /*5: Bus Fault Handler   */
	.long UsageFault_Handler    /*6: Usage Fault Handler */
	.long 0 /* Reserved */      /*7: Reserved            */
	.long 0 /* Reserved */      /*8: Reserved            */
	.long 0 /* Reserved */      /*9: Reserved            */
	.long 0 /* Reserved */      /*10: Reserved           */
	.long SVC_Handler  	        /*11: SVCall Handler     */
	.long 0 /* Reserved */      /*12: Debug Monitor Handler */
	.long 0 /* Reserved */      /*13: Reserved           */
	.long oceos_PendSV_Handler  /*14: PendSV Handler     */
	.long oceos_SysTick_Handler /*15: SysTick Handler    */

API Functions

API Functions
Directive Description main task IRQ handler
oceos_time_sys_get64() Get Current system time * * *
oceos_time_sys_get32() Get Current system time * * *

oceos_time_sys_get64()

Header File
oceos_timer.h

Description
Get the current system time (64-bit). This directive can be called from main() after oceos_init().

Prototype

U64_t                   oceos_time_sys_get64(void);

Parameters

Parameter Description

Returns
This function returns U64_t.

U64_t Description
>= 0 64-bit System time in microseconds

Example Usage

 U64_t time;
 time = oceos_time_sys_get64();

oceos_time_sys_get32()

Header File
oceos_timer.h

Description
Get the current system time (32-bit). This directive can be called from main() after oceos_init().

Prototype

U32_t                   oceos_time_sys_get32(void);

Parameters

Parameter Description

Returns
This function returns U32_t.

U32_t Description
>= 0 32-bit System time in microseconds

Example Usage

 U32_t time;
 time = oceos_time_sys_get32();