⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 winbug.c

📁 上传一个带源代码的嵌入式实时多任务操作系统CMX
💻 C
📖 第 1 页 / 共 2 页
字号:
			{
			parse_packet();
			cmxbug_process = FALSE;
			comm_error();	/* NO error, just way to reset */
			}
		}
}

static void parse_packet(void)
cmx_reentrant {
	setup_outbuff();
	working_num = in_com_buff[WORKING_NUM_LOCATION];
	in_com_ptr = &in_com_buff[COMMAND_LOCATION];
	switch(*in_com_ptr) {
		case DUMP_TARGET:
			dump_target();
			break;
		case DUMP_TASK_SIZE:
			dump_task_size();
			break;
		case DUMP_RESOURCE_SIZE:
			dump_resource_size();
			break;
		case DUMP_MAILBOX_SIZE:
			dump_mailbox_size();
			break;
		case DUMP_CYCLIC_SIZE:
			dump_cyclic_size();
			break;
		case DUMP_QUEUE_SIZE:
			dump_queue_size();
			break;
		case DUMP_SEMAPHORE_SIZE:
#if CMX_SEMAPHORE_ENABLE == 1
			dump_semaphore_size();
#endif
			break;
		case TICK_COMPUTE:
			compute_tick_func();
			break;
		case DUMP_TASK_NAME:
			dump_task_name();
			break;
		case FREEZE:
			freeze_bug();
			break;
		case UNFREEZE:
			unfreeze_bug();
			break;
		case DUMP_TASK:
			dump_task();
			break;
		case DUMP_RESOURCES:
			dump_resource();
			break;
		case DUMP_CYCLIC:
			dump_cyclic();
			break;
		case DUMP_QUEUES:
			dump_queue();
			break;
		case DUMP_SEMAPHORE:
#if CMX_SEMAPHORE_ENABLE == 1
			dump_semaphore();
#endif
			break;
		case DUMP_MAILBOXES:
			dump_mailbox();
			break;
		case CHANGE_RTC_SCALE:
			change_rtc();
			break;
		case CHANGE_TSLICE_SCALE:
			change_tslice();
			break;
		case ENABLE_TIME_SLICING:
			tslice_on_off(1);
			break;
		case DISABLE_TIME_SLICING:
			tslice_on_off(0);
			break;
		case TIME_SLICING_STATE:
			tslice_state();
			break;
		case DELAY_TICK:
			quick_tick(1);
			break;
		case QUICK_TICK:
			quick_tick(0);
			break;
		case DELAY_NUM_FUNCS:
			function_tick(1);
			break;
		case QUICK_NUM_FUNCS:
			function_tick(0);
			break;
		case FREEZE_ACK:
			freeze_acknowledge();
			break;
		case BUG_CONNECT2:
			freeze_acknowledge();
			break;
		default:
			break;
			}
}

static void setup_outbuff(void)
cmx_reentrant {
	out_com_ptr = out_com_buff;
	*out_com_ptr++ = COMM_START1;
	*out_com_ptr++ = COMM_START2;
	out_com_ptr++;		/* bypass count */
	*out_com_ptr++ = in_com_buff[MAJOR_LOCATION];
	*out_com_ptr++ = in_com_buff[MINOR_LOCATION];
}

static void gencopy(void *src,byte count)
cmx_reentrant {
	byte *new_src;

	new_src = (byte *)src;
	do {
		*out_com_ptr++ = *new_src++;
		} while (--count);
}

static void dump_target(void)
cmx_reentrant {
	*out_com_ptr++ = CMX_SEMAPHORE_ENABLE;
	*out_com_ptr++ = MAX_TASKS;
	*out_com_ptr++ = MAX_RESOURCES;
	*out_com_ptr++ = MAX_CYCLIC_TIMERS;
	*out_com_ptr++ = MAX_MAILBOXES;
	*out_com_ptr++ = MAX_QUEUES;
	*out_com_ptr++ = RTC_SCALE;
	*out_com_ptr++ = TSLICE_SCALE;
	*out_com_ptr++ = MAX_SEMAPHORES;
	*out_com_ptr++ = MAX_DUMMY;
	*out_com_ptr++ = MAX_DUMMY;
	*out_com_ptr++ = MAX_DUMMY;
	*out_com_ptr++ = MAX_DUMMY;
	*out_com_ptr++ = MAX_DUMMY;
	*out_com_ptr++ = MAX_DUMMY;
	*out_com_ptr++ = MAX_DUMMY;
	*out_com_ptr++ = MAX_DUMMY;
	*out_com_ptr++ = MAX_DUMMY;
	*out_com_ptr++ = MAX_DUMMY;
	*out_com_ptr++ = MAX_DUMMY;
	*out_com_ptr++ = MAX_DUMMY;
	*out_com_ptr++ = MAX_DUMMY;
	*out_com_ptr++ = MAX_DUMMY;
	*out_com_ptr++ = MAX_DUMMY;
	*out_com_ptr++ = MAX_DUMMY;
	*out_com_ptr++ = MAX_DUMMY;
	*out_com_ptr++ = MAX_DUMMY;
	*out_com_ptr++ = MAX_DUMMY;
	*out_com_ptr++ = MAX_DUMMY;
	*out_com_ptr++ = MAX_DUMMY;
	*out_com_ptr++ = MAX_DUMMY;
	*out_com_ptr++ = MAX_DUMMY; 
	*out_com_ptr++ = MAX_DUMMY;
	*out_com_ptr++ = endian;
	*out_com_ptr++ = BYTE1;
	*out_com_ptr++ = BYTE2;
	*out_com_ptr++ = BYTE3;
	*out_com_ptr++ = BYTE4;
	gencopy(TARGET_NAME,21);
	gencopy(VERSION,5);
	compute_csum();
}

static void freeze_acknowledge(void)
cmx_reentrant {
	locked_out = 1;
	CMXBUG_ACTIVE = 1;
	out_com_ptr[0] = COMM_START1;
	out_com_ptr[1] = COMM_START2;
	out_com_ptr[3] = FREEZE_ACK;
	out_com_ptr[4] = 0x00;
	compute_csum();
}

static void dump_task_size(void)
cmx_reentrant {
	gencopy((void *)tcb_size, sizeof (tcb_size));
	compute_csum();
}

static void dump_resource_size(void)
cmx_reentrant {
	gencopy((void *)resource_size, sizeof (resource_size));
	compute_csum();
}

static void dump_mailbox_size(void)
cmx_reentrant {
	gencopy((void *)mailbox_size, sizeof (mailbox_size));
	compute_csum();
}

static void dump_queue_size(void)
cmx_reentrant {
	gencopy((void *)queue_size, sizeof (queue_size));
	compute_csum();
}

static void dump_cyclic_size(void)
cmx_reentrant {
	gencopy((void *)cyclic_size, sizeof (cyclic_size));
	compute_csum();
}

#if CMX_SEMAPHORE_ENABLE == 1

static void dump_semaphore_size(void)
cmx_reentrant {
	gencopy((void *)semaphore_size, sizeof (semaphore_size));
	compute_csum();
}

#endif


static void dump_task_name(void)
cmx_reentrant {
	char *src;

	if (working_num <= MAX_TASKS)
		{
		if (src = task_name[working_num])
			{
			do {
				*out_com_ptr++ = *((byte *)(src));
				} while (*src++);
			}
		else
			*out_com_ptr++ = 0;
		compute_csum();
		}
	else
		{
		*out_com_ptr++ = RANGE_ERROR;
		compute_csum();
		}
}

static void dump_task(void)
cmx_reentrant {
	tcbpointer tcbptr;

	if (working_num <= MAX_TASKS)
		{
		tcbptr = &cmx_tcb[working_num];
		gencopy(tcbptr,sizeof (struct _tcb));
		compute_csum();
		}
	else
	{
	*out_com_ptr++ = RANGE_ERROR;
	compute_csum();
	}
}

static void dump_resource(void)
cmx_reentrant {
	RESHDR *res_ptr;
	RESHDR *link;		/* forward wait link. */
    
	if (working_num < MAX_RESOURCES)
		{
		res_ptr = &res_que[working_num];	/* 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 = (tcbpointer)res_ptr;
		link->owner = res_ptr->owner;                    
		if (link->owner)
			{
			*out_com_ptr++ = (link->owner - cmx_tcb);				
			while(1)
				{
				if (link->fwlink == (tcbpointer)link->bwlink)
					break;
				*out_com_ptr++ = (link->fwlink - cmx_tcb);
				link->fwlink = link->fwlink->fwlink;				
				}
			}
		*out_com_ptr++ = 0xff;
		compute_csum();
		}
	else
		{
		*out_com_ptr++ = RANGE_ERROR;
		compute_csum();
		}
}

static void dump_cyclic(void)
cmx_reentrant {
	struct _tcproc *tpptr;

	if (working_num < MAX_CYCLIC_TIMERS)
		{
		tpptr = &tcproc[working_num];
		gencopy(tpptr,sizeof (struct _tcproc));
		compute_csum();
		}
	else
		{
		*out_com_ptr++ = RANGE_ERROR;
		compute_csum();
		}
}

static void dump_queue(void)
cmx_reentrant {
	QUEHDR *queue_ptr;

	if (working_num < MAX_QUEUES)
		{
		queue_ptr = &queue[working_num];	/* get address of proper queue handler. */
		gencopy(queue_ptr,sizeof (struct cmxqueue));
		compute_csum();
		}
	else
		{
		*out_com_ptr++ = RANGE_ERROR;
		compute_csum();
		}
}

#if CMX_SEMAPHORE_ENABLE == 1

static void dump_semaphore(void)
cmx_reentrant {
	SEM *sem_ptr;

	if (working_num <= MAX_SEMAPHORES)
		{
		sem_ptr = &sem_array[working_num];	/* CMX semaphore handler. */
		gencopy(sem_ptr,sizeof (struct semaphore));
		compute_csum();
		}
	else
	{
	*out_com_ptr++ = RANGE_ERROR;
	compute_csum();
	}
}

#endif
static void dump_mailbox(void)
cmx_reentrant {
	MAILBOX *mail_ptr;
	MSG *link;	/* scratch pointer */
	word16 ctr;

	if (working_num < MAX_MAILBOXES)
		{
		ctr = 0;
		mail_ptr = &mail_box[working_num];	/* get address of proper queue handler. */
		link = mail_ptr->first_lnk;	/* get first link. */
		while(1)
			{
			if (!link)
				break;
			link = link->link;
			ctr++;
			}
		*out_com_ptr++ = (byte)ctr;
		if (mail_ptr->waiter)	/* task waiting on this mailbox */
			{
			*out_com_ptr++ = mail_ptr->waiter - cmx_tcb;
			}
		else
			*out_com_ptr++ = 0xff;
		if (mail_ptr->task_num)
			{
			*out_com_ptr++ = mail_ptr->task_num;
			}
		else
			*out_com_ptr++ = 0xff;
		*out_com_ptr++ = (byte)(mail_ptr->event_num);
		compute_csum();
		}
	else
		{
		*out_com_ptr++ = RANGE_ERROR;
		compute_csum();
		}
}

static void quick_tick(byte tick_identifier)
cmx_reentrant {
	word16 num_ticks;

	if (tick_identifier)
		{
		num_ticks = in_com_buff[DATA_LOC1] << 8;
		num_ticks += in_com_buff[DATA_LOC2];
		}
	else
		num_ticks = 1;
	CMXBUG_ACTIVE = 0;
	locked_out = 0;
	K_Task_Wait(num_ticks);
	locked_out = 1;
	CMXBUG_ACTIVE = 1;
	setup_outbuff();
	*out_com_ptr++ = GOOD;
	compute_csum();
}

static void function_tick(byte func_identifier)
cmx_reentrant {

	if (func_identifier)
		{
		bug_step_count = in_com_buff[DATA_LOC1] << 8;
		bug_step_count += in_com_buff[DATA_LOC2];
		}
	else
		bug_step_count = 1;
	CMXBUG_ACTIVE = 0;
	locked_out = 0;
	bug_step_one = 1;
	K_Task_Wait(0);
	bug_step_one = 0;
	locked_out = 1;
	CMXBUG_ACTIVE = 1;
	setup_outbuff();
	*out_com_ptr++ = GOOD;
	compute_csum();
}


static void change_rtc(void)
cmx_reentrant {
	RTC_SCALE = working_num;
	*out_com_ptr++ = GOOD;
	compute_csum();
}

static void change_tslice(void)
cmx_reentrant {
	TSLICE_SCALE = working_num;
	*out_com_ptr++ = GOOD;
	compute_csum();
}

static void tslice_state()
cmx_reentrant {
	*out_com_ptr++ = SLICE_ON;
	compute_csum();
}

static void tslice_on_off(byte on)
cmx_reentrant {
	if (on)
		{
		if (!SLICE_ON)
			SLICE_ON = 1;
		}
	else
		{
		if (SLICE_ON)
			SLICE_ON = 0;
		}
	*out_com_ptr++ = GOOD;
	compute_csum();
}

static void compute_tick_func(void)
cmx_reentrant {
	if (bug_freeze)
		{
		if (!commflag.compute_tick)
			{
			commflag.compute_tick = TRUE;
			compute_csum();
			stat_array[cmxbug_slot] = 0;
			CMXBUG_ACTIVE = 0;
			}
		else
			{
			CMXBUG_ACTIVE = 1;
			commflag.compute_tick = FALSE;
			gencopy(&stat_array[cmxbug_slot],sizeof (long) ); 
			compute_csum();
			}
		}
}

static void freeze_bug(void)
cmx_reentrant {
	locked_out = 1;
	CMXBUG_ACTIVE = 1;
	bug_freeze = TRUE;
	*out_com_ptr++ = GOOD;
	compute_csum();
}

static void unfreeze_bug(void)
cmx_reentrant {
	CMXBUG_ACTIVE = 0;
	locked_out = 0;
	bug_freeze = FALSE;
/*	*out_com_ptr++ = GOOD; */
	compute_csum();
}

static void refresh_request(void)
cmx_reentrant {
	locked_out = 1;
	CMXBUG_ACTIVE = 1;
	out_com_ptr = out_com_buff;
	*out_com_ptr++ = COMM_START1;
	*out_com_ptr++ = COMM_START2;
	out_com_ptr++;		/* bypass count */
	*out_com_ptr++ = BUG_REFRESH;
	*out_com_ptr++ = 0x00;
	compute_csum();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -