?? ex7.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 + -