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

📄 ex7.c

📁 51单片机上可以使用的操作系统
💻 C
字号:
//
// example 7: This program demo how to use Message queue.
// descriptions: The first task send message with front insert mode,
//               the second task receive message and display time.
// author: Taiyun Wang 
// date: 2003/2/22
///////////////////////////////////////////////////////////////////////////

#include "sposvar.h"
#include "spos.h"

int err;						//Error No
int t1stack[25];				//Task 1 stack
int t2stack[25];				//Task 2 stack
HEvent queue;					//Event handle
int *Q[5];						//Message queue array

volatile unsigned int *P_IOB_BUFFER =(unsigned int*)(0x7006);	//Port B data register
volatile unsigned int *P_IOB_DIR =(unsigned int*)(0x7007);		//Port B direction register
volatile unsigned int *P_IOB_ATTRIB = (unsigned int*)(0x7008);	//Port B attribute register

main()
{
	void Task1();
	void Task2();
	SpSInit();
	*P_IOB_DIR = 0XFFFF;                        //Set Port B output
	*P_IOB_ATTRIB = 0XFFFF;                     //Set Prot B attribute
	err = SpSTaskCreate(Task1,0,t1stack+24,1);	//Create fist task
	err = SpSTaskCreate(Task2,0,t2stack+24,2);	//Create second task
	queue = SpSQCreate((void*)Q,5);				//Create Message queue
	SpSStart();									//Start Os kernel
}
void Task1() 			                       
{
	int msg[2];
	msg[0]=0;
	msg[1]=1;
	SpSQPostFront(queue,&msg[0]);				//insert queue head
	SpSQPostFront(queue,&msg[1]);				//insert queue head
//	SpSQPost(queue,&msg[0]);					//insert queue
//	SpSQPost(queue,&msg[1]);					//insert queue
	while(1) {
		SpSTimeDly(256);						//Delay 256 tick
		msg[0] = (msg[0]+2)%256;
		msg[1] = msg[0]+1;
		SpSQPostFront(queue,&msg[0]);
		SpSQPostFront(queue,&msg[1]);
//		SpSQPost(queue,&msg[0]);
//		SpSQPost(queue,&msg[1]);
	}
}
void Task2()
{
	int msg;
	int * pmsg;
	int err;
	while(1) {
		pmsg = SpSQPend(queue,0,&err);			//Waiting first message
		msg = *pmsg;
		*P_IOB_BUFFER = msg;						//Send first message to prot B
		SpSTimeDly(128);
		pmsg = SpSQPend(queue,0,&err);			//Waiting second message
		msg = *pmsg;
		*P_IOB_BUFFER = msg;						//Send second message to prot B
		SpSTimeDly(128);
	}
}

⌨️ 快捷键说明

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