feat(ulp-riscv): Added utility functions for atomicity

This commit adds utility functions to enter and exit critical sections
in the code flow by disabling and enabling interrupts.
pull/13294/head
Sudeep Mohanty 2024-02-12 13:53:11 +01:00
rodzic bc74cf808d
commit d352ec615a
1 zmienionych plików z 26 dodań i 0 usunięć

Wyświetl plik

@ -132,6 +132,32 @@ void ulp_riscv_disable_sw_intr(void);
*/
void ulp_riscv_trigger_sw_intr(void);
/**
* @brief Enter a critical section by disabling all interrupts
* This inline assembly construct uses the t0 register and is equivalent to:
*
* li t0, 0x80000007
* maskirq_insn(zero, t0) // Mask all interrupt bits
*/
#define ULP_RISCV_ENTER_CRITICAL() \
asm volatile ( \
"li t0, 0x80000007\n" \
".word 0x0602e00b" \
); \
/**
* @brief Exit a critical section by enabling all interrupts
* This inline assembly construct is equivalent to:
*
* maskirq_insn(zero, zero) // Unmask all interrupt bits
*/
#define ULP_RISCV_EXIT_CRITICAL() asm volatile (".word 0x0600600b");
#else /* CONFIG_ULP_RISCV_INTERRUPT_ENABLE */
#define ULP_RISCV_ENTER_CRITICAL()
#define ULP_RISCV_EXIT_CRITICAL()
#endif /* CONFIG_ULP_RISCV_INTERRUPT_ENABLE */
#ifdef __cplusplus