This bug was found while using MPLAB-C18 v3.01 (this also means MPLINK v4.01 which is the real culprit I suspect).
Roughly defined, the setup is as follows:
- 2 tasks (TCB structure is 7 bytes)
- OSMPLAB_C18_LOC_ALL_NEAR = FALSE
- OSENABLE_STACK_CHECKING = FALSE
- OSGATHER_STATISTICS = FALSE
- OSLOGGING = OSLOG_NONE
- 2 events, 1 event flag
- no delays/timeouts
- no non-Salvo global variables (except c18 library globals)
My first thought was that the problem was because the TCB array was roughly the same size as the rest of the global variables (i.e. the OSVars section) and in mem.c, it is the first "completely declared" section. However, I've tried adding more tasks (many more in some cases) and restructuring the order of the mem.c file, all to no avail. The only time when I could get the linker to not place the TCB array at location zero was when the the TCB array was very large enough to take up most of a 256 byte RAM bank by itself (i.e. large number of tasks). So, I believe the best solution is to simply do the following:
In mem.c, change the declaration of OScTcbP to:
code:
#if OSENABLE_TASKS
#define __OSCTCBP_MEM_C
#include <salvoprg.h>
OSgltypeCTcbP OScTcbP;
#undef __OSCTCBP_MEM_C
#endif
In salvoprg.h, change the MPLAB-C18 section to:
code:
#if defined(__OSCTCBP_MEM_C)
#pragma udata OSVarsCTcbP = 0
#elif defined(__OSTCBAREA_MEM_C)
#pragma udata OSVarsTcbArea
#elif defined(__OSECBAREA_MEM_C)
#pragma udata OSVarsEcbArea
#elif defined(__OSEFCBAREA_MEM_C)
#pragma udata OSVarsEfcbArea
#elif defined(__OSMQCBAREA_MEM_C)
#pragma udata OSVarsMqcbArea
#else
#pragma udata OSVars
#endif
This will explicitly place OScTcbP at location zero.
I should note that this is not the ideal solution simply because I'm sure that someone out there needs to use location zero in the RAM bank.
Also, if the original setup DID work to keep the TCB array out of location zero, then the real culprit is the latest incarnation of Microchip's linker, MPLINK v4.01.
Tyrel
------------------
Tyrel Newton
Electrical Engineer
Tethers Unlimited, Inc.
11807 North Creek Parkway South, Suite B-102
Bothell, WA 98011-8804, USA
425-486-0100 x836 425-482-9670 FAX
newton@tethers.com
http://www.tethers.com/