Common Rules of T-Kernel

Data Types

General Data Types

typedef signed char          B;     /* signed 8-bit integer */
typedef signed short         H;     /* signed 16-bit integer */
typedef signed long          W;     /* signed 32-bit integer */
typedef signed long long     D;     /* signed 64-bit integer */
typedef unsigned char       UB;     /* unsigned 8-bit integer */
typedef unsigned short      UH;     /* unsigned 16-bit integer */
typedef unsigned long       UW;     /* unsigned 32-bit integer */
typedef unsigned long long  UD;     /* unsigned 64-bit integer */

typedef char                VB;     /* 8-bit data without an intended type */
typedef short               VH;     /* 16-bit data without an intended type */
typedef long                VW;     /* 32-bit data without an intended type */
typedef long long           VD;     /* 64-bit data without an intended type */
typedef void                *VP;    /* pointer to data without an intended type */

typedef volatile B          _B;     /* volatile declaration */
typedef volatile H          _H;
typedef volatile W          _W;
typedef volatile D          _D;
typedef volatile UB         _UB;
typedef volatile UH         _UH;
typedef volatile UW         _UW;
typedef volatile UD         _UD;

typedef signed int          INT;    /* signed integer of processor bit width, 32 bits or more */
typedef unsigned int        UINT;   /* unsigned integer of processor bit width, 32 bits or more */

typedef INT                 ID;     /* general ID */
typedef W                   MSEC;   /* general time (in milliseconds) */

typedef void            (*FP)();    /* general function address */
typedef INT             (*FUNCP)(); /* general function address */

#define LOCAL           static      /* local symbol definition */
#define EXPORT                      /* global symbol definition */
#define IMPORT          extern      /* global symbol reference */

/*
 * Boolean values
 *      TRUE = 1 is defined, but any value other than 0 is logically TRUE.
 *      A decision such as bool == TRUE must be avoided for this reason.
 *      Instead use bool != FALSE.
 */
typedef INT             BOOL;
#define TRUE            1           /* true */
#define FALSE           0           /* false */

/*
 * TRON character codes
 */
typedef UH              TC;         /* TRON character codes */
#define TNULL           ((TC)0)     /* TRON code string termination */

Note

  • VB, VH, VW, and VD differ from B, H, W, and D in that the former mean only the bit width is known, not the contents of the data type, whereas the latter clearly indicate integer type.

  • Processor bit width must be 32 bits or more. INT and UINT must therefore always have a width of 32 bits or more.

  • BOOL defines TRUE = 1, but any value other than 0 is also TRUE. For this reason a decision such as bool == TRUE must be avoided. Instead use bool != FALSE.

NoteAdditional Notes
 

Parameters such as stksz, wupcnt, and message size that clearly do not take negative values are also in principle signed integer (INT) data type. This is in keeping with the overall TRON rule that integers should be treated as signed numbers as much as possible. As for the timeout (TMO tmout) parameter, its being a signed integer enables the use of TMO_FEVR(= -1) having special meaning. Parameters with unsigned data type are those treated as bit patterns (object attribute, event flag, etc.).

NoteDifference from T-Kernel 1.0
 

  • 64-bit D and UD are added. 'D' means Double integer. "signed" is added to the declaration of a signed integer. int is changed to long to clearly indicate that W and UW are 32-bit.

  • Though MSEC in T-Kernel 1.0 was INT (integer with processor bit width), MSEC in T-Kernel 2.0 has been changed to W (integer with 32-bit fixed width). This is a feedback from μT-Kernel specification. That specification was negatively affected when INT is 16-bit was changed to W (integer with 32-bit fixed width).

Other Defined Data Types

The following names are used for other data types that appear frequently or have special meaning, in order to make The parameter meaning clear.

typedef INT             FN;             /* Function Codes */
typedef INT             RNO;            /* rendezvous number */
typedef UW              ATR;            /* Object/handler attributes */
typedef INT             ER;             /* Error Code */
typedef INT             PRI;            /* Priority */
typedef W               TMO;            /* Timeout specification in milliseconds */
typedef D               TMO_U;          /* Timeout specification in microseconds with 64-bit integer */
typedef UW              RELTIM;         /* Relative time in milliseconds */
typedef UD              RELTIM_U;       /* Relative time in microseconds with 64-bit integer */

typedef struct systim {                 /* System time in milliseconds */
        W       hi;                     /* High 32 bits */
        UW      lo;                     /* Low 32 bits */
} SYSTIM;

typedef D               SYSTIM_U;       /* System time in microseconds with 64-bit integer */

/*
 * Common constants
 */
#define NULL            0               /* Null pointer */
#define TA_NULL         0               /* No special attributes indicated */
#define TMO_POL         0               /* Polling */
#define TMO_FEVR        (-1)            /* Eternal wait */

Note

  • A data type that combines two or more data types is represented by its main data type. For example, the value returned by tk_cre_tsk can be a task ID or error code, but since it is mainly a task ID, the data type is ID.

NoteDifference from T-Kernel 1.0
 

TMO_U that represents timeout specification in microseconds with 64-bit integer, RELTIM_U that represents relative time in microseconds with 64-bit integer, and SYSTIM_U that represents system time in microseconds with 64-bit integer are added. RELTIM_U is unsigned corresponding to RELTIM, and SYSTIM_U is signed corresponding to SYSTIM. Though SYSTIM is a structure comprising two 32-bit members, SYSTIM_U is a plain 64-bit integer rather than a structure to directly take advantage of the convenience of a 64-bit data.

Though TMO that represents timeout specification in milliseconds was INT in T-Kernel 1.0, it has been changed to W in T-Kernel 2.0. Additionally, though ATR that represents an object attribute and others and RELTIM that represents a relative time in milliseconds were UINT in T-Kernel 1.0, they have been changed to UW in T-Kernel 2.0.

NoteAdditional Notes
 

The policy is to append "_u" (u means μ) or "_U" at the end for parameters and data types representing microsecond (μsec), or append "_d" (d means double integer) or "_D" at the end for other parameters and data types representing 64-bit integer. TMO_U, RELTIM_U, and SYSTIM_U are data type names complying to this policy.