HWSPINLOCK
Overview
This sample runs two Zephyr images (sysbuild):
HOST periodically locks a hardware spinlock gate, sends a mailbox ping while holding the lock, then releases the lock and waits for a pong.
REMOTE receives the ping, shows that a non-blocking trylock fails while HOST holds the gate, then blocks until it can lock the same gate and replies.
The purpose is to show that the HWSPINLOCK API provides real inter-core mutual exclusion (via a hardware hwspinlock controller), while MBOX is used for signaling.
Building and Running
Build for FRDM-MCXN947 (CPU0 + CPU1)
# From the root of the zephyr repository
west build -b frdm_mcxn947/mcxn947/cpu0 --sysbuild samples/drivers/hwspinlock
Expected Output
HOST output example:
Hello from HOST - frdm_mcxn947/mcxn947/cpu0
...
HOST: locked gate id=0, sending ping on channel 1
HOST: unlocked gate, waiting for pong...
HOST: received pong
REMOTE output example:
Hello from REMOTE - frdm_mcxn947/mcxn947/cpu1
...
REMOTE: got ping (rx_sem), checking gate contention...
REMOTE: trylock returned -16 (expected if HOST holds the lock)
REMOTE: waiting to acquire gate...
REMOTE: acquired gate id=0
REMOTE: locked gate id=0, sending pong on channel 0