📄 txc_os_task.c
字号:
/*--------------------------------------------------------------------------
******* ****
* ***** ** * * * * * * ***** **** * *
* * * * * ** * * * * * * * * * *
* * * * * * * * **** * * * * * ******
* ***** ****** * * * * * ** * * * * * *
* * * * * * ** * * ** ** * * * * * *
* * * * * * * **** * * * * **** * *
Proprietary and Confidential
This program is made available only to customers and prospective customers
of TranSwitch Corporation under license and may be used only with TranSwitch
semi-conductor products.
Copyright(c) 2004 TranSwitch Inc.
|-----------------------------------------------------------------------|
| |
| ******** ****** |
| ** ** ** ** |
| ** ** ** * |
| ** ** ** |
| ** ** ** |
| ** ** ** |
| ** ** * *** |
| ** ** ** ** |
| ******** ****** |
| |
|-----------------------------------------------------------------------|
| Task Source File |
|-----------------------------------------------------------------------|
| |
| Workfile: txc_os_task.c |
| |
| Description: this file contains all code for task management |
| |
-------------------------------------------------------------------------
Revision History
-------------------------------------------------------------------------
Rev # Date Author Description
----- ------ ------- -----------
1.0 20-Mar-01 R. Ruchandani Initial Revision.
1.1 16-May-01 D. Zhang Added VxWorks block
1.2 19-Apr-02 R. Ruchandani Removed VxWorks block
1.3 25-Apr-02 B. Hawthorne Adding VxWorks block back in, needed
by Aspen Express.
1.4 28-Jun-02 R. Kuhnen Made a change in TXC_GetTaskId
1.5 02-Oct-02 R. Kuhnen 1) Added include errnoLib.h to get rid of compiler warning
2) Changed TXC_SignalTask:
Added check if input taskId is equal to
current task id then exit with TXC_NO_ERR
3) Changed TXC_WaitOnSignal:
a) Added check if parameter milliSecondsWait
= 0 then exit with TXC_NO_ERR
b) Removed sigfillset and added sigemptyset;
also added some sanity checking
c) Changed timeOut.tv_nsec computation
1.6 24-Oct-02 D. Shea Redefined, PSOS, VXWORKS.
Added TXC_NO_RTOS
Removed nested #elif statements
1.7 22-Nov-02 J. Federici Changed call to sigqueue to allow compile in C++.
1.8 10-Dec-02 R. Kuhnen Removed GetTaskId from SignalTask
1.9 27-Dec-02 R. Kuhnen Added include file, sysLib.h
1.10 7-Jan-03 R. Kuhnen Added int to extern declaration of sysClkRateGet
to eliminate C++ compiler warning
-----------------------------------------------------------------------*/
/***********************************************************************
** Include Files **
***********************************************************************/
#ifdef TXC_PSOS
#include <sys_conf.h>
#include <psos.h>
#endif
#ifdef TXC_VXWORKS
#include <vxWorks.h>
#include <stdio.h>
#include <stdlib.h>
#include <semLib.h>
#include <taskLib.h>
#include <sigLib.h>
#include <sysLib.h>
#include <time.h>
#include <errnoLib.h>
extern int sysClkRateGet (void);
#endif
#include "txc_generic.h"
#include "txc_platform.h"
#include "txc_error.h"
#include "txc_os_task.h"
/***********************************************************************
** Imported Variables / Externs **
***********************************************************************/
/***********************************************************************
** Global Variables **
***********************************************************************/
/***********************************************************************
** Static Variables **
***********************************************************************/
/***********************************************************************
** Static Prototypes **
***********************************************************************/
/************************************************************************
* *
* FUNCTION: TXC_SpawnTask *
* *
* DESCRIPTION: Create a task. *
* *
* INPUTS:const char * name, void * startAddr, TXC_TASK_ID * taskIdPtr *
* TXC_U32BIT priority *
* RETURNS: *
* TXC_U16BIT error code *
* TXC_NO_ERR, TXC_OS_RESOURCE_ERR *
* *
* CAVEATS: *
* None at this time. *
* *
* *
* REVISION HISTORY: *
* Date Author Description *
* ------------------------------------------------------------------- *
* 1.0 20-Mar-01 R. Ruchandani Initial Revision *
* 1.1 25-Apr-02 B. Hawthorne Adding VxWorks RTOS support. *
* *
************************************************************************/
TXC_U16BIT TXC_SpawnTask (const char * name, void * startAddr,
TXC_TASK_ID * taskIdPtr, TXC_U32BIT priority)
{
#ifdef TXC_PSOS
unsigned long psosError, flags, mode, targ[4];
/* Create the task and test for failure */
flags = T_LOCAL | T_NOFPU;
psosError = t_create (name,
(unsigned long) priority, /* task priority */
(unsigned long) TXC_TASK_STACK_SIZE, /* supervisor stack size */
(unsigned long) TXC_TASK_STACK_SIZE, /* user stack size */
flags, taskIdPtr);
if (psosError)
return TXC_OS_RESOURCE_ERR;
/* mode will set the task as preemptive, it can be time sliced, and the tasks
ASR is disabled */
mode = T_PREEMPT | T_TSLICE | T_NOASR;
targ[0] = targ[1] = targ[2] = targ[3] = 0;
/* start the task */
psosError = t_start(*taskIdPtr, mode, startAddr, targ);
/* return the error code */
if (psosError)
{
*taskIdPtr = TXC_NULL;
return TXC_OS_RESOURCE_ERR;
}
/* all is well */
return TXC_NO_ERR;
#elif defined (TXC_VXWORKS) /* end of TXC_PSOS */
int taskError, option;
/* Create the task and test for failure */
option = 0; /* enable breakpoints*/
taskError = taskSpawn ((char *)name,
(int) priority, /* task priority */
option, /* enable breakpoints*/
(int) TXC_TASK_STACK_SIZE, /* user stack size */
(FUNCPTR)startAddr, /* function entry */
0,0,0,0,0,0,0,0,0,0
);
if (taskError == ERROR)
{
*taskIdPtr = TXC_NULL;
return TXC_OS_RESOURCE_ERR;
}
else
{
*taskIdPtr = (TXC_TASK_ID)taskError; /* valid task id */
return TXC_NO_ERR;
}
#elif defined (TXC_NO_RTOS) /* end of TXC_VXWORKS */
return TXC_NO_ERR;
#else /* end of TXC_NO_RTOS */
return TXC_OS_RESOURCE_ERR;
#endif /* end of default */
}
/************************************************************************
* *
* FUNCTION: TXC_DeleteTask *
* *
* DESCRIPTION: Delete a task. *
* *
* INPUTS:TXC_TASK_ID taskId *
* *
* RETURNS: *
* TXC_U16BIT error code *
* TXC_NO_ERR, TXC_OS_RESOURCE_ERR *
* *
* CAVEATS: *
* None at this time. *
* *
* *
* REVISION HISTORY: *
* Date Author Description *
* ------------------------------------------------------------------- *
* 1.0 20-Mar-01 R. Ruchandani Initial Revision *
* 1.1 25-Apr-02 B. Hawthorne Adding VxWorks RTOS support. *
* *
************************************************************************/
TXC_U16BIT TXC_DeleteTask(TXC_TASK_ID taskId)
{
#ifdef TXC_PSOS
unsigned long psosError;
/* call psos to delete the task */
psosError = t_delete(taskId);
/* return the error code */
if (psosError)
return TXC_OS_RESOURCE_ERR;
else
return TXC_NO_ERR;
#elif defined (TXC_VXWORKS) /* end of TXC_PSOS */
int taskError;
/* call vxworks to delete the task */
taskError = taskDelete((int)taskId);
/* return the error code */
if (taskError == ERROR)
return TXC_OS_RESOURCE_ERR;
else
return TXC_NO_ERR;
#elif defined (TXC_NO_RTOS) /* end of TXC_VXWORKS */
return TXC_NO_ERR;
#else /* end of TXC_NO_RTOS */
return TXC_OS_RESOURCE_ERR;
#endif /* end of default */
}
/************************************************************************
* *
* FUNCTION: TXC_SleepTask *
* *
* DESCRIPTION: Sleep a task. *
* *
* INPUTS:TXC_U32BIT milliseconds *
* *
* RETURNS: *
* TXC_U16BIT error code *
* TXC_NO_ERR *
* *
* CAVEATS: *
* *
* *
* *
* REVISION HISTORY: *
* Date Author Description *
* ------------------------------------------------------------------- *
* 1.0 20-Mar-01 R. Ruchandani Initial Revision *
* 1.1 25-Apr-02 B. Hawthorne Adding VxWorks RTOS support. *
* *
************************************************************************/
TXC_U16BIT TXC_SleepTask(TXC_U32BIT milliseconds)
{
#ifdef TXC_PSOS
unsigned long ticks, msPerTick;
/* Determine how many ticks, rounded to the nearest tick */
msPerTick = 1000 / KC_TICKS2SEC;
milliseconds += (msPerTick / 2);
ticks = milliseconds / msPerTick;
tm_wkafter (ticks);
return TXC_NO_ERR;
#elif defined (TXC_VXWORKS) /* end of TXC_PSOS */
int ticks, msPerTick, delayError;
/* return immediately if the delay is 0 */
if (milliseconds == 0)
return TXC_NO_ERR;
else
/* Determine how many ticks, rounded up to the nearest tick */
{
msPerTick = 1000 / CLOCKS_PER_SEC;
milliseconds += (msPerTick / 2);
ticks = milliseconds / msPerTick;
delayError = taskDelay (ticks);
if (delayError == ERROR)
return TXC_OS_RESOURCE_ERR;
else
return TXC_NO_ERR;
}
#elif defined (TXC_NO_RTOS) /* end of TXC_VXWORKS */
return TXC_NO_ERR;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -