📄 core.h
字号:
/******************************************************************************
Copyright (c) 2006 by RockOS.
All rights reserved.
This software is supported by the Rock Software Workroom only.
Any bugs please contact the author with e-mail or QQ:
E-mail : baobaoba520@yahoo.com.cn
QQ : 59681888
*******************************************************************************
File name : core.h
Description : header file for RockOS's core.
:
:
Auther : sunxinqiu
History :
2006-3-15 first release.
******************************************************************************/
#ifndef __CORE_H__
#define __CORE_H__
#ifdef __cplusplus
extern "C" {
#endif
/* value for g_OSRunning. */
enum
{
OS_PHASE_UNKNOWN = 0,
OS_PHASE_INIT = 1,
OS_PHASE_SCHEDULING = 2
};
/* options for task. */
enum
{
OPT_TASK_DEFAULT = 0,
OPT_TASK_LOCK = 1, /* this task can't be deprived. */
OPT_TASK_SERVICE = 2 /* this task is a service task (device driver service). */
};
/* task state. */
enum
{
OS_TASK_FREE = 0, /* not create. */
OS_TASK_READY = 1, /* ready to run. */
OS_TASK_RUNNING = 2, /* running. */
OS_TASK_PEND_ON_SEMA = 3, /* pending on a sema. */
OS_TASK_PEND_ON_MSGQ_R = 4, /* pending when receiving msg from its msg queue. */
OS_TASK_PEND_ON_MSGQ_S = 5, /* pending when sending msg to other task. */
OS_TASK_DELAY = 6, /* taskDelay() called. */
OS_TASK_SUSPEND = 7, /* taskSuspend() called. */
OS_TASK_FAULT = 8, /* fatal error occurs when task is running. */
OS_TASK_REMOVING = 9, /* task is to be removed. */
OS_TASK_STATE_MAX = 10
};
/* task fsm events. */
enum
{
/* these events(0~10) below are scheduled by the task FSM. */
T_TRIG_FIRST_RUN = 0, /* task first run after created. */
T_TRIG_DEPRIVED = 1, /* task losts its cpu. */
T_TRIG_RESUME = 2, /* task get cpu again. */
T_TRIG_SEMA_GIVE = 3, /* release a (own) semaphore. */
T_TRIG_TAKE_SEMA_PEND = 4, /* pend when call semTake(). */
T_TRIG_TAKE_SEMA_DONE = 5, /* continue when call semTake() successfully. */
T_TRIG_RECV_MSGQ_PEND = 6, /* pend when call msgQReceive(). */
T_TRIG_RECV_MSGQ_DONE = 7, /* continue when all msgQReceive successfully. */
T_TRIG_SEND_MSGQ_PEND = 8, /* pend when call msgQSend(). */
T_TRIG_SEND_MSGQ_DONE = 9, /* coninue when call msgQSend() successfully. */
T_TRIG_DELAY = 10, /* taskDelay() called. */
T_TRIG_DELAY_TMO = 11, /* taskDelay(), semTake(), msgQReceive() or msgQSend() timeout. */
/* events below are not scheduled by task fsm, but by the OS API. */
T_TRIG_CREATE = 12, /* taskCreate() called. */
T_TRIG_REMOVE = 13, /* taskRemove() called. */
T_TRIG_RESTART = 14, /* taskRestart() called. */
T_TRIG_SUSPEND = 15, /* taskSuspend() called. */
T_TRIG_WAKEUP = 16, /* taskWakeup() called. */
T_TRIG_PRIO_CHANGE_MAN = 17, /* taskPrioChange() called. */
T_TRIG_PRIO_CHANGE_AUTO = 18, /* taskPrioChangeAuto() called. */
T_TRIG_INTERRUPT = 19, /* CPU interrupt occurs. */
T_TRIG_FAULT = 20, /* taskFault() called. */
T_TRIG_MAX
};
enum
{
OS_EVENT_NORMAL = 0,
OS_EVENT_DELAY_TMO = 1
};
typedef void (*TASK_ENTRY)(void *);
typedef struct
{
void * pSP; /* SP's current position, it's defined here only for switching
* task easyly ^_^ */
char name[MAX_NAME_LEN+1]; /* task's name. */
U16 state; /* task's state. */
U8 bFirstRun; /* the first running flag after task created.*/
U8 bDeprived; /* whether this task is deprived or not. */
U8 bWaitTimeout; /* whether this task is pend or delay timeout. */
U16 priority; /* task's default priority. */
U16 runningPriority; /* task's running priority. */
TASK_ENTRY taskEntry; /* task entry function. */
void * pData; /* param for taskEntry. */
HMSGQ hMsgQ; /* task's msg queue. */
HQUEUE hmutexSemaQ; /* task's mutex semaphore queue, as LIFO. */
void * pStack; /* task's stack (low address always). */
U32 stackSize; /* task's stack size. */
HANDLE hPend; /* the system object(msg queue handle or semaphore handle)
* which the task is pending on. */
U16 suspendState; /* state before it is suspended. */
U16 lockDepth; /* nest depth of taskLock(). */
U32 option; /* task options for scheduler. */
U32 delayTicks; /* delay ticks when this task is delay or pend. */
}TCB;
extern HQUEUE g_readyTaskQueue;
extern HTASK g_runningTask;
extern TCB * g_runningTcb;
extern HTASK g_newTask;
extern TCB * g_newTcb;
extern HFSM g_taskFsm;
extern TCB g_sysTcb[];
extern FSM_NAME_TBL g_taskState[];
extern FSM_NAME_TBL g_taskEvent[];
extern FSM_NAME_TBL g_taskAction[];
/* core functions. */
STATUS core_init(void);
U32 OSEnterISR(void);
void OSLeaveISR(void);
void OS_ENTER_CRITICAL(void);
void OS_LEAVE_CRITICAL(void);
void OSStartScheduler(void);
void OSScheduler(void);
void OSTickCore(U32 ticks);
void taskFsmDump (HFSM hFsm, HANDLE hInst, U16 oldState, U16 event, void *action);
char * getTaskActionName (void * p);
void taskSetTrigger(HTASK task, U16 trigger, void * p);
U16 getTaskState(HTASK handle);
U32 getTaskCount(void);
HANDLE getTaskPendObj (HTASK task);
U16 getCoreEvent(HTASK task);
void OntaskDeprived(HANDLE handle, void * p);
void OnSemGive(HANDLE handle, void * p);
void OnSemTakePending(HANDLE handle, void * p);
void OnSemTakeDone(HANDLE handle, void * p);
void OnSemTakeTimeout(HANDLE handle, void * p);
void OnMsgQRecvPending(HANDLE handle, void * p);
void OnMsgQRecvDone(HANDLE handle, void * p);
void OnMsgQRecvTimeout(HANDLE handle, void * p);
void OnMsgQSendPending(HANDLE handle, void * p);
void OnMsgQSendDone(HANDLE handle, void * p);
void OnMsgQSendTimeout(HANDLE handle, void * p);
void OnTaskDelay (HANDLE handle, void * p);
void OnTaskDelayTimeout (HANDLE handle, void * p);
#ifdef __cplusplus
}
#endif
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -