Pumpkin, Inc.

Pumpkin User Forums

How to make 8 bit data FIFO with Message Queues

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

How to make 8 bit data FIFO with Message Queues

Postby luben » Tue Jan 02, 2001 6:41 am

Hello,

Immagine that I have project - to read data from serial port. The using of the message queues fits better to the dinamic stack, that holds data from the moment of receive to the moment of its processing. I mean - from ISR I could pass data into message queue and then with simple OS_WaitMsgQ() from some task I can take the data, without worrying about time problems.

But as I understand message queues correctly they are in fact array of pointers to real data. This is very powerful, because I can send complicated and meaningfull messages like "Press any key", "ERROR", etc. And this messages could reside into ROM and RAM (by the way is it possible to mix both types?)

Now my question - if I want to use the message queue like ordinary stack FIFO for coming data, what should I do? Will be big waisting of RAM to declare 2 arrays - BUFFER_of_pointers[n] and BUFFER_of_data[n]. And when sending the message in the BUFFER_of_pointers I should point to other array, where resides the real data.

Is it possible to send directly 8 or 16 bit values from Message Queue, without declaring new array for real data?

What I can figure out is to use pointers to hold not real address to some data, but the real data. Then, when I call OS_WaitMsgQ() I should not use

my_data = *Queue_pointer;
.... but
my_data = (byte)(Queue_pointer);

If I use (char *) pointer the pointer will consume 1 byte, so the message queue could directly keep the sequence of the comming data, without any increase of the RAM size, compared with pure FIFO stack.

If I want to send value from variable VAR to the message queue I should take care when I signal the Message Queue using OSSignalMsgQ(queID, ??????). I can't immagine what to put on the ????? - it should be like address, but this address must be just the value of variable VAR (maybe it's not Salvo, but C question :-)

And what if the data is 16 bit - then I should use pointers to const byte type (they are 16 bit long)?

The information about such topics is very little in the manual, but your excellent support compensates completely this "hole".
And maybe it's impossible to say something about all possible problems and situations - will take years and the manual will look like Britanica - all volumes.

Regards
Luben

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

Re: How to make 8 bit data FIFO with Message Queues

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

Hello,

On page 325 of the manual you have examples of passing data via messages (the same is with message queues). But there is no one example how to pass data directly from some variable. I mean - you always pass pointer to some data. Maybe when you explain how to pass directly constant value 1 it's near to what I need, but it's not variable.

So, if it's possible to pass directly the value of one variable to the queue (the pointer will content the value of the variable, not its address) will be good to add this into the manual. I'm sure that I'll be not the only one, who will want to use the Message queues like ordinary FIFO stack for data. In this case I don't need to double the RAM size needed to pass simple bytes (first I have to declare array for pointers and then array for the data, where real values are kept).

Regards
Luben

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

Re: How to make 8 bit data FIFO with Message Queues

Postby luben » Fri Jan 05, 2001 7:53 am

Hello,

What I think could work to pass value, instead the address to real value in message queues is

static byte var, other_var;
static OStypeMsgP queue_pointer;

OSSignalMsgQ(queue1,(OStypeMsgP)(var));

In this case the value of var will be converted like address to some non existing data.

After then I could take the data from the queue with

other_var = (byte)(queue_pointer);

Is it correct to do so? In fact the queue is still not very optimized, because *void pointers are 2 bytes and to have FIFO for 12 bytes I need 24 bytes of memory to hold the data. Or it's possible to redeclare the type of OStypeMsg to *byte pointer, instead of *void?

Because I don't have the full version for me it's impossible to check my suggestions on the source files.

Regards
Luben

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

Re: How to make 8 bit data FIFO with Message Queues

Postby aek » Fri Jan 05, 2001 11:27 am

Sorry we haven't been able to reply to this yet ...

One correction is in order: under PIC C, * void (i.e. void pointers) consume one byte of RAM per pointer, not two. Therefore there's no need to redeclare OStypeMsgP (which would be very dangerous anyway).

Here are PIC C's pointer sizes as they relate to Salvo (PIC16):

code:
OStypeMsgP:   void *                    1 byte    (!OSBIG_MESSAGE_POINTERS)

OStypeMsgP: const * 2 bytes (OSBIG_MESSAGE_POINTERS)

task pointer: void (* OStypeTP) (void) 2 bytes


The first line is for standard messages (i.e. message is in RAM). The second line is for const messages (i.e. message is in RAM or ROM). The third line is for task (function) pointers.

Why are void pointers only one byte? Because of banking! Each bank has only 128 bytes in it, so 7 bits of pointer is enough. But how does PIC C handle multiple banks? By requiring a priori knowledge of which bank you're trying to access. So the compiled code does the bank switching for you -- you just have to declare the bankn directives properly. AN-3 on the website covers this issue in detail.

And how does a const * pointer allow ROM and RAM access? It looks at the top bit of the pointer -- if it's a zero (I think), it interprets it as a pointer to somewhere in RAM. If it's a 1, it's somewhere in ROM (where consts would be). Since neither the PIC16 nor PIC17 families of PICmicros have more than 16K words of ROM, this works fine. Though I don't know what would happen on a PIC17 with external memory if you located a const above 7FFFh.

[This message has been edited by aek (edited January 05, 2001).]

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

Re: How to make 8 bit data FIFO with Message Queues

Postby luben » Sat Jan 06, 2001 10:29 am

Hello,

With two words, its' possible to use the message queue for standard FIFO stack. Will be good if you menshen this in the manual and will be better if you even give simple example with this.

I think that this will working (will be thankful if you can check this on the full version)

static byte QUEUE_array[n];
static OStypeMsgP queue_pointer;
static byte var1,var2;

so if you want to pass the value of var1 trought the queue to var2 it will look like

OSSignalMsgQ(Queue1,(OStypeMsgP)(var1));

and the reading of the message

OS_WaitMsgQ(Queu1,&queue_pointer,OSNO_TIMEOUT,Label);
var2 = (byte)(queue_pointer);

I think that it should work.... but who knows. Until it's not checked on real projects I'm not sure.

Regards
Luben

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

Re: How to make 8 bit data FIFO with Message Queues

Postby luben » Mon Jan 08, 2001 9:26 am

Hello,
just wondering is it possible to pass via message queue unsigned int values.

static int QUEUE_array[n];
static OStypeMsgP queue_pointer;
static int var1,var2;

OSBIG_MESSAGES = TRUE; // enable mesages from both RAM and ROM

so if you want to pass the value of var1 trought the queue to var2 it will look like

OSSignalMsgQ(Queue1,(OStypeMsgP)(var1));

and the reading of the message

OS_WaitMsgQ(Queu1,&queue_pointer,OSNO_TIMEOUT,Label);
var2 = (int)(queue_pointer);

What you think, will it work? If works, will be good to include such examples in the manual too.

Regards
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