2022-11-14 10:59:44 +01:00
|
|
|
/* SPDX-License-Identifier: BSD-2-Clause */
|
|
|
|
|
|
2013-12-02 14:07:35 -06:00
|
|
|
/**
|
|
|
|
|
* @file
|
2019-03-04 15:32:15 +01:00
|
|
|
* @ingroup RTEMSBSPsSPARCLEON2
|
2013-12-02 14:07:35 -06:00
|
|
|
* @brief Clock Tick Device Driver
|
2006-01-09 10:36:06 +00:00
|
|
|
*
|
|
|
|
|
* This routine initializes LEON timer 1 which used for the clock tick.
|
|
|
|
|
*
|
|
|
|
|
* The tick frequency is directly programmed to the configured number of
|
|
|
|
|
* microseconds per tick.
|
2014-04-03 15:14:47 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*
|
2008-05-07 17:40:52 +00:00
|
|
|
* COPYRIGHT (c) 1989-2008.
|
2006-01-09 10:36:06 +00:00
|
|
|
* On-Line Applications Research Corporation (OAR).
|
|
|
|
|
*
|
2006-11-16 16:31:34 +00:00
|
|
|
* Modified for LEON BSP
|
|
|
|
|
* COPYRIGHT (c) 2004.
|
|
|
|
|
* Gaisler Research.
|
|
|
|
|
*
|
2022-11-14 10:59:44 +01:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
|
* are met:
|
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
2006-01-09 10:36:06 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <bsp.h>
|
2006-11-16 16:31:34 +00:00
|
|
|
#include <bspopts.h>
|
2018-05-03 13:03:27 +02:00
|
|
|
#include <rtems/sysinit.h>
|
2015-04-01 15:33:25 +02:00
|
|
|
#include <rtems/timecounter.h>
|
2023-09-14 16:08:53 +02:00
|
|
|
#include <bsp/sparc-counter.h>
|
2006-01-09 10:36:06 +00:00
|
|
|
|
2018-05-03 13:03:27 +02:00
|
|
|
extern int CLOCK_SPEED;
|
|
|
|
|
|
|
|
|
|
#define LEON2_TIMER_1_FREQUENCY 1000000
|
|
|
|
|
|
|
|
|
|
static struct timecounter leon2_tc;
|
2015-04-01 15:33:25 +02:00
|
|
|
|
2018-05-03 13:03:27 +02:00
|
|
|
static void leon2_clock_init( void )
|
2015-04-01 15:33:25 +02:00
|
|
|
{
|
2018-05-03 13:03:27 +02:00
|
|
|
struct timecounter *tc;
|
|
|
|
|
|
|
|
|
|
tc = &leon2_tc;
|
|
|
|
|
tc->tc_get_timecount = _SPARC_Get_timecount_clock;
|
|
|
|
|
tc->tc_counter_mask = 0xffffffff;
|
|
|
|
|
tc->tc_frequency = LEON2_TIMER_1_FREQUENCY;
|
|
|
|
|
tc->tc_quality = RTEMS_TIMECOUNTER_QUALITY_CLOCK_DRIVER;
|
|
|
|
|
rtems_timecounter_install(tc);
|
2015-04-01 15:33:25 +02:00
|
|
|
}
|
|
|
|
|
|
2018-05-03 13:03:27 +02:00
|
|
|
static void leon2_clock_at_tick( void )
|
2015-04-01 15:33:25 +02:00
|
|
|
{
|
2018-05-03 13:03:27 +02:00
|
|
|
SPARC_Counter *counter;
|
|
|
|
|
rtems_interrupt_level level;
|
|
|
|
|
|
2023-09-14 16:08:53 +02:00
|
|
|
counter = &_SPARC_Counter;
|
2018-05-03 13:03:27 +02:00
|
|
|
rtems_interrupt_local_disable(level);
|
|
|
|
|
|
|
|
|
|
LEON_Clear_interrupt( LEON_INTERRUPT_TIMER1 );
|
|
|
|
|
counter->accumulated += counter->interval;
|
|
|
|
|
|
|
|
|
|
rtems_interrupt_local_enable(level);
|
2015-04-01 15:33:25 +02:00
|
|
|
}
|
|
|
|
|
|
2018-05-03 13:03:27 +02:00
|
|
|
static void leon2_clock_initialize_early( void )
|
2015-04-01 15:33:25 +02:00
|
|
|
{
|
2018-05-03 13:03:27 +02:00
|
|
|
SPARC_Counter *counter;
|
|
|
|
|
|
|
|
|
|
LEON_REG.Timer_Reload_1 =
|
|
|
|
|
rtems_configuration_get_microseconds_per_tick() - 1;
|
|
|
|
|
LEON_REG.Timer_Control_1 = (
|
|
|
|
|
LEON_REG_TIMER_COUNTER_ENABLE_COUNTING |
|
|
|
|
|
LEON_REG_TIMER_COUNTER_RELOAD_AT_ZERO |
|
|
|
|
|
LEON_REG_TIMER_COUNTER_LOAD_COUNTER
|
2015-04-01 15:33:25 +02:00
|
|
|
);
|
|
|
|
|
|
2023-09-14 16:08:53 +02:00
|
|
|
counter = &_SPARC_Counter;
|
2018-05-03 13:03:27 +02:00
|
|
|
counter->read_isr_disabled = _SPARC_Counter_read_clock_isr_disabled;
|
|
|
|
|
counter->read = _SPARC_Counter_read_clock;
|
|
|
|
|
counter->counter_register = &LEON_REG.Timer_Counter_1;
|
|
|
|
|
counter->pending_register = &LEON_REG.Interrupt_Pending;
|
|
|
|
|
counter->pending_mask = UINT32_C(1) << LEON_INTERRUPT_TIMER1;
|
|
|
|
|
counter->accumulated = rtems_configuration_get_microseconds_per_tick();
|
|
|
|
|
counter->interval = rtems_configuration_get_microseconds_per_tick();
|
2015-12-23 07:29:47 +01:00
|
|
|
}
|
|
|
|
|
|
2018-05-03 13:03:27 +02:00
|
|
|
RTEMS_SYSINIT_ITEM(
|
|
|
|
|
leon2_clock_initialize_early,
|
|
|
|
|
RTEMS_SYSINIT_CPU_COUNTER,
|
|
|
|
|
RTEMS_SYSINIT_ORDER_FIRST
|
|
|
|
|
);
|
|
|
|
|
|
2023-09-14 16:08:53 +02:00
|
|
|
uint32_t _CPU_Counter_frequency( void )
|
2015-04-01 15:33:25 +02:00
|
|
|
{
|
2018-05-03 13:03:27 +02:00
|
|
|
return LEON2_TIMER_1_FREQUENCY;
|
2015-04-01 15:33:25 +02:00
|
|
|
}
|
|
|
|
|
|
2017-09-18 08:22:38 +02:00
|
|
|
#define Clock_driver_support_install_isr( _new ) \
|
2021-06-22 15:40:39 +02:00
|
|
|
(void) rtems_interrupt_handler_install( \
|
|
|
|
|
LEON_INTERRUPT_TIMER1, \
|
|
|
|
|
"Clock", \
|
|
|
|
|
RTEMS_INTERRUPT_SHARED, \
|
|
|
|
|
_new, \
|
|
|
|
|
NULL \
|
|
|
|
|
)
|
2006-11-16 16:31:34 +00:00
|
|
|
|
2023-03-23 16:53:30 +01:00
|
|
|
#define Clock_driver_support_at_tick(arg) leon2_clock_at_tick()
|
2006-11-16 16:31:34 +00:00
|
|
|
|
2018-05-03 13:03:27 +02:00
|
|
|
#define Clock_driver_support_initialize_hardware() leon2_clock_init()
|
2008-05-07 17:40:52 +00:00
|
|
|
|
2018-04-19 06:35:52 +02:00
|
|
|
#include "../../../shared/dev/clock/clockimpl.h"
|
2016-06-20 10:08:39 +02:00
|
|
|
|
2016-06-22 13:45:02 +02:00
|
|
|
SPARC_COUNTER_DEFINITION;
|