Brown-Out Detection and Blackout Monitoring#
Introduction#
Brown-Out Detector (BOD) is a hardware module designed to monitor the supply voltage of the system. It ensures that the system operates within safe voltage levels by detecting voltage drops below a defined threshold. When a brown-out condition is detected, the BOD can trigger an interrupt or reset the system to prevent malfunction.
Blackout Monitoring is a feature that enables the BOD to reset the system during Active/Sleep mode when the supply voltage drops less then ~1.65v to VMCU.
Common use cases for BOD include:
Voltage Monitoring: Ensuring the supply voltage remains within safe operating limits.
System Reset: Resetting the system during unsafe voltage (voltage drops less then ~1.65v to VMCU) conditions to prevent damage or malfunction.
Interrupt Generation: Notifying the system of voltage drops via interrupts.
Configuration#
The BOD module offers several configurable parameters, such as:
Threshold Voltage: Specifies the voltage level at which the BOD will trigger an interrupt or system reset.
Slot Value: Specifies the number of inactive (empty) slots inserted between two active comparator sampling slots. Each empty slot corresponds to 6 cycles of the 32KHz (ulp_fsm_clk), determining the interval between consecutive active sampling events. Configuring the slot value allows you to adjust the timing and frequency of BOD checks, which can help balance synchronization requirements and power consumption. Each slot defines a time interval based on 6 cycles of the 32KHz (ulp_fsm_clk).
Slots are used to control the timing between active operations, supporting proper synchronization and improved power efficiency.
For example, if cmp_slot_value is programmed as 2, there will be 2 empty slots between active slots, each consisting of 6 cycles.
Blackout Enable: Enabling or disabling blackout reset functionality.
These configurations are encapsulated in the sl_bod_uc_param_t structure and initialized using the respective BOD APIs.
For more details on configuration parameters, see the respective peripheral example readme document.
Usage#
After defining the BOD configuration structures and passing an instance of sl_bod_uc_param_t, the following functions can be used to initiate and configure the BOD module. The typical flow for implementation is as follows:
Initialize the BOD module: sl_si91x_bod_init
Register a callback for BOD interrupts: sl_si91x_bod_register_callback
Set the voltage threshold: sl_si91x_bod_set_threshold
Set the BOD configuration parameters sl_si91x_bod_set_configuration.
Get the calibrated threshold value sl_si91x_bod_get_threshold (Optional)
Enable BOD interrupt: sl_si91x_bod_enable_interrupt
Monitor battery status: sl_si91x_bod_get_battery_status
Clear BOD interrupt: sl_si91x_bod_clear_interrupt
Deinitialize the BOD module: sl_si91x_bod_deinit
APIs#
The following APIs are available for configuring and using the BOD module:
Initialization and Deinitialization:
Configuration:
Interrupt Handling:
Battery Monitoring:
Blackout Reset:
Button Configuration:
Example#
Below is an example of how to configure and use the BOD module:
#include "sl_si91x_bod.h"
void bod_callback(void) {
// Handle BOD interrupt
}
int main(void) {
sl_status_t status;
sl_bod_uc_param_t bod_config = {
.slot_value = 2,
.blackout_en = SL_ENABLE,
};
// Initialize the BOD module
status = sl_si91x_bod_init();
if (status != SL_STATUS_OK) {
// Handle initialization error
}
// Configure the slot value
status = sl_si91x_bod_config_slot_value(2);
if (status != SL_STATUS_OK) {
// Handle slot value configuration error
}
// Set the voltage threshold
status = sl_si91x_bod_set_threshold(2.5f);
if (status != SL_STATUS_OK) {
// Handle threshold setting error
}
// Register a callback for BOD interrupts
status = sl_si91x_bod_register_callback(bod_callback);
if (status != SL_STATUS_OK) {
// Handle callback registration error
}
// Enable BOD interrupt
sl_si91x_bod_enable_interrupt();
while (1) {
// Main loop
}
return 0;
}
Notes#
Ensure that the BOD module is properly initialized before using any other BOD APIs.
The voltage threshold must be within the range defined by SL_BOD_MIN_THRESHOLD and SL_BOD_MAX_THRESHOLD.
Use the blackout reset functionality to protect the system from unexpected power failures.
Modules#
Typedefs#
BOD callback function type.
Button callback function type.
Button enable type.
Functions#
Set the BOD mode.
Configure the slot value for BOD.
Initialize the BOD module.
Deinitialize the BOD module.
Get the BOD threshold value.
Enable the BOD interrupt in the NVIC.
sl_si91x_bod_get_blackout_status
Set the BOD configuration.
Configures the BOD (Brown-Out Detector) button values.
Enable or disable button wakeup functionality for the BOD (Brown-Out Detector).
Register a callback function for BOD interrupts.
Register a callback function for BOD button interrupts.
Unregister the callback function for BOD interrupts.
Handle BOD interrupts.
Get the current battery status.
Set the BOD voltage threshold.
Enable BOD interrupt.
Disable BOD interrupt.
Clear BOD interrupt.
Calculate the battery percentage based on the given voltage.
Controls the Black Out Detector (BOD) reset functionality.
Clears the BOD (Brown-Out Detector) button interrupt.
Enable the blackout reset in sleep mode.
Disable the blackout reset in sleep mode.
Macros#
BOD interrupt handler.
Define the SL_BGSAMPLE register address.
Define BOD clock division factor and ULP processor clock selection.
Define ULP processor clock selection.
NPSS GPIO 2 analog mode.
NPSS GPIO 2 analog mode value.
Enable signal for bod detection.
SCDC in LP mode Bit.
Zero Value define.
Button range value clear mask.
Manual mode selection.
Automatic mode selection.
Enable flag.
Disable flag.
Minimum BOD threshold value.
Maximum BOD threshold value.
NVIC BOD interrupt number.
Automatic BOD mode.
Maximum mode value.
Threshold offset value.
Threshold roundup value.
Manual comparator multiplexer selection button clear mask.
Manual comparator multiplexer selection button value.
BOD test selection bits clear mask.
Maximum battery status value.
BOD VBATT computation first element.
BOD VBATT computation second element.
BOD VBATT computation third element.
Slot maximum value.
Slot minimum value.
BOD clear battery status bits in EFUSE mask.
Maximum battery voltage for Brown-Out Detector (BOD)
Minimum battery voltage for Brown-Out Detector (BOD)
BOD NVIC button interrupt.
BOD NPSS to MCU button interrupt handler.
BOD comparator multiplexer selection enable value.
Status code indicating that the BOD is not enabled.
Status code indicating a failure in configuring the BOD threshold.
Status code indicating a failure in configuring the BOD slot value.
Status code indicating a failure in configuring the BOD button.
Typedef Documentation#
bod_button_callback_t
typedef void(* bod_button_callback_t) (uint8_t button) )(uint8_t button)
Button callback function type.
sl_button_en_t
typedef uint8_t sl_button_en_t
Button enable type.
Function Documentation#
sl_si91x_bod_set_mode#
sl_status_t sl_si91x_bod_set_mode (uint8_t mode)
Set the BOD mode.
Type | Direction | Argument Name | Description |
---|---|---|---|
uint8_t | [in] | mode | The mode to set (manual or automatic). |
Pre-conditions:
The BOD module must be initialized using sl_si91x_bod_init().
Returns
Status of the operation.
SL_STATUS_OK if the operation was successful.
For more information on status codes, see SL STATUS DOCUMENTATION.
Note
The mode can be set to either
SL_BOD_MANUAL_MODE
orSL_BOD_AUTOMATIC_MODE
.SL_BOD_MANUAL_MODE
allows manual control of the BOD settings.SL_BOD_AUTOMATIC_MODE
enables automatic BOD operation based on predefined settings.
sl_si91x_bod_config_slot_value#
sl_status_t sl_si91x_bod_config_slot_value (uint16_t slot_value)
Configure the slot value for BOD.
Type | Direction | Argument Name | Description |
---|---|---|---|
uint16_t | [in] | slot_value | The slot value to set, which must be in the range 2 to 65535. |
Pre-conditions:
The BOD module must be initialized using sl_si91x_bod_init().
The BOD mode must be set using sl_si91x_bod_set_mode() As
SL_BOD_MODE_AUTOMATIC
.
Returns
Status of the operation.
SL_STATUS_OK if the operation was successful.
For more information on status codes, see SL STATUS DOCUMENTATION.
sl_si91x_bod_init#
sl_status_t sl_si91x_bod_init (void )
Initialize the BOD module.
Type | Direction | Argument Name | Description |
---|---|---|---|
void | N/A |
This function initializes the BOD module with the specified battery voltage threshold.
Returns
Status of the BOD initialization operation.
SL_STATUS_OK if the initialization was successful.
SL_STATUS_FAIL if the initialization failed.
For more information on status codes, see SL STATUS DOCUMENTATION.
sl_si91x_bod_deinit#
sl_status_t sl_si91x_bod_deinit (void )
Deinitialize the BOD module.
Type | Direction | Argument Name | Description |
---|---|---|---|
void | N/A |
This function deinitializes the BOD module.
Pre-conditions:
The BOD module must be initialized using sl_si91x_bod_init().
Returns
Status of the BOD deinitialization operation.
SL_STATUS_OK if the deinitialization was successful.
For more information on status codes, see SL STATUS DOCUMENTATION.
sl_si91x_bod_get_threshold#
sl_status_t sl_si91x_bod_get_threshold (float * vbatt_threshold)
Get the BOD threshold value.
Type | Direction | Argument Name | Description |
---|---|---|---|
float * | [out] | vbatt_threshold | to store the current threshold value |
This function retrieves the current threshold value set for the BOD.
Pre-conditions:
The BOD module must be initialized using sl_si91x_bod_init().
Returns
Status of the BOD configuration operation.
SL_STATUS_OK if the configuration was successful.
For more information on status codes, see SL STATUS DOCUMENTATION.
sl_si91x_bod_NVIC_enable_irq#
void sl_si91x_bod_NVIC_enable_irq (void )
Enable the BOD interrupt in the NVIC.
Type | Direction | Argument Name | Description |
---|---|---|---|
void | N/A |
This function enables the interrupt for the BOD in the NVIC, allowing the system to handle BOD-related interrupts.
sl_si91x_bod_get_blackout_status#
en_t sl_si91x_bod_get_blackout_status (void )
sl_si91x_bod_get_blackout_status
Type | Direction | Argument Name | Description |
---|---|---|---|
void | N/A |
This function is used to get the blackout status.
Returns
Returns the blackout enable status.
sl_si91x_bod_set_configuration#
sl_status_t sl_si91x_bod_set_configuration (sl_bod_uc_param_t usr_config_params)
Set the BOD configuration.
Type | Direction | Argument Name | Description |
---|---|---|---|
sl_bod_uc_param_t | [in] | usr_config_params | The BOD configuration parameters. |
Pre-conditions:
The BOD module must be initialized using sl_si91x_bod_init().
Returns
Status of the BOD configuration operation.
SL_STATUS_OK if the configuration was successful.
For more information on status codes, see SL STATUS DOCUMENTATION.
sl_si91x_bod_button_configuration
void sl_si91x_bod_button_configuration (uint16_t button_max_value, uint16_t button1_min_value, uint16_t button2_min_value, uint16_t button3_min_value)
Configures the BOD (Brown-Out Detector) button values.
Type | Direction | Argument Name | Description |
---|---|---|---|
uint16_t | [in] | button_max_value | The maximum value for the button. |
uint16_t | [in] | button1_min_value | The minimum value for button 1. |
uint16_t | [in] | button2_min_value | The minimum value for button 2. |
uint16_t | [in] | button3_min_value | The minimum value for button 3. |
Pre-conditions:
The BOD module must be initialized using sl_si91x_bod_init() and
The BOD button must be initialized using sl_si91x_bod_button_wakeup_enable().
This function sets the maximum value for the button and the minimum values for three different buttons.
sl_si91x_bod_button_wakeup_enable
void sl_si91x_bod_button_wakeup_enable (uint8_t enable)
Enable or disable button wakeup functionality for the BOD (Brown-Out Detector).
Type | Direction | Argument Name | Description |
---|---|---|---|
uint8_t | [in] | enable |
|
This function allows the user to enable or disable the button wakeup feature for the BOD. When enabled, the system can wake up from a low-power state using a button press.
Pre-conditions:
The BOD module must be initialized using sl_si91x_bod_init() and
The BOD button must be initialized using sl_si91x_bod_button_wakeup_enable().
sl_si91x_bod_register_callback#
sl_status_t sl_si91x_bod_register_callback (bod_callback_t callback)
Register a callback function for BOD interrupts.
Type | Direction | Argument Name | Description |
---|---|---|---|
bod_callback_t | [in] | callback | The callback function to register. |
This function registers a callback function to be called when a BOD interrupt occurs.
Pre-conditions:
The BOD module must be initialized using sl_si91x_bod_init().
Returns
Status of the callback registration operation.
SL_STATUS_OK if the operation was successful.
For more information on status codes, see SL STATUS DOCUMENTATION.
sl_si91x_bod_button_register_callback
sl_status_t sl_si91x_bod_button_register_callback (bod_button_callback_t callback)
Register a callback function for BOD button interrupts.
Type | Direction | Argument Name | Description |
---|---|---|---|
bod_button_callback_t | [in] | callback | The callback function to register. |
This function registers a callback function to be called when a BOD button interrupt occurs.
Pre-conditions:
The BOD module must be initialized using .and
The BOD button must be initialized using sl_si91x_bod_button_wakeup_enable().
Returns
Status of the callback registration operation.
SL_STATUS_OK if the operation was successful.
For more information on status codes, see SL STATUS DOCUMENTATION.
sl_si91x_bod_unregister_callback#
void sl_si91x_bod_unregister_callback (void )
Unregister the callback function for BOD interrupts.
Type | Direction | Argument Name | Description |
---|---|---|---|
void | N/A |
Pre-conditions:
The BOD module must be initialized using sl_si91x_bod_init().
BOD callback must be registered using sl_si91x_bod_register_callback().
This function unregisters the callback function for BOD interrupts.
sl_si91x_bod_interrupt_handler#
void sl_si91x_bod_interrupt_handler (void )
Handle BOD interrupts.
Type | Direction | Argument Name | Description |
---|---|---|---|
void | N/A |
This function handles BOD interrupts.
sl_si91x_bod_get_battery_status#
sl_status_t sl_si91x_bod_get_battery_status (float * battery_status)
Get the current battery status.
Type | Direction | Argument Name | Description |
---|---|---|---|
float * | [out] | battery_status | Pointer to store the battery status. |
This function retrieves the current battery status.
Pre-conditions:
The BOD module must be initialized using sl_si91x_bod_init().
Returns
Status of the battery status retrieval operation.
SL_STATUS_OK if the operation was successful.
SL_STATUS_INVALID_PARAMETER if the battery_status pointer is NULL.
For more information on status codes, see SL STATUS DOCUMEN TATION.
sl_si91x_bod_set_threshold#
sl_status_t sl_si91x_bod_set_threshold (float threshold)
Set the BOD voltage threshold.
Type | Direction | Argument Name | Description |
---|---|---|---|
float | [in] | threshold | The BOD voltage threshold to set. |
This function sets the BOD voltage threshold to the specified value.
Pre-conditions:
The BOD module must be initialized using sl_si91x_bod_init().
Returns
Status of the BOD threshold setting operation.
SL_STATUS_OK if the setting was successful.
SL_STATUS_INVALID_PARAMETER if the threshold is out of range.
For more information on status codes, see SL STATUS DOCUMENTATION.
sl_si91x_bod_enable_interrupt#
void sl_si91x_bod_enable_interrupt (void )
Enable BOD interrupt.
Type | Direction | Argument Name | Description |
---|---|---|---|
void | N/A |
This function enables the BOD interrupt for detecting voltage drops below the threshold.
Pre-conditions:
The BOD module must be initialized using sl_si91x_bod_init().
sl_si91x_bod_disable_interrupt#
void sl_si91x_bod_disable_interrupt (void )
Disable BOD interrupt.
Type | Direction | Argument Name | Description |
---|---|---|---|
void | N/A |
This function disables the BOD interrupt.
Pre-conditions:
The BOD module must be initialized using sl_si91x_bod_init().
BOD interrupt must be enabled using sl_si91x_bod_enable_interrupt().
sl_si91x_bod_clear_interrupt#
void sl_si91x_bod_clear_interrupt (void )
Clear BOD interrupt.
Type | Direction | Argument Name | Description |
---|---|---|---|
void | N/A |
This function clears the BOD interrupt flag.
sl_si91x_bod_battery_percentage#
sl_status_t sl_si91x_bod_battery_percentage (float voltage, float * vbat_per)
Calculate the battery percentage based on the given voltage.
Type | Direction | Argument Name | Description |
---|---|---|---|
float | [in] | voltage | The input voltage value to be converted to battery percentage. |
float * | [out] | vbat_per | Pointer to a float where the calculated battery percentage will be stored. |
This function takes a voltage value and calculates the corresponding battery percentage, storing the result in the provided pointer.
Pre-conditions:
BOD battery status must be read using sl_si91x_bod_get_battery_status()
Returns
sl_status_t Returns the status of the operation.
SL_STATUS_OK if the operation was successful.
SL_STATUS_INVALID_PARAMETER if the input voltage is out of range.
sl_si91x_bod_black_out_reset#
void sl_si91x_bod_black_out_reset (en_t enable)
Controls the Black Out Detector (BOD) reset functionality.
Type | Direction | Argument Name | Description |
---|---|---|---|
en_t | N/A | enable | A value of type en_t that specifies whether to enable or disable the BOD reset.
|
This function enables or disables the Black Out Detector (BOD) reset. The BOD reset is used to reset the system when the supply voltage drops below a certain threshold, ensuring the system does not operate under unsafe conditions.
sl_si91x_bod_button_interrupt_clear
void sl_si91x_bod_button_interrupt_clear (void )
Clears the BOD (Brown-Out Detector) button interrupt.
Type | Direction | Argument Name | Description |
---|---|---|---|
void | N/A |
This function is used to clear the interrupt triggered by the BOD button. It ensures that the interrupt flag is reset, allowing for subsequent interrupts to be detected and handled appropriately.
sl_si91x_bod_enable_blackout_in_sleep_mode#
void sl_si91x_bod_enable_blackout_in_sleep_mode (void )
Enable the blackout reset in sleep mode.
Type | Direction | Argument Name | Description |
---|---|---|---|
void | N/A |
This API is used to enable the blackout reset functionality when the device is in sleep mode. Blackout reset helps in protecting the device from unexpected power failures by resetting the device.
sl_si91x_bod_disable_blackout_in_sleep_mode#
void sl_si91x_bod_disable_blackout_in_sleep_mode (void )
Disable the blackout reset in sleep mode.
Type | Direction | Argument Name | Description |
---|---|---|---|
void | N/A |
This API is used to disable the blackout reset functionality when the device is in sleep mode. Blackout reset helps in protecting the device from unexpected power failures by resetting the device.