Comtrol eCos User Manual
Page 486

Chapter 32. µITRON API
CYG_UIT_SEMA_NOEXS,
\
CYG_UIT_SEMA_NOEXS,
\
CYG_UIT_SEMA_NOEXS
Semaphore 1 will have initial count 1, semaphores 2 and 3 will be zero, number 4 will be 99 initially, 5 will be one
and numbers 6 though 10 do not exist initially.
Aside: this is how the definition of the symbol would appear in the configuration header file
pkgconf/uitron.h
—
unfortunately editing such a long, multi-line definition is somewhat cumbersome in the GUI config tool in current
releases. The macros
CYG_UIT_SEMA()
— to create a semaphore initializer — and
CYG_UIT_SEMA_NOEXS
— to
invoke a dummy initializer — are provided in in the environment to help with this. Similar macros are provided for
other object types. The resulting #define symbol is used in the context of a C++ array initializer, such as:
Cyg_Counting_Semaphore2 cyg_uitron_SEMAS[ CYGNUM_UITRON_SEMAS ] = {
CYGDAT_UITRON_SEMA_INITIALIZERS
};
which is eventually macro-processed to give
Cyg_Counting_Semaphore2 cyg_uitron_SEMAS[ 10 ] = {
Cyg_Counting_Semaphore2( ( 1 ) ),
Cyg_Counting_Semaphore2( ( 0 ) ),
Cyg_Counting_Semaphore2( ( 0 ) ),
Cyg_Counting_Semaphore2( ( 99 ) ),
Cyg_Counting_Semaphore2( ( 1 ) ),
Cyg_Counting_Semaphore2(0),
Cyg_Counting_Semaphore2(0),
Cyg_Counting_Semaphore2(0),
Cyg_Counting_Semaphore2(0),
Cyg_Counting_Semaphore2(0),
};
so you can see how it is necessary to include the dummy entries in that definition, otherwise the resulting code will
not compile correctly.
If you choose
CYGNUM_UITRON_SEMAS_INITIALLY
=0 it is meaningless to initialize them, for they must be created
and so initialized then, before use.
Q: What about µITRON tasks?
Some object types require initialization. Tasks are an example of this. You must provide a task with a priority, a
function to enter when the task starts, a name (for debugging purposes), and some memory to use for the stack. For
example (again in terms of the resulting definitions in
pkgconf/uitron.h
):
#define CYGNUM_UITRON_TASKS 4
// valid task ids are 1,2,3,4
#define CYGNUM_UITRON_TASKS_INITIALLY 4 // they all exist at start
#define CYGDAT_UITRON_TASK_EXTERNS
\
extern "C" void startup( unsigned int );
\
extern "C" void worktask( unsigned int );
\
extern "C" void lowtask( unsigned int );
\
static char stack1[ CYGNUM_UITRON_STACK_SIZE ], \
stack2[ CYGNUM_UITRON_STACK_SIZE ], \
stack3[ CYGNUM_UITRON_STACK_SIZE ], \
stack4[ CYGNUM_UITRON_STACK_SIZE ];
382