pico]OS
1.0.4
Main Page
Modules
Data Structures
Files
File List
Globals
inc
picoos.h
Go to the documentation of this file.
1
/*
2
* License: Modified BSD license, see documentation below.
3
*
4
* This file is originally from the pico]OS realtime operating system
5
* (http://picoos.sourceforge.net).
6
*
7
* CVS-ID $Id: picoos.h,v 1.29 2010/02/20 13:18:52 dkuschel Exp $
8
*
9
*/
10
248
#ifndef _PICOOS_H
249
#define _PICOOS_H
250
251
252
#define POS_VER_N 0x0104
253
#define POS_VER_S "1.0.4"
254
#define POS_COPYRIGHT "(c) 2004-2012, D.Kuschel"
255
#define POS_STARTUPSTRING "pico]OS " POS_VER_S " " POS_COPYRIGHT
256
257
#ifndef NULL
258
#ifndef _HAVE_NULL
259
#define _HAVE_NULL
260
#define NULL ((void*)0)
261
#endif
262
#endif
263
264
#ifndef DOX
265
#define DOX 0
266
#endif
267
#if DOX==0
268
269
#ifndef _POSPACK
270
#ifdef __MYCPU__
271
#define PICOSUBDIR 1
272
#endif
273
#endif
274
275
#ifdef PICOSUBDIR
276
/* required because of stupid CC65 compiler */
277
#include <picoos/port.h>
278
#include <picoos/poscfg.h>
279
#else
280
#include <
port.h
>
281
#include <
poscfg.h
>
282
#endif
283
284
285
/*---------------------------------------------------------------------------
286
* CONFIGURATION
287
*-------------------------------------------------------------------------*/
288
289
/* test if all needed parameters are set */
290
#ifndef MVAR_t
291
#error MVAR_t not defined
292
#endif
293
#ifndef MVAR_BITS
294
#error MVAR_BITS not defined
295
#endif
296
#ifndef POSCFG_ALIGNMENT
297
#error POSCFG_ALIGNMENT not defined
298
#endif
299
#ifndef POSCFG_MAX_PRIO_LEVEL
300
#error POSCFG_MAX_PRIO_LEVEL not defined
301
#endif
302
#ifndef POSCFG_MAX_TASKS
303
#error POSCFG_MAX_TASKS not defined
304
#endif
305
#ifndef POSCFG_MAX_EVENTS
306
#error POSCFG_MAX_EVENTS not defined
307
#endif
308
#ifndef POSCFG_MAX_MESSAGES
309
#error POSCFG_MAX_MESSAGES not defined
310
#endif
311
#ifndef POSCFG_MAX_TIMER
312
#error POSCFG_MAX_TIMER not defined
313
#endif
314
#ifndef POSCFG_SOFT_MTASK
315
#error POSCFG_SOFT_MTASK not defined
316
#endif
317
#ifndef POSCFG_CTXSW_COMBINE
318
#error POSCFG_CTXSW_COMBINE not defined
319
#endif
320
#ifndef POSCFG_REALTIME_PRIO
321
#error POSCFG_REALTIME_PRIO not defined
322
#endif
323
#ifndef POSCFG_ISR_INTERRUPTABLE
324
#error POSCFG_ISR_INTERRUPTABLE not defined
325
#endif
326
#ifndef POSCFG_ROUNDROBIN
327
#error POSCFG_ROUNDROBIN not defined
328
#endif
329
#ifndef POSCFG_TASKS_PER_PRIO
330
#error POSCFG_TASKS_PER_PRIO not defined
331
#endif
332
#ifndef POSCFG_FASTCODE
333
#error POSCFG_FASTCODE not defined
334
#endif
335
#ifndef POSCFG_SMALLCODE
336
#error POSCFG_SMALLCODE not defined
337
#endif
338
#ifndef POSCFG_ARGCHECK
339
#error POSCFG_ARGCHECK not defined
340
#endif
341
#ifndef POSCFG_MSG_MEMORY
342
#error POSCFG_MSG_MEMORY not defined
343
#endif
344
#ifndef POSCFG_MSG_BUFSIZE
345
#error POSCFG_MSG_BUFSIZE not defined
346
#endif
347
#ifndef POSCFG_DYNAMIC_MEMORY
348
#error POSCFG_DYNAMIC_MEMORY not defined
349
#endif
350
#ifndef POSCFG_DYNAMIC_REFILL
351
#error POSCFG_DYNAMIC_REFILL
352
#endif
353
#if POSCFG_DYNAMIC_MEMORY != 0
354
#ifndef POS_MEM_ALLOC
355
#error POS_MEM_ALLOC not defined
356
#endif
357
#ifndef POS_MEM_ALLOC
358
#error POS_MEM_ALLOC not defined
359
#endif
360
#endif
361
#ifndef POSCFG_CALLINITARCH
362
#error POSCFG_CALLINITARCH not defined
363
#endif
364
#ifndef POSCFG_LOCK_USEFLAGS
365
#error POSCFG_LOCK_USEFLAGS not defined
366
#endif
367
#if POSCFG_LOCK_USEFLAGS != 0
368
#ifndef POSCFG_LOCK_FLAGSTYPE
369
#error POSCFG_LOCK_FLAGSTYPE not defined
370
#endif
371
#endif
372
#ifndef POS_SCHED_LOCK
373
#error POS_SCHED_LOCK not defined
374
#endif
375
#ifndef POS_SCHED_UNLOCK
376
#error POS_SCHED_UNLOCK not defined
377
#endif
378
#ifndef HZ
379
#error HZ not defined
380
#endif
381
#ifndef POSCFG_TASKSTACKTYPE
382
#error POSCFG_TASKSTACKTYPE not defined
383
#endif
384
#ifndef POS_USERTASKDATA
385
#error POS_USERTASKDATA not defined
386
#endif
387
#ifndef POSCFG_FEATURE_YIELD
388
#error POSCFG_FEATURE_YIELD not defined
389
#endif
390
#ifndef POSCFG_FEATURE_SLEEP
391
#error POSCFG_FEATURE_SLEEP not defined
392
#endif
393
#ifndef POSCFG_FEATURE_EXIT
394
#error POSCFG_FEATURE_EXIT not defined
395
#endif
396
#ifndef POSCFG_FEATURE_GETPRIORITY
397
#error POSCFG_FEATURE_GETPRIORITY not defined
398
#endif
399
#ifndef POSCFG_FEATURE_SETPRIORITY
400
#error POSCFG_FEATURE_SETPRIORITY not defined
401
#endif
402
#ifndef POSCFG_FEATURE_SEMAPHORES
403
#error POSCFG_FEATURE_SEMAPHORES not defined
404
#endif
405
#ifndef POSCFG_FEATURE_SEMADESTROY
406
#error POSCFG_FEATURE_SEMADESTROY not defined
407
#endif
408
#ifndef POSCFG_FEATURE_SEMAWAIT
409
#error POSCFG_FEATURE_SEMAWAIT not defined
410
#endif
411
#ifndef POSCFG_FEATURE_MUTEXES
412
#error POSCFG_FEATURE_MUTEXES not defined
413
#endif
414
#ifndef POSCFG_FEATURE_MUTEXDESTROY
415
#error POSCFG_FEATURE_MUTEXDESTROY not defined
416
#endif
417
#ifndef POSCFG_FEATURE_MUTEXTRYLOCK
418
#error POSCFG_FEATURE_MUTEXTRYLOCK not defined
419
#endif
420
#ifndef POSCFG_FEATURE_GETTASK
421
#error POSCFG_FEATURE_GETTASK not defined
422
#endif
423
#ifndef POSCFG_FEATURE_TASKUNUSED
424
#error POSCFG_FEATURE_TASKUNUSED not defined
425
#endif
426
#ifndef POSCFG_FEATURE_MSGBOXES
427
#error POSCFG_FEATURE_MSGBOXES not defined
428
#endif
429
#ifndef POSCFG_FEATURE_MSGWAIT
430
#error POSCFG_FEATURE_MSGWAIT not defined
431
#endif
432
#ifndef POSCFG_FEATURE_INHIBITSCHED
433
#error POSCFG_FEATURE_INHIBITSCHED not defined
434
#endif
435
#ifndef POSCFG_FEATURE_JIFFIES
436
#error POSCFG_FEATURE_JIFFIES not defined
437
#endif
438
#ifndef POSCFG_FEATURE_TIMER
439
#error POSCFG_FEATURE_TIMER not defined
440
#endif
441
#ifndef POSCFG_FEATURE_TIMERDESTROY
442
#error POSCFG_FEATURE_TIMERDESTROY not defined
443
#endif
444
#ifndef POSCFG_FEATURE_TIMERFIRED
445
#error POSCFG_FEATURE_TIMERFIRED not defined
446
#endif
447
#ifndef POSCFG_FEATURE_FLAGS
448
#error POSCFG_FEATURE_FLAGS not defined
449
#endif
450
#ifndef POSCFG_FEATURE_FLAGDESTROY
451
#error POSCFG_FEATURE_FLAGDESTROY not defined
452
#endif
453
#ifndef POSCFG_FEATURE_FLAGWAIT
454
#error POSCFG_FEATURE_FLAGWAIT not defined
455
#endif
456
#ifndef POSCFG_FEATURE_SOFTINTS
457
#error POSCFG_FEATURE_SOFTINTS not defined
458
#else
459
#ifndef POSCFG_FEATURE_SOFTINTDEL
460
#error POSCFG_FEATURE_SOFTINTDEL not defined
461
#endif
462
#ifndef POSCFG_SOFTINTERRUPTS
463
#error POSCFG_SOFTINTERRUPTS not defined
464
#endif
465
#ifndef POSCFG_SOFTINTQUEUELEN
466
#error POSCFG_SOFTINTQUEUELEN not defined
467
#endif
468
#endif
469
#ifndef POSCFG_FEATURE_IDLETASKHOOK
470
#error POSCFG_FEATURE_IDLETASKHOOK not defined
471
#endif
472
#ifndef POSCFG_FEATURE_ERRNO
473
#error POSCFG_FEATURE_ERRNO not defined
474
#endif
475
#ifndef POSCFG_FEATURE_ATOMICVAR
476
#error POSCFG_FEATURE_ATOMICVAR not defined
477
#endif
478
#ifndef POSCFG_FEATURE_LISTS
479
#error POSCFG_FEATURE_LISTS not defined
480
#else
481
#ifndef POSCFG_FEATURE_LISTJOIN
482
#error POSCFG_FEATURE_LISTJOIN not defined
483
#endif
484
#ifndef POSCFG_FEATURE_LISTLEN
485
#define POSCFG_FEATURE_LISTLEN 1
486
#endif
487
#endif
488
#ifndef POSCFG_FEATURE_DEBUGHELP
489
#define POSCFG_FEATURE_DEBUGHELP 0
490
#endif
491
#ifdef _DBG
492
#if POSCFG_FEATURE_DEBUGHELP
493
#define POS_DEBUGHELP
494
#endif
495
#endif
496
#ifndef POSCFG_PORTMUTEX
497
#define POSCFG_PORTMUTEX 0
498
#endif
499
#ifndef POSCFG_INT_EXIT_QUICK
500
#define POSCFG_INT_EXIT_QUICK 0
501
#endif
502
503
/* parameter range checking */
504
#if (POSCFG_DYNAMIC_MEMORY != 0) && (POSCFG_DYNAMIC_REFILL != 0)
505
#define SYS_POSTALLOCATE 1
506
#else
507
#define SYS_POSTALLOCATE 0
508
#endif
509
#if (MVAR_BITS != 8) && (MVAR_BITS != 16) && (MVAR_BITS != 32)
510
#error MVAR_BITS must be 8, 16 or 32
511
#endif
512
#if POSCFG_MAX_PRIO_LEVEL == 0
513
#error POSCFG_MAX_PRIO_LEVEL must not be zero
514
#endif
515
#if (POSCFG_ROUNDROBIN != 0) && (POSCFG_MAX_PRIO_LEVEL > MVAR_BITS)
516
#error POSCFG_MAX_PRIO_LEVEL must not exceed MVAR_BITS
517
#endif
518
#if (POSCFG_ROUNDROBIN == 0) && (POSCFG_MAX_PRIO_LEVEL > (MVAR_BITS*MVAR_BITS))
519
#error POSCFG_MAX_PRIO_LEVEL must not exceed (MVAR_BITS * MVAR_BITS)
520
#endif
521
#if (POSCFG_MAX_TASKS < 2) && (SYS_POSTALLOCATE == 0)
522
#error POSCFG_MAX_TASKS is less than 2
523
#endif
524
#if (POSCFG_MAX_TASKS > (POSCFG_TASKS_PER_PRIO * POSCFG_MAX_PRIO_LEVEL))
525
#error POSCFG_MAX_TASKS is much to big
526
#endif
527
#if (POSCFG_MAX_EVENTS < 1) && (SYS_POSTALLOCATE == 0)
528
#error POSCFG_MAX_EVENTS must be at least 1
529
#endif
530
#if POSCFG_TASKS_PER_PRIO > MVAR_BITS
531
#error POSCFG_TASKS_PER_PRIO can not exceed MVAR_BITS
532
#endif
533
#if (POSCFG_TASKS_PER_PRIO < 2) && (POSCFG_ROUNDROBIN != 0)
534
#error POSCFG_TASKS_PER_PRIO must be at least 2
535
#endif
536
#if (POSCFG_TASKS_PER_PRIO != 1) && (POSCFG_ROUNDROBIN == 0)
537
#error POSCFG_TASKS_PER_PRIO must be 1 when round robin scheduling is disabled
538
#endif
539
#if ((POSCFG_TASKS_PER_PRIO % 3) == 0) || ((POSCFG_TASKS_PER_PRIO % 5) == 0)
540
#error POSCFG_TASKS_PER_PRIO must be 1/2/4/8/16 or 32
541
#endif
542
#if (POSCFG_REALTIME_PRIO >= POSCFG_MAX_PRIO_LEVEL) && (POSCFG_ROUNDROBIN != 0)
543
#error POSCFG_REALTIME_PRIO must be less than POSCFG_MAX_PRIO_LEVEL
544
#endif
545
#if POSCFG_FEATURE_MSGBOXES != 0
546
#if (POSCFG_MAX_MESSAGES < 2) && (SYS_POSTALLOCATE == 0)
547
#error POSCFG_MAX_MESSAGES must be at least 2
548
#endif
549
#if POSCFG_MSG_BUFSIZE < 1
550
#error POSCFG_MSG_BUFSIZE must be at least 1
551
#endif
552
#endif
553
#if (POSCFG_FEATURE_TIMER != 0)
554
#if (POSCFG_MAX_TIMER == 0) && (SYS_POSTALLOCATE == 0)
555
#error POSCFG_MAX_TIMER must be at least 1
556
#endif
557
#endif
558
#if (POSCFG_TASKSTACKTYPE < 0) || (POSCFG_TASKSTACKTYPE > 2)
559
#error POSCFG_TASKSTACKTYPE must be 0, 1 or 2
560
#endif
561
#if POSCFG_ALIGNMENT == 0
562
#undef POSCFG_ALIGNMENT
563
#define POSCFG_ALIGNMENT 1
564
#else
565
#if ((POSCFG_ALIGNMENT % 3) == 0) || ((POSCFG_ALIGNMENT % 5) == 0)
566
#error POSCFG_ALIGNMENT must be 1/2/4/8/16/32/64/128/256 etc.
567
#endif
568
#endif
569
#if POSCFG_FEATURE_SOFTINTS != 0
570
#if POSCFG_SOFTINTERRUPTS == 0
571
#error POSCFG_SOFTINTERRUPTS must be greater than 0
572
#endif
573
#if POSCFG_SOFTINTQUEUELEN < 2
574
#error POSCFG_SOFTINTQUEUELEN must be at least 2
575
#endif
576
#endif
577
578
579
/* parameter reconfiguration */
580
#ifndef POSCFG_TASKCB_USERSPACE
581
#define POSCFG_TASKCB_USERSPACE 0
582
#endif
583
#if POSCFG_FEATURE_SEMAPHORES == 0
584
#undef POSCFG_FEATURE_SEMADESTROY
585
#define POSCFG_FEATURE_SEMADESTROY 0
586
#endif
587
#if POSCFG_FEATURE_FLAGS == 0
588
#undef POSCFG_FEATURE_FLAGDESTROY
589
#define POSCFG_FEATURE_FLAGDESTROY 0
590
#endif
591
#if POSCFG_FEATURE_MUTEXES == 0
592
#undef POSCFG_FEATURE_MUTEXDESTROY
593
#define POSCFG_FEATURE_MUTEXDESTROY 0
594
#else
595
#if (POSCFG_FEATURE_MUTEXDESTROY != 0) && (POSCFG_FEATURE_SEMADESTROY == 0)
596
#undef POSCFG_FEATURE_SEMADESTROY
597
#define POSCFG_FEATURE_SEMADESTROY 1
598
#endif
599
#endif
600
#if (POSCFG_FEATURE_MSGBOXES != 0) && (SYS_POSTALLOCATE == 0)
601
#define SYS_MSGBOXEVENTS 2
602
#else
603
#define SYS_MSGBOXEVENTS 0
604
#endif
605
#if (POSCFG_FEATURE_MSGBOXES != 0) && (POSCFG_FEATURE_GETTASK == 0)
606
#undef POSCFG_FEATURE_GETTASK
607
#define POSCFG_FEATURE_GETTASK 1
608
#endif
609
#if (POSCFG_FEATURE_SEMAWAIT != 0) || (POSCFG_FEATURE_MSGWAIT != 0)
610
#define SYS_TASKDOUBLELINK 1
611
#else
612
#define SYS_TASKDOUBLELINK 0
613
#endif
614
#define SYS_EVENTS_USED \
615
(POSCFG_FEATURE_MUTEXES | POSCFG_FEATURE_MSGBOXES | \
616
POSCFG_FEATURE_FLAGS | POSCFG_FEATURE_LISTS)
617
#define SYS_FEATURE_EVENTS (POSCFG_FEATURE_SEMAPHORES | SYS_EVENTS_USED)
618
#define SYS_FEATURE_EVENTFREE (POSCFG_FEATURE_SEMADESTROY | \
619
POSCFG_FEATURE_MUTEXDESTROY | POSCFG_FEATURE_FLAGDESTROY | \
620
POSCFG_FEATURE_LISTS)
621
#if (POSCFG_FEATURE_MSGBOXES != 0) && (POSCFG_FEATURE_EXIT != 0)
622
#undef SYS_FEATURE_EVENTFREE
623
#define SYS_FEATURE_EVENTFREE 1
624
#endif
625
#ifndef POSCFG_FEATURE_LARGEJIFFIES
626
#if MVAR_BITS < 16
627
#define POSCFG_FEATURE_LARGEJIFFIES 1
628
#else
629
#define POSCFG_FEATURE_LARGEJIFFIES 0
630
#endif
631
#endif
632
#ifndef POSCALL
633
#define POSCALL
634
#endif
635
#if POSCFG_FEATURE_SETPRIORITY != 0
636
#define SYS_TASKEVENTLINK 1
637
#else
638
#define SYS_TASKEVENTLINK 0
639
#endif
640
641
#endif
/* DOX!=0 */
642
643
644
645
/*---------------------------------------------------------------------------
646
* SOME DEFINITIONS AND MACROS
647
*-------------------------------------------------------------------------*/
648
649
#ifdef _POSCORE_C
650
#define POSEXTERN
651
#define POSFROMEXT extern
652
#else
653
#define POSEXTERN extern
654
#define POSFROMEXT
655
#endif
656
657
#if POSCFG_ROUNDROBIN == 0
658
#define SYS_TASKTABSIZE_X MVAR_BITS
659
#define SYS_TASKTABSIZE_Y ((POSCFG_MAX_PRIO_LEVEL+MVAR_BITS-1)/MVAR_BITS)
660
#else
661
#define SYS_TASKTABSIZE_X POSCFG_TASKS_PER_PRIO
662
#define SYS_TASKTABSIZE_Y POSCFG_MAX_PRIO_LEVEL
663
#endif
664
665
#define SYS_TASKSTATE (POSCFG_FEATURE_TASKUNUSED | POSCFG_FEATURE_MSGBOXES)
666
667
#if POSCFG_LOCK_USEFLAGS != 0
668
#define POS_LOCKFLAGS POSCFG_LOCK_FLAGSTYPE flags
669
#else
670
#define POS_LOCKFLAGS do { } while(0)
671
#endif
672
673
#define POSTASKSTATE_UNUSED 0
674
#define POSTASKSTATE_ZOMBIE 1
675
#define POSTASKSTATE_ACTIVE 2
676
677
#define INFINITE ((UINT_t)~0)
678
679
680
681
/*---------------------------------------------------------------------------
682
* ERROR CODES
683
*-------------------------------------------------------------------------*/
684
699
#define E_OK 0
700
702
#define E_FAIL 1
703
705
#define E_NOMEM 2
706
708
#define E_ARG 3
709
711
#define E_FORB 4
712
714
#define E_NOMORE 5
715
717
#define E_NOTFOUND 6
718
723
/*---------------------------------------------------------------------------
724
* MACROS
725
*-------------------------------------------------------------------------*/
726
732
#if (DOX==0) && (HZ <= 1000)
733
#define MS(msec) (((msec)<(1000/HZ)) ? \
734
((UINT_t)1) : ((UINT_t)((1L*HZ*(msec))/1000)))
735
#else
736
#define MS(msec) ((UINT_t)((1L*HZ*(msec))/1000))
737
#endif
738
739
740
741
/*---------------------------------------------------------------------------
742
* DATA TYPES
743
*-------------------------------------------------------------------------*/
744
750
typedef
signed
MVAR_t
VAR_t
;
751
757
typedef
unsigned
MVAR_t
UVAR_t
;
758
759
#ifndef MINT_t
760
#define MINT_t int
761
#endif
762
771
typedef
signed
MINT_t
INT_t
;
772
782
typedef
unsigned
MINT_t
UINT_t
;
783
784
#ifndef MPTR_t
785
#define MPTR_t long
786
#endif
787
798
typedef
unsigned
MPTR_t
MEMPTR_t
;
799
800
#if (DOX!=0) || (POSCFG_FEATURE_LARGEJIFFIES == 0)
801
804
typedef
VAR_t
SJIF_t
;
808
typedef
UVAR_t
JIF_t
;
809
#else
810
typedef
INT_t
SJIF_t
;
811
typedef
UINT_t
JIF_t
;
812
#endif
813
817
typedef
void (*
POSTASKFUNC_t
)(
void
* arg);
818
825
typedef
void (*
POSINTFUNC_t
)(
UVAR_t
arg);
826
827
#if (DOX!=0) ||(POSCFG_FEATURE_IDLETASKHOOK != 0)
828
829
typedef
void (*
POSIDLEFUNC_t
)(void);
830
#endif
831
832
/* forward declarations (just dummies) */
833
struct
POSSEMA;
834
struct
POSMUTEX;
835
struct
POSFLAG;
836
struct
POSTIMER;
837
841
typedef
struct
POSSEMA *
POSSEMA_t
;
842
846
typedef
struct
POSMUTEX *
POSMUTEX_t
;
847
851
typedef
struct
POSFLAG *
POSFLAG_t
;
852
856
typedef
struct
POSTIMER *
POSTIMER_t
;
857
861
typedef
volatile
INT_t
POSATOMIC_t
;
862
863
#if (DOX!=0) || (POSCFG_FEATURE_LISTS != 0)
864
struct
POSLIST;
865
struct
POSLISTHEAD {
866
struct
POSLIST*
volatile
prev;
867
struct
POSLIST*
volatile
next;
868
POSSEMA_t
volatile
sema;
869
UVAR_t
volatile
flag;
870
#if POSCFG_FEATURE_LISTLEN != 0
871
UINT_t
volatile
length;
872
#endif
873
};
874
struct
POSLIST {
875
struct
POSLIST*
volatile
prev;
876
struct
POSLIST*
volatile
next;
877
#if POSCFG_FEATURE_LISTLEN != 0
878
struct
POSLISTHEAD*
volatile
head;
879
#endif
880
};
885
typedef
struct
POSLIST
POSLIST_t
;
890
typedef
struct
POSLISTHEAD
POSLISTHEAD_t
;
891
#endif
892
893
913
typedef
struct
POSTASK *
POSTASK_t
;
/* forward declaration */
914
915
916
917
/*---------------------------------------------------------------------------
918
* DEFINITIONS FOR GENERIC "findbit" FUNCTION (file fbit_gen.c)
919
*-------------------------------------------------------------------------*/
920
921
#ifndef POSCFG_FBIT_USE_LUTABLE
922
#define POSCFG_FBIT_USE_LUTABLE 0
923
#endif
924
#if (POSCFG_FBIT_USE_LUTABLE > 1) && (POSCFG_ROUNDROBIN == 0)
925
#undef POSCFG_FBIT_USE_LUTABLE
926
#define POSCFG_FBIT_USE_LUTABLE 1
927
#endif
928
#ifndef FINDBIT
929
#if POSCFG_FBIT_USE_LUTABLE == 1
930
#if POSCFG_ROUNDROBIN == 0
931
#ifndef _FBIT_GEN_C
932
extern
VAR_t
const
p_pos_fbittbl[256];
933
#endif
934
#define FINDBIT(x) p_pos_fbittbl[x]
935
#else
936
UVAR_t
POSCALL
p_pos_findbit
(
const
UVAR_t
bitfield,
UVAR_t
rrOffset);
937
#define FINDBIT(x, o) p_pos_findbit(x, o)
938
#endif
939
#elif POSCFG_FBIT_USE_LUTABLE == 2
940
#ifndef _FBIT_GEN_C
941
extern
VAR_t
const
p_pos_fbittbl_rr[8][256];
942
#endif
943
#define FINDBIT(x, o) p_pos_fbittbl_rr[o][x]
944
#endif
945
#endif
/* !FINDBIT */
946
947
948
949
/*---------------------------------------------------------------------------
950
* GLOBAL VARIABLES
951
*-------------------------------------------------------------------------*/
952
961
POSEXTERN
volatile
POSTASK_t
posCurrentTask_g
;
962
971
POSEXTERN
volatile
POSTASK_t
posNextTask_g
;
972
979
#ifndef _POSCORE_C
980
POSEXTERN
volatile
UVAR_t
posInInterrupt_g
;
981
#else
982
POSEXTERN
volatile
UVAR_t
posInInterrupt_g
= 1;
983
#endif
984
991
#ifndef _POSCORE_C
992
POSEXTERN
volatile
UVAR_t
posRunning_g
;
993
#else
994
POSEXTERN
volatile
UVAR_t
posRunning_g
= 0;
995
#endif
996
997
998
#if DOX!=0
999
1004
VAR_t
errno
;
1005
#endif
1006
#if POSCFG_FEATURE_ERRNO != 0
1007
#ifdef errno
1008
#undef errno
1009
#endif
1010
POSEXTERN
VAR_t
* _errno_p(
void
);
1011
#define errno (*_errno_p())
1012
#endif
1013
1014
1015
1016
/*---------------------------------------------------------------------------
1017
* PROTOTYPES OF INTERNAL FUNCTIONS
1018
*-------------------------------------------------------------------------*/
1019
1154
/* findbit function or macro definition */
1155
#if (DOX!=0) || (POSCFG_ROUNDROBIN == 0)
1156
#ifdef FINDBIT
1157
#define POS_FINDBIT(bf) FINDBIT(bf, 0)
1158
#define POS_FINDBIT_EX(bf, ofs) FINDBIT(bf, 0)
1159
#else
/* FINDBIT */
1160
POSFROMEXT
UVAR_t
POSCALL
p_pos_findbit
(
const
UVAR_t
bitfield);
/* arch_c.c */
1161
#define POS_FINDBIT(bf) p_pos_findbit(bf)
1162
#define POS_FINDBIT_EX(bf, ofs) p_pos_findbit(bf)
1163
#endif
/* FINDBIT */
1164
#else
/* POSCFG_ROUNDROBIN */
1165
#ifdef FINDBIT
1166
#define POS_FINDBIT(bf) FINDBIT(bf, 0)
1167
#define POS_FINDBIT_EX(bf, ofs) FINDBIT(bf, ofs)
1168
#else
/* FINDBIT */
1169
POSFROMEXT
UVAR_t
POSCALL
p_pos_findbit
(
const
UVAR_t
bitfield,
UVAR_t
rrOffset);
/* arch_c.c */
1170
#define POS_FINDBIT(bf) p_pos_findbit(bf, 0)
1171
#define POS_FINDBIT_EX(bf, ofs) p_pos_findbit(bf, ofs)
1172
#endif
/* FINDBIT */
1173
#endif
/* POSCFG_ROUNDROBIN */
1174
1175
#if DOX!=0
1176
1185
POSFROMEXT
UVAR_t
POSCALL
p_pos_findbit
(
const
UVAR_t
bitfield);
1186
1197
POSFROMEXT
UVAR_t
POSCALL
p_pos_findbit
(
const
UVAR_t
bitfield,
UVAR_t
rrOffset);
1198
#endif
1199
1200
#if (DOX!=0) || (POSCFG_CALLINITARCH != 0)
1201
1212
POSFROMEXT
void
POSCALL
p_pos_initArch
(
void
);
1213
#endif
1214
1215
#if (DOX!=0) || (POSCFG_TASKSTACKTYPE == 0)
1216
1235
POSFROMEXT
void
POSCALL
p_pos_initTask
(
POSTASK_t
task,
void
*stackstart,
1236
POSTASKFUNC_t
funcptr,
1237
void
*funcarg);
/* arch_c.c */
1238
#endif
1239
#if (DOX!=0) || (POSCFG_TASKSTACKTYPE == 1)
1240
1264
POSFROMEXT
VAR_t
POSCALL
p_pos_initTask
(
POSTASK_t
task,
UINT_t
stacksize,
1265
POSTASKFUNC_t
funcptr,
1266
void
*funcarg);
/* arch_c.c */
1285
POSFROMEXT
void
POSCALL
p_pos_freeStack
(
POSTASK_t
task);
/* arch_c.c */
1286
#endif
1287
1288
#if (DOX!=0) || (POSCFG_PORTMUTEX != 0)
1289
1297
POSFROMEXT
void
POSCALL
p_pos_lock
(
void
);
/* arch_c.c */
1298
1302
POSFROMEXT
void
POSCALL
p_pos_unlock
(
void
);
/* arch_c.c */
1303
#endif
1304
1305
#if (DOX!=0) || (POSCFG_TASKSTACKTYPE == 2)
1306
1329
POSFROMEXT
VAR_t
POSCALL
p_pos_initTask
(
POSTASK_t
task,
POSTASKFUNC_t
funcptr,
1330
void
*funcarg);
/* arch_c.c */
1331
1348
POSFROMEXT
void
POSCALL
p_pos_freeStack
(
POSTASK_t
task);
/* arch_c.c */
1349
#endif
1350
1364
POSFROMEXT
void
POSCALL
p_pos_startFirstContext
(
void
);
/* arch_c.c */
1365
1380
POSFROMEXT
void
POSCALL
p_pos_softContextSwitch
(
void
);
/* arch_c.c */
1381
1395
POSFROMEXT
void
POSCALL
p_pos_intContextSwitch
(
void
);
/* arch_c.c */
1396
1397
#if (DOX!=0) || POSCFG_INT_EXIT_QUICK == 1
1398
1411
POSFROMEXT
void
POSCALL
p_pos_intContextSwitchPending
(
void
);
/* arch_c.c */
1412
1413
#endif
1414
1423
POSEXTERN
void
POSCALL
c_pos_intEnter
(
void
);
/* picoos.c */
1424
1433
POSEXTERN
void
POSCALL
c_pos_intExit
(
void
);
/* picoos.c */
1434
1435
#if (DOX!=0) || POSCFG_INT_EXIT_QUICK == 1
1436
1447
POSEXTERN
void
POSCALL
c_pos_intExitQuick
(
void
);
/* picoos.c */
1448
1449
#endif
1450
1483
POSEXTERN
void
POSCALL
c_pos_timerInterrupt
(
void
);
/* picoos.c */
1484
1489
/*---------------------------------------------------------------------------
1490
* PROTOTYPES OF EXPORTED FUNCTIONS (USER API)
1491
*-------------------------------------------------------------------------*/
1492
1498
#if (DOX!=0) || (POSCFG_FEATURE_YIELD != 0)
1499
1507
POSEXTERN
void
POSCALL
posTaskYield
(
void
);
1508
#endif
1509
1510
#if (DOX!=0) || (POSCFG_FEATURE_SLEEP != 0)
1511
1525
POSEXTERN
void
POSCALL
posTaskSleep
(
UINT_t
ticks);
1526
#endif
1527
1528
#if (DOX!=0) || (POSCFG_TASKSTACKTYPE == 0)
1529
1545
POSEXTERN
POSTASK_t
POSCALL
posTaskCreate
(
POSTASKFUNC_t
funcptr,
void
*funcarg,
1546
VAR_t
priority,
void
*stackstart);
1547
1563
POSEXTERN
void
POSCALL posInit(
POSTASKFUNC_t
firstfunc,
void
*funcarg,
1564
VAR_t
priority,
1565
void
*stackFirstTask,
void
*stackIdleTask);
1566
#endif
1567
#if (DOX!=0) || (POSCFG_TASKSTACKTYPE == 1)
1568
1587
POSEXTERN
POSTASK_t
POSCALL
posTaskCreate
(
POSTASKFUNC_t
funcptr,
void
*funcarg,
1588
VAR_t
priority,
UINT_t
stacksize);
1589
1605
POSEXTERN
void
POSCALL posInit(
POSTASKFUNC_t
firstfunc,
void
*funcarg,
1606
VAR_t
priority,
UINT_t
taskStackSize,
1607
UINT_t
idleStackSize);
1608
#endif
1609
#if (DOX!=0) || (POSCFG_TASKSTACKTYPE == 2)
1610
1626
POSEXTERN
POSTASK_t
POSCALL
posTaskCreate
(
POSTASKFUNC_t
funcptr,
void
*funcarg,
1627
VAR_t
priority);
1628
1642
POSEXTERN
void
POSCALL posInit(
POSTASKFUNC_t
firstfunc,
void
*funcarg,
1643
VAR_t
priority);
1644
1645
#endif
1646
1647
1648
#if (DOX!=0) || (POSCFG_FEATURE_EXIT != 0)
1649
1656
POSEXTERN
void
POSCALL
posTaskExit
(
void
);
1657
#endif
1658
1659
#if (DOX!=0) || (POSCFG_FEATURE_GETTASK != 0)
1660
1668
POSEXTERN
POSTASK_t
POSCALL
posTaskGetCurrent
(
void
);
1669
#endif
1670
1671
#if (DOX!=0) || (POSCFG_FEATURE_TASKUNUSED != 0)
1672
1685
POSEXTERN
VAR_t
POSCALL
posTaskUnused
(
POSTASK_t
taskhandle);
1686
#endif
1687
1688
#if (DOX!=0) || (POSCFG_FEATURE_SETPRIORITY != 0)
1689
1702
POSEXTERN
VAR_t
POSCALL
posTaskSetPriority
(
POSTASK_t
taskhandle,
1703
VAR_t
priority);
1704
#endif
1705
1706
#if (DOX!=0) || (POSCFG_FEATURE_GETPRIORITY != 0)
1707
1716
POSEXTERN
VAR_t
POSCALL
posTaskGetPriority
(
POSTASK_t
taskhandle);
1717
#endif
1718
1719
#if (DOX!=0) || (POSCFG_FEATURE_INHIBITSCHED != 0)
1720
1731
POSEXTERN
void
POSCALL
posTaskSchedLock
(
void
);
1732
1742
POSEXTERN
void
POSCALL
posTaskSchedUnlock
(
void
);
1743
#endif
1744
1745
#if (DOX!=0) || (POSCFG_TASKCB_USERSPACE > 0)
1746
1754
POSEXTERN
void
* POSCALL
posTaskGetUserspace
(
void
);
1755
#endif
1756
1757
#if (DOX!=0) || (POSCFG_FEATURE_IDLETASKHOOK != 0)
1758
1776
POSEXTERN
POSIDLEFUNC_t
POSCALL
posInstallIdleTaskHook
(
POSIDLEFUNC_t
idlefunc);
1777
#endif
1778
1781
/*-------------------------------------------------------------------------*/
1782
1783
#if (DOX!=0) || (SYS_FEATURE_EVENTS != 0)
1784
1823
POSEXTERN
POSSEMA_t
POSCALL
posSemaCreate
(
INT_t
initcount);
1824
1825
#if (DOX!=0) || (SYS_FEATURE_EVENTFREE != 0)
1826
1836
POSEXTERN
void
POSCALL
posSemaDestroy
(
POSSEMA_t
sema);
1837
#endif
1838
1851
#if (DOX!=0) || (POSCFG_SMALLCODE == 0) || (POSCFG_FEATURE_SEMAWAIT == 0)
1852
POSEXTERN
VAR_t
POSCALL
posSemaGet
(
POSSEMA_t
sema);
1853
#else
1854
/* this define is for small code and it saves stack memory */
1855
#define posSemaGet(sema) posSemaWait(sema, INFINITE)
1856
#endif
1857
1869
POSEXTERN
VAR_t
POSCALL
posSemaSignal
(
POSSEMA_t
sema);
1870
1871
#if (DOX!=0) || (POSCFG_FEATURE_SEMAWAIT != 0)
1872
1892
POSEXTERN
VAR_t
POSCALL
posSemaWait
(
POSSEMA_t
sema,
UINT_t
timeoutticks);
1893
#endif
1894
1895
#endif
/* SYS_FEATURE_EVENTS */
1896
1898
/*-------------------------------------------------------------------------*/
1899
1900
#if (DOX!=0) || (POSCFG_FEATURE_MUTEXES != 0)
1901
1922
POSEXTERN
POSMUTEX_t
POSCALL
posMutexCreate
(
void
);
1923
1924
#if (DOX!=0) || (POSCFG_FEATURE_MUTEXDESTROY != 0)
1925
1935
POSEXTERN
void
POSCALL
posMutexDestroy
(
POSMUTEX_t
mutex);
1936
#endif
1937
1938
#if (DOX!=0) || (POSCFG_FEATURE_MUTEXTRYLOCK != 0)
1939
1954
POSEXTERN
VAR_t
POSCALL
posMutexTryLock
(
POSMUTEX_t
mutex);
1955
#endif
1956
1969
POSEXTERN
VAR_t
POSCALL
posMutexLock
(
POSMUTEX_t
mutex);
1970
1981
POSEXTERN
VAR_t
POSCALL
posMutexUnlock
(
POSMUTEX_t
mutex);
1982
1983
#endif
/* POSCFG_FEATURE_MUTEXES */
1984
1986
/*-------------------------------------------------------------------------*/
1987
1988
#if (DOX!=0) || (POSCFG_FEATURE_MSGBOXES != 0)
1989
2011
#if (DOX!=0) || (POSCFG_MSG_MEMORY != 0)
2012
2025
POSEXTERN
void
* POSCALL
posMessageAlloc
(
void
);
2026
2039
POSEXTERN
void
POSCALL
posMessageFree
(
void
*buf);
2040
#endif
2041
2059
POSEXTERN
VAR_t
POSCALL
posMessageSend
(
void
*buf,
POSTASK_t
taskhandle);
2060
2076
#if (DOX!=0) || (POSCFG_SMALLCODE == 0) || (POSCFG_FEATURE_MSGWAIT == 0)
2077
POSEXTERN
void
* POSCALL
posMessageGet
(
void
);
2078
#else
2079
/* this define is for small code and it saves stack memory */
2080
#define posMessageGet() posMessageWait(INFINITE)
2081
#endif
2082
2095
POSEXTERN
VAR_t
POSCALL
posMessageAvailable
(
void
);
2096
2097
#if (DOX!=0) || (POSCFG_FEATURE_MSGWAIT != 0)
2098
2123
POSEXTERN
void
* POSCALL
posMessageWait
(
UINT_t
timeoutticks);
2124
#endif
2125
2126
#endif
/* POSCFG_FEATURE_MSGBOXES */
2127
2129
/*-------------------------------------------------------------------------*/
2130
2131
#if (DOX!=0) || (POSCFG_FEATURE_FLAGS != 0)
2132
2152
POSEXTERN
POSFLAG_t
POSCALL
posFlagCreate
(
void
);
2153
2154
#if (DOX!=0) || (POSCFG_FEATURE_FLAGDESTROY != 0)
2155
2165
POSEXTERN
void
POSCALL
posFlagDestroy
(
POSFLAG_t
flg);
2166
#endif
2167
2180
POSEXTERN
VAR_t
POSCALL
posFlagSet
(
POSFLAG_t
flg,
UVAR_t
flgnum);
2181
2196
POSEXTERN
VAR_t
POSCALL
posFlagGet
(
POSFLAG_t
flg,
UVAR_t
mode);
2197
2198
#if (DOX!=0) || (POSCFG_FEATURE_FLAGWAIT != 0)
2199
2218
POSEXTERN
VAR_t
POSCALL
posFlagWait
(
POSFLAG_t
flg,
UINT_t
timeoutticks);
2219
#endif
2220
2221
#define POSFLAG_MODE_GETSINGLE 0
2222
#define POSFLAG_MODE_GETMASK 1
2223
2224
#endif
/* POSCFG_FEATURE_FLAGS */
2225
2227
/*-------------------------------------------------------------------------*/
2228
2250
#if DOX!=0
2251
#define HZ (timerticks per second)
2252
#endif
2253
2263
#if (DOX!=0) || (POSCFG_FEATURE_JIFFIES != 0)
2264
#if (DOX!=0) || (POSCFG_FEATURE_LARGEJIFFIES == 0)
2265
POSEXTERN
volatile
JIF_t
jiffies
;
2266
#else
2267
POSEXTERN
JIF_t
POSCALL posGetJiffies(
void
);
2268
#define jiffies posGetJiffies()
2269
#endif
2270
2281
#define POS_TIMEAFTER(x, y) ((((SJIF_t)(x)) - ((SJIF_t)(y))) >= 0)
2282
2283
#endif
/* POSCFG_FEATURE_JIFFIES */
2284
2285
#if (DOX!=0) || (POSCFG_FEATURE_TIMER != 0)
2286
2296
POSEXTERN
POSTIMER_t
POSCALL
posTimerCreate
(
void
);
2297
2315
POSEXTERN
VAR_t
POSCALL
posTimerSet
(
POSTIMER_t
tmr,
POSSEMA_t
sema,
2316
UINT_t
waitticks,
UINT_t
periodticks);
2328
POSEXTERN
VAR_t
POSCALL
posTimerStart
(
POSTIMER_t
tmr);
2329
2340
POSEXTERN
VAR_t
POSCALL
posTimerStop
(
POSTIMER_t
tmr);
2341
2342
#if (DOX!=0) || (POSCFG_FEATURE_TIMERDESTROY != 0)
2343
2353
POSEXTERN
void
POSCALL
posTimerDestroy
(
POSTIMER_t
tmr);
2354
#endif
2355
#if (DOX!=0) || (POSCFG_FEATURE_TIMERFIRED != 0)
2356
2368
POSEXTERN
VAR_t
POSCALL
posTimerFired
(
POSTIMER_t
tmr);
2369
#endif
2370
2371
#endif
/* POSCFG_FEATURE_TIMER */
2372
2374
/*-------------------------------------------------------------------------*/
2375
2376
#if (DOX!=0) || (POSCFG_FEATURE_SOFTINTS != 0)
2377
2423
POSEXTERN
void
POSCALL
posSoftInt
(
UVAR_t
intno,
UVAR_t
param);
2424
2438
POSEXTERN
VAR_t
POSCALL
posSoftIntSetHandler
(
UVAR_t
intno,
2439
POSINTFUNC_t
inthandler);
2440
2441
#if (DOX!=0) || (POSCFG_FEATURE_SOFTINTDEL != 0)
2442
2455
POSEXTERN
VAR_t
POSCALL
posSoftIntDelHandler
(
UVAR_t
intno);
2456
#endif
2457
2458
#endif
/* POSCFG_FEATURE_SOFTINTS */
2459
2461
/*-------------------------------------------------------------------------*/
2462
2463
#if (DOX!=0) || (POSCFG_FEATURE_ATOMICVAR != 0)
2464
2489
POSEXTERN
void
POSCALL
posAtomicSet
(
POSATOMIC_t
*var,
INT_t
value);
2490
2501
POSEXTERN
INT_t
POSCALL
posAtomicGet
(
POSATOMIC_t
*var);
2502
2513
POSEXTERN
INT_t
POSCALL
posAtomicAdd
(
POSATOMIC_t
*var,
INT_t
value);
2514
2525
POSEXTERN
INT_t
POSCALL
posAtomicSub
(
POSATOMIC_t
*var,
INT_t
value);
2526
2527
#endif
/* POSCFG_FEATURE_ATOMICVAR */
2528
2531
/*-------------------------------------------------------------------------*/
2532
2533
#if (DOX!=0) || (POSCFG_FEATURE_LISTS != 0)
2534
2549
#define POSLIST_HEAD 0
2550
#define POSLIST_TAIL 1
2551
2567
POSEXTERN
void
POSCALL
posListAdd
(
POSLISTHEAD_t
*listhead,
UVAR_t
pos,
2568
POSLIST_t
*
new
);
2569
2601
POSEXTERN
POSLIST_t
* POSCALL
posListGet
(
POSLISTHEAD_t
*listhead,
UVAR_t
pos,
2602
UINT_t
timeout);
2603
2612
POSEXTERN
void
POSCALL
posListRemove
(
POSLIST_t
*listelem);
2613
2614
#if (DOX!=0) || (POSCFG_FEATURE_LISTJOIN != 0)
2615
2634
POSEXTERN
void
POSCALL
posListJoin
(
POSLISTHEAD_t
*baselisthead,
UVAR_t
pos,
2635
POSLISTHEAD_t
*joinlisthead);
2636
#endif
2637
2638
#if (DOX!=0) || (POSCFG_FEATURE_LISTLEN != 0)
2639
2650
POSEXTERN
UINT_t
POSCALL
posListLen
(
POSLISTHEAD_t
*listhead);
2651
#endif
2652
2664
POSEXTERN
void
POSCALL
posListInit
(
POSLISTHEAD_t
*listhead);
2665
2673
POSEXTERN
void
POSCALL
posListTerm
(
POSLISTHEAD_t
*listhead);
2674
2675
#if (DOX!=0)
2676
2688
#define POSLIST_ELEMENT(elem, type, member)
2689
#else
2690
#define POSLIST_ELEMENT(elem, type, member) \
2691
((type*)((char*)(elem)-(char*)(&((type*)NULL)->member)))
2692
#endif
2693
2697
#define POSLIST_IS_EMPTY(plisthead) \
2698
((plisthead)->next == (POSLIST_t*)(plisthead))
2699
2703
#define POSLIST_NEXT_ENTRY(plist) (plist)->next
2704
2708
#define POSLIST_PREV_ENTRY(plist) (plist)->prev
2709
2713
#define POSLIST_FIRST_ENTRY(plisthead) (plisthead)->next
2714
2718
#define POSLIST_LAST_ENTRY(plisthead) (plisthead)->prev
2719
2723
#define POSLIST_IS_FIRST_ENTRY(element) ((element)->prev==(element)->head)
2724
2728
#define POSLIST_IS_LAST_ENTRY(element) ((element)->next==(element)->head)
2729
2732
#define POSLIST_IS_END(plisthead, element) \
2733
((element)==(POSLIST_t*)(plisthead))
2734
2735
2736
#if (DOX!=0)
2737
2753
#define POSLIST_FOR_EACH_ENTRY(plisthead, runvar)
2754
#else
2755
#define POSLIST_FOR_EACH_ENTRY(plisthead, runvar) \
2756
for (runvar = POSLIST_FIRST_ENTRY(plisthead); \
2757
!POSLIST_IS_END(plisthead, runvar); \
2758
runvar = POSLIST_NEXT_ENTRY(runvar))
2759
#endif
2760
2761
#if (DOX!=0)
2762
2783
#define POSLIST_FOREACH_BEGIN(plisthead, runvar, type, listmember)
2784
#else
2785
#define POSLIST_FOREACH_BEGIN(plisthead, runvar, type, listmember) \
2786
do { POSLIST_t *r, *n; \
2787
for (r = POSLIST_FIRST_ENTRY(plisthead); \
2788
!POSLIST_IS_END(plisthead, r); r = n) { \
2789
n = POSLIST_NEXT_ENTRY(r); \
2790
runvar = POSLIST_ELEMENT(r, type, listmember);
2791
#endif
2792
2793
#if (DOX!=0)
2794
2800
#define POSLIST_FOREACH_END
2801
#else
2802
#define POSLIST_FOREACH_END \
2803
} } while(0)
2804
#endif
2805
2806
#endif
/* POSCFG_FEATURE_LISTS */
2807
2810
/*---------------------------------------------------------------------------
2811
* DEBUG FEATURES
2812
*-------------------------------------------------------------------------*/
2813
2858
#if (DOX!=0) || defined(HAVE_PLATFORM_ASSERT)
2859
2867
#define P_ASSERT(text,x) \
2868
if (!(x)) POSCALL p_pos_assert((const char*)(text), __FILE__, __LINE__)
2869
#else
2870
#define P_ASSERT(text,x) do { } while(0)
2871
#endif
2872
2873
#if (DOX!=0) || defined(POS_DEBUGHELP)
2874
2879
enum
PTASKSTATE
2880
{
2881
task_notExisting
= 0,
2882
task_created
= 1,
2883
task_running
= 2,
2884
task_suspended
= 3,
2885
task_sleeping
= 4,
2886
task_waitingForSemaphore
= 5,
2887
task_waitingForSemaphoreWithTimeout
= 6,
2889
task_waitingForMutex
= 7,
2890
task_waitingForMutexWithTimeout
= 8,
2892
task_waitingForFlag
= 9,
2893
task_waitingForFlagWithTimeout
= 10,
2895
task_waitingForMessage
= 11,
2896
task_waitingForMessageWithTimeout
= 12
2898
};
2899
typedef
enum
PTASKSTATE
PTASKSTATE
;
2900
2905
enum
PEVENTTYPE
2906
{
2907
event_semaphore
= 0,
2908
event_mutex
= 1,
2909
event_flags
= 2
2910
};
2911
typedef
enum
PEVENTTYPE
PEVENTTYPE
;
2912
2922
typedef
struct
PICOEVENT
2923
{
2924
struct
PICOEVENT
*
next
;
2926
struct
PICOEVENT
*
prev
;
2928
#if DOX
2929
PEVENTTYPE
type
;
2932
#else
2933
enum
PEVENTTYPE
type
;
2934
#endif
2935
void
*
handle
;
2937
const
char
*
name
;
2939
INT_t
counter
;
2943
}
PICOEVENT
;
2944
2954
typedef
struct
PICOTASK
2955
{
2956
struct
PICOTASK
*
next
;
2958
struct
PICOTASK
*
prev
;
2960
POSTASK_t
handle
;
2962
POSTASKFUNC_t
func
;
2964
const
char
*
name
;
2966
#if DOX
2967
PTASKSTATE
state
;
2970
#else
2971
enum
PTASKSTATE
state
;
2972
#endif
2973
struct
PICOEVENT
*
event
;
2975
UINT_t
timeout
;
2977
}
PICOTASK
;
2978
2979
#if DOX
2980
3002
#define POS_SETTASKNAME(taskhandle, taskname)
3003
3023
#define POS_SETEVENTNAME(eventhandle, name)
3024
3025
#else
3026
#define POS_SETTASKNAME(taskhandle, taskname) \
3027
do { if ((taskhandle) != NULL) (taskhandle)->deb.name = taskname;} while(0)
3028
#define POS_SETEVENTNAME(eventhandle, name) \
3029
posdeb_setEventName(eventhandle, name)
3030
POSEXTERN
void
posdeb_setEventName(
void
*event,
const
char
*
name
);
3031
#endif
3032
3033
#ifdef _POSCORE_C
3034
struct
PICOTASK
*
picodeb_taskhistory
[3];
3035
struct
PICOTASK
*
picodeb_tasklist
= NULL;
3036
struct
PICOEVENT
*
picodeb_eventlist
= NULL;
3037
#else
3038
3052
extern
struct
PICOTASK
*picodeb_taskhistory[3];
3053
3066
extern
struct
PICOTASK
*
picodeb_tasklist
;
3067
3082
extern
struct
PICOEVENT
*
picodeb_eventlist
;
3083
#endif
3084
3085
#else
/* POS_DEBUGHELP */
3086
3087
#define POS_SETTASKNAME(taskhandle, name) do { } while(0)
3088
#define POS_SETEVENTNAME(eventhandle, name) do { } while(0)
3089
3090
#endif
/* POS_DEBUGHELP */
3091
3094
/* ==== END OF USER API ==== */
3095
3096
3097
3098
/*---------------------------------------------------------------------------
3099
* INTERNAL DEFINITIONS
3100
*-------------------------------------------------------------------------*/
3101
3102
#ifdef PICOS_PRIVINCL
3103
3104
#if MVAR_BITS == 8
3105
#ifndef _POSCORE_C
3106
POSEXTERN
UVAR_t
posShift1lTab_g[8];
3107
#endif
3108
#define pos_shift1l(bits) posShift1lTab_g[(UVAR_t)(bits)]
3109
#else
3110
#define pos_shift1l(bits) (((UVAR_t)1)<<(bits))
3111
#endif
3112
3113
#endif
/* PICOS_PRIV_H */
3114
3115
/*-------------------------------------------------------------------------*/
3116
3117
/* include the header of the nano layer */
3118
3119
#ifdef POSNANO
3120
#ifdef POSCFG_ENABLE_NANO
3121
#undef POSCFG_ENABLE_NANO
3122
#endif
3123
#define POSCFG_ENABLE_NANO 1
3124
#else
3125
#ifndef POSCFG_ENABLE_NANO
3126
#define POSCFG_ENABLE_NANO 0
3127
#endif
3128
#endif
3129
#if POSCFG_ENABLE_NANO != 0
3130
#ifdef PICOSUBDIR
3131
/* required because of stupid CC65 compiler */
3132
#include <picoos\pos_nano.h>
3133
#else
3134
#include <
pos_nano.h
>
3135
#endif
3136
#endif
3137
3138
/*-------------------------------------------------------------------------*/
3139
3140
/* defaults for hooks */
3141
3142
#ifndef POSCFG_TASKEXIT_HOOK
3143
#define POSCFG_TASKEXIT_HOOK 0
3144
#endif
3145
3146
/*-------------------------------------------------------------------------*/
3147
3148
/* fully define the task structure */
3149
3150
#ifndef NOS_TASKDATA
3151
#define NOS_TASKDATA
3152
#endif
3153
3154
#if POSCFG_TASKEXIT_HOOK != 0
3155
typedef
enum
{
3156
texh_exitcalled,
3157
texh_freestackmem
3158
} texhookevent_t;
3159
typedef
void (*POSTASKEXITFUNC_t)(
POSTASK_t
task, texhookevent_t event);
3160
#endif
3161
3162
struct
POSTASK {
3163
POS_USERTASKDATA
3164
NOS_TASKDATA
3165
#if POSCFG_TASKCB_USERSPACE > 0
3166
UVAR_t
usrspace[(
POSCFG_TASKCB_USERSPACE
+
POSCFG_ALIGNMENT
+
3167
sizeof
(
UVAR_t
)-2) /
sizeof
(
UVAR_t
)];
3168
#endif
3169
#if POSCFG_TASKEXIT_HOOK != 0
3170
POSTASKEXITFUNC_t exithook;
3171
#endif
3172
#if DOX==0
3173
#if POSCFG_ARGCHECK > 1
3174
UVAR_t
magic;
3175
#endif
3176
#if SYS_TASKDOUBLELINK != 0
3177
struct
POSTASK *prev;
3178
#endif
3179
struct
POSTASK *next;
3180
UVAR_t
bit_x;
3181
#if SYS_TASKTABSIZE_Y > 1
3182
UVAR_t
bit_y;
3183
UVAR_t
idx_y;
3184
#endif
3185
#ifndef POS_DEBUGHELP
3186
UINT_t
ticks;
3187
#endif
3188
#if SYS_TASKSTATE != 0
3189
UVAR_t
state;
3190
#endif
3191
#if POSCFG_FEATURE_ERRNO != 0
3192
VAR_t
error;
3193
#endif
3194
#if POSCFG_FEATURE_MSGBOXES != 0
3195
UVAR_t
msgwait;
3196
POSSEMA_t
msgsem;
3197
void
*firstmsg;
3198
void
*lastmsg;
3199
#endif
3200
#ifdef POS_DEBUGHELP
3201
struct
PICOTASK
deb;
3202
#endif
3203
#if SYS_TASKEVENTLINK != 0
3204
void
*
event
;
3205
#endif
3206
#endif
/* !DOX */
3207
};
3208
3209
3210
#endif
/* _PICOOS_H */
3211
Generated on Thu Jun 7 2012 13:17:16 for pico]OS by
1.8.1