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

PVD / LVD runtime control: IRQ / reset / CMPE toggles, filter, hysteresis, negate, and status read / clear. More...

#include <stdint.h>
#include "ra8_check.h"
#include "ra8_err.h"
#include "ra8_lvd.h"
#include "ra8_lvd_internal.h"
#include "ra8_lvd_regs.h"
Include dependency graph for ra8_lvd_runtime.c:

Go to the source code of this file.

Functions

ra8_err_t ra8_lvd_enable_irq (ra8_lvd_channel_t channel)
 Set CR0.RIE on an IRQ-capable PVDm channel.
ra8_err_t ra8_lvd_disable_irq (ra8_lvd_channel_t channel)
 Clear CR0.RIE on an IRQ-capable PVDm channel.
ra8_err_t ra8_lvd_enable_reset (ra8_lvd_channel_t channel)
 Arm the reset response for a PVD channel.
ra8_err_t ra8_lvd_disable_reset (ra8_lvd_channel_t channel)
 Disarm the reset response for a PVD channel.
ra8_err_t ra8_lvd_enable_cmpe (ra8_lvd_channel_t channel)
 Set CR0.CMPE so the comparator output drives the response logic.
ra8_err_t ra8_lvd_disable_cmpe (ra8_lvd_channel_t channel)
 Clear CR0.CMPE so the comparator stops driving the response logic.
ra8_err_t ra8_lvd_set_filter (ra8_lvd_channel_t channel, ra8_lvd_loco_div_t filter_div, bool filter_en)
 Update FSAMP and DFDIS for a PVD channel at runtime.
ra8_err_t ra8_lvd_set_hysteresis_mode (ra8_lvd_channel_t channel, ra8_lvd_hysteresis_t hyst)
 Update FCR.RHSEL (hysteresis mode) for a PVD channel.
ra8_err_t ra8_lvd_set_negate_mode (ra8_lvd_channel_t channel, ra8_lvd_negate_t negate)
 Update CR0.RN (negate-after-assert) for a PVDm channel.
ra8_err_t ra8_lvd_get_status (ra8_lvd_channel_t channel, ra8_lvd_status_t *out)
 Read PVDmSR and decode DET / MON into ra8_lvd_status_t.
ra8_err_t ra8_lvd_clear_status (ra8_lvd_channel_t channel)
 Acknowledge PVDmSR.DET via write-0-to-clear.

Variables

static const char * s_tag = "LVD"
 Logging tag used by every error path in this TU.

Detailed Description

PVD / LVD runtime control: IRQ / reset / CMPE toggles, filter, hysteresis, negate, and status read / clear.

Tag
[Ring 3 / HAL] {World: S}

Companion translation unit to ra8_lvd.c. Holds the single-bit CR0 toggles (RIE / RI / RE / CMPE), the runtime filter / RHSEL / RN updaters, and the PVDmSR status read / clear path. The shared channel-map descriptor table and the cross-TU register helpers it calls live in ra8_lvd_internal.h; every register access keeps its HUM Ch 8 citation (R01UH1065EJ rev 1.30).

Since
0.1.0

Definition in file ra8_lvd_runtime.c.

Function Documentation

◆ ra8_lvd_clear_status()

ra8_err_t ra8_lvd_clear_status ( ra8_lvd_channel_t channel)
nodiscard

Acknowledge PVDmSR.DET via write-0-to-clear.

Clear the latched DET flag on one channel (write-0-to-clear).

Per HUM Ch 12.2.7 "PVDmSR" p 600 Note 1, only 0 can be written to DET; MON is preserved by clearing only the DET bit.

Parameters
[in]channelPVDm channel id.
Returns
ra8_err_t error code.
Return values
k_ra8_okDET acknowledged.
k_ra8_err_invalid_argChannel mapping failed.
k_ra8_err_not_supportedChannel has no IRQ path (PVDn).
Precondition
Channel previously brought up via ra8_lvd_channel_init.
PRCR.PRC3 unlocked.
Postcondition
SR.DET reads as 0.
SR.MON is unchanged.
Note
Not thread-safe (read-modify-write on SR).
Since
0.1.0

Definition at line 516 of file ra8_lvd_runtime.c.

References g_lvd_map, ra8_lvd_channel_map_t::has_irq, k_ra8_err_not_supported, k_ra8_lvd_sr_mask_det, k_ra8_ok, priv_ra8_lvd_internal_channel_to_idx(), ra8_lvd_reg8(), RA8_RETURN_ON_ERROR, s_tag, and ra8_lvd_channel_map_t::sr.

◆ ra8_lvd_disable_cmpe()

ra8_err_t ra8_lvd_disable_cmpe ( ra8_lvd_channel_t channel)
nodiscard

Clear CR0.CMPE so the comparator stops driving the response logic.

Drop PVDmCR0.CMPE / PVDnCR0.CMPE for a channel.

Per HUM Ch 12.2.4 (p 597), used during shutdown or reconfiguration to silence the channel's response path without dropping PVDE.

Parameters
[in]channelPVD channel id.
Returns
ra8_err_t error code.
Return values
k_ra8_okCMPE cleared.
k_ra8_err_invalid_argChannel mapping failed.
Precondition
Channel previously brought up via ra8_lvd_channel_init.
PRCR.PRC3 unlocked.
Postcondition
CR0.CMPE reads as 0.
Reserved-bit invariant for the channel is preserved.
Note
Not thread-safe.
Since
0.1.0

Definition at line 259 of file ra8_lvd_runtime.c.

References g_lvd_map, k_ra8_lvd_cr0_mask_cmpe, k_ra8_ok, priv_ra8_lvd_internal_channel_to_idx(), priv_ra8_lvd_internal_cr0_rmw(), RA8_RETURN_ON_ERROR, and s_tag.

◆ ra8_lvd_disable_irq()

ra8_err_t ra8_lvd_disable_irq ( ra8_lvd_channel_t channel)
nodiscard

Clear CR0.RIE on an IRQ-capable PVDm channel.

Drop PVDmCR0.RIE for one channel.

Disables IRQ delivery via the standard CR0 RMW path so the reserved bit-3 stays set (HUM Ch 12.2.4 "PVDmCR0" p 597).

Parameters
[in]channelPVDm channel id.
Returns
ra8_err_t error code.
Return values
k_ra8_okIRQ disabled.
k_ra8_err_invalid_argChannel mapping failed.
k_ra8_err_not_supportedChannel has no IRQ path.
Precondition
Channel previously brought up via ra8_lvd_channel_init.
PRCR.PRC3 unlocked.
Postcondition
CR0.RIE reads as 0.
Reserved-bit invariant for the channel is preserved.
Note
Not thread-safe.
Since
0.1.0

Definition at line 106 of file ra8_lvd_runtime.c.

References g_lvd_map, ra8_lvd_channel_map_t::has_irq, k_ra8_err_not_supported, k_ra8_lvd_cr0_mask_rie, k_ra8_ok, priv_ra8_lvd_internal_channel_to_idx(), priv_ra8_lvd_internal_cr0_rmw(), RA8_RETURN_ON_ERROR, and s_tag.

◆ ra8_lvd_disable_reset()

ra8_err_t ra8_lvd_disable_reset ( ra8_lvd_channel_t channel)
nodiscard

Disarm the reset response for a PVD channel.

Drop the reset enable bit (RIE for m, RE for n).

For PVDm channels clears RI; for PVDn channels clears RE. See HUM Ch 12.2.4 / 12.2.5 (pp 597-598).

Parameters
[in]channelPVD channel id.
Returns
ra8_err_t error code.
Return values
k_ra8_okReset response disarmed.
k_ra8_err_invalid_argChannel mapping failed.
Precondition
Channel previously brought up via ra8_lvd_channel_init.
PRCR.PRC3 unlocked.
Postcondition
Channel will not reset the SoC on subsequent crossings.
Reserved-bit invariant for the channel is preserved.
Note
Not thread-safe.
Since
0.1.0

Definition at line 186 of file ra8_lvd_runtime.c.

References g_lvd_map, ra8_lvd_channel_map_t::has_irq, k_ra8_lvd_cr0_mask_re, k_ra8_lvd_cr0_mask_rie, k_ra8_ok, priv_ra8_lvd_internal_channel_to_idx(), priv_ra8_lvd_internal_cr0_rmw(), RA8_RETURN_ON_ERROR, and s_tag.

◆ ra8_lvd_enable_cmpe()

ra8_err_t ra8_lvd_enable_cmpe ( ra8_lvd_channel_t channel)
nodiscard

Set CR0.CMPE so the comparator output drives the response logic.

Drive PVDmCR0.CMPE / PVDnCR0.CMPE high for a channel.

Per HUM Ch 12.2.4 (p 597) CMPE gates whether a detected crossing fans out to RIE/RE/RI; this helper toggles CMPE alone so the caller can stage the bring-up.

Parameters
[in]channelPVD channel id.
Returns
ra8_err_t error code.
Return values
k_ra8_okCMPE asserted.
k_ra8_err_invalid_argChannel mapping failed.
Precondition
Channel previously brought up via ra8_lvd_channel_init.
PRCR.PRC3 unlocked.
Postcondition
CR0.CMPE reads as 1.
Reserved-bit invariant for the channel is preserved.
Note
Not thread-safe.
Since
0.1.0

Definition at line 226 of file ra8_lvd_runtime.c.

References g_lvd_map, k_ra8_lvd_cr0_mask_cmpe, k_ra8_ok, priv_ra8_lvd_internal_channel_to_idx(), priv_ra8_lvd_internal_cr0_rmw(), RA8_RETURN_ON_ERROR, and s_tag.

◆ ra8_lvd_enable_irq()

ra8_err_t ra8_lvd_enable_irq ( ra8_lvd_channel_t channel)
nodiscard

Set CR0.RIE on an IRQ-capable PVDm channel.

Enable interrupt-on-cross for a monitor m channel.

Enables IRQ delivery via the standard CR0 RMW path so the reserved bit-3 stays set (HUM Ch 12.2.4 "PVDmCR0" p 597).

Parameters
[in]channelPVDm channel id.
Returns
ra8_err_t error code.
Return values
k_ra8_okIRQ enabled.
k_ra8_err_invalid_argChannel mapping failed.
k_ra8_err_not_supportedChannel has no IRQ path.
Precondition
Channel previously brought up via ra8_lvd_channel_init.
PRCR.PRC3 unlocked.
Postcondition
CR0.RIE reads as 1.
Reserved-bit invariant for the channel is preserved.
Note
Not thread-safe.
Since
0.1.0

Definition at line 68 of file ra8_lvd_runtime.c.

References g_lvd_map, ra8_lvd_channel_map_t::has_irq, k_ra8_err_not_supported, k_ra8_lvd_cr0_mask_rie, k_ra8_ok, priv_ra8_lvd_internal_channel_to_idx(), priv_ra8_lvd_internal_cr0_rmw(), RA8_RETURN_ON_ERROR, and s_tag.

◆ ra8_lvd_enable_reset()

ra8_err_t ra8_lvd_enable_reset ( ra8_lvd_channel_t channel)
nodiscard

Arm the reset response for a PVD channel.

Enable the reset path for a channel.

For PVDm channels sets RI + RIE; for PVDn channels sets RE (the only response option). See HUM Ch 12.2.4 / 12.2.5 (pp 597-598).

Parameters
[in]channelPVD channel id.
Returns
ra8_err_t error code.
Return values
k_ra8_okReset response armed.
k_ra8_err_invalid_argChannel mapping failed.
Precondition
Channel previously brought up via ra8_lvd_channel_init.
PRCR.PRC3 unlocked.
Postcondition
Channel will reset the SoC on the configured crossing.
Reserved-bit invariant for the channel is preserved.
Note
Not thread-safe.
Since
0.1.0

Definition at line 142 of file ra8_lvd_runtime.c.

References g_lvd_map, ra8_lvd_channel_map_t::has_irq, k_ra8_lvd_cr0_mask_re, k_ra8_lvd_cr0_mask_ri, k_ra8_lvd_cr0_mask_rie, k_ra8_ok, priv_ra8_lvd_internal_channel_to_idx(), priv_ra8_lvd_internal_cr0_rmw(), RA8_RETURN_ON_ERROR, and s_tag.

◆ ra8_lvd_get_status()

ra8_err_t ra8_lvd_get_status ( ra8_lvd_channel_t channel,
ra8_lvd_status_t * out )
nodiscard

Read PVDmSR and decode DET / MON into ra8_lvd_status_t.

Read the DET and MON flags for one channel.

Reads the status register documented at HUM Ch 12.2.7 "PVDmSR" p 600 and unpacks the latched-crossing (DET) and live-comparator (MON) bits.

Parameters
[in]channelPVDm channel id.
[out]outReceives the decoded status.
Returns
ra8_err_t error code.
Return values
k_ra8_okStatus decoded.
k_ra8_err_null_ptrout was NULL.
k_ra8_err_invalid_argChannel mapping failed.
k_ra8_err_not_supportedChannel has no IRQ path (PVDn).
Precondition
out non-NULL.
Channel previously brought up via ra8_lvd_channel_init.
Postcondition
*out reflects the live SR contents.
Hardware state is unchanged.
Note
Read-only; safe under simple races.
Since
0.1.0

Definition at line 474 of file ra8_lvd_runtime.c.

References ra8_lvd_status_t::above, ra8_lvd_status_t::crossed, g_lvd_map, ra8_lvd_channel_map_t::has_irq, k_ra8_err_not_supported, k_ra8_lvd_sr_mask_det, k_ra8_lvd_sr_mask_mon, k_ra8_ok, priv_ra8_lvd_internal_channel_to_idx(), RA8_CHECK_NULL_PTR, ra8_lvd_reg8(), RA8_RETURN_ON_ERROR, s_tag, and ra8_lvd_channel_map_t::sr.

Referenced by internal_lvd_demo_sample().

◆ ra8_lvd_set_filter()

ra8_err_t ra8_lvd_set_filter ( ra8_lvd_channel_t channel,
ra8_lvd_loco_div_t filter_div,
bool filter_en )
nodiscard

Update FSAMP and DFDIS for a PVD channel at runtime.

Tune the digital filter (FSAMP[1:0] + DFDIS) on one channel.

FSAMP can only be modified while DFDIS = 1 (HUM Ch 12.2.4 / 12.2.5 pp 597-598). This helper temporarily sets DFDIS, writes FSAMP, and drops DFDIS back when filter_en is true.

Parameters
[in]channelPVD channel id.
[in]filter_divNew FSAMP divider.
[in]filter_enTrue to enable the digital filter.
Returns
ra8_err_t error code.
Return values
k_ra8_okFilter updated.
k_ra8_err_invalid_argChannel or divider out of range.
Precondition
Channel previously brought up via ra8_lvd_channel_init.
PRCR.PRC3 unlocked.
Postcondition
CR0.FSAMP reflects filter_div.
CR0.DFDIS reflects the inverse of filter_en.
Note
Not thread-safe.
Since
0.1.0

Definition at line 301 of file ra8_lvd_runtime.c.

References g_lvd_map, k_ra8_lvd_cr0_mask_dfdis, k_ra8_lvd_cr0_mask_fsamp, k_ra8_lvd_cr0_shift_fsamp, k_ra8_ok, priv_ra8_lvd_internal_channel_to_idx(), priv_ra8_lvd_internal_cr0_rmw(), priv_ra8_lvd_internal_validate_div(), RA8_RETURN_ON_ERROR, and s_tag.

◆ ra8_lvd_set_hysteresis_mode()

ra8_err_t ra8_lvd_set_hysteresis_mode ( ra8_lvd_channel_t channel,
ra8_lvd_hysteresis_t hyst )
nodiscard

Update FCR.RHSEL (hysteresis mode) for a PVD channel.

Update PVDmFCR.RHSEL / PVDnFCR.RHSEL hysteresis-band selector.

Per HUM Ch 12.2.8 "PVDmFCR" p 600 RHSEL must not be set to 1 when PVDmCR0.RI = 0 on m channels. RHSEL can only be modified when every PVDE is 0; this helper preserves and restores the channel's own PVDE around the write.

Parameters
[in]channelPVD channel id.
[in]hystNew hysteresis mode.
Returns
ra8_err_t error code.
Return values
k_ra8_okHysteresis mode updated.
k_ra8_err_invalid_argChannel or mode out of range.
k_ra8_err_invalid_stateHVD requested with RI=0 (m channel only).
Precondition
Channel previously brought up via ra8_lvd_channel_init.
PRCR.PRC3 unlocked.
Postcondition
FCR.RHSEL reflects hyst.
CMPCR.PVDE state is preserved across the write.
Note
Not thread-safe.
Since
0.1.0

Definition at line 352 of file ra8_lvd_runtime.c.

References ra8_lvd_channel_map_t::cmpcr, ra8_lvd_channel_map_t::fcr, g_lvd_map, ra8_lvd_channel_map_t::has_irq, k_ra8_err_invalid_arg, k_ra8_err_invalid_state, k_ra8_lvd_cmpcr_mask_pvde, k_ra8_lvd_fcr_mask_rhsel, k_ra8_lvd_hysteresis_hvd, k_ra8_ok, priv_ra8_lvd_internal_channel_to_idx(), priv_ra8_lvd_internal_read_ri(), ra8_lvd_reg8(), RA8_RETURN_ON_ERROR, and s_tag.

◆ ra8_lvd_set_negate_mode()

ra8_err_t ra8_lvd_set_negate_mode ( ra8_lvd_channel_t channel,
ra8_lvd_negate_t negate )
nodiscard

Update CR0.RN (negate-after-assert) for a PVDm channel.

Update PVDmCR0.RN reset-negate timing on an m channel.

Per HUM Ch 12.2.4 "PVDmCR0" p 597, RN=1 is rejected when RHSEL=1 (HVD mode). This helper enforces the constraint and writes RN.

Parameters
[in]channelPVDm channel id.
[in]negateNegation behaviour.
Returns
ra8_err_t error code.
Return values
k_ra8_okRN updated.
k_ra8_err_invalid_argChannel or mode out of range.
k_ra8_err_not_supportedChannel has no IRQ path (PVDn).
k_ra8_err_invalid_stateRN=1 conflicts with FCR.RHSEL=1.
Precondition
Channel previously brought up via ra8_lvd_channel_init.
PRCR.PRC3 unlocked.
Postcondition
CR0.RN reflects negate.
Reserved-bit invariant for the channel is preserved.
Note
Not thread-safe.
Since
0.1.0

Definition at line 411 of file ra8_lvd_runtime.c.

References ra8_lvd_channel_map_t::fcr, g_lvd_map, ra8_lvd_channel_map_t::has_irq, k_ra8_err_invalid_arg, k_ra8_err_invalid_state, k_ra8_err_not_supported, k_ra8_lvd_cr0_mask_rn, k_ra8_lvd_fcr_mask_rhsel, k_ra8_lvd_negate_after_assert, k_ra8_ok, priv_ra8_lvd_internal_channel_to_idx(), priv_ra8_lvd_internal_cr0_rmw(), ra8_lvd_reg8(), RA8_RETURN_ON_ERROR, and s_tag.

Variable Documentation

◆ s_tag

const char* s_tag = "LVD"
static

Logging tag used by every error path in this TU.

Private per-TU copy of the driver-wide "LVD" log tag.

Note
PRIVATE.
Warning
Do not modify at runtime.
Since
0.1.0

Definition at line 39 of file ra8_lvd_runtime.c.