Digital Power Starter Kit 3 Firmware
dsPIC33C Boost Converter Voltage Mode Control Example
app_fault_monitor.c
1 /*
2  * @file app_fault_monitor.c
3  * Author: M91406
4  * @brief Fault monitor application layer source file
5  * Revision history:
6  */
7 
8 #include <xc.h> // include processor files - each processor file is guarded.
9 #include <stdint.h> // include standard integer data types
10 #include <stdbool.h> // include standard boolean data types
11 #include <stddef.h> // include standard definition data types
12 
13 #include "config/hal.h" // include hardware abstraction layer header file
14 #include "config/apps.h" // include application layer abstraction layer header file
15 
16 // User fault object declarations
17 extern volatile struct FAULT_OBJECT_s* FaultObjectList[];
18 extern volatile uint16_t FaultObjectList_size;
19 
20 /*********************************************************************************
21  * @fn volatile uint16_t appFaultMonitor_Execute(void)
22  * @ingroup app-layer-fault-handler-functions-public
23  * @brief Application wide fault object monitoring routine
24  * @return 0=failure
25  * @return 1=success
26  *
27  * @details
28  * In this function all user-defined fault objects are monitored for
29  * threshold violations. While fault responses are triggered by each
30  * fault object individually, system recovery from a fault condition is
31  * only allowed when all fault conditions have been cleared. Hence,
32  * individual fault status bits are combined into a common fault bit,
33  * which needs to be cleared to allow the power supply to start-up again.
34  *
35  *********************************************************************************/
36 
37 volatile uint16_t appFaultMonitor_Execute(void)
38 {
39  volatile uint16_t retval=1;
40 
41  // Scan all declared fault objects
42  drv_FaultHandler_ScanObjects(FaultObjectList, FaultObjectList_size);
43 
44  // Push global fault state to buck converter device driver status
45  boost.status.bits.fault_active = FaultMonitor.Status.bits.FaultStatus;
46 
47  // If power supply controller passes POWER GOOD and reaches state ONLINE,
48  // reset restart cycle counter
49  if (boost.state_id.bits.opstate_id == BOOST_OPSTATE_ONLINE)
50  FaultMonitor.FaultRecoveryCounter = 0;
51 
52 
53  return (retval);
54 }
55 
56 /*********************************************************************************
57  * @fn volatile uint16_t appFaultMonitor_Initialize(void)
58  * @ingroup app-layer-fault-handler-functions-public
59  * @brief Initialization of user-defined fault objects
60  * @return 0=failure
61  * @return 1=success
62  *
63  * @details
64  * This function initializes the fault monitor data object user settings.
65  *********************************************************************************/
66 
67 volatile uint16_t appFaultMonitor_Initialize(void)
68 {
69  volatile uint16_t retval=1;
70 
71  FaultMonitor.FaultRecovery = &appPowerSupply_Resume;
72  FaultMonitor.FaultLatchCount = BOOST_FAULT_RESTART_CYCLES;
73  FaultMonitor.FaultRecoveryCounter = 0;
74 
75  return(retval);
76 }
77 
78 /*********************************************************************************
79  * @fn volatile uint16_t appFaultMonitor_Start(void)
80  * @ingroup app-layer-fault-handler-functions-public
81  * @brief Function starting all pre-configured fault checks
82  * @return 0=failure
83  * @return 1=success
84  *
85  * @details
86  * This function is used to set the fault status of all fault objects
87  * to ACTIVE, enforcing the system monitor to clear them one-by-one as
88  * default startup self-test procedure. Once cleared, the respective
89  * recovery procedures will turn on the respective user-tasks being
90  * kept on-hold while faults have been active.
91  *
92  * Users can set the initial state of each fault object in accordance
93  * to their inclusion in the self-test period at firmware startup.
94  *
95  *********************************************************************************/
96 
97 volatile uint16_t appFaultMonitor_Start(void)
98 {
99  fltobj_BoostUVLO.Status.bits.FaultStatus = true; // Set Under Voltage Lock Out fault
100  fltobj_BoostUVLO.Status.bits.FaultActive = true; // Set Under Voltage Lock Out fault condition indicator
101  fltobj_BoostUVLO.Status.bits.Enabled = true; // Enable Under Voltage Lock Out object
102 
103  fltobj_BoostOVLO.Status.bits.FaultStatus = true; // Set Over Voltage Lock Out fault
104  fltobj_BoostOVLO.Status.bits.FaultActive = true; // Set Over Voltage Lock Out fault condition indicator
105  fltobj_BoostOVLO.Status.bits.Enabled = true; // Enable Over Voltage Lock Out object
106 
107  fltobj_BoostOCP.Status.bits.FaultStatus = false; // Clear Over Current Protection fault
108  fltobj_BoostOCP.Status.bits.FaultActive = false; // Clear Over Current Protection fault condition indicator
109  fltobj_BoostOCP.Status.bits.Enabled = false; // Disable Over Current Protection object (will be enabled by power supply state machine)
110 
111  fltobj_BoostRegErr.Status.bits.FaultStatus = false; // Clear Regulation Error fault
112  fltobj_BoostRegErr.Status.bits.FaultActive = false; // Clear Regulation Error fault condition indicator
113  fltobj_BoostRegErr.Status.bits.Enabled = false; // Disable Regulation Error object (will be enabled by power supply state machine)
114 
115  return(1);
116 }
117 
118 /*********************************************************************************
119  * @fn volatile uint16_t appFaultMonitor_Dispose(void)
120  * @ingroup app-layer-fault-handler-functions-public
121  * @brief Function clearing all fault object settings
122  * @return 0=failure
123  * @return 1=success
124  *
125  * @details
126  * This function is used to clear all fault objects settings. Once cleared,
127  * the fault objects are detached from memory addresses and cannot be used
128  * for fault monitoring anymore until they have been re-initialized.
129  *
130  *********************************************************************************/
131 
132 volatile uint16_t appFaultMonitor_Dispose(void) {
133 
134  // Clear all user defined fault objects
135  drv_FaultHandler_Dispose(FaultObjectList, FaultObjectList_size);
136 
137  return(1);
138 }
139 
140 // end of file
volatile bool fault_active
Bit #5: Flag bit indicating system is in enforced shut down mode (usually due to a fault condition)
volatile bool Enabled
Bit 15: Control bit enabling/disabling monitoring of the fault object.
volatile uint16_t(* FaultRecovery)(void)
Function pointer to the common fault recovery function.
volatile struct FLT_OBJECT_STATUS_s Status
Status word of this fault object.
volatile uint16_t FaultRecoveryCounter
Most recent number of fault recovery attempts.
struct BOOST_STATE_ID_s::@372::@373 bits
volatile struct FAULT_MONITOR_STATUS_s Status
Status word of the fault monitor.
volatile bool FaultStatus
Bit 0: Flag bit indicating if FAULT has been tripped.
Generic fault object.
volatile uint16_t FaultLatchCount
Number of fault recovery attempts after which the system gets locked in a latched fault state.
volatile struct BOOST_CONVERTER_STATUS_s status
BOOST operation status bits.
volatile struct BOOST_STATE_ID_s state_id
BOOST state machine operating state ID.
volatile bool FaultActive
Bit 1: Flag bit indicating if fault condition has been detected but FAULT has not been tripped yet.
volatile bool FaultStatus
Bit 0: Flag bit indicating if a FAULT condition has been tripped.