Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Altera_Forum
Honored Contributor I
893 Views

Niche Stack Switching Tasks

Hi Guys, 

 

I've been working with the simple socket server example. One thing has been stumping me, i can't exactly see how the tasks relenquish control. 

 

The http://www.altera.com/literature/tt/tt_nios2_tcpip.pdf document outlines creation of Niche Stack specific tasks but doesn't clearly (for me) show about switching between. 

 

Basically i want to have a TCP server and client working simulataneously. 

 

What command do you guys recommend for these to relinquish control to each other? 

 

Thanks in Advance
0 Kudos
5 Replies
Altera_Forum
Honored Contributor I
61 Views

The scheduler is responsible for this. The one is ucOS is rather simple and just uses priorities. Just create two tasks, and when the one with the highest priority goes to sleep or waits on an I/O (including network), the one with the lower priority will run.

Altera_Forum
Honored Contributor I
61 Views

Thanks for the reply Diaxiwen. 

 

Just to be clear. 

If each task is an infinite while loop. If i use should i use the "TKSleep(1)" function and the end of each tasks loop, the scheduler will rotate through the tasks automatically?
Altera_Forum
Honored Contributor I
61 Views

You really don't want to have tasks in infinite while loops on any scheduler (well any scheduler that uses a stack per task and allows tasks to sleep). Your tasks need to block somewhere and be woken up by an interrupt or other task when there is work to do. 

 

There is a vague possibility that TKSleep(0) will cause a reschedule - but I've no idea really what that call does. 

In any case that will only work if your spinning tasks are the lowest priority ones (and the scheduler hasn't done anything silly like increase the priority to avoid a 'priority inversion' problem). 

 

For small embedded systems it isn't unusual to just call every 'task' in turn. If your code works this way you often don't need to take interrupts from many devices, since the main loop can directly check the device registers often enough. This saves the expence of the register saves required for the interrupt, and any requirement to mask the interrupt through 'critical sections'. 

 

Slightly larger systems (and even quite big systems) will use a very limited number of blockable system threads, using each to process a (dynamic) list of work functions (which must not block waiting external events).
Altera_Forum
Honored Contributor I
61 Views

With network server and client tasks you can probably use blocking calls and they will be put to sleep automatically when they have to wait for network traffic.

Altera_Forum
Honored Contributor I
61 Views

I think Daixiwen is right. There must be network calls that do that since, i had some earlier experiment tasks i made and i'm pretty I didn't use any sleep and they worked. I'll give it a go.

Reply