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

Test-access surface for ra8_lvd internal helpers (MC/DC). More...

#include <stdint.h>
#include "ra8_attributes.h"
#include "ra8_err.h"
#include "ra8_lvd.h"
Include dependency graph for ra8_lvd_internal.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ra8_lvd_channel_map_t
 Per-channel register-offset bundle. More...

Enumerations

enum  ra8_lvd_map_idx_t : uint8_t {
  k_ra8_lvd_map_idx_ch1 = 0U ,
  k_ra8_lvd_map_idx_ch2 = 1U ,
  k_ra8_lvd_map_idx_ch4 = 2U ,
  k_ra8_lvd_map_idx_ch5 = 3U ,
  k_ra8_lvd_map_idx_count = 4U
}
 Indices into g_lvd_map. More...

Functions

ra8_err_t priv_ra8_lvd_internal_channel_to_idx (ra8_lvd_channel_t channel, uint8_t *out_idx)
 Translate a public channel id to an index into g_lvd_map.
ra8_err_t priv_ra8_lvd_internal_validate_div (ra8_lvd_loco_div_t div)
 Validate FSAMP[1:0] candidate (0..3).
uint8_t priv_ra8_lvd_internal_read_ri (const ra8_lvd_channel_map_t *map)
 Read PVDmCR0.RI for an m channel.
void priv_ra8_lvd_internal_cr0_rmw (const ra8_lvd_channel_map_t *map, uint8_t clear_mask, uint8_t set_bits)
 Read-modify-write helper for PVDmCR0 / PVDnCR0 with reserved-bit rewrite forced.
bool priv_ra8_lvd_internal_reject_hvd_after (uint32_t hvd_val, uint32_t after_assert_val, uint32_t hysteresis, uint32_t negate)
 Pure predicate for "RN=1 prohibited when RHSEL=1" rejection.
bool priv_ra8_lvd_internal_set_ri_bit (uint32_t reset_val, uint32_t reset_on_rise_val, uint32_t response)
 Pure predicate for the CR0 "set RI bit" decision.

Variables

const ra8_lvd_channel_map_t g_lvd_map [k_ra8_lvd_map_idx_count]
 Lookup table from ra8_lvd_map_idx_t to register offsets.

Detailed Description

Test-access surface for ra8_lvd internal helpers (MC/DC).

Not part of the public API. Tests under tests/ MAY include this header to drive compound boolean decisions that sit in TU-private helpers behind the public ra8_lvd facade.

Definition in file ra8_lvd_internal.h.

Enumeration Type Documentation

◆ ra8_lvd_map_idx_t

enum ra8_lvd_map_idx_t : uint8_t

Indices into g_lvd_map.

Enumerator
k_ra8_lvd_map_idx_ch1 

PVD1.

k_ra8_lvd_map_idx_ch2 

PVD2.

k_ra8_lvd_map_idx_ch4 

PVD4.

k_ra8_lvd_map_idx_ch5 

PVD5.

k_ra8_lvd_map_idx_count 

Sentinel.

Definition at line 61 of file ra8_lvd_internal.h.

Function Documentation

◆ priv_ra8_lvd_internal_channel_to_idx()

ra8_err_t priv_ra8_lvd_internal_channel_to_idx ( ra8_lvd_channel_t channel,
uint8_t * out_idx )

Translate a public channel id to an index into g_lvd_map.

Parameters
[in]channelPublic channel id.
[out]out_idxOn success, the index in [0..3].
Returns
k_ra8_ok if mapping succeeded, k_ra8_err_invalid_arg otherwise.

Folds the public ra8_lvd_channel_t enumerator (which uses the datasheet's PVD1/2/4/5 numbering) into a 0..3 array index used by the internal g_lvd_map lookup table. Shared across the ra8_lvd translation units.

Return values
k_ra8_okMapping succeeded.
k_ra8_err_invalid_argchannel is not one of PVD1/2/4/5.
Precondition
out_idx != nullptr.
channel may be any uint8_t.
Postcondition
On success, *out_idx is in [0, k_ra8_lvd_map_idx_count).
On failure, *out_idx is unchanged.
Note
Pure helper; safe from any context. Driver-internal.
Since
0.1.0

Translate a public channel id to an index into g_lvd_map.

Definition at line 141 of file ra8_lvd.c.

References k_ra8_err_invalid_arg, k_ra8_lvd_ch1, k_ra8_lvd_ch2, k_ra8_lvd_ch4, k_ra8_lvd_ch5, k_ra8_lvd_map_idx_ch1, k_ra8_lvd_map_idx_ch2, k_ra8_lvd_map_idx_ch4, k_ra8_lvd_map_idx_ch5, and k_ra8_ok.

Referenced by ra8_lvd_attach_channel_handler(), ra8_lvd_channel_deinit(), ra8_lvd_channel_init(), ra8_lvd_clear_status(), ra8_lvd_configure_for_standby(), ra8_lvd_disable_cmpe(), ra8_lvd_disable_elc_event(), ra8_lvd_disable_irq(), ra8_lvd_disable_reset(), ra8_lvd_dispatch(), ra8_lvd_enable_cmpe(), ra8_lvd_enable_elc_event(), ra8_lvd_enable_irq(), ra8_lvd_enable_reset(), ra8_lvd_get_status(), ra8_lvd_set_filter(), ra8_lvd_set_hysteresis_mode(), ra8_lvd_set_irq_edge(), ra8_lvd_set_irq_kind(), ra8_lvd_set_negate_mode(), and ra8_lvd_set_threshold().

◆ priv_ra8_lvd_internal_cr0_rmw()

void priv_ra8_lvd_internal_cr0_rmw ( const ra8_lvd_channel_map_t * map,
uint8_t clear_mask,
uint8_t set_bits )

Read-modify-write helper for PVDmCR0 / PVDnCR0 with reserved-bit rewrite forced.

Reads PVDxCR0, masks out clear_mask, ORs in set_bits, then folds the channel's mandatory reserved-bit pattern back in (HUM Ch 12.2.4 / 12.2.5). Shared across the ra8_lvd TUs.

Parameters
[in]mapChannel map.
[in]clear_maskBits to clear.
[in]set_bitsBits to set.
Precondition
PRCR.PRC3 unlocked.
Caller has serialised access to the CR0 register.
Postcondition
Register reads as ((old & ~clear_mask) | set_bits | reserved).
Reserved-bit invariant for the channel is preserved.
Note
Internal helper; not thread-safe. Driver-internal.
Since
0.1.0

Read-modify-write helper for PVDmCR0 / PVDnCR0 with reserved-bit rewrite forced.

Definition at line 325 of file ra8_lvd.c.

References ra8_lvd_channel_map_t::cr0, internal_cr0_apply_reserved(), and ra8_lvd_reg8().

Referenced by ra8_lvd_cancel_deep_standby_path(), ra8_lvd_channel_deinit(), ra8_lvd_configure_for_standby(), ra8_lvd_disable_cmpe(), ra8_lvd_disable_elc_event(), ra8_lvd_disable_irq(), ra8_lvd_disable_reset(), ra8_lvd_enable_cmpe(), ra8_lvd_enable_elc_event(), ra8_lvd_enable_irq(), ra8_lvd_enable_reset(), ra8_lvd_set_filter(), and ra8_lvd_set_negate_mode().

◆ priv_ra8_lvd_internal_read_ri()

uint8_t priv_ra8_lvd_internal_read_ri ( const ra8_lvd_channel_map_t * map)

Read PVDmCR0.RI for an m channel.

Returns the Reset-on-Voltage bit (HUM Ch 12.2.4 "PVDmCR0" p 597) so the caller can decide whether to issue a software reset on a detected voltage crossing. Shared across the ra8_lvd TUs.

Parameters
[in]mapChannel map entry (must be has_irq=true).
Returns
Non-zero if RI is set.
Return values
0RI bit clear – IRQ-only path.
!=0RI bit set – channel will reset the SoC on crossing.
Precondition
map.has_irq == true.
PRCR.PRC3 unlocked (caller-managed).
Postcondition
Hardware state unchanged.
No CR0 write has been issued.
Note
Read-only; safe under simple races. Driver-internal.
Since
0.1.0

Read PVDmCR0.RI for an m channel.

Definition at line 233 of file ra8_lvd.c.

References ra8_lvd_channel_map_t::cr0, k_ra8_lvd_cr0_mask_ri, and ra8_lvd_reg8().

Referenced by ra8_lvd_set_hysteresis_mode().

◆ priv_ra8_lvd_internal_reject_hvd_after()

bool priv_ra8_lvd_internal_reject_hvd_after ( uint32_t hvd_val,
uint32_t after_assert_val,
uint32_t hysteresis,
uint32_t negate )

Pure predicate for "RN=1 prohibited when RHSEL=1" rejection.

Returns true iff hysteresis equals the HVD code AND negate equals the after-assert code. Promoted from the inline compound AND at libs/ra8_hal/src/ra8_lvd.c.

Parameters
[in]hvd_valNumeric value of k_ra8_lvd_hysteresis_hvd.
[in]after_assert_valNumeric value of k_ra8_lvd_negate_after_assert.
[in]hysteresisCandidate hysteresis value.
[in]negateCandidate negate value.
Returns
Boolean reject-config predicate.
Return values
trueCaller must return k_ra8_err_invalid_arg.
falseCombination is allowed.
Precondition
None.
None.
Postcondition
No state mutated.
Return depends solely on the four inputs.
Note
Test-access only. Pure function.
MC/DC:
2-condition AND; N+1 = 3 vectors:
  • hyst!=hvd, neg=after -> false
  • hyst=hvd, neg=after -> true (varies hyst)
  • hyst=hvd, neg!=after -> false (varies neg)
Since
0.1.0

Pure predicate for "RN=1 prohibited when RHSEL=1" rejection.

Promoted helper so the line-494 AND can be driven under MC/DC.

Parameters
[in]hvd_valNumeric value of k_ra8_lvd_hysteresis_hvd.
[in]after_assert_valNumeric value of k_ra8_lvd_negate_after_assert.
[in]hysteresisCandidate hysteresis value.
[in]negateCandidate negate value.
Returns
Boolean reject predicate.
Return values
trueCaller returns k_ra8_err_invalid_arg.
falseCombination is allowed.
Precondition
None.
None.
Postcondition
No state mutated.
Return depends solely on inputs.
Note
Pure; thread-safe.
Since
0.1.0

Definition at line 51 of file ra8_lvd.c.

Referenced by internal_validate_cfg().

◆ priv_ra8_lvd_internal_set_ri_bit()

bool priv_ra8_lvd_internal_set_ri_bit ( uint32_t reset_val,
uint32_t reset_on_rise_val,
uint32_t response )

Pure predicate for the CR0 "set RI bit" decision.

Returns true iff response equals the reset code OR equals the reset-on-rise code. Promoted from the inline compound OR at libs/ra8_hal/src/ra8_lvd.c inside internal_compose_cr0.

Parameters
[in]reset_valNumeric value of k_ra8_lvd_response_reset.
[in]reset_on_rise_valNumeric value of k_ra8_lvd_response_reset_on_rise.
[in]responseCandidate response value.
Returns
Boolean set-RI predicate.
Return values
trueCaller must OR k_ra8_lvd_cr0_mask_ri into CR0.
falseRI bit stays clear.
Precondition
None.
None.
Postcondition
No state mutated.
Return depends solely on the three inputs.
Note
Test-access only. Pure function.
MC/DC:
2-condition OR; N+1 = 3 vectors:
  • resp=interrupt -> false
  • resp=reset -> true (varies left)
  • resp=reset_on_rise-> true (varies right)
Since
0.1.0

Pure predicate for the CR0 "set RI bit" decision.

Promoted helper so the line-533 OR can be driven under MC/DC.

Parameters
[in]reset_valNumeric value of k_ra8_lvd_response_reset.
[in]reset_on_rise_valNumeric value of k_ra8_lvd_response_reset_on_rise.
[in]responseCandidate response value.
Returns
Boolean predicate.
Return values
trueCaller ORs RI bit into CR0.
falseRI bit stays clear.
Precondition
None.
None.
Postcondition
No state mutated.
Return depends solely on inputs.
Note
Pure; thread-safe.
Since
0.1.0

Definition at line 75 of file ra8_lvd.c.

Referenced by internal_compose_cr0().

◆ priv_ra8_lvd_internal_validate_div()

ra8_err_t priv_ra8_lvd_internal_validate_div ( ra8_lvd_loco_div_t div)

Validate FSAMP[1:0] candidate (0..3).

FSAMP[1:0] selects the LOCO sample-divider for the digital filter (HUM Ch 12.2.6 "PVDmCR1" p 599). All four encodings are valid. Shared across the ra8_lvd translation units.

Parameters
[in]divDivider candidate.
Returns
k_ra8_ok or k_ra8_err_invalid_arg.
Return values
k_ra8_okDivider within enum domain.
k_ra8_err_invalid_argDivider above the documented maximum.
Precondition
None.
Caller has not yet committed FSAMP to a register.
Postcondition
Hardware state unchanged.
Return value reflects the bounds check only.
Note
Pure helper; safe from any context. Driver-internal.
Since
0.1.0

Validate FSAMP[1:0] candidate (0..3).

Definition at line 194 of file ra8_lvd.c.

References k_ra8_err_invalid_arg, k_ra8_lvd_loco_div_max, and k_ra8_ok.

Referenced by internal_validate_cfg(), and ra8_lvd_set_filter().

Variable Documentation

◆ g_lvd_map

Lookup table from ra8_lvd_map_idx_t to register offsets.

Single definition for the whole ra8_lvd driver. The descriptor type, its index enum, and the matching extern declaration live in ra8_lvd_internal.h so the runtime / events translation units can read the same table.

Note
PRIVATE to the ra8_lvd driver TUs.
Warning
Read-only; do not mutate.
Since
0.1.0

Defined once in ra8_lvd.c; declared here so the runtime / events translation units can read the same descriptor table.

Note
PRIVATE to the ra8_lvd driver TUs.
Warning
Read-only; do not mutate.
Since
0.1.0

Definition at line 108 of file ra8_lvd.c.

Referenced by ra8_lvd_attach_channel_handler(), ra8_lvd_cancel_deep_standby_path(), ra8_lvd_channel_deinit(), ra8_lvd_channel_init(), ra8_lvd_clear_status(), ra8_lvd_configure_for_standby(), ra8_lvd_disable_cmpe(), ra8_lvd_disable_elc_event(), ra8_lvd_disable_irq(), ra8_lvd_disable_reset(), ra8_lvd_dispatch(), ra8_lvd_enable_cmpe(), ra8_lvd_enable_elc_event(), ra8_lvd_enable_irq(), ra8_lvd_enable_reset(), ra8_lvd_get_status(), ra8_lvd_set_filter(), ra8_lvd_set_hysteresis_mode(), ra8_lvd_set_irq_edge(), ra8_lvd_set_irq_kind(), ra8_lvd_set_negate_mode(), and ra8_lvd_set_threshold().