📄 ex3.c
字号:
//
// example 3: semaphore
// descriptions: The first task turned on LEDs from left to right,moved slowly until the eighth LED lighten,
// then the second task started up , it turned on LEDs from right to left,moved fleetly
// until the first LED lighten,and then the first task started up again.The program repeat endless.
// 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 sem; //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();
SpSInit(); //Initialize OS kernel
*P_IOB_DIR = 0XFFFF; //Set port B direction
*P_IOB_ATTRIB = 0XFFFF; //Set prot B attribute
err = SpSTaskCreate(Task1,0,t1stack+24,1); //Create first task
sem = SpSSemCreate(1); //Create a semaphone
SpSStart(); //Start kernel
}
void Task1() //task 1
{
void Task2();
unsigned int i = 1;
err = SpSTaskCreate(Task2,0,t2stack+24,2); //Create second task
while(1) {
SpSSemPend(sem,0); // Waiting semaphone
for(i = 1;i<0x100;i<<=1) {
*P_IOB_BUFFER = i;
SpSTimeDly(30); //Delay 30 tick
}
SpSSemPost(sem); //Release semaphone
}
}
void Task2() //task 2
{
volatile unsigned int *P_IOB_DATA = (unsigned int*)(0x7005);
unsigned int i = 0x80;
while(1) {
SpSSemPend(sem,0); //Waiting semaphone
for(i = 0x80;i != 0;i>>=1) {
*P_IOB_BUFFER = i;
SpSTimeDly(5); //Delay 5 tick
}
SpSSemPost(sem); //Release semaphone
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -