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

📄 tmr0.c

📁 TDK 6521 SOC 芯片 DEMO程序
💻 C
字号:
/***************************************************************************
 * This code and information is provided "as is" without warranty of any   *
 * kind, either expressed or implied, including but not limited to the     *
 * implied warranties of merchantability and/or fitness for a particular   *
 * purpose.                                                                *
 *                                                                         *
 * Copyright (C) 2005 Teridian Semiconductor Corp. All Rights Reserved.    *
 ***************************************************************************/
//**************************************************************************
//
//  DESCRIPTION: 71M651x POWER METER - Timer Routines. 
//
//  AUTHOR:  RGV
//
//  HISTORY: See end of file
//
//**************************************************************************
//
//  File: TIMERS.C
//

#include "options.h"
#if TMR0
#include "wd.h"
#include "tmr0.h"

/*** Public functions declared within this module ***/
// the start function and the isr

/*** External functions used by this module ***/
// None.

/*** External variables used within this module ***/
// None.

/*** Public variables declared within this module ***/
// None.

/*** Private functions declared within this module ***/
// None.

/*** Private variables declared within this module ***/
static uint8_16_t tmr0_reload;
static bool tmr0_restart;
static void (*tmr0_pfn) (void);


/*****************************************************/
//  A single timer, MPU clk speed is fixed.
// coded to no absolute registers because it's called by stm_start,
// which in turn is called from inside several serial interrupts to handle
// protocol timeouts.
#pragma save
#pragma NOAREGS
void tmr0_start (uint16_t reload_reg, uint8_t restart, void (*pfn) (void)) small reentrant
{
    // TIMER0: 16-bit timer...  TIMER1: unchanged
    TR0 = FALSE; // turn off the timer
    TF0 = FALSE; // clear any pending interrupts
    tmr0_restart = restart;  // set the restart flag
    tmr0_pfn = pfn; // set the application function

    // configure the timer- set or clear every bit for timer 0
    TMOD = (TMOD & 0xF0) | T0_16_;     // TIMER0: 16-bit timer
    tmr0_reload.i = reload_reg;
    TH0 = tmr0_reload.c[HI]; // set the reload register
    TL0 = tmr0_reload.c[LO];

    // Interrupt priorities are set in main.

    tmr0_enable(); // enable the relevant interrupt

    TR0 = TRUE; // start the timer

    #ifdef WD_TMR0  // if it's defined, then it needs testing
    wd_create( WD_TMR0 ); // reset tmr0's software watchdog
    #endif
}
#pragma restore


//  A single timer, MPU clk speed is fixed.
//  Note, if this is invoked very frequently, change it to have a
//  private register bank, rather than using NOAREGS
//  See the serial interrupts (e.g. es0_isr in io\ser0.c) for examples.
//  Register banks are allocated in main\options_gbl.h
#pragma save
#pragma NOAREGS
void tmr0_isr (void)  small reentrant interrupt TMR0_IV
{                                       // Uses hardware TIMER0.
    // do the default timer stuff first, so the application routine
    // can set up the timer again.
    if (!tmr0_restart)
    {
        TR0 = FALSE; // stop the timer
    }
    else
    {
        TH0 = tmr0_reload.c[HI]; // set the reload register
        TL0 = tmr0_reload.c[LO];
    }
    // if it's not null, run the application's timer routine
    if (tmr0_pfn != 0)
        (*tmr0_pfn)();

    #ifdef WD_TMR0  // if it's defined, then it needs testing
    wd_reset( WD_TMR0 ); // reset tmr0's software watchdog
    #endif
}
#pragma restore

#endif
/***************************************************************************
 * History:
 * $Log: tmr0.c,v $
 * Revision 1.18  2006/09/20 23:49:34  tvander
 * Set interrupt priorities only once, during start-up
 *
 * Revision 1.17  2006/09/18 19:22:43  tvander
 * Sets interrupt priorities.
 *
 * Revision 1.16  2006/09/09 01:10:07  gmikef
 * *** empty log message ***
 *
 * Revision 1.15  2006/08/09 00:56:36  tvander
 * *** empty log message ***
 *
 * Revision 1.14  2006/06/29 00:55:49  tvander
 * Marked NOAREGS on reentrant routines that needed it.
 *
 * Revision 1.12  2005/11/29 01:14:13  tvander
 * Automatic software watchdogs
 *
 * Revision 1.11  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.10  2005/09/22 23:45:08  tvander
 * Clean build all models and unit tests, updated copyright to be fore Teridian
 *
 * Revision 1.9  2005/08/28 02:16:23  gmikef
 * *** empty log message ***
 *
 * Revision 1.8  2005/08/10 21:35:48  tvander
 * Uses interrupt enabled macro.
 *
 * Revision 1.7  2005/07/01 00:24:04  tvander
 * Modified to reduce the idata used.
 *
 * Revision 1.6  2005/05/26 21:54:37  tvander
 * Flag is grossly working with GUI: signs on, reads, writes both xdata and idata, interlocks with CE cycle, and timeouts work.
 *
 * Revision 1.5  2005/05/19 00:43:32  tvander
 * Made hardware timers optional.
 *
 * Revision 1.4  2005/05/03 00:39:44  tvander
 * Incorporated event reporting in tmr0,tmr1 and unit tests.
 * Retested stm, trm0, tmr1.
 * Incorporated untested changes in io651x.h
 *
 * Revision 1.3  2005/04/25 19:15:31  tvander
 * tested hardware timer code
 *
 * Revision 1.2  2005/04/21 02:01:14  gmikef
 * *** empty log message ***
 *
 * Revision 1.4  2005/04/09 02:04:27  gmikef
 * *** empty log message ***
 *
 * Revision 1.1  2005/03/23 19:19:32  tvander
 * Added untested timer functions.
 * Updated iicdio and iiceep to reflect improvements in 6510 code.
 * ser0 and ser1 updated to provide features for flag.
 *
 * Revision 1.4  2005/03/08 19:06:53  tvander
 * Self calibration in all software models
 *
 * Revision 1.2  2005/02/17 18:32:40  tvander
 * Added automatic check-in logging to all source code.
 *
 * 2003 OCTOBER 30; First Version.
 *
 * 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 + -