mng_tsk.c
来自「基于MSP430FG4618MCU的铭正同创LCD驱动程序。」· C语言 代码 · 共 123 行
C
123 行
#include "sys_def.h"
#include "mng_tsk.h"
/*******************************************************************************
// 静态变量定义
*******************************************************************************/
/* taskinfo array */
static const TaskInfo_t aTskInfo[NUM_TASKS] = {
#if NUM_TASKS > 0
{TASK_ID0, TASK_INIT0, TASK_PROC0}
#if NUM_TASKS > 1
{TASK_ID1, TASK_INIT1, TASK_PROC1}
#if NUM_TASKS > 2
{TASK_ID2, TASK_INIT2, TASK_PROC2}
#if NUM_TASKS > 3
{TASK_ID3, TASK_INIT3, TASK_PROC3}
#if NUM_TASKS > 4
{TASK_ID4, TASK_INIT4, TASK_PROC4}
#if NUM_TASKS > 5
{TASK_ID5, TASK_INIT5, TASK_PROC5}
#if NUM_TASKS > 6
{TASK_ID6, TASK_INIT6, TASK_PROC6}
#if NUM_TASKS > 7
{TASK_ID7, TASK_INIT7, TASK_PROC7}
#if NUM_TASKS > 8
{TASK_ID8, TASK_INIT8, TASK_PROC8}
#if NUM_TASKS > 9
{TASK_ID9, TASK_INIT9, TASK_PROC9}
#if NUM_TASKS > 10
{TASK_ID10, TASK_INIT10, TASK_PROC10},
#endif /* NUM_TASKS > 10 */
#endif /* NUM_TASKS > 9 */
#endif /* NUM_TASKS > 8 */
#endif /* NUM_TASKS > 7 */
#endif /* NUM_TASKS > 6 */
#endif /* NUM_TASKS > 5 */
#endif /* NUM_TASKS > 4 */
#endif /* NUM_TASKS > 3 */
#endif /* NUM_TASKS > 2 */
#endif /* NUM_TASKS > 1 */
#endif /* NUM_TASKS > 0 */
};
/*******************************************************************************
// 静态变量定义
*******************************************************************************/
//message data
#define SIZE_MSG_BUFFER 32
static MsgNode_t aMsgBuffer[SIZE_MSG_BUFFER];
static MsgList_t stMsgList;
/*******************************************************************************
// 外部函数定义
*******************************************************************************/
void MngTskInit(void)
{
USHORT int_state = __get_interrupt_state();
__disable_interrupt();
for (int i = 0; i < SIZE_MSG_BUFFER-1; ++i){
aMsgBuffer[i].next = &aMsgBuffer[i + 1];
aMsgBuffer[i + 1].prev = &aMsgBuffer[i];
}
aMsgBuffer[SIZE_MSG_BUFFER-1].next = &stMsgList.stFreeHead;
aMsgBuffer[0].prev = &stMsgList.stFreeHead;
stMsgList.stFreeHead.next = &aMsgBuffer[0];
stMsgList.stFreeHead.prev = &aMsgBuffer[SIZE_MSG_BUFFER-1];
stMsgList.stMsgHead.next = &stMsgList.stMsgHead;
stMsgList.stMsgHead.prev = &stMsgList.stMsgHead;
__set_interrupt_state(int_state);
return;
}
int SendMsg(const pMsg_t pMsg)
{
int iRst = NG;
USHORT int_state = __get_interrupt_state();
__disable_interrupt();
if (NUM_TASKS <= pMsg->ucSrcID
|| NUM_TASKS <= pMsg->ucTgtID){
iRst = ER;
}
else if (stMsgList.stFreeHead.next != &stMsgList.stFreeHead){
pMsgNode_t pMsgNode = NULL;
pMsgNode = stMsgList.stFreeHead.next;
memcpy(pMsgNode, pMsg, sizeof(Msg_t));
stMsgList.stFreeHead.next = pMsgNode->next;
pMsgNode->next->prev = &stMsgList.stFreeHead;
pMsgNode->next = &stMsgList.stMsgHead;
stMsgList.stMsgHead.prev->next = pMsgNode;
pMsgNode->prev = stMsgList.stMsgHead.prev;
stMsgList.stMsgHead.prev = pMsgNode;
iRst = OK;
}
__set_interrupt_state(int_state);
return iRst;
}
void DstrbtMsg(void)
{
USHORT int_state = __get_interrupt_state();
__disable_interrupt();
if (stMsgList.stMsgHead.next != &stMsgList.stMsgHead){
pMsgNode_t pMsgNode = NULL;
pMsgNode = stMsgList.stMsgHead.next;
aTskInfo[pMsgNode->stMsg.ucTgtID].pfTskProc(&pMsgNode->stMsg);
pMsgNode->prev->next = pMsgNode->next;
pMsgNode->next->prev = pMsgNode->prev;
pMsgNode->next = stMsgList.stFreeHead.next;
pMsgNode->prev = &stMsgList.stFreeHead;
stMsgList.stFreeHead.next = pMsgNode;
pMsgNode->next->prev = pMsgNode;
}
__set_interrupt_state(int_state);
return;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?