📄 consol.c
字号:
wResult=(wResult<<4)+pbString[wI]-'A'+10;
else
wResult=(wResult<<4)+pbString[wI]-'a'+10;
}
else
{
wResult=(wResult<<4)+pbString[wI]-'0';
}
}
wResult=wMinus ? (-1*wResult):wResult;
}
return wResult;
}
/*
*********************************************************************************************
* CONSOL_SendChar
*
* Description: This routine waits till the character is sent.
*
* Arguments : bData - Data to be sent.
*
* Return : none.
*
* Note(s) :
*********************************************************************************************
*/
void CONSOL_SendChar(char bData)
{
if(__bU0FifoFlag)
{
if(rU0LSR & (0x01<<5))
{
rU0THR = bData;
__bU0FifoCnt = 1;
}
else
{
if(__bU0FifoCnt < 16)
{
rU0THR = bData;
__bU0FifoCnt++;
}
else
{
while(!(rU0LSR & (0x01<<5))); //Wait until THR is empty
rU0THR = bData;
__bU0FifoCnt = 1;
}
}
}
else
{
while(!(rU0LSR & (0x01<<5))); //Wait until THR is empty
rU0THR = bData;
}
}
/*
*********************************************************************************************
* CONSOL_SendCh
*
* Description: This routine waits till the character is sent. It also sends an extra carriage
* return character when sending a new line character
*
* Arguments : bData - Data to be sent.
*
* Return : none.
*
* Note(s) :
*********************************************************************************************
*/
void CONSOL_SendCh(char bData)
{
if(bData == '\n')
{
CONSOL_SendChar('\r');
}
CONSOL_SendChar(bData);
}
/*
*********************************************************************************************
* CONSOL_SendString
*
* Description: This routine waits till the string is sent.
*
* Arguments : pbString - String to be sent.
*
* Return : none.
*
* Note(s) :
*********************************************************************************************
*/
void CONSOL_SendString(char *pbString)
{
while(*pbString)CONSOL_SendCh(*pbString++);
}
#if (INCLUDE_CONSOL1)
/*
*********************************************************************************************
* CONSOL1_SendChar
*
* Description: This routine waits till the character is sent.
*
* Arguments : bData - Data to be sent.
*
* Return : none.
*
* Note(s) :
*********************************************************************************************
*/
void CONSOL1_SendChar(char bData)
{
if(__bU1FifoFlag)
{
if(rU1LSR & (0x01<<5))
{
rU1THR = bData;
__bU1FifoCnt = 1;
}
else
{
if(__bU1FifoCnt < 16)
{
rU1THR = bData;
__bU1FifoCnt++;
}
else
{
while(!(rU1LSR & (0x01<<5))); //Wait until THR is empty
rU1THR = bData;
__bU1FifoCnt = 1;
}
}
}
else
{
while(!(rU1LSR & (0x01<<5))); //Wait until THR is empty
rU1THR = bData;
}
}
/*
*********************************************************************************************
* CONSOL1_SendCh
*
* Description: This routine waits till the character is sent. It also sends an extra carriage
* return character when sending a new line character
*
* Arguments : bData - Data to be sent.
*
* Return : none.
*
* Note(s) :
*********************************************************************************************
*/
void CONSOL1_SendCh(char bData)
{
if(bData == '\n')
{
CONSOL1_SendChar('\r');
}
CONSOL1_SendChar(bData);
}
/*
*********************************************************************************************
* CONSOL1_SendString
*
* Description: This routine waits till the string is sent.
*
* Arguments : pbString - String to be sent.
*
* Return : none.
*
* Note(s) :
*********************************************************************************************
*/
void CONSOL1_SendString(char *pbString)
{
while(*pbString)CONSOL1_SendCh(*pbString++);
}
#endif
/*
*********************************************************************************************
* CONSOL_PrintNum
*
* Description: This routine is a special printf for numbers only.
*
* Arguments : pbString - String to be sent.
*
* Return : bBase - Number base.
* bNoDigits - Number of digits printed.
* bSign - Sign flag.
* wNum - Number to print.
*
* Note(s) :
* see formatting information below
* Print the number 'n' in the given 'bBase' using exactly 'bNoDigits'
* print +/- if signed flag 'bSign' is TRUE
* use the character specified in 'bPad' to pad extra characters
*********************************************************************************************
*/
void CONSOL_PrintNum(U8 bBase, U8 bNoDigits, U8 bSign, char bPad, S32 wNum)
{
static char abHexChars[16] = "0123456789ABCDEF";
char *pbPtr, bBuf[32];
U32 wNumAbs;
U8 bCount;
// prepare negative number
if( bSign && (wNum < 0) )
{
wNumAbs = -wNum;
}
else
{
wNumAbs = wNum;
}
// setup little string buffer
bCount = (bNoDigits-1)-(bSign?1:0);
pbPtr = bBuf + sizeof (bBuf);
*--pbPtr = '\0';
// force calculation of first digit
// (to prevent zero from not printing at all!!!)
*--pbPtr = abHexChars[(wNumAbs%bBase)];
wNumAbs /= bBase;
// calculate remaining digits
while(bCount--)
{
if(wNumAbs != 0)
{
// calculate next digit
*--pbPtr = abHexChars[(wNumAbs%bBase)];
wNumAbs /= bBase;
}
else
{
// no more digits left, pad out to desired length
*--pbPtr = bPad;
}
}
// apply signed notation if requested
if( bSign )
{
if(wNum < 0)
{
*--pbPtr = '-';
}
else if(wNum > 0)
{
*--pbPtr = '+';
}
else
{
*--pbPtr = ' ';
}
}
// print the string right-justified
CONSOL_SendString(pbPtr);
}
/*
*********************************************************************************************
* CONSOL_vPrintData
*
* Description: This routine prints the hex data through the CONSOL port.
*
* Arguments : pbData - Pointer to data.
* hwLen - Data length.
*
* Return : none.
*
* Note(s) :
*********************************************************************************************
*/
void CONSOL_vPrintData(U8 *pbData, U16 hwLen)
{
CONSOL_SendString("Length: ");
CONSOL_PrintNum(10, 5, False, ' ', hwLen);
CONSOL_SendString(" bytes\n");
if(hwLen)
{
U16 hwRest = hwLen;
U16 hwOffset = 0;
while(1)
{
hwOffset = __hwPrintDataLines(pbData, hwOffset, hwRest);
hwRest = hwLen-hwOffset;
if(hwRest)
{
}
else
{
goto done;
}
}
}
done:
CONSOL_SendString("\n");
}
#if (CONSOL_VARARG == 1)
/*
*********************************************************************************************
* CONSOL_Scanf
*
* Description: Reads input from the consol stream, under control of the string pointed to by
* format that specifies the admissible input sequences and how they are to be
* converted for assignment, using subsequent arguments as pointers to the
* objects to receive the converted input. If there are insufficient arguments
* for the format, the behavior is undefined. If the format is exhausted while
* arguments remain, the excess arguments are ignored.
*
* Arguments : pcFmt - Format string. It can contain only the following format specifiers:
* %s - String.
* %c - character.
* %i - Integer.
* ... - Are the passed parameters (pointers to the objects to receive the
* converted input).
*
* Return : none.
*
* Note(s) :
*********************************************************************************************
*/
void CONSOL_Scanf(char *pcFmt,...)
{
va_list pArg;
char cChar;
int *pwInt;
char *pbChar;
va_start(pArg, pcFmt);
while((cChar=*pcFmt++) != '\0')
{
if(cChar != '%')continue;
switch(*pcFmt)
{
case 's':
case 'S':
pbChar = va_arg (pArg, char *);
CONSOL_GetString(pbChar);
break;
case 'i':
case 'I':
pwInt = va_arg (pArg, int *);
*pwInt = CONSOL_GetIntNum();
break;
case 'c':
case 'C':
pbChar = va_arg (pArg, char *);
*pbChar = CONSOL_GetCh();
break;
}
}
va_end(pArg);
}
/*
*********************************************************************************************
* CONSOL_Printf
*
* Description: Writes output to the consol stream, under control of the string pointed to by
* format that specifies how subsequent arguments are converted for output. If
* there are insufficient arguments for the format, the behavior is undefined.
* If the format is exhausted while arguments remain, the excess arguments are
* ignored.
*
* Arguments : pcFmt - Format string. It can contain all the format specifies.
* ... - Are the passed parameters (pointers to the objects to receive the
* converted input).
*
* Return : none.
*
* Note(s) :
*********************************************************************************************
*/
void CONSOL_Printf(char *pcFmt,...)
{
va_list ap;
char pbString[256];
va_start(ap,pcFmt);
vsprintf(pbString,pcFmt,ap);
CONSOL_SendString(pbString);
va_end(ap);
}
#endif /* (CONSOL_VARARG == 1) */
#endif /* (INCLUDE_CONSOL == 1) */
/* ********************************************************************* */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -