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
0044 #include <bsp.h>
0045 #include <bspopts.h>
0046 #include <rtems/sysinit.h>
0047 #include <rtems/timecounter.h>
0048 #include <bsp/sparc-counter.h>
0049
0050 extern int CLOCK_SPEED;
0051
0052 #define LEON2_TIMER_1_FREQUENCY 1000000
0053
0054 static struct timecounter leon2_tc;
0055
0056 static void leon2_clock_init( void )
0057 {
0058 struct timecounter *tc;
0059
0060 tc = &leon2_tc;
0061 tc->tc_get_timecount = _SPARC_Get_timecount_clock;
0062 tc->tc_counter_mask = 0xffffffff;
0063 tc->tc_frequency = LEON2_TIMER_1_FREQUENCY;
0064 tc->tc_quality = RTEMS_TIMECOUNTER_QUALITY_CLOCK_DRIVER;
0065 rtems_timecounter_install(tc);
0066 }
0067
0068 static void leon2_clock_at_tick( void )
0069 {
0070 SPARC_Counter *counter;
0071 rtems_interrupt_level level;
0072
0073 counter = &_SPARC_Counter;
0074 rtems_interrupt_local_disable(level);
0075
0076 LEON_Clear_interrupt( LEON_INTERRUPT_TIMER1 );
0077 counter->accumulated += counter->interval;
0078
0079 rtems_interrupt_local_enable(level);
0080 }
0081
0082 static void leon2_clock_initialize_early( void )
0083 {
0084 SPARC_Counter *counter;
0085
0086 LEON_REG.Timer_Reload_1 =
0087 rtems_configuration_get_microseconds_per_tick() - 1;
0088 LEON_REG.Timer_Control_1 = (
0089 LEON_REG_TIMER_COUNTER_ENABLE_COUNTING |
0090 LEON_REG_TIMER_COUNTER_RELOAD_AT_ZERO |
0091 LEON_REG_TIMER_COUNTER_LOAD_COUNTER
0092 );
0093
0094 counter = &_SPARC_Counter;
0095 counter->read_isr_disabled = _SPARC_Counter_read_clock_isr_disabled;
0096 counter->read = _SPARC_Counter_read_clock;
0097 counter->counter_register = &LEON_REG.Timer_Counter_1;
0098 counter->pending_register = &LEON_REG.Interrupt_Pending;
0099 counter->pending_mask = UINT32_C(1) << LEON_INTERRUPT_TIMER1;
0100 counter->accumulated = rtems_configuration_get_microseconds_per_tick();
0101 counter->interval = rtems_configuration_get_microseconds_per_tick();
0102 }
0103
0104 RTEMS_SYSINIT_ITEM(
0105 leon2_clock_initialize_early,
0106 RTEMS_SYSINIT_CPU_COUNTER,
0107 RTEMS_SYSINIT_ORDER_FIRST
0108 );
0109
0110 uint32_t _CPU_Counter_frequency( void )
0111 {
0112 return LEON2_TIMER_1_FREQUENCY;
0113 }
0114
0115 #define Clock_driver_support_install_isr( _new ) \
0116 (void) rtems_interrupt_handler_install( \
0117 LEON_INTERRUPT_TIMER1, \
0118 "Clock", \
0119 RTEMS_INTERRUPT_SHARED, \
0120 _new, \
0121 NULL \
0122 )
0123
0124 #define Clock_driver_support_at_tick(arg) leon2_clock_at_tick()
0125
0126 #define Clock_driver_support_initialize_hardware() leon2_clock_init()
0127
0128 #include "../../../shared/dev/clock/clockimpl.h"
0129
0130 SPARC_COUNTER_DEFINITION;