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

📄 stacktaskschedule.h

📁 ucos在NEC平台下的移植
💻 H
字号:
/*
 *******************************************************************************************************
 * CONFIDENTIAL                                                                                        *
 * The use of this file is restricted by SkywiseSystems                    *
 *                                                                                                     *
 * Copyright liquanling 02/09/2006                                                                          *
 *******************************************************************************************************
 * This module contains general types, constants, macros and functions used by many other NWK modules.  
 *******************************************************************************************************
 * Compiler: NEC-CC78K0                                                                                  *
 * Target platform:                                                   *
 *******************************************************************************************************
 * The revision history is located at the bottom of this file                                          *
 *******************************************************************************************************/

#ifndef STACKTASKSCHEDULE_H
#define STACKTASKSCHEDULE_H




/*******************************************************************************************************
 *******************************************************************************************************
 **************************               CONSTANTS AND MACROS                **************************
 *******************************************************************************************************
 *******************************************************************************************************/


//-------------------------------------------------------------------------------------------------------
// The total number of tasks in the pool
#define STACK_TASK_COUNT                  60
// The number of priorities/queues
#define STACK_TASK_PRIORITY_COUNT         4
typedef struct {
    UINT8 firstTask;
    UINT8 lastTask;
    ZBOOL taskInProgress;
}  STACK_TASK_QUEUE;

extern STACK_TASK_QUEUE pStackTaskQueues[STACK_TASK_PRIORITY_COUNT];
///typedef void(*TFPTR)(STACK_TASK_INFO * pTask);
// Tasks/pool
typedef struct {
    void *pTaskFunc;
    WORD taskData;
    BYTE state;
    volatile ZBOOL occupied;
    volatile UINT8 nextTask;
    UINT8 priority;
    UINT8 taskNumber;
	unsigned long    threadFuncId;   //should be removed if don't use threadFunction to replace the task function.
}  STACK_TASK_INFO;
extern STACK_TASK_INFO pStackTasks[STACK_TASK_COUNT];


// Priority names (STACK_TASK_PRIORITY_COUNT = 4) 
#define STACK_TASK_PRI_HIGHEST            3
#define STACK_TASK_PRI_HIGH               2
#define STACK_TASK_PRI_MEDIUM             1
#define STACK_TASK_PRI_LOW                0

// The initial task state (do not change)
#define STACK_TASK_STATE_INITIAL          0

// Queue terminator
#define NO_TASK                         0xFF
//-------------------------------------------------------------------------------------------------------


//-------------------------------------------------------------------------------------------------------
// Task removal flags

// Don't release the task back to the pool when it is removed from the queue
#define STACK_SCH_KEEP_TASK_RESERVED_BM      0x01

// Don't start other tasks of same or lower priority until the removed task has returned
#define STACK_SCH_KEEP_TASK_IN_PROGRESS_BM   0x02
//-------------------------------------------------------------------------------------------------------




/*******************************************************************************************************
 *******************************************************************************************************
 **************************                   MODULE DATA                     **************************
 *******************************************************************************************************
 *******************************************************************************************************/


//-------------------------------------------------------------------------------------------------------


// Task function pointer type (        )
typedef void (*TFPTR)(STACK_TASK_INFO *pTask);


//typedef unsigned _stdcall  UNSTD;
//typedef UNSTD(*THREADFPTR)(UINT8 *a);

//-------------------------------------------------------------------------------------------------------
//  void  stackSchInit(void)
//
//  DESCRIPTION:
//      Initializes the task pool and the task queues.
//-------------------------------------------------------------------------------------------------------
void  stackSchInit(void) ;

//-------------------------------------------------------------------------------------------------------
//  UINT8  stackSchReserveTask(void)
//
//  DESCRIPTION:
//      Reserves a task from the task pool (a task must be reserved before it can be used.
//
//  RETURN VALUE:
//      UINT8
//          The index of the reserved task (to be used with mschAddTask(...))
//-------------------------------------------------------------------------------------------------------
UINT8  stackSchReserveTask(void) ;
//-------------------------------------------------------------------------------------------------------
//  void  stackSchReleaseTask(UINT8 taskNumber)
//
//  DESCRIPTION:
//      Clears the reservation for an unused task.
//
//  ARGUMENTS:
//      UINT8 taskNumber
//          The number of the task (returned by mschReserveTask())
//-------------------------------------------------------------------------------------------------------
void  stackSchReleaseTask(UINT8 taskNumber);

//-------------------------------------------------------------------------------------------------------
//  ZBOOL  stackSchAddTask(UINT8 taskNumber, UINT8 priority, TFPTR pTaskFunc, WORD taskData)
//
//  DESCRIPTION:
//      Configures and adds a reserved to task to the desired task queue.
//
//  ARGUMENTS:
//      UINT8 taskNumber
//          The number of the task (returned by mschReserveTask(...))
//      UINT8 priority
//          STACK_TASK_PRI_HIGHEST, STACK_TASK_PRI_HIGH, STACK_TASK_PRI_MEDIUM or STACK_TASK_PRI_LOW
//      TFPTR pTaskFunc
//          A pointer to the task function (void TaskFunction(MAC_TASK_INFO *pTask))
//      WORD taskData
//          Two bytes of task data (usually a pointer to more data)
//
//  RETURN VALUE:
//      ZBOOL
//          The task was added (the task number was OK)
//-------------------------------------------------------------------------------------------------------
//ZBOOL  stackSchAddTask(UINT8 taskNumber, UINT8 priority, TFPTR pTaskFunc, WORD taskData) ;
ZBOOL  stackSchAddTask(UINT8 taskNumber, UINT8 priority, THREADFPTR pTaskFunc, WORD taskData) ;
//-------------------------------------------------------------------------------------------------------
//  void  stackSchRemoveTask(UINT8 priority, BYTE flags)
//
//  DESCRIPTION:
//      Removes the active task from the specified task queue. This function is usually run from the task
//      function when it's about to finished, or before it makes a call to the higher layer.
//
//  ARGUMENTS:
//      UINT8 priority
//          The priority of the task to be removed
//      BYTE flags
//          STACK_SCH_KEEP_TASK_RESERVED_BM: The task is not released back to the task pool
//          STACK_SCH_KEEP_TASK_IN_PROGRESS_BM: Does not allow other tasks of the same priority to run before
//              the current task has finished (even if it is removed from the queue).
//-------------------------------------------------------------------------------------------------------
void  stackSchRemoveTask(UINT8 priority, ZBOOL flags);
//-------------------------------------------------------------------------------------------------------
//  void stackSchRescheduleTask(MAC_TASK_INFO *pTask, UINT8 state) 
//
//  DESCRIPTION:
//      Removes the currently running task from a queue, and adds it to the back of the same queue, 
//      possibly behind a number of waiting tasks which now will be run first.
//
//  ARGUMENTS:
//      STACK_TASK_INFO *pTask
//          The task to be rescheduled
//      UINT8 state
//          The task state when run after the rescheduling.
//-------------------------------------------------------------------------------------------------------
void stackSchRescheduleTask(STACK_TASK_INFO *pTask, UINT8 state);

// Task execution (called by the timing module)
//-------------------------------------------------------------------------------------------------------
//  void stackSchDoTask(void)
//
//  DESCRIPTION:
//      Used by the timer module to start or resume a task at every backoff slot boundary
//
//  ARGUMENTS:
//      None      
//
//  RETURN VALUE:
//      None
//-------------------------------------------------------------------------------------------------------
void stackSchDoTask(void);
//-------------------------------------------------------------------------------------------------------


#endif




⌨️ 快捷键说明

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