📄 winbug.c
字号:
#define CMXMODULE 1
#include <cxfuncs.h> /* get cmx include header file */
#include <cxextern.h> /* get cmx include header file */
#include <winio.h>
#define CMX_SEMAPHORE_ENABLE 1 /* Set to one, for CMX-RTX ver 5.xx */
#define RECORD_XMT_REC 0 /* Set to 1, to record transmit and receive stuff */
/* You should not have to change any of the following. */
byte VERSION[5] = {" 1.00"};
/* What services availble in this version. */
#define A_TASKS 0x01
#define A_RESOURCES 0x02
#define A_CYCLIC_TIMERS 0x04
#define A_MAILBOXES 0x08
#define A_QUEUES 0x10
#define A_RTC_SCALE 0x20
#define A_TSLICE_SCALE 0x40
#if CMX_SEMAPHORE_ENABLE == 1
#define A_SEMAPHORES 0x80
#else
#define A_SEMAPHORES 0x00
static byte MAX_SEMAPHORES = 0;
#endif
#define BYTE1 (A_TASKS|A_RESOURCES|A_CYCLIC_TIMERS|A_MAILBOXES|A_QUEUES|A_RTC_SCALE|A_TSLICE_SCALE|A_SEMAPHORES)
#define BYTE2 0
#define BYTE3 0
#define BYTE4 0
static byte cmx_code tcb_size[] = {
sizeof(tcbpointer), /* fwlink size */
sizeof(tcbpointer), /* bwlink size */
sizeof(tcbpointer), /* fwlink size */
sizeof(tcbpointer), /* bwlink size */
sizeof(word16), /* tcbstate size */
sizeof(byte), /* trigger size */
sizeof(byte), /* priority size */
sizeof(word16), /* timer size */
sizeof(tcbpointer), /* nxttcb size */
sizeof(CMX_FP), /* task_addr size */
sizeof(word16 cmx_xdata *), /* stack start size */
sizeof(word16 cmx_xdata *), /* stack save size */
sizeof(tcbpointer), /* mesg sender size */
sizeof(word16), /* event flags size */
sizeof(word16), /* event match size */
((char)&(((struct _tcb *)0)->fwlink)), /* offset position */
((char)&(((struct _tcb *)0)->bwlink)), /* offset position */
((char)&(((struct _tcb *)0)->ftlink)), /* offset position */
((char)&(((struct _tcb *)0)->btlink)), /* offset position */
((char)&(((struct _tcb *)0)->tcbstate)), /* offset position */
((char)&(((struct _tcb *)0)->trig)), /* offset position */
((char)&(((struct _tcb *)0)->priority)), /* offset position */
((char)&(((struct _tcb *)0)->tcbtimer)), /* offset position */
((char)&(((struct _tcb *)0)->nxttcb)), /* offset position */
((char)&(((struct _tcb *)0)->task_addr)), /* offset position */
((char)&(((struct _tcb *)0)->stk_start)), /* offset position */
((char)&(((struct _tcb *)0)->stk_save)), /* offset position */
((char)&(((struct _tcb *)0)->mesg_sender)), /* offset position */
((char)&(((struct _tcb *)0)->e_flags)), /* offset position */
((char)&(((struct _tcb *)0)->e_match)) /* offset position */
};
static byte cmx_code resource_size[] = {
sizeof(tcbpointer), /* fwlink size */
sizeof(tcbpointer), /* bwlink size */
sizeof(tcbpointer), /* owner size */
((char)&(((struct cmxresource *)0)->fwlink)), /* offset position */
((char)&(((struct cmxresource *)0)->bwlink)), /* offset position */
((char)&(((struct cmxresource *)0)->owner)) /* offset position */
};
static byte cmx_code mailbox_size[] = {
sizeof (MSG cmx_xdata *), /* link to message block. */
sizeof (MSG cmx_xdata *), /* link to message block. */
sizeof (tcbpointer), /* what task is waiting for message. */
sizeof (byte), /* task number for setting event bit */
sizeof (word16), /* event number */
((char)&(((struct cmxmbox *)0)->first_lnk)), /* offset position */
((char)&(((struct cmxmbox *)0)->next_lnk)), /* offset position */
((char)&(((struct cmxmbox *)0)->waiter)), /* offset position */
((char)&(((struct cmxmbox *)0)->task_num)), /* offset position */
((char)&(((struct cmxmbox *)0)->event_num)) /* offset position */
};
static byte cmx_code queue_size[] = {
sizeof (byte cmx_xdata *), /* address of user supplied memory for queue. */
sizeof (word16), /* the number of slots within this queue */
sizeof (word16), /* the number of slots used */
sizeof (byte), /* size of slots */
sizeof (signed int), /* must be signed to test for < 0 */
sizeof (signed int), /* must be signed to test for < 0 */
((char)&(((struct cmxqueue *)0)->base_ptr)), /* offset position */
((char)&(((struct cmxqueue *)0)->num_slots)), /* offset position */
((char)&(((struct cmxqueue *)0)->queue_cnt)), /* offset position */
((char)&(((struct cmxqueue *)0)->size_slot)), /* offset position */
((char)&(((struct cmxqueue *)0)->head)), /* offset position */
((char)&(((struct cmxqueue *)0)->tail)) /* offset position */
};
/* the timed procedure structure */
static byte cmx_code cyclic_size[] = {
sizeof (struct _tcproc cmx_xdata *), /* forward time link */
sizeof (struct _tcproc cmx_xdata *), /* backward time link */
sizeof (byte), /* byte indicating timed procedure stopped / started */
sizeof (word16), /* the timer counter */
sizeof (word16), /* the cyclic time that will be reloaded */
sizeof (byte), /* what mode to sent to K_Event_Signal function. */
sizeof (byte), /* task slot number or priority (may not be used). */
sizeof (word16), /* the event to set. */
((char)&(((struct _tcproc *)0)->ftlink)), /* offset position */
((char)&(((struct _tcproc *)0)->btlink)), /* offset position */
((char)&(((struct _tcproc *)0)->tproc_start)), /* offset position */
((char)&(((struct _tcproc *)0)->tproc_timer)), /* offset position */
((char)&(((struct _tcproc *)0)->reload_time)), /* offset position */
((char)&(((struct _tcproc *)0)->mode)), /* offset position */
((char)&(((struct _tcproc *)0)->tskid_pri)), /* offset position */
((char)&(((struct _tcproc *)0)->event_num)) /* offset position */
};
#if CMX_SEMAPHORE_ENABLE == 1
/* the semaphore structure */
static byte cmx_code semaphore_size[] = {
sizeof(tcbpointer), /* fwlink size */
sizeof(tcbpointer), /* bwlink size */
sizeof (word16), /* the semaphore counter */
sizeof (word16), /* the semaphore N count (maximum) */
((char)&(((struct semaphore *)0)->fwlink)), /* offset position */
((char)&(((struct semaphore *)0)->bwlink)), /* offset position */
((char)&(((struct semaphore *)0)->sem_count)), /* offset position */
((char)&(((struct semaphore *)0)->sem_n)), /* offset position */
};
#endif
#define IN_BUFF_LEN 20
#define COMMAND_LOCATION 0x00
#define MAJOR_LOCATION 0x00
#define MINOR_LOCATION 0x01
#define WORKING_NUM_LOCATION 0x02
#define DATA_LOC1 0x02
#define DATA_LOC2 0x03
#define OUT_BUFF_LEN 256+5 /* 5 = START1, start2, COUNT, CRC */
#define MAX_DUMMY 0x00
#define DUMP_TARGET 0x10
#define DUMP_TASK_SIZE 0x11
#define DUMP_RESOURCE_SIZE 0x12
#define DUMP_MAILBOX_SIZE 0x13
#define DUMP_CYCLIC_SIZE 0x14
#define DUMP_QUEUE_SIZE 0x15
#define TICK_COMPUTE 0x16
#define DUMP_SEMAPHORE_SIZE 0x17
#define DUMP_TASK_NAME 0x20
#define FREEZE 0x22
#define UNFREEZE 0x23
#define DUMP_TASK 0x30
#define DUMP_RESOURCES 0x31
#define DUMP_CYCLIC 0x32
#define DUMP_QUEUES 0x33
#define DUMP_MAILBOXES 0x34
#define CHANGE_RTC_SCALE 0x35
#define CHANGE_TSLICE_SCALE 0x36
#define ENABLE_TIME_SLICING 0x37
#define DELAY_TICK 0x38
#define QUICK_TICK 0x39
#define DISABLE_TIME_SLICING 0x3A
#define TIME_SLICING_STATE 0x3B
#define DUMP_SEMAPHORE 0x3C
#define DELAY_NUM_FUNCS 0x3D
#define QUICK_NUM_FUNCS 0x3E
#define FREEZE_ACK 0x90
#define BUG_CONNECT2 0xA0
#define BUG_REFRESH 0xA1
/* NOT IN AS OF YET, IF EVER */
/*
#define STATS 13
#define STATS_RESET 14
#define TASK_CTRL 15
#define DUMP_RAM 6
#define DUMP_STACKS 7
#define EXIT_BUG 99
*/
#define COMM_START1 'z' /* 0xAA */
#define COMM_START2 'U' /* 0x55 */
#define COMM_ERR 0x00
#define INSERT_CHAR 0x0F
#define GOOD 0x80
#define RANGE_ERROR 0x81
/* keyboard flags */
typedef struct in_commflag { /* bit structure */
bit_word16 start1:1;
bit_word16 start2:1;
bit_word16 count:1;
bit_word16 csum1:1;
bit_word16 csum2:1;
bit_word16 insert:1;
bit_word16 transmitting:1;
bit_word16 err:1;
bit_word16 compute_tick:1;
};
static struct in_commflag cmx_xdata commflag;
static byte cmx_xdata in_com_buff[IN_BUFF_LEN];
static byte cmx_xdata *in_com_ptr;
static byte cmx_xdata in_com_state;
static word16 cmx_xdata in_com_ctr;
static word16 cmx_xdata in_csum;
static word16 cmx_xdata computed_csum;
byte cmx_xdata cmxbug_slot;
static byte cmx_xdata endian;
static byte cmx_xdata *out_com_ptr;
static byte cmx_xdata out_com_buff[OUT_BUFF_LEN];
static byte cmx_xdata out_count;
static byte cmx_xdata in_char;
static word16 cmx_xdata out_csum;
static byte cmx_xdata bug_freeze;
static byte cmx_xdata bug_nodelay;
byte cmx_xdata bug_step_one;
word16 cmx_xdata bug_step_count;
static volatile byte cmx_xdata cmxbug_process;
static byte cmx_xdata working_num;
static RESHDR cmx_xdata res_dummy[1];
static byte cmx_xdata bug_refresh = FALSE;
#if RECORD_XMT_REC > 0
byte cmx_xdata testrec_buff[1000];
byte cmx_xdata *testrec_ptr;
byte cmx_xdata testxmt_buff[1000];
byte cmx_xdata *testxmt_ptr;
#endif
extern long cmx_xdata stat_array[];
extern byte cmx_xdata CMXBUG_ACTIVE;
extern byte cmx_xdata BUG_WAIT_TICKS;
extern char * cmx_xdata task_name[];
static void bug2_getchr1(void) cmx_reentrant;
static void gencopy(void *,byte) cmx_reentrant;
static byte insert_rtn(void) cmx_reentrant;
static void setup_outbuff(void) cmx_reentrant;
void cmxbug(void) cmx_reentrant;
static void parse_packet(void) cmx_reentrant;
static void dump_task(void) cmx_reentrant;
static void dump_target(void) cmx_reentrant;
static void dump_task_name(void) cmx_reentrant;
static void dump_resource(void) cmx_reentrant;
static void dump_cyclic(void) cmx_reentrant;
static void dump_queue(void) cmx_reentrant;
static void dump_mailbox(void) cmx_reentrant;
static void change_rtc(void) cmx_reentrant;
static void change_tslice(void) cmx_reentrant;
static void tslice_state(void) cmx_reentrant;
static void tslice_on_off(byte) cmx_reentrant;
static void quick_tick(byte) cmx_reentrant;
static void function_tick(byte) cmx_reentrant;
static void comm_error(void) cmx_reentrant;
static void compute_csum(void) cmx_reentrant;
static void dump_task_size(void) cmx_reentrant;
static void dump_resource_size(void) cmx_reentrant;
static void dump_mailbox_size(void) cmx_reentrant;
static void dump_queue_size(void) cmx_reentrant;
static void dump_cyclic_size(void) cmx_reentrant;
void cmxbug_activate(void) cmx_reentrant;
static void refresh_request(void) cmx_reentrant;
#if CMX_SEMAPHORE_ENABLE == 1
static void dump_semaphore(void) cmx_reentrant;
static void dump_semaphore_size(void) cmx_reentrant;
#endif
static void freeze_bug(void) cmx_reentrant;
static void unfreeze_bug(void) cmx_reentrant;
static void compute_tick_func(void) cmx_reentrant;
static byte K_Bug_Getchr1(byte *);
static void freeze_acknowledge(void) cmx_reentrant;
static byte K_Bug_Getchr1(byte *ptr)
{
TEST_REC();
}
static void bug2_getchr1(void)
cmx_reentrant {
if (K_Bug_Getchr1(&in_char))
{
#if RECORD_XMT_REC > 0
*testrec_ptr = in_char;
if (++testrec_ptr == &testrec_buff[sizeof (testrec_buff)])
testrec_ptr = testrec_buff;
#endif
if (!cmxbug_process)
{
if (in_com_state < 2 && (in_char != COMM_START1 && in_char != COMM_START2))
{
comm_error();
}
switch (in_com_state)
{
case 0:
if (in_char == COMM_START1)
{
commflag.start1 = 1;
in_com_state++;
}
else
{
comm_error();
}
break;
case 1:
if (in_char == COMM_START2)
{
commflag.start2 = 1;
in_com_state++;
}
else
{
comm_error();
}
break;
default:
if (in_com_state == 0x02)
{
if (in_char)
{
in_com_ctr = in_char;
commflag.count = 1;
in_com_state++;
}
else
{
comm_error();
}
break;
}
if (insert_rtn())
break;
if (commflag.csum2)
{
/* check csum and decide, if good continue */
in_csum |= in_char;
if (computed_csum == in_csum)
{
cmxbug_process = TRUE;
}
comm_error(); /* NO error, just way to reset */
}
else if (commflag.csum1)
{
commflag.csum2 = 1;
in_csum = in_char << 8;
}
else
{
if (in_com_ptr < &in_com_buff[IN_BUFF_LEN])
*in_com_ptr++ = in_char;
else
{
comm_error();
return;
}
computed_csum += in_char;
if (--in_com_ctr)
break;
else
commflag.csum1 = 1;
}
break;
}
}
}
}
static void compute_csum(void)
cmx_reentrant {
--out_com_ptr; /* decrement by 1, for pointing to next free */
out_com_buff[2] = out_com_ptr - &out_com_buff[2]; /* COUNT */
out_com_ptr = &out_com_buff[2];
out_csum = 0;
out_count = *out_com_ptr++;
do {
out_csum += *out_com_ptr++;
} while(--out_count);
*out_com_ptr++ = (byte)(out_csum >> 8);
*out_com_ptr++ = (byte)out_csum;
out_count = out_com_ptr - out_com_buff;
out_com_ptr = out_com_buff;
commflag.transmitting = TRUE;
XMT_PROLOGUE();
ENABLE_XMT();
while (out_count--)
{
#if RECORD_XMT_REC > 0
*testxmt_ptr = *out_com_ptr;
if (++testxmt_ptr == &testxmt_buff[sizeof (testxmt_buff)])
testxmt_ptr = testxmt_buff;
#endif
TEST_XMT();
UART_XMT();
}
/* TEST_XMT(); */
XMT_EPILOGUE();
commflag.transmitting = FALSE;
}
static byte insert_rtn(void)
cmx_reentrant {
if (commflag.insert)
{
if (in_char == COMM_START2)
{
comm_error();
return(1);
}
if (in_char == INSERT_CHAR)
{
commflag.insert = FALSE;
return(1);
}
else
commflag.insert = FALSE;
}
if (in_char == COMM_START1)
commflag.insert = TRUE;
else
commflag.insert = FALSE;
return(0);
}
static void comm_error(void)
cmx_reentrant {
in_com_state = COMM_ERR;
in_com_ctr = 0;
in_com_ptr = in_com_buff;
commflag.start1 = 0;
commflag.start2 = 0;
commflag.count = 0;
commflag.csum2 = 0;
commflag.csum1 = 0;
computed_csum = 0;
commflag.insert = FALSE;
}
void cmxbug_activate(void)
cmx_reentrant {
if (!bug_freeze)
{
bug_nodelay = 1;
}
K_Task_Wake(cmxbug_slot);
}
void cmxbug(void)
cmx_reentrant {
byte key_pressed;
#if RECORD_XMT_REC > 0
testrec_ptr = testrec_buff;
testxmt_ptr = testxmt_buff;
#endif
/* calculate if big or little endian */
in_csum = 0xAA55;
in_com_ptr = (byte cmx_xdata *)&in_csum;
if (*in_com_ptr == 0xAA)
endian = 1; /* big endian */
else
endian = 0;
comm_error();
bug_freeze = 0;
while(1)
{
if (!bug_freeze)
{
if (bug_refresh)
{
bug_refresh = FALSE;
refresh_request();
}
if(K_Bug_Getchr1(&key_pressed))
{
#if RECORD_XMT_REC > 0
*testrec_ptr = key_pressed;
if (++testrec_ptr == &testrec_buff[sizeof (testrec_buff)])
testrec_ptr = testrec_buff;
#endif
if (key_pressed == '+')
{
in_com_buff[COMMAND_LOCATION] = FREEZE_ACK;
cmxbug_process = TRUE;
bug_freeze = 1;
bug_nodelay = 0;
goto cmxbug_1;
}
}
if (!bug_nodelay)
{
K_Task_Wait(BUG_WAIT_TICKS);
}
}
else
{
bug2_getchr1();
}
cmxbug_1:
if (cmxbug_process)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -