I’ve been thinking about a different way that xTaskCreate() could work easier and be more portable. I wonder if others have given it much thought.
We can see that each task typically has it’s own initialization code first, and then begins it’s infinite loop for the real task code. So that code before the loop is always executed once, the first time.
What makes sense to me is if a function for the same purpose as xTaskCreate() were defined which is meant to be called from *within* the task function itself. That means it would not have to pass the parameter that tells where that task needs to run when called again later, because it can be taken from context.
It would help in HCS12 and GCC because it would be easier to start tasks which begin in a different memory banks, without the wierd trampoline stuff that GCC does.
Basically in GCC-m68hc1x if a start address of the func is 31:80A0, there is no way to pass the whole address in a pointer (only have 16-bit ptr). Instead, it gives a 16-bit addr to a trampoline func which manually tweaks the stack, sets the mem ory bank, then jumps to the real func. It seems more straight forward if xTaskCreate() could just look at the current stack to see the full addr it was called from. I realize however that would be one more function that would have to be in port.c instead of task.c, so maybe not so convenient for everyone.