📄 plf_misc.c
字号:
//==========================================================================
//
// plf_misc.c
//
// HAL platform miscellaneous functions
//
//==========================================================================
//####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
//
// eCos is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 or (at your option) any later version.
//
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License along
// with eCos; if not, write to the Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or inline functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. However the source code for this file must still be made available
// in accordance with section (3) of the GNU General Public License.
//
// This exception does not invalidate any other reasons why a work based on
// this file might be covered by the GNU General Public License.
//
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
// at http://sources.redhat.com/ecos/ecos-license/
// -------------------------------------------
//####ECOSGPLCOPYRIGHTEND####
//==========================================================================
//#####DESCRIPTIONBEGIN####
//
// Author(s): Uwe Kindler
// Contributors: Uwe Kindler, yoshinori sato
// Date: 2003-12-06
// Purpose: HAL miscellaneous functions
// Description: This file contains miscellaneous functions provided by the
// HAL.
//
//####DESCRIPTIONEND####
//
//==========================================================================
//=============================================================================
// DOXYGEN FILE HEADER
/// \file plf_misc.c
/// \brief HAL miscellaneous functions.
/// \author Uwe Kindler, yoshinori sato
/// \date 2003-12-06
///
/// This file contains miscellaneous functions provided by the
// HAL.
//=============================================================================
//==========================================================================
// INCLUDES
//==========================================================================
#include <pkgconf/hal.h>
#include <cyg/infra/diag.h>
#include <cyg/infra/cyg_type.h> // Base types
#include <cyg/hal/hal_arch.h> // architectural definitions
#include <cyg/hal/hal_io.h>
#include <cyg/hal/hal_if.h>
#include <cyg/hal/plf_intr.h>
#include <cyg/hal/var_arch.h>
#include <cyg/hal/hal_intr.h> // required for VSR initialisation
#ifdef CYGPKG_REDBOOT
#include <redboot.h>
#endif
//==========================================================================
// CROSS REFERNCES
//==========================================================================
///
/// Contains vector service routines for all interrupt vectors (vectors.S)
///
externC volatile CYG_ADDRESS hal_vsr_table[CYGNUM_HAL_VSR_COUNT];
///
/// Default interrupt vector service routine
externC void __default_interrupt_vsr(void);
//==========================================================================
// PLATFORM INIT
///
/// Additional platform initialisation.
/// These will perform any additional initialization needed by platform.
/// This typically includes further initialization of the interrupt
/// controller, PCI bus bridges, basic IO devices and enabling
/// the caches.
///
/// \note: At the moment there are nothing to do here for the EDOSK
/// platform except for calling hal_if_init() because we youse
/// virtual vector support.
//==========================================================================
void hal_platform_init(void)
{
//
// intialize virtual vector calling interface
//
hal_if_init();
}
//==========================================================================
// INITIALIZE RT CLOCK
///
/// Timer (TPU channel 5) initialisation.
/// Initializes the timer device to interrupt at the given period.
/// The period is essentially the value used to initialize the timer
/// counter and must be calculated from the timer frequency and the
/// desired interrupt rate.
///
/// \param period The timer device should generate an
/// interrupt every period cycles.
///
/// \note We initialize counter here but we do not enable interrupts.
/// This will be done by kernel later.
/// - NUMERATOR = 1.000.000.000
/// - DENOMINATOR = 100
/// - period = CPU Clock / Prescaler * NUMERATOR / DENOMINATOR / 1.000.000.000
//==========================================================================
void hal_clock_initialize(cyg_uint32 period)
{
cyg_uint8 tmp;
//
// start 16 bit timer module in MSTPCRH register
//
HAL_READ_UINT8(CYGARC_MSTPCRA, tmp);
tmp &= ~CYGARC_MSTPCRA_TPU;
HAL_WRITE_UINT8(CYGARC_MSTPCRA, tmp);
//
// initialize 16 bit timer - first we select timer counter clock and
// counter clearing source TGR
// Clock prescaler is 16 (clock/16) and TCNT is clear at compare match A
//
HAL_WRITE_UINT8(CYGARC_TCR5, CYGARC_TCR_CLR_CMA |
CYGARC_TCR_TPSC_16);
//
// Select output compare register - Designate the TGRA as an output compare
// register by means of TIOR.
//
HAL_WRITE_UINT8(CYGARC_TIOR5, 0x00); // output compare - output disabled
HAL_WRITE_UINT16(CYGARC_TGRA5, period); // set compare match value to period
HAL_WRITE_UINT16(CYGARC_TCNT5, 0x00); // reset up counter
//
// Now start the counter 5 - intterrupts will be enabled from HAL later
//
HAL_WRITE_UINT8(CYGARC_TSTR, CYGARC_TSTR_CST5);
}
//==========================================================================
// READ CLOCK VALUE
///
/// Reads current value of timer counter.
/// Reads the current value of the timer counter and puts the value in
/// the location pointed to by pvalue. The value stored will always be
/// the number of timer cycles since the last interrupt, and hence
/// ranges between zero and the initial period value.
/// If this is a count-down cyclic timer, some arithmetic may be
/// necessary to generate this value.
///
/// \param pvalue Points to place where value should be stored
//==========================================================================
void hal_clock_read(cyg_uint32 *pvalue)
{
cyg_uint16 val;
HAL_READ_UINT16(CYGARC_TCNT5, val);
*pvalue = val;
}
#ifdef CYGPKG_REDBOOT
//==========================================================================
// MEMORY MAP SUPPORT FOR REDBOOT
///
/// Provide information about additional memory segment.
/// We provide information about the internal H8S/2674 ram.
///
/// \param start Start address of memory segment
/// \param end End address of memory segment
/// \param seg Number of segment provided by redboot
///
/// \note The first memory segment 0 is calculated by RedBoot
//==========================================================================
void
cyg_plf_memory_segment(int seg, unsigned char **start, unsigned char **end)
{
cyg_uint32 mem_start;
//
// we have one additional memory segment - the H8S/2638 internal ram
//
if (seg == 1)
{
//
// the internal ram contains VSR table, virtual vector table and
// shadow vector table. these areas are reserved and not available
// so we end at start of CYGHWR_HAL_VSR_TABLE an not at ffc000
//
mem_start = 0xffb000;
*start = (unsigned char *)(mem_start);
*end = (unsigned char *)(CYGHWR_HAL_VSR_TABLE);
}
else
{
diag_printf("** Invalid memory segment #%d - ignored\n", seg);
*start = NO_MEMORY;
*end = NO_MEMORY;
}
}
#endif
//--------------------------------------------------------------------------
// End of plf_misc.c
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -