NMSIS-Core  Version 1.4.0
NMSIS-Core support for Nuclei processor-based devices
Semaphore Functions

Functions that configure and use semaphoresSemaphore is very useful for multi-core cluster without SMP enable. More...

Functions

__STATIC_FORCEINLINE uint32_t CIDU_GetSemaphoreStatus (uint32_t semph_n)
 Get SEMAPHOREn's value. More...
 
__STATIC_FORCEINLINE long CIDU_CheckSemaphoreAcquired (uint32_t semph_n, uint32_t core_id)
 check SEMAPHOREn's acquired status More...
 
__STATIC_FORCEINLINE long CIDU_AcquireSemaphore (uint32_t semph_n, uint32_t core_id)
 Acquire the SEMAPHOREn. More...
 
__STATIC_FORCEINLINE void CIDU_AcquireSemaphore_Block (uint32_t semph_n, uint32_t core_id)
 Keep acquiring the SEMAPHOREn until it has acquired this semaphore successfully. More...
 
__STATIC_FORCEINLINE void CIDU_ReleaseSemaphore (uint32_t semph_n)
 Release the SEMAPHOREn. More...
 

Detailed Description

Functions that configure and use semaphores

Semaphore is very useful for multi-core cluster without SMP enable.

Function Documentation

◆ CIDU_AcquireSemaphore()

__STATIC_FORCEINLINE long CIDU_AcquireSemaphore ( uint32_t  semph_n,
uint32_t  core_id 
)

Acquire the SEMAPHOREn.

Acuqire the SEMAPHOREn, and check the acquired status

Parameters
[in]semph_nthe semaphore id used to protect a critical resource
[in]core_idthe core id that wants to access the critical resource
Returns
0 if core_id has acquired this semaphore successfully, or else -1 if failed
Remarks
  • When the core n owns the register SEMPAPHORE_n and finishes the job related the critical resource, it should call CIDU_ReleaseSemaphore to release it.
See also

Definition at line 386 of file core_feature_cidu.h.

387 {
388  long semaphore_status = -1;
389  uint32_t* addr = (uint32_t*)CIDU_SEMAPHORE_ADDR(semph_n);
390 
391  __SW(addr, core_id);
392  semaphore_status = CIDU_CheckSemaphoreAcquired(semph_n, core_id);
393  return semaphore_status;
394 }
#define CIDU_SEMAPHORE_ADDR(n)
Semaphore n register address.
__STATIC_FORCEINLINE void __SW(volatile void *addr, uint32_t val)
Write 32bit value to address (32 bit)
__STATIC_FORCEINLINE long CIDU_CheckSemaphoreAcquired(uint32_t semph_n, uint32_t core_id)
check SEMAPHOREn's acquired status

References __SW(), CIDU_CheckSemaphoreAcquired(), and CIDU_SEMAPHORE_ADDR.

Referenced by CIDU_AcquireSemaphore_Block().

◆ CIDU_AcquireSemaphore_Block()

__STATIC_FORCEINLINE void CIDU_AcquireSemaphore_Block ( uint32_t  semph_n,
uint32_t  core_id 
)

Keep acquiring the SEMAPHOREn until it has acquired this semaphore successfully.

Query that whether SEMAPHOREn has been owned by one core successfully, if not, keep trying.

Parameters
[in]semph_nthe semaphore id used to protect a critical resource
[in]core_idthe core id that wants to access the critical resource
Remarks
  • Core n will block here acquiring, so take care that core should release the semaphore when related job done.
See also

Definition at line 408 of file core_feature_cidu.h.

409 {
410  int32_t semaphore_status = -1;
411 
412  while(0 != semaphore_status) {
413  semaphore_status = CIDU_AcquireSemaphore(semph_n, core_id);
414  }
415 }
__STATIC_FORCEINLINE long CIDU_AcquireSemaphore(uint32_t semph_n, uint32_t core_id)
Acquire the SEMAPHOREn.

References CIDU_AcquireSemaphore().

◆ CIDU_CheckSemaphoreAcquired()

__STATIC_FORCEINLINE long CIDU_CheckSemaphoreAcquired ( uint32_t  semph_n,
uint32_t  core_id 
)

check SEMAPHOREn's acquired status

Query that whether SEMAPHOREn has been acquired by one core successfully.

Parameters
[in]semph_nthe semaphore id used to protect a critical resource
[in]core_idthe core id that wants to access the critical resource
Returns
0 if core_id has acquired this semaphore successfully, or else -1 if failed
Remarks
  • When the core n owns the register SEMPAPHORE_n and finishes the job related the critical resource, it should call CIDU_ReleaseSemaphore to release it.
See also

Definition at line 362 of file core_feature_cidu.h.

363 {
364  uint32_t val;
365  val = CIDU_GetSemaphoreStatus(semph_n);
366  if (core_id != val) {
367  return -1;
368  }
369  return 0;
370 }
__STATIC_FORCEINLINE uint32_t CIDU_GetSemaphoreStatus(uint32_t semph_n)
Get SEMAPHOREn's value.

References CIDU_GetSemaphoreStatus().

Referenced by CIDU_AcquireSemaphore().

◆ CIDU_GetSemaphoreStatus()

__STATIC_FORCEINLINE uint32_t CIDU_GetSemaphoreStatus ( uint32_t  semph_n)

Get SEMAPHOREn's value.

Just query the semaphore n's value

Parameters
[in]semph_nthe semaphore id used to protect a critical resource
Returns
register SEMAPHOREn_STATUS value

Definition at line 339 of file core_feature_cidu.h.

340 {
341  uint32_t val;
342  uint32_t* addr = (uint32_t*)CIDU_SEMAPHORE_ADDR(semph_n);
343 
344  val = __LW(addr);
345  return val;
346 }
__STATIC_FORCEINLINE uint32_t __LW(volatile void *addr)
Load 32bit value from address (32 bit)

References __LW(), and CIDU_SEMAPHORE_ADDR.

Referenced by CIDU_CheckSemaphoreAcquired().

◆ CIDU_ReleaseSemaphore()

__STATIC_FORCEINLINE void CIDU_ReleaseSemaphore ( uint32_t  semph_n)

Release the SEMAPHOREn.

Release the SEMAPHOREn by writing all 1 to SEMAPHOREn register.

Parameters
[in]semph_nthe semaphore id used to protect a critical resource
Remarks
  • When the core finishes the job related to the critical resource, it should release the corresponding semaphore.
See also

Definition at line 427 of file core_feature_cidu.h.

428 {
429  uint32_t* addr = (uint32_t*)CIDU_SEMAPHORE_ADDR(semph_n);
430 
431  /* Release by writing all 1 */
432  __SW(addr, 0xFFFFFFFF);
433 }

References __SW(), and CIDU_SEMAPHORE_ADDR.