Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

multiple semaphore problem..plz help.

Status
Not open for further replies.

confusion

Junior Member level 3
Joined
Jan 6, 2012
Messages
25
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,516
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);           	
  }
}
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top