Page 2 of 2

Re: OS_Delay question

PostPosted: Thu Nov 04, 2004 6:28 am
by wiqu
hi

my program change a little bit i have only 2 tasks now
ldr and ntc
they send there own value now en that works fine but when i want to use OS_DELAY it wouldn't contexswitch and don't go back to NTC task
my program stay still in the for lus in my main without multitasking
when i put OSCreatTask(NTC.... in my LDR task it work fine but the time from OSDELAY doesn't matter it just contexswitch
my program:


_OSLabel(NTC1)
_OSLabel(LDR1)

void LDR (void);
void NTC (void);


unsigned int value, LDRresult;
unsigned char n,c;

void NTC (void)
{
for(;
{
read_NTC();
send_char(value);
send_itoa(n , 0);

OSSignalBinSem(DATA_SEND_P);
OS_Delay(90, NTC1);
//OS_Replace(LDR , 4);
}
}

void LDR (void)
{
for(;
{
OS_WaitBinSem(DATA_SEND_P, OSNO_TIMEOUT, LDR1);

read_LDR();

send_char(' ');
send_itoa(LDRresult , 1);
//OSCreateTask(NTC, TASKNTC_P, 7);
//OS_Replace(NTC , 4);
}

}


int main( void )
{
USART_Init(51);
Init();
OSInit();


OSCreateBinSem(DATA_SEND_P, 0);
OSCreateTask(LDR, TASKLDR_P, 8);
OSCreateTask(NTC, TASKNTC_P, 7);



for(;
{
OSSched();
}
}

my salvocfg file:


/* */
/* Salvo Pro source-code build */
/* */
#elif defined(MAKE_WITH_SOURCE)
#define OSBYTES_OF_DELAYS 1
//#define OSENABLE_MESSAGES TRUE
#define OSENABLE_TIMEOUTS TRUE
#define OSENABLE_BINARY_SEMAPHORES TRUE
#define OSEVENTS 1 /* multitasking only */
#define OSTASKS 2

the thing that i want with my program is that i change with OS_DELAY between the tasks, but NTC must be read first before i read LDR

i have read somewhere that if OS_DELAY is to fast he will stop the tasks mebay that's the problem but i have change OSBYTES_OF_DELAYS to 4 and OSDELAY(40000, NTC); but it still don't work

my microcontroller is the ATMEGA16 what's working on 8MHZ

regard, wiqu

(sorry for my bad english, i'm from netherlands)

[This message has been edited by wiqu (edited November 04, 2004).]


Re: OS_Delay question

PostPosted: Thu Nov 04, 2004 11:26 am
by aek
Hi wiqu.

I'm sorry, but I don't quite follow what's wrong ... Usually, if something involving OS_Delay() fails, it's because OSTimer() is not being called properly (and repetiively) from an interrupt.

I'd suggest that you examine the Salvo ex1 project. That uses binSems and delays. Run it on some basic hardware (like an STK500) and set breakpoints on the ISR and in the tasks. Then you should be able to see how OSTimer() must be called via an ISR, and how the tasks can delay or wait for events to be signaled.

------------------


Re: OS_Delay question

PostPosted: Thu Nov 04, 2004 11:48 am
by wiqu
oke i take a look @ that
tnx anyway


Re: OS_Delay question

PostPosted: Fri Nov 05, 2004 4:33 am
by wiqu
oke i see now my program don't call OSTimer

i have call OStimer in the for lus in my main function
int main( void )
{
USART_Init(51);
Init();
OSInit();
OSEi();

OSCreateBinSem(DATA_SEND_P, 0);
OSCreateTask(LDR, TASKLDR_P, 8);
OSCreateTask(NTC, TASKNTC_P, 5);



for(;
{
OSTimer();
OSSched();
}
}
i now this isn't good but now i now that OSTimer isn't called.
but what does OSEI() mean??
i think that will activate the OStimer() but that don't work.
end where is OSEI() located i ques in main.h or isr.h but can't find that
or have i it total wrong and must i make my own function with OSTimer??
when i must make my own function can i make a task of it or must i call that function every time before i call OSSched()


Re: OS_Delay question

PostPosted: Fri Nov 05, 2004 7:36 am
by aek
Hi wiqu.

OSEi() enables interrupts (see Salvo User Manual).

You shouldn't call OSTimer() from within your main() loop because it will be called much too fast.

You want to call OSTimer() every 10ms. For that, you create and use an interrupt (using a timer) that happens every 10ms. Then you call OSTimer() from within the code that happens when the interrupt occurs -- the ISR (Interrupt Service Routine).

Look in salvo ut u1isr.c or salvoexex1main.c for two examples of interrupts on the AVR where a timer calls OSTimer().

You mentioned that you were new to C. Interrupts are often hard to understand for beginners. That's OK. Keep working on trying to understand interrupts, look at all the examples, maybe get some help from someone where you work, and eventually it will "click."

And don;t try to code Salvo applications in a way that is not illustrated in the manual and examples -- that will only slow you down. Use the same format as we do. For example, you won't find OSTimer() called in the main loop with OSSched() on any part that has interrupts. Call OSTimer() from an ISR instead.

There are many, many examples of Salvo code in the manual, app notes and supplied code. Be sure to use them.

------------------

[This message has been edited by aek (edited November 05, 2004).]


Re: OS_Delay question

PostPosted: Mon Nov 08, 2004 10:07 am
by aek
Hi wiqu.

I'm glad you were able to get everything working.

Thanks for the feedback.

------------------


Re: OS_Delay question

PostPosted: Mon Nov 08, 2004 12:53 pm
by wiqu
it works now all
i have made mij own timer and it works
tnx for helping
regards
wiqu

Re: OS_Delay question

PostPosted: Tue Jul 18, 2006 2:43 am
by fil323
can you put ur final code up...