新增所有文件
This commit is contained in:
93
devices/include/spinlock.h
Normal file
93
devices/include/spinlock.h
Normal file
@@ -0,0 +1,93 @@
|
||||
/**
|
||||
* @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
|
||||
Reference in New Issue
Block a user