?? io.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 - IO Routines.
//
// AUTHOR: MTF
//
// HISTORY: See end of file
//**************************************************************************
// File: IO.C
//
// IO subroutines for use by TEST and CLI.
//
#include "options.h"
#include <ctype.h>
#include "cli.h"
#include "wd.h"
#include "io.h"
#include "library.h"
#include "main.h"
#include "sercli.h"
#include "ser0cli.h"
#include "ser1cli.h"
#include "serial.h"
#include "stm.h"
#include <ctype.h>
/*** Public variables declared within this module ***/
bool echo = 1;
#if CLI
#define TXBUFF_SIZE 128
uint8x_t txbuffer[ TXBUFF_SIZE ];
uint16x_t txlen;
bool io_timeout; // the flag read by high level protocols
/*** Private functions declared within this module ***/
//
/*** Private variables used within this module ***/
#define CLI_BUFF_SIZE 128 // 128 byte CLI buffer, no wrap;
static uint8x_t cli_buff[ CLI_BUFF_SIZE ];
static uint8r_t v_crlf[] = { CRET, LF, NULL };
// Convert ascii decimal (or hex) short to binary number.
// Used by flash commands, and the 6510's CLI commands to read the CE code space
#if FLASH || (TRACE10 && CLI)
int16_t get_short (void)
{
return ((int16_t) get_long ());
}
#endif
#if EXTRAS
// Convert ascii decimal short to binary number.
int16_t get_short_decimal (void)
{
return ((int16_t) get_long_decimal ('+'));
}
#endif
#if EXTRAS
// Convert ascii hexdecimal short to binary number.
uint16_t get_short_hex (void)
{
return ((uint16_t) get_long_hex ());
}
#endif
// Convert ascii decimal (or hex) number to binary number.
int8_t get_num (void)
{
return ((int8_t) get_long ());
}
// Convert ascii decimal number to binary number.
int8_t get_num_decimal (void)
{
return ((int8_t) get_long_decimal ('+'));
}
#if EXTRAS
// Convert ascii hexdecimal byte to binary number.
uint8_t get_num_hex (void)
{
return ((uint8_t) get_long_hex ());
}
#endif
// Convert ascii decimal (or hex) long to binary number.
int32_t get_long (void)
{
uint8_t idata c, d;
c = get_char_d (&d);
if ('+' == c || '-' == c)
return (get_long_decimal (c));
else
{
cli_index = d; // Unget last character.
return ((int32_t) get_long_hex ()); // Default to hexadecimal input.
}
}
int32_t get_long_decimal (uint8_t c)
{
bool sign;
uint8_t idata d, i;
int32_t xdata n;
i = 10; // Maximum number of digits allowed for decimal input.
n = 0; // Number to be returned.
sign = '-' == c;
while (i > 0 && (c = get_digit (&d)) < 10)
{ // Convert ASCII decimal number to binary number.
n = (n * 10) + c;
i--;
}
if (sign)
n = -n;
if (i) cli_index = d; // Unget last character, it wasn't a digit.
return (n);
}
uint32_t get_long_hex (void) // Convert ASCII hexadecimal number to binary number.
{
uint8_t idata c, d, i;
uint32_t xdata n;
i = 8; // Maximum number of digits allowed for hex input.
n = 0; // Number to be returned.
while (i > 0 && (c = get_digit (&d)) < 0x10)
{ // Convert ASCII hexadecimal number to binary number.
n = (n << 4) + c;
--i;
}
if (i) cli_index = d; // Unget last character, it wasn't a digit.
return (n);
}
// Get next decimal (or hex) digit from CLI buffer.
uint8_t get_digit (uint8_t idata *d)
{
uint8_t idata c;
if (isxdigit (c = get_char_d (d)))
{
c -= '0'; // '0' mapped to 0;
if (c >= 10)
{
c &= ~CASE_;
c -= 'A' - '0' - 10; // 'A' mapped to 10.
}
}
else
c = 0xFF;
return (c);
}
uint8_t get_char_d (uint8_t idata *d) // Get next character from CLI buffer..
{ // ..and allow unget.
*d = cli_index;
return (get_char ());
}
uint8_t get_char (void) // Get next character from CLI buffer.
{
uint8_t idata c;
c = cli_buff[ cli_index ];
if (c == '/') // the "comment" function simulates an end of line
c = '\0';
if (c != '\0')
cli_index++;
return (c);
}
void send_crlf (void) // Send <CR><LF> to UART.
{
start_tx_rslt (v_crlf);
}
void start_tx_rslt (uint8r_t *ptr) // Send ROM string out PC UART.
{
txlen = strlen_r (ptr);
memcpy_xr (txbuffer, ptr, txlen);
Serial_Tx (port, txbuffer, txlen);
}
#if EXTRAS
void start_tx_ram (uint8x_t *ptr) // Send RAM string out PC UART.
{
txlen = strlen_x (ptr);
memcpy_xx (txbuffer, ptr, txlen);
Serial_Tx (port, txbuffer, txlen);
}
#endif
void send_long (int32_t n) // Send a [0, 9,999,999,999] value to DTE.
{
send_num (n, 10);
send_char (SPACE);
}
#if TRACE10
void send_short (int16_t n) // Send a [0, 99,999] value to DTE.
{
send_num ((int32_t) n, 5);
send_char (SPACE);
}
#endif
void send_byte (int8_t n) // Send a [0, 255] value to DTE.
{
send_num ((int32_t) n, 3);
send_char (SPACE);
}
void send_num (int32_t n, uint8_t size)
{
uint8_t idata i;
uint8_t xdata d[10];
bool non_zero = FALSE;
if (n < 0)
{
send_char ('-');
n = -n;
}
for (i = 0; i < size; i++) // Compute digits in reverse order..LSD to MSD.
{
d[ size - 1 - i ] = n % 10;
n /= 10;
}
for (i = 0; i < size; i++) // Send in digits in proper order..MSD to LSD.
{
if (non_zero || d[ i ] || (i == size - 1))
{
send_digit (d[ i ]);
non_zero = TRUE;
}
}
}
void send_long_hex (uint32_t i)
{
send_hex ((uint8_t) (i >> 24));
send_hex ((uint8_t) (i >> 16));
send_hex ((uint8_t) (i >> 8));
send_hex ((uint8_t) (i));
send_char (SPACE);
}
#if TRACE10
void send_short_hex (uint16_t i)
{
send_hex ((uint8_t) (i >> 8));
send_hex ((uint8_t) (i));
send_char (SPACE);
}
#endif
void send_byte_hex (uint8_t c)
{
send_hex (c);
send_char (SPACE);
}
void send_hex (uint8_t c)
{
send_digit (c >> 4);
send_digit (c & 0x0F);
}
void send_digit (uint8_t c) // Send single ASCII hex or decimal digit to DTE.
{
send_char (htoc (c));
}
void send_char (uint8_t c)
{
uint8_t xdata cd;
cd = c;
Serial_Tx (port, &cd, 1);
}
#define CMD_BUFF_SIZE 16
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -