📄 hal_misc.c
字号:
//==========================================================================
//
// hal_misc.c
//
// HAL 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): nickg
// Contributors: nickg, jlarmour
// Date: 1999-02-18
// Purpose: HAL miscellaneous functions
// Description: This file contains miscellaneous functions provided by the
// HAL.
//
//####DESCRIPTIONEND####
//
//==========================================================================
//==========================================================================
// DOXYGEN FILE HEADER
/// \file hal_misc.c
/// \brief HAL miscellaneous functions
/// \author nickg, jlarmour
/// \date 1999-02-18
///
/// This file contains miscellaneous functions provided by the HAL.
//==========================================================================
//==========================================================================
// INCLUDES
//==========================================================================
#include <pkgconf/hal.h>
#include <cyg/infra/cyg_type.h>
#include <cyg/infra/cyg_trac.h>
#include <cyg/infra/cyg_ass.h>
#include <cyg/infra/diag.h>
#include <cyg/hal/hal_arch.h>
#include <cyg/hal/hal_intr.h>
//--------------------------------------------------------------------------
// This option supports environments where some constructors must be run
// in the context of a thread rather than at simple system startup time.
//
#ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
///
/// Set to 1 when constructors should no longer be invoked.
/// It is up to some other package to deal with the rest of the constructors.
/// In the current version this is only possible with the C library.
///
cyg_bool cyg_hal_stop_constructors;
#endif
//==========================================================================
// CALL CONSTRUCTORS FOR STATIC OBJECTS
///
/// This calls static constructors before program start.
/// This calls the constructors for all static objects before the program
/// starts. eCos relies on these being called in the correct order for
/// it to function correctly. The exact way in which constructors are
/// handled may differ between architectures, although most use a simple
/// table of function pointers between labels __CTOR_LIST__ and
/// __CTOR_END__ which must called in order from the top down.
/// Generally, this function can be copied directly from an existing
/// architecture HAL.
//==========================================================================
void cyg_hal_invoke_constructors(void)
{
typedef void (*pfunc) (void);
extern pfunc _CTOR_LIST__[];
extern pfunc _CTOR_END__[];
#ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
static pfunc *p = &_CTOR_END__[-1];
cyg_hal_stop_constructors = 0;
for (; p >= _CTOR_LIST__; p--) {
(*p) ();
if (cyg_hal_stop_constructors) {
p--;
break;
}
}
#else
pfunc *p;
for (p = &_CTOR_END__[-1]; p >= _CTOR_LIST__; p--)
(*p) ();
#endif
} // cyg_hal_invoke_constructors()
//==========================================================================
// INDEX OF LS BIT IN MASK
///
/// Determine the index of the ls bit of the supplied mask.
/// Because the H8S does not support these by hardware we have to implement
/// the macro HAL_LSBIT_INDEX( index, mask ) as call to this function.
/// This function is copied from h8300 HAL from yshinori sato.
///
/// \param mask Bit mask to be processed
///
/// \return Index of ls bit in mask
//==========================================================================
cyg_uint32 hal_lsbit_index(cyg_uint32 mask)
{
int bit = -1;
if (mask == 0)
return -1;
if ((mask & 0xffff) == 0) {
mask >>= 16;
bit += 16;
}
if ((mask & 0xff) == 0) {
mask >>= 8;
bit += 8;
}
__asm__("1:\n\t"
"adds #1,%0\n\t"
"shlr.b %w2\n\t"
"bcc 1b\n\t"
:"=r"(bit):"0"(bit),"r"(mask));
return bit;
}
//==========================================================================
// INDEX OF LS BIT IN MASK
///
/// Determine the index of the ms bit of the supplied mask.
/// Because the H8S does not support these by hardware we have to implement
/// the macro HAL_MSBIT_INDEX( index, mask ) as call to this function.
/// This function is copied from h8300 HAL from yshinori sato.
///
/// \param mask Bit mask to be processed.
///
/// \return Index of ms bit in supplied mask
//==========================================================================
cyg_uint32 hal_msbit_index(cyg_uint32 mask)
{
unsigned int bit = 8;
if (mask == 0)
return -1;
if ((mask & ~0xffff) != 0)
mask >>= 16;
else
bit += 16;
if ((mask & 0xff00) != 0)
mask >>= 8;
else
bit += 8;
__asm__("1:\n\t"
"dec.b %w0\n\t"
"shll.b %w2\n\t"
"bcc 1b\n\t"
:"=r"(bit):"0"(bit),"r"(mask));
return bit;
}
//==========================================================================
// DEFAULT ARCHITECTURE ISR
///
/// Default architecture interrupt service routine.
/// The real default ISR, hal_default_isr, is in
/// hal/common/.../src/hal_misc.c and calls this architecture ISR.
/// Normally this function should just return
///
/// \param vector Interrupt vector
/// \param data Points to some interrupt data
///
/// \return Zero
//==========================================================================
externC cyg_uint32 hal_arch_default_isr(CYG_ADDRWORD vector, CYG_ADDRWORD data)
{
CYG_FAIL("Spurious interrupt!");
return 0;
}
externC void __handle_exception (void); ///< GDB exception handler
externC HAL_SavedRegisters *_hal_registers; ///< saved machine state for GDB
//==========================================================================
// FIRST LEVEL C EXCEPTION HANDLER
///
/// First level C exception handler.
/// This function is called from the exception VSR. It usually does
/// extra decoding of the exception and invokes any special handlers
/// for things like FPU traps, bus errors or memory exceptions. If there
/// is nothing special to be done for an exception, then it either
/// calls into the GDB stubs, by calling __handle_exception(), or
/// invokes the kernel by calling cyg_hal_deliver_exception()
///
/// \param regs Points to saved machine stack on stack
/// \param vector Exception vector
//==========================================================================
void cyg_hal_exception_handler(HAL_SavedRegisters *regs, CYG_WORD vector)
{
//
// if GDB is included then we let GDB handle the exception
//
#ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
//
// Set the pointer to the registers of the current exception
// context. At entry the GDB stub will expand the
// HAL_SavedRegisters structure into a (bigger) register array.
//
_hal_registers = regs;
__handle_exception();
#elif defined(CYGFUN_HAL_COMMON_KERNEL_SUPPORT) && defined(CYGPKG_HAL_EXCEPTIONS)
//
// We should decode the vector and pass a more appropriate
// value as the second argument. For now we simply pass a
// pointer to the saved registers. We should also divert
// breakpoint and other debug vectors into the debug stubs.
//
cyg_hal_deliver_exception( vector, (CYG_ADDRWORD)regs );
#else
CYG_FAIL("Exception!!!");
#endif
}
//==========================================================================
// IDLE THREAD ACTION
///
/// Idle thread action called from idle thread.
/// This function is called from the idle thread via the
/// HAL_IDLE_THREAD_ACTION() macro, if so defined. While normally this
/// function does nothing, during development this is often a good place
/// to report various important system parameters on LCDs, LED or other
/// displays. This function can also monitor system state and report any
/// anomalies. If the architecture supports a halt instruction then this
/// is a good place to put an inline assembly fragment to execute it.
/// It is also a good place to handle any power saving activity.
///
/// \param loop_count Counter provided by idle thread - counts how
/// often idle thread was executed.
//==========================================================================
externC void hal_idle_thread_action(cyg_uint32 loop_count)
{
}
//==========================================================================
// MANUAL RESET
///
/// Resets board by jumping to manual reset vector.
/// This istruction will bring us to the to the address stored in
/// the exception vector MANUAL RESET of the hardware vector table.
/// This will bring us to _start.
///
/// \note
/// Normally this should be the same for the whole H8S architecture.
/// But you can overwrite it in variant or platform part by defining
/// CYGPKG_HAL_H8S_MRESET_DEFINED
//==========================================================================
#ifndef CYGPKG_HAL_H8S_MRESET_DEFINED
void h8s_reset_manual(void)
{
__asm__ ("jmp @@4\n\t");
}
#endif
//--------------------------------------------------------------------------
// End of hal_misc.c
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -