📄 cmxbug.c
字号:
}
static void display_char(char x)
{
if (!keyflags.echo_off)
K_Bug_Putchr(x);
}
static void clear_chars_in(void)
{
in_char_ptr = keys_in_buff;
do {
*in_char_ptr++ = 0;
} while (in_char_ptr != &keys_in_buff[sizeof keys_in_buff]);
in_char_ptr = keys_in_buff;
num_chars_in = 0;
}
static void putword(word16 num) /* output a number (decimal) */
{
byte digit,suppress;
word16 divisor;
divisor = 10000;
suppress = 1;
while( !( divisor == 1 )){
digit = num / divisor;
num = num - (digit * divisor);
divisor = divisor / 10;
if( suppress && digit )
suppress = 0;
if( !suppress )
digit |= '0';
else
digit = ' ';
K_Bug_Putchr(digit);
}
K_Bug_Putchr(num+'0');
}
static void putbyte(byte num) /* output a number (decimal) */
{
byte digit,suppress;
byte divisor;
divisor = 100;
suppress = 1;
while( !( divisor == 1 )){
digit = num / divisor;
num = num - (digit * divisor);
divisor = divisor / 10;
if( suppress && digit )
suppress = 0;
if( !suppress )
digit |= '0';
else
digit = ' ';
K_Bug_Putchr(digit);
}
K_Bug_Putchr(num+'0');
}
static void putpercent(byte num,byte fill) /* output a number (decimal) */
{
byte digit,suppress;
byte divisor;
divisor = 100;
suppress = 1;
while( !( divisor == 1 )){
digit = num / divisor;
num = num - (digit * divisor);
if (divisor == 10 && fill)
suppress = 0;
divisor = divisor / 10;
if( suppress && digit )
suppress = 0;
if( !suppress )
digit |= '0';
else
continue;
K_Bug_Putchr(digit);
}
K_Bug_Putchr(num+'0');
}
static void putlong(long num) /* output a number (decimal) */
{
unsigned int digit,suppress;
long divisor;
divisor = 1000000;
suppress = 1;
while( !( divisor == 1 )){
digit = num / divisor;
num = num - (digit * divisor);
divisor = divisor / 10;
if( suppress && digit )
suppress = 0;
if( !suppress )
digit |= '0';
else
digit = ' ';
K_Bug_Putchr(digit);
}
K_Bug_Putchr((char)('0'+num));
}
static void putstg(char *s) /* display null-terminated ASCII string thru serial port */
{
while (*s)
K_Bug_Putchr(*s++);
}
static void putname(char *s) /* display null-terminated ASCII string thru serial port */
{
byte ctr;
ctr = 0;
do {
if (*s)
K_Bug_Putchr(*s++);
else
K_Bug_Putchr(' ');
} while (++ctr < 13 );
}
static void putspaces(byte num)
{
while (num--)
K_Bug_Putchr(' ');
}
static void putcrlf(void)
{
K_Bug_Putchr(0x0d);
K_Bug_Putchr(0x0a);
} /* putcrlf */
static void puthexlong(long w) /* puts out long word in hex */
{
puthexbyte((byte)(w>>24));
puthexbyte((byte)(w>>16));
K_Bug_Putchr(':');
puthexbyte((byte)(w>>8));
puthexbyte((byte)(w & 0xff));
putspaces(1);
} /* puthexlong */
static void puthexbyte(byte b) /* puts out byte in ASCII hex, to serial port */
{
K_Bug_Putchr(nibs[ b >> 4 ]);
K_Bug_Putchr(nibs[ b & 0x0F ]);
} /* puthexbyte */
static void puthexword(word16 w)
/* Put out word in hex, high byte first. */
{
puthexbyte((byte)(w>>8));
puthexbyte((byte)(w & 0xff));
putspaces(1);
} /* puthexword */
static void showstate(word16 ts)
{
if (ts & RESOURCE)
putstg("resource ");
else if (ts & WAIT)
putstg("wait ");
else if (ts & SEND_MESG)
putstg("mesg_send");
else if (ts & WAIT_MESG)
putstg("mesg_wait");
else if (ts & FLAGS)
putstg("events ");
else if (ts & IDLE)
putstg("idle ");
else if (ts & READY)
putstg("ready ");
else if (ts & RESUME)
putstg("ready++ ");
else if (ts & RUNNING)
putstg("running ");
else
putstg("no create");
} /* showstate */
static void dump_task()
{
tcbpointer tcbptr;
prompt_index = DUMP_TASK_PROMPT;
switch (func_offset) {
case 0x00: /* display 1'st prompt */
putcrlf();
prompt_out();
common_prompt();
break;
case 0x80: /* process card number prompt */
func_offset &= 0x7f;
/* if good */
/* if all, set hex_byte to 2, because of bug task */
if (!keyflags.scroll)
{
if (hex_byte == '*')
{
keyflags.loop = TRUE;
hex_byte = 1;
}
else
{
keyflags.loop = FALSE;
}
}
putcrlf();
putstg("SLOT, NAME , State (time), Trig, Pri, TSK Addr, E-Flags, E-Match\r\n");
while (1)
{
if (hex_byte <= MAX_TASKS)
{
/* MUST change to relect slot number and name */
tcbptr = &cmx_tcb[hex_byte];
/* maybe change to decimal, later */
putspaces(1);
putbyte(hex_byte); /* output task number */
putspaces(1);
if (task_name[hex_byte])
putname(task_name[hex_byte]);
else
putspaces(12);
putspaces(1);
showstate(tcbptr->tcbstate);
if (tcbptr->tcbstate & TIME)
{
putstg("(");
putword(tcbptr->tcbtimer);
putstg(")");
}
else if ((tcbptr->tcbstate & TIME_EXPIRED) && ((activetcb - cmx_tcb) != hex_byte))
{
putstg("( TIME)");
}
else
putspaces(7);
putspaces(1);
putbyte(tcbptr->trig);
putspaces(3);
putbyte(tcbptr->priority);
putstg(" 0x");
if ((sizeof(void (*)())) == 4)
puthexlong((long)(tcbptr->task_addr)); /* TCB address */
else
puthexword((word16)(tcbptr->task_addr)); /* TCB address */
putstg(" 0x");
puthexword(tcbptr->e_flags);
putstg(" 0x");
puthexword(tcbptr->e_match);
putcrlf();
}
else
{
putstg("TASK Number out of range\r\n");
keyflags.loop = FALSE;
}
if (keyflags.loop)
{
if (++hex_byte > MAX_TASKS)
{
keyflags.scroll = FALSE;
break;
}
else
{
if (hex_byte % SCROLL_SIZE == 0)
{
keyflags.scroll = TRUE;
putstg("Enter <return> to continue");
return;
}
}
}
else
{
break;
}
}
keyflags.cont = TRUE;
break;
}
}
static void dump_stack(void)
{
tcbpointer tcbptr;
prompt_index = DUMP_STACK_PROMPT;
switch (func_offset) {
case 0x00: /* display 1'st prompt */
putcrlf();
prompt_out();
common_prompt();
break;
case 0x80: /* process card number prompt */
func_offset &= 0x7f;
/* if good */
/* if all, set hex_byte to 2, because of bug task */
if (!keyflags.scroll)
{
if (hex_byte == '*')
{
keyflags.loop = TRUE;
hex_byte = 1;
}
else
{
keyflags.loop = FALSE;
}
}
putcrlf();
putstg("SLOT, NAME , STACK Addr, MAX. bytes used SO FAR \r\n");
while (1)
{
if (hex_byte <= MAX_TASKS)
{
/* MUST change to relect slot number and name */
tcbptr = &cmx_tcb[hex_byte];
/* maybe change to decimal, later */
putspaces(1);
putbyte(hex_byte); /* output task number */
putspaces(1);
if (task_name[hex_byte])
putname(task_name[hex_byte]);
else
putspaces(12);
putspaces(1);
putstg(" 0x");
if ((sizeof(char *)) == 4)
puthexlong((long)(tcbptr->stk_start)); /* TCB address */
else
puthexword((word16)(tcbptr->stk_start)); /* TCB address */
putspaces(5);
putstg("Not Implemented");
/* putword(stack_usage[hex_byte]); */
putcrlf();
}
else
{
putstg("TASK Number out of range\r\n");
keyflags.loop = FALSE;
}
if (keyflags.loop)
{
if (++hex_byte > MAX_TASKS)
{
keyflags.scroll = FALSE;
break;
}
else
{
if (hex_byte % SCROLL_SIZE == 0)
{
keyflags.scroll = TRUE;
putstg("Enter <return> to continue");
return;
}
}
}
else
{
break;
}
}
keyflags.cont = TRUE;
break;
}
}
static void dump_resource(void)
{
RESHDR *res_ptr;
RESHDR *link; /* forward wait link. */
word16 ctr;
prompt_index = DUMP_RESOURCE_PROMPT;
switch (func_offset) {
case 0x00: /* display 1'st prompt */
putcrlf();
prompt_out();
common_prompt();
break;
case 0x80: /* process card number prompt */
func_offset &= 0x7f;
if (hex_byte == '*')
{
keyflags.loop = TRUE;
hex_byte = 0;
}
else
{
keyflags.loop = FALSE;
}
putcrlf();
putstg("RES #, Owner , Task(s) Waiting, MAX. 3 shown\r\n");
while (1)
{
if (hex_byte < MAX_RESOURCES)
{
res_ptr = &res_que[hex_byte]; /* get address of resource */
link = res_dummy; /* get address of dummy resource */
/* now copy over, so we do NOT trash true resources que items. */
link->fwlink = res_ptr->fwlink;
link->bwlink = res_ptr->bwlink;
link->owner = res_ptr->owner;
/* maybe change to decimal, later */
putspaces(1);
putbyte(hex_byte); /* output task number */
putspaces(1);
if (res_ptr->owner)
{
if (task_name[res_ptr->owner - cmx_tcb])
putname(task_name[res_ptr->owner - cmx_tcb]);
else
putspaces(12);
putspaces(1);
ctr = 0;
while(1)
{
if (link->fwlink == (tcbpointer)res_ptr)
{
break;
}
if (ctr == 3)
{
putstg(", More...");
break;
}
if (ctr)
putstg(", ");
if (task_name[link->fwlink - cmx_tcb])
putname(task_name[link->fwlink - cmx_tcb]);
else
putspaces(12);
link->fwlink = link->fwlink->fwlink;
ctr++;
}
if (!ctr)
{
putstg("NONE");
}
}
else
{
putstg("NONE NONE");
}
putcrlf();
}
else
{
putstg("RESOURCE Number out of range\r\n");
keyflags.loop = FALSE;
}
if (keyflags.loop)
{
if (++hex_byte >= MAX_RESOURCES)
{
break;
}
}
else
{
break;
}
}
keyflags.cont = TRUE;
break;
}
}
static void dump_cyclic(void)
{
struct _tcproc *tpptr;
prompt_index = DUMP_CYCLIC_PROMPT;
switch (func_offset) {
case 0x00: /* display 1'st prompt */
putcrlf();
prompt_out();
common_prompt();
break;
case 0x80: /* process card number prompt */
func_offset &= 0x7f;
if (hex_byte == '*')
{
keyflags.loop = TRUE;
hex_byte = 0;
}
else
{
keyflags.loop = FALSE;
}
putcrlf();
putstg("TIMER #, Started?, Time left, CYCLIC Time, Mode , task/pri. , EVENT \r\n");
while (1)
{
if (hex_byte < MAX_CYCLIC_TIMERS)
{
tpptr = &tcproc[hex_byte];
/* maybe change to decimal, later */
putspaces(3);
putbyte(hex_byte); /* output task number */
putspaces(4);
if (tpptr->tproc_start)
putstg("YES ");
else
putstg("NO ");
putstg(" 0x");
puthexword(tpptr->tproc_timer);
putstg(" 0x");
puthexword(tpptr->reload_time);
putspaces(2);
switch(tpptr->mode) {
case 0:
putstg("Task number ");
if (task_name[tpptr->tskid_pri])
putname(task_name[tpptr->tskid_pri]);
else
putspaces(12);
break;
case 1:
putstg("Top Pri task ");
putspaces(12);
break;
case 2:
putstg("Top Pri task waiting");
putspaces(5);
break;
case 3:
putstg("ALL tasks ");
putspaces(12);
break;
case 4:
putstg("ALL tasks waiting");
putspaces(8);
break;
case 5:
putstg("Same priority");
putspaces(4);
putbyte(tpptr->tskid_pri);
putspaces(4);
break;
case 6:
putstg("Same Pri waiting");
putspaces(1);
putbyte(tpptr->tskid_pri);
putspaces(4);
break;
default:
putstg("Illegal mode ");
putspaces(12);
break;
}
putstg(" 0x");
puthexword(tpptr->event_num);
putcrlf();
}
else
{
putstg("CYCLIC Number out of range\r\n");
keyflags.loop = FALSE;
}
if (keyflags.loop)
{
if (++hex_byte >= MAX_CYCLIC_TIMERS)
{
break;
}
}
else
{
break;
}
}
keyflags.cont = TRUE;
break;
}
}
static void dump_queue(void)
{
QUEHDR *queue_ptr;
prompt_index = DUMP_QUEUES_PROMPT;
switch (func_offset) {
case 0x00: /* display 1'st prompt */
putcrlf();
prompt_out();
common_prompt();
break;
case 0x80: /* process card number prompt */
func_offset &= 0x7f;
if (hex_byte == '*')
{
keyflags.loop = TRUE;
hex_byte = 0;
}
else
{
keyflags.loop = FALSE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -