📄 cmd_ce.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 - Command Line Interface Routines.
//
// AUTHOR: MTF
//
// HISTORY: see end of file
//***************************************************************************
// File: CMD_CE.C
//
#include "options.h"
#if CLI && (1 == SERIAL0_CLI || 1 == SERIAL1_CLI)
#include "ce.h"
#include "stm.h"
#include "eeprom.h"
#include "irq.h"
#include "wd.h"
#include "cli.h"
#include "calibration.h"
#include "cal_ldr.h"
#include "defaults.h"
#include "io.h"
#include "lcd.h"
#include "library.h"
#include "help.h"
#include "meter.h"
#include "pcnt.h"
#include "ser0cli.h"
#include "ser1cli.h"
#include "sercli.h"
#include <ctype.h>
//#define MAX_OUTPUT 9
//#define MAX_RMS 2
//#define MAX_TOTAL 15
//#define MAX_SCROLL (MAX_TOTAL + 1)
//#define MAX_PHASE 3
//#define DATE 10
//---------------------------------------------------//
/*** Private functions declared within this module ***/
static void ce_cmd_cal (void);
static void ce_cmd_pulse (void);
static void ce_cmd_rtm (void);
/*** Private variables declared within this module ***/
// None.
//---------------------------------------------------//
void cmd_ce (void) // 'C' (C)ompute Engine controls.
{
uint8_t data c;
#if HELP
bool help = FALSE;
#endif
while (!done (&c))
{
c = toupper (c);
switch (c)
{
#if HELP
case '?':
help = TRUE;
break;
#endif
case 'E':
if (get_num ())
{
CE_ENABLE();
#ifdef WD_XFER_BUSYZ // if this watchdog is enabled
wd_create ( WD_XFER_BUSYZ );
#endif
}
else
{
CE_DISABLE();
#ifdef WD_XFER_BUSYZ // if this watchdog is enabled
wd_destroy ( WD_XFER_BUSYZ );
#endif
}
break;
case 'I':
ce_init ();
break;
#if AUTOCAL || CAL_LDR || CAL_SAVE
case 'L':
#if HELP
if (help)
{
send_help (CLHelp);
help = FALSE;
}
else
#endif
ce_cmd_cal ();
break;
#endif
#if 0
case 'M':
while (!done (&c))
{
switch (toupper (c))
{
case 'A':
meter_alt = get_num (); // Do MUX alternate sequence.
break;
case 'S': // Select MPU speed.
if (!MPU_Clk_Select (get_num ()))
start_tx_rslt ("\r\nNeed to lower Serial Rate first\r\n");
break;
}
}
break;
#endif
#if PULSE_CNT
case 'P':
#if HELP
if (help)
{
send_help (CPHelp);
help = FALSE;
}
else
#endif
ce_cmd_pulse ();
break;
#endif
case 'R':
#if HELP
if (help)
{
send_help (CRHelp);
help = FALSE;
}
else
#endif
ce_cmd_rtm ();
break;
case 'T':
#if TRACE10
CE0 = (CE0 & TMUX) | get_num ();
#elif M6520
TMUX = get_num ();
#else
#error unknown device
#endif
break;
}
}
}
// control calibration
#if AUTOCAL || CAL_LDR || CAL_SAVE
static void ce_cmd_cal (void)
{
uint8_t data c;
while (!done (&c))
{
c = toupper (c);
switch (c)
{
#if AUTOCAL
case 'B':
cal_begin(); // start a calibration.
break;
#endif
#if CAL_LDR
case 'C':
cal_ldr(); // load a calibration by the serial port.
break;
#endif
#if CAL_SAVE
case 'S':
if (CE0 & CE_EN)
{
start_tx_rslt ("Save failed; turn CE off.");
send_crlf ();
}
else
{
cal_save(); // save a calibration to EEPROM.
}
break;
case 'R':
// restore a calibration from EEPROM
if (!(CE0 & CE_EN) && cal_restore())
break; // if it worked, fine
start_tx_rslt ("Restore failed; turn CE off, or bad checksum.");
send_crlf ();
break;
#endif
case 'D':
stm_wait ( milliseconds(300) ); // let the typing echo
EA = 0;
set_defaults(); // if it fails, use the defaults.
CE_ENABLE(); // meter already set up, start CE.
EA = 1;
break;
}
}
}
#endif
#if PULSE_CNT
static void ce_cmd_pulse (void)
{
uint8_t data c;
while (!done (&c))
{
c = toupper (c);
irq_disable (); // Begin critical RTC section.
switch (c)
{
case 'C':
pcnt_w_mod = pcnt_r_mod = 0;
#if PULSE_SOFT
pcnt_3_mod = pcnt_4_mod = 0;
#endif
break;
}
irq_enable (); // End critical RTC section.
}
}
#endif
static void ce_cmd_rtm (void)
{
uint8_t data c;
while (!done (&c))
{
c = toupper (c);
switch (c)
{
case 'E':
if (get_num ())
CE2 |= RTM_EN;
else
CE2 &= ~RTM_EN;
break;
case 'S':
RTM[0] = get_num ();
done (&c); // Skip delimiter.
RTM[1] = get_num ();
done (&c); // Skip delimiter.
RTM[2] = get_num ();
done (&c); // Skip delimiter.
RTM[3] = get_num ();
break;
}
}
}
/***************************************************************************
* History:
* $Log: cmd_ce.c,v $
* Revision 1.22 2006/10/13 00:46:19 tvander
* Removed compile options for 6530, 6515; renamed 6511 and 6513 to trace11 and trace13; Binary verified unchanged from previous version.
*
* Revision 1.21 2006/03/10 00:12:21 tvander
* Removed unused pulse counting variables.
*
* Revision 1.20 2006/09/29 08:51:56 tvander
* EEPROM operations are locked out when the CE is running.
*
* Revision 1.19 2006/09/09 01:08:11 gmikef
* *** empty log message ***
*
* Revision 1.18 2006/07/08 01:55:59 tvander
* Fixed problem in which CE0 caused a watchdog reset. It was because
* the wd_destroy command was never called.
*
* Revision 1.17 2006/06/23 21:09:15 tvander
* Added Z1 to test watchdog, and Z2 to test reset logic.
*
* Revision 1.16 2006/06/23 20:46:04 tvander
* Removed wait-for-io; it slowed response in brownout mode, and caused
* hangs. The cure was definitely worse than the disease: a few clobbered characters after certain commands.
*
* Revision 1.15 2006/06/15 19:56:03 tvander
* Fixed misc. serial errors.
*
* Revision 1.14 2006/06/08 18:24:22 tvander
* Fix ce0, ce1 to not cause a watchdog reset.
* FIxed CLD to restart correctly
*
* Revision 1.13 2006/06/06 03:53:50 tvander
* Added calibration count to access.c
* Added to help files, at least, they compile for a 6513.
* io.c support the calibration loader.
* ser0cli.c and ser1cli.c were allocating too many timers. Fixed.
*
* Revision 1.12 2006/05/30 17:14:51 tvander
* Integrated calibration loader
*
* Revision 1.11 2006/03/07 23:57:07 tvander
* Revised help system for accuracy.
* Revised help system for compile flags.
* Clean build
*
* Revision 1.10 2006/03/06 03:28:05 Michael T. Fischer
* More 6530 prep.
*
* Revision 1.9 2006/03/03 11:24:29 Michael T. Fischer
* Prep for 6530 LCD, etc.
*
* Revision 1.8 2006/02/10 00:51:41 tvander
* Made pulse count clearing optional.
*
* Revision 1.7 2006/02/08 03:43:16 tvander
* Made "import" the default power measurement mode, rather than net-metering
*
* Revision 1.6 2006/01/04 04:47:49 gmikef
* Switched RMS and VA calculations to use floating point. (and Calibration).
*
* Revision 1.4 2005/10/08 04:41:17 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.3 2005/08/31 05:51:41 gmikef
* First version w/ LAPIE interface.
*
* Revision 1.2 2005/08/30 01:56:17 gmikef
* *** empty log message ***
*
* Revision 1.1 2005/08/28 02:22:13 gmikef
* *** empty log message ***
*
* Revision 1.4 2005/08/20 01:32:43 gmikef
* *** empty log message ***
*
* Revision 1.3 2005/08/19 01:04:36 gmikef
* *** empty log message ***
*
* Revision 1.2 2005/08/18 17:38:53 gmikef
* *** empty log message ***
*
* Revision 1.1 2005/08/18 02:56:06 gmikef
* *** empty log message ***
*
*
* 2005 August 17; 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. *
***************************************************************************/
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -