| mutex Vitis Drivers API Documentation

- Overview
- Data Structures
- APIs
- File List
- Examples

Macros | Functions
xmutex_tapp_example.c File Reference

## Overview

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 seperate 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.

Note

These code fragments will illustrate how the XMutex driver can be used to:

- Initialize the Mutex core
- Lock, Unlock and query the status of the hardware

      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.

    *

## Macros
#define | MUTEX_NUM 0
| The Mutex number on which this example is run. More...

## Functions
int | MutexExample (u16 MutexDeviceID)
| 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...

## Macro Definition Documentation

#define MUTEX_NUM 0

The Mutex number on which this example is run.

Referenced by MutexExample().

## Function Documentation

int main | ( | void |  | ) |

This function is the main function for the Mutex example.

Parameters

  None. |

Returns
  - XST_SUCCESS if successful.
  - XST_FAILURE if unsuccessful.

Note
  None.

int MutexExample | ( | u16 | MutexDeviceID | ) |

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.

Parameters

  MutexDeviceID | is the device id to be initialized and used.

Returns
  - XST_SUCCESS if successful
  - XST_FAILURE if unsuccessful

Note
  None

References XMutex_Config::BaseAddress, MUTEX_NUM, XMutex_CfgInitialize(), XMutex_Lock(), XMutex_Trylock(), and XMutex_Unlock().