Jump to content
Sign in to follow this  
Antonio Pires

Novo Rtos Not Multitasking

Recommended Posts

Can somebody tell me why this code does not multitask:

 

#include <system.h>
#include <stdlib.h>
#include <novocfg_pic16t3e5ts1.h>
#include <novo.h>
#include "cpucfg.h"
#include "I2Cslv.h"
#include "soldrv.h"

...

// Novo RTOS tasks - high priority task first

#define hTask0	0	// Scheduler
#define hTask1	1	// Battery Task
#define hTask2	2	// Test


// Task priorities

#define HI_PRIO 2

// Novo RTOS Semaphores

#define hI2CCmdRcvd	0	// I2C semaphore
#define hSerPktRdy  1	// Serial semaphore
#ifdef TESTMODE
#define hTestRun	3	// Test
#endif

...

void Task0(void)
{
unsigned char ch;

while (1)
{
	Sys_WaitSemaphore(hI2CCmdRcvd, EVENT_NO_TIMEOUT);
	switch ( ch=I2C_GetCmd(0))
	{
		// Solenoids

		case 1:
		case 2:
		case 3:
		case 4:
		case 5:
		case 6: unsigned char mode=I2C_GetCmd(1); activateSolenoid(ch,mode);
				break;

		// Digital Inputs

		case 7: readInputs();
				break;

		// Initiate Bat Msg decoding
#ifdef USE_BATTERY
		case 8: Initialise();
				serEnable();
				startBatdecode();	
				break;

		// Read Battery status

		case 9: getBatStatus();
				break;
#endif
		// Test Solenoids

		case 11:
		case 12:
		case 13:
		case 14:
		case 15:
		case 16: testSolenoids(ch-10); 
				 break;


		// Healthy msg

		case 20: I2C_SendDataByte(FLAG,'O');			 
				 break;

		default: break;
	}
	Sys_Yield();
}
}

void Task1(void)
{
while (1)
{
#ifdef USE_BATTERY
	Sys_WaitSemaphore(hSerPktRdy, EVENT_NO_TIMEOUT);
	Power = decode("ower:");
	Volts = decode("Voltage:");
	Current = Power / (Volts/10);
	Charge = decode("Avg Charge:");
	Sys_Sleep(50);//Sleep 500 ms
	Initialise();
	Sys_Yield();
#else
	Sys_Sleep(200);// Sleep 2 segs
	Sys_Yield();
#endif
}
}

void Task2(void)
{
while (1)
{
#ifdef TESTMODE
	Sys_WaitSemaphore(hTestRun, EVENT_NO_TIMEOUT);
	porta = 0x0F;
	Sys_Sleep(50);
	porta = 0x00;
	Sys_Sleep(50)
#else
	Sys_Sleep(200);
#endif
	Sys_Yield();
}
}

void main(void)
{
#ifdef TESTMODE
unsigned char i;
#endif

InitHW();
SysInit();
SysCreateTask(hTask0,HI_PRIO,Task0);// Scheduler task
SysCreateTask(hTask1,HI_PRIO,Task1);// Battery task
SysCreateTask(hTask2,HI_PRIO,Task2);


SysStartTask(hTask0);
SysStartTask(hTask1);
SysStartTask(hTask2);

#ifdef TESTMODE
for (i = 0; i < 10; i++)
{
	SysSignalSemaphore(hTestRun);
}
#endif
// Background Task


while (1)
{

	if(!isWDTdis())
	{
		clear_wdt();
	}
	Sys_Yield();
}
}

 

 

The code has 3 tasks. When initially running, task2 should run during around 10 secs until the semaphore reaches zero, while task0 and task1 should be blocked waiting for a semaphore.

The code compiles well, I use MPLAB IDE v8.30, BoostC v6.95 and boostlink 6.95.

I use the -swcs in the boostlink.

 

I've tryied everything.........I'm stucked!

 

Thanks

 

A. Pires

Share this post


Link to post
Share on other sites

In all your tasks you wait for different semaphores but there is no code that signals them. Your tasks must be stuck waiting for these semaphores that never get signalled.

 

Regards,

Pavel

Share this post


Link to post
Share on other sites
In all your tasks you wait for different semaphores but there is no code that signals them. Your tasks must be stuck waiting for these semaphores that never get signalled.

 

Regards,

Pavel

Sorry but that is not true.

 

1. For Task2 I initialise the hTestRun semaphore in the main(). I incremented 10 times this semaphore in order for Task 2 to run 10 iteractions.

2. Both semaphores hI2CCmdRcvd and hSerPktRdy are signaled in interrupt routines. After power up, only Task2 should run because there are no activity in the I2C bus neither in the RS232 link.

 

Please find below the the code built in the interrupt vector.

 

For the I2C (only an extract)

===================

 

.......

 

//---------------------------------------------------------------------

// STATE 5: A NACK from the master device is used to indicate that a

// complete transmission has occurred. The clearing of the

// WDT is reenabled in the main loop at this time.

//---------------------------------------------------------------------

 

else if(stat_da && !stat_rw && !stat_bf) {

 

slv_stat.wdtdis = 0;

clear_wdt();

LED_0 = OFF;

slv_stat.cmdrcvd = 1;

SysSignalSemaphoreIsr(hI2CCmdRcvd);

}

 

else;

}

 

............

 

For the RS232

==========

 

void getpkt(void)

{

switch (state)

{

case PKT_WAIT_START: if (NewChar == 'P')

{

sptr = &batstr[0];

state++;

}

break;

 

case PKT_WAIT_DATA: if (NewChar != '%')

{

*sptr++ = NewChar;

}

else

{

*sptr=0;

state = PKT_COMPLETE;

}

break;

 

case PKT_COMPLETE: SysSignalSemaphoreIsr(hSerPktRdy);

break;

 

default: state = PKT_WAIT_START;

break;

}

 

}

 

I realy do not understand what is happening. I followed all the correct procedures.

 

Thanks.

 

A. Pires

Share this post


Link to post
Share on other sites
In all your tasks you wait for different semaphores but there is no code that signals them. Your tasks must be stuck waiting for these semaphores that never get signalled.

 

Regards,

Pavel

 

Dear all,

 

Problem fixed...

 

The problem was no related to the rtos but with a directive:

 

Task2 code is dependent of the TEST_MODE directive. This directive was mispelled in the code as TESTMODE. In this way the code was never generated and off course no task could run.

 

thanks

A. Pires

Share this post


Link to post
Share on other sites
In all your tasks you wait for different semaphores but there is no code that signals them. Your tasks must be stuck waiting for these semaphores that never get signalled.

Sorry but that is not true.

 

1. For Task2 I initialise the hTestRun semaphore in the main(). I incremented 10 times this semaphore in order for Task 2 to run 10 iteractions.

...

 

hTestRun is initialised only if TESTMODE is defined. But your original post you did not say that TESTMODE is defined and code that you posted doesn't define it either.

 

Pavel

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...