?? defaults.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: 71M652x POWER METER - Default values.
//
// AUTHOR: MTF
//
// HISTORY: See end of file.
//**************************************************************************
// File: DEFAULTS.C
//
#include "options.h"
#include "batmodes.h"
#include "ce.h"
#include "library.h"
#include "cli.h"
#include "io.h"
#include "meter.h"
#if SERIAL0
#include "ser0.h"
#endif
#if SERIAL1
#include "ser1.h"
#endif
#include "flag0.h"
#include "flag1.h"
#include "ser0cli.h"
#include "ser1cli.h"
#include "sercli.h"
#include "serial.h"
#include "lcd.h"
#include "defaults.h"
extern const uint8r_t pre_samps[];
extern uint16x_t samples;
#if CLI
extern enum SERIAL_PORT xdata port;
#endif
/*** Public variables declared within this module ***/
uint8_t xdata select_total, select_phase, select_flow;
#if PULSE_CNT
uint8_t xdata select_pulse;
#endif
#if PULSE_CNT || MAIN_EDGE_COUNT
uint8_t xdata select_interval;
#endif
/*** Private functions declared within this module ***/
// None.
/*** Private variables declared within this module ***/
/*
This function initializes the mode bits as shown below.
All mode bits are in 'reset state' except:
CE_EN=1;
DIO_DIR0=11111111;
DIO_PV=1;
DIO_PW=1;
EQU=010;
LCD_EN=1;
LCD_FS=11111;
LCD_NUM=01101;
SUM_CYCLES=60=111100;
CHOP=11;
VREF_CAL=1;
*/
uint8r_t ri_defaults[] =
{ // 0 1 2 3 4 5 6 7
#if M6520
EQUATION, 0x3C, // 2000-2001
#if REAL_TIME_DATE
0x43, // 2002 enable xfer_busy, RTC interrupt.
#else
0x41, // 2002 enable xfer_busy interrupt .
#endif
0x01, MPU_FREQ, 0x1F, 0x01, // 2003-6. MPU_FREQ, (probably 614kHz).
#if BROWNOUT_BATMODE
0x20, // 2007. Enable PLL_OK
#else
0x00, // 2007.
#endif
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 2008-F. DIO Resources, etc.
#if DGM0915_HTN
0x08, 0x2D, // 2020-1. 8 extra segs.
#else
0x0D, 0x2D, // 2020-1. 13 extra segs.
#endif
0x00, // 205A. LCD BLINK.
0x00, 0x00, 0x00, 0x00, // 2060-3. RTM.
0x44, 0x51, // 2080-1. 10ms Pulse_Width, Pulse_Interval.
0x04, 0x00, 0x00, // 20A8-A. CE3, WAKE, TMUX.
0x00, 0x00, 0x00 // 20FD-F. TRIMSEL, TRIMX, TRIM.
#elif TRACE11
#if REAL_TIME_DATE
EQUATION, 0x3C, 0x73, 0x01, // 2000-3. Enable XFER_BUSY, etc.
#else
EQUATION, 0x3C, 0x71, 0x01, // 2000-3. Enable XFER_BUSY, etc.
#endif
MPU_FREQ, 0x12, 0x01, 0x00, // 2004-7. MPU_FREQ, longer FIR
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 2008-F. DIO Resources, etc.
0x8E, 0x25, 0x1F, // 2020-2. LCD Enable, 14 extra segs, etc.
0x00, 0x00, 0x00, 0x00, // 2060-3. RTM.
0x00, 0x00, 0x00, 0x00, 0x00, // Padding, for IO_MERGE
0x00, 0x00, 0x00 // 20FD TRIMSEL
#elif TRACE13
#if REAL_TIME_DATE
EQUATION, 0x3C, 0x33, 0x01, // 2000-3. Enable RTC & XFER_BUSY, etc.
#else
EQUATION, 0x3C, 0x31, 0x01, // 2000-3. Enable XFER_BUSY, etc.
#endif
MPU_FREQ, 0x02, 0x01, 0x00, // 2004-7. MPU_FREQ, short FIR
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 2008-F. DIO Resources, etc.
0x8E, 0x25, 0x1F, // 2020-2. LCD Enable, 14 extra segs, etc.
0x00, 0x00, 0x00, 0x00, // 2060-3. RTM.
0x00, 0x00, 0x00, 0x00, 0x00, // Padding, for IO_MERGE
0x00, 0x00, 0x00 // 20FD TRIMSEL
#else
#error unknown configuration
#endif
};
uint8r_t defaults[] =
{
0x3, 0, 0, 1, // 0..3 Wh A, Output, RMS display select, aux_mux.
0, 0, // 4,5 Default debug port.
#if M6520
// DIO pin directions: outputs,
// DIO_4,5 pulled up by EEPROM, DIO_0 is the button,
// DIO-8 is battery mode select.
0xFF, 0xFE, 0xCE, // 6..8
0xFF, 0xFF, 0xFF, // 9..11 DIO pin values: Drive all outputs high.
#elif TRACE11
#if SCROLL_METER || (AUTOCAL && !CLI)
0xFE, 0xFF, 0xCF, // 6..8 DIO pin directions: outputs, DIO_16 is a button.
#else // normal
0xFF, 0xFF, 0xCF, // 6..8 DIO pin directions: outputs
#endif
0xFF, 0xFF, 0xFF, // 9..11 DIO pin values: Drive all outputs high.
#elif TRACE13
#if SCROLL_METER || (AUTOCAL && !CLI)
0xFF, 0xFF, 0xFB, // 6..8 DIO pin directions: outputs, DIO_2 is a button.
#else // normal
0xFF, 0xFF, 0xFF, // 6..8 DIO pin directions: outputs
#endif
0xFF, 0xFF, 0xFF, // 9..11 DIO pin values: Drive all outputs high.
#else
#error unknown device
#endif
BAUD_0, 0x39, // 12,13 Serial0, bit rate, (seven bit, echo, parity none, odd, stop_bits, xon_xoff).
BAUD_1, 0x39, // 14,15 Serial1, bit rate, (seven bit, echo, parity none, odd, stop_bits, xon_xoff).
0, 0 // 16,17 calibration count, checksum
};
struct Parameters_t code r_Parms =
{
#if M6520 || TRACE11
513421L, // )0: 0.08A IThrshld starting current
0, // )1: Config: Configuration Register.
906156350L, // )2: 407.3V VPThresh: Peak voltage threshold.
544498635L, // )3: 50.9A IPThresh: Peak current threshold.
0x0000, // )4: Y_Cal: Crystal calibration constants.
0x0000, // )5: Y_Cal_Deg1.
0x0000, // )6: Y_Cal_Deg2.
#if WATT_SUMS
0x00, // )7: PulseWSource;
0x04, // )8: PulseRSource;
#else
0x01, // )7: PulseWSource;
0x05, // )8: PulseRSource;
#endif
6000, // )9: Vmax,
2080, // )A: Imax.
0, // )B: ppmc1, -150 is the untrimmed value
0, // )C: ppmc2, -392 is the untrimmed value
#if WATT_SUMS
0x00, // )D: Pulse3Source; for software pulse outputs
0x04, // )E: Pulse4Source; for software pulse outputs
#else
0x01, // )D: Pulse3Source; for software pulse outputs
0x05, // )E: Pulse4Source; for software pulse outputs
#endif
2, // )F: seconds of calibration.
2400, // )10: calibration voltage, LSB = 0.1V (like VMAX).
300, // )11: calibration current, LSB = 0.1A (like IMAX).
88992958L, // )12: 40V VThrshld min vlts for mainedge, phase, freq
50, // )13: 10ms pulse width
#if M6520
0x3DCC7800, // )14: temp_nom
#elif TRACE11
2025084L, // )14: temp_nom
#else
#error unknown device
#endif
2080, // )15: IMax2
513421L, // )16: 0.08A IThrshld2 starting current
0x00E54D4C // )17: 2V battery minimum, Units: ADC>>8
#elif TRACE13
433199L, // )0: 0.08A IThrshld starting current
0, // )1: Config: Configuration Register.
764569660L, // )2: 407.3V VPThresh: Peak voltage threshold.
275652520L, // )3: 50.9A IPThresh: Peak current threshold.
0x0000, // )4: Y_Cal: Crystal calibration constants.
0x0000, // )5: Y_Cal_Deg1.
0x0000, // )6: Y_Cal_Deg2.
#if WATT_SUMS
0x00, // )7: PulseWSource;
0x04, // )8: PulseRSource;
#else
0x01, // )7: PulseWSource;
0x05, // )8: PulseRSource;
#endif
6000, // )9: Vmax,
2080, // )A: Imax.
0, // )B: ppmc1, -150 is the untrimmed value
0, // )C: ppmc2, -392 is the untrimmed value
#if WATT_SUMS
0x00, // )D: Pulse3Source; for software pulse outputs
0x04, // )E: Pulse4Source; for software pulse outputs
#else
0x01, // )D: Pulse3Source; for software pulse outputs
0x05, // )E: Pulse4Source; for software pulse outputs
#endif
2, // )F: seconds of calibration.
2400, // )10: calibration voltage, LSB = 0.1V (like VMAX).
300, // )11: calibration current, LSB = 0.1A (like IMAX).
75087832L, // )12: 40V VThrshld min vlts for mainedge, phase, freq
50, // )13: 10ms pulse width
#if TRACE13
847662L, // )14: temp_nom
#else
#error unknown device
#endif
2080, // )15: IMax2
433199L, // )16: 0.08A IThrshld2 starting current
0x00E54D4C // )17: 2V battery minimum, Units: ADC>>8
#else
#error unknown device
#endif
};
/*** Public variables declared within this module ***/
#if M6520
uint8r_t copyright1[] = { "TSC 71M6521" };
uint8r_t r_demo_version[32] = { "TSC6521.4.3.4,"__DATE__ };
#elif TRACE11 // This is an experimental configuration.
uint8r_t copyright1[] = { "TRACE11" };
uint8r_t r_demo_version[32] = { "TRACE11H.4.3.4,"__DATE__ };
#elif TRACE13 // This is an experimental configuration.
uint8r_t copyright1[] = { "TRACE13" };
uint8r_t r_demo_version[32] = { "TRACE13H.4.3.4,"__DATE__ };
#else
#error unknown device type
#endif
uint8r_t copyright2[] = { " (c) 2006 Teridian Semiconductor Corp. All rights reserved" };
// This is not a fashionable design in some ways. In particular, initialization is not modularized
// because software design must serve business needs.
// To demonstrate meters and meter chips, it is very convenient to be able to set-up
// a firmware image for a customer, and then e-mail it. Therefore...
// An application engineer must be able to configure the firmware without recompiling it. Therefore...
// TSC has a PC program IOMERGE.EXE that writes changes to the defaults of the firmware. Therefore...
// The firmware default tables must remain stable under maintenance, so IOMERGE works, therefore...
// unlike most object-oriented systems, some object-level initializations
// are centralized here to keep the default tables controlled under maintenance.
void set_defaults (void)
{
int16_t baud;
// CE set-up
samples = pre_samps[ (CE1 & PRE_SAMPS) >> 6 ] * (CE1 & SUM_CYCLES);
#if M6520 && BROWNOUT_BATMODE
if (!batmode_is_brownout() )
memcpy_xr ((uint8x_t *) IO_CE, &ri_defaults[ IO_CE_IDX ], IO_CE_SIZE);
else
{ // Leave CONFIG0 at reset value (i.e. MPU_DIV = 0).
memcpy_xr ((uint8x_t *) IO_CE + 0, &ri_defaults[ IO_CE_IDX + 0 ], 4);
memcpy_xr ((uint8x_t *) IO_CE + 5, &ri_defaults[ IO_CE_IDX + 5 ], IO_CE_SIZE - 5);
}
#elif M6520 || TRACE10
memcpy_xr ((uint8x_t *) IO_CE, &ri_defaults[ IO_CE_IDX ], IO_CE_SIZE);
#else
#error unknown configuration
#endif // M6520
#if M6520
// pulse width set up
memcpy_xr ((uint8x_t *) IO_PLS, &ri_defaults[ IO_PLS_IDX ], IO_PLS_SIZE);
// CE location (resetup by ce_init(), also WAKE and TMUX defaults
memcpy_xr ((uint8x_t *) IO_CE3, &ri_defaults[ IO_CE3_IDX ], IO_CE3_SIZE);
#endif // M6520
// Trim register selection (i.e. just here to set a default for the read index)
memcpy_xr ((uint8x_t *) IO_TRIM, &ri_defaults[ IO_TRIM_IDX ], IO_TRIM_SIZE);
// RTM set up; really part of CE set-up, because it reads CE registers
memcpy_xr ((uint8x_t *) IO_RTM, &ri_defaults[ IO_RTM_IDX ], IO_RTM_SIZE);
ce_init (); // Initialize Compute Engine.
// the CE is actually started in the main initialization
// LCD set up in io\lcd.c LCD_Init(), because brownout needed a complete
// initialization of LCD, and calling this whole routine was too much.
#if LCD_ACTIVE
LCD_Init();
#endif
// totals and parameters for meter\meter.c
memcpy_xr ((uint8x_t *) &Totals.Parms, (uint8r_t *) &r_Parms, sizeof (r_Parms));
select_total = defaults[ 0 ] & 0x3F; // defines LCD output
select_phase = (defaults[ 0 ] & 0xC0) >> 6;
#if RMS_VALUES
switch(defaults[ 2 ])
{
case 1: select_total = M_IRMS; break;
case 2: select_total = M_VRMS; break;
default: break;
}
#endif
// CLI (command line interface) set up
select_flow = 0;
#if PULSE_CNT
select_pulse = 0;
#endif
#if PULSE_CNT || MAIN_EDGE_COUNT
select_interval = 0;
#endif
// serial set up
#if CLI
port = defaults[ 4 ]; // Default debug port.
#endif
#if SERIAL0
baud = defaults[BAUD0_IDX];
#if M6520
if (BATTERY_MODE_ENABLE)
baud = _RATE_300;
#endif
#if FLAG0
ser0_initialize (baud); // initialize serial interface
flag0_initialize (); // initialize flag
#elif SERIAL0_CLI
#if !SERIAL1_CLI
port = 0; // force it if it's the only one
#endif
if (port == 0)
echo = defaults[ BAUD0_IDX+1 ] & ECHO;
cli0_init (baud, defaults[ BAUD0_IDX+1 ] & XON_XOFF);
#else
ser0_initialize (baud); // initialize serial interface
#endif
#endif
#if SERIAL1
baud = defaults[BAUD1_IDX];
#if M6520
if (BATTERY_MODE_ENABLE)
baud = _RATE_300;
#endif
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -