pico]OS  1.1.0
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  */
8 
260 #ifndef _PICOOS_H
261 #define _PICOOS_H
262 
263 
264 #define POS_VER_N 0x0110
265 #define POS_VER_S "1.1.0"
266 #define POS_COPYRIGHT "(c) 2004-2012, Dennis Kuschel\n" \
267  "(c) 2011-2016, Ari Suutari"
268 
269 #define POS_STARTUPSTRING "pico]OS " POS_VER_S "\n" POS_COPYRIGHT
270 
271 #ifndef NULL
272 #ifndef _HAVE_NULL
273 #define _HAVE_NULL
274 #define NULL ((void*)0)
275 #endif
276 #endif
277 
278 #ifndef DOX
279 #define DOX 0
280 #endif
281 #if DOX==0
282 
283 #ifndef _POSPACK
284 #ifdef __MYCPU__
285 #define PICOSUBDIR 1
286 #endif
287 #endif
288 
289 #ifdef PICOSUBDIR
290 /* required because of stupid CC65 compiler */
291 #include <picoos/port.h>
292 #include <picoos/poscfg.h>
293 #else
294 #include <port.h>
295 #include <poscfg.h>
296 #endif
297 
298 
299 /*---------------------------------------------------------------------------
300  * CONFIGURATION
301  *-------------------------------------------------------------------------*/
302 
303 /* test if all needed parameters are set */
304 #ifndef MVAR_t
305 #error MVAR_t not defined
306 #endif
307 #ifndef MVAR_BITS
308 #error MVAR_BITS not defined
309 #endif
310 #ifndef POSCFG_ALIGNMENT
311 #error POSCFG_ALIGNMENT not defined
312 #endif
313 #ifndef POSCFG_MAX_PRIO_LEVEL
314 #error POSCFG_MAX_PRIO_LEVEL not defined
315 #endif
316 #ifndef POSCFG_MAX_TASKS
317 #error POSCFG_MAX_TASKS not defined
318 #endif
319 #ifndef POSCFG_MAX_EVENTS
320 #error POSCFG_MAX_EVENTS not defined
321 #endif
322 #ifndef POSCFG_MAX_MESSAGES
323 #error POSCFG_MAX_MESSAGES not defined
324 #endif
325 #ifndef POSCFG_MAX_TIMER
326 #error POSCFG_MAX_TIMER not defined
327 #endif
328 #ifndef POSCFG_SOFT_MTASK
329 #error POSCFG_SOFT_MTASK not defined
330 #endif
331 #ifndef POSCFG_CTXSW_COMBINE
332 #error POSCFG_CTXSW_COMBINE not defined
333 #endif
334 #ifndef POSCFG_REALTIME_PRIO
335 #error POSCFG_REALTIME_PRIO not defined
336 #endif
337 #ifndef POSCFG_ISR_INTERRUPTABLE
338 #error POSCFG_ISR_INTERRUPTABLE not defined
339 #endif
340 #ifndef POSCFG_ROUNDROBIN
341 #error POSCFG_ROUNDROBIN not defined
342 #endif
343 #ifndef POSCFG_TASKS_PER_PRIO
344 #error POSCFG_TASKS_PER_PRIO not defined
345 #endif
346 #ifndef POSCFG_FASTCODE
347 #error POSCFG_FASTCODE not defined
348 #endif
349 #ifndef POSCFG_SMALLCODE
350 #error POSCFG_SMALLCODE not defined
351 #endif
352 #ifndef POSCFG_ARGCHECK
353 #error POSCFG_ARGCHECK not defined
354 #endif
355 #ifndef POSCFG_MSG_MEMORY
356 #error POSCFG_MSG_MEMORY not defined
357 #endif
358 #ifndef POSCFG_MSG_BUFSIZE
359 #error POSCFG_MSG_BUFSIZE not defined
360 #endif
361 #ifndef POSCFG_DYNAMIC_MEMORY
362 #error POSCFG_DYNAMIC_MEMORY not defined
363 #endif
364 #ifndef POSCFG_DYNAMIC_REFILL
365 #error POSCFG_DYNAMIC_REFILL
366 #endif
367 #if POSCFG_DYNAMIC_MEMORY != 0
368 #ifndef POS_MEM_ALLOC
369 #error POS_MEM_ALLOC not defined
370 #endif
371 #ifndef POS_MEM_ALLOC
372 #error POS_MEM_ALLOC not defined
373 #endif
374 #endif
375 #ifndef POSCFG_CALLINITARCH
376 #error POSCFG_CALLINITARCH not defined
377 #endif
378 #ifndef POSCFG_LOCK_USEFLAGS
379 #error POSCFG_LOCK_USEFLAGS not defined
380 #endif
381 #if POSCFG_LOCK_USEFLAGS != 0
382 #ifndef POSCFG_LOCK_FLAGSTYPE
383 #error POSCFG_LOCK_FLAGSTYPE not defined
384 #endif
385 #endif
386 #ifndef POS_SCHED_LOCK
387 #error POS_SCHED_LOCK not defined
388 #endif
389 #ifndef POS_SCHED_UNLOCK
390 #error POS_SCHED_UNLOCK not defined
391 #endif
392 #ifndef HZ
393 #error HZ not defined
394 #endif
395 #ifndef POSCFG_TASKSTACKTYPE
396 #error POSCFG_TASKSTACKTYPE not defined
397 #endif
398 #ifndef POS_USERTASKDATA
399 #error POS_USERTASKDATA not defined
400 #endif
401 #ifndef POSCFG_FEATURE_YIELD
402 #error POSCFG_FEATURE_YIELD not defined
403 #endif
404 #ifndef POSCFG_FEATURE_SLEEP
405 #error POSCFG_FEATURE_SLEEP not defined
406 #endif
407 #ifndef POSCFG_FEATURE_EXIT
408 #error POSCFG_FEATURE_EXIT not defined
409 #endif
410 #ifndef POSCFG_FEATURE_GETPRIORITY
411 #error POSCFG_FEATURE_GETPRIORITY not defined
412 #endif
413 #ifndef POSCFG_FEATURE_SETPRIORITY
414 #error POSCFG_FEATURE_SETPRIORITY not defined
415 #endif
416 #ifndef POSCFG_FEATURE_SEMAPHORES
417 #error POSCFG_FEATURE_SEMAPHORES not defined
418 #endif
419 #ifndef POSCFG_FEATURE_SEMADESTROY
420 #error POSCFG_FEATURE_SEMADESTROY not defined
421 #endif
422 #ifndef POSCFG_FEATURE_SEMAWAIT
423 #error POSCFG_FEATURE_SEMAWAIT not defined
424 #endif
425 #ifndef POSCFG_FEATURE_MUTEXES
426 #error POSCFG_FEATURE_MUTEXES not defined
427 #endif
428 #ifndef POSCFG_FEATURE_MUTEXDESTROY
429 #error POSCFG_FEATURE_MUTEXDESTROY not defined
430 #endif
431 #ifndef POSCFG_FEATURE_MUTEXTRYLOCK
432 #error POSCFG_FEATURE_MUTEXTRYLOCK not defined
433 #endif
434 #ifndef POSCFG_FEATURE_GETTASK
435 #error POSCFG_FEATURE_GETTASK not defined
436 #endif
437 #ifndef POSCFG_FEATURE_TASKUNUSED
438 #error POSCFG_FEATURE_TASKUNUSED not defined
439 #endif
440 #ifndef POSCFG_FEATURE_MSGBOXES
441 #error POSCFG_FEATURE_MSGBOXES not defined
442 #endif
443 #ifndef POSCFG_FEATURE_MSGWAIT
444 #error POSCFG_FEATURE_MSGWAIT not defined
445 #endif
446 #ifndef POSCFG_FEATURE_INHIBITSCHED
447 #error POSCFG_FEATURE_INHIBITSCHED not defined
448 #endif
449 #ifndef POSCFG_FEATURE_JIFFIES
450 #error POSCFG_FEATURE_JIFFIES not defined
451 #endif
452 #ifndef POSCFG_FEATURE_TIMER
453 #error POSCFG_FEATURE_TIMER not defined
454 #endif
455 #ifndef POSCFG_FEATURE_TIMERDESTROY
456 #error POSCFG_FEATURE_TIMERDESTROY not defined
457 #endif
458 #ifndef POSCFG_FEATURE_TIMERFIRED
459 #error POSCFG_FEATURE_TIMERFIRED not defined
460 #endif
461 #ifndef POSCFG_FEATURE_FLAGS
462 #error POSCFG_FEATURE_FLAGS not defined
463 #endif
464 #ifndef POSCFG_FEATURE_FLAGDESTROY
465 #error POSCFG_FEATURE_FLAGDESTROY not defined
466 #endif
467 #ifndef POSCFG_FEATURE_FLAGWAIT
468 #error POSCFG_FEATURE_FLAGWAIT not defined
469 #endif
470 #ifndef POSCFG_FEATURE_SOFTINTS
471 #error POSCFG_FEATURE_SOFTINTS not defined
472 #else
473 #ifndef POSCFG_FEATURE_SOFTINTDEL
474 #error POSCFG_FEATURE_SOFTINTDEL not defined
475 #endif
476 #ifndef POSCFG_SOFTINTERRUPTS
477 #error POSCFG_SOFTINTERRUPTS not defined
478 #endif
479 #ifndef POSCFG_SOFTINTQUEUELEN
480 #error POSCFG_SOFTINTQUEUELEN not defined
481 #endif
482 #endif
483 #ifndef POSCFG_FEATURE_IDLETASKHOOK
484 #error POSCFG_FEATURE_IDLETASKHOOK not defined
485 #endif
486 #ifndef POSCFG_FEATURE_ERRNO
487 #error POSCFG_FEATURE_ERRNO not defined
488 #endif
489 #ifndef POSCFG_FEATURE_ATOMICVAR
490 #error POSCFG_FEATURE_ATOMICVAR not defined
491 #endif
492 #ifndef POSCFG_FEATURE_LISTS
493 #error POSCFG_FEATURE_LISTS not defined
494 #else
495 #ifndef POSCFG_FEATURE_LISTJOIN
496 #error POSCFG_FEATURE_LISTJOIN not defined
497 #endif
498 #ifndef POSCFG_FEATURE_LISTLEN
499 #define POSCFG_FEATURE_LISTLEN 1
500 #endif
501 #endif
502 #ifndef POSCFG_FEATURE_DEBUGHELP
503 #define POSCFG_FEATURE_DEBUGHELP 0
504 #endif
505 #ifdef _DBG
506 #if POSCFG_FEATURE_DEBUGHELP
507 #define POS_DEBUGHELP
508 #endif
509 #endif
510 #ifndef POSCFG_PORTMUTEX
511 #define POSCFG_PORTMUTEX 0
512 #endif
513 #ifndef POSCFG_INT_EXIT_QUICK
514 #define POSCFG_INT_EXIT_QUICK 0
515 #endif
516 #ifndef POSCFG_FEATURE_POWER
517 #define POSCFG_FEATURE_POWER 0
518 #endif
519 #ifndef POSCFG_POWER_WAKEUP
520 #define POSCFG_POWER_WAKEUP 0
521 #endif
522 
523 /* parameter range checking */
524 #if (POSCFG_DYNAMIC_MEMORY != 0) && (POSCFG_DYNAMIC_REFILL != 0)
525 #define SYS_POSTALLOCATE 1
526 #else
527 #define SYS_POSTALLOCATE 0
528 #endif
529 #if (MVAR_BITS != 8) && (MVAR_BITS != 16) && (MVAR_BITS != 32)
530 #error MVAR_BITS must be 8, 16 or 32
531 #endif
532 #if POSCFG_MAX_PRIO_LEVEL == 0
533 #error POSCFG_MAX_PRIO_LEVEL must not be zero
534 #endif
535 #if (POSCFG_ROUNDROBIN != 0) && (POSCFG_MAX_PRIO_LEVEL > MVAR_BITS)
536 #error POSCFG_MAX_PRIO_LEVEL must not exceed MVAR_BITS
537 #endif
538 #if (POSCFG_ROUNDROBIN == 0) && (POSCFG_MAX_PRIO_LEVEL > (MVAR_BITS*MVAR_BITS))
539 #error POSCFG_MAX_PRIO_LEVEL must not exceed (MVAR_BITS * MVAR_BITS)
540 #endif
541 #if (POSCFG_MAX_TASKS < 2) && (SYS_POSTALLOCATE == 0)
542 #error POSCFG_MAX_TASKS is less than 2
543 #endif
544 #if (POSCFG_MAX_TASKS > (POSCFG_TASKS_PER_PRIO * POSCFG_MAX_PRIO_LEVEL))
545 #error POSCFG_MAX_TASKS is much to big
546 #endif
547 #if (POSCFG_MAX_EVENTS < 1) && (SYS_POSTALLOCATE == 0)
548 #error POSCFG_MAX_EVENTS must be at least 1
549 #endif
550 #if POSCFG_TASKS_PER_PRIO > MVAR_BITS
551 #error POSCFG_TASKS_PER_PRIO can not exceed MVAR_BITS
552 #endif
553 #if (POSCFG_TASKS_PER_PRIO < 2) && (POSCFG_ROUNDROBIN != 0)
554 #error POSCFG_TASKS_PER_PRIO must be at least 2
555 #endif
556 #if (POSCFG_TASKS_PER_PRIO != 1) && (POSCFG_ROUNDROBIN == 0)
557 #error POSCFG_TASKS_PER_PRIO must be 1 when round robin scheduling is disabled
558 #endif
559 #if ((POSCFG_TASKS_PER_PRIO % 3) == 0) || ((POSCFG_TASKS_PER_PRIO % 5) == 0)
560 #error POSCFG_TASKS_PER_PRIO must be 1/2/4/8/16 or 32
561 #endif
562 #if (POSCFG_REALTIME_PRIO >= POSCFG_MAX_PRIO_LEVEL) && (POSCFG_ROUNDROBIN != 0)
563 #error POSCFG_REALTIME_PRIO must be less than POSCFG_MAX_PRIO_LEVEL
564 #endif
565 #if POSCFG_FEATURE_MSGBOXES != 0
566 #if (POSCFG_MAX_MESSAGES < 2) && (SYS_POSTALLOCATE == 0)
567 #error POSCFG_MAX_MESSAGES must be at least 2
568 #endif
569 #if POSCFG_MSG_BUFSIZE < 1
570 #error POSCFG_MSG_BUFSIZE must be at least 1
571 #endif
572 #endif
573 #if (POSCFG_FEATURE_TIMER != 0)
574 #if (POSCFG_MAX_TIMER == 0) && (SYS_POSTALLOCATE == 0)
575 #error POSCFG_MAX_TIMER must be at least 1
576 #endif
577 #endif
578 #if (POSCFG_TASKSTACKTYPE < 0) || (POSCFG_TASKSTACKTYPE > 2)
579 #error POSCFG_TASKSTACKTYPE must be 0, 1 or 2
580 #endif
581 #if POSCFG_ALIGNMENT == 0
582 #undef POSCFG_ALIGNMENT
583 #define POSCFG_ALIGNMENT 1
584 #else
585 #if ((POSCFG_ALIGNMENT % 3) == 0) || ((POSCFG_ALIGNMENT % 5) == 0)
586 #error POSCFG_ALIGNMENT must be 1/2/4/8/16/32/64/128/256 etc.
587 #endif
588 #endif
589 #if POSCFG_FEATURE_SOFTINTS != 0
590 #if POSCFG_SOFTINTERRUPTS == 0
591 #error POSCFG_SOFTINTERRUPTS must be greater than 0
592 #endif
593 #if POSCFG_SOFTINTQUEUELEN < 2
594 #error POSCFG_SOFTINTQUEUELEN must be at least 2
595 #endif
596 #endif
597 
598 
599 /* parameter reconfiguration */
600 #ifndef POSCFG_TASKCB_USERSPACE
601 #define POSCFG_TASKCB_USERSPACE 0
602 #endif
603 #if POSCFG_FEATURE_SEMAPHORES == 0
604 #undef POSCFG_FEATURE_SEMADESTROY
605 #define POSCFG_FEATURE_SEMADESTROY 0
606 #endif
607 #if POSCFG_FEATURE_FLAGS == 0
608 #undef POSCFG_FEATURE_FLAGDESTROY
609 #define POSCFG_FEATURE_FLAGDESTROY 0
610 #endif
611 #if POSCFG_FEATURE_MUTEXES == 0
612 #undef POSCFG_FEATURE_MUTEXDESTROY
613 #define POSCFG_FEATURE_MUTEXDESTROY 0
614 #else
615 #if (POSCFG_FEATURE_MUTEXDESTROY != 0) && (POSCFG_FEATURE_SEMADESTROY == 0)
616 #undef POSCFG_FEATURE_SEMADESTROY
617 #define POSCFG_FEATURE_SEMADESTROY 1
618 #endif
619 #endif
620 #if (POSCFG_FEATURE_MSGBOXES != 0) && (SYS_POSTALLOCATE == 0)
621 #define SYS_MSGBOXEVENTS 2
622 #else
623 #define SYS_MSGBOXEVENTS 0
624 #endif
625 #if (POSCFG_FEATURE_MSGBOXES != 0) && (POSCFG_FEATURE_GETTASK == 0)
626 #undef POSCFG_FEATURE_GETTASK
627 #define POSCFG_FEATURE_GETTASK 1
628 #endif
629 #if (POSCFG_FEATURE_SEMAWAIT != 0) || (POSCFG_FEATURE_MSGWAIT != 0)
630 #define SYS_TASKDOUBLELINK 1
631 #else
632 #define SYS_TASKDOUBLELINK 0
633 #endif
634 #define SYS_EVENTS_USED \
635  (POSCFG_FEATURE_MUTEXES | POSCFG_FEATURE_MSGBOXES | \
636  POSCFG_FEATURE_FLAGS | POSCFG_FEATURE_LISTS)
637 #define SYS_FEATURE_EVENTS (POSCFG_FEATURE_SEMAPHORES | SYS_EVENTS_USED)
638 #define SYS_FEATURE_EVENTFREE (POSCFG_FEATURE_SEMADESTROY | \
639  POSCFG_FEATURE_MUTEXDESTROY | POSCFG_FEATURE_FLAGDESTROY | \
640  POSCFG_FEATURE_LISTS)
641 #if (POSCFG_FEATURE_MSGBOXES != 0) && (POSCFG_FEATURE_EXIT != 0)
642 #undef SYS_FEATURE_EVENTFREE
643 #define SYS_FEATURE_EVENTFREE 1
644 #endif
645 #ifndef POSCFG_FEATURE_LARGEJIFFIES
646 #if MVAR_BITS < 16
647 #define POSCFG_FEATURE_LARGEJIFFIES 1
648 #else
649 #define POSCFG_FEATURE_LARGEJIFFIES 0
650 #endif
651 #endif
652 #ifndef POSCALL
653 #define POSCALL
654 #endif
655 #if POSCFG_FEATURE_SETPRIORITY != 0
656 #define SYS_TASKEVENTLINK 1
657 #else
658 #define SYS_TASKEVENTLINK 0
659 #endif
660 
661 #endif /* DOX!=0 */
662 
663 
664 
665 /*---------------------------------------------------------------------------
666  * SOME DEFINITIONS AND MACROS
667  *-------------------------------------------------------------------------*/
668 
669 #ifdef _POSCORE_C
670 #define POSEXTERN
671 #define POSFROMEXT extern
672 #else
673 #define POSEXTERN extern
674 #define POSFROMEXT
675 #endif
676 
677 #if POSCFG_ROUNDROBIN == 0
678 #define SYS_TASKTABSIZE_X MVAR_BITS
679 #define SYS_TASKTABSIZE_Y ((POSCFG_MAX_PRIO_LEVEL+MVAR_BITS-1)/MVAR_BITS)
680 #else
681 #define SYS_TASKTABSIZE_X POSCFG_TASKS_PER_PRIO
682 #define SYS_TASKTABSIZE_Y POSCFG_MAX_PRIO_LEVEL
683 #endif
684 
685 #define SYS_TASKSTATE (POSCFG_FEATURE_TASKUNUSED | POSCFG_FEATURE_MSGBOXES)
686 
687 #if POSCFG_LOCK_USEFLAGS != 0
688 #define POS_LOCKFLAGS POSCFG_LOCK_FLAGSTYPE flags
689 #else
690 #define POS_LOCKFLAGS do { } while(0)
691 #endif
692 
693 #define POSTASKSTATE_UNUSED 0
694 #define POSTASKSTATE_ZOMBIE 1
695 #define POSTASKSTATE_ACTIVE 2
696 
697 #define INFINITE ((UINT_t)~0)
698 
699 
700 
701 /*---------------------------------------------------------------------------
702  * ERROR CODES
703  *-------------------------------------------------------------------------*/
704 
719 #define E_OK 0
720 
722 #define E_FAIL 1
723 
725 #define E_NOMEM 2
726 
728 #define E_ARG 3
729 
731 #define E_FORB 4
732 
734 #define E_NOMORE 5
735 
737 #define E_NOTFOUND 6
738 
743 /*---------------------------------------------------------------------------
744  * MACROS
745  *-------------------------------------------------------------------------*/
746 
752 #if (DOX==0) && (HZ <= 1000)
753 #define MS(msec) (((msec)<(1000/HZ)) ? \
754  ((UINT_t)1) : ((UINT_t)((1L*HZ*(msec))/1000)))
755 #else
756 #define MS(msec) ((UINT_t)((1L*HZ*(msec))/1000))
757 #endif
758 
759 
760 
761 /*---------------------------------------------------------------------------
762  * DATA TYPES
763  *-------------------------------------------------------------------------*/
764 
770 typedef signed MVAR_t VAR_t;
771 
777 typedef unsigned MVAR_t UVAR_t;
778 
779 #ifndef MINT_t
780 #define MINT_t int
781 #endif
782 
791 typedef signed MINT_t INT_t;
792 
802 typedef unsigned MINT_t UINT_t;
803 
804 #ifndef MPTR_t
805 #define MPTR_t long
806 #endif
807 
818 typedef unsigned MPTR_t MEMPTR_t;
819 
820 #if (DOX!=0) || (POSCFG_FEATURE_LARGEJIFFIES == 0)
821 
824 typedef VAR_t SJIF_t;
828 typedef UVAR_t JIF_t;
829 #else
830 typedef INT_t SJIF_t;
831 typedef UINT_t JIF_t;
832 #endif
833 
837 typedef void (*POSTASKFUNC_t)(void* arg);
838 
845 typedef void (*POSINTFUNC_t)(UVAR_t arg);
846 
847 #if (DOX!=0) ||(POSCFG_FEATURE_IDLETASKHOOK != 0)
848 
849 typedef void (*POSIDLEFUNC_t)(void);
850 #endif
851 
852 #if (DOX!=0) ||(POSCFG_FEATURE_POWER != 0)
853 
854 typedef void (*POSPOWERCB_t)(UVAR_t event);
855 
856 #define POSPOWER_EVENT_SLEEP 0
857 #define POSPOWER_EVENT_WAKEUP 1
858 
859 #endif
860 
861 /* forward declarations (just dummies) */
862 struct POSSEMA;
863 struct POSMUTEX;
864 struct POSFLAG;
865 struct POSTIMER;
866 
870 typedef struct POSSEMA *POSSEMA_t;
871 
875 typedef struct POSMUTEX *POSMUTEX_t;
876 
880 typedef struct POSFLAG *POSFLAG_t;
881 
885 typedef struct POSTIMER *POSTIMER_t;
886 
890 typedef volatile INT_t POSATOMIC_t;
891 
892 #if (DOX!=0) || (POSCFG_FEATURE_LISTS != 0)
893 struct POSLIST;
894 struct POSLISTHEAD {
895  struct POSLIST* volatile prev;
896  struct POSLIST* volatile next;
897  POSSEMA_t volatile sema;
898  UVAR_t volatile flag;
899 #if POSCFG_FEATURE_LISTLEN != 0
900  UINT_t volatile length;
901 #endif
902 };
903 struct POSLIST {
904  struct POSLIST* volatile prev;
905  struct POSLIST* volatile next;
906 #if POSCFG_FEATURE_LISTLEN != 0
907  struct POSLISTHEAD* volatile head;
908 #endif
909 };
914 typedef struct POSLIST POSLIST_t;
919 typedef struct POSLISTHEAD POSLISTHEAD_t;
920 #endif
921 
922 
942 typedef struct POSTASK *POSTASK_t; /* forward declaration */
943 
944 
945 
946 /*---------------------------------------------------------------------------
947  * DEFINITIONS FOR GENERIC "findbit" FUNCTION (file fbit_gen.c)
948  *-------------------------------------------------------------------------*/
949 
950 #ifndef POSCFG_FBIT_USE_LUTABLE
951 #define POSCFG_FBIT_USE_LUTABLE 0
952 #endif
953 #if (POSCFG_FBIT_USE_LUTABLE > 1) && (POSCFG_ROUNDROBIN == 0)
954 #undef POSCFG_FBIT_USE_LUTABLE
955 #define POSCFG_FBIT_USE_LUTABLE 1
956 #endif
957 #ifndef FINDBIT
958 #if POSCFG_FBIT_USE_LUTABLE == 1
959 #if POSCFG_ROUNDROBIN == 0
960 #ifndef _FBIT_GEN_C
961 extern VAR_t const p_pos_fbittbl[256];
962 #endif
963 #define FINDBIT(x) p_pos_fbittbl[x]
964 #else
965 UVAR_t POSCALL p_pos_findbit(const UVAR_t bitfield, UVAR_t rrOffset);
966 #define FINDBIT(x, o) p_pos_findbit(x, o)
967 #endif
968 #elif POSCFG_FBIT_USE_LUTABLE == 2
969 #ifndef _FBIT_GEN_C
970 extern VAR_t const p_pos_fbittbl_rr[8][256];
971 #endif
972 #define FINDBIT(x, o) p_pos_fbittbl_rr[o][x]
973 #endif
974 #endif /* !FINDBIT */
975 
976 
977 
978 /*---------------------------------------------------------------------------
979  * GLOBAL VARIABLES
980  *-------------------------------------------------------------------------*/
981 
990 POSEXTERN volatile POSTASK_t posCurrentTask_g;
991 
1000 POSEXTERN volatile POSTASK_t posNextTask_g;
1001 
1008 #ifndef _POSCORE_C
1009 POSEXTERN volatile UVAR_t posInInterrupt_g;
1010 #else
1011 POSEXTERN volatile UVAR_t posInInterrupt_g = 1;
1012 #endif
1013 
1020 #ifndef _POSCORE_C
1021 POSEXTERN volatile UVAR_t posRunning_g;
1022 #else
1023 POSEXTERN volatile UVAR_t posRunning_g = 0;
1024 #endif
1025 
1026 
1027 #if DOX!=0
1028 
1034 #endif
1035 #if POSCFG_FEATURE_ERRNO != 0
1036 #ifdef errno
1037 #undef errno
1038 #endif
1039 POSEXTERN VAR_t* _errno_p(void);
1040 #define errno (*_errno_p())
1041 #endif
1042 
1043 
1044 
1045 /*---------------------------------------------------------------------------
1046  * PROTOTYPES OF INTERNAL FUNCTIONS
1047  *-------------------------------------------------------------------------*/
1048 
1229 /* findbit function or macro definition */
1230 #if (DOX!=0) || (POSCFG_ROUNDROBIN == 0)
1231 #ifdef FINDBIT
1232 #define POS_FINDBIT(bf) FINDBIT(bf, 0)
1233 #define POS_FINDBIT_EX(bf, ofs) FINDBIT(bf, 0)
1234 #else /* FINDBIT */
1235 POSFROMEXT UVAR_t POSCALL p_pos_findbit(const UVAR_t bitfield); /* arch_c.c */
1236 #define POS_FINDBIT(bf) p_pos_findbit(bf)
1237 #define POS_FINDBIT_EX(bf, ofs) p_pos_findbit(bf)
1238 #endif /* FINDBIT */
1239 #else /* POSCFG_ROUNDROBIN */
1240 #ifdef FINDBIT
1241 #define POS_FINDBIT(bf) FINDBIT(bf, 0)
1242 #define POS_FINDBIT_EX(bf, ofs) FINDBIT(bf, ofs)
1243 #else /* FINDBIT */
1244 POSFROMEXT UVAR_t POSCALL p_pos_findbit(const UVAR_t bitfield, UVAR_t rrOffset); /* arch_c.c */
1245 #define POS_FINDBIT(bf) p_pos_findbit(bf, 0)
1246 #define POS_FINDBIT_EX(bf, ofs) p_pos_findbit(bf, ofs)
1247 #endif /* FINDBIT */
1248 #endif /* POSCFG_ROUNDROBIN */
1249 
1250 #if DOX!=0
1251 
1260 POSFROMEXT UVAR_t POSCALL p_pos_findbit(const UVAR_t bitfield);
1261 
1272 POSFROMEXT UVAR_t POSCALL p_pos_findbit(const UVAR_t bitfield, UVAR_t rrOffset);
1273 #endif
1274 
1275 #if (DOX!=0) || (POSCFG_CALLINITARCH != 0)
1276 
1287 POSFROMEXT void POSCALL p_pos_initArch(void);
1288 #endif
1289 
1290 #if (DOX!=0) || (POSCFG_TASKSTACKTYPE == 0)
1291 
1310 POSFROMEXT void POSCALL p_pos_initTask(POSTASK_t task, void *stackstart,
1311  POSTASKFUNC_t funcptr,
1312  void *funcarg); /* arch_c.c */
1313 #endif
1314 #if (DOX!=0) || (POSCFG_TASKSTACKTYPE == 1)
1315 
1339 POSFROMEXT VAR_t POSCALL p_pos_initTask(POSTASK_t task, UINT_t stacksize,
1340  POSTASKFUNC_t funcptr,
1341  void *funcarg); /* arch_c.c */
1360 POSFROMEXT void POSCALL p_pos_freeStack(POSTASK_t task);/* arch_c.c */
1361 #endif
1362 
1363 #if (DOX!=0) || (POSCFG_PORTMUTEX != 0)
1364 
1372 POSFROMEXT void POSCALL p_pos_lock(void);/* arch_c.c */
1373 
1377 POSFROMEXT void POSCALL p_pos_unlock(void);/* arch_c.c */
1378 #endif
1379 
1380 #if (DOX!=0) || (POSCFG_TASKSTACKTYPE == 2)
1381 
1404 POSFROMEXT VAR_t POSCALL p_pos_initTask(POSTASK_t task, POSTASKFUNC_t funcptr,
1405  void *funcarg); /* arch_c.c */
1406 
1423 POSFROMEXT void POSCALL p_pos_freeStack(POSTASK_t task);/* arch_c.c */
1424 #endif
1425 
1439 POSFROMEXT void POSCALL p_pos_startFirstContext(void); /* arch_c.c */
1440 
1455 POSFROMEXT void POSCALL p_pos_softContextSwitch(void); /* arch_c.c */
1456 
1470 POSFROMEXT void POSCALL p_pos_intContextSwitch(void); /* arch_c.c */
1471 
1472 #if (DOX!=0) || POSCFG_INT_EXIT_QUICK == 1
1473 
1486 POSFROMEXT void POSCALL p_pos_intContextSwitchPending(void); /* arch_c.c */
1487 
1488 #endif
1489 
1498 POSEXTERN void POSCALL c_pos_intEnter(void); /* picoos.c */
1499 
1508 POSEXTERN void POSCALL c_pos_intExit(void); /* picoos.c */
1509 
1510 #if (DOX!=0) || POSCFG_INT_EXIT_QUICK == 1
1511 
1522 POSEXTERN void POSCALL c_pos_intExitQuick(void); /* picoos.c */
1523 
1524 #endif
1525 
1558 POSEXTERN void POSCALL c_pos_timerInterrupt(void); /* picoos.c */
1559 
1560 #if (DOX!=0) || POSCFG_FEATURE_TICKLESS == 1
1561 
1574 POSEXTERN void POSCALL c_pos_timerStep(UVAR_t ticks); /* picoos.c */
1575 
1581 POSEXTERN UINT_t POSCALL c_pos_nextWakeup(void);
1582 
1583 #endif
1584 
1585 #if (DOX!=0) || POSCFG_FEATURE_POWER == 1
1586 
1594 POSFROMEXT void POSCALL p_pos_powerSleep(void); /* arch_c.c */
1595 
1596 #if (DOX!=0) || POSCFG_POWER_WAKEUP == 1
1597 
1604 POSFROMEXT void POSCALL p_pos_powerWakeup(void); /* arch_c.c */
1605 
1606 #endif
1607 #endif
1608 
1609 #if (DOX!=0) || POSCFG_FEATURE_TICKLESS == 1
1610 
1618 POSFROMEXT void POSCALL p_pos_powerTickSuspend(UVAR_t ticks);
1619 
1629 POSFROMEXT void POSCALL p_pos_powerTickResume(void);
1630 
1631 #endif
1632 
1637 /*---------------------------------------------------------------------------
1638  * PROTOTYPES OF EXPORTED FUNCTIONS (USER API)
1639  *-------------------------------------------------------------------------*/
1640 
1646 #if (DOX!=0) || (POSCFG_FEATURE_YIELD != 0)
1647 
1655 POSEXTERN void POSCALL posTaskYield(void);
1656 #endif
1657 
1658 #if (DOX!=0) || (POSCFG_FEATURE_SLEEP != 0)
1659 
1673 POSEXTERN void POSCALL posTaskSleep(UINT_t ticks);
1674 #endif
1675 
1676 #if (DOX!=0) || (POSCFG_TASKSTACKTYPE == 0)
1677 
1693 POSEXTERN POSTASK_t POSCALL posTaskCreate(POSTASKFUNC_t funcptr, void *funcarg,
1694  VAR_t priority, void *stackstart);
1695 
1711 POSEXTERN void POSCALL posInit(POSTASKFUNC_t firstfunc, void *funcarg,
1712  VAR_t priority,
1713  void *stackFirstTask, void *stackIdleTask);
1714 #endif
1715 #if (DOX!=0) || (POSCFG_TASKSTACKTYPE == 1)
1716 
1735 POSEXTERN POSTASK_t POSCALL posTaskCreate(POSTASKFUNC_t funcptr, void *funcarg,
1736  VAR_t priority, UINT_t stacksize);
1737 
1753 POSEXTERN void POSCALL posInit(POSTASKFUNC_t firstfunc, void *funcarg,
1754  VAR_t priority, UINT_t taskStackSize,
1755  UINT_t idleStackSize);
1756 #endif
1757 #if (DOX!=0) || (POSCFG_TASKSTACKTYPE == 2)
1758 
1774 POSEXTERN POSTASK_t POSCALL posTaskCreate(POSTASKFUNC_t funcptr, void *funcarg,
1775  VAR_t priority);
1776 
1790 POSEXTERN void POSCALL posInit(POSTASKFUNC_t firstfunc, void *funcarg,
1791  VAR_t priority);
1792 
1793 #endif
1794 
1795 
1796 #if (DOX!=0) || (POSCFG_FEATURE_EXIT != 0)
1797 
1804 POSEXTERN void POSCALL posTaskExit(void);
1805 #endif
1806 
1807 #if (DOX!=0) || (POSCFG_FEATURE_GETTASK != 0)
1808 
1816 POSEXTERN POSTASK_t POSCALL posTaskGetCurrent(void);
1817 #endif
1818 
1819 #if (DOX!=0) || (POSCFG_FEATURE_TASKUNUSED != 0)
1820 
1833 POSEXTERN VAR_t POSCALL posTaskUnused(POSTASK_t taskhandle);
1834 #endif
1835 
1836 #if (DOX!=0) || (POSCFG_FEATURE_SETPRIORITY != 0)
1837 
1850 POSEXTERN VAR_t POSCALL posTaskSetPriority(POSTASK_t taskhandle,
1851  VAR_t priority);
1852 #endif
1853 
1854 #if (DOX!=0) || (POSCFG_FEATURE_GETPRIORITY != 0)
1855 
1864 POSEXTERN VAR_t POSCALL posTaskGetPriority(POSTASK_t taskhandle);
1865 #endif
1866 
1867 #if (DOX!=0) || (POSCFG_FEATURE_INHIBITSCHED != 0)
1868 
1879 POSEXTERN void POSCALL posTaskSchedLock(void);
1880 
1890 POSEXTERN void POSCALL posTaskSchedUnlock(void);
1891 #endif
1892 
1893 #if (DOX!=0) || (POSCFG_TASKCB_USERSPACE > 0)
1894 
1902 POSEXTERN void* POSCALL posTaskGetUserspace(void);
1903 #endif
1904 
1905 #if (DOX!=0) || (POSCFG_FEATURE_IDLETASKHOOK != 0)
1906 
1924 POSEXTERN POSIDLEFUNC_t POSCALL posInstallIdleTaskHook(POSIDLEFUNC_t idlefunc);
1925 #endif
1926 
1929 /*-------------------------------------------------------------------------*/
1930 
1936 #if (DOX!=0) || POSCFG_FEATURE_POWER == 1
1937 
1944 POSEXTERN void POSCALL posPowerDisableSleep(void);
1945 
1953 POSEXTERN void POSCALL posPowerEnableSleep(void);
1954 
1969 POSEXTERN POSPOWERCB_t POSCALL posPowerSetCallback(POSPOWERCB_t callback);
1970 #endif
1971 
1974 /*-------------------------------------------------------------------------*/
1975 
1976 #if (DOX!=0) || (SYS_FEATURE_EVENTS != 0)
1977 
2016 POSEXTERN POSSEMA_t POSCALL posSemaCreate(INT_t initcount);
2017 
2018 #if (DOX!=0) || (SYS_FEATURE_EVENTFREE != 0)
2019 
2029 POSEXTERN void POSCALL posSemaDestroy(POSSEMA_t sema);
2030 #endif
2031 
2044 #if (DOX!=0) || (POSCFG_SMALLCODE == 0) || (POSCFG_FEATURE_SEMAWAIT == 0)
2045 POSEXTERN VAR_t POSCALL posSemaGet(POSSEMA_t sema);
2046 #else
2047 /* this define is for small code and it saves stack memory */
2048 #define posSemaGet(sema) posSemaWait(sema, INFINITE)
2049 #endif
2050 
2062 POSEXTERN VAR_t POSCALL posSemaSignal(POSSEMA_t sema);
2063 
2064 #if (DOX!=0) || (POSCFG_FEATURE_SEMAWAIT != 0)
2065 
2085 POSEXTERN VAR_t POSCALL posSemaWait(POSSEMA_t sema, UINT_t timeoutticks);
2086 #endif
2087 
2088 #endif /* SYS_FEATURE_EVENTS */
2089 
2091 /*-------------------------------------------------------------------------*/
2092 
2093 #if (DOX!=0) || (POSCFG_FEATURE_MUTEXES != 0)
2094 
2115 POSEXTERN POSMUTEX_t POSCALL posMutexCreate(void);
2116 
2117 #if (DOX!=0) || (POSCFG_FEATURE_MUTEXDESTROY != 0)
2118 
2128 POSEXTERN void POSCALL posMutexDestroy(POSMUTEX_t mutex);
2129 #endif
2130 
2131 #if (DOX!=0) || (POSCFG_FEATURE_MUTEXTRYLOCK != 0)
2132 
2147 POSEXTERN VAR_t POSCALL posMutexTryLock(POSMUTEX_t mutex);
2148 #endif
2149 
2162 POSEXTERN VAR_t POSCALL posMutexLock(POSMUTEX_t mutex);
2163 
2174 POSEXTERN VAR_t POSCALL posMutexUnlock(POSMUTEX_t mutex);
2175 
2176 #endif /* POSCFG_FEATURE_MUTEXES */
2177 
2179 /*-------------------------------------------------------------------------*/
2180 
2181 #if (DOX!=0) || (POSCFG_FEATURE_MSGBOXES != 0)
2182 
2204 #if (DOX!=0) || (POSCFG_MSG_MEMORY != 0)
2205 
2218 POSEXTERN void* POSCALL posMessageAlloc(void);
2219 
2232 POSEXTERN void POSCALL posMessageFree(void *buf);
2233 #endif
2234 
2252 POSEXTERN VAR_t POSCALL posMessageSend(void *buf, POSTASK_t taskhandle);
2253 
2269 #if (DOX!=0) || (POSCFG_SMALLCODE == 0) || (POSCFG_FEATURE_MSGWAIT == 0)
2270 POSEXTERN void* POSCALL posMessageGet(void);
2271 #else
2272 /* this define is for small code and it saves stack memory */
2273 #define posMessageGet() posMessageWait(INFINITE)
2274 #endif
2275 
2288 POSEXTERN VAR_t POSCALL posMessageAvailable(void);
2289 
2290 #if (DOX!=0) || (POSCFG_FEATURE_MSGWAIT != 0)
2291 
2316 POSEXTERN void* POSCALL posMessageWait(UINT_t timeoutticks);
2317 #endif
2318 
2319 #endif /* POSCFG_FEATURE_MSGBOXES */
2320 
2322 /*-------------------------------------------------------------------------*/
2323 
2324 #if (DOX!=0) || (POSCFG_FEATURE_FLAGS != 0)
2325 
2345 POSEXTERN POSFLAG_t POSCALL posFlagCreate(void);
2346 
2347 #if (DOX!=0) || (POSCFG_FEATURE_FLAGDESTROY != 0)
2348 
2358 POSEXTERN void POSCALL posFlagDestroy(POSFLAG_t flg);
2359 #endif
2360 
2373 POSEXTERN VAR_t POSCALL posFlagSet(POSFLAG_t flg, UVAR_t flgnum);
2374 
2389 POSEXTERN VAR_t POSCALL posFlagGet(POSFLAG_t flg, UVAR_t mode);
2390 
2391 #if (DOX!=0) || (POSCFG_FEATURE_FLAGWAIT != 0)
2392 
2411 POSEXTERN VAR_t POSCALL posFlagWait(POSFLAG_t flg, UINT_t timeoutticks);
2412 #endif
2413 
2414 #define POSFLAG_MODE_GETSINGLE 0
2415 #define POSFLAG_MODE_GETMASK 1
2416 
2417 #endif /* POSCFG_FEATURE_FLAGS */
2418 
2420 /*-------------------------------------------------------------------------*/
2421 
2443 #if DOX!=0
2444 #define HZ (timerticks per second)
2445 #endif
2446 
2456 #if (DOX!=0) || (POSCFG_FEATURE_JIFFIES != 0)
2457 #if (DOX!=0) || (POSCFG_FEATURE_LARGEJIFFIES == 0)
2458 POSEXTERN volatile JIF_t jiffies;
2459 #else
2460 POSEXTERN JIF_t POSCALL posGetJiffies(void);
2461 #define jiffies posGetJiffies()
2462 #endif
2463 
2474 #define POS_TIMEAFTER(x, y) ((((SJIF_t)(x)) - ((SJIF_t)(y))) >= 0)
2475 
2476 #endif /* POSCFG_FEATURE_JIFFIES */
2477 
2478 #if (DOX!=0) || (POSCFG_FEATURE_TIMER != 0)
2479 
2489 POSEXTERN POSTIMER_t POSCALL posTimerCreate(void);
2490 
2508 POSEXTERN VAR_t POSCALL posTimerSet(POSTIMER_t tmr, POSSEMA_t sema,
2509  UINT_t waitticks, UINT_t periodticks);
2521 POSEXTERN VAR_t POSCALL posTimerStart(POSTIMER_t tmr);
2522 
2533 POSEXTERN VAR_t POSCALL posTimerStop(POSTIMER_t tmr);
2534 
2535 #if (DOX!=0) || (POSCFG_FEATURE_TIMERDESTROY != 0)
2536 
2546 POSEXTERN void POSCALL posTimerDestroy(POSTIMER_t tmr);
2547 #endif
2548 #if (DOX!=0) || (POSCFG_FEATURE_TIMERFIRED != 0)
2549 
2561 POSEXTERN VAR_t POSCALL posTimerFired(POSTIMER_t tmr);
2562 #endif
2563 
2564 #endif /* POSCFG_FEATURE_TIMER */
2565 
2567 /*-------------------------------------------------------------------------*/
2568 
2569 #if (DOX!=0) || (POSCFG_FEATURE_SOFTINTS != 0)
2570 
2616 POSEXTERN void POSCALL posSoftInt(UVAR_t intno, UVAR_t param);
2617 
2631 POSEXTERN VAR_t POSCALL posSoftIntSetHandler(UVAR_t intno,
2632  POSINTFUNC_t inthandler);
2633 
2634 #if (DOX!=0) || (POSCFG_FEATURE_SOFTINTDEL != 0)
2635 
2648 POSEXTERN VAR_t POSCALL posSoftIntDelHandler(UVAR_t intno);
2649 #endif
2650 
2651 #endif /* POSCFG_FEATURE_SOFTINTS */
2652 
2654 /*-------------------------------------------------------------------------*/
2655 
2656 #if (DOX!=0) || (POSCFG_FEATURE_ATOMICVAR != 0)
2657 
2682 POSEXTERN void POSCALL posAtomicSet(POSATOMIC_t *var, INT_t value);
2683 
2694 POSEXTERN INT_t POSCALL posAtomicGet(POSATOMIC_t *var);
2695 
2706 POSEXTERN INT_t POSCALL posAtomicAdd(POSATOMIC_t *var, INT_t value);
2707 
2718 POSEXTERN INT_t POSCALL posAtomicSub(POSATOMIC_t *var, INT_t value);
2719 
2720 #endif /* POSCFG_FEATURE_ATOMICVAR */
2721 
2724 /*-------------------------------------------------------------------------*/
2725 
2726 #if (DOX!=0) || (POSCFG_FEATURE_LISTS != 0)
2727 
2742 #define POSLIST_HEAD 0
2743 #define POSLIST_TAIL 1
2744 
2760 POSEXTERN void POSCALL posListAdd(POSLISTHEAD_t *listhead, UVAR_t pos,
2761  POSLIST_t *new);
2762 
2794 POSEXTERN POSLIST_t* POSCALL posListGet(POSLISTHEAD_t *listhead, UVAR_t pos,
2795  UINT_t timeout);
2796 
2805 POSEXTERN void POSCALL posListRemove(POSLIST_t *listelem);
2806 
2807 #if (DOX!=0) || (POSCFG_FEATURE_LISTJOIN != 0)
2808 
2827 POSEXTERN void POSCALL posListJoin(POSLISTHEAD_t *baselisthead, UVAR_t pos,
2828  POSLISTHEAD_t *joinlisthead);
2829 #endif
2830 
2831 #if (DOX!=0) || (POSCFG_FEATURE_LISTLEN != 0)
2832 
2843 POSEXTERN UINT_t POSCALL posListLen(POSLISTHEAD_t *listhead);
2844 #endif
2845 
2857 POSEXTERN void POSCALL posListInit(POSLISTHEAD_t *listhead);
2858 
2866 POSEXTERN void POSCALL posListTerm(POSLISTHEAD_t *listhead);
2867 
2868 #if (DOX!=0)
2869 
2881 #define POSLIST_ELEMENT(elem, type, member)
2882 #else
2883 #define POSLIST_ELEMENT(elem, type, member) \
2884  ((type*)((char*)(elem)-(char*)(&((type*)NULL)->member)))
2885 #endif
2886 
2890 #define POSLIST_IS_EMPTY(plisthead) \
2891  ((plisthead)->next == (POSLIST_t*)(plisthead))
2892 
2896 #define POSLIST_NEXT_ENTRY(plist) (plist)->next
2897 
2901 #define POSLIST_PREV_ENTRY(plist) (plist)->prev
2902 
2906 #define POSLIST_FIRST_ENTRY(plisthead) (plisthead)->next
2907 
2911 #define POSLIST_LAST_ENTRY(plisthead) (plisthead)->prev
2912 
2916 #define POSLIST_IS_FIRST_ENTRY(element) ((element)->prev==(element)->head)
2917 
2921 #define POSLIST_IS_LAST_ENTRY(element) ((element)->next==(element)->head)
2922 
2925 #define POSLIST_IS_END(plisthead, element) \
2926  ((element)==(POSLIST_t*)(plisthead))
2927 
2928 
2929 #if (DOX!=0)
2930 
2946 #define POSLIST_FOR_EACH_ENTRY(plisthead, runvar)
2947 #else
2948 #define POSLIST_FOR_EACH_ENTRY(plisthead, runvar) \
2949  for (runvar = POSLIST_FIRST_ENTRY(plisthead); \
2950  !POSLIST_IS_END(plisthead, runvar); \
2951  runvar = POSLIST_NEXT_ENTRY(runvar))
2952 #endif
2953 
2954 #if (DOX!=0)
2955 
2976 #define POSLIST_FOREACH_BEGIN(plisthead, runvar, type, listmember)
2977 #else
2978 #define POSLIST_FOREACH_BEGIN(plisthead, runvar, type, listmember) \
2979  do { POSLIST_t *r, *n; \
2980  for (r = POSLIST_FIRST_ENTRY(plisthead); \
2981  !POSLIST_IS_END(plisthead, r); r = n) { \
2982  n = POSLIST_NEXT_ENTRY(r); \
2983  runvar = POSLIST_ELEMENT(r, type, listmember);
2984 #endif
2985 
2986 #if (DOX!=0)
2987 
2993 #define POSLIST_FOREACH_END
2994 #else
2995 #define POSLIST_FOREACH_END \
2996  } } while(0)
2997 #endif
2998 
2999 #endif /* POSCFG_FEATURE_LISTS */
3000 
3003 /*---------------------------------------------------------------------------
3004  * DEBUG FEATURES
3005  *-------------------------------------------------------------------------*/
3006 
3051 #if (DOX!=0) || defined(HAVE_PLATFORM_ASSERT)
3052 
3060 #define P_ASSERT(text,x) \
3061  if (!(x)) POSCALL p_pos_assert((const char*)(text), __FILE__, __LINE__)
3062 #else
3063 #define P_ASSERT(text,x) do { } while(0)
3064 #endif
3065 
3066 #if (DOX!=0) || defined(POS_DEBUGHELP)
3067 
3073 {
3091 };
3092 typedef enum PTASKSTATE PTASKSTATE;
3093 
3099 {
3103 };
3104 typedef enum PEVENTTYPE PEVENTTYPE;
3105 
3115 typedef struct PICOEVENT
3116 {
3117  struct PICOEVENT *next;
3119  struct PICOEVENT *prev;
3121 #if DOX
3125 #else
3126  enum PEVENTTYPE type;
3127 #endif
3128  void *handle;
3130  const char *name;
3136 } PICOEVENT;
3137 
3147 typedef struct PICOTASK
3148 {
3149  struct PICOTASK *next;
3151  struct PICOTASK *prev;
3157  const char *name;
3159 #if DOX
3163 #else
3164  enum PTASKSTATE state;
3165 #endif
3166  struct PICOEVENT *event;
3170 } PICOTASK;
3171 
3172 #if DOX
3173 
3195 #define POS_SETTASKNAME(taskhandle, taskname)
3196 
3216 #define POS_SETEVENTNAME(eventhandle, name)
3217 
3218 #else
3219 #define POS_SETTASKNAME(taskhandle, taskname) \
3220  do { if ((taskhandle) != NULL) (taskhandle)->deb.name = taskname;} while(0)
3221 #define POS_SETEVENTNAME(eventhandle, name) \
3222  posdeb_setEventName(eventhandle, name)
3223 POSEXTERN void posdeb_setEventName(void *event, const char *name);
3224 #endif
3225 
3226 #ifdef _POSCORE_C
3227 struct PICOTASK *picodeb_taskhistory[3];
3228 struct PICOTASK *picodeb_tasklist = NULL;
3229 struct PICOEVENT *picodeb_eventlist = NULL;
3230 #else
3231 
3245 extern struct PICOTASK *picodeb_taskhistory[3];
3246 
3259 extern struct PICOTASK *picodeb_tasklist;
3260 
3275 extern struct PICOEVENT *picodeb_eventlist;
3276 #endif
3277 
3278 #else /* POS_DEBUGHELP */
3279 
3280 #define POS_SETTASKNAME(taskhandle, name) do { } while(0)
3281 #define POS_SETEVENTNAME(eventhandle, name) do { } while(0)
3282 
3283 #endif /* POS_DEBUGHELP */
3284 
3287 /* ==== END OF USER API ==== */
3288 
3289 
3290 
3291 /*---------------------------------------------------------------------------
3292  * INTERNAL DEFINITIONS
3293  *-------------------------------------------------------------------------*/
3294 
3295 #ifdef PICOS_PRIVINCL
3296 
3297 #if MVAR_BITS == 8
3298 #ifndef _POSCORE_C
3299 POSEXTERN UVAR_t posShift1lTab_g[8];
3300 #endif
3301 #define pos_shift1l(bits) posShift1lTab_g[(UVAR_t)(bits)]
3302 #else
3303 #define pos_shift1l(bits) (((UVAR_t)1)<<(bits))
3304 #endif
3305 
3306 #endif /* PICOS_PRIV_H */
3307 
3308 /*-------------------------------------------------------------------------*/
3309 
3310 /* include the header of the nano layer */
3311 
3312 #ifdef POSNANO
3313 #ifdef POSCFG_ENABLE_NANO
3314 #undef POSCFG_ENABLE_NANO
3315 #endif
3316 #define POSCFG_ENABLE_NANO 1
3317 #else
3318 #ifndef POSCFG_ENABLE_NANO
3319 #define POSCFG_ENABLE_NANO 0
3320 #endif
3321 #endif
3322 #if POSCFG_ENABLE_NANO != 0
3323 #ifdef PICOSUBDIR
3324 /* required because of stupid CC65 compiler */
3325 #include <picoos\pos_nano.h>
3326 #else
3327 #include <pos_nano.h>
3328 #endif
3329 #endif
3330 
3331 /*-------------------------------------------------------------------------*/
3332 
3333 /* defaults for hooks */
3334 
3335 #ifndef POSCFG_TASKEXIT_HOOK
3336 #define POSCFG_TASKEXIT_HOOK 0
3337 #endif
3338 
3339 /*-------------------------------------------------------------------------*/
3340 
3341 /* fully define the task structure */
3342 
3343 #ifndef NOS_TASKDATA
3344 #define NOS_TASKDATA
3345 #endif
3346 
3347 #if POSCFG_TASKEXIT_HOOK != 0
3348 typedef enum {
3349  texh_exitcalled,
3350  texh_freestackmem
3351 } texhookevent_t;
3352 typedef void (*POSTASKEXITFUNC_t)(POSTASK_t task, texhookevent_t event);
3353 #endif
3354 
3355 struct POSTASK {
3357  NOS_TASKDATA
3358 #if POSCFG_TASKCB_USERSPACE > 0
3360  sizeof(UVAR_t)-2) / sizeof(UVAR_t)];
3361 #endif
3362 #if POSCFG_TASKEXIT_HOOK != 0
3363  POSTASKEXITFUNC_t exithook;
3364 #endif
3365 #if DOX==0
3366 #if POSCFG_ARGCHECK > 1
3367  UVAR_t magic;
3368 #endif
3369 #if SYS_TASKDOUBLELINK != 0
3370  struct POSTASK *prev;
3371 #endif
3372  struct POSTASK *next;
3373  UVAR_t bit_x;
3374 #if SYS_TASKTABSIZE_Y > 1
3375  UVAR_t bit_y;
3376  UVAR_t idx_y;
3377 #endif
3378 #ifndef POS_DEBUGHELP
3379  UINT_t ticks;
3380 #endif
3381 #if SYS_TASKSTATE != 0
3382  UVAR_t state;
3383 #endif
3384 #if POSCFG_FEATURE_ERRNO != 0
3385  VAR_t error;
3386 #endif
3387 #if POSCFG_FEATURE_MSGBOXES != 0
3388  UVAR_t msgwait;
3389  POSSEMA_t msgsem;
3390  void *firstmsg;
3391  void *lastmsg;
3392 #endif
3393 #ifdef POS_DEBUGHELP
3394  struct PICOTASK deb;
3395 #endif
3396 #if SYS_TASKEVENTLINK != 0
3397  void *event;
3398 #endif
3399 #endif /* !DOX */
3400 };
3401 
3402 
3403 #endif /* _PICOOS_H */
3404 
void(* POSIDLEFUNC_t)(void)
Idle task function pointer.
Definition: picoos.h:849
POSEXTERN void POSCALL posTimerDestroy(POSTIMER_t tmr)
struct POSTIMER * POSTIMER_t
Handle to a timer object.
Definition: picoos.h:885
POSEXTERN VAR_t POSCALL posMessageSend(void *buf, POSTASK_t taskhandle)
POSEXTERN volatile UVAR_t posInInterrupt_g
Global flag variable. This variable is nonzero when the CPU is currently executing an interrupt servi...
Definition: picoos.h:1009
#define POSCFG_ALIGNMENT
Definition: port.h:99
POSEXTERN void POSCALL c_pos_intExit(void)
POSEXTERN void POSCALL posSoftInt(UVAR_t intno, UVAR_t param)
UINT_t timeout
State of the task&#39;s timeout counter.
Definition: picoos.h:3168
Definition: picoos.h:3080
struct PICOEVENT PICOEVENT
Event info structure.
VAR_t errno
Unix style error variable. This variable is global for the currently runnig task. ...
Definition: picoos.h:1033
POSEXTERN void POSCALL posTaskExit(void)
POSFROMEXT void POSCALL p_pos_intContextSwitchPending(void)
POSEXTERN void *POSCALL posMessageAlloc(void)
POSEXTERN VAR_t POSCALL posMutexTryLock(POSMUTEX_t mutex)
#define MPTR_t
Definition: port.h:89
POSEXTERN void POSCALL posListRemove(POSLIST_t *listelem)
POSEXTERN POSLIST_t *POSCALL posListGet(POSLISTHEAD_t *listhead, UVAR_t pos, UINT_t timeout)
POSEXTERN void POSCALL posTaskSleep(UINT_t ticks)
const char * name
Name of this task (ASCII string)
Definition: picoos.h:3157
Definition: picoos.h:3076
POSEXTERN VAR_t POSCALL posSemaSignal(POSSEMA_t sema)
POSEXTERN INT_t POSCALL posAtomicAdd(POSATOMIC_t *var, INT_t value)
POSEXTERN INT_t POSCALL posAtomicSub(POSATOMIC_t *var, INT_t value)
POSEXTERN VAR_t POSCALL posTimerStart(POSTIMER_t tmr)
struct PICOEVENT * prev
Pointer to the previous event structure.
Definition: picoos.h:3119
POSFROMEXT void POSCALL p_pos_powerTickResume(void)
POSEXTERN VAR_t POSCALL posTaskUnused(POSTASK_t taskhandle)
Definition: picoos.h:3102
const char * name
Name of this event (ASCII string)
Definition: picoos.h:3130
POSFROMEXT void POSCALL p_pos_initTask(POSTASK_t task, void *stackstart, POSTASKFUNC_t funcptr, void *funcarg)
POSFROMEXT void POSCALL p_pos_freeStack(POSTASK_t task)
struct PICOTASK * picodeb_taskhistory[3]
This array contains the last 3 tasks that run.
POSFROMEXT void POSCALL p_pos_initArch(void)
POSEXTERN void POSCALL posFlagDestroy(POSFLAG_t flg)
POSEXTERN void POSCALL c_pos_intExitQuick(void)
PTASKSTATE
Task states (used for debugging when POSCFG_FEATURE_DEBUGHELP is set to 1)
Definition: picoos.h:3072
POSEXTERN VAR_t POSCALL posMutexLock(POSMUTEX_t mutex)
POSEXTERN void POSCALL posMutexDestroy(POSMUTEX_t mutex)
POSEXTERN POSTASK_t POSCALL posTaskCreate(POSTASKFUNC_t funcptr, void *funcarg, VAR_t priority, void *stackstart)
UVAR_t JIF_t
Timer counter type. Can be UVAR_t or UINT_t.
Definition: picoos.h:828
POSEXTERN POSPOWERCB_t POSCALL posPowerSetCallback(POSPOWERCB_t callback)
struct PICOTASK * next
Pointer to the next task info structure.
Definition: picoos.h:3149
Definition: picoos.h:3088
void * handle
Handle value of the pico]OS event.
Definition: picoos.h:3128
PEVENTTYPE
Event types (used for debugging when POSCFG_FEATURE_DEBUGHELP is set to 1)
Definition: picoos.h:3098
pico]OS configuration file
struct PICOEVENT * picodeb_eventlist
Pointer to the list of all system events.
POSEXTERN volatile POSTASK_t posCurrentTask_g
Global task variable. This variable points to the environment structure of the currently active task...
Definition: picoos.h:990
struct POSMUTEX * POSMUTEX_t
Handle to a mutex object.
Definition: picoos.h:875
POSFROMEXT void POSCALL p_pos_intContextSwitch(void)
POSEXTERN void POSCALL posMessageFree(void *buf)
POSEXTERN POSIDLEFUNC_t POSCALL posInstallIdleTaskHook(POSIDLEFUNC_t idlefunc)
POSEXTERN void POSCALL posTaskSchedUnlock(void)
POSEXTERN VAR_t POSCALL posSemaGet(POSSEMA_t sema)
POSEXTERN void *POSCALL posTaskGetUserspace(void)
POSEXTERN VAR_t POSCALL posTaskSetPriority(POSTASK_t taskhandle, VAR_t priority)
POSEXTERN void POSCALL posPowerDisableSleep(void)
POSEXTERN void POSCALL posSemaDestroy(POSSEMA_t sema)
POSFROMEXT void POSCALL p_pos_lock(void)
pico]OS nano layer main include file
POSEXTERN void POSCALL posTaskSchedLock(void)
POSEXTERN void POSCALL c_pos_timerStep(UVAR_t ticks)
Definition: picoos.h:3085
struct POSFLAG * POSFLAG_t
Handle to a flag object.
Definition: picoos.h:880
Definition: picoos.h:3100
POSEXTERN void POSCALL posListAdd(POSLISTHEAD_t *listhead, UVAR_t pos, POSLIST_t *new)
POSEXTERN POSFLAG_t POSCALL posFlagCreate(void)
POSFROMEXT void POSCALL p_pos_softContextSwitch(void)
POSEXTERN POSTIMER_t POSCALL posTimerCreate(void)
POSFROMEXT void POSCALL p_pos_startFirstContext(void)
void(* POSTASKFUNC_t)(void *arg)
Generic function pointer.
Definition: picoos.h:837
POSEXTERN VAR_t POSCALL posSoftIntDelHandler(UVAR_t intno)
POSEXTERN void POSCALL posListJoin(POSLISTHEAD_t *baselisthead, UVAR_t pos, POSLISTHEAD_t *joinlisthead)
Definition: picoos.h:3077
POSEXTERN VAR_t POSCALL posFlagWait(POSFLAG_t flg, UINT_t timeoutticks)
POSEXTERN void POSCALL posListTerm(POSLISTHEAD_t *listhead)
unsigned MINT_t UINT_t
Unsigned integer.
Definition: picoos.h:802
POSEXTERN void POSCALL c_pos_intEnter(void)
POSEXTERN VAR_t POSCALL posSoftIntSetHandler(UVAR_t intno, POSINTFUNC_t inthandler)
struct POSLIST POSLIST_t
List variable. This variable type is used as running variable of a list or as list link...
Definition: picoos.h:914
POSEXTERN POSTASK_t POSCALL posTaskGetCurrent(void)
POSEXTERN VAR_t POSCALL posSemaWait(POSSEMA_t sema, UINT_t timeoutticks)
POSEXTERN VAR_t POSCALL posMutexUnlock(POSMUTEX_t mutex)
POSEXTERN VAR_t POSCALL posFlagSet(POSFLAG_t flg, UVAR_t flgnum)
struct PICOTASK * picodeb_tasklist
Pointer to the list of active tasks.
struct PICOEVENT * event
Cross-reference to the involved event.
Definition: picoos.h:3166
Definition: picoos.h:3083
signed MVAR_t VAR_t
Signed machine variable type. This variable type is the fastest for the target architecture.
Definition: picoos.h:770
#define MVAR_t
Definition: port.h:71
POSTASKFUNC_t func
First function that ran in the task context.
Definition: picoos.h:3155
POSEXTERN POSSEMA_t POSCALL posSemaCreate(INT_t initcount)
POSFROMEXT void POSCALL p_pos_powerWakeup(void)
#define POSCFG_TASKCB_USERSPACE
Definition: poscfg.h:196
POSEXTERN void POSCALL posPowerEnableSleep(void)
PTASKSTATE state
Current state of the task (see PTASKSTATE for details).
Definition: picoos.h:3160
POSFROMEXT void POSCALL p_pos_powerSleep(void)
struct PICOEVENT * next
Pointer to the next event info structure.
Definition: picoos.h:3117
POSEXTERN void POSCALL posListInit(POSLISTHEAD_t *listhead)
POSEXTERN void POSCALL posTaskYield(void)
struct PICOTASK PICOTASK
Task info structure.
POSEXTERN void *POSCALL posMessageWait(UINT_t timeoutticks)
Definition: picoos.h:3086
Definition: picoos.h:3074
unsigned MVAR_t UVAR_t
Unsigned machine variable type. This variable type is the fastest for the target architecture.
Definition: picoos.h:777
POSEXTERN void POSCALL posAtomicSet(POSATOMIC_t *var, INT_t value)
POSEXTERN void POSCALL posInit(POSTASKFUNC_t firstfunc, void *funcarg, VAR_t priority, void *stackFirstTask, void *stackIdleTask)
POSEXTERN volatile JIF_t jiffies
Global timer variable. The jiffies counter variable is incremented HZ times per second.
Definition: picoos.h:2458
POSEXTERN void *POSCALL posMessageGet(void)
INT_t counter
State of the internal counter of the event (semaphore or mutex), or bitfield of flags (flag event) ...
Definition: picoos.h:3132
POSEXTERN volatile UVAR_t posRunning_g
Global flag variable. This variable is nonzero when the operating system is initialized and running...
Definition: picoos.h:1021
void(* POSINTFUNC_t)(UVAR_t arg)
Software interrupt callback function pointer.
Definition: picoos.h:845
port configuration file
signed MINT_t INT_t
Signed integer.
Definition: picoos.h:791
Task info structure.
Definition: picoos.h:3147
POSFROMEXT UVAR_t POSCALL p_pos_findbit(const UVAR_t bitfield)
VAR_t SJIF_t
Signed type of JIF_t.
Definition: picoos.h:824
struct POSLISTHEAD POSLISTHEAD_t
List variable. This variable defines the head of a list.
Definition: picoos.h:919
struct POSTASK * POSTASK_t
Task environment structure.
Definition: picoos.h:942
Definition: picoos.h:3075
PEVENTTYPE type
Type of the event (semaphore / mutex / flag event, see PEVENTTYPE for details).
Definition: picoos.h:3122
Definition: picoos.h:3078
POSTASK_t handle
Handle value of the pico]OS task.
Definition: picoos.h:3153
struct POSSEMA * POSSEMA_t
Handle to a semaphore object.
Definition: picoos.h:870
POSEXTERN UINT_t POSCALL posListLen(POSLISTHEAD_t *listhead)
POSEXTERN VAR_t POSCALL posTimerSet(POSTIMER_t tmr, POSSEMA_t sema, UINT_t waitticks, UINT_t periodticks)
void(* POSPOWERCB_t)(UVAR_t event)
Power management callback function pointer.
Definition: picoos.h:854
POSFROMEXT void POSCALL p_pos_powerTickSuspend(UVAR_t ticks)
volatile INT_t POSATOMIC_t
Atomic variable.
Definition: picoos.h:890
unsigned MPTR_t MEMPTR_t
Memory pointer type.
Definition: picoos.h:818
POSEXTERN VAR_t POSCALL posTimerFired(POSTIMER_t tmr)
POSEXTERN void POSCALL c_pos_timerInterrupt(void)
struct PICOTASK * prev
Pointer to the previous task structure.
Definition: picoos.h:3151
POSFROMEXT void POSCALL p_pos_unlock(void)
POSEXTERN INT_t POSCALL posAtomicGet(POSATOMIC_t *var)
POSEXTERN VAR_t POSCALL posMessageAvailable(void)
#define POS_USERTASKDATA
Definition: port.h:409
Definition: picoos.h:3089
Event info structure.
Definition: picoos.h:3115
Definition: picoos.h:3101
POSEXTERN VAR_t POSCALL posTimerStop(POSTIMER_t tmr)
Definition: picoos.h:3079
POSEXTERN volatile POSTASK_t posNextTask_g
Global task variable. This variable points to the environment structure of the next task that shall b...
Definition: picoos.h:1000
Definition: picoos.h:3082
POSEXTERN POSMUTEX_t POSCALL posMutexCreate(void)
POSEXTERN UINT_t POSCALL c_pos_nextWakeup(void)
POSEXTERN VAR_t POSCALL posFlagGet(POSFLAG_t flg, UVAR_t mode)
POSEXTERN VAR_t POSCALL posTaskGetPriority(POSTASK_t taskhandle)