Passing data from task in main.c to httpd-cgi.c file / web interface

Hello. I’ve got a problem of a similar nature as in DiBosco’s thread. To be precise, I want to pass some data from task declared and running in main.c to my www interface, meaning I have to add some code to httpd-cgi.c as well. And it’s the whole “data passing” thing that I’ve got a problem with. I think there are basically three ways to pass data: (1) Using queues. Problem? Declaring “#include queues.h” in my httpd-cgi.c file leads to a… ahem… huge amount of errors while compiling. (2) Using “return” at the end of the data-generating task in main.c. Problem #1? Task gotta be “void” and there can be no “return” at the end of a “void”. Problem #2? Even if so, how do I reach this task in my httpd-cgi.c file? Adding “#include main.c” in header does not work. (3) Generating data to pointers. Basically simple idea. Problem? How do I reach this task (and pointer) in my httpd-cgi.c file? Adding “#include main.c” in httpd-cgi’s header does not work. Using “extern pointer_name” does not work (can’t be sure I’m using it correctly). So that’s how I tried to deal with this situation. Can you help with any suggestions to make this work?

Passing data from task in main.c to httpd-cgi.c file / web interface

I’m not following what the problem is you are trying to solve, or why having main() return would solve anything (if the scheduler is started in main() then main() will never complete because the tasks will be running, and even if main() did complete there is nothing you can return to). What is it that is declared in main.c that you need access to? Is it a const structure, or a structure that is dynamically updated at run time? If it is a const structure then presumably you could move the definition of the structure into httpd-cgi.c? If it is a structure that is dynamically updated then do you need access to the whole structure in httpd-cgi.c or just certain data values. If it is just certain data values then you could add in some get() functions, like: uint32t getvalue( uint32_t ulValueId ); to return the data associated with ulValueId. Regards.

Passing data from task in main.c to httpd-cgi.c file / web interface

main() will never complete because the tasks will be running, and even if main() did complete there is nothing you can return to).
You’re right, this I didn’t think about. My bad. Anyway, here’s a simple idea of what my code looks like, main.c: http://pastebin.com/c4j72Vkq (using pastebin since I can’t get used to the new text formatting in here with no bbcode) And my httpd-cgi.c: http://pastebin.com/UFNTC2DD I can use a different approach, sure, but in the final version there has to be a task + generating non-static data + sending it to www interface.

Passing data from task in main.c to httpd-cgi.c file / web interface

Bump. Anyone?

Passing data from task in main.c to httpd-cgi.c file / web interface

Sorry – I didn’t realise there was anything outstanding on this post. I have checked your code, but have to admit to still not being completely sure what it is you are trying to do. Your vDataGeneratingTask() task is creating data that is local to (on the stack of) the vDataGeneratingTask(). How is that related to the data being sent by the sending_data() function? Regards.

Passing data from task in main.c to httpd-cgi.c file / web interface

That’s the problem – it’s supposed to be related, by I don’t know how to make it so, how to pass the data from vDataGeneratingTask to sending_data (see first post about these three ways I was thinking I could do that). What I want to do is to generate some integer data (using task / thread / whatever you call it) and send it to www. If there’s an easier and more proper way than the one I’m trying to use, I’m all ears and 100% open to suggestions 🙂

Passing data from task in main.c to httpd-cgi.c file / web interface

If the data is on a task stack then the only way is to have that task copy it to global data (not generally a good thing) or pass it to another task on a queue. If it is a single variable then you could make use of the xQueueOverwrite() each time the data changes to send the data to a queue that can only hold one value. Using the overwrite function will just keep updating the value in the queue with the latest value sent. That would seem overkill though. Why not just make the variable global the use a critical section or scheduler lock to update the variable. Reading the variable should not need a critical section if unless it is a structure. There is another thread very recently on the same thing.

Passing data from task in main.c to httpd-cgi.c file / web interface

If the data is on a task stack then the only way is to have that task copy it to global data (not generally a good thing) or pass it to another task on a queue. If it is a single variable then you could make use of the xQueueOverwrite() each time the data changes to send the data to a queue that can only hold one value. Using the overwrite function will just keep updating the value in the queue with the latest value sent.
Okay, I surely can pass the data to queue. But here’s the problem – data “travels” from main.c -> httpd-cgi.c (in order for it to be displayed in www browser). But there is a declaration missing (image1). So I tried to declare #include queue.h and main.c, but it leads to a lots of erros, so this doesn’t seem the right way. So the only question is – what to declare? Maybe it sounds stupid, but I’m really lost. Image1 – error message image1 Image2 – code in httpd-cgi.c image2 By “the other thread” you mean this one https://sourceforge.net/p/freertos/discussion/382005/thread/c03c3e19/ ? I’ll look into it.

Passing data from task in main.c to httpd-cgi.c file / web interface

Queue handles are just variables, so have the same scope as any other variable. If you declare GlobalQueueHandle in one file, you need to extern it in any other file that wants to use it. For example, if main.c contains the following code:
#include "FreeRTOS.h"
#include "queue.h"

xQueueHandle Global_Queue_Handle = NULL;

void main( void )
{
   /* Some code... */

    Global_Queue_Handle = xQueueCreate( ... );

    vTaskStartScheduler();
}

Then you want to access GlobalQueueHandle in another file:
#include "FreeRTOS.h"
#include "queue.h"

extern xQueueHandle Global_Queue_Handle;

void SomeFunctionOrOther()
{
    if( Global_Queue_Handle != NULL )
    {
        xQueuePeek( Global_Queue_Handle, ... );
    }
}
Regards.

Passing data from task in main.c to httpd-cgi.c file / web interface

This works for me! Including FreeRTOS.h was the key. Thank you for your help! Btw, does rand() function require anything else besides #include “stdlib.h” (which I downloaded from some site, so can’t be sure it’s legit)? Still, both with / without this declaration, it compiles with no erros, but website doesn’t load in the browser. Strange. My code:
void vDataGeneratingFunction(void *pvParameters)
{
int data=0;
while(1)
{
data=rand()%10;
xQueueSend(Global_Queue_Handle, &data, 1000);
vTaskDelay(5000);
}
}

Passing data from task in main.c to httpd-cgi.c file / web interface

rand() is just a standard library function, I have seen it do some strange things. You can write your own version, there is lots of code on the web. Don’t forget to call srand() first.

Passing data from task in main.c to httpd-cgi.c file / web interface

Didn’t find anything interesting using srand(), but to be honest, I haven’t searched for a lot of time, since have I quickly found something that worked for me – KISS generator (link) The code, in case someone would be interested:
static unsigned int x=123456789,y=234567891,z=345678912,w=456789123,c=0;
unsigned int JKISS32()
{
int t;
y ^= (y<<5); y ^= (y>>7); y ^= (y<<22);
t = z+w+c; z = w; c = t < 0; w = t&2147483647;
x += 1411392427;
return x + y + w;
}
Once again many thanks to everyone for their help! 🙂

Passing data from task in main.c to httpd-cgi.c file / web interface

Hello i had same issue, i have compiled successfully but i want to confirm i am doing this right: in file main.c i have:
/*kernel includes*/
all kernel includes goes here

/*project includes*/
 #include "subfunctions.h"


/*queue handles*/

xQueueHandle someQHandlename =0;

int main(void)
{
someQHandlename = xQueueCreate(....);

code for task creation goes here

}


in subfunctions.c file i have:

/*kernel includes*/
all kernel includes goes here

/*project includes*/
 #include "subfunctions.h"

void task1(void *pvParameters)
{
//somecode
xQueueSend(someQHandlename, &ulRx_data,100);
//morecode
}

void task2(void *pvParameters)
{
//somecode
xQueueReceive(someQHandlename, &ultx_data,100);
//morecode
}


and in file subfunctions.h i have:


#ifndef SUBFUNCTIONS_H
#define SUBFUNCTIONS_H
extern xQueueHandle Queue_SPI_DataHander;
#endif
IS this correct? does this queue will work correctly?

Passing data from task in main.c to httpd-cgi.c file / web interface

Can't see anything wrong with it. Regards.