console.c
来自「三星S3C2460 USB DEVICE /USB HOST 监控代码」· C语言 代码 · 共 89 行
C
89 行
#include <stdio.h>
#include "Option.h"
#include "2460lib.h"
#if !SEMIHOSTING
#pragma import(__use_no_semihosting_swi)
struct __FILE { int handle; /* Add whatever you need here */};
FILE __stdout;
FILE __stdin;
FILE __stderr;
//NOTE.
//1. If __FILE is redefined by user, the fgetc(),fputc(),ferror(),defined by user,are used.
//2. __stdout,__stdin should be redefined .
// If the semihosting is not used,
// redefine fputc(),fgetc(),ferror() for printf/scanf through UART
int fputc(int ch, FILE *f)
{
/* Place your implementation of fputc here */
/* e.g. write a character to a UART, or to the debugger console with SWI WriteC */
Uart_putc(ch);
return ch;
}
int ferror(FILE *f)
{ /* Your implementation of ferror */
return EOF;
}
int fgetc(FILE *f)
{
int ch;
ch=Uart_getc();
Uart_putc(ch);
switch(ch){
case 0xd : ch=0xa;
break;
case '\b' : Uart_putc(' ');
Uart_putc('\b');
break;
}
return ch;
}
char *gets( char *s)
{
int c;
int i=0;
while((c = getchar())!=0xa) {
if(c=='\b') {
if (i>0) i--;
} else {
s[i++]=(char)c;
}
}
s[i]='\0';
return s;
}
void _ttywrch(int ch)
{
Uart_putc(ch);
}
void _sys_exit(int return_code)
{
while(1);
}
#endif //!SEMIHOSTING
void Init_LogicalConsole( void)
{
#if !SEMIHOSTING
Uart_Init(0,115200);
#else
setbuf(stdin,NULL);
#endif
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?