Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12682 Discussions

NIOSII uCOSII Stack - 2 bytes wide, or 4?

Altera_Forum
Honored Contributor II
1,951 Views

I have just started with some of the examples. The ported uCOS-II code seems to indicate in many places that only a 16bit stack is needed. I am assuming this is incorrect as my programs always crash with 16bit stack. Currently OS_STK is defined as int and sizeof(int) is reporting as 4 bytes. 

 

Also some of the LWIP tasks are using over 75% of there stack while running idle (no HTTP comms in the comms example etc.). What are the recommended sizes to avoid overflow?
0 Kudos
3 Replies
Altera_Forum
Honored Contributor II
757 Views

What do you mean by a "16-bit stack"? The stack is just a chunk of memory, like any other. As long as the pointer you pass to the OSCreateTask is actually the end of your allocated stack, there shouldn't be a problem (Although the base address probably needs to be 32-bit aligned. The NIOS processor seems to behave very strangely when trying to access misaligned data) 

 

OS_STK is indeed 4 bytes which IMO is just a pointless recipe for stupid bugs. One of these appears to be that the sizes returned from OSStkChk are measure in bytes, not OS_STKs... 

 

By default, tasks created with sys_new_task get an 2K OS_STK stack (= 8KBytes) , but they are NOT created with the OS_STK_CLR and OS_STK_CHK options. You should check that before believing the task usage stats. 

 

- Roddy
0 Kudos
Altera_Forum
Honored Contributor II
757 Views

If you change OS_STK from int to short you will only get half as much stack, yet if you double the stack size the OS still won't run, so it must be type casting each stack array element to a long * causing the stack variables to over-align each other (or if mis-alignments don't work as you mentioned, then writing onto the same stack space twice would happen). 

 

Basically what I am asking is should sizeof(OS_STK) by 4 or 2? In many comments it says 16bit yet I can only get it working as 32bit. 

 

I have modified the sys_thread_new to use the TaskCreateExt function so that the extra options can be used, and as you said they appear to return byte counts.
0 Kudos
Altera_Forum
Honored Contributor II
757 Views

I've never tried changing it. I don't think it's meant as a 'user' variable. I would absolutely recommend you left it at four, and just remember that "OS_STK my_stack[4000]" will give you 16Kb of stack.  

 

- Roddy
0 Kudos
Reply