File indexing completed on 2025-05-11 08:24:08
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043 #include <bsp.h>
0044 #include <bsp/fatal.h>
0045 #include <bsp/irq-generic.h>
0046 #include <bsp/leon3.h>
0047 #include <grlib/irqamp.h>
0048 #include <rtems/score/profiling.h>
0049 #include <rtems/timecounter.h>
0050
0051
0052
0053
0054
0055
0056
0057 #ifndef RTEMS_DRVMGR_STARTUP
0058
0059
0060 static int clkirq;
0061
0062 #if defined(RTEMS_PROFILING) && \
0063 (defined(LEON3_HAS_ASR_22_23_UP_COUNTER) || \
0064 defined(LEON3_PROBE_ASR_22_23_UP_COUNTER) || \
0065 defined(LEON3_IRQAMP_PROBE_TIMESTAMP))
0066
0067 #define LEON3_CLOCK_PROBE_IRQAMP_TIMESTAMP
0068
0069 #define IRQMP_TIMESTAMP_S1_S2 ((1U << 25) | (1U << 26))
0070
0071 static void leon3_tc_tick_default(void)
0072 {
0073 rtems_timecounter_tick();
0074 }
0075
0076 static void (*leon3_tc_tick)(void) = leon3_tc_tick_default;
0077
0078 static void leon3_tc_do_tick(void)
0079 {
0080 (*leon3_tc_tick)();
0081 }
0082
0083 static void leon3_tc_tick_irqmp_timestamp(void)
0084 {
0085 irqamp_timestamp *irqmp_ts =
0086 irqamp_get_timestamp_registers(LEON3_IrqCtrl_Regs);
0087 uint32_t first = grlib_load_32(&irqmp_ts->itstmpas);
0088 uint32_t second = grlib_load_32(&irqmp_ts->itcnt);
0089 uint32_t control = grlib_load_32(&irqmp_ts->itstmpc);
0090
0091 control |= IRQMP_TIMESTAMP_S1_S2;
0092 grlib_store_32(&irqmp_ts->itstmpc, control);
0093
0094 _Profiling_Update_max_interrupt_delay(_Per_CPU_Get(), second - first);
0095
0096 rtems_timecounter_tick();
0097 }
0098
0099 static void leon3_tc_tick_irqmp_timestamp_init(void)
0100 {
0101
0102
0103
0104
0105
0106 #ifdef RTEMS_SMP
0107 static Atomic_Uint counter = ATOMIC_INITIALIZER_UINT(0);
0108
0109 bool done =
0110 _Atomic_Fetch_add_uint(&counter, 1, ATOMIC_ORDER_RELAXED)
0111 == rtems_scheduler_get_processor_maximum() - 1;
0112 #else
0113 bool done = true;
0114 #endif
0115
0116 irqamp_timestamp *irqmp_ts =
0117 irqamp_get_timestamp_registers(LEON3_IrqCtrl_Regs);
0118 uint32_t ks = 1U << 5;
0119 uint32_t control = grlib_load_32(&irqmp_ts->itstmpc);
0120
0121 control = ks | IRQMP_TIMESTAMP_S1_S2 | (unsigned int) clkirq;
0122 grlib_store_32(&irqmp_ts->itstmpc, control);
0123
0124 if (done) {
0125 leon3_tc_tick = leon3_tc_tick_irqmp_timestamp;
0126 }
0127
0128 rtems_timecounter_tick();
0129 }
0130 #else
0131 static void leon3_tc_do_tick(void)
0132 {
0133 rtems_timecounter_tick();
0134 }
0135 #endif
0136
0137 #define Adjust_clkirq_for_node() do { clkirq += LEON3_CLOCK_INDEX; } while(0)
0138
0139 #define Clock_driver_support_find_timer() \
0140 do { \
0141 \
0142 if (LEON3_Timer_Regs) { \
0143 clkirq = (grlib_load_32(&LEON3_Timer_Regs->config) & 0xf8) >> 3; \
0144 \
0145 Adjust_clkirq_for_node(); \
0146 } \
0147 } while (0)
0148
0149 #define Clock_driver_support_install_isr(isr) \
0150 bsp_clock_handler_install(isr)
0151
0152 static rtems_interrupt_entry leon3_clock_interrupt_entry;
0153
0154 static void bsp_clock_handler_install(rtems_interrupt_handler isr)
0155 {
0156 rtems_status_code sc;
0157
0158 rtems_interrupt_entry_initialize(
0159 &leon3_clock_interrupt_entry,
0160 isr,
0161 NULL,
0162 "Clock"
0163 );
0164 sc = rtems_interrupt_entry_install(
0165 clkirq,
0166 RTEMS_INTERRUPT_UNIQUE,
0167 &leon3_clock_interrupt_entry
0168 );
0169 if (sc != RTEMS_SUCCESSFUL) {
0170 rtems_fatal(RTEMS_FATAL_SOURCE_BSP, LEON3_FATAL_CLOCK_INITIALIZATION);
0171 }
0172 }
0173
0174 #define Clock_driver_support_set_interrupt_affinity(online_processors) \
0175 bsp_interrupt_set_affinity(clkirq, online_processors)
0176
0177 static void leon3_clock_initialize(void)
0178 {
0179 gptimer_timer *timer;
0180
0181 timer = &LEON3_Timer_Regs->timer[LEON3_CLOCK_INDEX];
0182
0183 grlib_store_32(
0184 &timer->trldval,
0185 rtems_configuration_get_microseconds_per_tick() - 1
0186 );
0187 grlib_store_32(
0188 &timer->tctrl,
0189 GPTIMER_TCTRL_EN | GPTIMER_TCTRL_RS | GPTIMER_TCTRL_LD | GPTIMER_TCTRL_IE
0190 );
0191
0192 #if defined(LEON3_CLOCK_PROBE_IRQAMP_TIMESTAMP)
0193 if (irqamp_get_timestamp_registers(LEON3_IrqCtrl_Regs) != NULL) {
0194 leon3_tc_tick = leon3_tc_tick_irqmp_timestamp_init;
0195 }
0196 #endif
0197
0198 rtems_timecounter_install(&leon3_timecounter_instance.base);
0199 }
0200
0201 #define Clock_driver_support_initialize_hardware() \
0202 leon3_clock_initialize()
0203
0204 #define Clock_driver_timecounter_tick(arg) leon3_tc_do_tick()
0205
0206 #define BSP_FEATURE_IRQ_EXTENSION
0207
0208 #include "../../../shared/dev/clock/clockimpl.h"
0209
0210 #endif