📄 pollio.c
字号:
/********************************************************************/
/* */
/* Polled I/O Program for SNDS100 */
/* */
/*------------------------------------------------------------------*/
/* Copyright (C) 1997 Samsung Electronics. */
/*------------------------------------------------------------------*/
/* */
/* Modified, programmed by qorrha (Jong H. BAIK) */
/* */
/********************************************************************/
/*************************************************************************/
/* */
/* FILE NAME VERSION */
/* */
/* hwinit.c KS32C5000, KS32C50100 : version 1.0 */
/* */
/* COMPONENT */
/* */
/* InitInterrupt(); //Interrupt mode & vector table initialized */
/* Rtc_init() ; //Timer0 used for Rtc clock tick */
/* */
/* */
/* DESCRIPTION */
/* */
/* */
/* AUTHOR */
/* */
/* Young Sun KIM, Samsung Electronics, Inc. */
/* */
/* DATA STRUCTURES */
/* */
/* */
/* FUNCTIONS */
/* */
/* SNDS board initializing routine */
/* */
/* DEPENDENCIES */
/* */
/* */
/* HISTORY */
/* */
/* NAME DATE REMARKS */
/* */
/* 1997-05-12 first edited */
/* 1997-06-19 modified for KS32C5000 */
/* 1999-01-04 modified for KS32C50100 */
/* */
/*************************************************************************/
#include <stdarg.h>
#include "include\apdialog.h"
#include "include\uart.h"
#include "include\pollio.h"
#include "include\sysconf.h"
static UCHAR read_num(char *,UCHAR , ULONG *);
static void strout(FORMAT *,UCHAR *,long);
static char *percent(char *, FORMAT *, va_list *);
void copy(void *dstp, void *srcp, long count);
/*---------------------------------------------------------------------*/
/* Input buffer */
/*---------------------------------------------------------------------*/
char inp_buff[INP_LEN]; /* Input buffer */
unsigned char inp_cnt; /* # of chars currently in buffer */
/***********************************************************************/
/* copy: Copy memory */
/* */
/* INPUTS: dstp = pointer to destination */
/* srcp = pointer to source */
/* count = number of bytes to copy */
/* */
/***********************************************************************/
void copy(void *dstp, void *srcp, long count)
{
char *dst, *src;
dst = (char *)dstp;
src = (char *)srcp;
while (count--)
*dst++ = *src++;
}
/***********************************************************************/
/* getch: Get a character from console, waiting if necessary */
/* */
/* RETURNS: Value of character */
/* NOTES: 1. Handles backspaces */
/* 2. Doesn't echo characters or update the input buffer */
/* (unless character is backspace) */
/* */
/***********************************************************************/
UCHAR getch(void)
{
UCHAR c;
for (;;)
{
/*-----------------------------------------------------------------*/
/* Get a character when it is typed in. Translate linefeed to CR. */
/*-----------------------------------------------------------------*/
while (SerialPollConsts(0) == 0);
c = SerialPollConin() & 0x7F;
if (c == NL) c = CR;
/*-----------------------------------------------------------------*/
/* Handle backspace */
/*-----------------------------------------------------------------*/
if ((c == BSP) || (c == RUBOUT))
{
if (inp_cnt > 0)
{
Print("\b \b");
inp_cnt--;
}
}
/*-----------------------------------------------------------------*/
/* Don't allow the input buffer to overflow. */
/*-----------------------------------------------------------------*/
else if (inp_cnt >= INP_LEN)
SerialPollConout(7);
/*-----------------------------------------------------------------*/
/* Skip control characters (other than backspace and CR) */
/*-----------------------------------------------------------------*/
else if ((c <= CTRLZ) && (c != CR))
continue;
/*-----------------------------------------------------------------*/
/* Otherwise just return the character */
/*-----------------------------------------------------------------*/
else
return c;
}
}
/***********************************************************************/
/* getchar: Get a character from console, no waiting */
/* */
/* RETURNS: Value of character */
/* NOTES: 1. Didn't Handles backspaces */
/* 2. Doesn't echo characters or update the input buffer */
/* (unless character is backspace) */
/* */
/***********************************************************************/
UCHAR get_ch(U32 cur_pos)
{
UCHAR c;
for (;;)
{
/*-----------------------------------------------------------------*/
/* Get a character when it is typed in. Translate linefeed to CR. */
/*-----------------------------------------------------------------*/
while (SerialPollConsts(0) == 0);
c = SerialPollConin() & 0x7F;
if (c == NL) c = CR;
/*-----------------------------------------------------------------*/
/* Only Send backspace */
/*-----------------------------------------------------------------*/
if (c == BSP)
{
if (cur_pos > 0)
{
//Print("\b \b");
put_byte(' ');
put_byte('\b');
}
return c;
}
else if (c == RUBOUT)
{
if (cur_pos > 0)
{
Print("\b ");
}
}
/*-----------------------------------------------------------------*/
/* Don't allow the input buffer to overflow. */
/*-----------------------------------------------------------------*/
else if (cur_pos >= INP_LEN)
SerialPollConout(7);
/*-----------------------------------------------------------------*/
/* Skip control characters (other than backspace and CR) */
/*-----------------------------------------------------------------*/
//else if ((c <= CTRLZ) && (c != CR))
// continue;
/*-----------------------------------------------------------------*/
/* Otherwise just return the character */
/*-----------------------------------------------------------------*/
else
return c;
}
}
/***********************************************************************/
/* get_line: Get a line of input */
/* */
/* OUTPUTS: inp_buff[] and inp_cnt are updated */
/* */
/***********************************************************************/
static void get_line(void)
{
UCHAR c;
inp_cnt = 0;
while ((c = getch()) != CR)
{
inp_buff[inp_cnt++] = c;
// SerialPollConout(c);
}
inp_buff[inp_cnt] = 0;
SerialPollConout('\n');
SerialPollConout('\r');
}
/***********************************************************************/
/* read_string: Read a string from the input */
/* */
/* RETURNS: number of characters in the string */
/* OUTPUTS: *dest_ptr contains the null-terminated string. */
/* */
/***********************************************************************/
UCHAR read_string(char *dest_ptr)
{
char *src_ptr, count;
get_line();
count = 0;
src_ptr = inp_buff;
while ((*dest_ptr++ = *src_ptr++) != 0)
count++;
return count;
}
/***********************************************************************/
/* read_number: Read a number from the input */
/* */
/* RETURNS: number */
/* */
/***********************************************************************/
ULONG get_number(void)
{
char num[10];
ULONG number;
read_string(num);
read_num(num,10,&number);
return number;
}
/***********************************************************************/
/* read_num: Interpret a string as a number */
/* */
/* INPUTS: base = 10 or 16 */
/* OUTPUTS: *val_ptr = New value (if function returns TRUE) */
/* */
/* RETURNS: TRUE if a new number was entered. */
/* NOTES: Allows leading $ or 0x if base is 16. Number string */
/* is delimited by a null or a space. */
/* */
/***********************************************************************/
static UCHAR read_num(char *ptr, UCHAR base, ULONG *val_ptr)
{
ULONG value;
UCHAR c, hex;
//dbg_out("\n You input the number : %s \n",ptr);
value = 0;
while (*ptr == ' ') ptr++; /* Skip leading spaces */
hex = (base == 16);
if (*ptr == 0) return 0;
/*---------------------------------------------------------------------*/
/* If hex, allow leading $ or 0x. */
/*---------------------------------------------------------------------*/
if (hex)
{
if (*ptr == '$')
ptr++;
else if ((*ptr == '0') && ((ptr[1] == 'x') || (ptr[1] == 'X')))
ptr = ptr + 2;
}
/*---------------------------------------------------------------------*/
/* Run through the string, adding the value represented by each */
/* character to the total. */
/*---------------------------------------------------------------------*/
while (*ptr)
{
c = *ptr++;
if ((c >= '0') && (c <= '9'))
c -= '0';
else if (hex && (c >= 'A') && (c <= 'F'))
c = c - 'A' + 10;
else if (hex && (c >= 'a') && (c <= 'f'))
c = c - 'a' + 10;
else
{
Print("Invalid number\a\n");
return 0;
}
if (hex)
value = (value << 4) + c;
else
value = value * 10 + c;
}
*val_ptr = value;
return 1;
}
/***********************************************************************/
/* Prompt: Display the current value of a parameter, and allow */
/* user to change it. */
/* */
/* INPUTS: string = ptr to descriptive string */
/* ptype = type of parameter (DECIMAL, ULONG */
/* HEX, ULONG */
/* FLAG, UCHAR */
/* CHAR, UCHAR */
/* STRING, UCHAR[] */
/* IP) ULONG */
/* parm_ptr = ptr to parameter value */
/* */
/* OUTPUTS: *parm_ptr contains updated value of parameter */
/* */
/***********************************************************************/
void Prompt(char *string, PARM_TYPE ptype, void *parm_ptr)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -