Pumpkin, Inc.

Pumpkin User Forums

OS_Delay question

If you can't make Salvo do what you want it to do, post it here.

OS_Delay question

Postby wiqu » Wed Oct 27, 2004 1:23 am

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).]

wiqu
 
Posts: 9
Joined: Tue Oct 26, 2004 11:00 pm
Location: middelburg

Re: OS_Delay question

Postby aek » Wed Oct 27, 2004 7:42 am

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().

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

-------
aek
aek
 
Posts: 1888
Joined: Sat Aug 26, 2000 11:00 pm

Re: OS_Delay question

Postby wiqu » Thu Oct 28, 2004 2:15 am

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

wiqu
 
Posts: 9
Joined: Tue Oct 26, 2004 11:00 pm
Location: middelburg

Re: OS_Delay question

Postby aek » Thu Oct 28, 2004 5:41 am

Hello wiqu.

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

See salvo ut u1isr.c for an example of how to do that -- look towards the end of the file, where

code:
#elif defined(SYSY) ...

is located.

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

-------
aek
aek
 
Posts: 1888
Joined: Sat Aug 26, 2000 11:00 pm

Re: OS_Delay question

Postby wiqu » Thu Oct 28, 2004 11:21 am

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:salvoex est/main.c:46: undefined reference to `OSDelay'
main.o(.text+0x3a): In function `main':
D:salvoex est/main.c:60: undefined reference to `OSCreateTask'
main.o(.text+0x48) :salvoex est/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).]

wiqu
 
Posts: 9
Joined: Tue Oct 26, 2004 11:00 pm
Location: middelburg

Re: OS_Delay question

Postby aek » Fri Oct 29, 2004 8:23 am

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).]

-------
aek
aek
 
Posts: 1888
Joined: Sat Aug 26, 2000 11:00 pm

Re: OS_Delay question

Postby wiqu » Fri Oct 29, 2004 11:16 am

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).]

wiqu
 
Posts: 9
Joined: Tue Oct 26, 2004 11:00 pm
Location: middelburg

Re: OS_Delay question

Postby wiqu » Mon Nov 01, 2004 4:59 am

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:salvoex est/main.c:43: undefined reference to `OSWaitBinSem'
main.o(.text+0x56): In function `NTC':
D:salvoex est/main.c:60: undefined reference to `OSSignalBinSem'
main.o(.text+0x68): In function `LDR':
D:salvoex est/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).]

wiqu
 
Posts: 9
Joined: Tue Oct 26, 2004 11:00 pm
Location: middelburg

Re: OS_Delay question

Postby aek » Mon Nov 01, 2004 6:49 am

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).]

-------
aek
aek
 
Posts: 1888
Joined: Sat Aug 26, 2000 11:00 pm

Re: OS_Delay question

Postby aek » Mon Nov 01, 2004 6:52 am

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.

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

-------
aek
aek
 
Posts: 1888
Joined: Sat Aug 26, 2000 11:00 pm

Next

Return to Coding

Who is online

Users browsing this forum: No registered users and 2 guests

cron