?? guitask.c
字號:
/*************************************************************************************************************
uC/GUI
嵌入式通用圖形軟件
File : GUITASK.C
Purpose : Saves/Restores task context with supported OSs. It also uses a resource semaphore.
The following externals are used and should typically be defined in GUI_X.c:
U32 GUI_X_GetTaskId();
void GUI_X_Unlock();
void GUI_X_Lock();
************************************************************************************************************/
#include <stddef.h> /* needed for definition of NULL */
#include "GUI_Protected.H"
#include "GUIDEBUG.H"
/*************************************************************************************************************
Configuration defaults
*************************************************************************************************************/
#ifndef GUI_MAXTASK
#define GUI_MAXTASK (4)
#endif
#if GUI_OS
/*************************************************************************************************************
Static data
*************************************************************************************************************/
static struct
{
U32 TaskID;
GUI_CONTEXT Context;
} _Save[GUI_MAXTASK];
static int _CurrentTaskNo = -1;
static int _EntranceCnt = 0;
static U32 _TaskIDLock = 0;
/*************************************************************************************************************
Static functions
*************************************************************************************************************/
static int _GetTaskNo(void)
{
int i;
for (i=0; i< GUI_MAXTASK; i++)
{
U32 TaskId = GUI_X_GetTaskId();
if (_Save[i].TaskID == TaskId)
return i;
if (_Save[i].TaskID == 0)
{
_Save[i].TaskID = TaskId;
return i;
}
}
GUI_DEBUG_ERROROUT("No Context available for task ... (increase GUI_MAXTASK)");
return 0;
}
/*************************************************************************************************************
Public functions
*************************************************************************************************************/
void GUI_Unlock(void)
{
if (--_EntranceCnt == 0)
{
GUI_X_Unlock();
}
/* Test if _EntranceCnt is in reasonable range ... Not required in release builds */
GUI_DEBUG_ERROROUT_IF((_EntranceCnt < 0), "GUITASK.c: GUI_Unlock() _EntranceCnt underflow ");
}
void GUI_Lock(void)
{
if (_EntranceCnt == 0)
{
GUI_X_Lock();
_TaskIDLock = GUI_X_GetTaskId(); /* Save task ID */
} else {
if (_TaskIDLock != GUI_X_GetTaskId())
{
GUI_X_Lock();
_TaskIDLock = GUI_X_GetTaskId(); /* Save task ID */
}
}
if (++_EntranceCnt == 1)
{
int TaskNo = _GetTaskNo();
if (TaskNo != _CurrentTaskNo)
{
/* Save data of current task */
if (_CurrentTaskNo>=0) { /* Make sure _CurrentTaskNo is valid */
_Save[_CurrentTaskNo].Context = GUI_Context;
}
/* Load data of this task */
GUI_Context = _Save[TaskNo].Context;
_CurrentTaskNo = TaskNo;
}
}
/* Test if _EntranceCnt is in reasonable range ... Not required in release builds */
GUI_DEBUG_ERROROUT_IF((_EntranceCnt>12), "GUITASK.c: GUI_Lock() _EntranceCnt overflow ");
}
void GUITASK_Init(void)
{
int i;
_CurrentTaskNo =-1; /* Invalidate */
GUI_X_InitOS();
for (i=0; i<GUI_MAXTASK; i++)
{
_Save[i].Context = GUI_Context;
}
}
#else
/*************************************************************************************************************
Dummy Kernel routines
The routines below are dummies in case configuration tells us not
to use any kernel. In this case the routines below should
not be required, but it can not hurt to have them. The linker
will eliminate them anyhow.
*************************************************************************************************************/
void GUI_Unlock(void) {}
void GUI_Lock(void) {}
void GUITASK_Init(void) {}
void GUITASK_StoreDefaultContext(void) {}
#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -