107 lines
3.3 KiB
C
107 lines
3.3 KiB
C
/****************************************************************************
|
|
|
|
Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
|
|
|
|
This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
|
|
be copied by any method or incorporated into another program without
|
|
the express written consent of Aerospace C.Power. This Information or any portion
|
|
thereof remains the property of Aerospace C.Power. The Information contained herein
|
|
is believed to be accurate and Aerospace C.Power assumes no responsibility or
|
|
liability for its use in any way and conveys no license or title under
|
|
any patent or copyright and makes no representation or warranty that this
|
|
Information is free from patent or copyright infringement.
|
|
|
|
****************************************************************************/
|
|
#ifndef _IOT_SPINLOCK_H_
|
|
#define _IOT_SPINLOCK_H_
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#define SPINLOCK_MASTER_MAX 16
|
|
|
|
/* NOTE: consider the application of multi-cpu system spinlock,
|
|
* we can divide spinlock like this:
|
|
* ID 0: dynamically allocated mutually exclusive protection;
|
|
* ID 1 - 7: static allocation used by AMP;
|
|
* ID 8 - 15: dynamically allocation used by SMP;
|
|
*
|
|
* only static allocation of the AMP system is currently enabled.
|
|
*/
|
|
typedef enum {
|
|
SPINLOCK_INDEX_0 = 0,
|
|
/* define spinlock used to set registers synchronously
|
|
* between hplc cpu and bbcpu
|
|
*/
|
|
SPINLOCK_HPLC_RF_SYNC,
|
|
/* define spinlock used to set rtc synchronously
|
|
* between hplc cpu and cus cpu
|
|
*/
|
|
SPINLOCK_RTC_SYNC,
|
|
/* define spinlock used to crypto hw synchronously
|
|
* between hplc cpu and sec cpu
|
|
*/
|
|
SPINLOCK_CRYPTO_SM3_SHA,
|
|
SPINLOCK_INDEX_4,
|
|
SPINLOCK_INDEX_5,
|
|
SPINLOCK_INDEX_6,
|
|
SPINLOCK_INDEX_7,
|
|
SPINLOCK_INDEX_8,
|
|
SPINLOCK_INDEX_9,
|
|
SPINLOCK_INDEX_10,
|
|
SPINLOCK_INDEX_11,
|
|
SPINLOCK_INDEX_12,
|
|
SPINLOCK_INDEX_13,
|
|
SPINLOCK_INDEX_14,
|
|
SPINLOCK_INDEX_15,
|
|
SPINLOCK_INDEX_MAX,
|
|
} SPINLOCK_MODULE_E;
|
|
|
|
/**
|
|
* @brief iot_spinlock_lock() - spinlock lock.
|
|
* @param id: - spinlock id.
|
|
* @param master: - master id.
|
|
* @return uint32_t: - lock success or not.
|
|
*/
|
|
uint32_t iot_spinlock_lock(uint8_t id, uint8_t master);
|
|
|
|
/**
|
|
* @brief iot_spinlock_unlock() - spinlock unlock.
|
|
* @param id: - spinlock id.
|
|
* @param master: - master id.
|
|
* @return uint32_t: - unlock success or not.
|
|
*/
|
|
uint32_t iot_spinlock_unlock(uint8_t id, uint8_t master);
|
|
|
|
/**
|
|
* @brief iot_spinlock_owner() - spinlock owner.
|
|
* @param id: - spinlock id.
|
|
* @return uint32_t: - owner master.
|
|
*/
|
|
uint32_t iot_spinlock_owner(uint8_t id);
|
|
|
|
/**
|
|
* @brief iot_spinlock_init() - spinlock init.
|
|
* @param void: - void.
|
|
* @return uint32_t: - success or not.
|
|
*/
|
|
uint32_t iot_spinlock_init();
|
|
|
|
/**
|
|
* @brief iot_spinlock_alloc() - spinlock alloc.
|
|
* @param master: - master.
|
|
* @return uint32_t: - alloc success or not.
|
|
*/
|
|
uint8_t iot_spinlock_alloc(uint8_t master);
|
|
|
|
/**
|
|
* @brief iot_spinlock_free() - spinlock alloc.
|
|
* @param id: - spinlock id.
|
|
* @param master: - master.
|
|
*/
|
|
void iot_spinlock_free(uint8_t id, uint8_t master);
|
|
|
|
#endif /* _IOT_SPINLOCK_H_ */
|
|
|