?? io.c
字號:
bool cmd_pending (void)
{
static uint8_t xdata len = 0;
static uint8_t xdata cb[ CMD_BUFF_SIZE + 2 ]; // Leave room for a couple of LineFeeds.
static uint8_t xdata * idata cp = cb;
bool Ok;
uint8_t idata c, i;
if (!len)
{
if (!(len = Serial_CRx (port, cb, CMD_BUFF_SIZE)))
return (Ok = FALSE);
if (echo)
{
cp = cb;
c = len;
for (i = 0; i < c; i++)
{
if (CRET == *cp || LF == *cp)
{
*cp++ = CRET; // Insert <CR>.
memcpy_xx (cp + 1, cp, len - i - 1);
*cp = LF; // Insert <LF>.
len++;
}
cp++;
}
Serial_Tx (port, cb, len);
}
cp = cb;
}
while (len)
{ // Got some bytes.
len--;
c = *cp++;
if (c >= ' ' )
{
if ((CLI_BASE == cli_index) && (',' == c))
{
while (cli_buff[ cli_index ] && cli_index < CLI_BUFF_SIZE)
cli_index++; // Find end of command.
if (cli_index < CLI_BUFF_SIZE)
{ // Found old command.
Serial_Tx (port, cli_buff, cli_index);
send_crlf ();
}
else
*cli_buff = '\0'; // Null command, just echo prompt.
cli_index = CLI_BASE; // Reset index to begining of command buffer.
return (Ok = TRUE);
}
else
put_char (&c); // Just save it.
}
if ((CRET == c) || (LF == c))
{ // Carriage Return or LineFeed.
cli_buff[ cli_index ] = '\0'; // Stuff command terminator into buff.
if (!echo)
{
Serial_Tx (port, cli_buff, cli_index);
send_crlf ();
}
else if (echo)
{
cp++; // Skip inserted CRET or LF.
len--;
}
cli_index = CLI_BASE; // Reset index to begining of command buffer.
return (Ok = TRUE);
}
else if (BS == c)
{ // Backspace.
if (CLI_BASE != cli_index)
cli_index--;
}
else if (CTRL_X == c)
cli_index = CLI_BASE; // Cancel, reset index CLI_BASE.
}
return (Ok = FALSE);
}
void put_char (uint8_t idata *c)
{
if (cli_index < CLI_BUFF_SIZE - 1)
cli_buff[ cli_index++ ] = *c; // Just save it.
else
*c = CRET; // Force termination.
}
uint8_t htoc (uint8_t c)
{
if (c > 9)
c += 'A' - 10;
else
c += '0';
return (c);
}
#pragma save
#pragma NOAREGS
static void io_timer(void) small reentrant
{
io_timeout = 1;
}
#pragma restore
// character input
uint8_t getc (void)
{
uint8_t xdata b;
uint16_t len;
uint16x_t *pstm;
pstm = stm_start(milliseconds(30000),0,io_timer);
do
{
len = Serial_CRx (port, &b, 1);
if (!len)
main_background ();
if (io_timeout)
return 0;
}
while (len == 0);
stm_stop(pstm);
io_timeout = 0;
return b;
}
// Get next hexadecimal digit.
#undef CASE_
#define CASE_ 0x20
static uint8_t rcv_digit (void)
{
uint8_t c;
do {
c = getc ();
if (io_timeout)
return 0;
} while (!isxdigit(c));
c -= '0'; // '0' mapped to 0;
if (c >= 10)
{
c &= ~CASE_;
c -= 'A' - '0' - 10; // 'A' mapped to 10.
}
return (c);
}
uint8_t rcv_hex (void) // Convert ascii hexdecimal byte to binary
{
return ((rcv_digit () << 4) | rcv_digit ());
}
/***************************************************************************
* History:
* $Log: io.c,v $
* Revision 1.29 2006/10/13 00:46:20 tvander
* Removed compile options for 6530, 6515; renamed 6511 and 6513 to trace11 and trace13; Binary verified unchanged from previous version.
*
* Revision 1.28 2006/09/09 01:08:23 gmikef
* *** empty log message ***
*
* Revision 1.27 2006/07/31 18:02:41 tvander
* Fixed CLC timeout logic's integration with the CLI
*
* Revision 1.26 2006/07/25 17:21:11 tvander
* Added io_timeout boolean.
*
* Revision 1.25 2006/07/25 00:26:34 tvander
* *** empty log message ***
*
* Revision 1.24 2006/06/24 05:27:04 tvander
* Clean build
*
* Revision 1.23 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.22 2006/06/20 20:38:03 tvander
* Fixed hang in wait for data to be sent.
*
* Revision 1.21 2006/06/15 19:56:04 tvander
* Fixed misc. serial errors.
*
* Revision 1.20 2006/06/06 03:53:51 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.19 2006/05/30 17:16:19 tvander
* Integrated new code to support the calibration loader
*
* Revision 1.18 2006/05/25 03:25:58 tvander
* Some untested adjustments for calibration loader.
* Added automatic enabling of UART2 and switching to pulse output on DIO2
*
* Revision 1.17 2006/04/06 20:57:10 tvander
* I command is the same as I0 now.
*
* Revision 1.16 2006/03/07 23:57:08 tvander
* Revised help system for accuracy.
* Revised help system for compile flags.
* Clean build
*
* Revision 1.15 2006/03/06 03:28:33 Michael T. Fischer
* More 6530 prep.
*
* Revision 1.14 2006/03/03 11:24:47 Michael T. Fischer
* Prep for 6530 LCD, etc.
*
* Revision 1.13 2006/01/16 20:11:20 tvander
* Clean Keil build, all versions
*
* Revision 1.12 2006/01/10 03:54:33 gmikef
* Added PDATA support for CE Outputs.
*
* Revision 1.10 2005/12/21 01:23:12 tvander
* 13 and 11 are different. apparently
*
* Revision 1.9 2005/11/10 22:51:31 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.8 2005/11/05 02:23:26 gmikef
* Fixed bug in XON/XOFF protocol.
* Detect and notify of out of range download data.
*
* Revision 1.7 2005/11/02 03:06:46 gmikef
* Xon/Xoff flow control working.
*
* Revision 1.6 2005/10/18 02:17:08 tvander
* Access CLI in brownout by pressing reset.
* Debugged serial 1 usage from CLI.
* Implemented scrolling display as M17
*
* Revision 1.5 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.4 2005/09/22 23:44:54 tvander
* Clean build all models and unit tests, updated copyright to be fore Teridian
*
* Revision 1.3 2005/09/12 07:47:28 tvander
* Power measurement is stable, with no creep.
* VARh measurement is stable, with no creep.
* Pulse sources work.
* Full access to MPU variables.
* Rolled date.
* Clock software works.
*
* Revision 1.2 2005/08/30 01:56:50 gmikef
* *** empty log message ***
*
* Revision 1.1 2005/08/28 02:23:57 gmikef
* *** empty log message ***
*
* Revision 1.3 2005/08/20 01:32:44 gmikef
* *** empty log message ***
*
* Revision 1.2 2005/08/19 01:04:37 gmikef
* *** empty log message ***
*
* Revision 1.1 2005/08/18 02:56:07 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 + -