arch: nios2: add timing implementation
Add timing implementation for NIOS2 architecture. Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
parent
a180b33c55
commit
150c82c8f9
3 changed files with 67 additions and 0 deletions
|
@ -55,6 +55,7 @@ config NIOS2
|
||||||
select ATOMIC_OPERATIONS_C
|
select ATOMIC_OPERATIONS_C
|
||||||
select HAS_DTS
|
select HAS_DTS
|
||||||
imply XIP
|
imply XIP
|
||||||
|
select ARCH_HAS_TIMING_FUNCTIONS
|
||||||
help
|
help
|
||||||
Nios II Gen 2 architecture
|
Nios II Gen 2 architecture
|
||||||
|
|
||||||
|
|
|
@ -16,3 +16,4 @@ zephyr_library_sources(
|
||||||
)
|
)
|
||||||
|
|
||||||
zephyr_library_sources_ifdef(CONFIG_IRQ_OFFLOAD irq_offload.c)
|
zephyr_library_sources_ifdef(CONFIG_IRQ_OFFLOAD irq_offload.c)
|
||||||
|
zephyr_library_sources_ifdef(CONFIG_TIMING_FUNCTIONS timing.c)
|
||||||
|
|
65
arch/nios2/core/timing.c
Normal file
65
arch/nios2/core/timing.c
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2020 Intel Corporation.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <kernel.h>
|
||||||
|
#include <sys_clock.h>
|
||||||
|
#include <timing/timing.h>
|
||||||
|
#include "altera_avalon_timer_regs.h"
|
||||||
|
|
||||||
|
#define NIOS2_SUBTRACT_CLOCK_CYCLES(val) \
|
||||||
|
((IORD_ALTERA_AVALON_TIMER_PERIODH(TIMER_0_BASE) << 16 | \
|
||||||
|
(IORD_ALTERA_AVALON_TIMER_PERIODL(TIMER_0_BASE))) - \
|
||||||
|
((uint32_t)val))
|
||||||
|
|
||||||
|
#define TIMING_INFO_OS_GET_TIME() \
|
||||||
|
(NIOS2_SUBTRACT_CLOCK_CYCLES( \
|
||||||
|
((uint32_t)IORD_ALTERA_AVALON_TIMER_SNAPH(TIMER_0_BASE) \
|
||||||
|
<< 16) | \
|
||||||
|
((uint32_t)IORD_ALTERA_AVALON_TIMER_SNAPL(TIMER_0_BASE))))
|
||||||
|
|
||||||
|
void timing_init(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void timing_start(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void timing_stop(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
timing_t timing_counter_get(void)
|
||||||
|
{
|
||||||
|
IOWR_ALTERA_AVALON_TIMER_SNAPL(TIMER_0_BASE, 10);
|
||||||
|
return TIMING_INFO_OS_GET_TIME();
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t timing_cycles_get(volatile timing_t *const start,
|
||||||
|
volatile timing_t *const end)
|
||||||
|
{
|
||||||
|
return (*end - *start);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t timing_freq_get(void)
|
||||||
|
{
|
||||||
|
return sys_clock_hw_cycles_per_sec();
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t timing_cycles_to_ns(uint64_t cycles)
|
||||||
|
{
|
||||||
|
return k_cyc_to_ns_floor64(cycles);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t timing_cycles_to_ns_avg(uint64_t cycles, uint32_t count)
|
||||||
|
{
|
||||||
|
return timing_cycles_to_ns(cycles) / count;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t timing_freq_get_mhz(void)
|
||||||
|
{
|
||||||
|
return (uint32_t)(timing_freq_get() / 1000000);
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue