summaryrefslogtreecommitdiffstats
path: root/c
diff options
context:
space:
mode:
authorDaniel Hellstrom <daniel@gaisler.com>2015-02-19 09:25:09 +0100
committerDaniel Hellstrom <daniel@gaisler.com>2015-04-17 01:10:15 +0200
commite51eb80e8887b8e91b9a1dd80fc7a92ce22c218d (patch)
tree081f689eafe12067e8042833cb6890cba7f3d927 /c
parentleon3: make timer initialization configurable (diff)
downloadrtems-e51eb80e8887b8e91b9a1dd80fc7a92ce22c218d.tar.bz2
leon3,ngmp: simplify cpucounter initialization
Remove support for using the second timer for time stamping. Instead the user can configure the system clock timer to a higher base clock frequency (lower the prescaler). This change does not affect the GR712RC or LEON4-N2X. The GR712RC does not have two GPTIMERs and the N2X uses the Interrupt Controller for time stamping. Bow that the AMBA initialization code exports the AMBA device, the frequency can be obtained without an additional AMBA PnP scanning.
Diffstat (limited to 'c')
-rw-r--r--c/src/lib/libbsp/sparc/leon3/startup/cpucounter.c55
1 files changed, 6 insertions, 49 deletions
diff --git a/c/src/lib/libbsp/sparc/leon3/startup/cpucounter.c b/c/src/lib/libbsp/sparc/leon3/startup/cpucounter.c
index d28421c6d5..78096cd40a 100644
--- a/c/src/lib/libbsp/sparc/leon3/startup/cpucounter.c
+++ b/c/src/lib/libbsp/sparc/leon3/startup/cpucounter.c
@@ -16,11 +16,6 @@
#include <rtems/counter.h>
-static volatile struct gptimer_regs *adev_to_gpt(struct ambapp_dev *adev)
-{
- return (volatile struct gptimer_regs *) DEV_TO_APB(adev)->start;
-}
-
static CPU_Counter_ticks timestamp_counter_difference(
CPU_Counter_ticks second,
CPU_Counter_ticks first
@@ -29,14 +24,6 @@ static CPU_Counter_ticks timestamp_counter_difference(
return second - first;
}
-static CPU_Counter_ticks free_counter_difference(
- CPU_Counter_ticks second,
- CPU_Counter_ticks first
-)
-{
- return first - second;
-}
-
static CPU_Counter_ticks clock_counter_difference(
CPU_Counter_ticks second,
CPU_Counter_ticks first
@@ -66,8 +53,7 @@ void leon3_cpu_counter_initialize(void)
{
volatile struct irqmp_timestamp_regs *irqmp_ts =
&LEON3_IrqCtrl_Regs->timestamp[0];
- struct ambapp_dev *adev;
- int idx = 1;
+ unsigned int freq;
if (leon3_irqmp_has_timestamp(irqmp_ts)) {
/* Use the interrupt controller timestamp counter if available */
@@ -81,45 +67,16 @@ void leon3_cpu_counter_initialize(void)
);
/* Get and set the frequency */
- adev = (void *) ambapp_for_each(
- &ambapp_plb,
- OPTIONS_ALL | OPTIONS_APB_SLVS,
- VENDOR_GAISLER,
- GAISLER_IRQMP,
- ambapp_find_by_idx,
- NULL
- );
- rtems_counter_initialize_converter(ambapp_freq_get(&ambapp_plb, adev));
- } else {
- adev = (void *) ambapp_for_each(
- &ambapp_plb,
- OPTIONS_ALL | OPTIONS_APB_SLVS,
- VENDOR_GAISLER,
- GAISLER_GPTIMER,
- ambapp_find_by_idx,
- &idx
- );
- if (adev != NULL) {
- /* Use the second GPTIMER if available */
- volatile struct gptimer_regs *gpt = adev_to_gpt(adev);
- uint32_t max_frequency = ambapp_freq_get(&ambapp_plb, adev);
- unsigned min_prescaler = 8;
- uint32_t frequency = max_frequency / min_prescaler;
-
- gpt->scaler_reload = min_prescaler - 1;
- gpt->timer[0].reload = 0xffffffff;
- gpt->timer[0].ctrl = GPTIMER_TIMER_CTRL_EN | GPTIMER_TIMER_CTRL_RS
- | GPTIMER_TIMER_CTRL_LD;
-
- gpt_counter_initialize(gpt, 0, frequency, free_counter_difference);
- } else if (LEON3_Timer_Regs != NULL) {
+ rtems_counter_initialize_converter(ambapp_freq_get(&ambapp_plb, irqmp_dev));
+ } else if (LEON3_Timer_Regs != NULL) {
/* Fall back to the first GPTIMER if available */
+ freq = ambapp_freq_get(&ambapp_plb, timer_dev);
+
gpt_counter_initialize(
LEON3_Timer_Regs,
LEON3_CLOCK_INDEX,
- LEON3_GPTIMER_0_FREQUENCY_SET_BY_BOOT_LOADER,
+ freq / (LEON3_Timer_Regs->scaler_reload - 1),
clock_counter_difference
);
- }
}
}