3 <!-- =============================================================== -->
7 <!-- uITRON Compatibility -->
9 <!-- =============================================================== -->
10 <!-- ####COPYRIGHTBEGIN#### -->
12 <!-- =============================================================== -->
13 <!-- Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. -->
14 <!-- This material may be distributed only subject to the terms -->
15 <!-- and conditions set forth in the Open Publication License, v1.0 -->
16 <!-- or later (the latest version is presently available at -->
17 <!-- http://www.opencontent.org/openpub/) -->
18 <!-- Distribution of the work or derivative of the work in any -->
19 <!-- standard (paper) book form is prohibited unless prior -->
20 <!-- permission obtained from the copyright holder -->
21 <!-- =============================================================== -->
23 <!-- ####COPYRIGHTEND#### -->
24 <!-- =============================================================== -->
25 <!-- #####DESCRIPTIONBEGIN#### -->
27 <!-- ####DESCRIPTIONEND#### -->
28 <!-- =============================================================== -->
32 <part id="compat-uitron">
33 <title>µITRON</title>
34 <CHAPTER id="compat-uitron-microitron-api">
35 <TITLE><!-- <xref> -->µITRON API</TITLE>
36 <SECT1 id="compat-uitron-introduction">
37 <TITLE><!-- <index></index> -->Introduction to µITRON</TITLE>
38 <PARA>The <!-- <index></index> -->µITRON specification
39 defines a highly flexible operating system architecture designed
40 specifically for application in embedded systems. The specification addresses
41 features which are common to the majority of processor architectures and
42 deliberately avoids virtualization which would adversely impact
43 real-time performance. The µITRON specification
44 may be implemented on many hardware platforms and provides significant
45 advantages by reducing the effort involved in understanding and
46 porting application software to new processor architectures. </PARA>
47 <PARA>Several revisions of the µITRON specification exist.
48 In this release, <EMPHASIS>eCos</EMPHASIS> supports the
49 µITRON version 3.02 specification, with complete
50 “Standard functionality” (level S), plus many
51 “Extended” (level E) functions. The definitive
52 reference on µITRON is Dr. Sakamura’s book:
53 <CITETITLE>µITRON 3.0, An Open and Portable Real-Time Operating
54 System for Embedded Systems</CITETITLE>.
55 The book can be purchased from the IEEE Press, and
56 an ASCII version of the standard can be found online at
57 <ulink url="http://www.itron.gr.jp/">http://www.itron.gr.jp/</ulink>.
59 <ulink url="http://tron.um.u-tokyo.ac.jp/TRON/ITRON/">
60 http://tron.um.u-tokyo.ac.jp/TRON/ITRON/</ulink>
61 still exists as a mirror site. </PARA>
63 <SECT1 id="compat-uitron-over-ecos">
64 <TITLE><!-- <index></index> -->µITRON and <EMPHASIS>eCos</EMPHASIS></TITLE>
65 <PARA>The <EMPHASIS>eCos</EMPHASIS> kernel implements the functionality
66 used by the µITRON compatibility subsystem.
67 The configuration of the kernel influences the behavior of µITRON
69 <PARA>In particular, the default configuration has time slicing
70 (also known as round-robin scheduling) switched on; this means that
71 a task can be moved from <varname>RUN</varname> state
72 to <varname>READY</varname> state at any time, in
73 order that one of its peers may run. This is not strictly conformant
74 to the µITRON specification, which
75 states that timeslicing may be implemented by periodically issuing
76 a <literal>rot_rdq(0)</literal> call from
77 within a periodic task or cyclic handler; otherwise it is expected
78 that a task runs until it is pre-empted in consequence of synchronization
79 or communication calls it makes, or the effects of an interrupt
80 or other external event on a higher priority task cause that task
81 to become <varname>READY</varname>. To disable timeslicing
82 functionality in the kernel and µITRON
83 compatibility environment, please disable the
84 <LITERAL>CYGSEM_KERNEL_SCHED_TIMESLICE</LITERAL>
85 configuration option in the kernel package. A description of kernel
86 scheduling is in <xref linkend="kernel-overview">. </PARA>
87 <PARA>For another example, the semantics of task queueing when waiting
88 on a synchronization object depend solely on the way the underlying
89 kernel is configured. As discussed above, the multi-level queue
90 scheduler is the only one which is µITRON
91 compliant, and it queues waiting tasks in FIFO order. Future releases
92 of that scheduler might be configurable to support priority ordering
93 of task queues. Other schedulers might be different again: for example
94 the bitmap scheduler can be used with the µITRON
95 compatibility layer, even though it only allows one task at each
96 priority and as such is not µITRON
97 compliant, but it supports only priority ordering of task queues.
98 So which queueing scheme is supported is not really a property of
99 the µITRON compatibility layer; it
100 depends on the kernel. </PARA>
101 <PARA>In this version of the µITRON
102 compatibility layer, the calls to disable and enable scheduling
103 and interrupts (<FUNCTION>dis_dsp()</FUNCTION>,
104 <FUNCTION>ena_dsp()</FUNCTION>, <FUNCTION>loc_cpu()</FUNCTION>
105 and <FUNCTION>unl_cpu()</FUNCTION>)
106 call underlying kernel functions; in particular, the <FUNCTION>xxx_dsp()</FUNCTION> functions
107 lock the scheduler entirely, which prevents dispatching of DSRs; functions
108 implemented by DSRs include clock counters and alarm timers. Thus time “stops” while
109 dispatching is disabled with <FUNCTION>dis_dsp()</FUNCTION>. </PARA>
110 <PARA>Like all parts of the <EMPHASIS>eCos</EMPHASIS> system, the
111 detailed semantics of the µITRON layer
112 are dependent on its configuration and the configuration of other components
113 that it uses. The µITRON configuration
114 options are all defined in the file <filename>pkgconf/uitron.h</filename>,
115 and can be set using the configuration tool or editing the
116 <filename>.ecc</filename>
117 file in your build directory by hand. </PARA>
118 <PARA>An important configuration option for the µITRON
119 compatibility layer is “Option: Return Error Codes for Bad Params”
121 <LITERAL>CYGSEM_UITRON_BAD_PARAMS_RETURN_ERRORS</LITERAL>
122 ), which allows a lot of the error
123 checking code in the µITRON compatibility layer to
124 be removed. Of course this leaves a program open to undetected errors,
125 so it should only be used once an application is fully debugged and
126 tested. Its benefits include reduced code size and faster execution.
127 However, it affects the API significantly, in that with this option
128 enabled, bad calls do not return errors, but cause an assert
129 failure (if that is itself enabled) or malfunction internally. There
130 is discussion in more detail about this in each section below.</PARA>
131 <PARA>We now give a brief description of the µITRON
132 functions which are implemented in this release. Note that all C
133 and C++ source files should have the following <literal>#include</literal> statement: </PARA>
134 <PROGRAMLISTING>#include <cyg/compat/uitron/uit_func.h></PROGRAMLISTING>
136 <SECT1 id="compat-uitron-task-management-functions">
137 <TITLE><!-- <index></index> -->Task Management Functions</TITLE>
138 <PARA>The following functions are fully supported in this release: </PARA>
139 <PROGRAMLISTING>ER <FUNCTION>sta_tsk</FUNCTION>(
140 ID <EMPHASIS>tskid,</EMPHASIS>
141 INT <EMPHASIS>stacd</EMPHASIS> )</programlisting>
143 void <FUNCTION>ext_tsk</FUNCTION>( void )</programlisting>
145 void <FUNCTION>exd_tsk</FUNCTION>( void )</programlisting>
147 ER <FUNCTION>dis_dsp</FUNCTION>( void )</programlisting>
149 ER <FUNCTION>ena_dsp</FUNCTION>( void )</programlisting>
151 ER <FUNCTION>chg_pri</FUNCTION>(
152 ID <EMPHASIS>tskid,</EMPHASIS>
153 PRI <EMPHASIS>tskpri</EMPHASIS> )</programlisting>
155 ER <FUNCTION>rot_rdq</FUNCTION>(
156 PRI <EMPHASIS>tskpri</EMPHASIS> )</programlisting>
158 ER <FUNCTION>get_tid</FUNCTION>(
159 ID *<EMPHASIS>p_tskid</EMPHASIS> )</programlisting>
161 ER <FUNCTION>ref_tsk</FUNCTION>(
162 T_RTSK *<EMPHASIS>pk_rtsk,</EMPHASIS>
163 ID <EMPHASIS>tskid</EMPHASIS> )</programlisting>
165 ER <FUNCTION>ter_tsk</FUNCTION>(
166 ID <EMPHASIS>tskid</EMPHASIS> )</programlisting>
168 ER <FUNCTION>rel_wai</FUNCTION>(
169 ID <EMPHASIS>tskid</EMPHASIS> )</PROGRAMLISTING>
170 <PARA>The following two functions are supported in this release,
171 when enabled with the configuration option
172 <LITERAL>CYGPKG_UITRON_TASKS_CREATE_DELETE</LITERAL>
173 with some restrictions:</PARA>
174 <PROGRAMLISTING>ER <FUNCTION>cre_tsk</FUNCTION>(
175 ID <EMPHASIS>tskid,</EMPHASIS>
176 T_CTSK *<EMPHASIS>pk_ctsk</EMPHASIS> )</programlisting>
178 ER <FUNCTION>del_tsk</FUNCTION>(
179 ID <EMPHASIS>tskid</EMPHASIS> )</PROGRAMLISTING>
180 <PARA>These functions are restricted as follows:</PARA>
181 <PARA>Because of the static initialization facilities provided for
182 system objects, a task is allocated stack space statically in the
183 configuration. So while tasks can be created and deleted, the same
184 stack space is used for that task (task ID number) each time. Thus
185 the stack size (pk_ctsk->stksz) requested in <FUNCTION>cre_tsk()</FUNCTION> is
186 checked for being less than that which was statically allocated,
187 and otherwise ignored. This ensures that the new task will have
188 enough stack to run. For this reason <FUNCTION>del_tsk()</FUNCTION> does
189 not in any sense free the memory that was in use for the task's
191 <PARA>The task attributes (pk_ctsk->tskatr) are
192 ignored; current versions of <EMPHASIS>eCos</EMPHASIS> do not need
193 to know whether a task is written in assembler or C/C++ so
194 long as the procedure call standard appropriate to the CPU is followed.</PARA>
195 <PARA>Extended information (pk_ctsk->exinf) is
198 <TITLE>Error checking</TITLE>
199 <PARA>For all these calls, an invalid task id (tskid) (less than
200 1 or greater than the number of configured tasks) only returns E_ID
201 when bad params return errors (
202 <LITERAL>CYGSEM_UITRON_BAD_PARAMS_RETURN_ERRORS</LITERAL>
203 is enabled, see above).</PARA>
204 <PARA>Similarly, the following conditions are only checked for,
205 and only return errors if
206 <LITERAL>CYGSEM_UITRON_BAD_PARAMS_RETURN_ERRORS</LITERAL>
211 <FUNCTION>cre_tsk()</FUNCTION>
212 is a valid pointer, otherwise return E_PAR</PARA>
215 <PARA><FUNCTION>ter_tsk()</FUNCTION>
217 <FUNCTION>rel_wai()</FUNCTION>
218 on the calling task returns E_OBJ</PARA>
221 <PARA>the CPU is not locked already in
222 <FUNCTION>dis_dsp()</FUNCTION>
224 <FUNCTION>ena_dsp()</FUNCTION>
225 ; returns E_CTX</PARA>
228 <PARA>priority level in
229 <FUNCTION>chg_pri()</FUNCTION>
231 <FUNCTION>rot_rdq()</FUNCTION>
232 is checked for validity, E_PAR</PARA>
235 <PARA>return value pointer in
236 <FUNCTION>get_tid()</FUNCTION>
238 <FUNCTION>ref_tsk()</FUNCTION>
239 is a valid pointer, or E_PAR</PARA>
242 <PARA>The following conditions are checked for, and return
243 error codes if appropriate, regardless of the setting of
244 <LITERAL>CYGSEM_UITRON_BAD_PARAMS_RETURN_ERRORS</LITERAL>
248 <PARA>When create and delete functions
249 <FUNCTION>cre_tsk()</FUNCTION>
251 <FUNCTION>del_tsk()</FUNCTION>
252 are supported, all calls which use a valid task ID number check
253 that the task exists; if not, E_NOEXS is returned</PARA>
256 <PARA>When supported,
257 <FUNCTION>cre_tsk()</FUNCTION>
258 : the task must not already exist; otherwise E_OBJ</PARA>
261 <PARA>When supported,
262 <FUNCTION>cre_tsk()</FUNCTION>
263 : the requested stack size must not be larger than that statically
264 configured for the task; see the configuration options
265 “Static initializers”, and “Default stack size”.
269 <PARA>When supported,
270 <FUNCTION>del_tsk()</FUNCTION>
272 <EMPHASIS>eCos</EMPHASIS>
273 thread must not be running - this would imply either a bug or some
274 program bypassing the
275 µITRON compatibility layer and manipulating the thread directly.
279 <PARA><FUNCTION>sta_tsk()</FUNCTION>
280 : the task must be dormant, else E_OBJ</PARA>
283 <PARA><FUNCTION>ter_tsk()</FUNCTION>
284 : the task must not be dormant, else E_OBJ</PARA>
287 <PARA><FUNCTION>chg_pri()</FUNCTION>
288 : the task must not be dormant, else E_OBJ</PARA>
291 <PARA><FUNCTION>rel_wai()</FUNCTION>
292 : the task must be in
293 <varname>WAIT</varname> or <varname>WAIT-SUSPEND</varname>
294 state, else E_OBJ</PARA>
299 <SECT1 id="compat-uitron-task-dependent-synch-functions">
300 <TITLE><!-- <index></index> -->Task-Dependent Synchronization Functions</TITLE>
301 <PARA>These functions are fully supported in this release: </PARA>
302 <PROGRAMLISTING>ER <FUNCTION>sus_tsk</FUNCTION>(
303 ID <EMPHASIS>tskid</EMPHASIS> )</programlisting>
305 ER <FUNCTION>rsm_tsk</FUNCTION>(
306 ID <EMPHASIS>tskid</EMPHASIS> )</programlisting>
308 ER <FUNCTION>frsm_tsk</FUNCTION>(
309 ID <EMPHASIS>tskid</EMPHASIS> )</programlisting>
311 ER <FUNCTION>slp_tsk</FUNCTION>( void )</programlisting>
313 ER <FUNCTION>tslp_tsk</FUNCTION>(
314 TMO <EMPHASIS>tmout</EMPHASIS> )</programlisting>
316 ER <FUNCTION>wup_tsk</FUNCTION>(
317 ID <EMPHASIS>tskid</EMPHASIS> )</programlisting>
319 ER <FUNCTION>can_wup</FUNCTION>(
320 INT *<EMPHASIS>p_wupcnt,</EMPHASIS> ID <EMPHASIS>tskid</EMPHASIS> )</PROGRAMLISTING>
322 <TITLE>Error checking</TITLE>
323 <PARA>The following conditions are only checked for, and only return
325 <LITERAL>CYGSEM_UITRON_BAD_PARAMS_RETURN_ERRORS</LITERAL>
326 is enabled (see the configuration option “Return Error Codes for Bad
327 Params”):</PARA>
330 <PARA>invalid tskid; less than 1 or greater than
331 <LITERAL>CYGNUM_UITRON_TASKS</LITERAL>
335 <PARA><FUNCTION>wup_tsk()</FUNCTION>
337 <FUNCTION>sus_tsk()</FUNCTION>
339 <FUNCTION>rsm_tsk()</FUNCTION>
341 <FUNCTION>frsm_tsk()</FUNCTION>
342 on the calling task returns E_OBJ</PARA>
345 <PARA>dispatching is enabled in
346 <FUNCTION>tslp_tsk()</FUNCTION>
348 <FUNCTION>slp_tsk()</FUNCTION>
352 <PARA>tmout must be positive, otherwise E_PAR</PARA>
355 <PARA>return value pointer in
356 <FUNCTION>can_wup()</FUNCTION>
357 is a valid pointer, or E_PAR</PARA>
360 <PARA>The following conditions are checked for, and can
361 return error codes, regardless of the setting of
362 <LITERAL>CYGSEM_UITRON_BAD_PARAMS_RETURN_ERRORS</LITERAL>:
366 <PARA>When create and delete functions
367 <FUNCTION>cre_tsk()</FUNCTION>
369 <FUNCTION>del_tsk()</FUNCTION>
370 are supported, all calls which use a valid task ID number check
371 that the task exists; if not, E_NOEXS is returned</PARA>
374 <PARA><FUNCTION>sus_tsk()</FUNCTION>
375 : the task must not be dormant, else E_OBJ</PARA>
378 <PARA><FUNCTION>frsm/rsm_tsk()</FUNCTION>
379 : the task must be suspended, else E_OBJ</PARA>
382 <PARA><FUNCTION>tslp/slp_tsk()</FUNCTION>
383 : return codes E_TMOUT, E_RLWAI and E_DLT
384 are returned depending on the reason for terminating the sleep</PARA>
387 <PARA><FUNCTION>wup_tsk()</FUNCTION>
389 <FUNCTION>can_wup()</FUNCTION>
390 : the task must not be dormant, or E_OBJ is returned</PARA>
395 <SECT1 id="compat-uitron-sync-and-comm-functions">
396 <TITLE><!-- <index></index> --> Synchronization and Communication Functions</TITLE>
397 <PARA>These functions are fully supported in this release: </PARA>
398 <PROGRAMLISTING>ER <FUNCTION>sig_sem</FUNCTION>(
399 ID <EMPHASIS>semid</EMPHASIS> )
402 ER <FUNCTION>wai_sem</FUNCTION>(
403 ID <EMPHASIS>semid</EMPHASIS> )
406 ER <FUNCTION>preq_sem</FUNCTION>(
407 ID <EMPHASIS>semid</EMPHASIS> )
410 ER <FUNCTION>twai_sem</FUNCTION>(
411 ID <EMPHASIS>semid,</EMPHASIS> TMO <EMPHASIS>tmout</EMPHASIS> )
414 ER <FUNCTION>ref_sem</FUNCTION>(
415 T_RSEM *<EMPHASIS>pk_rsem ,</EMPHASIS> ID <EMPHASIS>semid</EMPHASIS> )
418 ER <FUNCTION>set_flg</FUNCTION>(
419 ID <EMPHASIS>flgid,</EMPHASIS> UINT <EMPHASIS>setptn</EMPHASIS> )
422 ER <FUNCTION>clr_flg</FUNCTION>(
423 ID <EMPHASIS>flgid,</EMPHASIS> UINT <EMPHASIS>clrptn</EMPHASIS> )
426 ER <FUNCTION>wai_flg</FUNCTION>(
427 UINT *<EMPHASIS>p_flgptn,</EMPHASIS> ID <EMPHASIS>flgid ,</EMPHASIS>
428 UINT <EMPHASIS>waiptn ,</EMPHASIS> UINT <EMPHASIS>wfmode</EMPHASIS> )
431 ER <FUNCTION>pol_flg</FUNCTION>(
432 UINT *<EMPHASIS>p_flgptn,</EMPHASIS> ID <EMPHASIS>flgid ,</EMPHASIS>
433 UINT <EMPHASIS>waiptn ,</EMPHASIS> UINT <EMPHASIS>wfmode</EMPHASIS> )
436 ER <FUNCTION>twai_flg</FUNCTION>(
437 UINT *<EMPHASIS>p_flgptn</EMPHASIS> ID <EMPHASIS>flgid ,</EMPHASIS>
438 UINT <EMPHASIS>waiptn ,</EMPHASIS> UINT <EMPHASIS>wfmode,</EMPHASIS> TMO <EMPHASIS>tmout</EMPHASIS> )
441 ER <FUNCTION>ref_flg</FUNCTION>(
442 T_RFLG *<EMPHASIS>pk_rflg,</EMPHASIS> ID <EMPHASIS>flgid</EMPHASIS> )
445 ER <FUNCTION>snd_msg</FUNCTION>(
446 ID <EMPHASIS>mbxid,</EMPHASIS> T_MSG <EMPHASIS>*pk_msg</EMPHASIS> )
449 ER <FUNCTION>rcv_msg</FUNCTION>(
450 T_MSG **<EMPHASIS>ppk_msg,</EMPHASIS> ID <EMPHASIS>mbxid</EMPHASIS> )
453 ER <FUNCTION>prcv_msg</FUNCTION>(
454 T_MSG **<EMPHASIS>ppk_msg,</EMPHASIS> ID <EMPHASIS>mbxid</EMPHASIS> )
457 ER <FUNCTION>trcv_msg</FUNCTION>(
458 T_MSG **<EMPHASIS>ppk_msg,</EMPHASIS> ID <EMPHASIS>mbxid ,</EMPHASIS> TMO <EMPHASIS>tmout</EMPHASIS> )
461 ER <FUNCTION>ref_mbx</FUNCTION>(
462 T_RMBX *<EMPHASIS>pk_rmbx,</EMPHASIS> ID <EMPHASIS>mbxid</EMPHASIS> )</PROGRAMLISTING>
463 <PARA>The following functions are supported in this release (with
464 some restrictions) if enabled with the appropriate configuration
465 option for the object type (for example
466 <LITERAL>CYGPKG_UITRON_SEMAS_CREATE_DELETE</LITERAL>):
468 <PROGRAMLISTING>ER <FUNCTION>cre_sem</FUNCTION>(
469 ID <EMPHASIS>semid,</EMPHASIS> T_CSEM *<EMPHASIS>pk_csem</EMPHASIS> )
472 ER <FUNCTION>del_sem</FUNCTION>(
473 ID <EMPHASIS>semid</EMPHASIS> )
476 ER <FUNCTION>cre_flg</FUNCTION>(
477 ID <EMPHASIS>flgid,</EMPHASIS> T_CFLG *<EMPHASIS>pk_cflg</EMPHASIS> )
480 ER <FUNCTION>del_flg</FUNCTION>(
481 ID <EMPHASIS>flgid</EMPHASIS> )
484 ER <FUNCTION>cre_mbx</FUNCTION>(
485 ID <EMPHASIS>mbxid,</EMPHASIS> T_CMBX *<EMPHASIS>pk_cmbx</EMPHASIS> )
488 ER <FUNCTION>del_mbx</FUNCTION>(
489 ID <EMPHASIS>mbxid</EMPHASIS> )</PROGRAMLISTING>
490 <PARA>In general the queueing order when waiting on a synchronization
491 object depends on the underlying kernel configuration. The multi-level
492 queue scheduler is required for strict µITRON
493 conformance and it queues tasks in FIFO order, so requests to create
494 an object with priority queueing of tasks (<literal>pk_cxxx->xxxatr = TA_TPRI</literal>)
495 are rejected with E_RSATR. Additional undefined bits in
496 the attributes fields must be zero. </PARA>
497 <PARA>In general, extended information (pk_cxxx->exinf)
499 <PARA>For semaphores, the initial semaphore count (pk_csem->isemcnt)
500 is supported; the new semaphore's count is set. The maximum
501 count is not supported, and is not in fact defined in type pk_csem. </PARA>
502 <PARA>For flags, multiple tasks are allowed to wait. Because single
503 task waiting is a subset of this, the W bit (TA_WMUL) of
504 the flag attributes is ignored; all other bits must be zero. The
505 initial flag value is supported. </PARA>
506 <PARA>For mailboxes, the buffer count is defined statically by kernel
508 <LITERAL>CYGNUM_KERNEL_SYNCH_MBOX_QUEUE_SIZE</LITERAL>;
509 therefore the buffer count field is not supported and is not in
510 fact defined in type pk_cmbx. Queueing of messages is FIFO
511 ordered only, so TA_MPRI (in pk_cmbx->mbxatr)
512 is not supported. </PARA>
514 <TITLE>Error checking</TITLE>
515 <PARA>The following conditions are only checked for, and only return
517 <LITERAL>CYGSEM_UITRON_BAD_PARAMS_RETURN_ERRORS</LITERAL>
521 <PARA>invalid object id; less than 1 or greater than
522 <LITERAL>CYGNUM_UITRON_TASKS/SEMAS/MBOXES</LITERAL>
523 as appropriate returns E_ID</PARA>
526 <PARA>dispatching is enabled in any call which can sleep, or
530 <PARA>tmout must be positive, otherwise E_PAR</PARA>
533 <PARA>pk_cxxx pointers in
534 <FUNCTION>cre_xxx()</FUNCTION>
535 must be valid pointers, or E_PAR</PARA>
538 <PARA>return value pointer in
539 <FUNCTION>ref_xxx()</FUNCTION>
540 is valid pointer, or E_PAR</PARA>
543 <PARA>flag wait pattern must be non-zero, and mode must be valid,
547 <PARA>return value pointer in flag wait calls is a valid pointer,
551 <PARA>The following conditions are checked for, and can return error
552 codes, regardless of the setting of
553 <LITERAL>CYGSEM_UITRON_BAD_PARAMS_RETURN_ERRORS</LITERAL>
557 <PARA>When create and delete functions
558 <FUNCTION>cre_xxx()</FUNCTION>
560 <FUNCTION>del_xxx()</FUNCTION>
561 are supported, all calls which use a valid object ID number check
562 that the object exists. If not, E_NOEXS is returned.</PARA>
565 <PARA>In create functions
566 <FUNCTION>cre_xxx()</FUNCTION>
567 , when supported, if the object already exists, then E_OBJ</PARA>
570 <PARA>In any call which can sleep, such as
571 <FUNCTION>twai_sem()</FUNCTION>
572 : return codes E_TMOUT, E_RLWAI, E_DLT
573 or of course E_OK are returned depending on the reason
574 for terminating the sleep</PARA>
577 <PARA>In polling functions such as
578 <FUNCTION>preq_sem()</FUNCTION>
579 return codes E_TMOUT or E_OK are returned depending
580 on the state of the synchronization object</PARA>
583 <PARA>In creation functions, the attributes must be compatible
584 with the selected underlying kernel configuration: in
585 <FUNCTION>cre_sem()</FUNCTION>
586 <literal>pk_csem->sematr</literal>
588 <literal>TA_TFIFO</literal>
593 <FUNCTION>cre_flg()</FUNCTION>
594 <literal>pk_cflg->flgatr</literal>
596 <varname>TA_WMUL</varname>
598 <varname>TA_WSGL</varname>
599 else <varname>E_RSATR</varname>.</PARA>
603 <FUNCTION>cre_mbx()</FUNCTION>
605 <LITERAL>pk_cmbx->mbxatr</LITERAL>
607 <LITERAL>TA_TFIFO + TA_MFIFO</LITERAL>
613 <SECT1 id="compat-uitron-extended-sync-comm-functions">
614 <TITLE><!-- <index></index> -->Extended Synchronization and Communication Functions</TITLE>
615 <PARA>None of these functions are supported in this release. </PARA>
617 <SECT1 id="compat-uitron-interrupt-management-functions">
618 <TITLE><!-- <index></index> -->Interrupt management functions</TITLE>
619 <PARA>These functions are fully supported in this release:</PARA>
620 <PROGRAMLISTING>void <FUNCTION> ret_int</FUNCTION>( void )
623 ER <FUNCTION>loc_cpu</FUNCTION>( void )
626 ER <FUNCTION>unl_cpu</FUNCTION>( void )
629 ER <FUNCTION>dis_int</FUNCTION>(
630 UINT <EMPHASIS>eintno</EMPHASIS> )
633 ER <FUNCTION>ena_int</FUNCTION>(
634 UINT <EMPHASIS>eintno</EMPHASIS> )
637 void <FUNCTION>ret_wup</FUNCTION>(
638 ID <EMPHASIS>tskid</EMPHASIS> )
641 ER <FUNCTION>iwup_tsk</FUNCTION>(
642 ID <EMPHASIS>tskid</EMPHASIS> )
645 ER <FUNCTION>isig_sem</FUNCTION>(
646 ID <EMPHASIS>semid</EMPHASIS> )
649 ER <FUNCTION>iset_flg</FUNCTION>(
650 ID <EMPHASIS>flgid ,</EMPHASIS>
651 UID<EMPHASIS> setptn</EMPHASIS> )
654 ER <FUNCTION>isend_msg</FUNCTION>(
655 ID <EMPHASIS>mbxid ,</EMPHASIS>
656 T_MSG<EMPHASIS> *pk_msg</EMPHASIS> )</PROGRAMLISTING>
657 <PARA>Note that <FUNCTION>ret_int()</FUNCTION> and
658 the <FUNCTION>ret_wup()</FUNCTION> are implemented
659 as macros, containing a “return” statement.</PARA>
660 <PARA>Also note that <FUNCTION>ret_wup()</FUNCTION> and
661 the <FUNCTION>ixxx_yyy()</FUNCTION> style functions
662 will only work when called from an ISR whose associated DSR is <FUNCTION>cyg_uitron_dsr()</FUNCTION>,
663 as specified in include file <filename><cyg/compat/uitron/uit_ifnc.h></filename>,
664 which defines the <FUNCTION>ixxx_yyy()</FUNCTION> style
665 functions also.</PARA>
666 <PARA>If you are writing interrupt handlers more in the
667 <EMPHASIS>eCos</EMPHASIS> style, with separate ISR and DSR routines both of
668 your own devising, do not use these special functions from a DSR: use plain
669 <FUNCTION>xxx_yyy()</FUNCTION> style functions (with no ‘i’ prefix)
670 instead, and do not call any µITRON functions from the ISR at
672 <PARA>The following functions are not supported in this release: </PARA>
673 <PROGRAMLISTING>ER <FUNCTION>def_int</FUNCTION>(
674 UINT <EMPHASIS>dintno,</EMPHASIS>
675 T_DINT *<EMPHASIS>pk_dint</EMPHASIS> )</programlisting>
677 ER <FUNCTION>chg_iXX</FUNCTION>(
678 UINT <EMPHASIS>iXXXX</EMPHASIS> )
681 ER <FUNCTION>ref_iXX</FUNCTION>(
682 UINT * <EMPHASIS>p_iXXXX</EMPHASIS> )</PROGRAMLISTING>
683 <PARA>These unsupported functions are all Level C (CPU dependent).
684 Equivalent functionality is available via other <EMPHASIS>eCos</EMPHASIS>-specific
687 <TITLE>Error checking</TITLE>
688 <PARA>The following conditions are only checked for, and only return
690 <LITERAL>CYGSEM_UITRON_BAD_PARAMS_RETURN_ERRORS</LITERAL>
694 <PARA><FUNCTION>loc/unl_cpu()</FUNCTION>
695 : these must only be called in a
696 µITRON task context, else E_CTX.</PARA>
699 <PARA><FUNCTION>dis/ena_int()</FUNCTION>
700 : the interrupt number must be in range as specified by the platform
701 HAL in qustion, else E_PAR.</PARA>
706 <SECT1 id="compat-uitron-memory-pool-mgmt-functions">
707 <TITLE><!-- <index></index> --> Memory pool Management Functions</TITLE>
708 <PARA>These functions are fully supported in this release: </PARA>
709 <PROGRAMLISTING>ER <FUNCTION>get_blf</FUNCTION>(
710 VP *<EMPHASIS>p_blf,</EMPHASIS> ID <EMPHASIS>mpfid</EMPHASIS> )
713 ER <FUNCTION>pget_blf</FUNCTION>(
714 VP *<EMPHASIS>p_blf,</EMPHASIS> ID <EMPHASIS>mpfid</EMPHASIS> )
717 ER <FUNCTION>tget_blf</FUNCTION>(
718 VP *<EMPHASIS>p_blf,</EMPHASIS> ID <EMPHASIS>mpfid,</EMPHASIS> TMO <EMPHASIS>tmout</EMPHASIS> )
721 ER <FUNCTION>rel_blf</FUNCTION>(
722 ID <EMPHASIS>mpfid,</EMPHASIS> VP <EMPHASIS>blf</EMPHASIS> )
725 ER <FUNCTION>ref_mpf</FUNCTION>(
726 T_RMPF *<EMPHASIS>pk_rmpf,</EMPHASIS> ID <EMPHASIS>mpfid</EMPHASIS> )
729 ER <FUNCTION>get_blk</FUNCTION>(
730 VP *<EMPHASIS>p_blk,</EMPHASIS> ID <EMPHASIS>mplid,</EMPHASIS> INT <EMPHASIS>blksz</EMPHASIS> )
733 ER <FUNCTION>pget_blk</FUNCTION>(
734 VP *<EMPHASIS>p_blk,</EMPHASIS> ID <EMPHASIS>mplid,</EMPHASIS> INT <EMPHASIS>blksz</EMPHASIS> )
737 ER <FUNCTION>tget_blk</FUNCTION>(
738 VP *<EMPHASIS>p_blk,</EMPHASIS> ID <EMPHASIS>mplid,</EMPHASIS> INT <EMPHASIS>blksz,</EMPHASIS> TMO <EMPHASIS>tmout</EMPHASIS> )
741 ER <FUNCTION>rel_blk</FUNCTION>(
742 ID <EMPHASIS>mplid,</EMPHASIS> VP <EMPHASIS>blk</EMPHASIS> )
745 ER <FUNCTION>ref_mpl</FUNCTION>(
746 T_RMPL *<EMPHASIS>pk_rmpl,</EMPHASIS> ID <EMPHASIS>mplid )
747 </EMPHASIS></programlisting>
749 <PARA>Note that of the memory provided for a particular pool to
750 manage in the static initialization of the memory pool objects,
751 some memory will be used to manage the pool itself. Therefore the
752 number of blocks * the blocksize will be less than the total
754 <PARA>The following functions are supported in this release, when
756 <LITERAL>CYGPKG_UITRON_MEMPOOLVAR_CREATE_DELETE</LITERAL>
758 <LITERAL>CYGPKG_UITRON_MEMPOOLFIXED_CREATE_DELETE</LITERAL>
759 as appropriate, with some restrictions: </PARA>
760 <PROGRAMLISTING>ER <FUNCTION>cre_mpl</FUNCTION>(
761 ID <EMPHASIS>mplid,</EMPHASIS> T_CMPL *<EMPHASIS>pk_cmpl</EMPHASIS> )
764 ER <FUNCTION>del_mpl</FUNCTION>(
765 ID <EMPHASIS>mplid</EMPHASIS> )
768 ER <FUNCTION>cre_mpf</FUNCTION>(
769 ID <EMPHASIS>mpfid,</EMPHASIS> T_CMPF *<EMPHASIS>pk_cmpf</EMPHASIS> )
772 ER <FUNCTION>del_mpf</FUNCTION>(
773 ID <EMPHASIS>mpfid</EMPHASIS> )</PROGRAMLISTING>
774 <PARA>Because of the static initialization facilities provided for
775 system objects, a memory pool is allocated a region of memory to
776 manage statically in the configuration. So while memory pools can
777 be created and deleted, the same area of memory is used for that
778 memory pool (memory pool ID number) each time. The requested variable pool
779 size (pk_cmpl->mplsz) or the number of fixed-size
780 blocks (pk_cmpf->mpfcnt) times the block size
781 (pk_cmpf->blfsz) are checked for fitting within
782 the statically allocated memory area, so if a create call succeeds,
783 the resulting pool will be at least as large as that requested.
784 For this reason <FUNCTION>del_mpl()</FUNCTION> and <FUNCTION>del_mpf()</FUNCTION> do
785 not in any sense free the memory that was managed by the deleted
786 pool for use by other pools; it may only be managed by a pool of
787 the same object id. </PARA>
788 <PARA>For both fixed and variable memory pools, the queueing order
789 when waiting on a synchronization object depends on the underlying
790 kernel configuration. The multi-level queue scheduler is required
791 for strict µITRON conformance and
792 it queues tasks in FIFO order, so requests to create an object with
793 priority queueing of tasks (pk_cxxx->xxxatr = TA_TPRI)
794 are rejected with E_RSATR. Additional undefined bits in
795 the attributes fields must be zero. </PARA>
796 <PARA>In general, extended information (pk_cxxx->exinf)
799 <TITLE>Error checking</TITLE>
800 <PARA>The following conditions are only checked for, and only return
802 <LITERAL>CYGSEM_UITRON_BAD_PARAMS_RETURN_ERRORS</LITERAL>
806 <PARA>invalid object id; less than 1 or greater than
807 <LITERAL>CYGNUM_UITRON_MEMPOOLVAR/MEMPOOLFIXED</LITERAL>
808 as appropriate returns E_ID</PARA>
811 <PARA>dispatching is enabled in any call which can sleep, or
815 <PARA>tmout must be positive, otherwise E_PAR</PARA>
818 <PARA>pk_cxxx pointers in
819 <FUNCTION>cre_xxx()</FUNCTION>
820 must be valid pointers, or E_PAR</PARA>
823 <PARA>return value pointer in
824 <FUNCTION>ref_xxx()</FUNCTION>
825 is a valid pointer, or E_PAR</PARA>
828 <PARA>return value pointers in get block routines is a valid
829 pointer, or E_PAR</PARA>
832 <PARA>blocksize request in get variable block routines is greater
833 than zero, or E_PAR</PARA>
836 <PARA>The following conditions are checked for, and can return error
837 codes, regardless of the setting of
838 <LITERAL>CYGSEM_UITRON_BAD_PARAMS_RETURN_ERRORS</LITERAL>:
842 <PARA>When create and delete functions
843 <FUNCTION>cre_xxx()</FUNCTION>
845 <FUNCTION>del_xxx()</FUNCTION>
846 are supported, all calls which use a valid object ID number check
847 that the object exists. If not, E_NOEXS is returned.</PARA>
850 <PARA>When create functions
851 <FUNCTION>cre_xxx()</FUNCTION>
852 are supported, if the object already exists, then E_OBJ</PARA>
855 <PARA>In any call which can sleep, such as
856 <FUNCTION>get_blk()</FUNCTION>
857 : return codes E_TMOUT, E_RLWAI, E_DLT
858 or of course E_OK are returned depending on the reason
859 for terminating the sleep</PARA>
862 <PARA>In polling functions such as
863 <FUNCTION>pget_blk()</FUNCTION>
864 return codes E_TMOUT or E_OK are returned depending
865 on the state of the synchronization object</PARA>
868 <PARA>In creation functions, the attributes must be compatible
869 with the selected underlying kernel configuration: in
870 <FUNCTION>cre_mpl()</FUNCTION>
872 <LITERAL>pk_cmpl->mplatr</LITERAL>
874 <LITERAL>TA_TFIFO</LITERAL>
879 <FUNCTION>cre_mpf()</FUNCTION>
881 <LITERAL>pk_cmpf->mpfatr</LITERAL>
883 <LITERAL>TA_TFIFO</LITERAL>
887 <PARA>In creation functions, the requested size of the memory
888 pool must not be larger than that statically configured for the
889 pool else E_RSATR; see the configuration option
890 “Option: Static initializers”.
892 <FUNCTION>cre_mpl()</FUNCTION>
894 <LITERAL>pk_cmpl->mplsz</LITERAL>
895 is the field of interest</PARA>
899 <FUNCTION>cre_mpf()</FUNCTION>
901 <LITERAL>pk_cmpf->blfsz</LITERAL>
903 <LITERAL>pk_cmpf->mpfcnt</LITERAL>
904 must be smaller than the memory statically configured for the pool
908 <PARA>In functions which return memory to the pool
909 <FUNCTION>rel_blk()</FUNCTION>
911 <FUNCTION>rel_blf()</FUNCTION>
912 , if the free fails, for example because the memory did not come
913 from that pool originally, then E_PAR is returned</PARA>
918 <SECT1 id="compat-uitron-time-mgmt-functions">
919 <TITLE><!-- <index></index> -->Time Management Functions</TITLE>
920 <PARA>These functions are fully supported in this release: </PARA>
921 <PROGRAMLISTING>ER <FUNCTION>set_tim</FUNCTION>(
922 SYSTIME *<EMPHASIS>pk_tim</EMPHASIS> )</PROGRAMLISTING>
924 <PARA> Setting the time may cause erroneous operation of the
925 kernel, for example a task performing a wait with a
926 time-out may never awaken.</PARA>
928 <PROGRAMLISTING>ER <FUNCTION>get_tim</FUNCTION>(
929 SYSTIME *<EMPHASIS>pk_tim</EMPHASIS> )
932 ER <FUNCTION>dly_tsk</FUNCTION>(
933 DLYTIME <EMPHASIS>dlytim</EMPHASIS> )
936 ER <FUNCTION>def_cyc</FUNCTION>(
937 HNO <EMPHASIS>cycno,</EMPHASIS> T_DCYC *<EMPHASIS>pk_dcyc</EMPHASIS> )
940 ER <FUNCTION>act_cyc</FUNCTION>(
941 HNO <EMPHASIS>cycno,</EMPHASIS> UINT <EMPHASIS>cycact</EMPHASIS> )
944 ER <FUNCTION>ref_cyc</FUNCTION>(
945 T_RCYC *<EMPHASIS>pk_rcyc,</EMPHASIS> HNO <EMPHASIS>cycno</EMPHASIS> )
948 ER <FUNCTION>def_alm</FUNCTION>(
949 HNO <EMPHASIS>almno,</EMPHASIS> T_DALM *<EMPHASIS>pk_dalm</EMPHASIS> )
952 ER <FUNCTION>ref_alm</FUNCTION>(
953 T_RALM *<EMPHASIS>pk_ralm,</EMPHASIS> HNO <EMPHASIS>almno</EMPHASIS> )
956 void <FUNCTION>ret_tmr</FUNCTION>( void )</programlisting>
958 <title>Error checking</title>
959 <PARA>The following conditions are only checked for, and only return
961 <LITERAL>CYGSEM_UITRON_BAD_PARAMS_RETURN_ERRORS</LITERAL>
965 <PARA>invalid handler number; less than 1 or greater than
966 <LITERAL>CYGNUM_UITRON_CYCLICS/ALARMS</LITERAL>
967 as appropriate, or E_PAR</PARA>
970 <PARA>dispatching is enabled in
971 <FUNCTION>dly_tsk()</FUNCTION>
975 <PARA>dlytim must be positive or zero, otherwise E_PAR</PARA>
978 <PARA>return value pointer in
979 <FUNCTION>ref_xxx()</FUNCTION>
980 is a valid pointer, or E_PAR</PARA>
983 <PARA>params within pk_dalm and pk_dcyc must
984 be valid, or E_PAR</PARA>
988 <FUNCTION>act_cyc()</FUNCTION>
989 must be valid, or E_PAR</PARA>
992 <PARA>handler must be defined in
993 <FUNCTION>ref_xxx()</FUNCTION>
995 <FUNCTION>act_cyc()</FUNCTION>
999 <PARA>parameter pointer must be a good pointer in
1000 <FUNCTION>get_tim()</FUNCTION>
1002 <FUNCTION>set_tim()</FUNCTION>
1003 , otherwise E_PAR is returned</PARA>
1006 <PARA>The following conditions are checked for, and can return
1007 error codes, regardless of the setting of
1008 <LITERAL>CYGSEM_UITRON_BAD_PARAMS_RETURN_ERRORS</LITERAL>
1012 <PARA><FUNCTION>dly_tsk()</FUNCTION>
1013 : return code E_RLWAI is returned depending on the reason
1014 for terminating the sleep</PARA>
1019 <SECT1 id="compat-uitron-system-mgmt-functions">
1020 <TITLE><!-- <index></index> --> System Management Functions</TITLE>
1021 <PARA>These functions are fully supported in this release:
1023 <PROGRAMLISTING>ER <FUNCTION>get_ver</FUNCTION>(
1024 T_VER *<EMPHASIS>pk_ver</EMPHASIS> )
1026 <PROGRAMLISTING>ER <FUNCTION>ref_sys</FUNCTION>(
1027 T_RSYS *<EMPHASIS>pk_rsys</EMPHASIS> )
1029 <PROGRAMLISTING>ER <FUNCTION>ref_cfg</FUNCTION>(
1030 T_RCFG *<EMPHASIS>pk_rcfg</EMPHASIS> )
1032 <PARA>Note that the information returned by each of these calls
1033 may be configured to match the user's own versioning system,
1034 and the values supplied by the default configuration may be inappropriate. </PARA>
1035 <PARA>These functions are not supported in this release: </PARA>
1036 <PROGRAMLISTING>ER <FUNCTION>def_svc</FUNCTION>(
1037 FN <EMPHASIS>s_fncd,</EMPHASIS>
1038 T_DSVC *<EMPHASIS>pk_dsvc</EMPHASIS> )
1040 <PROGRAMLISTING>ER <FUNCTION>def_exc</FUNCTION>(
1041 UINT <EMPHASIS>exckind,</EMPHASIS>
1042 T_DEXC *<EMPHASIS>pk_dexc</EMPHASIS> )
1045 <TITLE>Error checking</TITLE>
1046 <PARA>The following conditions are only checked for, and
1047 only return errors if
1049 <LITERAL>CYGSEM_UITRON_BAD_PARAMS_RETURN_ERRORS</LITERAL>
1053 <PARA>return value pointer in all calls is a valid
1054 pointer, or E_PAR</PARA>
1059 <SECT1 id="compat-uitron-network-support-functions">
1060 <TITLE><!-- <index></index> --> Network Support Functions</TITLE>
1061 <PARA>None of these functions are supported in this release.
1064 <SECT1 id="compat-uitron-configuration-faq">
1065 <TITLE><!-- <index></index> -->µITRON Configuration FAQ</TITLE>
1066 <PARA><EMPHASIS>Q: How are µITRON objects created?</EMPHASIS>
1069 For each type of uITRON object (tasks, semaphores, flags, mboxes, mpf, mpl)
1070 these two quantities are controlled by configuration:
1074 The <EMPHASIS>maximum</EMPHASIS> number of this type of object.
1077 The number of these objects which exist <EMPHASIS>initially</EMPHASIS>.
1081 This is assuming that for the relevant object type,
1082 <EMPHASIS>create</EMPHASIS> and <EMPHASIS>delete</EMPHASIS>
1083 operations are enabled; enabled is the default. For example, the option
1084 <LITERAL>CYGPKG_UITRON_MBOXES_CREATE_DELETE</LITERAL>
1085 controls whether the functions
1086 <FUNCTION>cre_mbx()</FUNCTION>
1088 <FUNCTION>del_mbx()</FUNCTION>
1089 exist in the API. If not, then the maximum number of
1090 mboxes is the same as the initial number of mboxes, and so on for all
1091 µITRON object types.
1094 Mboxes have no initialization, so there are only a few, simple
1095 configuration options:
1099 <LITERAL>CYGNUM_UITRON_MBOXES</LITERAL>
1100 is the total number of mboxes that you can have in the
1101 system. By default this is 4, so you can use mboxes 1,2,3 and 4. You
1102 cannot create mboxes outside this range; trying to
1103 <FUNCTION>cre_mbx(5,...)</FUNCTION>
1104 will return an error.
1107 <LITERAL>CYGNUM_UITRON_MBOXES_INITIALLY</LITERAL>
1108 is the number of mboxes created
1109 automatically for you, during startup. By default this is 4, so all 4
1110 mboxes exist already, and an attempt to create one of these
1111 eg. <FUNCTION>cre_mbx(3,...)</FUNCTION>
1112 will return an error because the mbox in quesion already
1113 exists. You can delete a pre-existing mbox, and then re-create it.
1118 <LITERAL>CYGNUM_UITRON_MBOXES_INITIALLY</LITERAL>,
1119 for example to 0, no mboxes
1120 are created automatically for you during startup. Any attempt to use an
1121 mbox without creating it will return E_NOEXS because the mbox does not
1122 exist. You can create an mbox, say <FUNCTION>cre_mbx(3,...)</FUNCTION>
1123 and then use it, say
1124 <FUNCTION>snd_msg(3,&foo)</FUNCTION>, and all will be well.
1126 <PARA><EMPHASIS>Q: How are µITRON objects initialized?</EMPHASIS>
1129 Some object types have optional initialization. Semaphores are an
1130 example. You could have
1131 <LITERAL>CYGNUM_UITRON_SEMAS</LITERAL>=10 and
1132 <LITERAL>CYGNUM_UITRON_SEMAS_INITIALLY</LITERAL>=5
1133 which means you can use semaphores 1-5
1134 straight off, but you must create semaphores 6-10 before you can use them.
1135 If you decide not to initialize semaphores, semaphores 1-5 will have an
1136 initial count of zero. If you decide to initialize them, you must supply
1137 a dummy initializer for semaphores 6-10 also. For example,
1138 in terms of the configuration output in
1139 <filename>pkgconf/uitron.h</filename>:
1142 #define CYGDAT_UITRON_SEMA_INITIALIZERS \
1143 CYG_UIT_SEMA( 1 ), \
1144 CYG_UIT_SEMA( 0 ), \
1145 CYG_UIT_SEMA( 0 ), \
1146 CYG_UIT_SEMA( 99 ), \
1147 CYG_UIT_SEMA( 1 ), \
1148 CYG_UIT_SEMA_NOEXS, \
1149 CYG_UIT_SEMA_NOEXS, \
1150 CYG_UIT_SEMA_NOEXS, \
1151 CYG_UIT_SEMA_NOEXS, \
1155 Semaphore 1 will have initial count 1, semaphores 2 and 3 will be zero,
1156 number 4 will be 99 initially, 5 will be one and numbers 6 though 10 do not
1160 Aside: this is how the definition of the symbol would appear in the
1161 configuration header file <filename>pkgconf/uitron.h</filename> —
1162 unfortunately editing such a long, multi-line definition is somewhat
1163 cumbersome in the GUI config tool in current releases. The macros
1164 <LITERAL>CYG_UIT_SEMA()</LITERAL>
1165 — to create a semaphore initializer — and
1166 <LITERAL>CYG_UIT_SEMA_NOEXS</LITERAL>
1167 — to invoke a dummy initializer —
1168 are provided in in the environment to help with this. Similar macros are
1169 provided for other object types. The resulting #define symbol is used in
1170 the context of a C++ array initializer, such as:
1172 Cyg_Counting_Semaphore2 cyg_uitron_SEMAS[ CYGNUM_UITRON_SEMAS ] = {
1173 CYGDAT_UITRON_SEMA_INITIALIZERS
1176 which is eventually macro-processed to give
1178 Cyg_Counting_Semaphore2 cyg_uitron_SEMAS[ 10 ] = {
1179 Cyg_Counting_Semaphore2( ( 1 ) ),
1180 Cyg_Counting_Semaphore2( ( 0 ) ),
1181 Cyg_Counting_Semaphore2( ( 0 ) ),
1182 Cyg_Counting_Semaphore2( ( 99 ) ),
1183 Cyg_Counting_Semaphore2( ( 1 ) ),
1184 Cyg_Counting_Semaphore2(0),
1185 Cyg_Counting_Semaphore2(0),
1186 Cyg_Counting_Semaphore2(0),
1187 Cyg_Counting_Semaphore2(0),
1188 Cyg_Counting_Semaphore2(0),
1191 so you can see how it is necessary to include the dummy entries in that
1192 definition, otherwise the resulting code will not compile correctly.
1196 <LITERAL>CYGNUM_UITRON_SEMAS_INITIALLY</LITERAL>=0
1197 it is meaningless to initialize them, for they must be created and so
1198 initialized then, before use.
1200 <PARA><EMPHASIS>Q: What about µITRON tasks?</EMPHASIS>
1203 Some object types require initialization. Tasks are an example of this.
1204 You must provide a task with a priority, a function to enter when the task
1205 starts, a name (for debugging purposes), and some memory to use for the stack.
1206 For example (again in terms of the resulting
1207 definitions in <filename>pkgconf/uitron.h</filename>):
1210 #define CYGNUM_UITRON_TASKS 4 // valid task ids are 1,2,3,4
1211 #define CYGNUM_UITRON_TASKS_INITIALLY 4 // they all exist at start
1213 #define CYGDAT_UITRON_TASK_EXTERNS \
1214 extern "C" void startup( unsigned int ); \
1215 extern "C" void worktask( unsigned int ); \
1216 extern "C" void lowtask( unsigned int ); \
1217 static char stack1[ CYGNUM_UITRON_STACK_SIZE ], \
1218 stack2[ CYGNUM_UITRON_STACK_SIZE ], \
1219 stack3[ CYGNUM_UITRON_STACK_SIZE ], \
1220 stack4[ CYGNUM_UITRON_STACK_SIZE ];
1222 #define CYGDAT_UITRON_TASK_INITIALIZERS \
1223 CYG_UIT_TASK("main task", 8, startup, &stack1, sizeof( stack1 )), \
1224 CYG_UIT_TASK("worker 2" , 9, worktask, &stack2, sizeof( stack2 )), \
1225 CYG_UIT_TASK("worker 3" , 9, worktask, &stack3, sizeof( stack3 )), \
1226 CYG_UIT_TASK("low task" ,20, lowtask, &stack4, sizeof( stack4 )), \
1230 So this example has all four tasks statically configured to exist, ready to
1231 run, from the start of time. The “main task” runs a routine
1232 called <FUNCTION>startup()</FUNCTION> at priority 8. Two
1233 “worker” tasks run both a priority 9, and a “low
1234 priority” task runs at priority 20 to do useful non-urgent background
1238 Task ID | Exists at | Function | Priority | Stack | Stack
1239 number | startup | entry | | address | size
1240 --------+-----------+----------+----------+---------+----------
1241 1 | Yes | startup | 8 | &stack1 | CYGNUM...
1242 2 | Yes | worktask | 9 | &stack2 | CYGNUM...
1243 3 | Yes | worktask | 9 | &stack3 | CYGNUM...
1244 4 | Yes | lowtask | 20 | &stack4 | CYGNUM...
1245 --------+-----------+----------+----------+---------+----------
1247 <PARA><EMPHASIS>Q: How can I create µITRON tasks in the program?</EMPHASIS>
1250 You must provide free slots in the task table in which to create new tasks,
1251 by configuring the number of tasks existing initially to be smaller than
1253 For a task ID which does not initially exist, it will be told what routine
1254 to call, and what priority it is, when the task is created. But you must
1255 still set aside memory for the task to use for its stack, and give it a
1256 name during initialization. For example:
1260 #define CYGNUM_UITRON_TASKS 4 // valid task ids are 1-4
1261 #define CYGNUM_UITRON_TASKS_INITIALLY 1 // only task #1 exists
1263 #define CYGDAT_UITRON_TASK_EXTERNS \
1264 extern "C" void startup( unsigned int ); \
1265 static char stack1[ CYGNUM_UITRON_STACK_SIZE ], \
1266 stack2[ CYGNUM_UITRON_STACK_SIZE ], \
1267 stack3[ CYGNUM_UITRON_STACK_SIZE ], \
1268 stack4[ CYGNUM_UITRON_STACK_SIZE ];
1270 #define CYGDAT_UITRON_TASK_INITIALIZERS \
1271 CYG_UIT_TASK( "main", 8, startup, &stack1, sizeof( stack1 ) ), \
1272 CYG_UIT_TASK_NOEXS( "slave", &stack2, sizeof( stack2 ) ), \
1273 CYG_UIT_TASK_NOEXS( "slave2", &stack3, sizeof( stack3 ) ), \
1274 CYG_UIT_TASK_NOEXS( "slave3", &stack4, sizeof( stack4 ) ), \
1278 So tasks numbered 2,3 and 4 have been given their stacks during startup,
1279 though they do not yet exist in terms of <FUNCTION>cre_tsk()</FUNCTION> and
1280 <FUNCTION>del_tsk()</FUNCTION> so you can create tasks 2–4 at
1284 Task ID | Exists at | Function | Priority | Stack | Stack
1285 number | startup | entry | | address | size
1286 --------+-----------+----------+----------+---------+----------
1287 1 | Yes | startup | 8 | &stack1 | CYGNUM...
1288 2 | No | N/A | N/A | &stack2 | CYGNUM...
1289 3 | No | N/A | N/A | &stack3 | CYGNUM...
1290 4 | No | N/A | N/A | &stack4 | CYGNUM...
1291 --------+-----------+----------+----------+---------+----------
1294 (you must have at least one task at startup in order that the system can
1295 actually run; this is not so for other uITRON object types)
1297 <PARA><EMPHASIS>Q: Can I have different stack sizes for µITRON tasks?</EMPHASIS>
1300 Simply set aside different amounts of memory for each task to use for its
1301 stack. Going back to a typical default setting for the µITRON tasks,
1302 the definitions in <filename>pkgconf/uitron.h</filename> might look like this:
1305 #define CYGDAT_UITRON_TASK_EXTERNS \
1306 extern "C" void task1( unsigned int ); \
1307 extern "C" void task2( unsigned int ); \
1308 extern "C" void task3( unsigned int ); \
1309 extern "C" void task4( unsigned int ); \
1310 static char stack1[ CYGNUM_UITRON_STACK_SIZE ], \
1311 stack2[ CYGNUM_UITRON_STACK_SIZE ], \
1312 stack3[ CYGNUM_UITRON_STACK_SIZE ], \
1313 stack4[ CYGNUM_UITRON_STACK_SIZE ];
1315 #define CYGDAT_UITRON_TASK_INITIALIZERS \
1316 CYG_UIT_TASK( "t1", 1, task1, &stack1, CYGNUM_UITRON_STACK_SIZE ), \
1317 CYG_UIT_TASK( "t2", 2, task2, &stack2, CYGNUM_UITRON_STACK_SIZE ), \
1318 CYG_UIT_TASK( "t3", 3, task3, &stack3, CYGNUM_UITRON_STACK_SIZE ), \
1319 CYG_UIT_TASK( "t4", 4, task4, &stack4, CYGNUM_UITRON_STACK_SIZE )
1324 <LITERAL>CYGNUM_UITRON_STACK_SIZE</LITERAL>
1325 is used to control the size of the stack
1326 objects themselves, and to tell the system what size stack is being provided.
1329 Suppose instead stack sizes of 2000, 1000, 800 and 800 were required:
1330 this could be achieved by using the GUI config tool to edit these
1331 options, or editting the <filename>.ecc</filename> file to get these
1332 results in <filename>pkgconf/uitron.h</filename>:
1335 #define CYGDAT_UITRON_TASK_EXTERNS \
1336 extern "C" void task1( unsigned int ); \
1337 extern "C" void task2( unsigned int ); \
1338 extern "C" void task3( unsigned int ); \
1339 extern "C" void task4( unsigned int ); \
1340 static char stack1[ 2000 ], \
1345 #define CYGDAT_UITRON_TASK_INITIALIZERS \
1346 CYG_UIT_TASK( "t1", 1, task1, &stack1, sizeof( stack1 ) ), \
1347 CYG_UIT_TASK( "t2", 2, task2, &stack2, sizeof( stack2 ) ), \
1348 CYG_UIT_TASK( "t3", 3, task3, &stack3, sizeof( stack3 ) ), \
1349 CYG_UIT_TASK( "t4", 4, task4, &stack4, sizeof( stack4 ) )
1352 Note that the sizeof() operator has been used to tell the system what size
1353 stacks are provided, rather than quoting a number (which is difficult for
1354 maintenance) or the symbol
1355 <LITERAL>CYGNUM_UITRON_STACK_SIZE</LITERAL>
1359 We recommend using (if available in your release) the stacksize symbols
1360 provided in the architectural HAL for your target, called
1361 <LITERAL>CYGNUM_HAL_STACK_SIZE_TYPICAL</LITERAL>
1363 <LITERAL>CYGNUM_HAL_STACK_SIZE_MINIMUM</LITERAL>.
1364 So a better (more portable) version of the above might be:
1367 #define CYGDAT_UITRON_TASK_EXTERNS \
1368 extern "C" void task1( unsigned int ); \
1369 extern "C" void task2( unsigned int ); \
1370 extern "C" void task3( unsigned int ); \
1371 extern "C" void task4( unsigned int ); \
1372 static char stack1[ CYGNUM_HAL_STACK_SIZE_TYPICAL + 1200 ], \
1373 stack2[ CYGNUM_HAL_STACK_SIZE_TYPICAL + 200 ], \
1374 stack3[ CYGNUM_HAL_STACK_SIZE_TYPICAL ], \
1375 stack4[ CYGNUM_HAL_STACK_SIZE_TYPICAL ];
1377 #define CYGDAT_UITRON_TASK_INITIALIZERS \
1378 CYG_UIT_TASK( "t1", 1, task1, &stack1, sizeof( stack1 ) ), \
1379 CYG_UIT_TASK( "t2", 2, task2, &stack2, sizeof( stack2 ) ), \
1380 CYG_UIT_TASK( "t3", 3, task3, &stack3, sizeof( stack3 ) ), \
1381 CYG_UIT_TASK( "t4", 4, task4, &stack4, sizeof( stack4 ) )