forked from Imagelibrary/rtems
arm: Simplify CPU counter support
Use the standard ARMv7-M systick module for the ARMv7-M CPU counter instead of DWT counter since the DWT counter is affected by power saving states. Use an inline function for _CPU_Counter_difference() for all ARM BSPs. Update #3456.
This commit is contained in:
78
bsps/arm/include/bsp/clock-armv7m.h
Normal file
78
bsps/arm/include/bsp/clock-armv7m.h
Normal file
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright (c) 2011, 2018 Sebastian Huber. All rights reserved.
|
||||
*
|
||||
* embedded brains GmbH
|
||||
* Dornierstr. 4
|
||||
* 82178 Puchheim
|
||||
* Germany
|
||||
* <rtems@embedded-brains.de>
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.org/license/LICENSE.
|
||||
*/
|
||||
|
||||
#ifndef BSP_CLOCK_ARMV7M_H
|
||||
#define BSP_CLOCK_ARMV7M_H
|
||||
|
||||
#include <rtems/score/armv7m.h>
|
||||
#include <rtems/timecounter.h>
|
||||
|
||||
#include <bsp.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#ifdef ARM_MULTILIB_ARCH_V7M
|
||||
|
||||
typedef struct {
|
||||
struct timecounter base;
|
||||
uint32_t ticks;
|
||||
} ARMV7M_Timecounter;
|
||||
|
||||
extern ARMV7M_Timecounter _ARMV7M_TC;
|
||||
|
||||
static inline uint32_t _ARMV7M_Clock_frequency(void)
|
||||
{
|
||||
#ifdef BSP_ARMV7M_SYSTICK_FREQUENCY
|
||||
return BSP_ARMV7M_SYSTICK_FREQUENCY;
|
||||
#else
|
||||
volatile ARMV7M_Systick *systick = _ARMV7M_Systick;
|
||||
return ARMV7M_SYSTICK_CALIB_TENMS_GET(systick->calib) * 100;
|
||||
#endif
|
||||
}
|
||||
|
||||
static uint32_t _ARMV7M_Clock_counter(ARMV7M_Timecounter *tc)
|
||||
{
|
||||
volatile ARMV7M_Systick *systick;
|
||||
rtems_interrupt_level level;
|
||||
uint32_t interval;
|
||||
uint32_t counter;
|
||||
uint32_t ticks;
|
||||
|
||||
systick = _ARMV7M_Systick;
|
||||
interval = systick->rvr;
|
||||
|
||||
rtems_interrupt_disable(level);
|
||||
counter = systick->cvr;
|
||||
ticks = tc->ticks;
|
||||
|
||||
if ((systick->csr & ARMV7M_SYSTICK_CSR_COUNTFLAG) != 0) {
|
||||
ticks += interval;
|
||||
tc->ticks = ticks;
|
||||
}
|
||||
|
||||
counter = interval - counter + ticks;
|
||||
rtems_interrupt_enable(level);
|
||||
|
||||
return counter;
|
||||
}
|
||||
|
||||
#endif /* ARM_MULTILIB_ARCH_V7M */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* BSP_CLOCK_ARMV7M_H */
|
||||
Reference in New Issue
Block a user