spinlock.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /*
  7. * This file provides only very simple stubs to build IDF-based FreeRTOSes which use spinlocks on Linux.
  8. */
  9. #pragma once
  10. #include <stdint.h>
  11. #include <stdbool.h>
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. #define SPINLOCK_FREE 0xB33FFFFF
  16. #define SPINLOCK_WAIT_FOREVER (-1)
  17. #define SPINLOCK_NO_WAIT 0
  18. #define SPINLOCK_INITIALIZER {.owner = SPINLOCK_FREE,.count = 0}
  19. #define CORE_ID_REGVAL_XOR_SWAP (0xCDCD ^ 0xABAB)
  20. /**
  21. * @brief Spinlock object
  22. * Owner:
  23. * - Set to 0 if uninitialized
  24. * - Set to portMUX_FREE_VAL when free
  25. * - Set to CORE_ID_REGVAL_PRO or CORE_ID_REGVAL_AP when locked
  26. * - Any other value indicates corruption
  27. * Count:
  28. * - 0 if unlocked
  29. * - Recursive count if locked
  30. *
  31. * @note Not a true spinlock as single core RISC-V does not have atomic compare and set instruction
  32. * @note Keep portMUX_INITIALIZER_UNLOCKED in sync with this struct
  33. */
  34. typedef struct {
  35. uint32_t owner;
  36. uint32_t count;
  37. }spinlock_t;
  38. static inline void __attribute__((always_inline)) spinlock_initialize(spinlock_t *lock)
  39. {
  40. }
  41. static inline bool __attribute__((always_inline)) spinlock_acquire(spinlock_t *lock, int32_t timeout)
  42. {
  43. return true;
  44. }
  45. static inline void __attribute__((always_inline)) spinlock_release(spinlock_t *lock)
  46. {
  47. }
  48. #ifdef __cplusplus
  49. }
  50. #endif