confusion
Junior Member level 3
i am attaching a code .plz tell me the flow of this code.i dont understand its working .. my doubt is 1)since task A is already pending on semaphore A,then after the OSTIMEDLY(100), there will be a context switch to task B .and in Task B, it requests to pend on semaphore b. so is it possible that the function under semaphore b which is an lcd display function will execute?? bcoz this resource that is lcd is already acquired by semaphore a. then will the function run??..plz reply asap
Code:
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);
}
}