?? ex6.c
字號:
//
// example 6: Mail box
// descriptions: First task displays the value of byte in binary way,
// the second task sends the value to the first task in runing 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 mailbox; //Event handle
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 is output
*P_IOB_ATTRIB = 0XFFFF; //Set Port B arribute
err = SpSTaskCreate(Task1,0,t1stack+24,1); //Create first task
err = SpSTaskCreate(Task2,0,t2stack+24,2); //Create second task
mailbox = SpSMboxCreate((void*)0); //Create mailbox
SpSStart(); //Start OS kernel
}
void Task1()
{
int msg = 0;
SpSMboxPost(mailbox,&msg);
while(1) {
SpSTimeDly(128); //Delay 128 tick
msg = (msg+1)%256;
SpSMboxPost(mailbox,&msg); //Send a mail to task 2
}
}
void Task2()
{
int msg;
int * pmsg;
int err;
while(1) {
pmsg = SpSMboxPend(mailbox,0,&err); //Waiting mail
msg = *pmsg; //Copy mail to local variable
*P_IOB_BUFFER = msg; //Write mail value to prot B
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -