CMSIS-Driver_PIC32CZ-CA70  
Peripheral Library (PLIB) Documentation
 
Loading...
Searching...
No Matches
SUPC Interface

Driver API for SUPC (plib_supc.h) More...

Content

 Supply Monitor Threshold Levels
 Threshold voltage levels for supply monitor detection.
 

Macros

#define SUPC_WAKE_SOURCES_Msk
 Mask of wake-from-Backup source bits in SUPC_WUMR.
 

Typedefs

typedef void(* SUPC_CALLBACK_HANDLER) (uint32_t status)
 SUPC event notification handler type.
 

Functions

void SUPC_Configure (void)
 Configures the Supply Controller (SUPC) to safe defaults.
 
void SUPC_EnterBackupMode (void)
 Enters Backup mode (lowest power state).
 
void SUPC_SelectCrystalOscillator (void)
 Selects the 32.768 kHz crystal as the SLOW_CLK source.
 
void SUPC_EnableOscillatorBypass (void)
 Enables crystal oscillator bypass (SUPC_MR.OSCBYPASS = 1).
 
void SUPC_DisableOscillatorBypass (void)
 Disables crystal oscillator bypass (SUPC_MR.OSCBYPASS = 0).
 
void SUPC_EnableSupplyMonitor (uint32_t threshold, uint32_t sampling)
 Enables the supply monitor with threshold and sampling period.
 
void SUPC_DisableSupplyMonitor (void)
 Disables the supply monitor (clears SMSMPL, SMIEN, SMRSTEN).
 
void SUPC_EnableSupplyMonitorReset (void)
 Arms core reset on supply-monitor detection (SMRSTEN = 1).
 
void SUPC_DisableSupplyMonitorReset (void)
 Disarms core reset on supply-monitor detection (SMRSTEN = 0).
 
void SUPC_EnableSupplyMonitorInterrupt (void)
 Arms SUPC interrupt on supply-monitor detection (SMIEN = 1).
 
void SUPC_DisableSupplyMonitorInterrupt (void)
 Disarms SUPC interrupt on supply-monitor detection (SMIEN = 0).
 
bool SUPC_SupplyMonitorOutputIsActive (void)
 Checks if the supply-monitor output is currently asserted.
 
void SUPC_EnableBrownoutDetector (void)
 Enables the Brownout Detector (clears SUPC_MR.BODDIS).
 
void SUPC_DisableBrownoutDetector (void)
 Disables the Brownout Detector (sets SUPC_MR.BODDIS).
 
void SUPC_EnableBrownoutDetectorReset (void)
 Arms core reset on brownout event (SUPC_MR.BODRSTEN = 1).
 
void SUPC_DisableBrownoutDetectorReset (void)
 Disarms core reset on brownout event (SUPC_MR.BODRSTEN = 0).
 
void SUPC_EnableVoltageRegulator (void)
 Selects the internal voltage regulator (SUPC_MR.ONREG = 1).
 
void SUPC_DisableVoltageRegulator (void)
 Disables the internal voltage regulator (SUPC_MR.ONREG = 0).
 
void SUPC_EnableBackupSRAMRetention (void)
 Retains backup SRAM in Backup mode (SUPC_MR.BKUPRETON = 1).
 
void SUPC_DisableBackupSRAMRetention (void)
 Drops backup SRAM in Backup mode (SUPC_MR.BKUPRETON = 0).
 
void SUPC_EnableWakeupSource (uint32_t source_mask)
 Enables wake-from-Backup sources in SUPC_WUMR.
 
void SUPC_DisableWakeupSource (uint32_t source_mask)
 Disables wake-from-Backup sources in SUPC_WUMR.
 
void SUPC_SetWakeupDebouncePeriod (uint32_t period)
 Sets the shared WKUPx debounce period (SUPC_WUMR.WKUPDBC).
 
void SUPC_EnableWakeupPin (uint32_t pin, uint32_t polarity)
 Enables a wake-up pin as a wake source.
 
void SUPC_DisableWakeupPin (uint32_t pin)
 Disables a wake-up pin (polarity bit is left unchanged).
 
void SUPC_EnableTamper (uint32_t pin_mask, uint32_t period, uint32_t polarity0, uint32_t polarity1)
 Configures WKUP0 and/or WKUP1 as low-power tamper inputs.
 
void SUPC_DisableTamper (void)
 Disables low-power tamper detection.
 
void SUPC_EnableTamperGPBRClear (void)
 Enables auto-erase of GPBR0..GPBR3 on tamper (LPDBCCLR = 1).
 
void SUPC_DisableTamperGPBRClear (void)
 Disables auto-erase of GPBR0..GPBR3 on tamper (LPDBCCLR = 0).
 
uint32_t SUPC_GetStatus (void)
 Reads the full SUPC_SR register.
 
bool SUPC_SlowClockIsCrystal (void)
 Checks if SLOW_CLK is sourced from the 32.768 kHz crystal.
 
uint32_t SUPC_GetWakeupInputStatus (void)
 Reads SUPC_SR.WKUPIS[13:0] right-shifted to bits [13:0].
 
uint32_t SUPC_ReadGPBR (uint32_t reg)
 Reads a General-Purpose Backup Register.
 
void SUPC_WriteGPBR (uint32_t reg, uint32_t data)
 Writes a General-Purpose Backup Register.
 
void SUPC_EnableWriteProtection (void)
 Locks SUPC/RTC/RTT/GPBR registers (SYSC_WPMR.WPEN = 1).
 
void SUPC_DisableWriteProtection (void)
 Unlocks SUPC/RTC/RTT/GPBR registers (SYSC_WPMR.WPEN = 0).
 
void SUPC_SetCallbackHandler (SUPC_CALLBACK_HANDLER callback)
 Registers a callback function for the supply-monitor interrupt.
 

Description

Driver API for SUPC (plib_supc.h)

Usage Example

The following example demonstrates typical usage of the SUPC peripheral:

/*******************************************************************************
* @file config_supc.c
* @brief SUPC Supply Monitor Configuration
*
* Configures SUPC for supply monitoring on VDDIO.
*
* Configuration:
* - Supply monitor threshold: ~2.56V
* - Sampling period: 256-SLCK cycles (~7.8ms)
* - Interrupt enabled on supply monitor event
* - Callback: on_supply_monitor_event() in app_plib.c
******************************************************************************/
#include "plib_supc.h"
#include <pic32c.h>
#include <stdint.h>
static void supc_status_callback(uint32_t status);
int32_t configure_supc(void)
{
/* Unlock SUPC registers for configuration. */
/* Configure SUPC with baseline defaults. */
/* Configure supply monitor: 2.56V threshold, 256-SLCK sampling. */
SUPC_SMMR_SMSMPL_256SLCK_Val);
/* Register callback handler and enable supply monitor interrupt. */
SUPC_SetCallbackHandler(&supc_status_callback);
return 0;
}
static void supc_status_callback(uint32_t status)
{
if ((status & SUPC_SR_SMS_Msk) != 0UL)
{
/*print message, LED Blink*/
}
}
#define SUPC_SM_THRESHOLD_3V40
Supply monitor threshold ~3.40 V.
Definition plib_supc.h:96
void SUPC_EnableSupplyMonitor(uint32_t threshold, uint32_t sampling)
Enables the supply monitor with threshold and sampling period.
void SUPC_EnableSupplyMonitorReset(void)
Arms core reset on supply-monitor detection (SMRSTEN = 1).
void SUPC_DisableWriteProtection(void)
Unlocks SUPC/RTC/RTT/GPBR registers (SYSC_WPMR.WPEN = 0).
void SUPC_EnableSupplyMonitorInterrupt(void)
Arms SUPC interrupt on supply-monitor detection (SMIEN = 1).
void SUPC_SetCallbackHandler(SUPC_CALLBACK_HANDLER callback)
Registers a callback function for the supply-monitor interrupt.
void SUPC_Configure(void)
Configures the Supply Controller (SUPC) to safe defaults.
SUPC PLIB interface.

Macro Definition Documentation

◆ SUPC_WAKE_SOURCES_Msk

#define SUPC_WAKE_SOURCES_Msk
Value:
(SUPC_WUMR_SMEN_Msk \
| SUPC_WUMR_RTTEN_Msk \
| SUPC_WUMR_RTCEN_Msk)

Mask of wake-from-Backup source bits in SUPC_WUMR.

Combines Supply Monitor Enable (SMEN), Real-Time Timer Enable (RTTEN), and Real-Time Clock Enable (RTCEN) mask bits.

Typedef Documentation

◆ SUPC_CALLBACK_HANDLER

typedef void(* SUPC_CALLBACK_HANDLER) (uint32_t status)

SUPC event notification handler type.

Parameters
statusSnapshot of the SUPC Status Register (SUPC_SR).

Function Documentation

◆ SUPC_Configure()

void SUPC_Configure ( void )

Configures the Supply Controller (SUPC) to safe defaults.

Returns
None.

◆ SUPC_DisableBackupSRAMRetention()

void SUPC_DisableBackupSRAMRetention ( void )

Drops backup SRAM in Backup mode (SUPC_MR.BKUPRETON = 0).

Returns
None.

◆ SUPC_DisableBrownoutDetector()

void SUPC_DisableBrownoutDetector ( void )

Disables the Brownout Detector (sets SUPC_MR.BODDIS).

Returns
None.

◆ SUPC_DisableBrownoutDetectorReset()

void SUPC_DisableBrownoutDetectorReset ( void )

Disarms core reset on brownout event (SUPC_MR.BODRSTEN = 0).

Returns
None.

◆ SUPC_DisableOscillatorBypass()

void SUPC_DisableOscillatorBypass ( void )

Disables crystal oscillator bypass (SUPC_MR.OSCBYPASS = 0).

Returns
None.

◆ SUPC_DisableSupplyMonitor()

void SUPC_DisableSupplyMonitor ( void )

Disables the supply monitor (clears SMSMPL, SMIEN, SMRSTEN).

Returns
None.

◆ SUPC_DisableSupplyMonitorInterrupt()

void SUPC_DisableSupplyMonitorInterrupt ( void )

Disarms SUPC interrupt on supply-monitor detection (SMIEN = 0).

Returns
None.

◆ SUPC_DisableSupplyMonitorReset()

void SUPC_DisableSupplyMonitorReset ( void )

Disarms core reset on supply-monitor detection (SMRSTEN = 0).

Returns
None.

◆ SUPC_DisableTamper()

void SUPC_DisableTamper ( void )

Disables low-power tamper detection.

Clears LPDBCEN0, LPDBCEN1 and LPDBC. WKUPx pins are NOT re-enabled.

Returns
None.

◆ SUPC_DisableTamperGPBRClear()

void SUPC_DisableTamperGPBRClear ( void )

Disables auto-erase of GPBR0..GPBR3 on tamper (LPDBCCLR = 0).

Returns
None.

◆ SUPC_DisableVoltageRegulator()

void SUPC_DisableVoltageRegulator ( void )

Disables the internal voltage regulator (SUPC_MR.ONREG = 0).

VDDCORE must be supplied by an external LDO.

Returns
None.

◆ SUPC_DisableWakeupPin()

void SUPC_DisableWakeupPin ( uint32_t pin)

Disables a wake-up pin (polarity bit is left unchanged).

Parameters
pinWake-up pin index (0..13).
Returns
None.

◆ SUPC_DisableWakeupSource()

void SUPC_DisableWakeupSource ( uint32_t source_mask)

Disables wake-from-Backup sources in SUPC_WUMR.

Parameters
source_maskOR-combination of SUPC_WUMR_SMEN_Msk, SUPC_WUMR_RTTEN_Msk, SUPC_WUMR_RTCEN_Msk.
Returns
None.

◆ SUPC_DisableWriteProtection()

void SUPC_DisableWriteProtection ( void )

Unlocks SUPC/RTC/RTT/GPBR registers (SYSC_WPMR.WPEN = 0).

Returns
None.

◆ SUPC_EnableBackupSRAMRetention()

void SUPC_EnableBackupSRAMRetention ( void )

Retains backup SRAM in Backup mode (SUPC_MR.BKUPRETON = 1).

Returns
None.

◆ SUPC_EnableBrownoutDetector()

void SUPC_EnableBrownoutDetector ( void )

Enables the Brownout Detector (clears SUPC_MR.BODDIS).

Returns
None.

◆ SUPC_EnableBrownoutDetectorReset()

void SUPC_EnableBrownoutDetectorReset ( void )

Arms core reset on brownout event (SUPC_MR.BODRSTEN = 1).

Returns
None.

◆ SUPC_EnableOscillatorBypass()

void SUPC_EnableOscillatorBypass ( void )

Enables crystal oscillator bypass (SUPC_MR.OSCBYPASS = 1).

Must be called BEFORE SUPC_SelectCrystalOscillator(). Use when an external clock is provided on XIN32 instead of a crystal.

Returns
None.

◆ SUPC_EnableSupplyMonitor()

void SUPC_EnableSupplyMonitor ( uint32_t threshold,
uint32_t sampling )

Enables the supply monitor with threshold and sampling period.

Preserves the SMIEN and SMRSTEN configuration bits.

Parameters
thresholdthreshold levels SUPC_SM_THRESHOLD_* macros, e.g. SUPC_SM_THRESHOLD_1V60, SUPC_SM_THRESHOLD_2V80, SUPC_SM_THRESHOLD_3V40
samplingUnshifted SUPC_SMMR_SMSMPL_CSM_Val / _32SLCK_Val / _256SLCK_Val / _2048SLCK_Val.
Returns
None.

◆ SUPC_EnableSupplyMonitorInterrupt()

void SUPC_EnableSupplyMonitorInterrupt ( void )

Arms SUPC interrupt on supply-monitor detection (SMIEN = 1).

Returns
None.

◆ SUPC_EnableSupplyMonitorReset()

void SUPC_EnableSupplyMonitorReset ( void )

Arms core reset on supply-monitor detection (SMRSTEN = 1).

Returns
None.

◆ SUPC_EnableTamper()

void SUPC_EnableTamper ( uint32_t pin_mask,
uint32_t period,
uint32_t polarity0,
uint32_t polarity1 )

Configures WKUP0 and/or WKUP1 as low-power tamper inputs.

Mutual exclusion with WKUPENx is enforced internally.

Parameters
pin_maskBit 0 = WKUP0, bit 1 = WKUP1 (e.g. 0x03 enables both).
periodPre-shifted SUPC_WUMR_LPDBC_2_RTCOUT ? _8_RTCOUT.
polarity00 = LOW / 1 = HIGH for WKUP0 (ignored if not in mask).
polarity10 = LOW / 1 = HIGH for WKUP1 (ignored if not in mask).
Returns
None.

◆ SUPC_EnableTamperGPBRClear()

void SUPC_EnableTamperGPBRClear ( void )

Enables auto-erase of GPBR0..GPBR3 on tamper (LPDBCCLR = 1).

Returns
None.

◆ SUPC_EnableVoltageRegulator()

void SUPC_EnableVoltageRegulator ( void )

Selects the internal voltage regulator (SUPC_MR.ONREG = 1).

Returns
None.

◆ SUPC_EnableWakeupPin()

void SUPC_EnableWakeupPin ( uint32_t pin,
uint32_t polarity )

Enables a wake-up pin as a wake source.

Parameters
pinWake-up pin index (0..13).
polarity0 = active LOW (falling edge), 1 = active HIGH (rising).
Returns
None.

◆ SUPC_EnableWakeupSource()

void SUPC_EnableWakeupSource ( uint32_t source_mask)

Enables wake-from-Backup sources in SUPC_WUMR.

Bits outside the wake-source set are filtered out.

Parameters
source_maskOR-combination of SUPC_WUMR_SMEN_Msk, SUPC_WUMR_RTTEN_Msk, SUPC_WUMR_RTCEN_Msk.
Returns
None.

◆ SUPC_EnableWriteProtection()

void SUPC_EnableWriteProtection ( void )

Locks SUPC/RTC/RTT/GPBR registers (SYSC_WPMR.WPEN = 1).

Returns
None.

◆ SUPC_EnterBackupMode()

void SUPC_EnterBackupMode ( void )

Enters Backup mode (lowest power state).

Does NOT return ? wake exits via a full power-on reset.

Returns
None.

◆ SUPC_GetStatus()

uint32_t SUPC_GetStatus ( void )

Reads the full SUPC_SR register.

Reading clears all latched event flags as a side effect.

Returns
Raw 32-bit register value. Test bits with SUPC_SR_*_Msk macros.

◆ SUPC_GetWakeupInputStatus()

uint32_t SUPC_GetWakeupInputStatus ( void )

Reads SUPC_SR.WKUPIS[13:0] right-shifted to bits [13:0].

Reading SUPC_SR clears all latched flags as a side effect.

Returns
14-bit mask of WKUPx pins active when WKUPDBC fired.

◆ SUPC_ReadGPBR()

uint32_t SUPC_ReadGPBR ( uint32_t reg)

Reads a General-Purpose Backup Register.

Parameters
regIndex of the GPBR to read (0..7). Returns 0 if out of range.
Returns
32-bit content of GPBR[reg], or 0 if reg >= 8.

◆ SUPC_SelectCrystalOscillator()

void SUPC_SelectCrystalOscillator ( void )

Selects the 32.768 kHz crystal as the SLOW_CLK source.

Polls SUPC_SR.OSCSEL until the switch is confirmed. IRREVERSIBLE: requires VDDIO power cycle to revert.

Returns
None.

◆ SUPC_SetCallbackHandler()

void SUPC_SetCallbackHandler ( SUPC_CALLBACK_HANDLER callback)

Registers a callback function for the supply-monitor interrupt.

Call BEFORE arming the SM interrupt.

Parameters
callbackCallback function to register.
Returns
None.

◆ SUPC_SetWakeupDebouncePeriod()

void SUPC_SetWakeupDebouncePeriod ( uint32_t period)

Sets the shared WKUPx debounce period (SUPC_WUMR.WKUPDBC).

Parameters
periodPre-shifted SUPC_WUMR_WKUPDBC_IMMEDIATE / _3_SLCK / _32_SLCK / _512_SLCK / _4096_SLCK / _32768_SLCK.
Returns
None.

◆ SUPC_SlowClockIsCrystal()

bool SUPC_SlowClockIsCrystal ( void )

Checks if SLOW_CLK is sourced from the 32.768 kHz crystal.

Reads the live SUPC_SR.OSCSEL bit. Reading SUPC_SR clears all latched flags as a side effect.

Returns
true if SLOW_CLK is the 32.768 kHz crystal.
false if SLOW_CLK is the slow RC oscillator.

◆ SUPC_SupplyMonitorOutputIsActive()

bool SUPC_SupplyMonitorOutputIsActive ( void )

Checks if the supply-monitor output is currently asserted.

Reads the live SMOS bit from SUPC_SR. Reading SUPC_SR clears all latched event flags as a side effect.

Returns
true if VDDIO is currently below the programmed threshold.
false if VDDIO is currently above the programmed threshold.

◆ SUPC_WriteGPBR()

void SUPC_WriteGPBR ( uint32_t reg,
uint32_t data )

Writes a General-Purpose Backup Register.

Write protection (SYSC_WPMR.WPEN) must be disabled before calling. Write is silently ignored if reg >= 8.

Parameters
regIndex of the GPBR to write (0..7). Ignored if out of range.
data32-bit value to write.
Returns
None.