mirror of
https://github.com/t-crest/rtems.git
synced 2025-12-07 16:13:11 +00:00
Added get_cpu_freq function to read out the CPU frequency.
This commit is contained in:
@@ -88,12 +88,24 @@ u64 get_cpu_time(void)
|
|||||||
return (((u64)u) << 32) | l;
|
return (((u64)u) << 32) | l;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t get_cpu_freq(void)
|
||||||
|
{
|
||||||
|
uint32_t freq;
|
||||||
|
__PATMOS_CPU_RD_FREQ(freq);
|
||||||
|
return freq;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t get_cpu_freq_mhz(void)
|
||||||
|
{
|
||||||
|
return get_cpu_freq()/1000000U;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
uint32_t bsp_clock_nanoseconds_since_last_tick(void)
|
uint32_t bsp_clock_nanoseconds_since_last_tick(void)
|
||||||
{
|
{
|
||||||
uint32_t usecs;
|
uint32_t usecs;
|
||||||
|
|
||||||
usecs = get_cpu_cycles()/__PATMOS_FREQ_MHZ - Clock_driver_ticks*rtems_configuration_get_microseconds_per_tick() - usecs_offset;
|
usecs = get_cpu_cycles()/get_cpu_freq_mhz() - Clock_driver_ticks*rtems_configuration_get_microseconds_per_tick() - usecs_offset;
|
||||||
|
|
||||||
return usecs * 1000;
|
return usecs * 1000;
|
||||||
}
|
}
|
||||||
@@ -214,7 +226,7 @@ rtems_isr Clock_isr(
|
|||||||
*/
|
*/
|
||||||
Clock_driver_ticks += 1;
|
Clock_driver_ticks += 1;
|
||||||
|
|
||||||
__PATMOS_RTC_WR_INTERVAL(rtems_configuration_get_microseconds_per_tick() * __PATMOS_FREQ_MHZ);
|
__PATMOS_RTC_WR_INTERVAL(rtems_configuration_get_microseconds_per_tick() * get_cpu_freq_mhz());
|
||||||
|
|
||||||
rtems_clock_tick();
|
rtems_clock_tick();
|
||||||
|
|
||||||
@@ -330,12 +342,12 @@ void Install_clock(
|
|||||||
);
|
);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
__PATMOS_RTC_WR_INTERVAL(rtems_configuration_get_microseconds_per_tick() * __PATMOS_FREQ_MHZ);
|
__PATMOS_RTC_WR_INTERVAL(rtems_configuration_get_microseconds_per_tick() * get_cpu_freq_mhz());
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* reset the cpu_cycles count to determine clock_nanoseconds_since_last_tick
|
* reset the cpu_cycles count to determine clock_nanoseconds_since_last_tick
|
||||||
*/
|
*/
|
||||||
//usecs_offset = get_cpu_cycles()/__PATMOS_FREQ_MHZ;
|
//usecs_offset = get_cpu_cycles()/get_cpu_freq_mhz();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Schedule the clock cleanup routine to execute if the application exits.
|
* Schedule the clock cleanup routine to execute if the application exits.
|
||||||
|
|||||||
@@ -94,12 +94,6 @@ extern void set_cpu_cycles (u64 time_warp);
|
|||||||
extern u64 get_cpu_cycles(void);
|
extern u64 get_cpu_cycles(void);
|
||||||
extern u64 get_cpu_time(void);
|
extern u64 get_cpu_time(void);
|
||||||
|
|
||||||
extern char __cycles_per_sec; /* linker symbol giving the CPU frequency */
|
|
||||||
|
|
||||||
#define __PATMOS_CPU_FREQ (int)(&__cycles_per_sec) /* CPU frequency in Hz */
|
|
||||||
#define __PATMOS_FREQ_MHZ __PATMOS_CPU_FREQ/1000000U
|
|
||||||
#define __PATMOS_INF 0xFFFFFFFF /* maximum cycles the clock can run without interrupts */
|
|
||||||
|
|
||||||
/* Address to access the cycle counter low register of the RTC */
|
/* Address to access the cycle counter low register of the RTC */
|
||||||
#define __PATMOS_RTC_CYCLE_LOW_ADDR (&_timer_base + 0x00)
|
#define __PATMOS_RTC_CYCLE_LOW_ADDR (&_timer_base + 0x00)
|
||||||
|
|
||||||
@@ -149,6 +143,35 @@ extern char __cycles_per_sec; /* linker symbol giving the CPU frequency */
|
|||||||
* End of RTC Management
|
* End of RTC Management
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* CPU Info Management
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern char _cpuinfo_base; /* linker symbol giving the address of the CPU info */
|
||||||
|
|
||||||
|
extern uint32_t get_cpu_freq(void);
|
||||||
|
|
||||||
|
extern uint32_t get_cpu_freq_mhz(void);
|
||||||
|
|
||||||
|
#define __PATMOS_INF 0xFFFFFFFF /* maximum cycles the clock can run without interrupts */
|
||||||
|
|
||||||
|
/* Address to access the CPU id */
|
||||||
|
#define __PATMOS_CPU_ID_ADDR (&_cpuinfo_base + 0x00)
|
||||||
|
|
||||||
|
/* Address to access the CPU frequency */
|
||||||
|
#define __PATMOS_CPU_FREQ_ADDR (&_cpuinfo_base + 0x04)
|
||||||
|
|
||||||
|
/* Macro to read the CPU id */
|
||||||
|
#define __PATMOS_CPU_RD_ID(res) res = *((_iodev_ptr_t)__PATMOS_CPU_ID_ADDR);
|
||||||
|
|
||||||
|
/* Macro to read the CPU frequency */
|
||||||
|
#define __PATMOS_CPU_RD_FREQ(res) res = *((_iodev_ptr_t)__PATMOS_CPU_FREQ_ADDR);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* End of CPU Info Management
|
||||||
|
*/
|
||||||
|
|
||||||
#endif /* !ASM */
|
#endif /* !ASM */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|||||||
@@ -16,4 +16,4 @@ CPU_CFLAGS = -msoft-float
|
|||||||
# optimize flag: typically -O2
|
# optimize flag: typically -O2
|
||||||
CFLAGS_OPTIMIZE_V = -O2 -g -Xllc -trap-func=abort_trap
|
CFLAGS_OPTIMIZE_V = -O2 -g -Xllc -trap-func=abort_trap
|
||||||
|
|
||||||
LINK_LIBS += $(PROJECT_RELEASE)/lib/start.o $(PROJECT_RELEASE)/lib/libsyms.ll -l=c -l=rtemscpu -l=rtemsbsp -nostartfiles -Xgold -Map -Xgold map.map -Xgold --script=$(PROJECT_RELEASE)/lib/linkcmds -Xgold --defsym -Xgold __cycles_per_sec=5000000 -Xopt -disable-internalize
|
LINK_LIBS += $(PROJECT_RELEASE)/lib/start.o $(PROJECT_RELEASE)/lib/libsyms.ll -l=c -l=rtemscpu -l=rtemsbsp -nostartfiles -Xgold -Map -Xgold map.map -Xgold --script=$(PROJECT_RELEASE)/lib/linkcmds -Xopt -disable-internalize
|
||||||
@@ -42,7 +42,7 @@ int benchmark_timer_read(void)
|
|||||||
|
|
||||||
__PATMOS_RTC_RD_INTERVAL(total);
|
__PATMOS_RTC_RD_INTERVAL(total);
|
||||||
|
|
||||||
total = (__PATMOS_INF - total)/__PATMOS_FREQ_MHZ;
|
total = (__PATMOS_INF - total)/get_cpu_freq_mhz();
|
||||||
|
|
||||||
if ( benchmark_timer_find_average_overhead == true )
|
if ( benchmark_timer_find_average_overhead == true )
|
||||||
return total; /* in one microsecond units */
|
return total; /* in one microsecond units */
|
||||||
|
|||||||
Reference in New Issue
Block a user