Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Examples #7

Open
ZeroAviation opened this issue Oct 5, 2020 · 5 comments
Open

Examples #7

ZeroAviation opened this issue Oct 5, 2020 · 5 comments

Comments

@ZeroAviation
Copy link

ZeroAviation commented Oct 5, 2020

Any chance for some examples on how to use the framework for us newbies?

header

class WriteTask: public TaskClassS<1000> {
public:
	WriteTask(): TaskClassS("WriteTask", TaskPrio_Mid){

	};

	void task();
};

cpp

#include <WriteTask.h>

void WriteTask::task() {

	while(1)
	{
		asm("NOP");
		vTaskDelay(500);
	}

}

my task function never gets executed, seems to delete the task before anything happens.

CHeers

@richard-damon
Copy link
Owner

Have you created an object of type WriteTask? I generally create it at file scope so it is created before main starts.

@ZeroAviation
Copy link
Author

Hi Richard,

Yes, I do create the object at runtime (on demand). The task itself is created (I can see it in the thread list) though the virtual task() override is never executed for some odd reason. Didn't know if I was missing something.

Cheers

@richard-damon
Copy link
Owner

If you are creating the task dynamically, is the task creating it higher in priority then this task? There is some code that if you enable the get/set task priority it will try to adjust things to make it work, but that isn't as well tested. If you haven't enabled the set priority function in FreeRTOSConfig.h, then you must create tasks with a task of higher priority than you are making them or it will run before the constructor finishes.

@ZeroAviation
Copy link
Author

I have tried both higher and lower on the task priority. INCLUDE_vTaskPrioritySet is set in the config

To create the task, I am simply instantiating it.

WriteTask writeTask;

taskfun() (line 370) doesn't execute before the deconstructor is called (and the task is deleted). I believe it's because I'm losing reference to the WriteTask object therefore it is destroyed.

With that said, is proper use to create the object, suspend the task, and hang onto it until needed?

@richard-damon
Copy link
Owner

If the task object gets destroyed, the task is deleted, so you don't want to make it as an automatic variable inside a function. Either make it as a file scope if it is to always be there, or you need to create the variable on the heap (and make sure your new function is thread safe) with something like WriteTask* task = new WriteTask; The one trick here is you need to then somehow make sure the object is deleted when your task is done (and it can't delete itself).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants