Pumpkin User Forums
  Coding
  OS_Delay question

Post New Topic  Post A Reply
profile | register | preferences | faq | search

UBBFriend: Email This Page to Someone! next newest topic | next oldest topic
Author Topic:   OS_Delay question
fil323
Junior Member
posted July 18, 2006 15:43     Click Here to See the Profile for fil323     Edit/Delete Message   Reply w/Quote
can you put ur final code up...

IP:

aek
Moderator
posted November 08, 2004 10:07     Click Here to See the Profile for aek     Edit/Delete Message   Reply w/Quote
Hi wiqu.

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

Thanks for the feedback.

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

IP: 63.203.232.106

wiqu
Junior Member
posted November 08, 2004 00:53     Click Here to See the Profile for wiqu     Edit/Delete Message   Reply w/Quote
it works now all
i have made mij own timer and it works
tnx for helping
regards
wiqu

IP: 212.129.201.179

aek
Moderator
posted November 05, 2004 07:36     Click Here to See the Profile for aek     Edit/Delete Message   Reply w/Quote
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\tut\tu1\isr.c or salvo\ex\ex1\main.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).]

IP: 63.203.232.107

wiqu
Junior Member
posted November 05, 2004 04:33     Click Here to See the Profile for wiqu     Edit/Delete Message   Reply w/Quote
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()

IP: 212.129.201.179

wiqu
Junior Member
posted November 04, 2004 23:48     Click Here to See the Profile for wiqu     Edit/Delete Message   Reply w/Quote
oke i take a look @ that
tnx anyway

IP: 212.129.201.179

aek
Moderator
posted November 04, 2004 23:26     Click Here to See the Profile for aek     Edit/Delete Message   Reply w/Quote
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.

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

IP: 63.203.232.106

wiqu
Junior Member
posted November 04, 2004 06:28     Click Here to See the Profile for wiqu     Edit/Delete Message   Reply w/Quote
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).]

IP: 212.129.201.179

aek
Moderator
posted November 01, 2004 06:52     Click Here to See the Profile for aek     Edit/Delete Message   Reply w/Quote
Oh, I forgot to mention that the Salvo User Manual contains a section that lists which source files certain modules are located in (e.g. OSCreateBinSem() is in binsem.c).

If you have timeouts enabled, you'll also have to add qdel.c to your list of Salvo sources.

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

IP: 63.203.232.107

aek
Moderator
posted November 01, 2004 06:49     Click Here to See the Profile for aek     Edit/Delete Message   Reply w/Quote
Hi wiqu.

You may want to review the AVR-GCC documentation to help you understand what causes errors like "undefined reference to `OSWaitBinSem'". That will help you solve this error.

What the AVR-GCC is telling you is that it doesn't know anything about Salvo's binSem services.

For a source-code build, you need to add binsem.c and event.c to your SALVO_SRCS:

code:
SALVO_SRCS = binsem event init qins sched delay event inittask timer

.

You started with Salvo's tutorial tu1 as the basis for your project, but tu1 doesn't use events (binSems in this case) or timeouts. Therefore you have to add these components (through salvocfg.h and the files in your project) to use them. Tutorial tu5 uses binary semaphores and delays, so you may want to look at it for comparison.

One thing to remember about Salvo is that it is designed to keep your application as small as possible. That's why, with source-code builds, you have to add these components to your project.

If you were doing a library build, then all of the components are already in the appropriate Salvo library. You'd just use a t-config library and that would support all events, delays and timeouts.

Your salvocfg.h shows that you want 2-byte delays, so you need to do a source-code build for now. After you have more experience with AVR-GCC and Salvo, you can build a custom Salvo library with 2-byte delays and do library builds instead.


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

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

IP: 63.203.232.107

wiqu
Junior Member
posted November 01, 2004 04:59     Click Here to See the Profile for wiqu     Edit/Delete Message   Reply w/Quote
mmm... the errors don't stop

now i have this error

avr-gcc -c -mmcu=atmega16 -I. -g -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-ahlms=main.lst -D SYSY -D MAKE_WITH_SOURCE=1 -I d:/salvo/projects/led_driver -I d:/salvo/inc main.c -o main.o
main.c:43:34: macro "OS_WaitBinSem" requires 3 arguments, but only 2 given
main.c: In function `send':
main.c:43: error: `OS_WaitBinSem' undeclared (first use in this function)

i have change it to >>>> OS_WaitBinSem(DATA_SEND_P,10, send1);
but that give the error like....

main.o(.text+0xc): In function `send':
D:\salvo\ex\test/main.c:43: undefined reference to `OSWaitBinSem'
main.o(.text+0x56): In function `NTC':
D:\salvo\ex\test/main.c:60: undefined reference to `OSSignalBinSem'
main.o(.text+0x68): In function `LDR':
D:\salvo\ex\test/main.c:72: undefined reference to `OSSignalBinSem'
make.exe: *** [main.elf] Error 1

i think i miss something in mij salvocgf file but i don't know what..
my slavocfg file @ this moment:

code:
/************************************************************ 
Copyright (C) 1995-2002 Pumpkin, Inc. and its
Licensor(s). Freely distributable.

$Source: C:\\RCS\\d\\salvo\\tut\\tu1\\sysy\\salvocfg.h,v $
$Author: aek $
$Revision: 3.0 $
$Date: 2003-07-28 18:30:55-07 $

Header file for tutorial programs.

************************************************************/

/* */
/* Salvo Lite build */
/* */
#if defined(MAKE_WITH_FREE_LIB)
#define OSUSE_LIBRARY TRUE
#define OSLIBRARY_TYPE OSF
#define OSLIBRARY_CONFIG OSA
#define OSEVENTS 1 /* multitasking only */
#define OSEVENT_FLAGS 0
#define OSMESSAGE_QUEUES 0
#define OSTASKS 2


/* */
/* Salvo LE & Pro library build */
/* */
#elif defined(MAKE_WITH_STD_LIB)
#define OSUSE_LIBRARY TRUE
#define OSLIBRARY_TYPE OSL
#define OSLIBRARY_CONFIG OSA
#define OSEVENTS 1 /* multitasking only */
#define OSEVENT_FLAGS 0
#define OSMESSAGE_QUEUES 0
#define OSTASKS 2


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


#else

#error No MAKE_WITH_??? symbol defined. See salvocfg.h.

#endif

#if !defined(SYSY)

#error SYSY must be defined for this GCCAVR tutorial project ...

#endif


/edit
now i change it to>>>>>> OS_WaitBinSem(DATA_SEND_P, OSNO_TIMEOUT, send1);
and i put #define OSENABLE_TIMEOUTS TRUE in my salvocfg file but still the same error

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

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

IP: 212.129.201.179

aek
Moderator
posted October 29, 2004 09:23     Click Here to See the Profile for aek     Edit/Delete Message   Reply w/Quote
Hi wiqu.

You mentioned that you're pretty new to C as well as Salvo ... so here's the simplest way to do it in Salvo.

1) In NTC() and LDR(), use OS_Delay() to set the frequency at which the two measurements are made (e.g. 10Hz and 5Hz). I'm assuming that you want different rates for the two sensors, since you have separate functions.

2) In your main.c, create a binSem and initialize it to zero:

code:
OSCreateBinSem(DATA_READY_P, 0);

3) Then your Send() looks like this:

code:
void send(void)
{
for (;;)
{
OS_WaitBinSem(DATA_READY_P, label);
send both NTC and LDR data ...
}
}

4) In your NTC() and LDR(), after you read the data and it's ready, call OSSignalBinSem(DATA_READY_P).

5) Set OSEVENTS to at least 1 in your salvocfg.h, and #define DATA_READY_P OSECBP(1) in your code, and #define OSENABLE_BINARY_SEMAPHORES in your salvocfg.h (for a source-code build).

That's it. With these changes, you'll sample NTC and LDR at the rates you want, and whenever one is ready to send, Send() will send both values out.

The nice thing about these three tasks is that none of them will be running unless you're actually sampling the data or sending the data. The rest of the time (99% of the time) your application can do something else ...

For a more efficient approach, look at the tutorial #6 -- that uses messages to send data. But binSems will work for now, as you get used to working with Salvo.

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

[This message has been edited by aek (edited October 29, 2004).]

IP: 63.203.232.106

wiqu
Junior Member
posted October 29, 2004 00:16     Click Here to See the Profile for wiqu     Edit/Delete Message   Reply w/Quote
oke tnx the timer was enable it was a problem in my ntc.c/ldr.c file's that's fixed now

But i have a other question ;)
i want to read ntc and ldr end send the values every x second
it's important that i first have the values before he send it
what's the best way to do that??

i have now:

code:
void send(void
{
for (;;)
{
send.....
OS_Delay(50 , send);
}
}

void ntc(void)
{
for (;;)
{
read ntc();
OS_Yield(ntc);
}
}

void ldr (void)
{
for (;;)
{
read_ldr();
OS_Yield(ldr);
}
}

OSCreateTask(send, TASKSEND_P, 6);
OSCreateTask(NTC, TASKNTC_P, 7);
OSCreateTask(LDR, TASKLDR_P, 8);


[This message has been edited by aek (edited October 29, 2004).]

IP: 212.129.201.179

aek
Moderator
posted October 28, 2004 06:41     Click Here to See the Profile for aek     Edit/Delete Message   Reply w/Quote
Hello wiqu.

You need to call OSTimer() from inside an ISR -- I can't tell if you're doing that already.

See salvo\tut\tu1\isr.c for an example of how to do that -- look towards the end of the file, where

code:
#elif defined(SYSY) ...

is located.

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

IP: 63.203.232.107

wiqu
Junior Member
posted October 28, 2004 03:15     Click Here to See the Profile for wiqu     Edit/Delete Message   Reply w/Quote
that problem is solved now i have edit a rule in my makefile
first it was : SALVO_SRCS = init qins sched
now : SALVO_SRCS = init qins sched delay event inittask timer

but now he don't what to switch between the 2 task but do'n give a error

my code:

/************************************************************
Copyright (C) 1995-2002 Pumpkin, Inc. and its
Licensor(s). Freely distributable.

$Source: C:\\RCS\\d\\salvo\\tut\\tu1\\main.c,v $
$Author: aek $
$Revision: 3.5 $
$Date: 2003-11-28 16:29:17-08 $

Source for tutorial programs.

************************************************************/

#include "main.h"
#include "salvo.h"
#include "RTC.h"
#include "serial.h"
#include "bevernet.h"
#include "isr.h"
#include "ntc.h"
#include "ldr.h"

#define TASKNTC_P OSTCBP(1)
#define TASKLDR_P OSTCBP(2)

_OSLabel(NTC1)
_OSLabel(LDR1)

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


void NTC (void)
{
for(;
{
read_NTC();
OS_Delay(200, NTC1);

}

}

void LDR (void)
{
for(;
{
read_LDR();
OS_Yield(LDR1);
}


}

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

OSInit();
OSCreateTask(NTC, TASKNTC_P, 6);
OSCreateTask(LDR, TASKLDR_P, 7);

OSEi();

for (;
OSSched();
}

he only shows me the ntc value

IP: 212.129.201.179

wiqu
Junior Member
posted October 28, 2004 00:21     Click Here to See the Profile for wiqu     Edit/Delete Message   Reply w/Quote
tnx for fast reply but i have some more questions:
first some info about mij configuration
1) Which target = AVR
2) Which compiler = GCC
3) What version of Salvo = Salvo Pro for Atmel AVR and MegaAVR v3.2.4
4) Your project's salvocfg.h =

/************************************************************
Copyright (C) 1995-2002 Pumpkin, Inc. and its
Licensor(s). Freely distributable.

$Source: C:\\RCS\\d\\salvo\\tut\\tu1\\sysy\\salvocfg.h,v $
$Author: aek $
$Revision: 3.0 $
$Date: 2003-07-28 18:30:55-07 $

Header file for tutorial programs.

************************************************************/

/* */
/* Salvo Lite build */
/* */
#if defined(MAKE_WITH_FREE_LIB)
#define OSUSE_LIBRARY TRUE
#define OSLIBRARY_TYPE OSF
#define OSLIBRARY_CONFIG OSM
#define OSEVENTS 0 /* multitasking only */
#define OSEVENT_FLAGS 0
#define OSMESSAGE_QUEUES 0
#define OSTASKS 2


/* */
/* Salvo LE & Pro library build */
/* */
#elif defined(MAKE_WITH_STD_LIB)
#define OSUSE_LIBRARY TRUE
#define OSLIBRARY_TYPE OSL
#define OSLIBRARY_CONFIG OSA
#define OSEVENTS 0 /* multitasking only */
#define OSEVENT_FLAGS 0
#define OSMESSAGE_QUEUES 0
#define OSTASKS 2


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


#else

#error No MAKE_WITH_??? symbol defined. See salvocfg.h.

#endif

#if !defined(SYSY)

#error SYSY must be defined for this GCCAVR tutorial project ...

#endif

first i have to tell that i'm just programming for 2 months and for 1 week with salvo.

but what did you mean with ISR must a make a kind of loop what call OSTimer()?

OSLIBRARY_CONFIG is change to OSA
And i have add #define OSBYTES_OF_DELAYS 2

This change the error to:

main.o(.text+0x18): In function `LDR':
D:\salvo\ex\test/main.c:46: undefined reference to `OSDelay'
main.o(.text+0x3a): In function `main':
D:\salvo\ex\test/main.c:60: undefined reference to `OSCreateTask'
main.o(.text+0x48) :\salvo\ex\test/main.c:61: undefined reference to `OSCreateTask'
make.exe: *** [main.elf] Error 1

> Process Exit Code: 2

[This message has been edited by wiqu (edited October 28, 2004).]

IP: 212.129.201.179

aek
Moderator
posted October 27, 2004 08:42     Click Here to See the Profile for aek     Edit/Delete Message   Reply w/Quote
Hello wiqu.

In the future, please indicate:

1) Which target (e.g. AVR)
2) Which compiler (e.g. ICCAVR)
3) What version of Salvo (e.g. Salvo Lite for AVR)
4) Your project's salvocfg.h

From what you've posted here, I see a couple of problems:

1) You're not calling OSTimer() correctly. For delays to work, it must be called every system tick, not just once. Create an interrupt service routine (ISR) and call OSTimer() from it. Usually, we recommend an ISR rate of 100Hz (i.e. every 10ms). The Salvo tutorial and example programs call OSTimer() at 100Hz.

2) I suspect you're using Salvo Lite, and you've set OSLIBRARY_CONFIG to be OSM. These libraries ('m' for multitasking only) do not support delays -- that's why you're getting the implicit declaration of function `OS_Delay' error. set OSLIBRARY_CONFIG to OSA and use an a-config library (see the Salvo COmpiler Reference Manual for your compiler for more information).

Salvo tutorials tu1-tu3 use OSM, tu4 uses OSE, and tu5-tu6 use OSA for OSLIBRARY_CONFIG. They use different libraries, too.

3) You're using OS_Yield()in your LDR() task. That's OK, since you set LDR()'s priority to 10, lower than NTC()'s. In your application, this is OK. But if NTC()'s priority were, say, 12, then NTC() would never run because LDR()'s priority would always be higher than NTC()'s. Please rmemeber this whenever you use OS_Yield().

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

IP: 63.203.232.107

wiqu
Junior Member
posted October 27, 2004 02:23     Click Here to See the Profile for wiqu     Edit/Delete Message   Reply w/Quote
hi i have some problems with my problem
i whant to switch between 2 task or more my code is:
code:
/*************incudes***********/
#include "main.h"
#include "salvo.h"
#include "RTC.h"
#include "serial.h"
#include "bevernet.h"
#include "isr.h"
#include "ntc.h"
#include "ldr.h"


/****************labels******************/

_OSLabel(NTClabel)
_OSLabel(LDRlabel)

/***************Programma****************************/

void NTC (void)
{
for(;;)
{
read_NTC();
asm volatile ("nop");

OS_Delay(5, NTClabel);
}
}

void LDR (void)
{
for(; ;)
{
read_LDR();
asm volatile ("nop");
OS_Yield(LDRlabel);
}
}

int main (void)
{
USART_Init(51);
Init();
OSInit();
OSEi();
OSTimer();
OSCreateTask(NTC, OSTCBP(1), 2);
OSCreateTask(LDR, OSTCBP(2), 10);

for (; ;)
OSSched();;
}


/edit he give this fault error

main.c:41: warning: implicit declaration of function `OS_Delay'
main.c:41: error: `NTClabel' undeclared (first use in this function)
main.c:41: error: (Each undeclared identifier is reported only once
main.c:41: error: for each function it appears in.)
did someone now what i doe wrong??
the ting i want is to switch between LDR and NTC tasks

regards
wiqu

[This message has been edited by wiqu (edited October 27, 2004).]

[This message has been edited by aek (edited October 27, 2004).]

IP: 212.129.201.179

All times are ET

next newest topic | next oldest topic

Administrative Options: Close Topic | Archive/Move | Delete Topic
Post New Topic  Post A Reply
Hop to:

Contact Us | Pumpkin Home Page

©2000-2008 Pumpkin, Inc. All Rights Reserved. Pumpkin and the Pumpkin logo, Salvo and the Salvo logo, The RTOS that runs in tiny places, CubeSat Kit and the CubeSat Kit logo are all trademarks of Pumpkin, Inc. All other trademarks are the properties of their respective owners.


Ultimate Bulletin Board 5.46a