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

📄 main.c

📁 TDK 6521 SOC 芯片 DEMO程序
💻 C
📖 第 1 页 / 共 2 页
字号:
    #if FLAG1
    flag1_run ();                       // run flag1
    #endif
}

// This is the code that is run while waiting for serial IO
void main_background (void)
{
    #ifdef OSCOPE_H
    OSCOPE_TOGGLE;                      // toggle DIO to measure time
    #endif

    #ifdef WD_MAIN_LOOP
    wd_reset (WD_MAIN_LOOP);            // The main loop is running...
    delay_clks (3);                     // Delay before next time.
    #endif

    #if !WATCHDOG
    RESET_WD();                         // No hierarchical watchdogs: reset it
    delay_clks (3);                     // Delay before next time.
    #endif

    FPAGE = PGADR_;                     // make an erase from EMC harmless.

    #if TIMERS
    stm_run ();                         // Run software timers.
    #endif

    meter_run ();                       // Run metering.

    #if BROWNOUT_BATMODE
    batmode_background ();              // detect and handle battery modes
    #endif

    #if ERROR_RECORDING
    Error_Record ();                    // Record errors
    #endif
}

// main loop
#define MODE_NONE 0  // no mode
#define MODE_SLEEP 1  // enter sleep mode
#define MODE_LCD 2 // enter LCD mode
#define MODE_RUN 3 // run the unit
void main (void)
{
    #if BROWNOUT_BATMODE & AUTOSLEEP
    uint8_t next_mode;
    #endif
    RESET_WD();                         // Reset watchdog.

    if (CE2 & WD_OVF)
    {
        Status |= WD_DETECTED;
        CE2 &= ~WD_OVF;                 // Clear WatchDog overflow flag.
        #if M6520
        main_soft_reset();              // simulate a hard reset
        #endif
    }

    #if BROWNOUT_BATMODE && AUTOSLEEP
    // If there's supposed to be a battery, run sleep and LCD modes
    if (BATTERY_MODE_ENABLE)
    {
        next_mode = MODE_NONE;
        while ( next_mode != MODE_RUN)
        {
            extern uint8_t xdata batmode_valid; // defined and set in batmodes.c

            // This policy finds the next state for the battery mode transitions.
            // Feel free to change this.
            if ( !(batmode_is_brownout ()) )
                next_mode = MODE_RUN;
            else if (batmode_valid == YES) // was XDATA memory on and CLI running?
                next_mode = MODE_SLEEP;
            else if ((LCDX & LCD_NUM) == 0) // did a reset occur?
                next_mode = MODE_RUN;
            else if (IE_PB)  // was the pushbutton pressed?
                next_mode = MODE_LCD;
            else
                next_mode = MODE_SLEEP;

            // The mechanism to start the next system state
            switch (next_mode)
            {
                default:
                case MODE_SLEEP:
                    #if LCD_ACTIVE
                    batmode_display ();
                    #endif

                    while ( batmode_is_brownout () )
                    {
                        CLR_IE_WAKE();              // clear the flags
                        CLR_IE_PB();

                        batmode_sleep ();           // save power
                        // exits this loop because waking from sleep starts
                        // at zero
                    }
                    break;

                case MODE_LCD:
                    while ( batmode_is_brownout () )
                    {
                        CLR_IE_PB();                // clear the flags
                        CLR_IE_WAKE();

                        batmode_wait_seconds (7);   // wake in a few seconds
                        batmode_lcd ();             // enter LCD-only mode
                        // exits this loop because waking from LCD mode starts
                        // at zero
                    }
                    break;

                case MODE_RUN:
                    break; // exit the loop, run the whole meter
            }
        } // end while next_mode != run
    } // end if battery present
    #endif // autosleep && brownout_batmode

    main_init ();                      // Initialize everything.

    while (TRUE)                       // run everything forever
        main_run ();
}


/***************************************************************************
 * History
 * $Log: main.c,v $
 * Revision 1.67  2006/10/13 00:48:14  tvander
 * Removed compile options for 6530, 6515;
 * renamed 6511 and 6513 to trace11 and trace13;
 * Binary verified unchanged from previous version.
 *
 * Revision 1.66  2006/10/06 01:44:03  tvander
 * Made null_int() always available for the 6520.
 *
 * Revision 1.65  2006/09/29 08:53:15  tvander
 * Calls soft reset when WD bit is set.
 *
 * Revision 1.64  2006/09/27 01:03:23  tvander
 * 6520 has a "Battery mode jumper" on DIO_8, added comments.
 * Changes baud rate depending on battery mode jumper.
 *
 * Revision 1.63  2006/09/20 23:50:26  tvander
 * Set interrupt priorities only once, during startup
 *
 * Revision 1.62  2006/09/18 19:28:07  tvander
 * Removed include of priority
 *
 * Revision 1.61  2006/09/10 00:26:02  Michael T. Fischer
 * First version to support DGM0915 LCD.
 *
 * Revision 1.60  2006/09/09 01:10:53  gmikef
 * *** empty log message ***
 *
 * Revision 1.59  2006/09/06 02:16:25  tvander
 * Removed delay routine to its own file.
 *
 * Revision 1.58  2006/08/30 21:55:42  gmikef
 * *** empty log message ***
 *
 * Revision 1.57  2006/08/30 02:09:25  gmikef
 * *** empty log message ***
 *
 * Revision 1.56  2006/08/09 00:56:58  tvander
 * *** empty log message ***
 *
 * Revision 1.55  2006/07/25 00:31:05  tvander
 * Moved the calibration loader into the main loop, so it runs during the meter's normal operation.
 *
 * Revision 1.54  2006/07/22 01:10:19  tvander
 * Fixed so a zero-length CE data area is possible
 *
 * Revision 1.53  2006/07/07 01:10:13  tvander
 * Clean build.
 * Rewrote order of soft reset.
 * Untested changes to use new battery-present configuration bit.
 *
 * Revision 1.52  2006/06/24 04:43:23  tvander
 * Debugged the battery modes, especially the mission->brownout transition
 * Includes necessary changes for the reset hack needed for the 6521A03.
 *
 * Revision 1.51  2006/06/22 22:42:10  tvander
 * Swapped order of port initialization so that DIOs do not glitch on soft reset.
 *
 * Revision 1.50  2006/06/20 20:32:52  tvander
 * Removed stuff to change LCD and DIOs around to read a button.
 *
 * Revision 1.49  2006/06/15 20:00:30  tvander
 * Removed read of power registers in brownout mode.
 * Changed so when the hierarchical watchdog (wd.c) is disabled, the main loop
 * resets the watchdog.
 *
 * Revision 1.48  2006/06/14 02:59:05  tvander
 * Simplifiedthe brownout, regressing to 17april06 version, but with hang
 * removed, and a brownout display that always executes before entering sleep mode.
 *
 * Reduced the MPU clock 8x from 4.9mHz to 614kHz
 *
 * Revision 1.47  2006/06/09 00:20:15  tvander
 * Improved invocation of calibration loader.
 *
 * Revision 1.46  2006/06/06 04:14:42  tvander
 * Added error logic, new scheme for calibration compile flags,
 * temporary holding place that might work for cal_ldr in D version
 *
 * Revision 1.45  2006/05/30 17:17:02  tvander
 * WAKE deprecated as a hardware dependency
 *
 * Revision 1.44  2006/05/18 23:18:46  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.43  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.42  2006/04/06 21:00:51  tvander
 * Shows start-up message.
 *
 * Revision 1.41  2006/03/08 20:25:28  gmikef
 * Simplify "Main_Soft_Reset". It now compiles, ok.
 *
 * Revision 1.40  2006/03/08 20:21:21  tvander
 * Reverted uncompilable code to previous, working code.
 *
 * Revision 1.39  2006/03/08 03:07:30  gmikef
 * *** empty log message ***
 *
 * Revision 1.38  2006/03/08 00:02:47  tvander
 * Disabled oscope.
 * Made date automatically the date of compilation.
 * Clean build, tested dates.
 *
 * Revision 1.37  2006/03/06 03:33:38  Michael T. Fischer
 * More 6530 prep.
 *
 * Revision 1.36  2006/03/03 11:27:04  Michael T. Fischer
 * Prep for 6530 LCD, etc.
 *
 * Revision 1.35  2006/01/17 00:59:28  tvander
 * Modified so 6513 would start up
 *
 * Revision 1.33  2005/12/21 01:29:22  tvander
 * 6513
 *
 * Revision 1.32  2005/12/12 23:53:14  tvander
 * Reliably runs 4mHz brownout mode.
 *
 * Revision 1.31  2005/11/29 01:18:58  tvander
 * Automatic software watchdog
 *
 * Revision 1.30  2005/11/19 04:15:16  gmikef
 * Fix CLI "cmd_v", blink "PASS" light when BOOTing.
 *
 * Revision 1.29  2005/11/10 22:51:33  tvander
 * 6520 has battery mode commands.
 * Brownout always has decimal point 7.
 * LCD Mode always has decimal points 7 and 6.
 * Sag detection is disabled.
 *
 * Revision 1.28  2005/11/05 01:57:24  tvander
 * Added code to clear pushbutton and wake flags.
 *
 * Revision 1.27  2005/10/31 17:38:00  tvander
 * Includes improved EEPROM code with uwire.
 * Clean build, all build trees (Thank-you, Mike!)
 *
 * Revision 1.26  2005/10/18 02:17:10  tvander
 * Access CLI in brownout by pressing reset.
 * Debugged serial 1 usage from CLI.
 * Implemented scrolling display as M17
 *
 * Revision 1.25  2005/10/12 23:00:03  tvander
 * Includes demonstratable mission mode, brownout, LCD and sleep modes
 *
 * Revision 1.24  2005/10/08 04:41:21  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.23  2005/10/06 20:55:01  tvander
 * Preliminary logic to manage the battery modes.
 *
 * Revision 1.22  2005/09/22 23:45:10  tvander
 * Clean build all models and unit tests, updated copyright to be fore Teridian
 *
 * Revision 1.21  2005/09/11 00:34:01  tvander
 * Clean compiles
 *
 * Revision 1.20  2005/09/08 00:31:41  tvander
 * Fixed: Lost data due to overwrite of Ithrshld, xfer busy never runs,
 * unavailable second phase, cosmetic issues with status.  Updated
 * date.
 *
 * Revision 1.19  2005/09/02 01:50:07  gmikef
 * Fixed CLI RTR command.
 *
 * Revision 1.18  2005/09/01 04:22:55  gmikef
 * *** empty log message ***
 *
 * Revision 1.17  2005/08/31 22:37:30  tvander
 * Debugged calibration logic well-enough that the code will start.
 *
 * Revision 1.16  2005/08/31 05:55:50  gmikef
 * First version w/ LAPIE interface.
 *
 * Revision 1.15  2005/08/30 18:13:20  gmikef
 * *** empty log message ***
 *
 * Revision 1.14  2005/08/28 02:18:35  gmikef
 * *** empty log message ***
 *
 * Revision 1.13  2005/08/22 22:30:55  tvander
 * Clean build of FLAG system
 * No pulse counting.
 * No debug/CLI.
 *
 * Revision 1.12  2005/08/20 01:32:47  gmikef
 * *** empty log message ***
 *
 * Revision 1.11  2005/08/19 01:04:41  gmikef
 * *** empty log message ***
 *
 * Revision 1.10  2005/08/18 17:38:53  gmikef
 * *** empty log message ***
 *
 * Revision 1.9  2005/08/18 16:54:36  gmikef
 * *** empty log message ***
 *
 * Revision 1.8  2005/08/16 02:28:30  gmikef
 * Remapped LCD for 6520 Eval Board.
 * Mapped CE code location to address of 'CeCode'.
 *
 * Revision 1.7  2005/08/12 21:52:55  tvander
 * main initialization now enables interrupts.
 *
 * Revision 1.6  2005/08/12 05:59:21  gmikef
 * Added MPU temperature compensation for GAIN_ADJ.
 * Added changes to support new CE 6521 code.
 *
 * Revision 1.5  2005/07/14 20:15:49  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.4  2005/06/25 02:01:02  tvander
 * Integrated pulse count.
 *
 * Revision 1.3  2005/06/16 18:56:32  tvander
 * When the EEPROM has invalid data, the values should be restored to a default.
 *
 * Revision 1.2  2005/06/10 22:57:07  tvander
 * Uses macros to reset watchdog and clear IE and RTC interrupts
 * Includes 6515 improvements in register defs.
 *
 * Revision 1.1  2005/05/20 01:19:02  gmikef
 * Switched to comon Main, Defaults & Display code for all parts.
 *
 * Revision 1.3  2005/05/14 00:56:19  tvander
 * Integrated flag0, ser0
 * Regression tested and fixed 6521b
 *
 * Revision 1.2  2005/05/13 00:34:43  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.1  2005/05/06 16:40:32  tvander
 * Build errors fixed
 *
 * Revision 1.1  2005/04/28 19:20:07  tvander
 * Improved; almost compiles
 *
 * Revision 1.1  2005/04/21 02:04:37  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.         *
 ***************************************************************************/
/* main.c */

⌨️ 快捷键说明

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