Пример #1
0
//________________________________________________________________________________
int main(void)
{
char i;

	ConfigDevice();
#ifndef SIMULATION
	ConfigDac();
#endif
	FillTableT();
	FillTableInvDV();
	OS_Init();
	OS_Task_Create(ProcessUartMsg, &task0);
	OS_Task_Create(Pid, &task1);
	OS_Sem_Create(&UartRcMsgSem,0);

	PR2     = OS_TMR_TICK;  // timer tick = 1000 instruction cycles=0.1 ms
	T2CON   = 0x05;
	ReportStartUp();
	while (1) 
		{
		if(TMR1IF)
		{
			TMR1IF=0;
			OS_Task_Resume(&task1);
		}
		asm("CLRWDT");
		OS_Scheduler();
		}
}
Пример #2
0
unsigned char Usart3_Getc(void)
{

	while (!(UCSR3A & (1<<RXC3))){
		OS_Scheduler();
		task_delay_dec(1);
	}
	return UDR3;
}
Пример #3
0
unsigned char Usart2_Getc(void)
{

	while (!(UCSR2A & (1<<RXC2))){
		OS_Scheduler();
		task_delay_dec(1);
	}
	return UDR2;
}
Пример #4
0
void Usart3_Putc(unsigned char ch)
{

	while(!(UCSR3A & (1 << UDRE3))){   //等待发送缓冲区空
		OS_Scheduler();
		task_delay_dec(1);
	}
	UDR3 = ch;                       //发送数据
}
Пример #5
0
unsigned char Usart1_Getc(void)
{

	while (!(UCSR1A & (1<<RXC1))){
		OS_Scheduler();
		task_delay_dec(1);
	}
	return UDR1;
}
Пример #6
0
unsigned char Usart0_Getc(void)
{

    while (!(UCSR0A & (1<<RXC0))){
    	OS_Scheduler();
    	task_delay_dec(1);
	}

    return UDR0;
}
Пример #7
0
//等待消息
unsigned char task_wait_message(void)
{
	
	IntEnter();
	cur_tcb -> tstatus |= TS_MESSAGE;
	IntLeave();
	
	OS_Scheduler();
	return cur_tcb -> tmessage;
}
Пример #8
0
//解除锁定
void task_unlock(void)
{

	IntEnter();
	cur_tcb->tstatus &= ~TS_LOCK;
	IntLeave();
	
	OS_Scheduler();
	
}
Пример #9
0
//给当前进程分配延时时间片
unsigned char task_delay(unsigned char time)
{

	if(time > 0)
	{

		IntEnter();
		cur_tcb->ttime_delay = time;
		cur_tcb->tstatus = TS_DELAY;
		IntLeave();
		OS_Scheduler();

		return 1;
	}

	return 0;
}
Пример #10
0
//发送消息
unsigned char task_send_message(unsigned char priority,unsigned char message)
{

	if(priority < Tasknum){
		os_tcb *tmp_tcb;
		tmp_tcb = &tcb[priority];

		IntEnter();
		tmp_tcb -> tmessage = message;
		tmp_tcb -> tstatus &= ~TS_MESSAGE;
		IntLeave();
		OS_Scheduler();

		return 1;
	}

	return 0;
}
Пример #11
0
//唤醒进程
unsigned char task_awake(unsigned char priority)
{

	if(priority < Tasknum){

		os_tcb *tmp_tcb;
		tmp_tcb = &tcb[priority];

		IntEnter();
		tmp_tcb->tstatus &= ~TS_SUSPEND;
		IntLeave();
		OS_Scheduler();

		return 1;
	}

	return 0;
}
Пример #12
0
//进程挂起
unsigned char task_suspend(unsigned char priority)
{

	if(priority < Tasknum)
	{

		os_tcb *tmp_tcb;
		tmp_tcb = &tcb[priority];

		IntEnter();
		tmp_tcb->tstatus |= TS_SUSPEND;
		IntLeave();

		if(cur_tcb == tmp_tcb)
		{
			OS_Scheduler();
		}

		return 1;
	}

	return 0;
}
Пример #13
0
//切换当前进程
unsigned char current_task_switch()
{

	if((cur_tcb->tstatus & TS_LOCK) == 0)
	{
		unsigned char i;
		os_tcb *tmp_tcb;
		tmp_tcb = tcb;

		for(i = 0;i < Tasknum;i++,tmp_tcb++)
		{
			if(tmp_tcb->tstatus == 0)
			{
				cur_tcb = tmp_tcb;
				OS_Scheduler();
				return 1;
			}
		}

	}

	return 0;
}