KugleFirmware/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_hsem.c
/**
  * @brief  Take a semaphore in 2 Step mode. 
  * @param  SemID: semaphore ID from 0 to 31  
  * @param  ProcessID: Process ID from 0 to 255 
  * @retval HAL status
*/
@brief  Take a semaphore in 2 Step mode.
@param  SemID: semaphore ID from 0 to 31
@param  ProcessID: Process ID from 0 to 255
@retval HAL status
@brief Take a semaphore in 2 Step mode . @param SemID : semaphore ID from 0 to 31 @param ProcessID : Process ID from 0 to 255 @retval HAL status
HAL_StatusTypeDef  HAL_HSEM_Take(uint32_t SemID, uint32_t ProcessID)
{          
  assert_param(IS_HSEM_SEMID(SemID));
  assert_param(IS_HSEM_PROCESSID(ProcessID));
  HSEM->R[SemID] = ((ProcessID & HSEM_R_PROCID) | ((HAL_GetCurrentCPUID() << POSITION_VAL(HSEM_R_MASTERID)) & HSEM_R_MASTERID) | HSEM_R_LOCK);
  if(HSEM->R[SemID] == ((ProcessID & HSEM_R_PROCID) | ((HAL_GetCurrentCPUID() << POSITION_VAL(HSEM_R_MASTERID)) & HSEM_R_MASTERID) | HSEM_R_LOCK))
  {
    return HAL_OK; 
  } 
  return HAL_ERROR;
}
HAL_StatusTypeDef HAL_HSEM_Take ( uint32_t SemID , uint32_t ProcessID ) { assert_param ( IS_HSEM_SEMID ( SemID ) ) ; assert_param ( IS_HSEM_PROCESSID ( ProcessID ) ) ; HSEM -> R [ SemID ] = ( ( ProcessID & HSEM_R_PROCID ) | ( ( HAL_GetCurrentCPUID ( ) << POSITION_VAL ( HSEM_R_MASTERID ) ) & HSEM_R_MASTERID ) | HSEM_R_LOCK ) ; if ( HSEM -> R [ SemID ] == ( ( ProcessID & HSEM_R_PROCID ) | ( ( HAL_GetCurrentCPUID ( ) << POSITION_VAL ( HSEM_R_MASTERID ) ) & HSEM_R_MASTERID ) | HSEM_R_LOCK ) ) { return HAL_OK ; } return HAL_ERROR ; }
@brief  Take a semaphore in 2 Step mode.
@brief Take a semaphore in 2 Step mode .
/* Check the parameters */ /* First step  write R register with MasterID, processID and take bit=1*/ /* second step : read the R register . Take achieved if MasterID and processID match and take bit set to 1 */ /*take success when MasterID and ProcessID match and take bit set*/ /* Semaphore take fails*/