PROGRAM :-
#include "config.h"
#include "stdlib.h"
#include<LPC21xx.H>
#include<key.h>
#include<lcd.h>
OS_STK Task1Stack[100];
void Task1(void *pdata);
OS_STK Task2Stack[256];
void Task2(void *pdata);
static OS_EVENT *semaphorea;
static OS_EVENT *semaphoreb;
int main (void)
{
keyinit();
LCDInit();
lcdcmd(0x80);
LCDInit();
OSInit();
semaphorea = OSSemCreate(1); //counting semaphore ,1st semaphore
semaphoreb = OSSemCreate(1); //2nd semaphore
if(semaphorea!=NULL)
{
DisplayLCD("Sema a create",13);
}
else
{
DisplayLCD("Sema a not create",17);
}
if(semaphoreb!=NULL)
{
DisplayLCD("Sema b create",13);
}
else
{
DisplayLCD("Sema b not create",17);
}
delay();
clrscreen();
delay();
//DisplayLCD("Key: LCD:");
OSTaskCreate(Task1, (void *)0, &Task1Stack[99], 0);
OSTaskCreate(Task2, (void *)0, &Task2Stack[255], 1);
OSStart();
return 0;
}
void Task1 (void *data)
{
int n, i;
char err;
data = data;
while(1)
{
OSSemPend(semaphorea, 1, &err);
clrscreen();
DisplayLCD("task1:sem a taken",17);
for(i=0;i<900000;i++);
OSTimeDly(100);
OSSemPend(semaphoreb, 1, &err);
OSTimeDly(100);
OSSemPost(semaphorea);
OSSemPost(semaphoreb);
}
}
void Task2 (void *data)
{
int n,i;
char err;
data = data;
while(1)
{
OSSemPend(semaphoreb, 1, &err);
clrscreen();
DisplayLCD("Task2:Sem b Taken",17);
for(i=0;i<900000;i++);
OSTimeDly(100);
OSSemPend(semaphorea, 1, &err);
OSTimeDly(100);
OSSemPost(semaphoreb);
OSSemPost(semaphorea);
}
}