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. | |
Driver API for SUPC (plib_supc.h)
The following example demonstrates typical usage of the SUPC peripheral:
| #define SUPC_WAKE_SOURCES_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 void(* SUPC_CALLBACK_HANDLER) (uint32_t status) |
SUPC event notification handler type.
| status | Snapshot of the SUPC Status Register (SUPC_SR). |
| void SUPC_Configure | ( | void | ) |
Configures the Supply Controller (SUPC) to safe defaults.
| void SUPC_DisableBackupSRAMRetention | ( | void | ) |
Drops backup SRAM in Backup mode (SUPC_MR.BKUPRETON = 0).
| void SUPC_DisableBrownoutDetector | ( | void | ) |
Disables the Brownout Detector (sets SUPC_MR.BODDIS).
| void SUPC_DisableBrownoutDetectorReset | ( | void | ) |
Disarms core reset on brownout event (SUPC_MR.BODRSTEN = 0).
| void SUPC_DisableOscillatorBypass | ( | void | ) |
Disables crystal oscillator bypass (SUPC_MR.OSCBYPASS = 0).
| void SUPC_DisableSupplyMonitor | ( | void | ) |
Disables the supply monitor (clears SMSMPL, SMIEN, SMRSTEN).
| void SUPC_DisableSupplyMonitorInterrupt | ( | void | ) |
Disarms SUPC interrupt on supply-monitor detection (SMIEN = 0).
| void SUPC_DisableSupplyMonitorReset | ( | void | ) |
Disarms core reset on supply-monitor detection (SMRSTEN = 0).
| void SUPC_DisableTamper | ( | void | ) |
Disables low-power tamper detection.
Clears LPDBCEN0, LPDBCEN1 and LPDBC. WKUPx pins are NOT re-enabled.
| void SUPC_DisableTamperGPBRClear | ( | void | ) |
Disables auto-erase of GPBR0..GPBR3 on tamper (LPDBCCLR = 0).
| void SUPC_DisableVoltageRegulator | ( | void | ) |
Disables the internal voltage regulator (SUPC_MR.ONREG = 0).
VDDCORE must be supplied by an external LDO.
| void SUPC_DisableWakeupPin | ( | uint32_t | pin | ) |
Disables a wake-up pin (polarity bit is left unchanged).
| pin | Wake-up pin index (0..13). |
| void SUPC_DisableWakeupSource | ( | uint32_t | source_mask | ) |
Disables wake-from-Backup sources in SUPC_WUMR.
| source_mask | OR-combination of SUPC_WUMR_SMEN_Msk, SUPC_WUMR_RTTEN_Msk, SUPC_WUMR_RTCEN_Msk. |
| void SUPC_DisableWriteProtection | ( | void | ) |
Unlocks SUPC/RTC/RTT/GPBR registers (SYSC_WPMR.WPEN = 0).
| void SUPC_EnableBackupSRAMRetention | ( | void | ) |
Retains backup SRAM in Backup mode (SUPC_MR.BKUPRETON = 1).
| void SUPC_EnableBrownoutDetector | ( | void | ) |
Enables the Brownout Detector (clears SUPC_MR.BODDIS).
| void SUPC_EnableBrownoutDetectorReset | ( | void | ) |
Arms core reset on brownout event (SUPC_MR.BODRSTEN = 1).
| 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.
| 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.
| threshold | threshold levels SUPC_SM_THRESHOLD_* macros, e.g. SUPC_SM_THRESHOLD_1V60, SUPC_SM_THRESHOLD_2V80, SUPC_SM_THRESHOLD_3V40 |
| sampling | Unshifted SUPC_SMMR_SMSMPL_CSM_Val / _32SLCK_Val / _256SLCK_Val / _2048SLCK_Val. |
| void SUPC_EnableSupplyMonitorInterrupt | ( | void | ) |
Arms SUPC interrupt on supply-monitor detection (SMIEN = 1).
| void SUPC_EnableSupplyMonitorReset | ( | void | ) |
Arms core reset on supply-monitor detection (SMRSTEN = 1).
| 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.
| pin_mask | Bit 0 = WKUP0, bit 1 = WKUP1 (e.g. 0x03 enables both). |
| period | Pre-shifted SUPC_WUMR_LPDBC_2_RTCOUT ? _8_RTCOUT. |
| polarity0 | 0 = LOW / 1 = HIGH for WKUP0 (ignored if not in mask). |
| polarity1 | 0 = LOW / 1 = HIGH for WKUP1 (ignored if not in mask). |
| void SUPC_EnableTamperGPBRClear | ( | void | ) |
Enables auto-erase of GPBR0..GPBR3 on tamper (LPDBCCLR = 1).
| void SUPC_EnableVoltageRegulator | ( | void | ) |
Selects the internal voltage regulator (SUPC_MR.ONREG = 1).
| void SUPC_EnableWakeupPin | ( | uint32_t | pin, |
| uint32_t | polarity ) |
Enables a wake-up pin as a wake source.
| pin | Wake-up pin index (0..13). |
| polarity | 0 = active LOW (falling edge), 1 = active HIGH (rising). |
| void SUPC_EnableWakeupSource | ( | uint32_t | source_mask | ) |
Enables wake-from-Backup sources in SUPC_WUMR.
Bits outside the wake-source set are filtered out.
| source_mask | OR-combination of SUPC_WUMR_SMEN_Msk, SUPC_WUMR_RTTEN_Msk, SUPC_WUMR_RTCEN_Msk. |
| void SUPC_EnableWriteProtection | ( | void | ) |
Locks SUPC/RTC/RTT/GPBR registers (SYSC_WPMR.WPEN = 1).
| void SUPC_EnterBackupMode | ( | void | ) |
Enters Backup mode (lowest power state).
Does NOT return ? wake exits via a full power-on reset.
| uint32_t SUPC_GetStatus | ( | void | ) |
Reads the full SUPC_SR register.
Reading clears all latched event flags as a side effect.
| 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.
| uint32_t SUPC_ReadGPBR | ( | uint32_t | reg | ) |
Reads a General-Purpose Backup Register.
| reg | Index of the GPBR to read (0..7). Returns 0 if out of range. |
| 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.
| void SUPC_SetCallbackHandler | ( | SUPC_CALLBACK_HANDLER | callback | ) |
Registers a callback function for the supply-monitor interrupt.
Call BEFORE arming the SM interrupt.
| callback | Callback function to register. |
| void SUPC_SetWakeupDebouncePeriod | ( | uint32_t | period | ) |
Sets the shared WKUPx debounce period (SUPC_WUMR.WKUPDBC).
| period | Pre-shifted SUPC_WUMR_WKUPDBC_IMMEDIATE / _3_SLCK / _32_SLCK / _512_SLCK / _4096_SLCK / _32768_SLCK. |
| 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.
| 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.
| 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.
| reg | Index of the GPBR to write (0..7). Ignored if out of range. |
| data | 32-bit value to write. |