add PIC watchdog

This commit is contained in:
Rémi Heredero 2023-09-05 11:06:23 +02:00
parent 32f1bd73b4
commit e0b94c5250
6 changed files with 169 additions and 41 deletions

View File

@ -10,7 +10,6 @@ void main(void)
// Initialize the device
SYSTEM_Initialize();
// Disable the Global Interrupts
// INTERRUPT_GlobalInterruptDisable();
@ -21,6 +20,7 @@ void main(void)
Factory_init();
Factory_build();
Factory_start();
//WWDT_SoftEnable();
// let the XF timers handling become the TMR0 interrupt handler
// this means that the XF timers are always decremented when the
@ -33,6 +33,7 @@ void main(void)
while (1)
{
//handle the next event if there is any in the queue
WWDT_TimerClear();
XF_executeOnce();
//maybe sleep a short while to save energy
}

View File

@ -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

View File

@ -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
*/

View 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 */
/**

View File

@ -224,6 +224,7 @@
<property key="debugoptions.useswbreakpoints" value="false"/>
<property key="event.recorder.enabled" value="false"/>
<property key="event.recorder.scvd.files" value=""/>
<property key="firmware.download.all" value="false"/>
<property key="hwtoolclock.frcindebug" value="false"/>
<property key="lastid" value=""/>
<property key="memories.aux" value="false"/>

File diff suppressed because one or more lines are too long