Pumpkin, Inc.

Pumpkin User Forums

Passing function to Message Queues

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

Passing function to Message Queues

Postby luben » Tue Jan 02, 2001 8:20 am

Hello,

Because message queues are passing pointers it's posssible to pass the address of one funtion too.
Could you give an example how to pass and execute after that the functions?

void func1(void);
byte func2(byte1,byte2);
void func3(long1);
int func4(void);
--------- are 4 functions ---------
Note that they are not from the same type. Is it possible to make program that can run this functions, if their addresses were passed via message queue (the program should understand what type and how many parameters should pass to the current function - it could be predefined in some table). Or, all functions should be only from type void func(void)? In fact the queue send the address to the function, but I can't figure out is it possible to start functions and is it possible to pass to them parameters / void func(byte1, byte2) /.
Maybe this is somehow C question too, because knowing how to operate with pointers will answer immediately to half of the questions, but don't forget that I don't have so big experience in the C programming.

Regards
Luben

luben
 
Posts: 324
Joined: Sun Nov 19, 2000 12:00 am
Location: Sofia, Bulgaria

Re: Passing function to Message Queues

Postby luben » Mon Jan 15, 2001 8:03 am

Hello,

what I succeed to imagine is:

code:

void func1(void)
{
....... body of the function
}

void func2(void)
{
....... body of the function
}

void func3(void)
{
....... body of the function
}

void TASK1(void)
// one Salvo task, that signals the address
// you have to enable OSBIG_MESSAGES TRUE
// to make to access the ROM (where is the code)
{
......
OS_SignalMsgQ(MSGQ_ID,(OStypeMsgP)(&func1));
// this will place the address of the function 1 into the queue

OS_SignalMsgQ(MSGQ_ID,(OStypeMsgP)(&func2));
// this will place the address of the function 2 into the queue

OS_SignalMsgQ(MSGQ_ID,(OStypeMsgP)(&func3));
// this will place the address of the function 3 into the queue

......
}

void TASK2(void)
// other task that receives the address
{
......
OS_WaitMsgQ(MSGQ_ID,pointer,OSNO_TIMEOUT,label);
// here the task waits the address

splitter((const byte *)(pointer));
// splitter is the program that will call the function (using GOTO)

....
}

void splitter(const byte *point)
// this is the program that will call other programs
{
goto point;
// the pointer is const byte (accessing code)
}


I think that this will produce working code. The returning from the functions is with <ret> at the end, but because in the splitter I used "goto", the "ret" will return the control directly to the TASK2.

So, sending to the message queue different addresses of programs I can start them. But I'm not sure that it's possible to send to them any parameters. Well, before calling the function you can place the desired values into static variables - this will have the same effect. Event it's possible to pass these parameters via message queue - the pointers access both RAM and ROM.

If the compiler can't calculate the address of "goto" maybe I should use dirrect assembler commands. Because you have big experience with Salvo (in Salvo there are many goto and this mecanism is well tunned), what is the right approach to start functions from Message Queue.

I think that such examples should be added in the manual to illustrate what you can pass to message queues and how you can use them. So, there are 2 new, unmenshened features of the message queues - to be used like FIFO stack for ordianary 8 bit data and
to be used to call different functions in any desired order (that will be ran after that)

Regards
Luben

luben
 
Posts: 324
Joined: Sun Nov 19, 2000 12:00 am
Location: Sofia, Bulgaria

Re: Passing function to Message Queues

Postby NoMore » Tue Jan 16, 2001 1:34 am

Do you mind if I answer that ?

If you have a function

code:
void function (long a)
{...}

and a pointer to that function
code:
void (*function_ptr)(long a);

You can call the function via its pointer like this
code:
long blah;
...
(*function_ptr) (blah);
...

Anyway, I don't believe you didn't know how to do this

[This message has been edited by NoMore (edited January 16, 2001).]

NoMore
 
Posts: 11
Joined: Fri Dec 01, 2000 12:00 am

Re: Passing function to Message Queues

Postby luben » Tue Jan 16, 2001 1:39 am

Hello,

Thank you for the reply. In fact I'm new in C, my experience is basicly into Assembler. So, I really had no idea how to do this, but was sure that there is some way.

Thank you
Luben

luben
 
Posts: 324
Joined: Sun Nov 19, 2000 12:00 am
Location: Sofia, Bulgaria


Return to Coding

Who is online

Users browsing this forum: No registered users and 2 guests

cron