⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ts_kernelcalls.c

📁 freescale的基于802.15.4的无线通讯例程
💻 C
字号:
/*****************************************************************************
* All the Task scheduler kernel functions are implemented in this file
*   
*
* (c) Copyright 2006, Freescale, Inc. All rights reserved.
*
* Freescale Semiconductor Confidential Proprietary
*
* No part of this document must be reproduced in any form - including copied,
* transcribed, printed or by any electronic means - without specific written
* permission from Freescale Semiconductor Danmark A/S.
*****************************************************************************/
#include "TS_Configuration.h"
#include "TS_Interface.h"
#include "TS_kernelCalls.h"
#include "IrqControlLib.h"

/*****************************************************************************
******************************************************************************
* Private macros
******************************************************************************
*****************************************************************************/

#define noEvents_c 0 

/*****************************************************************************
******************************************************************************
* Private type definitions
******************************************************************************
*****************************************************************************/

typedef struct mTsTcb_tag {       /* The Task Control Block Structure */
  void (*pftaskEntryPoint)(event_t events);  /* Function pointer  */
	event_t taskEvent;             /* Event of the task */
}mTsTcb_t;

/*****************************************************************************
******************************************************************************
* Private memory declarations
******************************************************************************
*****************************************************************************/
mTsTcb_t aTaskArray [ gHighestTaskID_c + 1 ];/*Array of Task Control Blocks */                             

/*****************************************************************************
* Do not change taskID name for the following tasks
*****************************************************************************/
const uint8_t gIdleTask      = gIdleTaskPriority_c;  
const uint8_t gMacTaskID_c   = gMacTaskPriority_c;
const uint8_t gNwkTaskID_c   = gNwkTaskPriority_c;
const uint8_t gApsTaskID_c   = gApsTaskPriority_c;
const uint8_t gAfTaskID_c    = gAfTaskPriority_c;
const uint8_t gZdoTaskID_c   = gZdoTaskPriority_c;
const uint8_t gZdoStateMachineTaskID_c   = gZdoStateMachineTaskPriority_c;
const uint8_t gTimerTask_c   = gTimerTaskPriority_c;
const uint8_t gZappTaskID_c = gZAppTaskIDPriority_c;
const uint8_t gUartTaskID_c = gUartTaskIDPriotity_c;
const uint8_t gZtcTaskID    = gZTCTaskIDPriotity_c ; 

/*****************************************************************************
*****************************************************************************/
/* If require change the following task ID names */






/****************************************************************************/
/*Similar way assign priority for other user tasks here.*/
/****************************************************************************/



/*****************************************************************************
******************************************************************************
* Private prototype
******************************************************************************
*****************************************************************************/

/*****************************************************************************
******************************************************************************
* Public functions
******************************************************************************
*****************************************************************************/


/*****************************************************************************
* Assigns a priority to the task and entry point of the task.
*
* Interface assumptions:
* 
* Return value:
* None
*
* Revison history:
* date   Author Comments
* ------ ------ --------
* 201005  LS     Created
*****************************************************************************/
void TS_Create(
    taskPriority_t taskPri,   /*task priority, values from 0 to 255*/
    void(*pftaskEntryPnt)(event_t events) /*entry point of tasks*/
    ) 
{
  aTaskArray[taskPri].pftaskEntryPoint = pftaskEntryPnt;/*assign entry point*/
}
  
/*****************************************************************************
* Checks for timer expiry of sleeping task and changes the task state to ready.
* Always schedules and executes the high priority task.
* 
* Interface assumptions:
* 
* Return value:
* None
*
* Revison history:
* date   Author Comments
* ------ ------ --------
* 201005  LS     Created
*****************************************************************************/
void TSScheduler(void)
{
  taskID_t tempTask;
  event_t events;
  uint8_t ccr;
  
  for(;;){
    
    TSPollTimerTask(); /*To support poll timer in TS*/
    
    for ( tempTask = gHighestTaskID_c; tempTask>0; --tempTask ) {
      if (aTaskArray[tempTask].taskEvent != noEvents_c)
        break;
    }
    
    IrqControlLib_BackupIrqStatus( ccr );
    IrqControlLib_DisableAllIrqs();
    events = aTaskArray[ tempTask ].taskEvent;
    aTaskArray[ tempTask ].taskEvent = noEvents_c;/*clear all events in PCB*/
    IrqControlLib_RestoreIrqStatus( ccr );

    aTaskArray[ tempTask ].pftaskEntryPoint( events );/*executes the task and 
                                                          giving all events*/
  }
}
/****************************************************************************/

/*****************************************************************************
* void TS_SendEvent
* Sends an event to the task referred by taskId and internally changes 
* the task state to ready state.
* 
* Interface assumptions:
* taskID_t taskId - Task which is receiving the events.
* event_t eventId - event Id for the receiving task.
*
* Return value:
* None
*
* Revison history:
* date   Author Comments
* ------ ------ --------
* 201005  LS     Created
*****************************************************************************/
void TS_SendEvent
  (taskID_t taskId, 
  event_t eventId   
  )
{
  uint8_t ccr;

  IrqControlLib_BackupIrqStatus(ccr);
  IrqControlLib_DisableAllIrqs();
  SetTaskEvent(taskId,eventId);
  IrqControlLib_RestoreIrqStatus(ccr);
}
 
/*****************************************************************************
* void TS_DefaultTaskHandler
* Default entry point for tasks in TCB. 
* Used to initialize the pftaskEntryPoint in TCB.
*
* Return value:
* None
*
* Revison history:
* date   Author Comments
* ------ ------ --------
* 201005  LS     Created
*****************************************************************************/
void TS_DefaultTaskHandler(event_t events){
  events |= TRUE; /*to avoid compiler warning*/
  return;
}

/*****************************************************************************
* void TSInitTCB
* Used to initialize the pftaskEntryPoint in TCB.
*
* Return value:
* None
*
* Revison history:
* date   Author Comments
* ------ ------ --------
* 201005  LS     Created
*****************************************************************************/
void TSInitTCB(void){
    taskID_t tempTask;
    for ( tempTask = 0; tempTask<(gHighestTaskID_c+1); tempTask++ ) {
      aTaskArray[tempTask].pftaskEntryPoint = TS_DefaultTaskHandler;
    }
}

/*****************************************************************************
* void TS_Init(void)
*
* TS_Init initializes the task scheduler and schedules the tasks to execute
* based on priority.
*
* Arguments
* void        
* 
* Return value:
* No return value provided.
*
* Revison history:
* date     Author   Comments
* ------   -------  --------
* 14092005 LS       Created
*****************************************************************************/
void TS_Init(void)
{
  TSInitTCB();
  TS_TaskCreate;
  TSScheduler();
}

/*****************************************************************************
* bool_t TS_PendingEvents(void)
*
* Description:This Function checks for the pending evnts for all the existing tasks.
*
* Arguments
* void        
* 
* Return value:
* TRUE:If any event is pending for any task.
* FALSE:If No eents are pending.
*
* Revison history:
* date     Author       Comments
* ------   -------      --------
* 14092005 Srinivasar   Created
*****************************************************************************/
bool_t TS_PendingEvents(void) 
{
  taskID_t tempTask; 
     
  for ( tempTask = gHighestTaskID_c; tempTask>0; --tempTask ) {
        if (aTaskArray[tempTask].taskEvent != noEvents_c){
        return TRUE;
        }
     }
  return FALSE;  
}
/********************************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -