firmware
IEM Firmware Documentation
Loading...
Searching...
No Matches
stm32_lock.h File Reference

STMicroelectronics lock mechanisms. More...

#include <stdint.h>
#include <stddef.h>
#include <cmsis_compiler.h>
Include dependency graph for stm32_lock.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define STM32_THREAD_SAFE_STRATEGY   2
#define STM32_LOCK_BLOCK()
#define STM32_LOCK_BLOCK_IF_NULL_ARGUMENT(x)
#define STM32_LOCK_BLOCK_IF_INTERRUPT_CONTEXT()
#define STM32_LOCK_UNUSED(var)
#define STM32_LOCK_ARRAY_SIZE(array)

Functions

void Error_Handler (void)
 This function is executed in case of error occurrence.

Detailed Description

STMicroelectronics lock mechanisms.

Author
STMicroelectronics

This implementation supports the following strategies for handling thread-safe locks. The strategy can be explicitly selected by defining \STM32_THREAD_SAFE_STRATEGY = <number> in the project. Please look at the '<toolchain/library>_lock_glue.c' file for more details.

  1. User defined thread-safe implementation. User defined solution for handling thread-safety.
    NOTE: The stubs in stm32_lock_user.h needs to be implemented to gain thread-safety.
  2. [DEFAULT] Allow lock usage from interrupts. This implementation will ensure thread-safety by disabling all interrupts during e.g. calls to malloc.
    NOTE: Disabling all interrupts creates interrupt latency which might not be desired for this application!
  3. Deny lock usage from interrupts. This implementation assumes single thread of execution.
    NOTE: Thread-safety dependent functions will enter an infinity loop if used in interrupt context.
  4. Allow lock usage from interrupts. Implemented using FreeRTOS locks. This implementation will ensure thread-safety by entering RTOS ISR capable critical sections during e.g. calls to malloc. By default this implementation supports 2 levels of recursive locking. Adding additional levels requires 4 bytes per lock per level of RAM.
    NOTE: Interrupts with high priority are not disabled. This implies that the lock is not thread-safe from high priority interrupts!
  5. Deny lock usage from interrupts. Implemented using FreeRTOS locks. This implementation will ensure thread-safety by suspending all tasks during e.g. calls to malloc.
    NOTE: Thread-safety dependent functions will enter an infinity loop if used in interrupt context.
Attention

© Copyright (c) 2021 STMicroelectronics. All rights reserved.

This software component is licensed by ST under BSD 3-Clause license, the "License"; You may not use this file except in compliance with the License. You may obtain a copy of the License at: opensource.org/licenses/BSD-3-Clause

Macro Definition Documentation

◆ STM32_LOCK_ARRAY_SIZE

#define STM32_LOCK_ARRAY_SIZE ( array)
Value:
(sizeof(array) / sizeof((array)[0]))

Size of array

◆ STM32_LOCK_BLOCK

#define STM32_LOCK_BLOCK ( )
Value:
do { \
__disable_irq(); \
Error_Handler(); \
while (1); \
} while (0)

Blocks execution

◆ STM32_LOCK_BLOCK_IF_INTERRUPT_CONTEXT

#define STM32_LOCK_BLOCK_IF_INTERRUPT_CONTEXT ( )
Value:
do { \
if (__get_IPSR()) { \
STM32_LOCK_BLOCK(); \
} \
} while (0)

Blocks execution if in interrupt context

◆ STM32_LOCK_BLOCK_IF_NULL_ARGUMENT

#define STM32_LOCK_BLOCK_IF_NULL_ARGUMENT ( x)
Value:
do { \
if ((x) == NULL) { \
STM32_LOCK_BLOCK(); \
} \
} while (0)

Blocks execution if argument is NULL

◆ STM32_LOCK_UNUSED

#define STM32_LOCK_UNUSED ( var)
Value:
(void)var

Hide unused parameter warning from compiler

◆ STM32_THREAD_SAFE_STRATEGY

#define STM32_THREAD_SAFE_STRATEGY   2

Assume strategy 2 if not specified

Function Documentation

◆ Error_Handler()

void Error_Handler ( void )

This function is executed in case of error occurrence.

Return values
None

This function is executed in case of error occurrence.