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

📄 rtc.c

📁 TDK 6521 SOC 芯片 DEMO程序
💻 C
📖 第 1 页 / 共 2 页
字号:
        + (((int32_t) (*ptm).Min + 3) / 6);
    #endif
    return j;
}

int32_t Delta_Seconds (struct RTC_t xdata *start, struct RTC_t xdata *end)
{
    return (Julian(end) - Julian(start));  // delta time. 
}
#endif

#endif // REAL_TIME_DATE

#if OPERATING_TIME || REAL_TIME_DATE
#define BILLION (1000000000L)
#pragma save
#pragma NOAREGS
// called from the interrupt decode routines in io65??.c
void rtc_isr (void) small reentrant
{
    // This produces a calibration signal, usable when the
    // pulse output is disabled.  It's needed to set the compensation.
    // It is enabled automatically after autocalibration.
    // It must be first in this routine to reduce timing uncertainties.
    #if 0
    DIO_7 ^= 1;                     // toggle pulse output
    #endif

    #if REAL_TIME_DATE
    rtc_ready = TRUE;

    #if !RTC_LINE_LOCKED  // at least a constant adjustment is the default
    // adjust the clock in real time
    trim_count += trim_value;
    if (trim_count < 0) // same speed as checking a flag
    {
        if (trim_count < -BILLION)  // -1.0e9 equals -1 second
        {
            second_count -= 1;
            trim_count += BILLION;
        }
    }
    else
    {
        if (trim_count > BILLION)  // 1.0e9 = 1 second
        {
            second_count += 1;
            trim_count -= 1.0e9;
        }
    }
    // catch up on adjustments; 
    // Adjustments have to be distributed, no more than one per two seconds
    // Normally this would be done just by the slow rate of adjustment,
    // but the unit might be in storage for years.  After that, it would
    // have many seconds of adjustment at once.
    if (rtc_adjusting_now)
    {
        rtc_adjusting_now = FALSE;
    }
    else
    {
        if (second_count < 0)
        {
            second_count += 1;
            // Pulse decrement.
            #if M6520
            WE = 0x00;                        // Write Enable RTC.
            #endif
            RTC_ADJUST =  RTC_DEC_SEC;
            rtc_adjusting_now = TRUE;
        }
        else if (second_count > 0)
        {
            second_count -= 1;
            // Pulse increment.
            #if M6520
            WE = 0x00;                        // Write Enable RTC.
            #endif
            RTC_ADJUST =  RTC_INC_SEC;   
            rtc_adjusting_now = TRUE;
        }
    }

    #else
    // This locks the RTC to the line frequency
    // This requires no calibration.
    {
        // get the nominal counts per second, calculated in meter\freq.c
        int8_t cnt = (int8_t)main_edge_cnt_nom;

        // Are mains data available? (demo code is often run without mains)
        if (cnt != 0) // from meter\freq.c
        {
            // how much error has accumulated?
            MainEdgeCount -= (long) cnt;       // remove this second's counts
            if (MainEdgeCount < (long)(-cnt)) // clock is too fast
            {
                MainEdgeCount += (long)cnt;    // adjust the measurement

                #if M6520
                WE = 0x00;                     // Write Enable RTC.
                #endif
                RTC_ADJUST =  RTC_DEC_SEC;     // Decrement the seconds.  
            }
            else if (MainEdgeCount > (long)cnt)     // clock is too slow
            {
                MainEdgeCount -= (long)cnt;    // adjust the measurement

                #if M6520
                WE = 0x00;                     // Write Enable RTC.
                #endif
                RTC_ADJUST =  RTC_INC_SEC;     // increment second.  
            }
        }
    }
    #endif // RTC_LINE_LOCKED
    #endif // REAL_TIME_DATE
    
    #if  OPERATING_TIME
    OperatingSeconds += 1;           // count seconds of operation
    #endif
}
#pragma restore
#endif // REAL_TIME_DATE || OPERATING_TIME
/***************************************************************************
 * $Log: rtc.c,v $
 * Revision 1.45  2006/09/14 00:35:46  tvander
 * substitute spaces for tabs
 *
 * Revision 1.44  2006/09/13 21:37:30  gmikef
 * *** empty log message ***
 *
 * Revision 1.43  2006/09/12 02:43:54  gmikef
 * *** empty log message ***
 *
 * Revision 1.42  2006/09/10 00:25:30  Michael T. Fischer
 * First version to support DGM0915 LCD.
 *
 * Revision 1.41  2006/09/09 01:09:46  gmikef
 * *** empty log message ***
 *
 * Revision 1.40  2006/09/08 07:35:47  Michael T. Fischer
 * *** empty log message ***
 *
 * Revision 1.39  2006/08/16 01:43:52  tvander
 * Julian diff. on date.
 *
 * Revision 1.38  2006/08/09 00:56:35  tvander
 * *** empty log message ***
 *
 * Revision 1.37  2006/07/27 00:55:27  tvander
 * Fixed errors in link-locking.
 *
 * Revision 1.36  2006/07/22 01:09:40  tvander
 * *** empty log message ***
 *
 * Revision 1.35  2006/07/17 18:02:47  tvander
 * Removed redundant calls to read real time clock.
 *
 * Revision 1.34  2006/07/07 00:54:40  tvander
 * Removed reference to mmath.h, which it no longer uses.
 *
 * Revision 1.33  2006/06/15 16:37:55  tvander
 * Put NOAREGs around the timer routine.
 *
 * Revision 1.32  2006/06/14 18:13:20  tvander
 * LCD display issues fixed.
 *
 * Revision 1.31  2006/06/06 03:56:05  tvander
 * Operating time can now be enabled without enabling real-time and date.
 *
 * Revision 1.30  2006/05/25 03:24:12  tvander
 * Added timeouts to EEPROMs.  Tested all three.
 * Newly ported calibration loader, compiles without error.
 * RTC setting uses a software timer (less code, also frees tmr1)
 *
 * Revision 1.29  2006/05/18 23:18:45  tvander
 * 16K and 32K
 * First cut at new requirements.
 * 32K 6521 is grossly tested.
 * All others have a clean compile with C51 8.02
 *
 * Revision 1.28  2006/04/27 00:06:52  tvander
 * Added tamper resistance, mostly to wh.c; Added a calibration signal to rtc.c
 *
 * Revision 1.27  2006/04/25 01:09:49  tvander
 * Integrated improved RTC.  Compensates for time off, has default constant
 * compensation.  Computes true hours of operation.
 *
 * Revision 1.26  2006/04/19 01:15:33  tvander
 * Integrated with unit test/clock.  The big thing was to uncouple it from the
 * data structure Totals in meter.h.  Now the options define where it puts its
 * data.
 *
 * Revision 1.25  2006/03/08 00:00:57  tvander
 * Revised IO so that multiplexed interrupts are centralized in io65xx.c
 * Added default interrupts to io65xx.c
 * Clean build.
 * Tested CE, serial.
 * interrupting EEPROM driver fails.
 *
 * Revision 1.24  2006/03/06 03:31:49  Michael T. Fischer
 * More 6530 prep.
 *
 * Revision 1.23  2006/03/03 11:26:20  Michael T. Fischer
 * Prep for 6530 LCD, etc.
 *
 * Revision 1.22  2006/01/10 03:58:22  gmikef
 * Added PDATA support for CE Outputs.
 *
 * Revision 1.21  2006/01/04 04:47:50  gmikef
 * Switched RMS and VA calculations to use floating point. (and Calibration).
 *
 * Revision 1.19  2005/11/18 22:11:58  tvander
 * In 6521, sleep or LCD-only modes causes the RAM to fail, but the clock is OK.
 * So, the check of RAM copies of the clock is wrong.
 *
 * Revision 1.18  2005/10/08 04:41:20  tvander
 * Fixed priority inversion.
 * Rewrote watchdog to work in brownout, but of course it doesn't work.
 * Watchdog can now be defeated by clearing watchdog option to 0.
 * Reorganized watt hour modules (at last!).
 * Disabled reading of STATUS in 6521_cli because the CE's status is always SAG.
 * Tested with 6521_CLI; measurements seem to work.
 * Fixed other builds.
 *
 * Revision 1.17  2005/09/22 23:45:06  tvander
 * Clean build all models and unit tests, updated copyright to be fore Teridian
 *
 * Revision 1.16  2005/09/11 00:33:58  tvander
 * Clean compiles
 *
 * Revision 1.15  2005/09/01 04:22:14  gmikef
 * *** empty log message ***
 *
 * Revision 1.14  2005/09/01 02:03:48  gmikef
 * Cleaned up the builds.
 *
 * Revision 1.13  2005/08/30 18:12:38  gmikef
 * *** empty log message ***
 *
 * Revision 1.12  2005/08/28 02:14:23  gmikef
 * *** empty log message ***
 *
 * Revision 1.11  2005/08/24 00:07:30  tvander
 * Incorrect argument order in the timer invocation, caused the timer interrupt
 * to run too many times and corrupt IO memory.
 *
 * Revision 1.10  2005/08/12 21:50:09  tvander
 * RTC TIC is redundant in the versions I tested.
 *
 * Revision 1.9  2005/08/12 05:58:59  gmikef
 * Added MPU temperature compensation for GAIN_ADJ.
 * Added changes to support new CE 6521 code.
 *
 * Revision 1.8  2005/08/11 18:12:13  tvander
 * *** empty log message ***
 *
 * Revision 1.7  2005/08/10 01:58:13  gmikef
 * *** empty log message ***
 *
 * Revision 1.6  2005/07/14 20:15:48  tvander
 * ce code concentrated in ce.c
 * ce interface concentrated in ce652x.c, .h
 * Fixed 0-length read or write using flag protocol.
 * display.c is out of the build
 * kwh_initialize now reads the LRC.
 *
 * Revision 1.5  2005/06/09 00:01:22  tvander
 * Flag reads and writes work for power registers, the real time clock and CE RAM.
 *
 * Revision 1.4  2005/05/13 00:34:41  tvander
 * 6511/32k works
 * Integrated and debugged self-calibration.
 * The build has one unused segment, and no other errors or warnings.
 * default LCD and pulse displays appear OK.
 * EEPROM, software timers and hardware timers are all integrated.
 *
 * Revision 1.3  2005/04/30 02:10:37  gmikef
 * *** empty log message ***
 *
 * Revision 1.9  2005/04/29 00:01:55  gmikef
 * *** empty log message ***
 *
 * Revision 1.8  2005/04/25 21:26:02  gmikef
 * *** empty log message ***
 *
 * Revision 1.1  2005/04/21 02:03:01  gmikef
 * *** empty log message ***
 *
 * Revision 1.7  2005/04/20 03:09:01  gmikef
 * *** empty log message ***
 *
 * Revision 1.6  2005/04/16 02:18:44  gmikef
 * *** empty log message ***
 *
 * Copyright (C) 2005 Teridian Semiconductor Corp. All Rights Reserved.    *
 * this program is fully protected by the United States copyright          *
 * laws and is the property of Teridian Semiconductor Corporation.         *
 ***************************************************************************/

⌨️ 快捷键说明

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