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

📄 ds1672.cxx

📁 ecos移植到R8H系列的源码。源码包来自http://www.cetoni.de/develop/develop_ecosh8s_en.html
💻 CXX
字号:
//==========================================================================////      devs/wallclock/ds1672.inl////      Wallclock implementation for Dallas 1672////==========================================================================//####ECOSGPLCOPYRIGHTBEGIN####// -------------------------------------------// This file is part of eCos, the Embedded Configurable Operating System.// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.// Copyright (C) 2003 Gary Thomas//// 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):     gthomas// Contributors:  uwe kindler// Date:          2003-11-26// Purpose:       Wallclock driver for Dallas 1672////####DESCRIPTIONEND####////==========================================================================//==========================================================================//                               INCLUDES//==========================================================================#include <pkgconf/hal.h>                  // Platform specific configury#include <pkgconf/wallclock.h>            // Wallclock device config#include <cyg/hal/hal_io.h>               // IO macros#include <cyg/hal/hal_intr.h>             // interrupt enable/disable#include <cyg/infra/cyg_type.h>           // Common type definitions and support#include <cyg/io/wallclock.hxx>           // The WallClock API#include <cyg/io/ds1672.h>                // our header file#include <cyg/infra/diag.h>//// This particular chip is always accessed via I2C (2-wire protocol)// The platform needs to provide simple I2C access functions//// void DS_GET(cyg_uint8 *regs)//    Reads the entire set of registers (8 bytes) into *regs// void DS_PUT(cyg_uint8 *regs)//    Updated the entire set of registers (8 bytes) from *regs//// Using this method, the data in the registers is guaranteed to be// stable (if the access function manipulates the registers in an// single operation)//// // Platform details//#include CYGDAT_DEVS_WALLCLOCK_DALLAS_1672_INL//-----------------------------------------------------------------------------// Accessor functions////===========================================================================//                      INITIALIZE DS1672 HARDWARE// DESCRIPTTION://     Initialize the DS1672 hardware//===========================================================================static inline void init_ds_hwclock(void){    cyg_uint8 regs[DS_REGS_SIZE];            //    // fetch the current state    //    DS_GET(regs);    //    // if oscillator is disabled in backup mode then enable osc    //    if (regs[DS_REG_CTRL] & DS_REG_CTRL_OSC_DIS)    {        regs[DS_REG_CTRL] = DS_REG_CTRL_OSC_EN;    }    //    // update the current state    //    DS_PUT(regs);}//===========================================================================//                        STORE TIME INTO DS1672  // DESCRIPTION://     Set new time value//// ARGUMENTS://     'secs'   New seconds value to be set//===========================================================================static inline void set_ds_hwclock(cyg_uint32 secs){    cyg_uint8  regs[DS_REGS_SIZE];            //    // fetch the current state    //    DS_GET(regs);    regs[DS_REG_CNT_BYTE_1] = (cyg_uint8)(secs & 0xff);    secs >>= 8;    regs[DS_REG_CNT_BYTE_2] = (cyg_uint8)(secs & 0xff);    secs >>= 8;    regs[DS_REG_CNT_BYTE_3] = (cyg_uint8)(secs & 0xff);    secs >>= 8;    regs[DS_REG_CNT_BYTE_4] = (cyg_uint8)(secs & 0xff);    //    // update current state    //    DS_PUT(regs);}//===========================================================================//                        GET TIMESTAMP FROM DS1672  // DESCRIPTTION://     Returns the counted seconds//// RETURNS://     Number of counted seconds//===========================================================================static inline cyg_uint32 get_ds_hwclock(void){    cyg_uint32 secs;    cyg_uint8  regs[DS_REGS_SIZE];            //    // fetch the current state - reads lsb first    //    DS_GET(regs);    secs =   regs[DS_REG_CNT_BYTE_4];    secs <<= 8;    secs +=  regs[DS_REG_CNT_BYTE_3];    secs <<= 8;    secs +=  regs[DS_REG_CNT_BYTE_2];    secs <<= 8;    secs +=  regs[DS_REG_CNT_BYTE_1];        return secs;    }//===========================================================================//                             GET SECONDS FROM HW// DESCRIPTTION://     Returns the number of seconds elapsed since 1970-01-01 00:00:00.//// RETURNS://     Number of counted seconds//===========================================================================cyg_uint32 Cyg_WallClock::get_hw_seconds(void){    return get_ds_hwclock();}#ifdef CYGSEM_WALLCLOCK_SET_GET_MODE//===========================================================================//                            STORE SECONDS INTO HW// DESCRIPTTION://     Sets the clock.//// ARGUMENT://     'secs'   Seconds elapsed since 1970-01-01 00:00:00.//===========================================================================void Cyg_WallClock::set_hw_seconds(cyg_uint32 secs){    set_ds_hwclock(secs);}#endif // CYGSEM_WALLCLOCK_SET_GET_MODE//===========================================================================//                            STORE SECONDS INTO HW// DESCRIPTTION://     Sets the clock.//// ARGUMENT://     'secs'   Seconds elapsed since 1970-01-01 00:00:00.//===========================================================================void Cyg_WallClock::init_hw_seconds(void){#ifdef CYGSEM_WALLCLOCK_SET_GET_MODE    init_ds_hwclock();#else    // This is our base: 1970-01-01 00:00:00    // Set the HW clock - if for nothing else, just to be sure it's in a    // legal range. Any arbitrary base could be used.    // After this the hardware clock is only read.    set_ds_hwclock(0);#endif}//-----------------------------------------------------------------------------// End of devs/wallclock/ds1672.inl

⌨️ 快捷键说明

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