📄 io652x.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) 2006 Teridian Semiconductor Corp. All Rights Reserved. *
***************************************************************************/
// DESCRIPTION: 71M652x POWER METER - I/O memory mapped SFR definitions.
//
// AUTHOR: MTF
//
// HISTORY: see end of file
//-------------------------------------------------------------------------//
// File: IO652x.C
//
// io652x special functions registers.
#include "options.h"
#include "ce.h" // access to CE interrupt code
#include "rtc.h" // access to RTC interrupt code
#include "wd.h" // access to watchdog code
#include "pcnt.h" // access to pulse counting code
#include "io652x.h" // check for consistency of definitions
/*** External functions referenced by this module ***/
/*** External variables referenced by this module ***/
// None.
/*** Public variables declared within this module *** selectable via "defaults" */
#if IO_DEBUG
volatile struct iConfig_t xdata Configuration _at_ (IO_BASE + 0x00);
volatile struct iDio_t xdata Digital_IO _at_ (IO_BASE + 0x08);
volatile struct iRTC_t xdata Real_Time_Clock _at_ (IO_BASE + 0x15);
volatile struct iLCD_Interface_t xdata Lcd_Interface _at_ (IO_BASE + 0x20);
volatile struct iLCD_Segments_t xdata Lcd_Segments _at_ (IO_BASE + 0x30);
volatile struct iRTM_t xdata Rtm_Probes _at_ (IO_BASE + 0x60);
volatile struct iPulseGenerator_t xdata PulseGenerator _at_ (IO_BASE + 0x80);
volatile struct iCE_Lctn_t xdata CE_Location _at_ (IO_BASE + 0xA8);
volatile struct iTrim_t xdata Trim_Control _at_ (IO_BASE + 0xFD);
#endif
volatile uint8x_t CE0 _at_ (IO_BASE + 0x00);
volatile uint8x_t CE1 _at_ (IO_BASE + 0x01);
volatile uint8x_t CE2 _at_ (IO_BASE + 0x02);
volatile uint8x_t COMP0 _at_ (IO_BASE + 0x03);
volatile uint8x_t CONFIG0 _at_ (IO_BASE + 0x04);
volatile uint8x_t CONFIG1 _at_ (IO_BASE + 0x05);
volatile uint8x_t VERSION _at_ (IO_BASE + 0x06);
volatile uint8x_t CONFIG2 _at_ (IO_BASE + 0x07);
volatile uint8x_t DIO _at_ (IO_BASE + 0x08);
volatile uint8x_t DIO_R[6] _at_ (IO_BASE + 0x09);
volatile uint8x_t RTC[7] _at_ (IO_BASE + 0x15);
volatile uint8x_t RTC_ADJUST _at_ (IO_BASE + 0x1C);
volatile uint8x_t WE _at_ (IO_BASE + 0x1F);
volatile uint8x_t LCDX _at_ (IO_BASE + 0x20);
volatile uint8x_t LCDY _at_ (IO_BASE + 0x21);
volatile uint8x_t LCDZ _at_ (IO_BASE + 0x22);
volatile uint8x_t LCD[39] _at_ (IO_BASE + 0x30);
volatile uint8x_t LCD_BLINK _at_ (IO_BASE + 0x5A);
volatile uint8x_t RTM[4] _at_ (IO_BASE + 0x60);
volatile uint8x_t PLS_W _at_ (IO_BASE + 0x80);
volatile uint8x_t PLS_I _at_ (IO_BASE + 0x81);
volatile uint8x_t CE3 _at_ (IO_BASE + 0xA8);
volatile uint8x_t WAKE _at_ (IO_BASE + 0xA9);
volatile uint8x_t TMUX _at_ (IO_BASE + 0xAA);
volatile uint8x_t TRIMSEL _at_ (IO_BASE + 0xFD);
volatile uint8x_t TRIMX _at_ (IO_BASE + 0xFE);
volatile int8x_t TRIM _at_ (IO_BASE + 0xFF);
/*** Private functions declared within this module ***/
// None.
/*** Private variables declared within this module ***/
// None.
// INTERRUPT SERVICE ROUTINES
// These are stubs to handle spurious interrupts when modules are
// omitted from the build,
// or disambiguation routines to route multiplexed interrupts.
#if !TMR0 && !M6521B
#pragma save
#pragma NOAREGS
void tmr0_isr (void) small reentrant interrupt TMR0_IV
{
ET0 = FALSE; // disable the interrupt
}
#pragma restore
#endif
#if !TMR1 && !M6521B
#pragma save
#pragma NOAREGS
void tmr1_isr (void) small reentrant interrupt TMR1_IV
{
ET1 = FALSE; // disable the interrupt
}
#pragma restore
#endif
#if !SERIAL0 && !M6521B
#pragma save
#pragma NOAREGS
void es0_isr (void) small reentrant interrupt ES0_IV
{
ES0 = FALSE;
}
#pragma restore
#endif
#if !SERIAL1 && !M6521B
#pragma save
#pragma NOAREGS
void es1_isr (void) small reentrant interrupt ES1_IV
{
IEN2 &= ~ES1_; // disable the interrupt
}
#pragma restore
#endif
#if !PULSE_CNT && !M6521B
#pragma save
#pragma NOAREGS
void io_int0_isr (void) small reentrant interrupt IO_INT0_IV
{
EX_IO_INT0 = FALSE; // disable the interrupt
}
#pragma restore
#endif
#if !PULSE_CNT && !M6521B
#pragma save
#pragma NOAREGS
void io_int1_isr (void) small reentrant interrupt IO_INT1_IV
{
EX_IO_INT1 = FALSE; // disable the interrupt
}
#pragma restore
#endif
#if !FLASH && !M6521B
#pragma save
#pragma NOAREGS
void fwcol_isr (void) small reentrant interrupt FWCOL_IV
{
EX_FWCOL01 = FALSE; // disable the interrupt
}
#pragma restore
#endif
// ce_busy_isr is in ce.c, and is not disabled in any configuration
#if !BROWNOUT_BATMODE
#pragma save
#pragma NOAREGS
void pll_isr (void) small reentrant interrupt PLL_IV
{
EX_PLL_OK = FALSE; // disable the interrupt
}
#pragma restore
#endif
#if !I2C_INT && !M6521B
#pragma save
#pragma NOAREGS
void eeprom_isr (void) small reentrant interrupt EEPROM_IV
{
EX_EEPROM = FALSE; // disable the interrupt
}
#pragma restore
#endif
#pragma save
#pragma NOAREGS
void xfer_rtc_isr (void) small reentrant interrupt XFER_RTC_IV
{
// If there's no loop, there's a rare, subtle timing error because int6
// is edge-triggered and the two interrupts "or" into it. Say that
// the RTC interrupt happens, and then the XFER interrupt happens
// after IE_XFER is tested, but before the RTC interrupt is cleared.
// In this case, the signal to int6 will remain set, and never have
// an edge to cause another interrupt 6. Therefore, the xfer interrupt
// will hang into the indefinite future.
// This is bad. It prevents delivery of the data to the meter.
// Both interrupts have a backup- the main watchdog timer is
// never reset unless the interrupts run.
do
{
// The RTC interrupt is first to reduce timing uncertainties
// for RTC calibration and compensation.
if (IE_RTC)
{
CLR_IE_RTC(); // Just clear IE_RTC bit.
// one can toggle a DIO bit here in order to calibrate
// the RTC.
#if REAL_TIME_DATE || OPERATING_TIME
rtc_isr (); // Compensate the clock
#endif // REAL_TIME_DATE.
#if PULSE_CNT
pcnt_accumulate (); // Sum timed counts of pulses
#endif
// This interrupt continues to run in brownout mode, and further
// it interrupts in real time, not CPU clock time, so that the
// watchdog continues to be accurately reset.
// Reset the watchdog if software watchdogs have all been reset
#ifdef WD_RTC
wd_reset ( WD_RTC );
#endif
// #if !WATCHDOG // if no hierarchical watchdogs
// RESET_WD(); // Reset the watchdog 1/sec.
// #endif
}
if (IE_XFER)
{
CLR_IE_XFER(); // clear IE_XFER bit
ce_xfer_busyz_isr (); // get the CE data
}
} while (IE_XFER | IE_RTC); // while interrupts need processing
}
#pragma restore
#if ENHANCED_TRIM
int8_t Read_Trim (enum eTRIMSEL select)
{
static int8_t code mask[9] =
// 0 1 2 3 4 5 6 7 8
{0x00, 0xFF, 0x3F, 0x0F, 0x3F, 0xFF, 0xFF, 0x3F, 0x01};
static int8_t code extend[9] =
// 0 1 2 3 4 5 6 7 8
{0x00, 0x00, 0xE0, 0xF8, 0x00, 0x00, 0x00, 0xE0, 0xFF};
int8_t t;
if (select < 0 || select > 8) // Prevent bad indices.
return 0;
TRIMSEL = select; // Select trim.
t = TRIM; // Read trim.
TRIMSEL = 0; // Restore the normal state (per spec).
t &= mask[ select ]; // Mask trim data
if (t & extend[ select ]) // Sign-extend trim data.
t |= extend[ select ];
return (t);
}
#endif
/***************************************************************************
* History:
* $Log: io652x.c,v $
* Revision 1.24 2006/09/09 01:14:02 gmikef
* *** empty log message ***
*
* Revision 1.23 2006/07/13 18:43:40 tvander
* If watchdog is reset continually in main loop, and doesn't depend on periodic interrupts, then the code to fix up the CE isn't needed either.
*
* Revision 1.22 2006/06/20 20:30:50 tvander
* Commented-out watchdog logic
*
* Revision 1.21 2006/06/15 16:51:49 tvander
* When non-hierarchical watchdogs (e.g. wd.c) are disabled, it now
* resets watchdogs in one-second timer and main loop.
*
* Revision 1.20 2006/06/08 20:57:11 tvander
* Regularized the call of the watchdog fns.
*
* Revision 1.19 2006/06/06 05:14:55 tvander
* clean build
*
* Revision 1.18 2006/06/06 04:01:37 tvander
* Modified so the real tiem date and operating time can be separated.
*
* Revision 1.17 2006/04/27 00:06:57 tvander
* Added tamper resistance, mostly to wh.c; Added a calibration signal to rtc.c
*
* Revision 1.16 2006/03/17 00:39:03 tvander
* Made 6521B smaller, by omitting spurious interrupt handling.
*
* Revision 1.15 2006/03/08 00:08:02 tvander
* Multiplexed interrupts are in io65xx.c
* Added stubbed interrupt to io65xx.c
* Clean build
*
* Revision 1.14 2006/03/06 03:38:57 Michael T. Fischer
* More 6530 prep.
*
* Revision 1.13 2005/12/23 01:27:46 tvander
* Meter.c would not compile for 6513 because a table was wrong.
* A few style issues.
*
* Revision 1.11 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.10 2005/09/22 23:45:16 tvander
* Clean build all models and unit tests, updated copyright to be fore Teridian
*
* Revision 1.9 2005/08/30 18:17:01 gmikef
* *** empty log message ***
*
* Revision 1.8 2005/07/14 20:15:52 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.7 2005/05/13 00:34:45 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.6 2005/05/06 16:40:34 tvander
* Build errors fixed
*
* Revision 1.5 2005/05/03 00:39:45 tvander
* Incorporated event reporting in tmr0,tmr1 and unit tests.
* Retested stm, trm0, tmr1.
* Incorporated untested changes in io651x.h
*
* Revision 1.4 2005/04/30 02:13:59 gmikef
* *** empty log message ***
*
* Revision 1.19 2005/04/29 00:01:59 gmikef
* *** empty log message ***
*
* Revision 1.18 2005/04/27 21:38:08 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. *
***************************************************************************/
/* io652x.c */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -