当前位置: 首页>>代码示例>>C++>>正文


C++ xSemaphoreGiveRecursive函数代码示例

本文整理汇总了C++中xSemaphoreGiveRecursive函数的典型用法代码示例。如果您正苦于以下问题:C++ xSemaphoreGiveRecursive函数的具体用法?C++ xSemaphoreGiveRecursive怎么用?C++ xSemaphoreGiveRecursive使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了xSemaphoreGiveRecursive函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: UAVObjGetInstanceDataField

/**
 * Get the data of a specific object instance
 * \param[in] obj The object handle
 * \param[in] instId The object instance ID
 * \param[out] dataOut The object's data structure
 * \return 0 if success or -1 if failure
 */
int32_t UAVObjGetInstanceDataField(UAVObjHandle obj, uint16_t instId, void* dataOut, uint32_t offset, uint32_t size)
{
	ObjectList* objEntry;
	ObjectInstList* instEntry;

	// Lock
	xSemaphoreTakeRecursive(mutex, portMAX_DELAY);

	// Cast to object info
	objEntry = (ObjectList*)obj;

	// Get instance information
	instEntry = getInstance(objEntry, instId);
	if ( instEntry == NULL )
	{
		// Error, unlock and return
		xSemaphoreGiveRecursive(mutex);
		return -1;
	}

	// return if we request too much of what we can give
	if ( (size + offset) > objEntry->numBytes) 
	{
		// Error, unlock and return
		xSemaphoreGiveRecursive(mutex);
		return -1;
	}
	
	// Set data
	memcpy(dataOut, instEntry->data + offset, size);

	// Unlock
	xSemaphoreGiveRecursive(mutex);
	return 0;
}
开发者ID:LeeSaferite,项目名称:OpenPilot,代码行数:42,代码来源:uavobjectmanager.c

示例2: UAVObjPack

/**
 * Pack an object to a byte array
 * \param[in] obj The object handle
 * \param[in] instId The instance ID
 * \param[out] dataOut The byte array
 * \return 0 if success or -1 if failure
 */
int32_t UAVObjPack(UAVObjHandle obj, uint16_t instId, uint8_t * dataOut)
{
	  ObjectList *objEntry;
	  ObjectInstList *instEntry;

	  // Lock
	  xSemaphoreTakeRecursive(mutex, portMAX_DELAY);

	  // Cast handle to object
	  objEntry = (ObjectList *) obj;

	  // Get the instance
	  instEntry = getInstance(objEntry, instId);
	  if (instEntry == NULL) {
		    // Error, unlock and return
		    xSemaphoreGiveRecursive(mutex);
		    return -1;
	  }
	  // Pack data
	  memcpy(dataOut, instEntry->data, objEntry->numBytes);

	  // Unlock
	  xSemaphoreGiveRecursive(mutex);
	  return 0;
}
开发者ID:LeeSaferite,项目名称:OpenPilot,代码行数:32,代码来源:uavobjectmanager.c

示例3: UAVObjUnpack

/**
 * Unpack an object from a byte array
 * \param[in] obj The object handle
 * \param[in] instId The instance ID
 * \param[in] dataIn The byte array
 * \return 0 if success or -1 if failure
 */
int32_t UAVObjUnpack(UAVObjHandle obj, uint16_t instId,
		     const uint8_t * dataIn)
{
	  ObjectList *objEntry;
	  ObjectInstList *instEntry;

	  // Lock
	  xSemaphoreTakeRecursive(mutex, portMAX_DELAY);

	  // Cast handle to object
	  objEntry = (ObjectList *) obj;

	  // Get the instance
	  instEntry = getInstance(objEntry, instId);

	  // If the instance does not exist create it and any other instances before it
	  if (instEntry == NULL) {
		    instEntry = createInstance(objEntry, instId);
		    if (instEntry == NULL) {
			      // Error, unlock and return
			      xSemaphoreGiveRecursive(mutex);
			      return -1;
		    }
	  }
	  // Set the data
	  memcpy(instEntry->data, dataIn, objEntry->numBytes);

	  // Fire event
	  sendEvent(objEntry, instId, EV_UNPACKED);

	  // Unlock
	  xSemaphoreGiveRecursive(mutex);
	  return 0;
}
开发者ID:LeeSaferite,项目名称:OpenPilot,代码行数:41,代码来源:uavobjectmanager.c

示例4: hasSeverity

/**
 * Check if there are any alarms with the given or higher severity
 * @return 0 if no alarms are found, 1 if at least one alarm is found
 */
static int32_t hasSeverity(SystemAlarmsAlarmOptions severity)
{
	SystemAlarmsData alarms;
	uint32_t n;

	// Lock
    xSemaphoreTakeRecursive(lock, portMAX_DELAY);

    // Read alarms
    SystemAlarmsGet(&alarms);

    // Go through alarms and check if any are of the given severity or higher
    for (n = 0; n < SYSTEMALARMS_ALARM_NUMELEM; ++n)
    {
    	if ( alarms.Alarm[n] >= severity)
    	{
    		xSemaphoreGiveRecursive(lock);
    		return 1;
    	}
    }

    // If this point is reached then no alarms found
    xSemaphoreGiveRecursive(lock);
    return 0;
}
开发者ID:1heinz,项目名称:TauLabs,代码行数:29,代码来源:alarms.c

示例5: UAVObjGetInstanceData

/**
 * Get the data of a specific object instance
 * \param[in] obj The object handle
 * \param[in] instId The object instance ID
 * \param[out] dataOut The object's data structure
 * \return 0 if success or -1 if failure
 */
int32_t UAVObjGetInstanceData(UAVObjHandle obj, uint16_t instId,
			      void *dataOut)
{
	  ObjectList *objEntry;
	  ObjectInstList *instEntry;

	  // Lock
	  xSemaphoreTakeRecursive(mutex, portMAX_DELAY);

	  // Cast to object info
	  objEntry = (ObjectList *) obj;

	  // Get instance information
	  instEntry = getInstance(objEntry, instId);
	  if (instEntry == NULL) {
		    // Error, unlock and return
		    xSemaphoreGiveRecursive(mutex);
		    return -1;
	  }
	  // Set data
	  memcpy(dataOut, instEntry->data, objEntry->numBytes);

	  // Unlock
	  xSemaphoreGiveRecursive(mutex);
	  return 0;
}
开发者ID:LeeSaferite,项目名称:OpenPilot,代码行数:33,代码来源:uavobjectmanager.c

示例6: UAVObjSave

/**
 * Save the data of the specified object to the file system (SD card).
 * If the object contains multiple instances, all of them will be saved.
 * A new file with the name of the object will be created.
 * The object data can be restored using the UAVObjLoad function.
 * @param[in] obj The object handle.
 * @param[in] instId The instance ID
 * @param[in] file File to append to
 * @return 0 if success or -1 if failure
 */
int32_t UAVObjSave(UAVObjHandle obj, uint16_t instId)
{
#if defined(PIOS_INCLUDE_FLASH_SECTOR_SETTINGS)
	  ObjectList *objEntry = (ObjectList *) obj;

	  if (objEntry == NULL)
		    return -1;

	  ObjectInstList *instEntry = getInstance(objEntry, instId);

	  if (instEntry == NULL)
		    return -1;

	  if (instEntry->data == NULL)
		    return -1;

	  if (PIOS_FLASHFS_ObjSave(obj, instId, instEntry->data) != 0)
		    return -1;
#endif
#if defined(PIOS_INCLUDE_SDCARD)
	  FILEINFO file;
	  ObjectList *objEntry;
	  uint8_t filename[14];

	  // Check for file system availability
	  if (PIOS_SDCARD_IsMounted() == 0) {
		    return -1;
	  }
	  // Lock
	  xSemaphoreTakeRecursive(mutex, portMAX_DELAY);

	  // Cast to object
	  objEntry = (ObjectList *) obj;

	  // Get filename
	  objectFilename(objEntry, filename);

	  // Open file
	  if (PIOS_FOPEN_WRITE(filename, file)) {
		    xSemaphoreGiveRecursive(mutex);
		    return -1;
	  }
	  // Append object
	  if (UAVObjSaveToFile(obj, instId, &file) == -1) {
		    PIOS_FCLOSE(file);
		    xSemaphoreGiveRecursive(mutex);
		    return -1;
	  }
	  // Done, close file and unlock
	  PIOS_FCLOSE(file);
	  xSemaphoreGiveRecursive(mutex);
#endif /* PIOS_INCLUDE_SDCARD */
	  return 0;
}
开发者ID:LeeSaferite,项目名称:OpenPilot,代码行数:64,代码来源:uavobjectmanager.c

示例7: prvExerciseSemaphoreAPI

static void prvExerciseSemaphoreAPI( void )
{
SemaphoreHandle_t xSemaphore;
const UBaseType_t uxMaxCount = 5, uxInitialCount = 0;

	/* Most of the semaphore API is common to the queue API and is already being
	used.  This function uses a few semaphore functions that are unique to the
	RTOS objects, rather than generic and used by queues also.

	First create and use a counting semaphore. */
	xSemaphore = xSemaphoreCreateCounting( uxMaxCount, uxInitialCount );
	configASSERT( xSemaphore );

	/* Give the semaphore a couple of times and ensure the count is returned
	correctly. */
	xSemaphoreGive( xSemaphore );
	xSemaphoreGive( xSemaphore );
	configASSERT( uxSemaphoreGetCount( xSemaphore ) == 2 );
	vSemaphoreDelete( xSemaphore );

	/* Create a recursive mutex, and ensure the mutex holder and count are
	returned returned correctly. */
	xSemaphore = xSemaphoreCreateRecursiveMutex();
	configASSERT( uxSemaphoreGetCount( xSemaphore ) == 1 );
	configASSERT( xSemaphore );
	xSemaphoreTakeRecursive( xSemaphore, mainDONT_BLOCK );
	xSemaphoreTakeRecursive( xSemaphore, mainDONT_BLOCK );
	configASSERT( xSemaphoreGetMutexHolder( xSemaphore ) == xTaskGetCurrentTaskHandle() );
	configASSERT( xSemaphoreGetMutexHolder( xSemaphore ) == xTaskGetHandle( mainTASK_TO_DELETE_NAME ) );
	xSemaphoreGiveRecursive( xSemaphore );
	configASSERT( uxSemaphoreGetCount( xSemaphore ) == 0 );
	xSemaphoreGiveRecursive( xSemaphore );
	configASSERT( uxSemaphoreGetCount( xSemaphore ) == 1 );
	configASSERT( xSemaphoreGetMutexHolder( xSemaphore ) == NULL );
	vSemaphoreDelete( xSemaphore );

	/* Create a normal mutex, and sure the mutex holder and count are returned
	returned correctly. */
	xSemaphore = xSemaphoreCreateMutex();
	configASSERT( xSemaphore );
	xSemaphoreTake( xSemaphore, mainDONT_BLOCK );
	xSemaphoreTake( xSemaphore, mainDONT_BLOCK );
	configASSERT( uxSemaphoreGetCount( xSemaphore ) == 0 ); /* Not recursive so can only be 1. */
	configASSERT( xSemaphoreGetMutexHolder( xSemaphore ) == xTaskGetCurrentTaskHandle() );
	xSemaphoreGive( xSemaphore );
	configASSERT( uxSemaphoreGetCount( xSemaphore ) == 1 );
	configASSERT( xSemaphoreGetMutexHolder( xSemaphore ) == NULL );
	vSemaphoreDelete( xSemaphore );
}
开发者ID:sean93park,项目名称:freertos,代码行数:49,代码来源:main.c

示例8: UAVObjSetInstanceDataField

/**
 * Set the data of a specific object instance
 * \param[in] obj The object handle
 * \param[in] instId The object instance ID
 * \param[in] dataIn The object's data structure
 * \return 0 if success or -1 if failure
 */
int32_t UAVObjSetInstanceDataField(UAVObjHandle obj, uint16_t instId, const void* dataIn, uint32_t offset, uint32_t size)
{
	ObjectList* objEntry;
	ObjectInstList* instEntry;
	UAVObjMetadata* mdata;

	// Lock
	xSemaphoreTakeRecursive(mutex, portMAX_DELAY);

	// Cast to object info
	objEntry = (ObjectList*)obj;

	// Check access level
	if ( !objEntry->isMetaobject )
	{
		mdata = (UAVObjMetadata*)(objEntry->linkedObj->instances.data);
		if ( mdata->access == ACCESS_READONLY )
		{
			xSemaphoreGiveRecursive(mutex);
			return -1;
		}
	}

	// Get instance information
	instEntry = getInstance(objEntry, instId);
	if ( instEntry == NULL )
	{
		// Error, unlock and return
		xSemaphoreGiveRecursive(mutex);
		return -1;
	}

	// return if we set too much of what we have
	if ( (size + offset) > objEntry->numBytes) {
		// Error, unlock and return
		xSemaphoreGiveRecursive(mutex);		
		return -1;
	}

	// Set data
	memcpy(instEntry->data + offset, dataIn, size);

	// Fire event
	sendEvent(objEntry, instId, EV_UPDATED);

	// Unlock
	xSemaphoreGiveRecursive(mutex);
	return 0;
}
开发者ID:LeeSaferite,项目名称:OpenPilot,代码行数:56,代码来源:uavobjectmanager.c

示例9: AlarmsSet

/**
 * Set an alarm
 * @param alarm The system alarm to be modified
 * @param severity The alarm severity
 * @return 0 if success, -1 if an error
 */
int32_t AlarmsSet(SystemAlarmsAlarmElem alarm, SystemAlarmsAlarmOptions severity)
{
	SystemAlarmsData alarms;

	// Check that this is a valid alarm
	if (alarm >= SYSTEMALARMS_ALARM_NUMELEM)
	{
		return -1;
	}

	// Lock
    xSemaphoreTakeRecursive(lock, portMAX_DELAY);

    // Read alarm and update its severity only if it was changed
    SystemAlarmsGet(&alarms);
    if ( alarms.Alarm[alarm] != severity )
    {
    	alarms.Alarm[alarm] = severity;
    	SystemAlarmsSet(&alarms);
    }

    // Release lock
    xSemaphoreGiveRecursive(lock);
    return 0;

}
开发者ID:1heinz,项目名称:TauLabs,代码行数:32,代码来源:alarms.c

示例10: UAVObjDelete

/**
 * Delete an object from the file system (SD card).
 * @param[in] obj The object handle.
 * @param[in] instId The object instance
 * @return 0 if success or -1 if failure
 */
int32_t UAVObjDelete(UAVObjHandle obj, uint16_t instId)
{
#if defined(PIOS_INCLUDE_FLASH_SECTOR_SETTINGS)
	  PIOS_FLASHFS_ObjDelete(obj, instId);
#endif
#if defined(PIOS_INCLUDE_SDCARD)
	  ObjectList *objEntry;
	  uint8_t filename[14];

	  // Check for file system availability
	  if (PIOS_SDCARD_IsMounted() == 0) {
		    return -1;
	  }
	  // Lock
	  xSemaphoreTakeRecursive(mutex, portMAX_DELAY);

	  // Cast to object
	  objEntry = (ObjectList *) obj;

	  // Get filename
	  objectFilename(objEntry, filename);

	  // Delete file
	  PIOS_FUNLINK(filename);

	  // Done
	  xSemaphoreGiveRecursive(mutex);
#endif /* PIOS_INCLUDE_SDCARD */
	  return 0;
}
开发者ID:LeeSaferite,项目名称:OpenPilot,代码行数:36,代码来源:uavobjectmanager.c

示例11: TaskMonitorUpdateAll

/**
 * Update the status of all tasks
 */
void TaskMonitorUpdateAll(void)
{
	TaskInfoData data;
	int n;

	// Lock
	xSemaphoreTakeRecursive(lock, portMAX_DELAY);

	// Update all task information
	for (n = 0; n < TASKINFO_RUNNING_NUMELEM; ++n)
	{
		if (handles[n] != 0)
		{
			data.Running[n] = TASKINFO_RUNNING_TRUE;
#if defined(ARCH_POSIX) || defined(ARCH_WIN32)
			data.StackRemaining[n] = 10000;
#else
			data.StackRemaining[n] = uxTaskGetStackHighWaterMark(handles[n]) * 4;
#endif
		}
		else
		{
			data.Running[n] = TASKINFO_RUNNING_FALSE;
			data.StackRemaining[n] = 0;
		}
	}

	// Update object
	TaskInfoSet(&data);

	// Done
	xSemaphoreGiveRecursive(lock);
}
开发者ID:mcu786,项目名称:my_OpenPilot_mods,代码行数:36,代码来源:taskmonitor.c

示例12: simpleQueueSize

int simpleQueueSize(struct SimpleQueue* queue){
	int return_value;
	while(xSemaphoreTakeRecursive(queue->xSemHandle,(TickType_t)0) != pdTRUE){}
	return_value = queue->size;
	xSemaphoreGiveRecursive(queue->xSemHandle);
	return return_value;
}
开发者ID:ntonjeta,项目名称:Nodo-Sensore,代码行数:7,代码来源:SimpleQueue.c

示例13: UAVTalkAddStats

/**
 * Get communication statistics counters
 * \param[in] connection UAVTalkConnection to be used
 * @param[out] statsOut Statistics counters
 */
void UAVTalkAddStats(UAVTalkConnection connectionHandle, UAVTalkStats *statsOut, bool reset)
{
    UAVTalkConnectionData *connection;

    CHECKCONHANDLE(connectionHandle, connection, return );

    // Lock
    xSemaphoreTakeRecursive(connection->lock, portMAX_DELAY);

    // Copy stats
    statsOut->txBytes       += connection->stats.txBytes;
    statsOut->txObjectBytes += connection->stats.txObjectBytes;
    statsOut->txObjects     += connection->stats.txObjects;
    statsOut->txErrors      += connection->stats.txErrors;
    statsOut->rxBytes       += connection->stats.rxBytes;
    statsOut->rxObjectBytes += connection->stats.rxObjectBytes;
    statsOut->rxObjects     += connection->stats.rxObjects;
    statsOut->rxErrors      += connection->stats.rxErrors;
    statsOut->rxSyncErrors  += connection->stats.rxSyncErrors;
    statsOut->rxCrcErrors   += connection->stats.rxCrcErrors;

    if (reset) {
        // Clear stats
        memset(&connection->stats, 0, sizeof(UAVTalkStats));
    }

    // Release lock
    xSemaphoreGiveRecursive(connection->lock);
}
开发者ID:MAVProxyUser,项目名称:NinjaPilot-15.02.ninja,代码行数:34,代码来源:uavtalk.c

示例14: simpleQueueDestroy

void simpleQueueDestroy(struct SimpleQueue* queue){
	while(xSemaphoreTakeRecursive(queue->xSemHandle,(TickType_t) 0)!=pdTRUE){}

	while(!simpleQueueEmpty(queue))
		simpleQueueDequeue(queue);
	 xSemaphoreGiveRecursive(queue->xSemHandle);
	 vSemaphoreDelete(queue->xSemHandle);	//TODO: ZUPPA
}
开发者ID:ntonjeta,项目名称:Nodo-Sensore,代码行数:8,代码来源:SimpleQueue.c

示例15: objectTransaction

/**
 * Execute the requested transaction on an object.
 * \param[in] connection UAVLinkConnection to be used
 * \param[in] obj Object
 * \param[in] instId The instance ID of UAVOBJ_ALL_INSTANCES for all instances.
 * \param[in] type Transaction type
 * 			  UAVLINK_TYPE_OBJ: send object,
 * 			  UAVLINK_TYPE_OBJ_REQ: request object update
 * 			  UAVLINK_TYPE_OBJ_ACK: send object with an ack
 * \return 0 Success
 * \return -1 Failure
 */
static int32_t objectTransaction(UAVLinkConnectionData *connection, UAVObjHandle obj, uint16_t instId, uint8_t type, int32_t timeoutMs)
{
	int32_t respReceived;
	
	// Send object depending on if a response is needed
	if (type == UAVLINK_TYPE_OBJ_ACK || type == UAVLINK_TYPE_OBJ_REQ)
	{
		// Get transaction lock (will block if a transaction is pending)
		xSemaphoreTakeRecursive(connection->transLock, portMAX_DELAY);
		// Send object
		xSemaphoreTakeRecursive(connection->lock, portMAX_DELAY);
		connection->respId =  UAVObjGetID(obj);
		connection->respInstId = instId;
		sendObject(connection, obj, instId, type);
		xSemaphoreGiveRecursive(connection->lock);
		// Wait for response (or timeout)
		respReceived = xSemaphoreTake(connection->respSema, timeoutMs/portTICK_RATE_MS);
		// Check if a response was received
		if (respReceived == pdFALSE)
		{
			// Cancel transaction
			xSemaphoreTakeRecursive(connection->lock, portMAX_DELAY);
			xSemaphoreTake(connection->respSema, 0); // non blocking call to make sure the value is reset to zero (binary sema)
			connection->respId = 0;
			xSemaphoreGiveRecursive(connection->lock);
			xSemaphoreGiveRecursive(connection->transLock);
			return -1;
		}
		else
		{
			xSemaphoreGiveRecursive(connection->transLock);
			return 0;
		}
	}
	else if (type == UAVLINK_TYPE_OBJ)
	{
		xSemaphoreTakeRecursive(connection->lock, portMAX_DELAY);
		sendObject(connection, obj, instId, UAVLINK_TYPE_OBJ);
		xSemaphoreGiveRecursive(connection->lock);
		return 0;
	}
	else
	{
		return -1;
	}
}
开发者ID:auuuux,项目名称:raspberrypilot,代码行数:58,代码来源:uavlink.c


注:本文中的xSemaphoreGiveRecursive函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。