93 lines
1.6 KiB
C
93 lines
1.6 KiB
C
/**
|
|
* @brief spinlock.h
|
|
*
|
|
* Copyright (c) 2020 Semidrive Semiconductor.
|
|
* All rights reserved.
|
|
*
|
|
* Description: spinlock interface.
|
|
*
|
|
* Revision History:
|
|
* -----------------
|
|
*/
|
|
|
|
#ifndef _INCLUDE_SPINLOCK_H_
|
|
#define _INCLUDE_SPINLOCK_H_
|
|
|
|
#ifndef ASSEMBLY
|
|
|
|
#include <armv7-r/spinlock.h>
|
|
#include <armv7-r/irq.h>
|
|
|
|
__BEGIN_CDECLS
|
|
|
|
/**
|
|
* @brief spinlock init.
|
|
*
|
|
* @param[in] spinlock spinlock address.
|
|
*/
|
|
static inline void spin_lock_init(spin_lock_t *spinlock)
|
|
{
|
|
arch_spin_lock_init(spinlock);
|
|
}
|
|
|
|
/**
|
|
* @brief spin lock.
|
|
*
|
|
* @param[in] spinlock spinlock address.
|
|
*/
|
|
static inline void spin_lock(spin_lock_t *spinlock)
|
|
{
|
|
arch_spin_lock(spinlock);
|
|
}
|
|
|
|
/**
|
|
* @brief spin trylock.
|
|
*
|
|
* @param[in] spinlock spinlock address.
|
|
* @return try lock result.
|
|
*/
|
|
static inline int spin_trylock(spin_lock_t *spinlock)
|
|
{
|
|
return arch_spin_trylock(spinlock);
|
|
}
|
|
|
|
/**
|
|
* @brief spin unlock.
|
|
*
|
|
* @param[in] spinlock spinlock address.
|
|
*/
|
|
static inline void spin_unlock(spin_lock_t *spinlock)
|
|
{
|
|
arch_spin_unlock(spinlock);
|
|
}
|
|
|
|
/**
|
|
* @brief spin lock with irq save
|
|
*
|
|
* @param[in] spinlock spinlock address.
|
|
* @return old irq state.
|
|
*/
|
|
static inline irq_state_t spin_lock_irqsave(spin_lock_t *spinlock)
|
|
{
|
|
irq_state_t state = arch_irq_save();
|
|
spin_lock(spinlock);
|
|
return state;
|
|
}
|
|
|
|
/**
|
|
* @brief spin unlock with irq restore
|
|
*
|
|
* @param[in] spinlock spinlock address.
|
|
* @param[in] state old irq state.
|
|
*/
|
|
static inline void spin_unlock_irqrestore(spin_lock_t *spinlock, irq_state_t state)
|
|
{
|
|
spin_unlock(spinlock);
|
|
arch_irq_restore(state);
|
|
}
|
|
|
|
__END_CDECLS
|
|
|
|
#endif
|
|
|
|
#endif |