XilinxProcessorIPLib/drivers/mutex/examples/xmutex_tapp_example.c
int MutexExample(u16 MutexDeviceID)
{
	XMutex_Config *ConfigPtr;
	XStatus Status;
	u32 TimeoutCount = 0;

	/*
	 * Lookup configuration data in the device configuration table.
	 * Use this configuration info down below when initializing this
	 * driver instance.
	 */
	ConfigPtr = XMutex_LookupConfig(MutexDeviceID);
	if (ConfigPtr == (XMutex_Config *)NULL) {
		return XST_FAILURE;
	}

	/*
	 * Perform the rest of the initialization.
	 */
	Status = XMutex_CfgInitialize(&Mutex, ConfigPtr,
					ConfigPtr->BaseAddress);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Depending on which CPU this is running on, either lock the
	 * Mutex or test the Mutex to see if it is locked.
	 */
	if (XPAR_CPU_ID == 0) {

		XMutex_Lock(&Mutex, MUTEX_NUM);	/* Acquire lock */
		XMutex_Unlock(&Mutex, MUTEX_NUM);	/* Release lock */
	} else {

		/*
		 * Try to acquire lock, other CPU should have it so it
		 * should fail.
		 */
		while ((XMutex_Trylock(&Mutex, MUTEX_NUM)) != XST_SUCCESS) {
			if (TimeoutCount++ > LOCK_TIMEOUT) {
				return XST_FAILURE;
			}
		}

		XMutex_Unlock(&Mutex, MUTEX_NUM);	/* Release lock */
	}

	return XST_SUCCESS;
}
/*****************************************************************************/
/**
* This function contains the actual functionality for the XMutex TestApp
* example. he idea is to have this application running on two processors which
* share the same bus and have access to the Mutex hardware. CPU 0 is considered
* the primary CPU since it is the one which is expected to initially lock the
* Mutex.
*
* @param	MutexDeviceID is the device id to be initialized and used.
*
* @return
*		- XST_SUCCESS if successful
*		- XST_FAILURE if unsuccessful
*
* @note		None
*
******************************************************************************/
This function contains the actual functionality for the XMutex TestApp
example. he idea is to have this application running on two processors which
share the same bus and have access to the Mutex hardware. CPU 0 is considered
the primary CPU since it is the one which is expected to initially lock the
Mutex.
This function contains the actual functionality for the XMutex TestApp example . he idea is to have this application running on two processors which share the same bus and have access to the Mutex hardware . CPU 0 is considered the primary CPU since it is the one which is expected to initially lock the Mutex .
int MutexExample(u16 MutexDeviceID)
{
	XMutex_Config *ConfigPtr;
	XStatus Status;
	u32 TimeoutCount = 0;
	ConfigPtr = XMutex_LookupConfig(MutexDeviceID);
	if (ConfigPtr == (XMutex_Config *)NULL) {
		return XST_FAILURE;
	}
	Status = XMutex_CfgInitialize(&Mutex, ConfigPtr,
					ConfigPtr->BaseAddress);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	if (XPAR_CPU_ID == 0) {
		XMutex_Lock(&Mutex, MUTEX_NUM);	
		XMutex_Unlock(&Mutex, MUTEX_NUM);	
	} else {
		while ((XMutex_Trylock(&Mutex, MUTEX_NUM)) != XST_SUCCESS) {
			if (TimeoutCount++ > LOCK_TIMEOUT) {
				return XST_FAILURE;
			}
		}
		XMutex_Unlock(&Mutex, MUTEX_NUM);	
	}
	return XST_SUCCESS;
}
int MutexExample ( u16 MutexDeviceID ) { XMutex_Config * ConfigPtr ; XStatus Status ; u32 TimeoutCount = 0 ; ConfigPtr = XMutex_LookupConfig ( MutexDeviceID ) ; if ( ConfigPtr == ( XMutex_Config * ) NULL ) { return XST_FAILURE ; } Status = XMutex_CfgInitialize ( & Mutex , ConfigPtr , ConfigPtr -> BaseAddress ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } if ( XPAR_CPU_ID == 0 ) { XMutex_Lock ( & Mutex , MUTEX_NUM ) ; XMutex_Unlock ( & Mutex , MUTEX_NUM ) ; } else { while ( ( XMutex_Trylock ( & Mutex , MUTEX_NUM ) ) != XST_SUCCESS ) { if ( TimeoutCount ++ > LOCK_TIMEOUT ) { return XST_FAILURE ; } } XMutex_Unlock ( & Mutex , MUTEX_NUM ) ; } return XST_SUCCESS ; }
This function contains the actual functionality for the XMutex TestApp
example.
This function contains the actual functionality for the XMutex TestApp example .
/*
	 * Lookup configuration data in the device configuration table.
	 * Use this configuration info down below when initializing this
	 * driver instance.
	 */ /*
	 * Perform the rest of the initialization.
	 */ /*
	 * Depending on which CPU this is running on, either lock the
	 * Mutex or test the Mutex to see if it is locked.
	 */ /* Acquire lock */ /* Release lock */ /*
		 * Try to acquire lock, other CPU should have it so it
		 * should fail.
		 */ /* Release lock */