📄 console.c
字号:
//#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//#include <ctype.h>
#include "Option.h"
#include "2443addr.h"
#include "System.h"
//===========================[ UART ]==============================
volatile unsigned int DebugUartCh=1;
void SelectDebugUart(unsigned int ch) // ch0 ~ ch3. added by junon 060530
{
DebugUartCh = ch;
if (ch>3) DebugUartCh = 1; // default UART channel 1
}
void InitDebugUart(unsigned int baud) // edited by junon 060530
{
int ch;
UART_REGS *pUartRegs;
// select UART function
rGPHCON &= ~((0xf<<12)|(0xf<<8)|(0xf<<4)|(0xf<<0));
rGPHCON |= ((0xa<<12)|(0xa<<8)|(0xa<<4)|(0xa<<0));
for (ch=0;ch<4;ch++)
{
pUartRegs = (UART_REGS *)(UART_REG_BASE+UART_REG_OFFSET*ch);
pUartRegs->rUlCon = 0x3; //Line control register : Normal,No parity,1 stop,8 bits
// [10] [9] [8] [7] [6] [5] [4] [3:2] [1:0]
// Clock Sel, Tx Int, Rx Int, Rx Time Out, Rx err, Loop-back, Send break, Transmit Mode, Receive Mode
// 0 1 0 , 0 1 0 0 , 01 01
// PCLK Level Pulse Disable Generate Normal Normal Interrupt or Polling
pUartRegs->rUCon = 0x245;
//pUartRegs->rUbrDiv = ((int)(PCLK/16./baud+0.5)-1); //Baud rate divisior register 0
pUartRegs->rUbrDiv = 26; //Baud rate divisior register 0
pUartRegs->rUfCon = 0x0; //UART FIFO control register, FIFO disable
pUartRegs->rUmCon = 0x0; //UART MODEM control register, AFC disable
}
}
/*
int GetIntNum( void)
{
char str[30];
char *string = str;
int base = 10;
int minus = 0;
int result = 0;
int lastIndex;
int i,j;
gets(string);
i=0; j=0;
do {
if (string[j]==0x8) {
if (i>0) i--;
} else
string[i++]=string[j];
} while(string[j++]!=0);
if(string[0]=='-') {
minus = 1;
string++;
}
if(string[0]=='0' && (string[1]=='x' || string[1]=='X')) {
base = 16;
string += 2;
}
lastIndex = strlen(string) - 1;
if(lastIndex<0)
return -1;
if(string[lastIndex]=='h' || string[lastIndex]=='H' ) {
base = 16;
string[lastIndex] = 0;
lastIndex--;
}
if(base==10) {
result = atoi(string);
result = minus ? (-1*result):result;
}
else {
for(i=0;i<=lastIndex;i++) {
if(isalpha(string[i])) {
if(isupper(string[i]))
result = (result<<4) + string[i] - 'A' + 10;
else
result = (result<<4) + string[i] - 'a' + 10;
}
else
result = (result<<4) + string[i] - '0';
}
result = minus ? (-1*result):result;
}
return result;
}
*/
unsigned int Uart_putc(unsigned int c) // edited by junon 060530
{
UART_REGS *pUartRegs;
pUartRegs = (UART_REGS *)(UART_REG_BASE+UART_REG_OFFSET*DebugUartCh);
if(c=='\n') {
while(!(pUartRegs->rUtrStat & 0x2));
pUartRegs->rUtxh = '\r';
}
while(!(pUartRegs->rUtrStat & 0x2)); //Wait until THR is empty.
pUartRegs->rUtxh = c;
return c;
}
int Uart_puts( const char *s)
{
while(*s!=0) Uart_putc( *s++);
return 0;
}
unsigned int Uart_getc(void) // edited by junon 060530
{
unsigned int chRx;
UART_REGS *pUartRegs;
pUartRegs = (UART_REGS *)(UART_REG_BASE+UART_REG_OFFSET*DebugUartCh);
while(!(pUartRegs->rUtrStat & 0x1)); //Receive data ready
chRx = pUartRegs->rUrxh;
return chRx;
}
//===========================[ BOARD LED ]================================
void Init_LED(void) // edited by junon 060522
{
// LED1,2,4,8 -> EINT4,5,6,7 = GPF4,5,6,7 in SMDK2443
rGPFCON = (rGPFCON&~(0xff<<8))|(0x55<<8); // output
rGPFUDP &= ~(0xaa<<8); // pull-up/down disable
}
void Led_Display(int data)
{
rGPFDAT = (rGPFDAT & ~(0xf<<4)) | ((data & 0xf)<<4) ;
}
//===========================[ Initializing Console ]================================
void Console(void) // edited by junon 060530
{
SelectDebugUart(1); // ch0 ~ ch3
InitDebugUart(115200);
SetResTDelay(1000); // Resolution of TDelay is 1000us=1ms
InitTDelayFunc();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -