Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  * @ingroup RTEMSBSPsSPARCLEON2
0006  * @brief Clock Tick Device Driver
0007  *
0008  *  This routine initializes LEON timer 1 which used for the clock tick.
0009  *
0010  *  The tick frequency is directly programmed to the configured number of
0011  *  microseconds per tick.
0012  */
0013 
0014 /*
0015  *  COPYRIGHT (c) 1989-2008.
0016  *  On-Line Applications Research Corporation (OAR).
0017  *
0018  *  Modified for LEON BSP
0019  *  COPYRIGHT (c) 2004.
0020  *  Gaisler Research.
0021  *
0022  * Redistribution and use in source and binary forms, with or without
0023  * modification, are permitted provided that the following conditions
0024  * are met:
0025  * 1. Redistributions of source code must retain the above copyright
0026  *    notice, this list of conditions and the following disclaimer.
0027  * 2. Redistributions in binary form must reproduce the above copyright
0028  *    notice, this list of conditions and the following disclaimer in the
0029  *    documentation and/or other materials provided with the distribution.
0030  *
0031  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0032  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0033  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0034  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0035  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0036  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0037  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0038  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0039  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0040  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0041  * POSSIBILITY OF SUCH DAMAGE.
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;