⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tsk.h

📁 一个嵌入式实时操作系统源码
💻 H
📖 第 1 页 / 共 3 页
字号:
/*
   --- Version 2.2 93-06-08 10:41 ---

   TSK.H - CTask - Type definitions and global routine prototypes.

   Public Domain Software written by
      Thomas Wagner
      Ferrari electronic Gmbh
      Beusselstrasse 27
      D-1000 Berlin 21
      Germany
*/


#include "tskconf.h"
#include <stdio.h>
#include <dos.h>
#include <conio.h>
#include <stdlib.h>

#if defined(__TURBOC__)
#define TSK_TURBO  1
#define TSK_MSC    0
#else
#define TSK_TURBO  0
#define TSK_MSC    1
#endif

/* 
   Selecting near/far and calling sequence attributes:

   For Turbo and Microsoft, you won't have to change the following
   defines. Just set the NEAR_CODE and LOCALS_FAR defines, and the
   CALL_PASCAL define, in tskconf.h.

   Other compilers may or may not support some aspects of the model
   mix used in standard CTask. For those compilers, you may have to
   edit the definitions to suit your memory model.

   Globalfunc  defines a global CTask routine.
               The attributes are normally "far cdecl", but may also
               be "near" and/or "pascal", depending on configuration.

   CGlobalfunc defines a global CTask routine that must be called
               using the C calling sequence.
               The attributes are normally "far cdecl", but may also
               be "near cdecl".

   Localfunc   defines a routine that is exclusively used inside CTask.
               Those routines are normally 'near' to save some code.
               If your compiler does not allow placing all CTask
               routines in a common code segment, you will have to
               define this as 'far'.
               It normally has the "near cdecl" attribute, but may also
               be "far" and/or "pascal".

   CLocalfunc  same as Localfunc, but must use C calling sequence.

   Staticfunc  defines a routine that is local to a module.
               Those routines are only used within a module, and can 
               normally be 'near'. Only if your compiler does not 
               support the 'near' keyword, or places all routines in
               separate segments, will you have to redefine this as 
               empty or 'far'.
               The attributes normally are "near pascal".

   CStaticfunc same as Staticfunc, but must use C calling sequence.

   Taskfunc    defines task and call-back functions.
               Must be 'far cdecl' unless your compiler does not
               support those keywords.

   Neardata    Is the attribute for local shared data in CTask. It is
               defined as 'near' for MSC, and empty for Turbo C.
               This causes the shared data to be placed in the
               default data segment (except for Turbo C Huge, where
               the assignment to the CTask data segment is done with
               compiler switches).
               If your compiler does not support the 'near' attribute
               for global data, you may define this as empty, but please
               make sure that the assembler modules can access the data.

*/

#if (TSK_TURBO)
#define Neardata           /* Turbo doesn't like near on data */
#else
#define Neardata near      /* MSC requires it when in Large model */
#endif

#if (NEAR_CODE)
#define Farc  near        /* near code means all routines are near */
#define Nearc near        /* including internal ones */
#else
#if (CODE_SHARING && TSK_MSC)
#define Farc  far _loadds /* for code sharing, _loadds is required */
#else
#define Farc  far         /* else it's just 'far' */
#endif
#if (LOCALS_FAR)
#define Nearc far         /* Near code is far, too */
#else
#define Nearc near        /* That's the normal case */
#endif
#endif
#if (CALL_PASCAL)
#define Cdeclc pascal
#else
#define Cdeclc cdecl
#endif

#define Globalfunc   Farc Cdeclc
#define Localfunc    Nearc Cdeclc
#define CGlobalfunc  Farc cdecl
#define CLocalfunc   Nearc cdecl
#define Staticfunc   near pascal
#define CStaticfunc  near cdecl
#define Taskfunc     far cdecl

/*
   The local attribute is used mainly for documentation purposes.
   It should be 'static', unless you want the routines to be globally
   visible for debugging (define empty).
*/

#define local  static

/*---------------------------------------------------------------------*/

typedef unsigned char byte;
typedef unsigned short word;
typedef unsigned long dword;
typedef void far *farptr;
typedef byte far *byteptr;
typedef word far *wordptr;
typedef void (Taskfunc *funcptr)();
typedef void (Taskfunc *funcptr_void)(void);
typedef void (Taskfunc *funcptr_int)(int);
typedef void (Taskfunc *funcptr_fp)(farptr);
typedef void (Taskfunc *funcptr_dword)(dword);
typedef void (interrupt far * intprocptr)(void);

#define TTIMEOUT ((farptr) -1L)
#define TWAKE    ((farptr) -2L)
#define TWATCH   ((farptr) -3L)

#define TIMEOUT   (-1)
#define WAKE      (-2)
#define WATCH     (-3)

/* Task states */

#define  ST_KILLED   (byte)0
#define  ST_STOPPED  (byte)1
#define  ST_DELAYED  (byte)2
#define  ST_WAITING  (byte)3
#define  ST_ELIGIBLE (byte)4
#define  ST_RUNNING  (byte)5

/* Task flags */

#define  F_TEMP      (byte)0x80     /* Task is temporary, free on kill */
#define  F_STTEMP    (byte)0x40     /* Task stack is temporary, free on kill */
#define  F_PERM      (byte)0x20     /* Task is permanent, do not kill */

#define  F_USES_NDP  (byte)0x02     /* Task uses the NDP */
#define  F_CRIT      (byte)0x01     /* Task is critical, may not be preempted */

#define  FL_SYSM     (byte)0xf0     /* Mask for system flags */
#define  FL_USRM     (byte)0x0f     /* Mask for user flags */

/* Timer queue element action kinds (upper nibble of elkind) */

#define  TELEM_TIMER       (byte)0x10  /* Timeout element */
#define  TELEM_MEM         (byte)0x20  /* Memory watch element */
#define  TELEM_PORT        (byte)0x30  /* Port watch element */
#define  TELEM_HOTKEY      (byte)0x40  /* Hotkey element */

/* Timer watch element comparison kinds (lower nibble of elkind) */

#define  TCMP_EQ           (byte)1     /* Equal */
#define  TCMP_NE           (byte)2     /* Not Equal */
#define  TCMP_GE           (byte)3     /* Greater or Equal (unsigned) */
#define  TCMP_LE           (byte)4     /* Less or Equal (unsigned) */
#define  TCMP_GES          (byte)5     /* Greater or Equal (signed) */
#define  TCMP_LES          (byte)6     /* Less or Equal (signed) */
#define  TCMP_CHG          (byte)7     /* Change in value */

/* Timer queue element control structure pointer kinds */

#define  TKIND_TASK        (byte)1     /* tcbptr, Wakeup associated task */
#define  TKIND_WAKE        (byte)2     /* tcbptr, but not same task */
#define  TKIND_PROC        (byte)3     /* call function */
#define  TKIND_FLAG        (byte)4     /* flagptr, set flag */
#define  TKIND_COUNTER     (byte)5     /* counterptr, increment counter */
#define  TKIND_COUNTDEC    (byte)6     /* counterptr, decrement counter */

/* Timer queue element flags */

#define  TFLAG_BUSY        (byte)0x01  /* Timer task is busy processing element */
#define  TFLAG_ENQUEUE     (byte)0x02  /* Enqueue after processing */
#define  TFLAG_UNQUEUE     (byte)0x04  /* Don't enqueue after processing */
#define  TFLAG_REMOVE      (byte)0x08  /* Free element after processing */
#define  TFLAG_REPEAT      (byte)0x40  /* Bit set signals repeat processing */
#define  TFLAG_TEMP        (byte)0x80  /* Bit set means temporary element */

/* Name link and queue head structure types */

#define  Q_HEAD         (byte)0x80     /* Queue head flag */

#define  TYP_GROUP      (byte)0
#define  TYP_TCB        (byte)1
#define  TYP_FLAG       (byte)2
#define  TYP_RESOURCE   (byte)3
#define  TYP_COUNTER    (byte)4
#define  TYP_MAILBOX    (byte)5
#define  TYP_PIPE       (byte)6
#define  TYP_WPIPE      (byte)7
#define  TYP_BUFFER     (byte)8
#define  TYP_TIMER      (byte)9
#define  TYP_WATCH     (byte)10
#define  TYP_HOTKEY    (byte)11

#define  NAMELENGTH     9  /* For structure names: 8 bytes + zero */

/* Installation flags */

#define IFL_VIDEO      0x0001      /* Install INT 10 access resource */
#define IFL_DISK       0x0002      /* Install INT 13 access resource */
#define IFL_INT8_DIR   0x0004      /* Call original INT 8 directly */
#define IFL_PRINTER    0x0008      /* Install INT 17 handler */
#define IFL_INT15      0x0010      /* Install IBM-AT INT 15 handler */
#define IFL_NODOSVARS  0x0020      /* Don't swap DOS variables */
#define IFL_NOEXITCHECK 0x0040     /* Don't check for premature exit */

#define IFL_STD   (IFL_DISK | IFL_PRINTER | IFL_INT15)   /* Standard flags */

/* 
   Size of the DOS variable swap area plus 8 bytes.
   40+8 is more than sufficient for all current versions of DOS up to
   DOS 4.01.
*/

#define DOSSWAPSIZE     0x30

/* --------------------------------------------------------------------- */

/*
   The following types define 80x87 data. They are used only when
   NDP is defined TRUE in tskconf.h.
   The type definitions and the basic algorithms for saving the
   coprocessor state were provided by Dan Heine.
*/

/* Temporary real (80-bit) type */

typedef struct {
               word  mant15_0;
               word  mant31_16;
               word  mant47_32;
               word  mant63_48;
               word  s_exponent;
               } t_real;

typedef t_real far *t_realptr;

/* 80x87 state save area */

typedef struct {
               word     control87;
               word     status87;
               word     tag87;
               word     iplo87;
               word     iphi87_opcode87;
               word     opaddrlo87;
               word     opaddrhi87_null;
               t_real   st0;
               t_real   st1;
               t_real   st2;
               t_real   st3;
               t_real   st4;
               t_real   st5;
               t_real   st6;
               t_real   st7;
               } ndpsave_t;

typedef ndpsave_t far *ndpsaveptr;

/* --------------------------------------------------------------------- */

typedef struct callchain_rec far *callchainptr;
typedef void (Taskfunc *funcptr_ccp)(callchainptr);

typedef struct callchain_rec {
                             callchainptr next;    /* Must be first */
                             funcptr_ccp  func;
                             farptr       user_ptr;
#if (TSK_DYNAMIC)
                             byte         flags;
#endif
                             } callchain;

/* --------------------------------------------------------------------- */

/*
   The 'queue' structure is a dual link for linking task control blocks 
   and timer blocks. The first three fields are used both for the queue
   head, and for elements to be inserted in a queue.

   CAUTION: Do not change the order of the first three fields in
            either queue or queue_head!
*/

typedef struct {
                word     prior;
                word     ini_prior;
               } qelem_pri;

typedef struct queue_rec far *queptr;

typedef struct queue_rec {
                          volatile queptr next;
                          volatile queptr prev;
                          byte            kind;
                          union  {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -