📄 txc_os_sem.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.
|-----------------------------------------------------------------------|
| |
| ******** ****** |
| ** ** ** ** |
| ** ** ** * |
| ** ** ** |
| ** ** ** |
| ** ** ** |
| ** ** * *** |
| ** ** ** ** |
| ******** ****** |
| |
|-----------------------------------------------------------------------|
| OS Semaphore Source File |
|-----------------------------------------------------------------------|
| |
| Workfile: txc_os_sem.c |
| |
| Description: this file contains all code for semaphore 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 23-Aug-02 R. Kuhnen Made change to TXC_SemOpen
1.5 24-Oct-02 D. Shea Redefined, PSOS, VXWORKS.
Added TXC_NO_RTOS
1.6 27-Dec-02 R. Kuhnen Added include file, sysLib.h
-----------------------------------------------------------------------*/
/***********************************************************************
** Include Files **
***********************************************************************/
#ifdef TXC_PSOS
#include <sys_conf.h>
#include <psos.h>
#endif
#ifdef TXC_VXWORKS
#include <vxWorks.h>
#include <semLib.h>
#include <objLib.h>
#include <sysLib.h>
#include <time.h>
extern int sysClkRateGet (void);
#endif
#include "txc_generic.h"
#include "txc_platform.h"
#include "txc_error.h"
#include "txc_os_sem.h"
/***********************************************************************
** Imported Variables / Externs **
***********************************************************************/
/***********************************************************************
** Global Variables **
***********************************************************************/
/***********************************************************************
** Static Variables **
***********************************************************************/
/***********************************************************************
** Static Prototypes **
***********************************************************************/
/************************************************************************
* *
* FUNCTION:TXC_SemOpen() *
* *
* DESCRIPTION: This function creates a new, named semaphore. *
* *
* INPUTS: const char * name, TXC_SEM_ID * semIdPtr *
* *
* RETURNS: TXC_OS_RESOURCE_ERR,TXC_NO_ERR *
* *
* CAVEATS: *
* *
* REVISION HISTORY: *
* Date Author Description *
* ------------------------------------------------------------------- *
* 20-Mar-01 R. Ruchandani Initial Revision *
* 25-Apr-02 B. Hawthorne Restoring VxWorks RTOS support. *
* 23-Aug-02 R. Kuhnen Fix a quirk in VxWorks - when creating *
* a downloadable application, would get *
* an unresolved external error for *
* semCreate when downloading to target. *
* Now using SemBCreate which solved *
* problem. Also, semBCreate combines *
* action of semGive so this was removed. *
* *
************************************************************************/
TXC_U16BIT TXC_SemOpen (const char * name, TXC_SEM_ID * semIdPtr)
{
#ifdef TXC_PSOS
unsigned long count, flags, psosError;
/* test if the name is null, if so, not semaphore is required
(assuming the user has non-time sliceable tasks */
if (name == TXC_NULL)
{
* semIdPtr = TXC_NULL;
return TXC_NO_ERR;
}
/* initialize the local variables */
count = 1;
flags = SM_LOCAL|SM_PRIOR;
/* Call the psos function */
psosError = sm_create(name, count, flags, semIdPtr);
/* Check to see if error */
if(psosError)
{
*semIdPtr = TXC_NULL;
return TXC_OS_RESOURCE_ERR;
}
else
return TXC_NO_ERR;
#elif defined (TXC_VXWORKS) /* end of TXC_PSOS */
SEM_ID semError;
/* test if the name is null, if so, no semaphore is required
(assuming the user has non-time sliceable tasks */
if (name == TXC_NULL)
{
* semIdPtr = TXC_NULL;
return TXC_NO_ERR;
}
/* Call the vxworks function */
semError = semBCreate(SEM_Q_FIFO, SEM_FULL);
/* Check to see if error */
if(semError==NULL)
{
*semIdPtr = TXC_NULL;
return TXC_OS_RESOURCE_ERR;
}
else
{
*semIdPtr = (TXC_SEM_ID)semError;
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_SemWait() *
* *
* DESCRIPTION: Calles the rtos semaphore wait function. *
* *
* INPUTS: TXC_SEM_ID semId *
* *
* RETURNS: TXC_OS_RESOURCE_ERR,TXC_NO_ERR *
* *
* CAVEATS: *
* *
* REVISION HISTORY: *
* Date Author Description *
* ------------------------------------------------------------------- *
* 20-Mar-01 R. Ruchandani Initial Revision *
* 25-Apr-02 B. Hawthorne Restoring VxWorks RTOS support. *
* *
************************************************************************/
TXC_U16BIT TXC_SemWait(TXC_SEM_ID semId, TXC_U32BIT milliSecondsWait)
{
TXC_U16BIT txcError;
#ifdef TXC_PSOS
unsigned long flags,timeoutTicks, psosError, msPerTick;
/* if the semaphore ID = 0, semaphores are not used */
if (semId == TXC_NULL)
return TXC_NO_ERR;
/* first, determine the wait ticks and flags, as a function of the
OS ticks, rounding up to the nearest tick */
switch (milliSecondsWait)
{
case TXC_OS_SEM_WAIT_NEVER: /* no wait */
flags = SM_NOWAIT;
timeoutTicks = 0;
break;
case TXC_OS_SEM_WAIT_FOREVER: /* just wait */
flags = SM_WAIT;
timeoutTicks = 0;
break;
default: /* wait a period of time, Determine how many ticks, rounded to the nearest tick */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -