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

📄 hal_io.h

📁 开放源码实时操作系统源码.
💻 H
📖 第 1 页 / 共 2 页
字号:
#ifndef CYGONCE_HAL_HAL_IO_H
#define CYGONCE_HAL_HAL_IO_H

//=============================================================================
//
//      hal_io.h
//
//      HAL device IO register support.
//
//=============================================================================
//####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
// Copyright (C) 2002 Bart Veer
// 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, bartv, alunn, jlarmour
// Date:        1998-02-17
// Purpose:     Define IO register support
// Description: The macros defined here provide the HAL APIs for handling
//              device IO control registers.
//
//              For the synthetic target these macros should never
//              actually be used since the application will run as an
//              ordinary user application and should not have
//              permission to access any real hardware. Instead
//              hardware access should go via the auxiliary. Possibly
//              the macros should be #pragma poison'd, but some people
//              may want to run the synthetic target in a way that
//              does involve accessing real hardware.
//              
//              The synthetic target provides some additional I/O
//              facilities in the form of Linux system calls. A useful
//              subset of these are prototyped here, together with
//              associated constants. There are also I/O operations to
//              interact with the auxiliary.
//
// Usage:
//              #include <cyg/hal/hal_io.h>
//              ...
//
//####DESCRIPTIONEND####
//
//=============================================================================

#include <cyg/infra/cyg_type.h>

#include <cyg/hal/var_io.h>     // Variant-specific definitions

//-----------------------------------------------------------------------------
// IO Register address.
// This type is for recording the address of an IO register.

typedef volatile CYG_ADDRWORD HAL_IO_REGISTER;

//-----------------------------------------------------------------------------
// BYTE Register access.
// Individual and vectorized access to 8 bit registers.

#define HAL_READ_UINT8( _register_, _value_ )           \
    CYG_MACRO_START                                     \
    ((_value_) = *((volatile CYG_BYTE *)(_register_))); \
    CYG_MACRO_END

#define HAL_WRITE_UINT8( _register_, _value_ )          \
    CYG_MACRO_START                                     \
    (*((volatile CYG_BYTE *)(_register_)) = (_value_)); \
    CYG_MACRO_END

#define HAL_READ_UINT8_VECTOR( _register_, _buf_, _count_, _step_ )     \
    CYG_MACRO_START                                                     \
    cyg_count32 _i_,_j_;                                                \
    for( _i_ = 0, _j_ = 0; _i_ < (_count_); _i_++, _j_ += (_step_)) {   \
        (_buf_)[_i_] = ((volatile CYG_BYTE *)(_register_))[_j_];        \
    }                                                                   \
    CYG_MACRO_END

#define HAL_WRITE_UINT8_VECTOR( _register_, _buf_, _count_, _step_ )    \
    CYG_MACRO_START                                                     \
    cyg_count32 _i_,_j_;                                                \
    for( _i_ = 0, _j_ = 0; _i_ < (_count_); _i_++, _j_ += (_step_)) {   \
        ((volatile CYG_BYTE *)(_register_))[_j_] = (_buf_)[_i_];        \
    }                                                                   \
    CYG_MACRO_END


//-----------------------------------------------------------------------------
// 16 bit access.
// Individual and vectorized access to 16 bit registers.
    
#define HAL_READ_UINT16( _register_, _value_ )                  \
    CYG_MACRO_START                                             \
    ((_value_) = *((volatile CYG_WORD16 *)(_register_)));       \
    CYG_MACRO_END

#define HAL_WRITE_UINT16( _register_, _value_ )                 \
    CYG_MACRO_START                                             \
    (*((volatile CYG_WORD16 *)(_register_)) = (_value_));       \
    CYG_MACRO_END

#define HAL_READ_UINT16_VECTOR( _register_, _buf_, _count_, _step_ )    \
    CYG_MACRO_START                                                     \
    cyg_count32 _i_,_j_;                                                \
    for( _i_ = 0, _j_ = 0; _i_ < (_count_); _i_++, _j_ += (_step_)) {   \
        (_buf_)[_i_] = ((volatile CYG_WORD16 *)(_register_))[_j_];      \
    }                                                                   \
    CYG_MACRO_END

#define HAL_WRITE_UINT16_VECTOR( _register_, _buf_, _count_, _step_ )   \
    CYG_MACRO_START                                                     \
    cyg_count32 _i_,_j_;                                                \
    for( _i_ = 0, _j_ = 0; _i_ < (_count_); _i_++, _j_ += (_step_)) {   \
        ((volatile CYG_WORD16 *)(_register_))[_j_] = (_buf_)[_i_];      \
    }                                                                   \
    CYG_MACRO_END

//-----------------------------------------------------------------------------
// 32 bit access.
// Individual and vectorized access to 32 bit registers.
    
#define HAL_READ_UINT32( _register_, _value_ )                  \
    CYG_MACRO_START                                             \
    ((_value_) = *((volatile CYG_WORD32 *)(_register_)));       \
    CYG_MACRO_END

#define HAL_WRITE_UINT32( _register_, _value_ )                 \
    CYG_MACRO_START                                             \
    (*((volatile CYG_WORD32 *)(_register_)) = (_value_));       \
    CYG_MACRO_END

#define HAL_READ_UINT32_VECTOR( _register_, _buf_, _count_, _step_ )    \
    CYG_MACRO_START                                                     \
    cyg_count32 _i_,_j_;                                                \
    for( _i_ = 0, _j_ = 0; _i_ < (_count_); _i_++, _j_ += (_step_)) {   \
        (_buf_)[_i_] = ((volatile CYG_WORD32 *)(_register_))[_j_];      \
    }                                                                   \
    CYG_MACRO_END

#define HAL_WRITE_UINT32_VECTOR( _register_, _buf_, _count_, _step_ )   \
    CYG_MACRO_START                                                     \
    cyg_count32 _i_,_j_;                                                \
    for( _i_ = 0, _j_ = 0; _i_ < (_count_); _i_++, _j_ += (_step_)) {   \
        ((volatile CYG_WORD32 *)(_register_))[_j_] = (_buf_)[_i_];      \
    }                                                                   \
    CYG_MACRO_END

// ----------------------------------------------------------------------------
// Linux system calls and associated structures and constants. This is
// by no means a complete list, but there is enough information for
// the needs of the relevant HAL packages. The information needs to be
// kept in synch with the Linux header files, but in practice
// divergence will be rare because that would imply incompatible
// changes in the Linux kernel API.
//
// It may seem tempting to import the Linux header files directly, but
// that would prevent cross-compilation and introduce all kinds of
// namespace pollution.
//
// The actual implementation lives in variant HAL packages since
// typically they involve direct system calls via bits of assembler.
// Note that only a subset of system calls are actually implemented,
// so the variant HALs may need to be updated if this list needs to
// be extended.

// Error codes.
#define CYG_HAL_SYS_EINTR                4
#define CYG_HAL_SYS_EAGAIN              11

// Signal-related information
#define CYG_HAL_SYS_SIGHUP               1
#define CYG_HAL_SYS_SIGINT               2
#define CYG_HAL_SYS_SIGQUIT              3
#define CYG_HAL_SYS_SIGILL               4
#define CYG_HAL_SYS_SIGTRAP              5
#define CYG_HAL_SYS_SIGABRT              6
#define CYG_HAL_SYS_SIGBUS               7
#define CYG_HAL_SYS_SIGFPE               8
#define CYG_HAL_SYS_SIGKILL              9
#define CYG_HAL_SYS_SIGUSR1             10
#define CYG_HAL_SYS_SIGSEGV             11
#define CYG_HAL_SYS_SIGUSR2             12
#define CYG_HAL_SYS_SIGPIPE             13
#define CYG_HAL_SYS_SIGALRM             14
#define CYG_HAL_SYS_SIGTERM             15
#define CYG_HAL_SYS_SIGSTKFLT           16
#define CYG_HAL_SYS_SIGCHLD             17
#define CYG_HAL_SYS_SIGCONT             18
#define CYG_HAL_SYS_SIGSTOP             19
#define CYG_HAL_SYS_SIGTSTP             20
#define CYG_HAL_SYS_SIGTTIN             21
#define CYG_HAL_SYS_SIGTTOU             22
#define CYG_HAL_SYS_SIGURG              23
#define CYG_HAL_SYS_SIGXCPU             24
#define CYG_HAL_SYS_SIGXFSZ             25
#define CYG_HAL_SYS_SIGVTALRM           26
#define CYG_HAL_SYS_SIGPROF             27
#define CYG_HAL_SYS_SIGWINCH            28
#define CYG_HAL_SYS_SIGIO               29
#define CYG_HAL_SYS_SIGPWR              30
#define CYG_HAL_SYS_SIGSYS              31

#define CYG_HAL_SYS_SA_NOCLDSTOP        0x00000001
#define CYG_HAL_SYS_SA_NOCLDWAIT        0x00000002
#define CYG_HAL_SYS_SA_SIGINFO          0x00000004
#define CYG_HAL_SYS_SA_RESTORER         0x04000000
#define CYG_HAL_SYS_SA_RESTART          0x10000000
#define CYG_HAL_SYS_SA_NODEFER          0x40000000

#define CYG_HAL_SYS_SIG_BLOCK           0
#define CYG_HAL_SYS_SIG_UNBLOCK         1
#define CYG_HAL_SYS_SIG_SETMASK         2

#define CYG_HAL_SYS__NSIG               64
#define CYG_HAL_SYS__SIGBITS            (8 * sizeof(unsigned long))
#define CYG_HAL_SYS__SIGELT(_d_)        ((_d_) / CYG_HAL_SYS__SIGBITS)
#define CYG_HAL_SYS__SIGMASK(_d_)       ((unsigned long)1 << ((_d_) % CYG_HAL_SYS__SIGBITS))

typedef struct cyg_hal_sys_sigset_t {
    unsigned long hal_sig_bits[CYG_HAL_SYS__NSIG / CYG_HAL_SYS__SIGBITS];
} cyg_hal_sys_sigset_t;

#define CYG_HAL_SYS_SIGFILLSET(_set_)                                                   \
    CYG_MACRO_START                                                                     \
        unsigned int __i;                                                               \
        for (__i = 0; __i < (CYG_HAL_SYS__NSIG / CYG_HAL_SYS__SIGBITS); __i++) {        \
            (_set_)->hal_sig_bits[__i] = ~0;                                            \
        }                                                                               \
    CYG_MACRO_END

#define CYG_HAL_SYS_SIGEMPTYSET(_set_)                                                  \
    CYG_MACRO_START                                                                     \
        unsigned int __i;                                                               \
        for (__i = 0; __i < (CYG_HAL_SYS__NSIG / CYG_HAL_SYS__SIGBITS); __i++) {        \
            (_set_)->hal_sig_bits[__i] = 0;                                             \
        }                                                                               \
    CYG_MACRO_END

#define CYG_HAL_SYS_SIGADDSET(_set_, _bit_)                                                     \
    CYG_MACRO_START                                                                             \
    (_set_)->hal_sig_bits[CYG_HAL_SYS__SIGELT(_bit_ - 1)] |= CYG_HAL_SYS__SIGMASK(_bit_ - 1);   \
    CYG_MACRO_END

#define CYG_HAL_SYS_SIGDELSET(_set_, _bit_)                                                     \
    CYG_MACRO_START                                                                             \
    (_set_)->hal_sig_bits[CYG_HAL_SYS__SIGELT(_bit_ - 1)] &= ~CYG_HAL_SYS__SIGMASK(_bit_ - 1);  \
    CYG_MACRO_END
               
#define CYG_HAL_SYS_SIGISMEMBER(_set_, _bit_)                                                   \
    (0 != ((_set_)->hal_sig_bits[CYG_HAL_SYS__SIGELT(_bit_ - 1)] & CYG_HAL_SYS__SIGMASK(_bit_ - 1)))

// The kernel sigaction structure has changed, to allow for >32
// signals. This is the old version, i.e. a struct old_sigaction, for
// use with the sigaction() system call rather than rt_sigaction(). It
// is preferred to the more modern version because gdb knows about
// rt_sigaction() and will start intercepting signals, but it seems to
// ignore sigaction().
struct cyg_hal_sys_sigaction {
    void        (*hal_handler)(int);
    long        hal_mask;
    int         hal_flags;
    void        (*hal_restorer)(void);
};

// Time support.
struct cyg_hal_sys_timeval {
    long        hal_tv_sec;
    long        hal_tv_usec;
};

struct cyg_hal_sys_timezone {
    int         hal_tz_minuteswest;
    int         hal_tz_dsttime;
};

// Select support. Initially this is used only by the idle handler.
#define CYG_HAL_SYS_FD_SETSIZE          1024
#define CYG_HAL_SYS__NFDBITS            (8 * sizeof(unsigned long))
#define CYG_HAL_SYS__FDELT(_d_)         ((_d_) / CYG_HAL_SYS__NFDBITS)
#define CYG_HAL_SYS__FDMASK(_d_)        ((unsigned long)1 << ((_d_) % CYG_HAL_SYS__NFDBITS))

⌨️ 快捷键说明

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