Jump to main content

##

# 1.4.4.7 OSAL_CRIT_Enter Function

## C

    OSAL_CRITSECT_DATA_TYPE OSAL_CRIT_Enter(OSAL_CRIT_TYPE severity)

## Summary

Enters a critical section with the specified severity level.

## Description

This function enters a critical section of code. It is assumed that the sequence of operations bounded by the enter and leave critical section operations is treated as one atomic sequence that will not be disturbed. This function should be paired with OSAL_CRIT_Leave().

## Precondition

None.

## Parameters

Param | Description
--- | ---
severity | OSAL_CRIT_TYPE_LOW, The RTOS should disable all other running tasks effectively locking the scheduling mechanism. OSAL_CRIT_TYPE_HIGH, The RTOS should disable all possible interrupts sources including the scheduler ensuring that the sequence of code operates without interruption. The state of interrupts are returned to the user before they are disabled

## Returns

A data type of OSAL_CRITSECT_DATA_TYPE, this value represents the state of interrupts before entering the critical section.

## Example

    OSAL_CRITSECT_DATA_TYPE IntState;
    // prevent other tasks preempting this sequence of code
    IntState = OSAL_CRIT_Enter(OSAL_CRIT_TYPE_HIGH);
    // modify the peripheral
    DRV_USART_Reinitialize( objUSART, &initData);
    OSAL_CRIT_Leave(OSAL_CRIT_TYPE_HIGH, IntState);

## Remarks

The sequence of operations bounded by the OSAL_CRIT_Enter and OSAL_CRIT_Leave form a critical section. The severity level defines whether the RTOS should perform task locking or completely disable all interrupts.