]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/kernel/v2_0/include/kapidata.h
unified MX27, MX25, MX37 trees
[karo-tx-redboot.git] / packages / kernel / v2_0 / include / kapidata.h
1 #ifndef CYGONCE_KERNEL_KAPIDATA_H
2 #define CYGONCE_KERNEL_KAPIDATA_H
3
4 /*=============================================================================
5 //
6 //      kapidata.h
7 //
8 //      Native API data structures
9 //
10 //==========================================================================
11 //####ECOSGPLCOPYRIGHTBEGIN####
12 // -------------------------------------------
13 // This file is part of eCos, the Embedded Configurable Operating System.
14 // Copyright (C) 2002 Bart Veer
15 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
16 //
17 // eCos is free software; you can redistribute it and/or modify it under
18 // the terms of the GNU General Public License as published by the Free
19 // Software Foundation; either version 2 or (at your option) any later version.
20 //
21 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
22 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
23 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
24 // for more details.
25 //
26 // You should have received a copy of the GNU General Public License along
27 // with eCos; if not, write to the Free Software Foundation, Inc.,
28 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
29 //
30 // As a special exception, if other files instantiate templates or use macros
31 // or inline functions from this file, or you compile this file and link it
32 // with other works to produce a work based on this file, this file does not
33 // by itself cause the resulting work to be covered by the GNU General Public
34 // License. However the source code for this file must still be made available
35 // in accordance with section (3) of the GNU General Public License.
36 //
37 // This exception does not invalidate any other reasons why a work based on
38 // this file might be covered by the GNU General Public License.
39 //
40 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
41 // at http://sources.redhat.com/ecos/ecos-license/
42 // -------------------------------------------
43 //####ECOSGPLCOPYRIGHTEND####
44 //==========================================================================
45 //#####DESCRIPTIONBEGIN####
46 //
47 // Author(s):   nickg
48 // Contributors:        nickg
49 // Date:        1998-03-13
50 // Purpose:     Native API data structures
51 // Description: This file defines the structures used in the native API. The
52 //              sizes of these structures are dependent on the system
53 //              configuration and must be kept in step with their real
54 //              counterparts in the C++ headers.
55 //              IMPORTANT: It is NOT guaranteed that the fields of these
56 //              structures correspond to the equivalent fields in the
57 //              C++ classes they shadow.
58 //
59 //              One oddity with this file is that the way many of the "mirror"
60 //              classes are defined with macros. The resulting structures
61 //              then have a "flat" layout, rather than just declaring a
62 //              member structure directly in the structure. The reason for
63 //              this is that as of GCC 3.x, the C++ compiler will optimise
64 //              classes by removing padding and reusing it for subsequent
65 //              members defined in a derived class. This affects some targets
66 //              (including PowerPC and MIPS at least) when a C++ base class
67 //              includes a long long. By instead arranging for the C structure
68 //              to just list all the members directly, the compiler will then
69 //              behave the same for the C structures as the C++ classes.
70 //
71 //              This means that care has to be taken to follow the same
72 //              methodology if new stuff is added to this file. Even if
73 //              it doesn't contain long longs for your target, it may for
74 //              others, depending on HAL definitions.
75 //
76 // Usage:       included by kapi.h
77 //
78 //####DESCRIPTIONEND####
79 //
80 //==========================================================================*/
81
82 #include <pkgconf/system.h>
83 #include <pkgconf/kernel.h>
84
85 #include <cyg/infra/cyg_type.h>
86 #include <cyg/hal/hal_intr.h>           // exception defines
87
88 /*---------------------------------------------------------------------------*/
89
90 #ifdef __cplusplus
91 extern "C" {
92 #endif
93
94 /*---------------------------------------------------------------------------*/
95
96 #ifndef CYGNUM_KERNEL_SCHED_BITMAP_SIZE
97 #if defined(CYGSEM_KERNEL_SCHED_MLQUEUE)
98 #define CYGNUM_KERNEL_SCHED_BITMAP_SIZE 32
99 #elif defined(CYGSEM_KERNEL_SCHED_BITMAP)
100 #define CYGNUM_KERNEL_SCHED_BITMAP_SIZE 32
101 #endif
102 #endif
103
104 #if CYGNUM_KERNEL_SCHED_BITMAP_SIZE <= 8
105 typedef cyg_ucount8 cyg_sched_bitmap;
106 #elif CYGNUM_KERNEL_SCHED_BITMAP_SIZE <= 16
107 typedef cyg_ucount16 cyg_sched_bitmap;
108 #elif CYGNUM_KERNEL_SCHED_BITMAP_SIZE <= 32
109 typedef cyg_ucount32 cyg_sched_bitmap;
110 #elif CYGNUM_KERNEL_SCHED_BITMAP_SIZE <= 64
111 typedef cyg_ucount64 cyg_sched_bitmap;
112 #else
113 #error Bitmaps greater than 64 bits not currently allowed
114 #endif
115
116 typedef struct 
117 {
118 #if defined(CYGSEM_KERNEL_SCHED_BITMAP)
119
120     cyg_sched_bitmap map;
121     
122 #elif defined(CYGSEM_KERNEL_SCHED_MLQUEUE)
123
124     cyg_thread *queue;
125
126 #elif defined(CYGSEM_KERNEL_SCHED_LOTTERY)
127
128     cyg_thread *queue;
129
130 #else
131
132 #error Undefined scheduler type
133     
134 #endif    
135 } cyg_threadqueue;
136     
137 /*---------------------------------------------------------------------------*/
138
139 struct cyg_interrupt
140 {
141     cyg_vector_t        vector;
142     cyg_priority_t      priority;
143     cyg_ISR_t           *isr;
144     cyg_DSR_t           *dsr;
145     CYG_ADDRWORD        data;
146
147 #ifdef CYGIMP_KERNEL_INTERRUPTS_DSRS_LIST
148     cyg_ucount32        dsr_count;
149     cyg_interrupt       *next_dsr;
150 #endif
151 #ifdef CYGIMP_KERNEL_INTERRUPTS_CHAIN
152     cyg_interrupt       *next;
153 #endif
154 };
155
156
157 /*---------------------------------------------------------------------------*/
158
159
160 #if defined(CYGIMP_KERNEL_COUNTERS_SINGLE_LIST)
161 # define CYG_COUNTER_ALARM_LIST_MEMBER \
162     cyg_alarm           *alarm_list;
163 #elif defined(CYGIMP_KERNEL_COUNTERS_MULTI_LIST)
164 # define CYG_COUNTER_ALARM_LIST_MEMBER \
165     cyg_alarm           *alarm_list[CYGNUM_KERNEL_COUNTERS_MULTI_LIST_SIZE];
166 #else
167 # define CYG_COUNTER_ALARM_LIST_MEMBER
168 #endif
169
170 #define CYG_COUNTER_MEMBERS              \
171     CYG_COUNTER_ALARM_LIST_MEMBER        \
172     cyg_tick_count_t    counter;         \
173     cyg_uint32          increment;
174
175 struct cyg_counter
176 {
177     CYG_COUNTER_MEMBERS
178 };
179
180 /*---------------------------------------------------------------------------*/
181
182 struct cyg_clock
183 {
184     CYG_COUNTER_MEMBERS
185     CYG_RESOLUTION_T_MEMBERS
186 };
187
188 /*---------------------------------------------------------------------------*/
189
190
191 #if defined(CYGIMP_KERNEL_COUNTERS_SINGLE_LIST) ||  \
192     defined(CYGIMP_KERNEL_COUNTERS_MULTI_LIST)      
193 # define CYG_ALARM_LIST_MEMBERS                     \
194     cyg_alarm           *next;                      \
195     cyg_alarm           *prev;
196 #else 
197 # define CYG_ALARM_LIST_MEMBERS
198 #endif
199
200 #define CYG_ALARM_MEMBERS           \
201     CYG_ALARM_LIST_MEMBERS          \
202     cyg_counter         *counter;   \
203     cyg_alarm_t         *alarm;     \
204     CYG_ADDRWORD        data;       \
205     cyg_tick_count_t    trigger;    \
206     cyg_tick_count_t    interval;   \
207     cyg_bool            enabled;
208
209 struct cyg_alarm
210 {
211     CYG_ALARM_MEMBERS
212 };
213
214 /*---------------------------------------------------------------------------*/
215 /* Exception controller                                                      */
216
217 #ifdef CYGPKG_KERNEL_EXCEPTIONS
218
219 # ifdef CYGSEM_KERNEL_EXCEPTIONS_DECODE
220 #  define CYG_EXCEPTION_CONTROL_MEMBERS                                     \
221     cyg_exception_handler_t *exception_handler[CYGNUM_HAL_EXCEPTION_COUNT]; \
222     CYG_ADDRWORD            exception_data[CYGNUM_HAL_EXCEPTION_COUNT];     
223 # else
224 #  define CYG_EXCEPTION_CONTROL_MEMBERS                                \
225     cyg_exception_handler_t *exception_handler; /* Handler function */ \
226     CYG_ADDRWORD            exception_data;     /* Handler data */
227 # endif
228
229 typedef struct
230 {
231     CYG_EXCEPTION_CONTROL_MEMBERS    
232 } cyg_exception_control;
233
234 #endif
235
236 /*---------------------------------------------------------------------------*/
237 /* Hardware Thread structure                                                 */
238
239 #ifdef CYGFUN_KERNEL_THREADS_STACK_LIMIT
240 # define CYG_HARDWARETHREAD_STACK_LIMIT_MEMBER \
241     CYG_ADDRESS         stack_limit;    /* movable stack limit */
242 #else
243 # define CYG_HARDWARETHREAD_STACK_LIMIT_MEMBER
244 #endif
245
246 #ifdef CYGDBG_KERNEL_DEBUG_GDB_THREAD_SUPPORT
247 # define CYG_HARDWARETHREAD_SAVED_CONTEXT_MEMBER \
248     void                *saved_context; // If non-zero, this points at a more
249                                         // interesting context than stack_ptr.
250 #else
251 # define CYG_HARDWARETHREAD_SAVED_CONTEXT_MEMBER
252 #endif
253
254 typedef void cyg_thread_entry(CYG_ADDRWORD data);
255
256 #define CYG_HARDWARETHREAD_MEMBERS                                           \
257     CYG_ADDRESS         stack_base;   /* pointer to base of stack area */    \
258     cyg_uint32          stack_size;   /* size of stack area in bytes */      \
259     CYG_HARDWARETHREAD_STACK_LIMIT_MEMBER                                    \
260     CYG_ADDRESS         stack_ptr;    /* pointer to saved state on stack */  \
261     cyg_thread_entry   *entry_point;  /* main entry point (code pointer!) */ \
262     CYG_ADDRWORD        entry_data;   /* entry point argument */             \
263     CYG_HARDWARETHREAD_SAVED_CONTEXT_MEMBER
264
265 typedef struct
266 {
267     CYG_HARDWARETHREAD_MEMBERS
268 } cyg_hardwarethread;
269
270 /*---------------------------------------------------------------------------*/
271 /* Scheduler Thread structure                                                */
272
273 #ifdef CYGPKG_KERNEL_SMP_SUPPORT
274 # define CYG_SCHEDTHREAD_CPU_MEMBER \
275     cyg_uint32          cpu;            // CPU id of cpu currently running
276 #else
277 # define CYG_SCHEDTHREAD_CPU_MEMBER
278 #endif
279
280 #ifdef CYGSEM_KERNEL_SCHED_TIMESLICE
281 # define CYG_SCHEDTHREAD_TIMESLICE_MEMBER \
282     cyg_ucount32         timeslice_count; /* per-thread timeslice counter */
283 #else
284 # define CYG_SCHEDTHREAD_TIMESLICE_MEMBER
285 #endif
286
287 #ifdef CYGSEM_KERNEL_SCHED_TIMESLICE_ENABLE
288 # define CYG_SCHEDTHREAD_TIMESLICE_ENABLED_MEMBER \
289     cyg_bool            timeslice_enabled; /* per-thread timeslice enable */
290 #else
291 # define CYG_SCHEDTHREAD_TIMESLICE_ENABLED_MEMBER
292 #endif
293
294 #if defined(CYGSEM_KERNEL_SCHED_BITMAP)
295 # define CYG_SCHEDTHREAD_SCHEDIMP_MEMBERS \
296     cyg_priority_t      priority;       /* current thread priority */
297 #elif defined(CYGSEM_KERNEL_SCHED_MLQUEUE)
298 # define CYG_SCHEDTHREAD_SCHEDIMP_MEMBERS                                    \
299     cyg_thread *next;                                                        \
300     cyg_thread *prev;                                                        \
301     cyg_priority_t      priority;             /* current thread priority */  \
302     CYG_SCHEDTHREAD_CPU_MEMBER                                               \
303     CYG_SCHEDTHREAD_TIMESLICE_MEMBER                                         \
304     CYG_SCHEDTHREAD_TIMESLICE_ENABLED_MEMBER
305 #elif defined(CYGSEM_KERNEL_SCHED_LOTTERY)
306 # define CYG_SCHEDTHREAD_SCHEDIMP_MEMBERS                                    \
307     cyg_thread *next;                                                        \
308     cyg_thread *prev;                                                        \
309     cyg_priority_t      priority;             /* current thread priority */  \
310     cyg_priority_t      compensation_tickets; /* sleep compensation */
311 #else
312 # error Undefined scheduler type
313 #endif    
314
315 #ifndef CYGSEM_KERNEL_SCHED_ASR_GLOBAL
316 #  define CYG_SCHEDTHREAD_ASR_NONGLOBAL_MEMBER \
317     void              (*asr)(CYG_ADDRWORD);   // ASR function
318 #else
319 #  define CYG_SCHEDTHREAD_ASR_NONGLOBAL_MEMBER
320 #endif
321
322 #ifndef CYGSEM_KERNEL_SCHED_ASR_DATA_GLOBAL
323 #  define CYG_SCHEDTHREAD_ASR_DATA_NONGLOBAL_MEMBER \
324     CYG_ADDRWORD        asr_data;       // ASR data pointer
325 #else
326 #  define CYG_SCHEDTHREAD_ASR_DATA_NONGLOBAL_MEMBER
327 #endif
328
329 #ifdef CYGSEM_KERNEL_SCHED_ASR_SUPPORT
330 # define CYG_SCHEDTHREAD_ASR_MEMBER                                         \
331     volatile cyg_ucount32 asr_inhibit; /* If true, blocks calls to ASRs */  \
332     volatile cyg_bool     asr_pending; /* If true, this thread's ASR    */  \
333                                        /* should be called. */              \
334     CYG_SCHEDTHREAD_ASR_NONGLOBAL_MEMBER                                    \
335     CYG_SCHEDTHREAD_ASR_DATA_NONGLOBAL_MEMBER                             
336 #else
337 # define CYG_SCHEDTHREAD_ASR_MEMBER
338 #endif
339
340 #ifdef CYGSEM_KERNEL_SYNCH_MUTEX_PRIORITY_INVERSION_PROTOCOL_SIMPLE
341 # define CYG_SCHEDTHREAD_MUTEX_INV_PROTO_SIMPLE_MEMBERS \
342     cyg_priority_t      original_priority;              \
343     cyg_bool            priority_inherited;
344 #else
345 # define CYG_SCHEDTHREAD_MUTEX_INV_PROTO_SIMPLE_MEMBERS
346 #endif
347
348 #ifdef CYGSEM_KERNEL_SYNCH_MUTEX_PRIORITY_INVERSION_PROTOCOL
349 # define CYG_SCHEDTHREAD_MUTEX_INV_PROTO_MEMBERS   \
350     cyg_count32         mutex_count;               \
351     CYG_SCHEDTHREAD_MUTEX_INV_PROTO_SIMPLE_MEMBERS
352 #else
353 # define CYG_SCHEDTHREAD_MUTEX_INV_PROTO_MEMBERS
354 #endif
355
356 #define CYG_SCHEDTHREAD_MEMBERS               \
357     CYG_SCHEDTHREAD_SCHEDIMP_MEMBERS          \
358     cyg_threadqueue     *queue;               \
359     CYG_SCHEDTHREAD_ASR_MEMBER                \
360     CYG_SCHEDTHREAD_MUTEX_INV_PROTO_MEMBERS
361
362     
363 typedef struct 
364 {
365     CYG_SCHEDTHREAD_MEMBERS
366 } cyg_schedthread;
367
368 /* This compiler version test is required because the C++ ABI changed in
369    GCC v3.x and GCC could now reuse "spare" space from base classes in derived
370    classes, and in C++ land, cyg_alarm is a base class of cyg_threadtimer.
371 */
372 #if defined(__GNUC__) && (__GNUC__ < 3)
373 #define CYG_THREADTIMER_MEMBERS \
374     cyg_alarm           alarm;  \
375     cyg_thread          *thread;
376 #else
377 #define CYG_THREADTIMER_MEMBERS \
378     CYG_ALARM_MEMBERS           \
379     cyg_thread          *thread;
380 #endif
381
382 /*---------------------------------------------------------------------------*/
383 /* Thread structure                                                          */
384
385 typedef struct 
386 {
387     CYG_THREADTIMER_MEMBERS
388 } cyg_threadtimer;
389
390
391 typedef enum
392 {
393     CYG_REASON_NONE,
394     CYG_REASON_WAIT,
395     CYG_REASON_DELAY,
396     CYG_REASON_TIMEOUT,
397     CYG_REASON_BREAK,
398     CYG_REASON_DESTRUCT,
399     CYG_REASON_EXIT,
400     CYG_REASON_DONE
401 } cyg_reason_t;
402
403 #if defined(CYGPKG_KERNEL_EXCEPTIONS) && !defined(CYGSEM_KERNEL_EXCEPTIONS_GLOBAL)
404 # define CYG_THREAD_EXCEPTION_CONTROL_MEMBER \
405     cyg_exception_control       exception_control;
406 #else
407 # define CYG_THREAD_EXCEPTION_CONTROL_MEMBER
408 #endif
409
410 #ifdef CYGFUN_KERNEL_THREADS_TIMER
411 # define CYG_THREAD_TIMER_MEMBER \
412     cyg_threadtimer     timer;
413 #else
414 # define CYG_THREAD_TIMER_MEMBER
415 #endif
416
417 #ifdef CYGVAR_KERNEL_THREADS_DATA
418 # define CYG_THREAD_THREAD_DATA_MEMBER \
419     CYG_ADDRWORD        thread_data[CYGNUM_KERNEL_THREADS_DATA_MAX];
420 #else
421 # define CYG_THREAD_THREAD_DATA_MEMBER
422 #endif
423
424 #ifdef CYGVAR_KERNEL_THREADS_NAME
425 # define CYG_THREAD_NAME_MEMBER \
426     char                *name;
427 #else
428 # define CYG_THREAD_NAME_MEMBER
429 #endif
430
431 #ifdef CYGVAR_KERNEL_THREADS_LIST
432 # define CYG_THREAD_LIST_NEXT_MEMBER \
433     cyg_thread          *list_next;
434 #else
435 # define CYG_THREAD_LIST_NEXT_MEMBER
436 #endif
437
438
439
440 #ifdef CYGSEM_KERNEL_THREADS_DESTRUCTORS_PER_THREAD
441 struct Cyg_Destructor_Entry {
442     cyg_thread_destructor_fn fn;
443     cyg_addrword_t data;
444 };
445 # define CYG_THREAD_DESTRUCTORS_MEMBER \
446    struct Cyg_Destructor_Entry destructors[ CYGNUM_KERNEL_THREADS_DESTRUCTORS ];
447 #else
448 # define CYG_THREAD_DESTRUCTORS_MEMBER
449 #endif
450
451
452 #define CYG_THREAD_MEMBERS                        \
453     CYG_HARDWARETHREAD_MEMBERS                    \
454     CYG_SCHEDTHREAD_MEMBERS                       \
455                                                   \
456     cyg_uint32                  state;            \
457     cyg_ucount32                suspend_count;    \
458     cyg_ucount32                wakeup_count;     \
459     CYG_ADDRWORD                wait_info;        \
460     cyg_uint16                  unique_id;        \
461                                                   \
462     CYG_THREAD_EXCEPTION_CONTROL_MEMBER           \
463     CYG_THREAD_TIMER_MEMBER                       \
464                                                   \
465     cyg_reason_t        sleep_reason;             \
466     cyg_reason_t        wake_reason;              \
467                                                   \
468     CYG_THREAD_THREAD_DATA_MEMBER                 \
469     CYG_THREAD_DESTRUCTORS_MEMBER                 \
470     CYG_THREAD_NAME_MEMBER                        \
471     CYG_THREAD_LIST_NEXT_MEMBER                   
472
473
474 struct cyg_thread
475 {
476     CYG_THREAD_MEMBERS
477 };
478
479 /*---------------------------------------------------------------------------*/
480
481 struct cyg_mbox
482 {
483     cyg_count32         base;           /* index of first used slot          */
484     cyg_count32         count;          /* count of used slots               */
485     cyg_threadqueue     get_threadq;    /* Queue of waiting threads          */
486 #ifdef CYGMFN_KERNEL_SYNCH_MBOXT_PUT_CAN_WAIT
487     cyg_threadqueue     put_threadq;    /* Queue of waiting threads          */
488 #endif
489     void *              itemqueue[ CYGNUM_KERNEL_SYNCH_MBOX_QUEUE_SIZE ];
490 };
491
492 /*---------------------------------------------------------------------------*/
493
494 struct cyg_sem_t
495 {
496     cyg_count32         count;          /* The semaphore count          */
497     cyg_threadqueue     queue;          /* Queue of waiting threads     */    
498 };
499
500 /*---------------------------------------------------------------------------*/
501
502 struct cyg_flag_t
503 {
504     cyg_flag_value_t    value;          /* The flag value               */
505     cyg_threadqueue     queue;          /* Queue of waiting threads     */    
506 };
507
508 /*---------------------------------------------------------------------------*/
509
510 typedef enum
511 {
512     CYG_MUTEX_PROTOCOL_NONE,
513     CYG_MUTEX_PROTOCOL_INHERIT,
514     CYG_MUTEX_PROTOCOL_CEILING
515 } cyg_mutex_protocol_t;
516
517 struct cyg_mutex_t
518 {
519     cyg_atomic          locked;         /* true if locked               */
520     cyg_thread          *owner;         /* Current locking thread       */
521     cyg_threadqueue     queue;          /* Queue of waiting threads     */
522
523 #ifdef CYGSEM_KERNEL_SYNCH_MUTEX_PRIORITY_INVERSION_PROTOCOL_DYNAMIC
524     cyg_mutex_protocol_t protocol;       /* this mutex's protocol        */
525 #endif    
526 #ifdef CYGSEM_KERNEL_SYNCH_MUTEX_PRIORITY_INVERSION_PROTOCOL_CEILING
527     cyg_priority_t      ceiling;        /* mutex priority ceiling       */
528 #endif
529     
530 };
531
532 /*---------------------------------------------------------------------------*/
533
534 struct cyg_cond_t
535 {
536     cyg_mutex_t         *mutex;         /* Associated mutex             */
537     cyg_threadqueue     queue;          /* Queue of waiting threads     */
538 };
539
540 /*------------------------------------------------------------------------*/
541
542 struct cyg_spinlock_t
543 {
544     cyg_uint32          lock;           /* lock word                     */
545 };
546
547 /*------------------------------------------------------------------------*/
548
549 /* Memory allocator types now come from the "memalloc" package which is   */
550 /* where the implementation lives.                                        */
551
552 #ifdef CYGPKG_MEMALLOC
553 # include <cyg/memalloc/kapidata.h>
554 #endif
555
556 #ifdef __cplusplus
557 }
558 #endif
559
560 /*---------------------------------------------------------------------------*/
561 /* EOF kapidata.h                                                            */
562 #endif /* CYGONCE_KERNEL_KAPIDATA_H */