VOS_UINT32 VOS_SmV( VOS_SEM Sm_ID ) { SEM_CONTROL_BLOCK *temp_Ptr; temp_Ptr = (SEM_CONTROL_BLOCK *)Sm_ID; if( temp_Ptr == temp_Ptr->SemId ) { if( temp_Ptr->Flag == VOS_SEM_CTRL_BLK_IDLE) { VOS_SetErrorNo(VOS_ERRNO_SEMA4_V_NOTACTIVE); return(VOS_ERRNO_SEMA4_V_NOTACTIVE); } if ( NU_SUCCESS == NU_Release_Semaphore( &(temp_Ptr->NuSem) ) ) { return(VOS_OK); } else { LogPrint2("# VOS_SmV ID %x Name %s.\r\n", Sm_ID, temp_Ptr->Name); VOS_SetErrorNo(VOS_ERRNO_SEMA4_V_CANOTV); return(VOS_ERRNO_SEMA4_V_CANOTV); } } else { VOS_SetErrorNo(VOS_ERRNO_SEMA4_V_IDERR); return(VOS_ERRNO_SEMA4_V_IDERR); } }
/***************************************************************************** Function : VOS_SmP Description: Lock the resource for synchronization, if the resource is none then block, otherwise the number of the resource -- Input : ulSmID -- the ID of the resource to lock ulTimeOutInMillSec -- the time to wait(0 for ever) Return : VOS_OK on success and errno on failure *****************************************************************************/ VOS_UINT32 VOS_SmP( VOS_SEM Sm_ID, VOS_UINT32 ulTimeOutInMillSec ) { SEM_CONTROL_BLOCK *temp_Ptr; VOS_ULONG ulFlags; temp_Ptr = (SEM_CONTROL_BLOCK *)Sm_ID; if( temp_Ptr != temp_Ptr->SemId ) { VOS_SetErrorNo(VOS_ERRNO_SEMA4_P_IDERR); return (VOS_ERRNO_SEMA4_P_IDERR); } if (VOS_SEM_CTRL_BLK_IDLE == temp_Ptr->Flag) { VOS_SetErrorNo(VOS_ERRNO_SEMA4_P_NOTACTIVE); return(VOS_ERRNO_SEMA4_P_NOTACTIVE); } spin_lock_irqsave(&temp_Ptr->wait.lock, ulFlags); atomic_dec(&temp_Ptr->count); if (atomic_add_negative(0, &temp_Ptr->count)) { spin_unlock_irqrestore(&temp_Ptr->wait.lock, ulFlags); return VOS_SemDown(temp_Ptr, ulTimeOutInMillSec); } spin_unlock_irqrestore(&temp_Ptr->wait.lock, ulFlags); return VOS_OK; }
VOS_UINT32 VOS_SmDelete( VOS_SEM Sm_ID ) { SEM_CONTROL_BLOCK *temp_Ptr; temp_Ptr = (SEM_CONTROL_BLOCK *)Sm_ID; if( temp_Ptr == temp_Ptr->SemId ) { if(temp_Ptr->Flag == VOS_SEM_CTRL_BLK_IDLE) { VOS_SetErrorNo(VOS_ERRNO_SEMA4_CCREATE_OBJTFULL); return(VOS_ERRNO_SEMA4_CCREATE_INVALID_SMID); } if ( NU_SUCCESS == NU_Delete_Semaphore(&(temp_Ptr->NuSem)) ) { return VOS_SemCtrlBlkFree(temp_Ptr); } else { VOS_SetErrorNo(VOS_ERRNO_SEMA4_CCREATE_OSALCREATEERR); return(VOS_ERRNO_SEMA4_CCREATE_OSALCREATEERR); } } else { VOS_SetErrorNo(VOS_ERRNO_SEMA4_CCREATE_INVALID_SMID); return(VOS_ERRNO_SEMA4_CCREATE_INVALID_SMID); } }
/***************************************************************************** Function : MOD_RegFidPidRSP Description: map the PID and FID Input : ulPID -- PID : ulFID -- the belone of PID : priority -- PID's priority Return : VOS_OK on success or errno on failure. Other : *****************************************************************************/ VOS_UINT32 MOD_RegFidPidRSP( VOS_UINT32 ulPID, VOS_UINT32 ulFID, VOS_INT priority) { if ( ulPID <= VOS_PID_DOPRAEND-1 ) { return VOS_OK; } if( ulPID >= VOS_PID_BUTT ) { VOS_SetErrorNo(VOS_ERRNO_REG_FID_PID_INVALID_PID); return(VOS_ERRNO_REG_FID_PID_INVALID_FID); } if( VOS_ID_PID_NULL != vos_PidRecords[ulPID-VOS_PID_DOPRAEND].Pid ) { Print("# VOS_RegisterPIDInfo multiple register.\r\n"); } if( priority > VOS_PRIORITY_P6 ) { VOS_SetErrorNo(VOS_ERRNO_FIDPID_REGMPRI_INPUT2INVALID); return(VOS_ERRNO_FIDPID_REGMPRI_INPUT2INVALID); } vos_PidRecords[ulPID-VOS_PID_DOPRAEND].Pid = (int)ulPID; vos_PidRecords[ulPID-VOS_PID_DOPRAEND].Fid = (int)ulFID; vos_PidRecords[ulPID-VOS_PID_DOPRAEND].priority = priority; return( VOS_OK ); }
VOS_UINT32 VOS_RegisterPIDInfo( VOS_PID ulPID, Init_Fun_Type pfnInitFun, Msg_Fun_Type pfnMsgFun) { if((ulPID >= VOS_PID_BUTT)||(ulPID < VOS_PID_DOPRAEND)) { VOS_SetErrorNo(VOS_ERRNO_FIDPID_REGPIDI_INPUTPIDINVALID); LogPrint1("\r\nVOS_RegisterPIDInfo: Register Wrong PID %d", (VOS_INT)ulPID); return(VOS_ERRNO_FIDPID_REGPIDI_INPUTPIDINVALID); } if(pfnInitFun != VOS_NULL_PTR) { vos_PidRecords[ulPID-VOS_PID_DOPRAEND].InitFunc = pfnInitFun; } if(pfnMsgFun == VOS_NULL_PTR) { VOS_SetErrorNo(VOS_ERRNO_FIDPID_REGPIDI_INPUTFUNCARENULL); return(VOS_ERRNO_FIDPID_REGPIDI_INPUTFUNCARENULL); } else { vos_PidRecords[ulPID-VOS_PID_DOPRAEND].MsgFunction = pfnMsgFun; } return(VOS_OK); }
/***************************************************************************** Function : VOS_SmDelete Description: to delete the exiting semaphore according to the ulSmID Input : ulSmID -- ID of semaphore Return : VOS_OK on success and errno on failure *****************************************************************************/ VOS_UINT32 VOS_SmDelete( VOS_SEM Sm_ID ) { SEM_CONTROL_BLOCK *temp_Ptr; temp_Ptr = (SEM_CONTROL_BLOCK *)Sm_ID; if( temp_Ptr == temp_Ptr->SemId ) { if(temp_Ptr->Flag == VOS_SEM_CTRL_BLK_IDLE) { VOS_SetErrorNo(VOS_ERRNO_SEMA4_CCREATE_OBJTFULL); return(VOS_ERRNO_SEMA4_CCREATE_INVALID_SMID); } if ( 0 != CloseHandle(temp_Ptr->Win32Handle) ) { return VOS_SemCtrlBlkFree(temp_Ptr); } else { VOS_SetErrorNo(VOS_ERRNO_SEMA4_CCREATE_OSALCREATEERR); return(VOS_ERRNO_SEMA4_CCREATE_OSALCREATEERR); } } else { VOS_SetErrorNo(VOS_ERRNO_SEMA4_CCREATE_INVALID_SMID); return(VOS_ERRNO_SEMA4_CCREATE_INVALID_SMID); } }
/************************************************************************** Function : VOS_SmBCreate Description: To create a Binary semaphore; Input : acSmName -- the semaphore name, can be null Sm_Ini -- The count number of the semaphore that create; ulFlags -- FIFO or priority; Output : pulSmID -- the ID of the create semaphore; Return : VOS_OK on success and errno on failure **************************************************************************/ VOS_UINT32 VOS_SmBCreate( VOS_CHAR Sm_Name[4], VOS_UINT32 Sm_Init, VOS_UINT32 Flags, VOS_SEM * Sm_ID ) { int i; SEM_CONTROL_BLOCK *iSemId; HANDLE pulSemId; VOS_INT32 init_state; if ( Sm_Init >= 1 ) { init_state = 1; } else { init_state = 0; } iSemId = VOS_SemCtrlBlkGet(); if( iSemId == VOS_MAX_SEM_ID_NULL) { VOS_SetErrorNo(VOS_ERRNO_SEMA4_CCREATE_OBJTFULL); return(VOS_ERRNO_SEMA4_CCREATE_OBJTFULL); } pulSemId = CreateSemaphore( NULL, init_state,(VOS_INT32) 1, NULL ); if(pulSemId == NULL) { VOS_SemCtrlBlkFree(iSemId); VOS_SetErrorNo(VOS_ERRNO_SEMA4_CCREATE_OBJTFULL); return(VOS_ERRNO_SEMA4_CCREATE_OBJTFULL); } else { *Sm_ID = (VOS_SEM)iSemId; if ( VOS_NULL_PTR != Sm_Name ) { for(i=0; i<VOS_MAX_SEM_NAME_LENGTH/2; i++) { iSemId->Name[i] = Sm_Name[i]; } iSemId->Name[VOS_MAX_SEM_NAME_LENGTH/2] = '\0'; } else { iSemId->Name[0] = '\0'; } iSemId->SemType = VOS_SEM_TYPE_BINARY; iSemId->SemFlags = (int)Flags; iSemId->SemInitCount = (int)Sm_Init; iSemId->Win32Handle = pulSemId; return(VOS_OK); } }
/***************************************************************************** Function : VOS_RegisterPIDInfo Description: record PID info Input : ulPID -- PID : pfnInitFun -- Init FUN of the pid : pfnMsgFun -- process functin of the pid Return : VOS_OK on success or errno on failure. Other : *****************************************************************************/ VOS_UINT32 VOS_RegisterPIDInfo( VOS_PID ulPID, Init_Fun_Type pfnInitFun, Msg_Fun_Type pfnMsgFun ) { if(!VOS_PidCheck(ulPID)) { VOS_SetErrorNo(VOS_ERRNO_FIDPID_REGPIDI_INPUTPIDINVALID); return(VOS_ERRNO_FIDPID_REGPIDI_INPUTPIDINVALID); } if(VOS_NULL_PTR != pfnInitFun) { vos_PidRecords[VOS_PidIdx(ulPID)].InitFunc = pfnInitFun; } if(VOS_NULL_PTR == pfnMsgFun) { VOS_SetErrorNo(VOS_ERRNO_FIDPID_REGPIDI_INPUTFUNCARENULL); return(VOS_ERRNO_FIDPID_REGPIDI_INPUTFUNCARENULL); } vos_PidRecords[VOS_PidIdx(ulPID)].MsgFunction = pfnMsgFun; return(VOS_OK); }
/***************************************************************************** Function : VOS_SmV Description: Release/Unlock the sema4 that has locked a resource Input : ulSmID -- id of semaphore Return : VOS_OK on success and errno on failure *****************************************************************************/ VOS_UINT32 VOS_SmV( VOS_UINT32 Sm_ID ) { SEM_CONTROL_BLOCK *temp_Ptr; VOS_UINT32 ulerror; temp_Ptr = (SEM_CONTROL_BLOCK *)Sm_ID; if( temp_Ptr == temp_Ptr->SemId ) { if( temp_Ptr->Flag == CONTROL_BLOCK_IDLE) { VOS_SetErrorNo(VOS_ERRNO_SEMA4_V_NOTACTIVE); return(VOS_ERRNO_SEMA4_V_NOTACTIVE); } ulerror = (VOS_UINT32)ReleaseSemaphore( temp_Ptr->Win32Handle,\ 1, VOS_NULL_PTR ); if( 0 == ulerror ) { VOS_SetErrorNo(VOS_ERRNO_SEMA4_V_NOTACTIVE); return(VOS_ERRNO_SEMA4_V_NOTACTIVE); } else { return VOS_OK; } } else { VOS_SetErrorNo(VOS_ERRNO_SEMA4_V_IDERR); return(VOS_ERRNO_SEMA4_V_IDERR); } }
/***************************************************************************** Function : VOS_SmCCreate Description: To create a counting semaphore; Input : acSmName -- the semaphore name, can be null ulSmInit -- The count number of the semaphore that create; ulFlags -- FIFO or priority; Output : pulSmID -- the ID of the create semaphore; Return : VOS_OK on success and errno on failure *****************************************************************************/ VOS_UINT32 VOS_SmCCreate( VOS_CHAR acSmName[4], VOS_UINT32 ulSmInit, VOS_UINT32 ulFlags, VOS_UINT32 *pulSmID ) { VOS_UINT32 i; SEM_CONTROL_BLOCK *iSemId; HANDLE pulSemId; iSemId = VOS_SemCtrlBlkGet(); if( iSemId == VOS_NULL_PTR) { VOS_SetErrorNo(VOS_ERRNO_SEMA4_CCREATE_OBJTFULL); return(VOS_ERRNO_SEMA4_CCREATE_OBJTFULL); } if(ulSmInit == VOS_NULL_DWORD) { pulSemId = CreateSemaphore( VOS_NULL_PTR, (VOS_INT32)1, 1, VOS_NULL_PTR ); } else { pulSemId = CreateSemaphore( VOS_NULL_PTR, (VOS_INT32)ulSmInit,\ 0x400000, VOS_NULL_PTR ); } if(pulSemId == VOS_NULL_PTR) { VOS_SemCtrlBlkFree(iSemId); VOS_SetErrorNo(VOS_ERRNO_SEMA4_CCREATE_OBJTFULL); return(VOS_ERRNO_SEMA4_CCREATE_OBJTFULL); } else { *pulSmID = (VOS_UINT32)iSemId; if ( VOS_NULL_PTR != acSmName ) { for(i=0; i<VOS_MAX_SEM_NAME_LENGTH/2; i++) { iSemId->Name[i] = acSmName[i]; } iSemId->Name[VOS_MAX_SEM_NAME_LENGTH/2] = '\0'; } else { iSemId->Name[0] = '\0'; } iSemId->SemFlags = ulFlags; iSemId->SemInitCount = ulSmInit; iSemId->Win32Handle = pulSemId; return(VOS_OK); } }
VOS_UINT32 VOS_SmP( VOS_SEM Sm_ID, VOS_UINT32 ulTimeOutInMillSec ) { SEM_CONTROL_BLOCK *temp_Ptr; VOS_UINT32 TimeOut; VOS_UINT32 ulerror; temp_Ptr = (SEM_CONTROL_BLOCK *)Sm_ID; if( temp_Ptr != temp_Ptr->SemId ) { /*lint -e534*/ VOS_SetErrorNo(VOS_ERRNO_SEMA4_P_IDERR); /*lint +e534*/ return (VOS_ERRNO_SEMA4_P_IDERR); } if (VOS_SEM_CTRL_BLK_IDLE == temp_Ptr->Flag) { /*lint -e534*/ VOS_SetErrorNo(VOS_ERRNO_SEMA4_P_NOTACTIVE); /*lint +e534*/ return(VOS_ERRNO_SEMA4_P_NOTACTIVE); } if ( ulTimeOutInMillSec == 0 ) { TimeOut = INFINITE; } else { TimeOut = ulTimeOutInMillSec; } ulerror = WaitForSingleObject( temp_Ptr->Win32Handle, TimeOut ); if ( WAIT_OBJECT_0 == ulerror ) { return VOS_OK; } if ( WAIT_TIMEOUT == ulerror ) { /*lint -e534*/ VOS_SetErrorNo (VOS_ERRNO_SEMA4_P_TIMEOUT); /*lint +e534*/ return VOS_ERRNO_SEMA4_P_TIMEOUT; } /*lint -e534*/ VOS_SetErrorNo (VOS_ERRNO_SEMA4_P_CANOTP); /*lint +e534*/ return VOS_ERRNO_SEMA4_P_CANOTP; }
VOS_UINT32 VOS_SmP( VOS_SEM Sm_ID, VOS_UINT32 ulTimeOutInMillSec ) { SEM_CONTROL_BLOCK *temp_Ptr; VOS_UINT32 ulTimeOut; VOS_UINT32 ulResult; temp_Ptr = (SEM_CONTROL_BLOCK *)Sm_ID; #if (VOS_YES == VOS_CHECK_PARA) if( temp_Ptr != temp_Ptr->SemId ) { /*lint -e534*/ VOS_SetErrorNo(VOS_ERRNO_SEMA4_P_IDERR); /*lint +e534*/ return (VOS_ERRNO_SEMA4_P_IDERR); } if (VOS_SEM_CTRL_BLK_IDLE == temp_Ptr->Flag) { /*lint -e534*/ VOS_SetErrorNo(VOS_ERRNO_SEMA4_P_NOTACTIVE); /*lint +e534*/ return(VOS_ERRNO_SEMA4_P_NOTACTIVE); } #endif ulTimeOut = (0 == ulTimeOutInMillSec) ? (VOS_UINT32)(-1) : ulTimeOutInMillSec/MILLISECONDS_PER_TICK; ulResult = SRE_SemPend( temp_Ptr->RTOSckSemId, ulTimeOut ); if ( SRE_OK == ulResult ) { return(VOS_OK); } /*lint -e534*/ Print3("# semTake ID %x Name %s errno %x.\r\n", Sm_ID, temp_Ptr->Name, ulResult ); /*lint +e534*/ if ( OS_ERRNO_SEM_TIMEOUT == ulResult ) { /*lint -e534*/ VOS_SetErrorNo (VOS_ERRNO_SEMA4_P_TIMEOUT); /*lint +e534*/ return VOS_ERRNO_SEMA4_P_TIMEOUT; } /*lint -e534*/ VOS_SetErrorNo (VOS_ERRNO_SEMA4_P_CANOTP); /*lint +e534*/ return VOS_ERRNO_SEMA4_P_CANOTP; }
/***************************************************************************** Function : VOS_SmP Description: Lock the resource for synchronization, if the resource is none then block, otherwise the number of the resource -- Input : ulSmID -- the ID of the resource to lock ulTimeOutInMillSec -- the time to wait(0 for ever) Return : VOS_OK on success and errno on failure *****************************************************************************/ VOS_UINT32 VOS_SmP( VOS_SEM Sm_ID, VOS_UINT32 ulTimeOutInMillSec ) { SEM_CONTROL_BLOCK *temp_Ptr; VOS_INT32 timeintick; VOS_INT lRetValue; temp_Ptr = (SEM_CONTROL_BLOCK *)Sm_ID; if ( temp_Ptr != temp_Ptr->SemId ) { VOS_SetErrorNo(VOS_ERRNO_SEMA4_P_IDERR); return (VOS_ERRNO_SEMA4_P_IDERR); } if (VOS_SEM_CTRL_BLK_IDLE == temp_Ptr->Flag) { VOS_SetErrorNo(VOS_ERRNO_SEMA4_P_NOTACTIVE); return(VOS_ERRNO_SEMA4_P_NOTACTIVE); } if (ulTimeOutInMillSec == 0) { down(&(temp_Ptr->sem)); return VOS_OK; } timeintick = ((ulTimeOutInMillSec*HZ)/1000); lRetValue = down_timeout(&(temp_Ptr->sem), timeintick); if ( VOS_OK == lRetValue ) { return VOS_OK; } else if ( -ETIME == lRetValue ) { VOS_SetErrorNo(VOS_ERRNO_SEMA4_P_TIMEOUT); return VOS_ERRNO_SEMA4_P_TIMEOUT; } else { } VOS_SetErrorNo (VOS_ERRNO_SEMA4_P_CANOTP); return VOS_ERRNO_SEMA4_P_CANOTP; }
VOS_UINT32 VOS_SmV( VOS_SEM Sm_ID ) { SEM_CONTROL_BLOCK *temp_Ptr; VOS_UINT32 ulResult; temp_Ptr = (SEM_CONTROL_BLOCK *)Sm_ID; if( temp_Ptr == temp_Ptr->SemId ) { #if (VOS_YES == VOS_CHECK_PARA) if( temp_Ptr->Flag == VOS_SEM_CTRL_BLK_IDLE) { /*lint -e534*/ VOS_SetErrorNo(VOS_ERRNO_SEMA4_V_NOTACTIVE); /*lint +e534*/ return(VOS_ERRNO_SEMA4_V_NOTACTIVE); } #endif ulResult = SRE_SemPost( temp_Ptr->RTOSckSemId ); if ( SRE_OK == ulResult ) { return(VOS_OK); } else { /*lint -e534*/ Print3("# semGive ID %x Name %s errno %x.\r\n", Sm_ID, temp_Ptr->Name, ulResult ); VOS_SetErrorNo(VOS_ERRNO_SEMA4_V_CANOTV); /*lint +e534*/ return(VOS_ERRNO_SEMA4_V_CANOTV); } } else { /*lint -e534*/ VOS_SetErrorNo(VOS_ERRNO_SEMA4_V_IDERR); /*lint +e534*/ return(VOS_ERRNO_SEMA4_V_IDERR); } }
VOS_UINT32 VOS_SmP( VOS_SEM Sm_ID, VOS_UINT32 ulTimeOutInMillSec ) { SEM_CONTROL_BLOCK *temp_Ptr; UNSIGNED iTimeOut; STATUS ReturnCode; temp_Ptr = (SEM_CONTROL_BLOCK *)Sm_ID; if( temp_Ptr != temp_Ptr->SemId ) { VOS_SetErrorNo(VOS_ERRNO_SEMA4_P_IDERR); return (VOS_ERRNO_SEMA4_P_IDERR); } if (VOS_SEM_CTRL_BLK_IDLE == temp_Ptr->Flag) { VOS_SetErrorNo(VOS_ERRNO_SEMA4_P_NOTACTIVE); return(VOS_ERRNO_SEMA4_P_NOTACTIVE); } iTimeOut = (0 == ulTimeOutInMillSec) ? NU_SUSPEND : ulTimeOutInMillSec/MILLISECONDS_PER_TICK; ReturnCode = NU_Obtain_Semaphore(&(temp_Ptr->NuSem), iTimeOut); if ( NU_SUCCESS == ReturnCode ) { return(VOS_OK); } LogPrint3("# VOS_SmP ID %x Name %s error %x.\r\n", Sm_ID, temp_Ptr->Name, ReturnCode ); if ( NU_TIMEOUT == ReturnCode ) { VOS_SetErrorNo (VOS_ERRNO_SEMA4_P_TIMEOUT); return VOS_ERRNO_SEMA4_P_TIMEOUT; } VOS_SetErrorNo (VOS_ERRNO_SEMA4_P_CANOTP); return VOS_ERRNO_SEMA4_P_CANOTP; }
/***************************************************************************** Function : VOS_RegisterMsgTaskPrio Description: Register priority of FID message handling task. Input : ulFID -- Function module Identifier : TaskPrio -- priority of normal message handling task Return : VOS_OK on success or errno on failure *****************************************************************************/ VOS_UINT32 VOS_RegisterMsgTaskPrio( VOS_FID ulFID, enum VOS_PRIORITY_DEFINE TaskPrio ) { if(ulFID >= VOS_FID_BUTT) { VOS_SetErrorNo(VOS_ERRNO_FIDPID_REGMPRI_INPUT1INVALID); return(VOS_ERRNO_FIDPID_REGMPRI_INPUT1INVALID); } if(TaskPrio > VOS_PRIORITY_P6) { VOS_SetErrorNo(VOS_ERRNO_FIDPID_REGMPRI_INPUT2INVALID); return(VOS_ERRNO_FIDPID_REGMPRI_INPUT2INVALID); } vos_FidCtrlBlk[ulFID].Priority = vos_FidTaskRealPriority[TaskPrio]; return(VOS_OK); }
/***************************************************************************** Function : VOS_SmV Description: Release/Unlock the sema4 that has locked a resource Input : ulSmID -- id of semaphore Return : VOS_OK on success and errno on failure *****************************************************************************/ VOS_UINT32 VOS_SmV( VOS_SEM Sm_ID ) { SEM_CONTROL_BLOCK *temp_Ptr; VOS_ULONG ulFlags; temp_Ptr = (SEM_CONTROL_BLOCK *)Sm_ID; if ( temp_Ptr != temp_Ptr->SemId ) { VOS_SetErrorNo(VOS_ERRNO_SEMA4_V_IDERR); return(VOS_ERRNO_SEMA4_V_IDERR); } if( temp_Ptr->Flag == VOS_SEM_CTRL_BLK_IDLE) { VOS_SetErrorNo(VOS_ERRNO_SEMA4_V_NOTACTIVE); return(VOS_ERRNO_SEMA4_V_NOTACTIVE); } spin_lock_irqsave(&temp_Ptr->wait.lock, ulFlags); /* if less than 1, meaning others are waiting */ if (atomic_inc_return(&temp_Ptr->count) < 1) { spin_unlock_irqrestore(&temp_Ptr->wait.lock, ulFlags); wake_up(&temp_Ptr->wait); return VOS_OK; } if ( (VOS_SEM_TYPE_MUTEX == temp_Ptr->SemType) || (VOS_SEM_TYPE_BINARY == temp_Ptr->SemType) ) { atomic_set(&temp_Ptr->count, 1); } spin_unlock_irqrestore(&temp_Ptr->wait.lock, ulFlags); return VOS_OK; }
/***************************************************************************** Function : VOS_RegisterTaskPrio Description: Register real priority of FID message handling task. Input : ulFID -- Function module Identifier : TaskPrio -- priority of normal message handling task Return : VOS_OK on success or errno on failure *****************************************************************************/ VOS_UINT32 VOS_RegisterTaskPrio( VOS_FID ulFID, VOS_UINT32 ulTaskRealPri) { if(ulFID >= VOS_FID_BUTT) { VOS_SetErrorNo(VOS_ERRNO_FIDPID_REGMPRI_INPUT1INVALID); return(VOS_ERRNO_FIDPID_REGMPRI_INPUT1INVALID); } vos_FidCtrlBlk[ulFID].Priority = ulTaskRealPri; return(VOS_OK); }
/***************************************************************************** Function : VOS_SmCCreate Description: To create a counting semaphore; Input : acSmName -- the semaphore name, can be null ulSmInit -- The count number of the semaphore that create; ulFlags -- FIFO or priority; Output : pulSmID -- the ID of the create semaphore; Return : VOS_OK on success and errno on failure *****************************************************************************/ VOS_UINT32 VOS_SmCCreate( VOS_CHAR acSmName[4], VOS_UINT32 ulSmInit, VOS_UINT32 ulFlags, VOS_SEM *pSmID ) { int i; SEM_CONTROL_BLOCK *iSemId; iSemId = VOS_SemCtrlBlkGet(); if (VOS_MAX_SEM_ID_NULL == iSemId) { VOS_SetErrorNo(VOS_ERRNO_SEMA4_CCREATE_OBJTFULL); return(VOS_ERRNO_SEMA4_CCREATE_OBJTFULL); } *pSmID = (VOS_SEM)iSemId; if( 0xFFFFFFFF == ulSmInit ) { atomic_set(&(iSemId->count), 1); iSemId->SemType = VOS_SEM_TYPE_MUTEX; } else { atomic_set(&(iSemId->count), ulSmInit); iSemId->SemType = VOS_SEM_TYPE_COUNT; } iSemId->sleepers = 0; init_waitqueue_head(&(iSemId->wait)); if ( VOS_NULL_PTR != acSmName ) { for(i=0; i<VOS_MAX_SEM_NAME_LENGTH/2; i++) { iSemId->Name[i] = acSmName[i]; } iSemId->Name[VOS_MAX_SEM_NAME_LENGTH/2] = '\0'; } else { iSemId->Name[0] = '\0'; } iSemId->SemFlags = ulFlags; iSemId->SemInitCount = (int)ulSmInit; return(VOS_OK); }
/************************************************************************** Function : VOS_SmBCreate Description: To create a Binary semaphore; Input : acSmName -- the semaphore name, can be null Sm_Ini -- The count number of the semaphore that create; ulFlags -- FIFO or priority; Output : pulSmID -- the ID of the create semaphore; Return : VOS_OK on success and errno on failure **************************************************************************/ VOS_UINT32 VOS_SmBCreate( VOS_CHAR Sm_Name[4], VOS_UINT32 Sm_Init, VOS_UINT32 Flags, VOS_SEM * Sm_ID ) { int i; SEM_CONTROL_BLOCK *iSemId; VOS_INT32 init_state; if ( Sm_Init >= 1 ) { init_state = 1; } else { init_state = 0; } iSemId = VOS_SemCtrlBlkGet(); if( iSemId == VOS_MAX_SEM_ID_NULL) { VOS_SetErrorNo(VOS_ERRNO_SEMA4_CCREATE_OBJTFULL); return(VOS_ERRNO_SEMA4_CCREATE_OBJTFULL); } atomic_set(&(iSemId->count), init_state); iSemId->sleepers = 0; init_waitqueue_head(&(iSemId->wait)); *Sm_ID = (VOS_SEM)iSemId; if ( VOS_NULL_PTR != Sm_Name ) { for(i=0; i<VOS_MAX_SEM_NAME_LENGTH/2; i++) { iSemId->Name[i] = Sm_Name[i]; } iSemId->Name[VOS_MAX_SEM_NAME_LENGTH/2] = '\0'; } else { iSemId->Name[0] = '\0'; } iSemId->SemType = VOS_SEM_TYPE_BINARY; iSemId->SemFlags = Flags; iSemId->SemInitCount = (int)Sm_Init; return(VOS_OK); }
VOS_UINT32 VOS_SmV( VOS_SEM Sm_ID ) { SEM_CONTROL_BLOCK *temp_Ptr; VOS_UINT32 ulerror; temp_Ptr = (SEM_CONTROL_BLOCK *)Sm_ID; if( temp_Ptr == temp_Ptr->SemId ) { if( temp_Ptr->Flag == VOS_SEM_CTRL_BLK_IDLE) { /*lint -e534*/ VOS_SetErrorNo(VOS_ERRNO_SEMA4_V_NOTACTIVE); /*lint +e534*/ return(VOS_ERRNO_SEMA4_V_NOTACTIVE); } ulerror = (VOS_UINT32)ReleaseSemaphore( temp_Ptr->Win32Handle, 1, NULL ); if( 0 == ulerror ) { /*lint -e534*/ VOS_SetErrorNo(VOS_ERRNO_SEMA4_V_NOTACTIVE); /*lint +e534*/ return(VOS_ERRNO_SEMA4_V_NOTACTIVE); } else { return VOS_OK; } } else { /*lint -e534*/ VOS_SetErrorNo(VOS_ERRNO_SEMA4_V_IDERR); /*lint +e534*/ return(VOS_ERRNO_SEMA4_V_IDERR); } }
/***************************************************************************** Function : VOS_SmV Description: Release/Unlock the sema4 that has locked a resource Input : ulSmID -- id of semaphore Return : VOS_OK on success and errno on failure *****************************************************************************/ VOS_UINT32 VOS_SmV( VOS_SEM Sm_ID ) { SEM_CONTROL_BLOCK *temp_Ptr; temp_Ptr = (SEM_CONTROL_BLOCK *)Sm_ID; if ( temp_Ptr != temp_Ptr->SemId ) { VOS_SetErrorNo(VOS_ERRNO_SEMA4_V_IDERR); return(VOS_ERRNO_SEMA4_V_IDERR); } if( temp_Ptr->Flag == VOS_SEM_CTRL_BLK_IDLE) { VOS_SetErrorNo(VOS_ERRNO_SEMA4_V_NOTACTIVE); return(VOS_ERRNO_SEMA4_V_NOTACTIVE); } up( &(temp_Ptr->sem ) ); return VOS_OK; }
VOS_UINT32 VOS_SmDelete( VOS_SEM Sm_ID ) { SEM_CONTROL_BLOCK *temp_Ptr; temp_Ptr = (SEM_CONTROL_BLOCK *)Sm_ID; if( temp_Ptr == temp_Ptr->SemId ) { if(temp_Ptr->Flag == VOS_SEM_CTRL_BLK_IDLE) { /*lint -e534*/ VOS_SetErrorNo(VOS_ERRNO_SEMA4_CCREATE_OBJTFULL); /*lint +e534*/ return(VOS_ERRNO_SEMA4_CCREATE_INVALID_SMID); } if ( SRE_OK == SRE_SemDelete(temp_Ptr->RTOSckSemId) ) { return VOS_SemCtrlBlkFree(temp_Ptr); } else { /*lint -e534*/ VOS_SetErrorNo(VOS_ERRNO_SEMA4_CCREATE_OSALCREATEERR); /*lint +e534*/ return(VOS_ERRNO_SEMA4_CCREATE_OSALCREATEERR); } } else { /*lint -e534*/ VOS_SetErrorNo(VOS_ERRNO_SEMA4_CCREATE_INVALID_SMID); /*lint +e534*/ return(VOS_ERRNO_SEMA4_CCREATE_INVALID_SMID); } }
/***************************************************************************** Function : VOS_SmDelete Description: to delete the exiting semaphore according to the ulSmID Input : ulSmID -- ID of semaphore Return : VOS_OK on success and errno on failure *****************************************************************************/ VOS_UINT32 VOS_SmDelete( VOS_SEM Sm_ID ) { SEM_CONTROL_BLOCK *temp_Ptr; temp_Ptr = (SEM_CONTROL_BLOCK *)Sm_ID; if( temp_Ptr == temp_Ptr->SemId ) { vos_printf("\r\nVOS_SmDelete: Delete the Sem %x", Sm_ID); if(temp_Ptr->Flag == VOS_SEM_CTRL_BLK_IDLE) { VOS_SetErrorNo(VOS_ERRNO_SEMA4_CCREATE_OBJTFULL); return(VOS_ERRNO_SEMA4_CCREATE_INVALID_SMID); } return VOS_SemCtrlBlkFree(temp_Ptr); } else { VOS_SetErrorNo(VOS_ERRNO_SEMA4_CCREATE_INVALID_SMID); return(VOS_ERRNO_SEMA4_CCREATE_INVALID_SMID); } }
/***************************************************************************** Function : MOD_RegFidPidRSP Description: map the PID and FID Input : ulPID -- PID : ulFID -- the belone of PID : priority -- PID's priority Return : VOS_OK on success or errno on failure. Other : *****************************************************************************/ VOS_UINT32 MOD_RegFidPidRSP( VOS_UINT32 ulPID, VOS_UINT32 ulFID) { if(!VOS_PidCheck(ulPID)) { VOS_SetErrorNo(VOS_ERRNO_REG_FID_PID_INVALID_PID); return(VOS_ERRNO_REG_FID_PID_INVALID_FID); } if( VOS_NULL_DWORD != vos_PidRecords[VOS_PidIdx(ulPID)].Pid ) { Print("# VOS_RegisterPIDInfo multiple register.\r\n"); } vos_PidRecords[VOS_PidIdx(ulPID)].Pid = ulPID; vos_PidRecords[VOS_PidIdx(ulPID)].Fid = ulFID; return( VOS_OK ); }
/***************************************************************************** Function : VOS_SemCtrlBlkGet Description: allocate a control block Input : void Return : address Other : *****************************************************************************/ SEM_CONTROL_BLOCK *VOS_SemCtrlBlkGet(VOS_VOID) { VOS_UINT32 i; VOS_ULONG ulLockLevel; /*intLockLevel = VOS_SplIMP();*/ VOS_SpinLockIntLock(&g_stVosSemSpinLock, ulLockLevel); for(i=0; i<vos_SemCtrlBlkNumber; i++) { if(vos_SemCtrlBlk[i].Flag == VOS_SEM_CTRL_BLK_IDLE) { vos_SemCtrlBlk[i].Flag = VOS_SEM_CTRL_BLK_BUSY; break; } } /*VOS_Splx(intLockLevel);*/ VOS_SpinUnlockIntUnlock(&g_stVosSemSpinLock, ulLockLevel); if( i < vos_SemCtrlBlkNumber) { /* record the max usage of SEM */ if ( i > vos_SemMaxSemId ) { vos_SemMaxSemId = i; } return vos_SemCtrlBlk+i; } else { /*lint -e534*/ LogPrint("# VOS_GetSemCtrlBlk no Idle.\r\n"); /*lint +e534*/ VOS_SetErrorNo(VOS_ERRNO_SEMA4_FULL); return(VOS_MAX_SEM_ID_NULL); } }
/***************************************************************************** Function : VOS_SemCtrlBlkGet Description: allocate a control block Input : VOS_VOID Return : address Other : *****************************************************************************/ SEM_CONTROL_BLOCK *VOS_SemCtrlBlkGet(VOS_VOID) { VOS_UINT32 i; VOS_CPU_SR CpuLockLevel; CpuLockLevel = VOS_SplIMP(); for(i=0; i<vos_SemCtrlBlkNumber; i++) { if(vos_SemCtrlBlk[i].Flag == CONTROL_BLOCK_IDLE) { vos_SemCtrlBlk[i].Flag = CONTROL_BLOCK_BUSY; break; } } VOS_Splx(CpuLockLevel); if( i < vos_SemCtrlBlkNumber) { /* record the max usage of SEM */ if ( i > vos_SemMaxSemId ) { vos_SemMaxSemId = i; } return vos_SemCtrlBlk+i; } else { LogPrint("# VOS_GetSemCtrlBlk no Idle.\r\n"); VOS_SetErrorNo(VOS_ERRNO_SEMA4_FULL); return(VOS_NULL_PTR); } }
/***************************************************************************** Function : VOS_CreateTask Description: create task with default task mode: VOS_T_PREEMPT | VOS_T_NO_TSLICE | VOS_T_SUPV Input : puchName -- name identify task pfnFunc -- task entry function ulPriority -- task priority ulStackSize -- task stack size aulArgs[VOS_TARG_NUM] -- arguments for task Output : pulTaskID -- task id allocated by dopra Return : result of VOS_CreateTaskEx *****************************************************************************/ VOS_UINT32 VOS_CreateTask( VOS_CHAR * puchName, VOS_UINT32 * pulTaskID, VOS_TASK_ENTRY_TYPE pfnFunc, VOS_UINT32 ulPriority, VOS_UINT32 ulStackSize, VOS_UINT32 aulArgs[VOS_TARG_NUM] ) { int i; VOS_UINT32 iTid; pid_t ThreadID; VOS_CHAR default_name[8] = {0}; VOS_UCHAR value; struct task_struct *tsk; struct sched_param param; iTid = VOS_TaskCtrlBlkGet(); if( iTid == (VOS_UINT32)VOS_TASK_CTRL_BLK_NULL ) { VOS_TaskPrintCtrlBlkInfo(); DRV_SYSTEM_ERROR(OSA_ALLOC_TASK_CONTROL_ERROR, (VOS_INT)vos_TaskCtrlBlkNumber, (VOS_INT)pfnFunc, VOS_NULL_PTR, 0); VOS_SetErrorNo(VOS_ERRNO_TASK_CREATE_NOFREETCB); return( VOS_ERRNO_TASK_CREATE_NOFREETCB ); } /* caller not use name asign a default name */ if ( VOS_NULL_PTR == puchName ) { default_name[0]= 't'; default_name[1]= 'i'; default_name[2]= 'd'; default_name[3] = (VOS_CHAR)(48 + iTid/100); value = (VOS_UCHAR)(iTid%100); default_name[4] = (VOS_CHAR)(48 + value/10); default_name[5] = (VOS_CHAR)(48 + value%10); default_name[6]= '\0'; } *pulTaskID = iTid; if ( VOS_NULL_PTR != puchName ) { for(i=0; i<VOS_MAX_LENGTH_TASK_NAME; i++) { vos_TaskCtrlBlk[iTid].Name[i]= puchName[i]; } vos_TaskCtrlBlk[iTid].Name[i-1] = '\0'; } else { vos_TaskCtrlBlk[iTid].Name[0] = default_name[0]; vos_TaskCtrlBlk[iTid].Name[1] = default_name[1]; vos_TaskCtrlBlk[iTid].Name[2] = default_name[2]; vos_TaskCtrlBlk[iTid].Name[3] = default_name[3]; vos_TaskCtrlBlk[iTid].Name[4] = default_name[4]; vos_TaskCtrlBlk[iTid].Name[5] = default_name[5]; vos_TaskCtrlBlk[iTid].Name[6] = default_name[6]; } vos_TaskCtrlBlk[iTid].Function = pfnFunc; vos_TaskCtrlBlk[iTid].Priority = ulPriority; vos_TaskCtrlBlk[iTid].StackSize = ulStackSize; for ( i=0; i<VOS_TARG_NUM; i++ ) { vos_TaskCtrlBlk[iTid].Args[i] = aulArgs[i]; } ThreadID = kernel_thread( (LINUX_START_ROUTINE)VOS_LinuxTaskEntry, ( VOS_VOID * )&(vos_TaskCtrlBlk[iTid]), CLONE_KERNEL); if (ThreadID < VOS_NULL) { VOS_TaskPrintCtrlBlkInfo(); DRV_SYSTEM_ERROR(OSA_CREATE_TASK_ERROR, (VOS_INT)ThreadID, (VOS_INT)iTid, VOS_NULL_PTR, 0); VOS_TaskCtrlBlkFree(iTid); VOS_SetErrorNo(VOS_ERRNO_TASK_CREATE_OSALCREATEFAIL); return( VOS_ERRNO_TASK_CREATE_OSALCREATEFAIL ); } vos_TaskCtrlBlk[iTid].ulLinuxThreadId = ThreadID; tsk = pid_task(find_vpid(ThreadID), PIDTYPE_PID); if ( VOS_NULL_PTR == tsk ) { VOS_TaskPrintCtrlBlkInfo(); DRV_SYSTEM_ERROR(OSA_FIND_TASK_ERROR, (VOS_INT)ThreadID, (VOS_INT)iTid, VOS_NULL_PTR, 0); return VOS_ERR; } if ( tsk->pid != ThreadID ) { vos_printf("find task to set pri fail.\r\n"); VOS_TaskPrintCtrlBlkInfo(); DRV_SYSTEM_ERROR(OSA_FIND_TASK_PARA_ERROR, (VOS_INT)ThreadID, (VOS_INT)iTid, (VOS_CHAR *)tsk, sizeof(struct task_struct)); return VOS_ERR; } param.sched_priority = ulPriority; if (VOS_NULL != sched_setscheduler(tsk, SCHED_FIFO, ¶m)) { vos_printf("\r\nVOS_CreateTask: Creat Task %s ID %d sched_setscheduler Error", puchName, iTid); VOS_TaskPrintCtrlBlkInfo(); DRV_SYSTEM_ERROR(OSA_SET_TASK_PRI_ERROR, (VOS_INT)ulPriority, (VOS_INT)iTid, (VOS_CHAR *)tsk, sizeof(struct task_struct)); return VOS_ERR; } return VOS_OK; }
/***************************************************************************** Function : VOS_SmCCreate Description: To create a counting semaphore; Input : acSmName -- the semaphore name, can be null ulSmInit -- The count number of the semaphore that create; ulFlags -- FIFO or priority; Output : pulSmID -- the ID of the create semaphore; Return : VOS_OK on success and errno on failure *****************************************************************************/ VOS_UINT32 VOS_SmCCreate( VOS_CHAR acSmName[4], VOS_UINT32 ulSmInit, VOS_UINT32 ulFlags, VOS_SEM *pulSmID ) { int i; SEM_CONTROL_BLOCK *iSemId; OPTION SemOption; VOS_UINT32 ulTempInitVal; iSemId = VOS_SemCtrlBlkGet(); if( iSemId == VOS_MAX_SEM_ID_NULL) { VOS_SetErrorNo(VOS_ERRNO_SEMA4_CCREATE_OBJTFULL); return(VOS_ERRNO_SEMA4_CCREATE_OBJTFULL); } if( (ulFlags & VOS_SEMA4_PRIOR) ) { SemOption = NU_PRIORITY; } else { SemOption = NU_FIFO; } if( 0xFFFFFFFF == ulSmInit ) { ulTempInitVal = 1; } else { ulTempInitVal = ulSmInit; } if ( NU_SUCCESS != NU_Create_Semaphore(&(iSemId->NuSem), acSmName, ulTempInitVal, SemOption)) { VOS_SemCtrlBlkFree(iSemId); VOS_SetErrorNo(VOS_ERRNO_SEMA4_CCREATE_OBJTFULL); return(VOS_ERRNO_SEMA4_CCREATE_OBJTFULL); } else { *pulSmID = (VOS_SEM)iSemId; if ( VOS_NULL_PTR != acSmName ) { for(i=0; i<VOS_MAX_SEM_NAME_LENGTH/2; i++) { iSemId->Name[i] = acSmName[i]; } iSemId->Name[VOS_MAX_SEM_NAME_LENGTH/2] = '\0'; } else { iSemId->Name[0] = '\0'; } if( 0xFFFFFFFF == ulSmInit ) { iSemId->SemType = VOS_SEM_TYPE_MUTEX; } else { iSemId->SemType = VOS_SEM_TYPE_COUNT; } iSemId->SemFlags = (int)ulFlags; iSemId->SemInitCount = (int)ulSmInit; return(VOS_OK); } }
/***************************************************************************** Function : VOS_SmCCreate Description: To create a counting semaphore; Input : acSmName -- the semaphore name, can be null ulSmInit -- The count number of the semaphore that create; ulFlags -- FIFO or priority; Output : pulSmID -- the ID of the create semaphore; Return : VOS_OK on success and errno on failure *****************************************************************************/ VOS_UINT32 VOS_SmCCreate( VOS_CHAR acSmName[4], VOS_UINT32 ulSmInit, VOS_UINT32 ulFlags, VOS_SEM *pulSmID ) { int i; SEM_CONTROL_BLOCK *iSemId; HANDLE pulSemId; iSemId = VOS_SemCtrlBlkGet(); if( iSemId == VOS_MAX_SEM_ID_NULL) { /*lint -e534*/ VOS_SetErrorNo(VOS_ERRNO_SEMA4_CCREATE_OBJTFULL); /*lint +e534*/ return(VOS_ERRNO_SEMA4_CCREATE_OBJTFULL); } if(ulSmInit == 0xFFFFFFFF) { pulSemId = CreateSemaphore( NULL, (VOS_INT32)1, 1, NULL ); } else { pulSemId = CreateSemaphore( NULL, (VOS_INT32)ulSmInit, 0x400000, NULL ); } if(pulSemId == NULL) { VOS_SemCtrlBlkFree(iSemId); /*lint -e534*/ VOS_SetErrorNo(VOS_ERRNO_SEMA4_CCREATE_OBJTFULL); /*lint +e534*/ return(VOS_ERRNO_SEMA4_CCREATE_OBJTFULL); } else { *pulSmID = (VOS_SEM)iSemId; if ( VOS_NULL_PTR != acSmName ) { for(i=0; i<VOS_MAX_SEM_NAME_LENGTH/2; i++) { iSemId->Name[i] = acSmName[i]; } iSemId->Name[VOS_MAX_SEM_NAME_LENGTH/2] = '\0'; } else { iSemId->Name[0] = '\0'; } if(ulSmInit == 0xFFFFFFFF) { iSemId->SemType = VOS_SEM_TYPE_MUTEX; } else { iSemId->SemType = VOS_SEM_TYPE_COUNT; } iSemId->SemFlags = (int)ulFlags; iSemId->SemInitCount = (int)ulSmInit; iSemId->Win32Handle = pulSemId; return(VOS_OK); } }