亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? ds1307.cxx

?? 開放源碼實(shí)時(shí)操作系統(tǒng)源碼.
?? CXX
字號(hào):
//==========================================================================
//
//      devs/wallclock/ds1307.inl
//
//      Wallclock implementation for Dallas 1307
//
//==========================================================================
//####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
// Copyright (C) 2004 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.
//
// 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:  
// Date:          2003-09-19
// Purpose:       Wallclock driver for Dallas 1307
//
//####DESCRIPTIONEND####
//
//==========================================================================

#include <pkgconf/hal.h>                // Platform specific configury
#include <pkgconf/wallclock.h>          // Wallclock device config
#include <pkgconf/devices_wallclock_dallas_ds1307.h>

#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 <string.h>                     // memcpy()

#include <cyg/io/wallclock.hxx>         // The WallClock API
#include <cyg/io/wallclock/wallclock.inl> // Helpers

#include <cyg/infra/diag.h>

#if 1
# define DEBUG(_format_, ...)
#else
# define DEBUG(_format_, ...) diag_printf(_format_, ## __VA_ARGS__)
#endif

// Registers.
// FIXME: there is no need to include the control register here, it
// controls a square wave output which is independent from the wallclock.
// However fixing it would require changing any platforms that use the
// old DS_GET()/DS_PUT() functionality.
#define DS_SECONDS         0x00
#define DS_MINUTES         0x01
#define DS_HOURS           0x02
#define DS_DOW             0x03
#define DS_DOM             0x04
#define DS_MONTH           0x05
#define DS_YEAR            0x06
#define DS_CONTROL         0x07
#define DS_REGS_SIZE       0x08   // Size of register space

#define DS_SECONDS_CH      0x80   // Clock Halt
#define DS_HOURS_24        0x40   // 24 hour clock mode

// The DS1307 chip is accessed via I2C (2-wire protocol). This can be
// implemented in one of two ways. If the platform supports the generic
// I2C API then it should also export a cyg_i2c_device structure
// cyg_i2c_wallclock_ds1307, and this can be manipulated via the
// usual cyg_i2c_tx() and cyg_i2c_rx() functions. Alternatively (and
// primarily for older ports predating the generic I2C package)
// the platform HAL can provide the following two macros/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)
//
// If the platform HAL implements the CDL interface
// CYGINT_DEVICES_WALLCLOCK_DALLAS_DS1307_I2C then the I2C API will be used.

#ifdef CYGINT_DEVICES_WALLCLOCK_DALLAS_DS1307_I2C
# if defined(DS_GET) || defined(DS_PUT)
#  error The macros DS_GET and DS_PUT should not be defined if the generic I2C API is used
# endif

#include <cyg/io/i2c.h>

static void
DS_GET(cyg_uint8* regs)
{
    cyg_uint8   tx_data[1];
    cyg_bool    ok = true;

    tx_data[0]  = 0x00; // Initial register to read
    cyg_i2c_transaction_begin(&cyg_i2c_wallclock_ds1307);
    if (1 != cyg_i2c_transaction_tx(&cyg_i2c_wallclock_ds1307, true, tx_data, 1, false)) {
        // The device has not responded to the address byte.
        ok = false;
    } else {
        // Now fetch the data
        cyg_i2c_transaction_rx(&cyg_i2c_wallclock_ds1307, true, regs, 8, true, true);

        // Verify that there are reasonable default settings. The
        // register values can be used as array indices so bogus
        // values can lead to bus errors or similar problems.
        
        // Years: 00 - 99, with 70-99 interpreted as 1970 onwards.
        if ((regs[DS_YEAR] & 0x0F) > 0x09) {
            ok = false;
        }
        // Month: 1 - 12
        if ((regs[DS_MONTH] == 0x00) ||
            ((regs[DS_MONTH] > 0x09) && (regs[DS_MONTH] < 0x10)) ||
            (regs[DS_MONTH] > 0x12)) {
            ok = false;
        }
        // Day: 1 - 31. This check does not allow for 28-30 day months.
        if ((regs[DS_DOM] == 0x00) ||
            ((regs[DS_DOM] & 0x0F) > 0x09) ||
            (regs[DS_DOM] > 0x31)) {
            ok = false;
        }
        // Hours: 0 - 23. Always run in 24-hour mode
        if ((0 != (regs[DS_HOURS] & DS_HOURS_24)) ||
            ((regs[DS_HOURS] & 0x0F) > 0x09) ||
            ((regs[DS_HOURS] & 0x3F) > 0x023)) {
            ok = false;
        }
        // Ignore the DOW field. The wallclock code does not need it, and
        // it is hard to calculate.
        // Minutes: 0 - 59
        if (((regs[DS_MINUTES] & 0x0F) > 0x09) ||
            (regs[DS_MINUTES] > 0x59)) {
            ok = false;
        }
        // Seconds: 0 - 59
        if (((regs[DS_SECONDS] & 0x0F) > 0x09) ||
            (regs[DS_SECONDS] > 0x59)) {
            ok = false;
        }
    }
    cyg_i2c_transaction_end(&cyg_i2c_wallclock_ds1307);
    if (! ok) {
        // Any problems, return Jan 1 1970 but do not update the hardware.
        // Leave it to the user or other code to set the clock to a sensible
        // value.
        regs[DS_SECONDS]  = 0x00;
        regs[DS_MINUTES]  = 0x00;
        regs[DS_HOURS]    = 0x00;
        regs[DS_DOW]      = 0x00;
        regs[DS_DOM]      = 0x01;                                                         
        regs[DS_MONTH]    = 0x01;                                                        
        regs[DS_YEAR]     = 0x70;
        regs[DS_CONTROL]  = 0x00;
    }
}

static void
DS_PUT(cyg_uint8* regs)
{
    cyg_uint8 tx_data[9];
    tx_data[0] = 0;
    memcpy(&(tx_data[1]), regs, 8);
    cyg_i2c_tx(&cyg_i2c_wallclock_ds1307, tx_data, 9);
}

#else
// Platform details. The platform HAL or some other package should
// provide this header, containing the required macros
# include CYGDAT_DEVS_WALLCLOCK_DALLAS_1307_INL
#endif

//----------------------------------------------------------------------------
// Accessor functions

static inline void
init_ds_hwclock(void)
{
    cyg_uint8 regs[DS_REGS_SIZE];

    // Fetch the current state
    DS_GET(regs);
    
    // If the clock is not currently running or is not in 24-hours mode,
    // update it. Otherwise skip the update because the clock may have
    // ticked between DS_GET() and DS_PUT() and we could be losing the
    // occasional second.
    if ((0 != (regs[DS_HOURS] & DS_HOURS_24)) ||
        (0 != (regs[DS_SECONDS] & DS_SECONDS_CH))) {
        regs[DS_SECONDS] &= ~DS_SECONDS_CH;
        regs[DS_HOURS]   &= ~DS_HOURS_24;
        DS_PUT(regs);
    }
}

static inline void
set_ds_hwclock(cyg_uint32 year, cyg_uint32 month, cyg_uint32 mday,
               cyg_uint32 hour, cyg_uint32 minute, cyg_uint32 second)
{
    cyg_uint8 regs[DS_REGS_SIZE];

    // Set up the registers
    regs[DS_CONTROL]    = 0x00;
    regs[DS_YEAR]       = TO_BCD((cyg_uint8)(year % 100));
    regs[DS_MONTH]      = TO_BCD((cyg_uint8)month);
    regs[DS_DOM]        = TO_BCD((cyg_uint8)mday);
    regs[DS_DOW]        = TO_BCD(0x01);     // Not accurate, but not used by this driver either
    regs[DS_HOURS]      = TO_BCD((cyg_uint8)hour);
    regs[DS_MINUTES]    = TO_BCD((cyg_uint8)minute);
    // This also starts the clock
    regs[DS_SECONDS]    = TO_BCD((cyg_uint8)second);

    // Send the register set to the hardware
    DS_PUT(regs);

    // These debugs will cause the test to eventually fail due to
    // the printouts causing timer interrupts to be lost...
    DEBUG("DS1307 set -------------\n");
    DEBUG("regs %02x %02x %02x %02x %02x %02x %02x %02x\n",
          regs[0], regs[1], regs[2], regs[3], regs[4], regs[5], regs[6], regs[7]);
    DEBUG("year %02d\n", year);
    DEBUG("month %02d\n", month);
    DEBUG("mday %02d\n", mday);
    DEBUG("hour %02d\n", hour);
    DEBUG("minute %02d\n", minute);
    DEBUG("second %02d\n", second);
}

static inline void
get_ds_hwclock(cyg_uint32* year, cyg_uint32* month, cyg_uint32* mday,
               cyg_uint32* hour, cyg_uint32* minute, cyg_uint32* second)
{
    cyg_uint8 regs[DS_REGS_SIZE];

    // Fetch the current state
    DS_GET(regs);

    *year = (cyg_uint32)TO_DEC(regs[DS_YEAR]);
    // The year field only has the 2 least significant digits :-(
    if (*year >= 70) {
        *year += 1900;
    } else {
        *year += 2000;
    }
    *month = (cyg_uint32)TO_DEC(regs[DS_MONTH]);
    *mday = (cyg_uint32)TO_DEC(regs[DS_DOM]);
    *hour = (cyg_uint32)TO_DEC(regs[DS_HOURS] & 0x3F);
    *minute = (cyg_uint32)TO_DEC(regs[DS_MINUTES]);
    *second = (cyg_uint32)TO_DEC(regs[DS_SECONDS] & 0x7F);

    // These debugs will cause the test to eventually fail due to
    // the printouts causing timer interrupts to be lost...
    DEBUG("DS1307 get -------------\n");
    DEBUG("regs %02x %02x %02x %02x %02x %02x %02x %02x\n",
          regs[0], regs[1], regs[2], regs[3], regs[4], regs[5], regs[6], regs[7]);
    DEBUG("year %02d\n", *year);
    DEBUG("month %02d\n", *month);
    DEBUG("mday %02d\n", *mday);
    DEBUG("hour %02d\n", *hour);
    DEBUG("minute %02d\n", *minute);
    DEBUG("second %02d\n", *second);
}

//-----------------------------------------------------------------------------
// Functions required for the hardware-driver API.

// Returns the number of seconds elapsed since 1970-01-01 00:00:00.
cyg_uint32 
Cyg_WallClock::get_hw_seconds(void)
{
    cyg_uint32 year, month, mday, hour, minute, second;

    get_ds_hwclock(&year, &month, &mday, &hour, &minute, &second);
    cyg_uint32 now = _simple_mktime(year, month, mday, hour, minute, second);
    return now;
}

#ifdef CYGSEM_WALLCLOCK_SET_GET_MODE

// Sets the clock. Argument is seconds elapsed since 1970-01-01 00:00:00.
void
Cyg_WallClock::set_hw_seconds( cyg_uint32 secs )
{
    cyg_uint32 year, month, mday, hour, minute, second;

    _simple_mkdate(secs, &year, &month, &mday, &hour, &minute, &second);
    set_ds_hwclock(year, month, mday, hour, minute, second);
}

#endif

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(1970,1,1,0,0,0);
#endif
}

//-----------------------------------------------------------------------------
// End of devs/wallclock/ds1307.inl

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
www.色精品| 国产精品久久久久国产精品日日 | 国产成人日日夜夜| 91福利在线播放| 26uuu成人网一区二区三区| 亚洲同性gay激情无套| 久久er精品视频| 欧美午夜视频网站| 国产精品不卡一区二区三区| 青椒成人免费视频| 日本久久精品电影| 国产精品美女久久久久久久久久久| 热久久国产精品| 欧美日韩精品欧美日韩精品| 国产精品久久久久久亚洲毛片| 免费不卡在线视频| 69堂成人精品免费视频| 亚洲女与黑人做爰| 成人99免费视频| 亚洲精品乱码久久久久| 国产精品影视在线观看| 日韩久久精品一区| 老司机午夜精品| 337p亚洲精品色噜噜| 亚洲成人动漫一区| 欧美影视一区二区三区| 一区二区三区在线不卡| 日本电影亚洲天堂一区| 亚洲激情成人在线| 91福利小视频| 亚洲国产毛片aaaaa无费看| 色老头久久综合| 亚洲一区二区三区爽爽爽爽爽| 91麻豆精东视频| 亚洲国产中文字幕| 欧美人妇做爰xxxⅹ性高电影| 亚洲电影一区二区| 制服丝袜国产精品| 韩国欧美一区二区| 国产亚洲成aⅴ人片在线观看 | 欧美精品在线一区二区三区| 亚洲一区二区偷拍精品| 欧美日韩精品欧美日韩精品| 首页国产欧美久久| 精品入口麻豆88视频| 国产精品18久久久久久久久 | 国产一区二区福利| 国产日韩欧美综合一区| 成人午夜电影网站| 极品少妇xxxx精品少妇| 精品三级av在线| 懂色av一区二区三区免费观看| 国产精品色哟哟网站| 91成人在线观看喷潮| 日韩不卡一区二区三区| 久久精品视频免费| 91国偷自产一区二区开放时间| 天天亚洲美女在线视频| 久久免费电影网| 色噜噜狠狠一区二区三区果冻| 午夜久久久久久久久| 久久嫩草精品久久久精品| 91麻豆高清视频| 日本成人在线电影网| 国产人妖乱国产精品人妖| 色婷婷av久久久久久久| 久久精工是国产品牌吗| 中文字幕在线不卡国产视频| 欧美日韩1区2区| 国产91综合网| 水野朝阳av一区二区三区| 国产婷婷色一区二区三区在线| 日本精品一级二级| 狠狠久久亚洲欧美| 一区二区三区精品| 国产人久久人人人人爽| 欧美妇女性影城| 91视视频在线观看入口直接观看www | 综合久久久久久| 日韩亚洲欧美一区二区三区| 99re这里都是精品| 久久国产综合精品| 一区二区三区成人| 日本一区二区成人| 精品蜜桃在线看| 欧美日韩成人一区二区| 91在线观看免费视频| 国产一区二区三区四区五区美女| 亚洲黄色av一区| 国产精品久久久一区麻豆最新章节| 欧美精品色综合| 色综合天天做天天爱| 国产精品伊人色| 久久99久久99精品免视看婷婷 | 在线观看成人免费视频| 国产91在线观看丝袜| 精品一区二区三区日韩| 同产精品九九九| 亚洲一区日韩精品中文字幕| 中文字幕一区二| 欧美极品美女视频| 久久久久99精品国产片| 久久婷婷久久一区二区三区| 日韩一级完整毛片| 欧美一区二区福利在线| 欧美日本精品一区二区三区| 91丨九色丨蝌蚪富婆spa| 国产**成人网毛片九色| 国产高清成人在线| 国产一区二区成人久久免费影院| 麻豆freexxxx性91精品| 久久99精品久久久久久| 日韩av中文在线观看| 免费观看成人鲁鲁鲁鲁鲁视频| 亚洲图片一区二区| 一区二区三区电影在线播| 一区2区3区在线看| 亚洲一区二区三区影院| 五月综合激情婷婷六月色窝| 丝袜美腿亚洲色图| 日韩精品每日更新| 韩国午夜理伦三级不卡影院| 国产一区免费电影| 成人免费毛片a| 91亚洲永久精品| 欧美调教femdomvk| 精品视频一区二区不卡| 欧美乱妇23p| 26uuu国产在线精品一区二区| 久久精品人人做人人爽人人| 国产精品另类一区| 久久一区二区三区四区| 26uuu精品一区二区三区四区在线| 2023国产精品自拍| 国产清纯白嫩初高生在线观看91| 亚洲欧洲三级电影| 亚洲成人免费av| 激情小说亚洲一区| 成人动漫av在线| 欧美日韩精品电影| 国产亚洲欧美激情| 亚洲精品一二三| 久久精品噜噜噜成人88aⅴ| 粉嫩高潮美女一区二区三区 | 亚洲人精品午夜| 婷婷综合五月天| 国产米奇在线777精品观看| 99精品国产视频| 欧美一级在线免费| 国产精品久久午夜| 免费人成精品欧美精品| 国产成人日日夜夜| 欧美精品日韩精品| 中文字幕av资源一区| 日韩专区一卡二卡| av一区二区三区黑人| 日韩一区二区三区免费看 | 一级中文字幕一区二区| 久久国产免费看| 日本久久精品电影| 国产人成一区二区三区影院| 亚洲成av人片在线| 99视频一区二区三区| 欧美tk—视频vk| 亚洲综合999| www.99精品| 26uuu国产电影一区二区| 亚洲国产欧美一区二区三区丁香婷| 极品少妇xxxx精品少妇| 欧美精品久久久久久久多人混战 | 国产精品福利av| 亚洲成人第一页| 国产一区二区三区免费看| 在线观看视频一区| 中文字幕欧美激情| 国内成人精品2018免费看| 欧美日韩国产三级| 亚洲欧美另类久久久精品| 高清久久久久久| 久久蜜桃香蕉精品一区二区三区| 日韩va亚洲va欧美va久久| 91久久精品一区二区| 中文字幕一区二区三区视频| 国产精品18久久久久久久久| 日韩免费成人网| 亚洲成人av一区| 欧美综合欧美视频| 亚洲精品久久久久久国产精华液| 成人精品高清在线| 中文字幕在线免费不卡| 国产精品99久久久久久久vr | 欧美韩国日本综合| 极品少妇xxxx偷拍精品少妇| 日韩欧美久久久| 日韩精品午夜视频| 日韩一区二区三区观看| 美女一区二区三区| 欧美不卡一区二区三区四区| 蜜臀av性久久久久蜜臀aⅴ四虎| 7777精品伊人久久久大香线蕉的|