Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:08

0001 /*
0002  *  This routine initializes the Real Time Clock Counter Timer which is
0003  *  part of the MEC on the ERC32 CPU.
0004  *
0005  *  The tick frequency is directly programmed to the configured number of
0006  *  microseconds per tick.
0007  */
0008 
0009 /*
0010  *  COPYRIGHT (c) 1989-2008.
0011  *  On-Line Applications Research Corporation (OAR).
0012  *
0013  *  The license and distribution terms for this file may be
0014  *  found in the file LICENSE in this distribution or at
0015  *  http://www.rtems.org/license/LICENSE.
0016  *
0017  *  Ported to ERC32 implementation of the SPARC by On-Line Applications
0018  *  Research Corporation (OAR) under contract to the European Space
0019  *  Agency (ESA).
0020  *
0021  *  ERC32 modifications of respective RTEMS file: COPYRIGHT (c) 1995.
0022  *  European Space Agency.
0023  */
0024 
0025 #include <bsp.h>
0026 #include <rtems/irq-extension.h>
0027 #include <rtems/sysinit.h>
0028 #include <rtems/timecounter.h>
0029 #include <bsp/sparc-counter.h>
0030 
0031 extern int CLOCK_SPEED;
0032 
0033 #define ERC32_REAL_TIME_CLOCK_FREQUENCY 1000000
0034 
0035 static struct timecounter erc32_tc;
0036 
0037 static void erc32_clock_init( void )
0038 {
0039   struct timecounter *tc;
0040 
0041   tc = &erc32_tc;
0042   tc->tc_get_timecount = _SPARC_Get_timecount_clock;
0043   tc->tc_counter_mask = 0xffffffff;
0044   tc->tc_frequency = ERC32_REAL_TIME_CLOCK_FREQUENCY;
0045   tc->tc_quality = RTEMS_TIMECOUNTER_QUALITY_CLOCK_DRIVER;
0046   rtems_timecounter_install(tc);
0047 }
0048 
0049 uint32_t _CPU_Counter_frequency( void )
0050 {
0051   return ERC32_REAL_TIME_CLOCK_FREQUENCY;
0052 }
0053 
0054 static void erc32_clock_at_tick( SPARC_Counter *counter )
0055 {
0056   rtems_interrupt_level level;
0057 
0058   rtems_interrupt_local_disable(level);
0059 
0060   ERC32_Clear_interrupt( ERC32_INTERRUPT_REAL_TIME_CLOCK );
0061   counter->accumulated += counter->interval;
0062 
0063   rtems_interrupt_local_enable(level);
0064 }
0065 
0066 static void erc32_clock_initialize_early( void )
0067 {
0068   SPARC_Counter *counter;
0069 
0070   /* approximately 1 us per countdown */
0071   ERC32_MEC.Real_Time_Clock_Scalar = CLOCK_SPEED - 1;
0072   ERC32_MEC.Real_Time_Clock_Counter =
0073     rtems_configuration_get_microseconds_per_tick();
0074   ERC32_MEC_Set_Real_Time_Clock_Timer_Control(
0075       ERC32_MEC_TIMER_COUNTER_ENABLE_COUNTING |
0076       ERC32_MEC_TIMER_COUNTER_LOAD_SCALER |
0077       ERC32_MEC_TIMER_COUNTER_LOAD_COUNTER
0078   );
0079   ERC32_MEC_Set_Real_Time_Clock_Timer_Control(
0080     ERC32_MEC_TIMER_COUNTER_ENABLE_COUNTING |
0081     ERC32_MEC_TIMER_COUNTER_RELOAD_AT_ZERO
0082   );
0083 
0084   counter = &_SPARC_Counter;
0085   counter->read_isr_disabled = _SPARC_Counter_read_clock_isr_disabled;
0086   counter->read = _SPARC_Counter_read_clock;
0087   counter->counter_register = &ERC32_MEC.Real_Time_Clock_Counter,
0088   counter->pending_register = &ERC32_MEC.Interrupt_Pending;
0089   counter->pending_mask = UINT32_C(1) << ERC32_INTERRUPT_REAL_TIME_CLOCK;
0090   counter->accumulated = rtems_configuration_get_microseconds_per_tick();
0091   counter->interval = rtems_configuration_get_microseconds_per_tick();
0092 }
0093 
0094 RTEMS_SYSINIT_ITEM(
0095   erc32_clock_initialize_early,
0096   RTEMS_SYSINIT_CPU_COUNTER,
0097   RTEMS_SYSINIT_ORDER_FIRST
0098 );
0099 
0100 /*
0101  *  The Real Time Clock Counter Timer uses this trap type.
0102  */
0103 #define CLOCK_VECTOR ERC32_TRAP_TYPE( ERC32_INTERRUPT_REAL_TIME_CLOCK )
0104 
0105 #define Clock_driver_support_install_isr( _new ) \
0106   (void) rtems_interrupt_handler_install( \
0107     ERC32_INTERRUPT_REAL_TIME_CLOCK, \
0108     "Clock", \
0109     RTEMS_INTERRUPT_SHARED, \
0110     _new, \
0111     &_SPARC_Counter \
0112   )
0113 
0114 #define Clock_driver_support_set_interrupt_affinity( _online_processors ) \
0115   do { \
0116     (void) _online_processors; \
0117   } while (0)
0118 
0119 #define Clock_driver_support_at_tick(arg) erc32_clock_at_tick(arg)
0120 
0121 #define Clock_driver_support_initialize_hardware() erc32_clock_init()
0122 
0123 #include "../../../shared/dev/clock/clockimpl.h"
0124 
0125 SPARC_COUNTER_DEFINITION;