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

Driver API for RSTC (plib_rstc.h) More...

Typedefs

typedef void(* RSTC_CALLBACK) (void)
 User Reset interrupt callback function type.
 

Functions

bool RSTC_EnableUserReset (void)
 Enable User Reset on a low level on NRST.
 
bool RSTC_DisableUserReset (void)
 Disable User Reset on a low level on NRST.
 
bool RSTC_EnableUserResetInterrupt (void)
 Enable the User Reset interrupt.
 
bool RSTC_DisableUserResetInterrupt (void)
 Disable the User Reset interrupt.
 
bool RSTC_SetExternalResetLength (uint8_t length)
 Set the External Reset Length.
 
bool RSTC_AssertProcessorReset (void)
 Command a processor reset.
 
bool RSTC_AssertExternalReset (void)
 Command an external reset (RSTC_CR.EXTRST).
 
bool RSTC_NrstLevelIsHigh (void)
 Report whether the NRST pin is currently sampled high (RSTC_SR.NRSTL).
 
uint32_t RSTC_ReadResetType (void)
 Read the cause of the last processor reset.
 
bool RSTC_UserResetIsDetected (void)
 Report whether a User Reset has been detected (RSTC_SR.URSTS).
 
bool RSTC_SoftwareResetIsInProgress (void)
 Report whether a software reset command is currently in progress (RSTC_SR.SRCMP).
 
void RSTC_RegisterUserResetCallback (RSTC_CALLBACK callback)
 Register a callback to be invoked from RSTC_Handler() on a User Reset interrupt event.
 
void RSTC_ClearUserResetInterrupt (void)
 Clear the User Reset interrupt.
 

Description

Driver API for RSTC (plib_rstc.h)

Usage Example

The following example demonstrates typical usage of the RSTC peripheral:

/*******************************************************************************
* Copyright (C) 2026 Microchip Technology Inc. and its subsidiaries.
*
* Subject to your compliance with these terms, you may use Microchip software
* and any derivatives exclusively with Microchip products. It is your
* responsibility to comply with third party license terms applicable to your
* use of third party software (including open source software) that may
* accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
* EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
* WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
* INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
* WHATSOEVER RELATED TO THIS SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
* BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
* FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN
* ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*******************************************************************************/
/*******************************************************************************
* @file configure_rstc.c
*
* @brief Template for Reset Controller(RSTC) module.
*
* @details Example configuration for RSTC User Reset notification via callback.
********************************************************************************/
#include "plib_rstc.h"
#include <stdint.h>
static volatile bool rstc_user_reset_triggered = false;
static void UserResetCallback(void)
{
rstc_user_reset_triggered = true;
//user operation (e.g., log event, graceful shutdown, notify supervisor)
}
int32_t configure_rstc(void)
{
/* External Reset Length (ERSTL, 0-15): NRST is held low for
* 2^(ERSTL+1) SLOW_CLK cycles when RSTC_AssertExternalReset() runs. */
const uint8_t rstc_external_reset_length = 5U;
/* Disable automatic reset-on-NRST so the interrupt path below notifies
* software instead. */
/* Shape the NRST pulse used by RSTC_AssertExternalReset(). */
(void)RSTC_SetExternalResetLength(rstc_external_reset_length);
/* Register callback handler for the User Reset event. */
RSTC_RegisterUserResetCallback(&UserResetCallback);
/* Enable the User Reset interrupt (URSTIEN = 1). */
/* Enable RSTC interrupt in NVIC. */
NVIC_EnableIRQ(RSTC_IRQn);
return 0;
}
void RSTC_RegisterUserResetCallback(RSTC_CALLBACK callback)
Register a callback to be invoked from RSTC_Handler() on a User Reset interrupt event.
bool RSTC_DisableUserReset(void)
Disable User Reset on a low level on NRST.
bool RSTC_EnableUserResetInterrupt(void)
Enable the User Reset interrupt.
bool RSTC_SetExternalResetLength(uint8_t length)
Set the External Reset Length.

Typedef Documentation

◆ RSTC_CALLBACK

typedef void(* RSTC_CALLBACK) (void)

User Reset interrupt callback function type.

Function Documentation

◆ RSTC_AssertExternalReset()

bool RSTC_AssertExternalReset ( void )

Command an external reset (RSTC_CR.EXTRST).

Asserts the NRST pin low for the duration configured by RSTC_MR.ERSTL. No effect if a software reset command is already in progress. Reading RSTC_SR to check this also clears RSTC_SR.URSTS.

Returns
true if the reset command was issued, false if a software reset command was already in progress.

◆ RSTC_AssertProcessorReset()

bool RSTC_AssertProcessorReset ( void )

Command a processor reset.

Resets the processor and all embedded peripherals. No effect if a software reset command is already in progress. Reading RSTC_SR to check this also clears RSTC_SR.URSTS.

Returns
true if the reset command was issued, false if a software reset command was already in progress.

◆ RSTC_ClearUserResetInterrupt()

void RSTC_ClearUserResetInterrupt ( void )

Clear the User Reset interrupt.

Reading RSTC_SR clears RSTC_SR.URSTS, and with it the RSTC interrupt line.

◆ RSTC_DisableUserReset()

bool RSTC_DisableUserReset ( void )

Disable User Reset on a low level on NRST.

Returns
true if RSTC_MR was written, false if write protection is active.

◆ RSTC_DisableUserResetInterrupt()

bool RSTC_DisableUserResetInterrupt ( void )

Disable the User Reset interrupt.

Preserves the current URSTEN and ERSTL fields.

Returns
true if RSTC_MR was written, false if write protection is active.

◆ RSTC_EnableUserReset()

bool RSTC_EnableUserReset ( void )

Enable User Reset on a low level on NRST.

Returns
true if RSTC_MR was written, false if write protection is active.

◆ RSTC_EnableUserResetInterrupt()

bool RSTC_EnableUserResetInterrupt ( void )

Enable the User Reset interrupt.

Only asserts the RSTC interrupt line when URSTEN = 0. Preserves the current URSTEN and ERSTL fields.

Returns
true if RSTC_MR was written, false if write protection is active.

◆ RSTC_NrstLevelIsHigh()

bool RSTC_NrstLevelIsHigh ( void )

Report whether the NRST pin is currently sampled high (RSTC_SR.NRSTL).

Reading RSTC_SR clears RSTC_SR.URSTS.

Returns
true if NRST is currently high, false if low.

◆ RSTC_ReadResetType()

uint32_t RSTC_ReadResetType ( void )

Read the cause of the last processor reset.

Reading RSTC_SR clears RSTC_SR.URSTS.

Returns
The raw RSTTYP field value: 0=GENERAL_RST, 1=BACKUP_RST, 2=WDT_RST, 3=SOFT_RST, 4=USER_RST.

◆ RSTC_RegisterUserResetCallback()

void RSTC_RegisterUserResetCallback ( RSTC_CALLBACK callback)

Register a callback to be invoked from RSTC_Handler() on a User Reset interrupt event.

Only relevant when RSTC_MR.URSTEN = 0 and RSTC_MR.URSTIEN = 1 (see RSTC_DisableUserReset() and RSTC_EnableUserResetInterrupt()).

Parameters
[in]callbackFunction to invoke, or NULL to unregister.

◆ RSTC_SetExternalResetLength()

bool RSTC_SetExternalResetLength ( uint8_t length)

Set the External Reset Length.

NRST is held low for 2^(ERSTL+1) SLOW_CLK cycles. Must be non-zero for a correctly shaped Watchdog Timer reset; ERSTL defaults to 0 at power-up.

Parameters
[in]lengthExternal Reset Length (ERSTL, 0-15).
Returns
true if RSTC_MR was written, false if write protection is active.

◆ RSTC_SoftwareResetIsInProgress()

bool RSTC_SoftwareResetIsInProgress ( void )

Report whether a software reset command is currently in progress (RSTC_SR.SRCMP).

Reading RSTC_SR clears RSTC_SR.URSTS.

Returns
true if a software reset command is in progress, false if RSTC is ready for a new one.

◆ RSTC_UserResetIsDetected()

bool RSTC_UserResetIsDetected ( void )

Report whether a User Reset has been detected (RSTC_SR.URSTS).

Reading RSTC_SR clears RSTC_SR.URSTS.

Returns
true if a high-to-low transition on NRST was detected.