arc: add _tsc_read for 64-bit timestamp
This implementation of _tsc_read returns a 64-bit value that is derived from the 64-bit tick count multiplied by hwcycles per tick, and then it adds the current value from the 32-bit timer. This produces a 64-bit time. There is a bunch of math here, which could be avoided if the CPU is built with Real-Time-Clock option. EM Starter Kit SOCs don't have this. I don't think Arduino 101 does either. See ZEP-1559 Change-Id: I9f846d170246556ac40fe2f45809e457c6375d8c Signed-off-by: Chuck Jordan <cjordan@synopsys.com>
This commit is contained in:
parent
35fcb2736c
commit
ae15a26751
3 changed files with 49 additions and 1 deletions
|
@ -3,7 +3,7 @@ ccflags-y +=-I$(srctree)/arch/$(ARCH)/include
|
|||
|
||||
obj-y += thread.o thread_entry_wrapper.o \
|
||||
cpu_idle.o fast_irq.o fatal.o fault.o \
|
||||
fault_s.o irq_manage.o cache.o \
|
||||
fault_s.o irq_manage.o cache.o timestamp.o \
|
||||
isr_wrapper.o regular_irq.o swap.o \
|
||||
sys_fatal_error_handler.o
|
||||
|
||||
|
|
42
arch/arc/core/timestamp.c
Normal file
42
arch/arc/core/timestamp.c
Normal file
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright (c) 2017 Synopsys, Inc.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Time Stamp API for ARCv2
|
||||
*
|
||||
* Provide 64-bit time stamp API
|
||||
*/
|
||||
|
||||
#include <kernel.h>
|
||||
#include <toolchain.h>
|
||||
#include <kernel_structs.h>
|
||||
|
||||
extern int64_t _sys_clock_tick_count;
|
||||
extern int sys_clock_hw_cycles_per_tick;
|
||||
|
||||
/*
|
||||
* @brief Read 64-bit timestamp value
|
||||
*
|
||||
* This function returns a 64-bit bit time stamp value that is clocked
|
||||
* at the same frequency as the CPU.
|
||||
*
|
||||
* @return 64-bit time stamp value
|
||||
*/
|
||||
uint64_t _tsc_read(void)
|
||||
{
|
||||
unsigned int key;
|
||||
uint64_t t;
|
||||
uint32_t count;
|
||||
|
||||
key = irq_lock();
|
||||
t = (uint64_t)_sys_clock_tick_count;
|
||||
count = _arc_v2_aux_reg_read(_ARC_V2_TMR0_COUNT);
|
||||
irq_unlock(key);
|
||||
t *= (uint64_t)sys_clock_hw_cycles_per_tick;
|
||||
t += (uint64_t)count;
|
||||
return t;
|
||||
}
|
|
@ -21,6 +21,12 @@ extern "C" {
|
|||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
/**
|
||||
* @brief read timestamp register (CPU frequency)
|
||||
*/
|
||||
extern uint64_t _tsc_read(void);
|
||||
|
||||
|
||||
/* Implementation of sys_io.h's documented functions */
|
||||
|
||||
static ALWAYS_INLINE
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue