ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_register_guard.h File Reference

IRQ-masked read-modify-write helper for shared registers. More...

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

Go to the source code of this file.

Data Structures

struct  ra8_register_guard_t
 Opaque save-restore handle for IRQ masking. More...

Functions

static void ra8_register_guard_enter (ra8_register_guard_t *guard)
 Enter a critical section: save PRIMASK, mask interrupts.
static void ra8_register_guard_exit (const ra8_register_guard_t *guard)
 Exit a critical section: restore PRIMASK.

Detailed Description

IRQ-masked read-modify-write helper for shared registers.

Most RA8D2 peripheral registers are safe to read-modify-write from a single thread, but cross-peripheral routing (ELC events, ICU IELSR entries, MSTP module stop) is updated from several drivers and needs atomicity. This module provides a tiny primitive:

*reg = (*reg & ~mask) | new_value;
static void ra8_register_guard_exit(const ra8_register_guard_t *guard)
Exit a critical section: restore PRIMASK.
static void ra8_register_guard_enter(ra8_register_guard_t *guard)
Enter a critical section: save PRIMASK, mask interrupts.
Opaque save-restore handle for IRQ masking.

_enter stores the current PRIMASK and then sets it (masking all maskable interrupts). _exit restores the saved PRIMASK. Pairs must always balance; nested calls are supported.

Definition in file ra8_register_guard.h.

Function Documentation

◆ ra8_register_guard_enter()

void ra8_register_guard_enter ( ra8_register_guard_t * guard)
inlinestatic

Enter a critical section: save PRIMASK, mask interrupts.

Parameters
[out]guardPointer to a caller-allocated guard. Must not be nullptr.
Note
Nested calls are supported. Each enter must have a matching exit.

See implementation for details.

Precondition
Module has been initialized.
Caller has validated arguments.
Postcondition
Side effects bounded to documented state.
State reflects operation result.
Since
0.1.0

Definition at line 59 of file ra8_register_guard.h.

References ra8_register_guard_t::saved_primask.

Referenced by c6_cam_audio_snapshot_wav(), priv_dfu_write_secure(), ra8_sci_abort(), ra8_sci_attach_rx_handler(), ra8_sci_attach_tx_handler(), ra8_sci_deinit(), ra8_sci_read(), ra8_sci_read_stop(), ra8_sci_receive_resume(), ra8_sci_receive_suspend(), ra8_sci_set_baud(), and ra8_sci_write().

◆ ra8_register_guard_exit()

void ra8_register_guard_exit ( const ra8_register_guard_t * guard)
inlinestatic

Exit a critical section: restore PRIMASK.

Parameters
[in]guardPointer to a guard previously passed to ra8_register_guard_enter().

See implementation for details.

Precondition
Module has been initialized.
Caller has validated arguments.
Postcondition
Side effects bounded to documented state.
State reflects operation result.
Note
Not thread-safe unless documented otherwise.
Since
0.1.0

Definition at line 85 of file ra8_register_guard.h.

References ra8_register_guard_t::saved_primask.

Referenced by c6_cam_audio_snapshot_wav(), priv_dfu_write_secure(), ra8_sci_abort(), ra8_sci_attach_rx_handler(), ra8_sci_attach_tx_handler(), ra8_sci_deinit(), ra8_sci_read(), ra8_sci_read_stop(), ra8_sci_receive_resume(), ra8_sci_receive_suspend(), ra8_sci_set_baud(), and ra8_sci_write().