|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
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"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. | |
PVD / LVD runtime control: IRQ / reset / CMPE toggles, filter, hysteresis, negate, and status read / clear.
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).
Definition in file ra8_lvd_runtime.c.
|
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.
| [in] | channel | PVDm channel id. |
| k_ra8_ok | DET acknowledged. |
| k_ra8_err_invalid_arg | Channel mapping failed. |
| k_ra8_err_not_supported | Channel has no IRQ path (PVDn). |
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.
|
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.
| [in] | channel | PVD channel id. |
| k_ra8_ok | CMPE cleared. |
| k_ra8_err_invalid_arg | Channel mapping failed. |
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.
|
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).
| [in] | channel | PVDm channel id. |
| k_ra8_ok | IRQ disabled. |
| k_ra8_err_invalid_arg | Channel mapping failed. |
| k_ra8_err_not_supported | Channel has no IRQ path. |
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.
|
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).
| [in] | channel | PVD channel id. |
| k_ra8_ok | Reset response disarmed. |
| k_ra8_err_invalid_arg | Channel mapping failed. |
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.
|
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.
| [in] | channel | PVD channel id. |
| k_ra8_ok | CMPE asserted. |
| k_ra8_err_invalid_arg | Channel mapping failed. |
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.
|
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).
| [in] | channel | PVDm channel id. |
| k_ra8_ok | IRQ enabled. |
| k_ra8_err_invalid_arg | Channel mapping failed. |
| k_ra8_err_not_supported | Channel has no IRQ path. |
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.
|
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).
| [in] | channel | PVD channel id. |
| k_ra8_ok | Reset response armed. |
| k_ra8_err_invalid_arg | Channel mapping failed. |
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.
|
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.
| [in] | channel | PVDm channel id. |
| [out] | out | Receives the decoded status. |
| k_ra8_ok | Status decoded. |
| k_ra8_err_null_ptr | out was NULL. |
| k_ra8_err_invalid_arg | Channel mapping failed. |
| k_ra8_err_not_supported | Channel has no IRQ path (PVDn). |
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().
|
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.
| [in] | channel | PVD channel id. |
| [in] | filter_div | New FSAMP divider. |
| [in] | filter_en | True to enable the digital filter. |
| k_ra8_ok | Filter updated. |
| k_ra8_err_invalid_arg | Channel or divider out of range. |
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.
|
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.
| [in] | channel | PVD channel id. |
| [in] | hyst | New hysteresis mode. |
| k_ra8_ok | Hysteresis mode updated. |
| k_ra8_err_invalid_arg | Channel or mode out of range. |
| k_ra8_err_invalid_state | HVD requested with RI=0 (m channel only). |
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.
|
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.
| [in] | channel | PVDm channel id. |
| [in] | negate | Negation behaviour. |
| k_ra8_ok | RN updated. |
| k_ra8_err_invalid_arg | Channel or mode out of range. |
| k_ra8_err_not_supported | Channel has no IRQ path (PVDn). |
| k_ra8_err_invalid_state | RN=1 conflicts with FCR.RHSEL=1. |
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.
|
static |
Logging tag used by every error path in this TU.
Private per-TU copy of the driver-wide "LVD" log tag.
Definition at line 39 of file ra8_lvd_runtime.c.