Problem with Pico]OS function 'posTimerSet' on ATmega32

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

Currently playing around a bit with the Pico]OS RTOS on a ATmega32. To try out the use of timers I've started a task which is triggered by a simple semaphore which in turn is sent by the trigger-funtion used; posTimerSet.

A bit simplified... task1 (blinkTimerTask) blinks a LED and task2 (digOutTask) blinks a LED but is triggered by a timer which is run in task1. The delayfunctions are OK, but when it comes to the triggered semaphore it seems to come a lot more frequent than specified, specified value is 750ms but I measure 2.5V on the output which means it's switching really fast.

In fact, changes to the function-call (posTimerSet) doesn't seem to alter the behavior at all. Anybody got a clue as to why the triggering semaphore isn't every 750ms as specified? Does anything specific need to be set in the cfg files, apart from the defines which includes the function in the compilation process.

Cheers, Gert

static void blinkTimerTask(void* arg)
{
	int8_t toggleLED=0;

	(void) arg;

	for (;;)
	{
		posSemaGet(blinkTimerSem_g);
							
		if(toggleLED==0)
		{
			cbi(PORTD, WKL);			// switch on ERR LED
			toggleLED=1;
		}
		else
		{
			sbi(PORTD, WKL);			// Switch off ERR LED
			toggleLED=0;
		}
	}
}



static void digOutTask(void *arg)
{
	int8_t toggleELED=0;
	
	POSTASK_t  self;
	POSTIMER_t blinkTimer;
	VAR_t      curprio;

	(void) arg;	

	/* get handle and priority of current task */
	self    = posTaskGetCurrent();

	/* try to increase current priority */
	posTaskSetPriority(self, 20);
	curprio = posTaskGetPriority(self);		
	
	startTask(blinkTimerTask, NULL, curprio);
	blinkTimer = posTimerCreate();
	if (blinkTimer != NULL)
	{	
		posTimerSet(blinkTimer, blinkTimerSem_g,MS(750000),MS(750000));
		posTimerStart(blinkTimer);	/* Start the timer */
	}
	
	for (;;)
	{		
		if(toggleELED==0)
		{ 
			cbi(PORTD, ERL);			// switch on LED
			toggleELED=1;
		}
		else
		{
			sbi(PORTD, ERL);			// Switch off LED
			toggleELED=0;
		}
		
		posTaskSleep(MS(1000));					
	}
}



  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi again,

Solved the problem!

Before using a semaphore you not anly need to declare it, but you need to allocate it as well. The following code will take care of that. For further info I refer to the examples supplied with the distribution.

Not that big of a deal, but very easy to miss - "sowieso".

Regards

Gert

[code]
blinkTimerSem_g = posSemaCreate(0);