⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hal_arch.h

📁 实现快速傅立叶变换算法,provides test framwork for FFT testing
💻 H
📖 第 1 页 / 共 2 页
字号:
#ifndef CYGONCE_HAL_ARCH_H
#define CYGONCE_HAL_ARCH_H

//=============================================================================
//
//      hal_arch.h
//
//      Architecture specific abstractions
//
//=============================================================================
//####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
// Copyright (C) 2006 eCosCentric Ltd.
//
// 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.
// -------------------------------------------
//####ECOSGPLCOPYRIGHTEND####
//========================================================================
//#####DESCRIPTIONBEGIN####
//
// Author(s):     Enrico Piria
// Contributors:  Wade Jensen
// Date:          2005-25-06
// Purpose:       
// Description:   Definitions for the ColdFire architecture HAL.
//
//####DESCRIPTIONEND####
//========================================================================

#include <pkgconf/hal.h>
#include <cyg/infra/cyg_type.h>

// Include some variant specific architectural defines
#include <cyg/hal/var_arch.h>

#ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
#include <cyg/hal/coldfire_stub.h>
#endif // CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS

// ----------------------------------------------------------------------------
// Macros to deal with exception stack frame fields

// The ColdFire family of processors has a simplified exception stack
// frame that looks like the following:
//
//          8 +----------------+----------------+
//            |         Program Counter         |
//          4 +----------------+----------------+
//            |Fmt/FS/Vector/FS|      SR        |
//  SP -->  0 +----------------+----------------+
// The stack self-aligns to a 4-byte boundary at an exception, with
// the Fmt/FS/Vector/FS field indicating the size of the adjustment
// (SP += 0,1,2,3 bytes).

// Define the Fmt/FS/Vector/FS word.
// Bits 31-28 are the format word which tells the
// RTI instruction how to align the stack.
#define HAL_CF_EXCEPTION_FORMAT_MSK ((CYG_WORD16)0xF000)
// Bits 25-18 are the vector number of the exception.
#define HAL_CF_EXCEPTION_VECTOR_MSK ((CYG_WORD16)0x03FC)
// Bits 27-26, and 17-16 are the fault status used
// for bus and address errors.
#define HAL_CF_EXCEPTION_FS32_MSK   ((CYG_WORD16)0x0C00)
#define HAL_CF_EXCEPTION_FS10_MSK   ((CYG_WORD16)0x0003)

// Macros to access fields in the format vector word.

#define HAL_CF_EXCEPTION_FORMAT(_fmt_vec_word_)                            \
    ((((CYG_WORD16)(_fmt_vec_word_)) & HAL_CF_EXCEPTION_FORMAT_MSK) >> 12)

#define HAL_CF_EXCEPTION_VECTOR(_fmt_vec_word_)                            \
    ((((CYG_WORD16)(_fmt_vec_word_)) & HAL_CF_EXCEPTION_VECTOR_MSK) >> 2)

#define HAL_CF_EXCEPTION_FS(_fmt_vec_word_)                                \
     (((((CYG_WORD16)(_fmt_vec_word_)) & HAL_CF_EXCEPTION_FS32_MSK) >> 8)  \
     | (((CYG_WORD16)(_fmt_vec_word_)) & HAL_CF_EXCEPTION_FS10_MSK))

// ----------------------------------------------------------------------------
// HAL_SavedRegisters -- Saved by a context switch or by an exception/interrupt

typedef struct
{
    // These are common to all saved states and are in the order
    // stored and loaded by the movem instruction.

    // Data regs D0-D7
    CYG_WORD32 d[8];

    // Address regs A0-A7
    CYG_ADDRESS a[8];

#ifdef CYGHWR_HAL_COLDFIRE_MAC
    // MAC registers
    CYG_WORD32 macc;
    CYG_WORD32 macsr;
    CYG_WORD32 mask;
#endif

    // On exception/interrupt PC, SR and exception are pushed on the
    // stack automatically, so there is no need to allocate the entire
    // structure.
    
    // 16-bit format/vector word
    CYG_WORD16 fmt_vec_word;

    // Status register
    CYG_WORD16 sr;

    // Program counter
    CYG_ADDRESS pc;

} __attribute__ ((aligned, packed)) HAL_SavedRegisters;

#ifndef HAL_THREAD_SWITCH_CONTEXT

// ***************************************************************************
// HAL_THREAD_SWITCH_CONTEXT
// 
// This macro saves the state of the currently running thread and writes
// its stack pointer to *(_fspptr_).
// It then switches to the thread context that *(_tspptr_) points to.
// 
// INPUT:
//  _fspptr_: A pointer to the location to save the current thread's stack
//      pointer to.
// 
//   _tspptr_: A pointer to the location containing the stack pointer of
//      the thread context to switch to.
// 
// OUTPUT:
//   *(_fspptr_): Contains the stack pointer of the previous thread's context.
// 
// ***************************************************************************

externC void hal_thread_switch_context( CYG_ADDRESS to, CYG_ADDRESS from );
externC void hal_thread_load_context( CYG_ADDRESS to )
    CYGBLD_ATTRIB_NORET;

#define HAL_THREAD_SWITCH_CONTEXT(_fspptr_,_tspptr_)                    \
        hal_thread_switch_context((CYG_ADDRESS)_tspptr_,(CYG_ADDRESS)_fspptr_);
#endif // HAL_THREAD_SWITCH_CONTEXT

#ifndef HAL_THREAD_LOAD_CONTEXT

// ***************************************************************************
// hal_thread_load_context
// 
// This routine loads the thread context that *(_tspptr_) points to.
// This routine does not return.
// 
// INPUT:
//   _tspptr_: A pointer to  the location containing  the stack pointer  of
//      the thread context to switch to.
// 
// ***************************************************************************

#define HAL_THREAD_LOAD_CONTEXT(_tspptr_)                               \
        hal_thread_load_context( (CYG_ADDRESS)_tspptr_ );
#endif // HAL_THREAD_LOAD_CONTEXT


#ifndef HAL_THREAD_INIT_CONTEXT

// ***************************************************************************
// HAL_THREAD_INIT_CONTEXT -- Context Initialization
// 
// Initialize the context of a thread.
// 
// INPUT:
//   _sparg_: The name of the variable containing the current sp. This
//      will be written with the new sp.
// 
//   _thread_: The thread object address, passed as argument to entry
//      point.
// 
//   _entry_: The thread's entry point address.
// 
//   _id_: A bit pattern used in initializing registers, for debugging.
// 
// OUTPUT:
//   _sparg_: Updated with the value of the new sp.
// 
// ***************************************************************************

#define HAL_THREAD_INIT_CONTEXT(_sparg_, _thread_, _entry_, _id_)           \
    CYG_MACRO_START                                                         \
    CYG_WORD32 * _sp_ = ((CYG_WORD32*)((CYG_WORD32)(_sparg_) & ~15));       \
    HAL_SavedRegisters * _regs_;                                            \
    int _i_;                                                                \
                                                                            \
    /* Thread's parameter. */                                               \
    *(--_sp_) = (CYG_WORD32)(_thread_);                                     \
    /* Fake thread's return addr. Needed because thread is a function */    \
    /* and parameters to functions are always follwed by the return   */    \
    /* address on the stack.                                          */    \
    *(--_sp_) = (CYG_WORD32)(0xDEADC0DE);                                   \
     /* Thread's return addr. (used by hal_thread_load_context) */          \
    *(--_sp_) = (CYG_WORD32)(_entry_);                                      \
                                                                            \
    _regs_ = (HAL_SavedRegisters *)                                         \
              ((CYG_WORD32)_sp_ - sizeof(HAL_SavedRegisters));              \
                                                                            \
    for (_i_=0; _i_ < 8; _i_++)                                             \
        _regs_->a[_i_] = _regs_->d[_i_] = (_id_);                           \
    /* A6, initial frame pointer should be null */                          \
    _regs_->a[6] = (CYG_ADDRESS)0;                                          \
                                                                            \
    /* Thread's starting SR. All interrupts enabled. */                     \
    _regs_->sr = 0x3000;                                                    \
                                                                            \
    /* Thread's starting PC */                                              \
    _regs_->pc = (CYG_ADDRESS)(_entry_);                                    \
                                                                            \
    (_sparg_) = (CYG_ADDRESS)_regs_;                                        \

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -