rtel wrote on Sunday, February 22, 2009:
> HI, This might be a c-question, but I’m stuck and would
> appreciate some help 
>
> I’ve a local buffer in a task and I want to pass on a pointer
> to the first byte in that buffer to another task.
That’s fine, but make sure the buffer you are passing a pointer to is always valid. For example, don’t declare a buffer on a temporary stack within task A then pass a pointer to the buffer to task B. When the stack in task A disapears the pointer will point to random memory. It will be ok if the stack will always be there - for example the buffer is declared at the top function level within the task.
>
> I’ve created a queue with
> parserQueue = xQueueCreate(6, sizeof(unsigned char *));
So the queue can contain a maximum of 6 pointers to characters…
>
> In task1:
> unsigned char nmea[40];
… Task1 has the buffer … (note what I said above about ensuring the buffer is always valid, also take care allocating large buffers in task stacks as you will have to allocate more RAM to the task stack when the task is created).
>
> In task2:
> unsigned char * nmea;
>
> How shall the code look like in task1 and task2 to send a
> pointer from task1 to task2?
In task 1:
/* Your array. */
unsigned char nmea[40];
/* The address of the first byte in your array is saved in pc. */
char *pc = nmea;
/* Send the address of the first byte in the array. */
xQueueSend( xQueue, &pc, 0 );
In task 2:
char *nmea;
/* Copy the address received from the queue into the nmea pointer. */
xQueueReceive( xQueue, &nmea, portMAX_DELAY );
Regards.