📄 console.c
字号:
/*-------------------------------------------------------------------
FILE NAME:
display.c
DESCRIPTION:
this file includes display char to LCD functions.
AUTHOR:
WYF
VERSION:
2005.1122.00
COMPANY:
DATANG MICROELECTRONICS TECHNOLOGY CO,.LTD
HISTORY:
2005.1122 Creat this file
...
--------------------------------------------------------------------*/
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include "nucleus.h"
#include "ADSmx21_defs.h"
#include "drv_defs.h"
#include "drv_extr.h"
#include "command.h"
#include "console.h"
#include "..\main\main.h"
#define CMD_NON 0
#define CMD_RTN 1
#define CMD_ESC 2
#define CMD_CON 3
NU_TIMER display_timer;
NU_TASK command_tsk;
NU_HISR command_hisr;
static char stacks[2][1024];
void (*command_cb)(int);
unsigned short display_buf[DISPLAY_LINE_HEIGHT*DISPLAY_LINE_MAX][320];
unsigned short rotate_buf[240][320];
int line, totalline;
int row;
unsigned char command[2][256], *pcmd;
volatile int cmd_sel, cmd_type, processing;
int active;
extern unsigned int cpuratio, cache;
void display_TIMER(UNSIGNED id)
{
short *des;
if (active) cursor_shink();
des = (short *)rotate_buf;
if (totalline < DISPLAY_LINE_ECHO){
memcpy(des, display_buf[0], DISPLAY_LINE_HEIGHT*DISPLAY_LINE_ECHO*320*2);
}
else{
int top, left;
if (line >= (DISPLAY_LINE_ECHO-1)){
top = line - (DISPLAY_LINE_ECHO-1);
memcpy(des, display_buf[top*DISPLAY_LINE_HEIGHT], DISPLAY_LINE_HEIGHT*DISPLAY_LINE_ECHO*320*2);
}
else{
left = (DISPLAY_LINE_ECHO-1) - line;
top = DISPLAY_LINE_MAX - left;
memcpy(des, display_buf[top*DISPLAY_LINE_HEIGHT], left*DISPLAY_LINE_HEIGHT*320*2);
des += left*DISPLAY_LINE_HEIGHT*320;
memcpy(des, display_buf[0], (DISPLAY_LINE_ECHO-left)*DISPLAY_LINE_HEIGHT*320*2);
}
}
{ /* Display CPU load */
char str[32];
int i;
memset((unsigned short *)(&rotate_buf[226][0]), 0, 320*DISPLAY_LINE_HEIGHT*2);
sprintf(str,"CPU:%d%%",cpuratio);
if (cache){strcat(str," Cache:On");}
else {strcat(str," Cache:Off");}
i = 0;
while(str[i]){
display_char_12((unsigned short *)rotate_buf,10+i*6,226,str[i],0xffff);
i++;
}
}
{ /* Display time */
TDRV_RTC cur;
char str[12];
int i;
rtc_GetRealTime(&cur);
sprintf(str,"%02d:%02d:%02d",cur.hour,cur.minute,cur.second);
i = 0;
while(str[i]){
display_char_12((unsigned short *)rotate_buf,260+i*6,226,str[i],0xffff);
i++;
}
}
RGB_320x240_to_240x320((int)rotate_buf,LCDC_MAINWINDOW);
}
void display_init(void)
{
STATUS s;
memset(&display_timer,0,sizeof(NU_TIMER));
s = NU_Create_Timer(&display_timer, "rtc", display_TIMER, 1, 50, 50, NU_ENABLE_TIMER);
assert(s == NU_SUCCESS);
memset(rotate_buf,0,320*240*2);
memset(display_buf, 0, 320*DISPLAY_LINE_HEIGHT*DISPLAY_LINE_MAX*2);
totalline = 0;
line = 0;
row = 0;
}
void parse_char(char c)
{
if (c == 0x08) {/* backspace */
if (pcmd > command[cmd_sel]) pcmd--;
}
else if ((c == 0x0d)||(c == 0x0a)){ /* return */
UTXD_1 = 0x0a;
*(pcmd) = 0;
cmd_sel ^= 1;
pcmd = command[cmd_sel];
if (processing == 0){
processing = 1;
cmd_type = CMD_RTN;
}
}
else if (c == 0x1b){ /* ESC */
cmd_sel ^= 1;
pcmd = command[cmd_sel];
if (processing == 1){
processing = 0;
cmd_type = CMD_ESC;
}
}
else{
*pcmd ++ = c;
}
}
void command_input(char *str, int len)
{
unsigned char *des;
if (processing == 0){
des = command[cmd_sel];
cmd_sel ^= 1;
if (len > 255) len = 255;
memcpy(des,str,len);
if ((*(des+len-1) == 0x0d)||(*(des+len-1) == 0x0a)){
*(des+len-1) = 0;
}
else{
*(des+len) = 0;
}
printf("%s\n",des);
processing = 1;
cmd_type = CMD_RTN;
}
}
static void uart1_LISR(INT vector)
{
int r;
char c;
r = URXD_1;
if (r&0x8000){
c = r&0xff;
if (active == 0){
if (c == 'a'){active = 1;}
return;
}
UTXD_1 = c;
mputc(c);
parse_char(c);
}
}
void uart1_init(void)
{
PCCR0 |= 1;
/* Config IO */
PTE_GIUS &= ~(0xf<<12);
PTE_GPR &= ~(0xf<<12);
PTE_DDIR &= ~((1<<13)|(1<<15));
PTE_DDIR |= ((1<<12)|(1<<14));
/* Soft reset */
UTS_1 |= 1;
/* Clear auto detect baudrate complete bit */
USR2_1 |= (1<<15);
/* auto detect baud rate & receive ready int & enable uart1*/
UCR1_1 = ((1<<14)|(1<<9)|(1<<0));
/* disable RTS & no parity & 1 stop bit & 8 data bits & enable tx rx */
UCR2_1 = ((1<<14)|(1<<5)|(1<<2)|(1<<1));
/* Select input pin */
UCR3_1 = (1<<2);
/* tx level: 2 rx level : 1 */
UFCR_1 = ((2<<10)|(1<<0));
{
int i,r;
for(i=0;i<64;i++){
r = URXD_1;
UTXD_1 = r;
}
}
{
STATUS s;
void (*old)(int);
s = NU_Register_LISR(VECTOR_UART1, uart1_LISR, &old);
assert(s == NU_SUCCESS);
INTENNUM = VECTOR_UART1;
}
}
void command_HISR(void)
{
switch(cmd_type){
case CMD_RTN:
if (processing == 0){
processing = 1;
}
break;
case CMD_ESC:
if (processing == 1){
processing = 0;
mputs("^C\n");
console_active();
}
break;
default:
break;
}
}
int parse_line (char *line, char *argv[])
{
int nargs = 0;
while (nargs < CFG_MAXARGS) {
/* skip any white space */
while ((*line == ' ') || (*line == '\t')) {
++line;
}
if (*line == '\0') { /* end of line, no more args */
argv[nargs] = NULL;
return (nargs);
}
argv[nargs++] = line; /* begin of argument string */
/* find end of string */
while (*line && (*line != ' ') && (*line != '\t')) {
++line;
}
if (*line == '\0') { /* end of line, no more args */
argv[nargs] = NULL;
return (nargs);
}
*line++ = '\0'; /* terminate current arg */
}
printf ("** Too many args (max. %d) **\n", CFG_MAXARGS);
return (nargs);
}
/****************************************************************************
* returns:
* 1 - command executed, repeatable
* 0 - command executed but not repeatable, interrupted commands are
* always considered not repeatable
* -1 - not executed (unrecognized, bootd recursion or too many args)
* (If cmd is NULL or "" or longer than CFG_CBSIZE-1 it is
* considered unrecognized)
****************************************************************************
*/
int run_command (const char *cmd, int flag)
{
#define CFG_CBSIZE 256 /* Console I/O Buffer Size */
cmd_tbl_t *cmdtp;
char cmdbuf[CFG_CBSIZE]; /* working copy of cmd */
char *str = cmdbuf;
char *argv[CFG_MAXARGS + 1]; /* NULL terminated */
int argc;
if (!cmd || !*cmd || strlen(cmd) > CFG_CBSIZE - 1)
return -1; /* empty command or too long, do nothing */
strcpy (cmdbuf, cmd);
/* Extract arguments */
argc = parse_line (str, argv);
/* Look up command in command table */
if ((cmdtp = find_cmd(argv[0])) == NULL) {
printf ("Unknown command '%s' - try 'help'\n", argv[0]);
return -1; /* give up after bad command */
}
/* found - check max args */
if (argc > cmdtp->maxargs) {
printf ("Usage:\n%s\n", cmdtp->usage);
return -1;
}
/* OK - call function to do the command */
(cmdtp->cmd) (cmdtp, flag, argc, argv);
return 1;
}
void command_TSK(UNSIGNED arc, void *arv)
{
while(1){
NU_Sleep(5);
if (processing == 1){
if (cmd_type == CMD_RTN){
run_command((char *)command[cmd_sel^1],0);
if (cmd_type == CMD_ESC){
console_active();
mputs("^C\n");
}
mputs(PROMPT);
processing = 0;
cmd_type = CMD_NON;
}
}
}
}
void lcd_init(void)
{
DSCR1 &= (~(7<<22)); /* LCDC driving strength = 2mA */
PCDR1 &= (~(0x3f<<16));
PCDR1 |= (7<<16); /* PERCLK3 : 266/8 = 33.25M */
PCCR0 &= ~(1<<26); /* Disable HCLK_LCDC_EN */
PTA_GIUS = 0; /* Configure IO */
PTA_GPR = 0;
LSSAR = LCDC_MAINWINDOW; /* Screen Starting Address, 4Mb boundary */
LSR = (240<<16)+320; /* ??? Screen Size: 240x320 */
LVPWR = 120; /* virtual page width: 120 */
LCPR = 0; /* disable cursor */
LPCR = 0xFB108BC7; /* ??? set 16bpp */
LSCR = 0x00120300; /* ??? set sharp */
LHCR = 0x04000F06; /* ??? hsyn width = 12 hsyn_wait 1 = 15 hsyn_wait2 = 15 */
LVCR = 0x04000907; /* ??? vsyn width = 1 vsyn_wait 1 = 0 vsyn_wait2 = 4 */
LPCCR = 0x00A903FF; /* ??? with backlight */
LRMCR = 0; /* Disable self-refresh */
LDCR = 0x00020008; /* DMA */
LGWSAR = LCDC_GRAPHICWINDOW; /* Ghapic Window Starting Address, 4Mb boundary */
LGWSR = (240<<16)+320; /* Screen Size: 240x320 */
LGWVPWR = 120; /* virtual page width: 120 */
LGWPR = 0;
LGWCR = 0xffc0001f;
LGWDCR = 0x00020008; /* DMA */
PCCR0 |= ((1<<26)|(1<<18)); /* Enable PERCLK3 &HCLK_LCDC_EN */
MAPIO |= 0x200; /* Enable LCD */
memset((char *)LCDC_MAINWINDOW, 0, 240*320*2);
{
int i;
short *des;
des = (short *)LCDC_GRAPHICWINDOW;
for(i=0;i<240*320;i++){
*des++ = 0x001f;
}
}
}
void command_init(void (*cb)(int))
{
STATUS s;
memset(command, 0, 256);
pcmd = command[0];
cmd_sel = 0;
cmd_type = CMD_NON;
command_cb = cb;
s = NU_Create_Task(&command_tsk, "console", command_TSK, 0, NU_NULL, stacks[0], 1024, 18, 2, NU_PREEMPT, NU_START);
assert(s == NU_SUCCESS);
s = NU_Create_HISR(&command_hisr, "console", command_HISR, 2, stacks[1], 1024);
assert(s == NU_SUCCESS);
}
void console_init(void (*cb)(int))
{
lcd_init();
display_init();
uart1_init();
command_init(cb);
active = 0;
processing = 0;
}
void console_deactive(void)
{
STATUS s;
s = NU_Control_Timer(&display_timer, NU_DISABLE_TIMER);
assert(s == NU_SUCCESS);
}
void console_active(void)
{
STATUS s;
int i;
short *des;
des = (short *)LCDC_GRAPHICWINDOW;
for(i=0;i<240*320;i++){
*des++ = 0x001f;
}
s = NU_Control_Timer(&display_timer, NU_ENABLE_TIMER);
assert(s == NU_SUCCESS);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -