61#ifndef __STM32_LOCK_H__
62#define __STM32_LOCK_H__
67#include <cmsis_compiler.h>
69#ifndef STM32_THREAD_SAFE_STRATEGY
70#define STM32_THREAD_SAFE_STRATEGY 2
82#define STM32_LOCK_BLOCK() \
91#define STM32_LOCK_BLOCK_IF_NULL_ARGUMENT(x) \
101#define STM32_LOCK_BLOCK_IF_INTERRUPT_CONTEXT() \
106 STM32_LOCK_BLOCK(); \
111#define STM32_LOCK_UNUSED(var) (void)var
114#define STM32_LOCK_ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
116#if STM32_THREAD_SAFE_STRATEGY == 1
123#define STM32_LOCK_API 1
124#include "stm32_lock_user.h"
127#elif STM32_THREAD_SAFE_STRATEGY == 2
134#define LOCKING_DATA_INIT { 0, 0 }
162 uint8_t flag = (uint8_t)(__get_PRIMASK() & 0x1);
171 else if (lock->
counter == UINT8_MAX)
196#elif STM32_THREAD_SAFE_STRATEGY == 3
203#define LOCKING_DATA_INIT 0
239#elif STM32_THREAD_SAFE_STRATEGY == 4
248#if defined (__GNUC__) && !defined (__CC_ARM) && configUSE_NEWLIB_REENTRANT == 0
249#warning Please set configUSE_NEWLIB_REENTRANT to 1 in FreeRTOSConfig.h, otherwise newlib will not be thread-safe
254#define LOCKING_DATA_INIT { {0, 0}, 0 }
255#define STM32_LOCK_MAX_NESTED_LEVELS 2
258 uint32_t basepri[STM32_LOCK_MAX_NESTED_LEVELS];
259 uint8_t nesting_level;
264#define STM32_LOCK_ASSERT_VALID_NESTING_LEVEL(lock) \
267 if (lock->nesting_level >= STM32_LOCK_ARRAY_SIZE(lock->basepri)) \
269 STM32_LOCK_BLOCK(); \
284 lock->basepri[i] = 0;
286 lock->nesting_level = 0;
296 STM32_LOCK_ASSERT_VALID_NESTING_LEVEL(lock);
297 lock->basepri[lock->nesting_level++] = taskENTER_CRITICAL_FROM_ISR();
307 lock->nesting_level--;
308 STM32_LOCK_ASSERT_VALID_NESTING_LEVEL(lock);
309 taskEXIT_CRITICAL_FROM_ISR(lock->basepri[lock->nesting_level]);
312#undef STM32_LOCK_ASSERT_VALID_NESTING_LEVEL
313#undef STM32_LOCK_MAX_NESTED_LEVELS
315#elif STM32_THREAD_SAFE_STRATEGY == 5
323#if defined (__GNUC__) && !defined (__CC_ARM) && configUSE_NEWLIB_REENTRANT == 0
324#warning Please set configUSE_NEWLIB_REENTRANT to 1 in FreeRTOSConfig.h, otherwise newlib will not be thread-safe
329#define LOCKING_DATA_INIT 0
368#error Invalid STM32_THREAD_SAFE_STRATEGY specified
void Error_Handler(void)
Global Error_Handler.
Definition newlib_lock_glue.c:44
#define STM32_LOCK_ARRAY_SIZE(array)
Definition stm32_lock.h:114
#define STM32_LOCK_BLOCK_IF_INTERRUPT_CONTEXT()
Definition stm32_lock.h:101
#define STM32_LOCK_BLOCK_IF_NULL_ARGUMENT(x)
Definition stm32_lock.h:91
#define STM32_LOCK_BLOCK()
Definition stm32_lock.h:82
Definition stm32_lock.h:138
uint8_t flag
Definition stm32_lock.h:139
uint8_t counter
Definition stm32_lock.h:140