Pumpkin, Inc.

Pumpkin User Forums

signaling

For issues specific to Atmel's AVR and MegaAVR microcontrollers, including Atmel AVRStudio and ImageCraft's ICCAVR C compiler.

signaling

Postby Gerald » Sun May 25, 2008 1:17 am

hi,

when i have the following example...
ISR and Task1 is signaling a message with different content!
if Task1 is signaling a message and task2 waits for receiving...the ISR might overwrite the num? Is there a solution from Salvo for this special case?

bye

code:
static unsigned int num = 0;

ISR(SIG_OUTPUT_COMPARE1A)
{
//....

/* get message pointer (may be 0). */
while((msgP = OSTryMsg(MSG1_P)) != NULL)
{
OS_Delay(1);
}
num = 1;
OSSignalMsg(MSG1_P, (OStypeMsgP) &num);
}

void Task1()
{
while(1)
{
//....

/* get message pointer (may be 0). */
while((msgP = OSTryMsg(MSG1_P)) != NULL)
{
OS_Delay(1);
}
num = 2;
OSSignalMsg(MSG1_P, (OStypeMsgP) &num);
}
}

void Task2()
{
while(1)
{
//....

/* wait forever for a message. */
OS_WaitMsg(MSGQ1_P, &msgP);

receivednum = (unsigned int) msgP;
printf("received %d
", receivednum);
}
}


[This message has been edited by aek (edited May 25, 2008).]

Gerald
 
Posts: 24
Joined: Tue Mar 11, 2008 11:00 pm

Re: signaling

Postby aek » Sun May 25, 2008 2:05 am

1) You can't call OS_Delay() from inside an ISR.

2) Please review your previous thread where I pointed out that to do bidirectional task<-> ISR communications, you need to use your own objects, not Salvo objects. Salvo objects work for ISR->task but not task->ISR.

3) Nothing can be "overwitten" when signaling in Salvo -- either the message is empty, or the message is full. A full message cannot be overwritten. OSSignalMsg() returns an erro code when you signal a message that is full.

4) Whichever task has the highest priority will receive the message as a result of OS_WaitMsg().

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

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

Re: signaling

Postby Gerald » Mon May 26, 2008 2:44 am

1.) ok thats true

3.)
nothing is overwritten here? but num is a global var! if OSSignalMsg returns an errorcode num is 1!

code:
num = 1;
OSSignalMsg(MSG1_P, (OStypeMsgP) &num);

Gerald
 
Posts: 24
Joined: Tue Mar 11, 2008 11:00 pm

Re: signaling

Postby aek » Tue May 27, 2008 9:39 am

Ah, I see what you're saying ... and that is true (and is discussed at length in the Salvo User Manual). I.e. Salvo's messages are (normally) pointers to messages. Therefore the message (that is pointed to) must not change its value between when you signal it and when you successfully wait it.

In systems that have more memory (i.e. more RAM), you fill a pipe with the message contents and it remains unchanged until someone receives the message. You could add this feature to a Salvo application by managing a memory pool (via malloc, etc.) if you want ... or you could pass const pointers.

The other option is to use message queues and pass raw data ... in this case you could pass 16-bit numbers as the message when you call OSSignalMsgQ(), the message pointer goes into a buffer and will not be overwritten ... if you signal and dereference properly you can pass raw data (no larger than the size of the pointer).

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

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

Re: signaling

Postby Gerald » Wed May 28, 2008 11:17 am

could u provide some example code with memory pool and message queues?

i have a struct with:

code:

typedef struct Global_Struct
{
enum msg_source function_logic_msg_source;
enum msg_source stepper_driver_msg_source;
tBool direction;
tBool lage;
tBool normierung;
tBool freigabe;
unsigned int position;
unsigned int v;
tBool klemme15;
int steps;
int steps_done;
enum voltage_klemme30 voltage_klemme30_;
}tGlobal_Struct;

code:

Global_Struct_Buffer.abbruchbedingung_lin = false;
Global_Struct_Buffer.stepper_driver_msg_source = ADC_Message;
err = OSSignalMsg(MSG_STEPPER_DRIVER, (OStypeMsgP) &Global_Struct_Buffer); // send to function logic

// do some calc
Global_Struct_Buffer.stepper_driver_msg_source = Function_Logic_Message;
Global_Struct_Buffer.steps = steps;
err = OSSignalMsg(MSG_STEPPER_DRIVER, (OStypeMsgP) &Global_Struct_Buffer);

i saw that stepper_driver_msg_source is overwritten after the first OSSignalMsg! and the other task only see "Global_Struct_Buffer.stepper_driver_msg_source = Function_Logic_Message"

[This message has been edited by Gerald (edited June 03, 2008).]

Gerald
 
Posts: 24
Joined: Tue Mar 11, 2008 11:00 pm


Return to Atmel AVR and MegaAVR

Who is online

Users browsing this forum: No registered users and 0 guests

cron