add PIC watchdog
This commit is contained in:
@ -73,8 +73,8 @@
|
||||
#pragma config XINST = OFF // Extended Instruction Set Enable bit->Extended Instruction Set and Indexed Addressing Mode disabled
|
||||
|
||||
// CONFIG3L
|
||||
#pragma config WDTCPS = WDTCPS_31 // WDT Period selection bits->Divider ratio 1:65536; software control of WDTPS
|
||||
#pragma config WDTE = OFF // WDT operating mode->WDT Disabled; SWDTEN is ignored
|
||||
#pragma config WDTCPS = WDTCPS_6 // WDT Period selection bits->Divider ratio 1:2048
|
||||
#pragma config WDTE = SWDTEN // WDT operating mode->WDT enabled/disabled by SWDTEN bit
|
||||
|
||||
// CONFIG3H
|
||||
#pragma config WDTCWS = WDTCWS_7 // WDT Window Select bits->window always open (100%); software control; keyed access not required
|
||||
|
@ -53,6 +53,7 @@ void SYSTEM_Initialize(void)
|
||||
PMD_Initialize();
|
||||
PIN_MANAGER_Initialize();
|
||||
OSCILLATOR_Initialize();
|
||||
WWDT_Initialize();
|
||||
TMR0_Initialize();
|
||||
ECAN_Initialize();
|
||||
}
|
||||
@ -92,6 +93,50 @@ void PMD_Initialize(void)
|
||||
}
|
||||
|
||||
|
||||
void WWDT_Initialize(void)
|
||||
{
|
||||
// Initializes the WWDT to the default states configured in the MCC GUI
|
||||
WDTCON0 = WDTCPS;
|
||||
WDTCON1 = WDTCWS|WDTCCS;
|
||||
|
||||
}
|
||||
|
||||
void WWDT_SoftEnable(void)
|
||||
{
|
||||
// WWDT software enable.
|
||||
WDTCON0bits.SEN=1;
|
||||
}
|
||||
|
||||
void WWDT_SoftDisable(void)
|
||||
{
|
||||
// WWDT software disable.
|
||||
WDTCON0bits.SEN=0;
|
||||
}
|
||||
|
||||
bool WWDT_TimeOutStatusGet(void)
|
||||
{
|
||||
// Return the status of WWDT time out reset.
|
||||
return (PCON0bits.nRWDT);
|
||||
}
|
||||
|
||||
bool WWDT_WindowViolationStatusGet(void)
|
||||
{
|
||||
// Return the status of WWDT window violation reset.
|
||||
return (PCON0bits.nWDTWV);
|
||||
}
|
||||
|
||||
void WWDT_TimerClear(void)
|
||||
{
|
||||
// Disable the interrupt,read back the WDTCON0 reg for arming,
|
||||
// clearing the WWDT and enable the interrupt.
|
||||
uint8_t readBack=0;
|
||||
|
||||
bool state = GIE;
|
||||
GIE = 0;
|
||||
readBack = WDTCON0;
|
||||
CLRWDT();
|
||||
GIE = state;
|
||||
}
|
||||
/**
|
||||
End of File
|
||||
*/
|
||||
|
@ -57,6 +57,9 @@
|
||||
#include "tmr0.h"
|
||||
#include "ecan.h"
|
||||
|
||||
#define WDTCWS 7
|
||||
#define WDTCCS 48
|
||||
#define WDTCPS 12
|
||||
|
||||
|
||||
/**
|
||||
@ -98,6 +101,84 @@ void OSCILLATOR_Initialize(void);
|
||||
*/
|
||||
void PMD_Initialize(void);
|
||||
|
||||
/**
|
||||
* @Param
|
||||
none
|
||||
* @Returns
|
||||
none
|
||||
* @Description
|
||||
Initializes the WWDT to the default states configured in the
|
||||
* MCC GUI
|
||||
* @Example
|
||||
WWDT_Initialize();
|
||||
*/
|
||||
void WWDT_Initialize(void);
|
||||
|
||||
|
||||
/**
|
||||
* @Param
|
||||
none
|
||||
* @Returns
|
||||
none
|
||||
* @Description
|
||||
Enable the WWDT by setting the SEN bit.
|
||||
* @Example
|
||||
WWDT_SoftEnable();
|
||||
*/
|
||||
void WWDT_SoftEnable(void);
|
||||
|
||||
/**
|
||||
* @Param
|
||||
none
|
||||
* @Returns
|
||||
none
|
||||
* @Description
|
||||
Disable the WWDT by clearing the SEN bit.
|
||||
* @Example
|
||||
WWDT_SoftDisable();
|
||||
*/
|
||||
void WWDT_SoftDisable(void);
|
||||
|
||||
/**
|
||||
* @Param
|
||||
none
|
||||
* @Returns
|
||||
none
|
||||
* @Description
|
||||
Disable the interrupt, arm the WWDT by reading back the WDTCON0 register
|
||||
* clear the WWDT and enable the interrupt.
|
||||
* @Example
|
||||
WWDT_TimerClear();
|
||||
*/
|
||||
void WWDT_TimerClear(void);
|
||||
|
||||
/**
|
||||
* @Param
|
||||
none
|
||||
* @Returns
|
||||
High --> WWDT reset has not occurred.
|
||||
* Low --> WWDT reset has occurred.
|
||||
* @Description
|
||||
Returns the status of whether the WWDT reset has occurred or not.
|
||||
* @Example
|
||||
if(WWDT_TimeOutStatusGet())
|
||||
*/
|
||||
bool WWDT_TimeOutStatusGet(void);
|
||||
|
||||
/**
|
||||
* @Param
|
||||
none
|
||||
* @Returns
|
||||
High --> WWDT window violation reset has not occurred.
|
||||
* Low --> WWDT window violation reset has occurred.
|
||||
* @Description
|
||||
Returns the status of, whether the WWDT window violation
|
||||
* reset has occurred or not.
|
||||
* @Example
|
||||
if(WWDT_WindowViolationStatusGet())
|
||||
*/
|
||||
bool WWDT_WindowViolationStatusGet(void);
|
||||
|
||||
|
||||
#endif /* MCC_H */
|
||||
/**
|
||||
|
Reference in New Issue
Block a user