RA Flexible Software Package Documentation  Release v5.6.0

 
Low/Programmable Voltage Detection (r_lvd)

Functions

fsp_err_t R_LVD_Open (lvd_ctrl_t *const p_api_ctrl, lvd_cfg_t const *const p_cfg)
 
fsp_err_t R_LVD_StatusGet (lvd_ctrl_t *const p_api_ctrl, lvd_status_t *p_lvd_status)
 
fsp_err_t R_LVD_StatusClear (lvd_ctrl_t *const p_api_ctrl)
 
fsp_err_t R_LVD_CallbackSet (lvd_ctrl_t *const p_api_ctrl, void(*p_callback)(lvd_callback_args_t *), void const *const p_context, lvd_callback_args_t *const p_callback_memory)
 
fsp_err_t R_LVD_Close (lvd_ctrl_t *const p_api_ctrl)
 

Detailed Description

Driver for the LVD and PVD peripherals on RA MCUs. This module implements the Low Voltage Detection Interface.

Note
In the below usage notes, "LVD" refers to both LVD and PVD.

Overview

The Low Voltage Detection module configures the voltage monitors to detect when a power supply pin or a voltage detector pin voltages crosses a specified threshold.

Features

The LVD HAL module supports the following functions:

Configuration

Build Time Configurations for r_lvd

The following build time configurations are defined in fsp_cfg/r_lvd_cfg.h:

ConfigurationOptionsDefaultDescription
Parameter Checking
  • Default (BSP)
  • Enabled
  • Disabled
Default (BSP) If selected code for parameter checking is included in the build.

Configurations for Monitoring > Low/Programmable Voltage Detection (r_lvd)

This module can be added to the Stacks tab via New Stack > Monitoring > Low/Programmable Voltage Detection (r_lvd). Non-secure callable guard functions can be generated for this module by right clicking the module in the RA Configuration tool and checking the "Non-secure Callable" box.

ConfigurationOptionsDefaultDescription
NameName must be a valid C symbolg_lvd0 Module name.
Monitor NumberMCU Specific OptionsSelect the LVD monitor.
Digital FilterMCU Specific OptionsEnable the digital filter and select the digital filter clock divider.
Voltage ThresholdMCU Specific OptionsSelect the low voltage detection threshold.
Detection ResponseMCU Specific OptionsSelect what happens when the voltage crosses the threshold voltage.
Voltage SlopeMCU Specific OptionsSelect interrupt generation on rising voltage, falling voltage or both.
Negation DelayMCU Specific OptionsNegation of the monitor signal can either be delayed from the reset event or from voltage returning to normal range.
Monitor Interrupt CallbackName must be a valid C symbol.NULL A user callback function can be provided. If this callback function is provided, it will be called from the interrupt service routine (ISR) each time the IRQ triggers.
LVD Monitor Interrupt PriorityMCU Specific OptionsSelect the LVD Monitor interrupt priority.

Clock Configuration

The LOCO clock must be enabled in order to use the digital filter.

Pin Configuration

To use LVD module, you need to switch pin funtion of EXLVDVBAT pin, VRTC pin, EXLVD pin to enable LVD function on this pin.

Usage Notes

Startup Edge Detection

If VCC is below the threshold prior to configuring the voltage monitor for falling edge detection, the monitor will immediately detect the a falling edge condition. If VCC is above the threshold prior to configuring the monitor for rising edge detection, the monitor will not detect a rising edge condition until VCC falls below the threshold and then rises above it again.

Voltage Monitor 0

The LVD HAL module only supports configuring voltage monitor 1 and voltage monitor 2. Voltage monitor 0 can be configured by setting the appropriate bits in the OFS1 register. This means that voltage monitor 0 settings cannot be changed at runtime.

Voltage monitor 0 supports the following features

Limitations

Examples

Basic Example

This is a basic example of minimal use of the LVD in an application.

void basic_example (void)
{
fsp_err_t err = R_LVD_Open(&g_lvd_ctrl, &g_lvd_cfg);
assert(FSP_SUCCESS == err);
while (1)
{
lvd_status_t status;
err = R_LVD_StatusGet(&g_lvd_ctrl, &status);
assert(FSP_SUCCESS == err);
{
err = R_LVD_StatusClear(&g_lvd_ctrl);
assert(FSP_SUCCESS == err);
/* Do something */
}
}
}

Interrupt Example

This is a basic example of using a LVD instance that is configured to generate an interrupt.

void interrupt_example (void)
{
fsp_err_t err = R_LVD_Open(&g_lvd_ctrl, &g_lvd_cfg);
/* Handle any errors. This function should be defined by the user. */
assert(FSP_SUCCESS == err);
while (1)
{
/* Application Process */
/* Application will be interrupted when Vcc crosses the configured threshold. */
}
}
/* Called when Vcc crosses configured threshold. */
void lvd_callback (lvd_callback_args_t * p_args)
{
{
/* Do Something */
}
}

Reset Example

This is a basic example of using a LVD instance that is configured to reset the MCU.

void reset_example (void)
{
if (1U == R_SYSTEM->RSTSR0_b.LVD1RF)
{
/* The system is coming out of reset because Vcc crossed configured voltage threshold. */
/* Clear Voltage Monitor 1 Reset Detect Flag. */
R_SYSTEM->RSTSR0_b.LVD1RF = 0;
}
fsp_err_t err = R_LVD_Open(&g_lvd_ctrl, &g_lvd_cfg);
/* Handle any errors. This function should be defined by the user. */
assert(FSP_SUCCESS == err);
while (1)
{
/* Application Process */
/* Application will reset when Vcc crosses the configured threshold. */
}
}

Data Structures

struct  lvd_instance_ctrl_t
 

Data Structure Documentation

◆ lvd_instance_ctrl_t

struct lvd_instance_ctrl_t

LVD instance control structure

Function Documentation

◆ R_LVD_Open()

fsp_err_t R_LVD_Open ( lvd_ctrl_t *const  p_api_ctrl,
lvd_cfg_t const *const  p_cfg 
)

Initializes a voltage monitor and detector according to the passed-in configuration structure.

Parameters
[in]p_api_ctrlPointer to the control structure for the driver instance
[in]p_cfgPointer to the configuration structure for the driver instance
Note
Digital filter is not to be used with standby modes.
Startup time can take on the order of milliseconds for some configurations.

Example:

fsp_err_t err = R_LVD_Open(&g_lvd_ctrl, &g_lvd_cfg);
Return values
FSP_SUCCESSSuccessful
FSP_ERR_ASSERTIONRequested configuration was invalid
FSP_ERR_ALREADY_OPENThe instance was already opened
FSP_ERR_IN_USEAnother instance is already using the desired monitor
FSP_ERR_UNSUPPORTEDDigital filter was enabled on a device that does not support it

◆ R_LVD_StatusGet()

fsp_err_t R_LVD_StatusGet ( lvd_ctrl_t *const  p_api_ctrl,
lvd_status_t p_lvd_status 
)

Get the current state of the monitor (threshold crossing detected, voltage currently above or below threshold).

Parameters
[in]p_api_ctrlPointer to the control structure for the driver instance
[out]p_lvd_statusPointer to status structure

Example:

err = R_LVD_StatusGet(&g_lvd_ctrl, &status);
Return values
FSP_SUCCESSSuccessful
FSP_ERR_ASSERTIONAn argument was NULL
FSP_ERR_NOT_OPENDriver is not open

◆ R_LVD_StatusClear()

fsp_err_t R_LVD_StatusClear ( lvd_ctrl_t *const  p_api_ctrl)

Clears the latched status of the monitor.

Parameters
[in]p_api_ctrlPointer to the control structure for the driver instance
Return values
FSP_SUCCESSSuccessful
FSP_ERR_ASSERTIONAn argument was NULL
FSP_ERR_NOT_OPENDriver is not open

◆ R_LVD_CallbackSet()

fsp_err_t R_LVD_CallbackSet ( lvd_ctrl_t *const  p_api_ctrl,
void(*)(lvd_callback_args_t *)  p_callback,
void const *const  p_context,
lvd_callback_args_t *const  p_callback_memory 
)

Updates the user callback and has option of providing memory for callback structure. Implements lvd_api_t::callbackSet

Return values
FSP_SUCCESSCallback updated successfully.
FSP_ERR_ASSERTIONA required pointer is NULL.
FSP_ERR_NOT_OPENThe control block has not been opened.
FSP_ERR_NO_CALLBACK_MEMORYp_callback is non-secure and p_callback_memory is either secure or NULL.

◆ R_LVD_Close()

fsp_err_t R_LVD_Close ( lvd_ctrl_t *const  p_api_ctrl)

Disables the LVD peripheral. Closes the driver instance.

Parameters
[in]p_api_ctrlPointer to the control block structure for the driver instance
Return values
FSP_SUCCESSSuccessful
FSP_ERR_ASSERTIONAn argument was NULL
FSP_ERR_NOT_OPENDriver is not open