📄 rtos.h
字号:
#endif
#ifndef OS_CSEMAPTR
#define OS_CSEMAPTR
#endif
#ifndef OS_MBPTR
#define OS_MBPTR
#endif
#ifndef OS_TCBPTR
#define OS_TCBPTR
#endif
#ifndef OS_TIMERPTR
#define OS_TIMERPTR
#endif
#ifdef __cplusplus
extern "C" {
#endif
/*********************************************************************
*
* Data structures
*
**********************************************************************
*/
typedef struct OS_TASK OS_TASK;
typedef struct OS_WAIT_LIST OS_WAIT_LIST;
typedef struct OS_WAIT_OBJ OS_WAIT_OBJ;
typedef struct OS_WAIT_OBJ_EX OS_WAIT_OBJ_EX;
typedef struct OS_REGS OS_REGS;
typedef void voidRoutine(void);
typedef void OS_RX_CALLBACK(OS_U8 Data);
typedef void OS_TIMERROUTINE(void);
typedef void OS_TIMER_EX_ROUTINE(void *);
typedef void OS_ON_TERMINATE_FUNC(OS_TASK *);
typedef void OS_TICK_HOOK_ROUTINE(void);
/**********************************************************************
*
* OS_WAIT_OBJ
* OS_WAIT_LIST
* OS_WAIT_OBJ_EX
*/
struct OS_WAIT_OBJ {
OS_WAIT_LIST * pWaitList;
};
struct OS_WAIT_OBJ_EX {
OS_WAIT_OBJ WaitObj;
int v;
};
struct OS_WAIT_LIST {
OS_WAIT_LIST * pNext; /* Needs to be first element ! */
OS_WAIT_LIST * pPrev;
OS_WAIT_OBJ * pWaitObj;
OS_TASK * pTask;
};
/**********************************************************************
*
* OS_EXTEND_TASK_CONTEXT
*
* This structure is used to define a save and restore function for
* extension of the task context.
* A pointer to this structure is part of the task control block
* It is initialized by OS_ExtendTaskContext();
*/
typedef struct OS_EXTEND_TASK_CONTEXT {
void (*pfSave) ( void * pStack);
void (*pfRestore)(const void * pStack);
} OS_EXTEND_TASK_CONTEXT;
/**********************************************************************
*
* OS_TASK
*
* This structure (referred to as "task control block" or TCB) holds all relevant information
* about a single task. Note that some elements are optional, depending on the compile time
* options, especially the type of build
*/
struct OS_TASK {
//
// Elements required for all builds
//
// Start of assembly relevant section. Do not move these elements
OS_TASK * pNext; // Points to the TCB of the next task in the list (with equal or lower priority). Needs to be first element !
OS_REGS OS_STACKPTR * pStack; // Typically contains the stack pointer if the task is suspended. Needs to be second element !
// End of assembly relevant section
OS_WAIT_LIST * pWaitList; // Points to a waitable object if task is suspended.
OS_TIME Timeout;
OS_U8 Priority;
OS_U8 Stat;
OS_U8 Events; // Event storage
OS_U8 EventMask; // Event mask
//
// PPrev is required only in builds with doubly-linked task lists
//
#if OS_TASK_LIST_HAS_PPREV
OS_TASK * pPrev; //
#endif
//
// Elements required with "Track-name" functionality only. Typically available in all builds, but can be disabled at compile time
//
#if OS_TRACKNAME
const char * Name;
#endif
//
// Elements required with "Stack-check" functionality only. Available in stack-check and debug builds.
//
#if OS_CHECKSTACK
OS_UINT StackSize; // Stack size in bytes. Not required for functionality, just for analysis
OS_U8 OS_STACKPTR* pStackBot; // First byte of stack. Not required for functionality, just for analysis
#endif
//
// Elements required with profiling or debug builds
//
#if (OS_PROFILE || OS_DEBUG)
OS_U32 NumActivations; // Counts how many times task has been activated
OS_U32 NumPreemptions; // Counts how many times task has been preempted
#endif
//
// Elements required with profiling builds
//
#if OS_PROFILE
OS_U32 ExecTotal; // Time spent executing
OS_U32 ExecLast; // Time spent executing (Reference)
OS_U32 Load; // Profiling builds only:
#endif
//
// Elements required with Round-robin functionality only. Typically available in all builds, but can be disabled at compile time
//
#if OS_RR_SUPPORTED
OS_U8 TimeSliceRem;
OS_U8 TimeSliceReload;
#endif
//
// Optional Save & Restore hook support (usually only for bigger CPUs)
//
#if OS_SUPPORT_SAVE_RESTORE_HOOK
const OS_EXTEND_TASK_CONTEXT * pExtendContext;
#endif
//
// Elements required with debug builds
//
#if OS_DEBUG
char Id; // Debug builds only: Id of this control block.
#endif
//
// Allow port specific extension to the task control block. Not used in most ports
//
#ifdef OS_TCB_CPU_EX
OS_TCB_CPU_EX
#endif
};
/**********************************************************************
*
* OS_TIMER
*/
typedef struct OS_timer OS_TIMER;
struct OS_timer {
OS_TIMER * pNext;
voidRoutine* Hook;
OS_TIME Time;
OS_TIME Period;
char Active;
#if OS_DEBUG
char Id;
#endif
};
/**********************************************************************
*
* OS_TIMER_EX
*/
typedef struct {
OS_TIMER Timer;
OS_TIMER_EX_ROUTINE * pfUser;
void * pData;
} OS_TIMER_EX;
/**********************************************************************
*
* OS_TICK_HOOK
*/
typedef struct OS_TICK_HOOK OS_TICK_HOOK;
struct OS_TICK_HOOK {
OS_TICK_HOOK* pNext;
OS_TICK_HOOK_ROUTINE * pfUser;
};
/**********************************************************************
*
* OS_RSEMA
*/
typedef struct OS_RSEMA OS_RSEMA;
struct OS_RSEMA {
OS_WAIT_OBJ WaitObj;
OS_TASK * pTask; /* Owner */
OS_U8 UseCnt;
OS_RSEMA * pNext;
#if OS_DEBUG
char Id;
#endif
};
/**********************************************************************
*
* OS_CSEMA
*/
typedef struct OS_CSEMA OS_CSEMA;
struct OS_CSEMA {
OS_WAIT_OBJ WaitObj;
OS_UINT Cnt;
#if OS_DEBUG
OS_CSEMA * pNext;
char Id;
#endif
};
/**********************************************************************
*
* OS_MAILBOX
*/
typedef struct OS_MAILBOX OS_MAILBOX;
struct OS_MAILBOX {
OS_WAIT_OBJ WaitObj;
#if OS_LINK_MAILBOXES
OS_MAILBOX * pNext;
#endif
char *pData;
OS_UINT nofMsg;
OS_UINT maxMsg;
OS_UINT iRd;
OS_U8 sizeofMsg;
#if OS_DEBUG
char Id;
#endif
};
/**********************************************************************
*
* OS_Q
*/
typedef struct OS_Q OS_Q;
struct OS_Q {
OS_WAIT_OBJ WaitObj;
OS_Q* pNext; /* ptr to next queue (for debugging / monitoring) */
OS_U8* pData;
OS_UINT Size;
OS_UINT MsgCnt;
OS_UINT offFirst;
OS_UINT offLast;
#if OS_DEBUG
char Id;
#endif
};
/**********************************************************************
*
* OS_MEMF
*/
#ifndef OS_MEMF_MAX_ITEMS
#define OS_MEMF_MAX_ITEMS 20
#endif
#define OS_MEMF_SIZEOF_BLOCKCONTROL 0 /* sizeof(int) in future version for debugging */
typedef struct OS_MEMF OS_MEMF;
struct OS_MEMF {
OS_WAIT_OBJ WaitObj;
OS_MEMF* pNext; /* ptr to next memory pool */
void* pPool;
OS_U16 NumBlocks;
OS_U16 BlockSize;
OS_U16 NumFreeBlocks;
OS_U16 MaxUsed;
void* pFree;
#if OS_DEBUG
int aiPurpose[OS_MEMF_MAX_ITEMS];
char Id;
#endif
};
/**********************************************************************
*
* OS_EVENT
*/
typedef struct OS_EVENT OS_EVENT;
struct OS_EVENT {
OS_WAIT_OBJ WaitObj;
OS_U8 Signaled;
#if OS_DEBUG
char Id;
#endif
};
/**********************************************************************
*
* OS_TRACE_ENTRY
*/
typedef struct {
OS_U32 Time;
void *pCurrentTask;
void *p;
OS_U32 v;
OS_U8 iRout;
} OS_TRACE_ENTRY;
/*********************************************************************
*
* Globals
*
**********************************************************************
*/
/*
Handle DEFinition (storage is actually allocted) versus DEClaration
(reference) of RTOS variables depending upon who includes this header file.
*/
#ifdef __OSGLOBAL_C__
#define OS_EXTERN /* Declare variables if included by RTOSKERN.C */
#define OS_EXTERN_INIT(Var, Val) Var=Val
#else
#define OS_EXTERN extern /* Define variables if included by anyone else */
#define OS_EXTERN_INIT(Var, Val) Var
#endif
/***** Mark start of memory pragma area ****************************/
/* Some compilers can not deal with memory attributes and need pragmas */
#if defined(__ghs_zda)
#pragma ghs startzda
#endif
/********************************************************************/
typedef union {
int Dummy; // Make sure a full integer (32 bit on 32 bit CPUs) is used.
struct {
OS_U8 Region;
OS_U8 DI;
} Cnt;
} OS_COUNTERS;
#if OS_COMPILER_STORAGE_MODIFIER_LEFT /* default */
OS_EXTERN OS_SADDR volatile OS_I32 OS_Time;
OS_EXTERN OS_SADDR OS_TIME OS_EXTERN_INIT(OS_TimeDex, 16384);
OS_EXTERN OS_SADDR OS_COUNTERS OS_Counters;
OS_EXTERN OS_SADDR OS_U8 OS_EXTERN_INIT(OS_IntMSInc, 1);
OS_EXTERN OS_SADDR OS_U8 OS_Pending;
OS_EXTERN OS_SADDR volatile OS_U8 OS_Status;
#if OS_RR_SUPPORTED
OS_EXTERN OS_SADDR OS_U8 OS_TimeSlice;
OS_EXTERN OS_SADDR OS_U8 OS_TimeSliceAtStart;
#endif
#if OS_SUPPORT_TICKSTEP
OS_EXTERN OS_SADDR volatile OS_U8 OS_TickStep;
OS_EXTERN OS_SADDR volatile int OS_TickStepTime;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -