![]() |
mutex
Vitis Drivers API Documentation
|
This file contains a design example for using the Mutex hardware and driver XMutex.
The example assumes there are two processors availabile in the system that are expected to inter-communicate.
This example attempts to lock the Mutex from the processor identified as 0 (XPAR_CPU_ID=0) to prevent the other processor from getting the lock. Since the application is running on two separate processors, the initiator declares success when the Mutex locks the other processor declares success when the Mutex is locked from its perspective. There is no feedback to the initiator so a terminal is required for each processor to verify that the test passed for both sides.
This example has been tested on ML505 Hardware Evaluation board.
These code fragments will illustrate how the XMutex driver can be used to:
MODIFICATION HISTORY:
Ver Who Date Changes
1.00a va First release 1.00a ecm 06/04/07 Cleanup, new coding standard, check into XCS 1.00a ecm 08/28/08 Converted to testapp example 3.01a sdm 05/04/10 Removed printfs from the MutexExample 4.2 ms 01/23/17 Modified xil_printf statement in main function to ensure that "Successfully ran" and "Failed" strings are available in all examples. This is a fix for CR-965028. 4.7 ht 06/21/23 Added support for system device-tree flow. 4.10 ht 04/09/25 Fix parameter unused compilation warning.
4.11 vlt 12/14/25 Update Doxygen comments to include SDT flow details.
vlt 01/27/26 Fixed codespell issues
ht 02/24/26 Fix doxygen warnings
* #include "xparameters.h"#include "xstatus.h"#include "xmutex.h"#include <stdio.h>#include <stdlib.h>Macros | |
| #define | MUTEX_NUM 0 |
| The Mutex number on which this example is run. More... | |
Functions | |
| int | MutexExample (XMutex *MutexInstPtr, UINTPTR BaseAddress) |
| This function contains the actual functionality for the XMutex TestApp example. More... | |
| int | main (void) |
| This function is the main function for the Mutex example. More... | |
| #define MUTEX_NUM 0 |
The Mutex number on which this example is run.
Referenced by MutexExample().
| int main | ( | void | ) |
This function is the main function for the Mutex example.
| int MutexExample | ( | XMutex * | MutexInstPtr, |
| UINTPTR | BaseAddress | ||
| ) |
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.
| MutexInstPtr | is a pointer to the Mutex instance |
| BaseAddress | contains the base address of the device |
References XMutex_Config::BaseAddress, MUTEX_NUM, XMutex_CfgInitialize(), XMutex_Lock(), XMutex_LookupConfig(), XMutex_Trylock(), and XMutex_Unlock().