| Digital Power Starter Kit 3 Firmware dsPIC33C Boost Converter Voltage Mode Control Example |

drv_fault_handler.h
1
32 /*
33 * File: fault_handler.h
34 * Author: M91406
35 * Comments: Global, generic fault handler header file
36 * Revision history:
37 */
38
39 // This is a guard condition so that contents of this file are not included
40 // more than once.
41 #ifndef FAULT_HANDLER_H
42 #define FAULT_HANDLER_H
43
44
45
46 #include <xc.h> // include processor files - each processor file is guarded.
47 #include <stdint.h> // include standard integer types
48 #include <stdbool.h> // include standard boolean types
49 #include <stddef.h> // include standard definitions
50
55 /***********************************************************************************
56 * @enum FLT_COMPARE_TYPE_e
57 * @brief This data structure is comprised of fault comparison types
58 * @extends FLT_OBJECT_STATUS_s
59 *********************************************************************************/
60
61 typedef enum FLT_COMPARE_TYPE_e {
62
63 FLTCMP_NONE = 0,
64 FLTCMP_GREATER_THAN = 1,
65 FLTCMP_LESS_THAN = 2,
66 FLTCMP_IS_EQUAL = 3,
67 FLTCMP_IS_NOT_EQUAL = 4,
68 FLTCMP_BETWEEN = 5,
69 FLTCMP_OUTSIDE = 6
70
71 } FLT_COMPARE_TYPE_t;
72
73
74 /**********************************************************************************
75 * @struct FLT_OBJECT_STATUS_s
76 * @brief This data structure defines the fault object status
77 * @extends FAULT_OBJECT_s
78 *********************************************************************************/
79
80 typedef struct FLT_OBJECT_STATUS_s{
81
82 union {
83 struct {
84 volatile bool FaultStatus : 1;
85 volatile bool FaultActive : 1;
86 volatile unsigned : 6;
87 volatile enum FLT_COMPARE_TYPE_e CompareType: 3;
88 volatile unsigned : 4;
89 volatile bool Enabled : 1;
90 } __attribute__((packed)) bits; // Fault object status bit field for single bit access
91
92 volatile uint16_t value; // Fault object status word
93 };
94
95 } FLT_OBJECT_STATUS_t; // Fault object status
96
97
98 /**********************************************************************************
99 * @struct FLT_COMPARE_OBJECT_s
100 * @brief This data structure defines the data object which will be monitored by the fault handler
101 * @extends FAULT_OBJECT_s
102 *********************************************************************************/
103
104 typedef struct FLT_COMPARE_OBJECT_s {
105
106 volatile uint16_t* ptrObject;
107 volatile uint16_t bitMask;
108
109 } FLT_COMPARE_OBJECT_t; // Fault compare object
110
111
112 /**********************************************************************************
113 * @struct FLT_EVENT_RESPONSE_s
114 * @brief This data structure defines the fault monitor event response object
115 * @extends FAULT_OBJECT_s
116 *********************************************************************************/
117
118 typedef struct FLT_EVENT_RESPONSE_s {
119
120 volatile uint16_t compareThreshold;
121 volatile uint16_t eventThreshold;
122 volatile uint16_t (*ptrResponseFunction)(void);
123
124 } FLT_EVENT_RESPONSE_t; // Fault monitor event response object
125
126
127 /**********************************************************************************
128 * @struct FAULT_OBJECT_s
129 * @brief This data structure is a collection of data structures for fault handling.
130 *********************************************************************************/
131 struct FAULT_OBJECT_s {
132
133 volatile struct FLT_OBJECT_STATUS_s Status;
134 volatile uint16_t Counter;
135 volatile struct FLT_COMPARE_OBJECT_s SourceObject;
136 volatile struct FLT_COMPARE_OBJECT_s ReferenceObject;
137 volatile struct FLT_EVENT_RESPONSE_s TripResponse;
138 volatile struct FLT_EVENT_RESPONSE_s RecoveryResponse;
139
140 };
141 typedef struct FAULT_OBJECT_s FAULT_OBJECT_t;
142
143 struct FAULT_MONITOR_STATUS_s {
144 union {
145 struct {
146 volatile bool FaultStatus : 1;
147 volatile bool FaultLatch : 1;
148 volatile unsigned : 14;
149 } __attribute__((packed)) bits;
150 volatile uint16_t value;
151 };
152 };
153 typedef struct FAULT_MONITOR_STATUS_s FAULT_MONITOR_STATUS_t;
154
155 /**********************************************************************************
156 * @struct FAULT_MONITOR_s
157 * @brief Common fault monitor settings
158 *********************************************************************************/
159 struct FAULT_MONITOR_s {
160 volatile struct FAULT_MONITOR_STATUS_s Status;
161 volatile uint16_t FaultStatusList;
162 volatile uint16_t FaultRecoveryCounter;
163 volatile uint16_t FaultLatchCount;
164 volatile uint16_t (*FaultRecovery)(void);
165 };
166 typedef struct FAULT_MONITOR_s FAULT_MONITOR_t;
167
168 /*********************************************************************************
169 * @var FaultMonitor
170 * @brief Global fault monitor object
171 * @details
172 * ADD_DESCRIPTION_HERE
173 **********************************************************************************/
174 extern volatile struct FAULT_MONITOR_s FaultMonitor;
175 // end of group
177
178
179 // Public Function Prototypes
180 extern volatile uint16_t drv_FaultHandler_ScanObjects(volatile struct FAULT_OBJECT_s* fltObjectList[], volatile uint16_t size);
181 extern volatile uint16_t drv_FaultHandler_Dispose(volatile struct FAULT_OBJECT_s* fltObjectList[], volatile uint16_t size);
182
183 #endif /* FAULT_HANDLER_H */
184
FLT_OBJECT_STATUS_s
Definition: drv_fault_handler.h:80
FLT_OBJECT_STATUS_s::Enabled
volatile bool Enabled
Bit 15: Control bit enabling/disabling monitoring of the fault object.
Definition: drv_fault_handler.h:89
FAULT_OBJECT_s::Counter
volatile uint16_t Counter
Fault event counter (controlled by FAULT HANDLER)
Definition: drv_fault_handler.h:134
FAULT_MONITOR_s::FaultRecovery
volatile uint16_t(* FaultRecovery)(void)
Function pointer to the common fault recovery function.
Definition: drv_fault_handler.h:164
FLT_OBJECT_STATUS_s::CompareType
enum FLT_COMPARE_TYPE_e CompareType
Bit <10:8>: Fault check comparison type control bits.
Definition: drv_fault_handler.h:87
FAULT_OBJECT_s::ReferenceObject
volatile struct FLT_COMPARE_OBJECT_s ReferenceObject
Reference object the source should be compared with.
Definition: drv_fault_handler.h:136
FAULT_MONITOR_STATUS_s::unsigned
volatile unsigned
Bit <15:2>: (reserved)
Definition: drv_fault_handler.h:148
FAULT_OBJECT_s::Status
volatile struct FLT_OBJECT_STATUS_s Status
Status word of this fault object.
Definition: drv_fault_handler.h:133
FAULT_MONITOR_s::FaultStatusList
volatile uint16_t FaultStatusList
Status word encoding individual fault object states in order of their list index.
Definition: drv_fault_handler.h:161
FLT_COMPARE_OBJECT_s::ptrObject
volatile uint16_t * ptrObject
Pointer to register or variable which should be monitored.
Definition: drv_fault_handler.h:106
FAULT_MONITOR_STATUS_s
Definition: drv_fault_handler.h:143
FAULT_MONITOR_s::FaultRecoveryCounter
volatile uint16_t FaultRecoveryCounter
Most recent number of fault recovery attempts.
Definition: drv_fault_handler.h:162
FAULT_MONITOR_STATUS_s::value
volatile uint16_t value
Fault monitor status word.
Definition: drv_fault_handler.h:150
FAULT_MONITOR_s::Status
volatile struct FAULT_MONITOR_STATUS_s Status
Status word of the fault monitor.
Definition: drv_fault_handler.h:160
FLT_COMPARE_OBJECT_s
Definition: drv_fault_handler.h:104
FLT_EVENT_RESPONSE_s::eventThreshold
volatile uint16_t eventThreshold
Bit mask will be &-ed with source as value (use 0xFFFF for full value comparison)
Definition: drv_fault_handler.h:121
FLT_OBJECT_STATUS_s::FaultStatus
volatile bool FaultStatus
Bit 0: Flag bit indicating if FAULT has been tripped.
Definition: drv_fault_handler.h:84
FAULT_OBJECT_s
Generic fault object.
Definition: drv_fault_handler.h:131
FAULT_MONITOR_s::FaultLatchCount
volatile uint16_t FaultLatchCount
Number of fault recovery attempts after which the system gets locked in a latched fault state.
Definition: drv_fault_handler.h:163
FLT_EVENT_RESPONSE_s::compareThreshold
volatile uint16_t compareThreshold
Signal level at which the fault condition will be detected.
Definition: drv_fault_handler.h:120
FLT_EVENT_RESPONSE_s
Definition: drv_fault_handler.h:118
FLT_OBJECT_STATUS_s::unsigned
volatile unsigned
Bit <7:2>: (reserved)
Definition: drv_fault_handler.h:86
FLT_EVENT_RESPONSE_s::ptrResponseFunction
volatile uint16_t(* ptrResponseFunction)(void)
pointer to a user-defined function called when a defined fault monitoring event is detected
Definition: drv_fault_handler.h:122
FAULT_OBJECT_s::SourceObject
volatile struct FLT_COMPARE_OBJECT_s SourceObject
Object which should be monitored.
Definition: drv_fault_handler.h:135
FLT_OBJECT_STATUS_s::value
volatile uint16_t value
Definition: drv_fault_handler.h:92
FAULT_MONITOR_STATUS_s::FaultLatch
volatile bool FaultLatch
Bit 1: Flag bit indicating if a latched FAULT condition has been enforced.
Definition: drv_fault_handler.h:147
FAULT_MONITOR_s
Definition: drv_fault_handler.h:159
FLT_COMPARE_OBJECT_s::bitMask
volatile uint16_t bitMask
Bit mask will be &-ed with source as value (use 0xFFFF for full value comparison)
Definition: drv_fault_handler.h:107
FAULT_OBJECT_s::TripResponse
volatile struct FLT_EVENT_RESPONSE_s TripResponse
Settings defining the fault trip event.
Definition: drv_fault_handler.h:137
FLT_OBJECT_STATUS_s::FaultActive
volatile bool FaultActive
Bit 1: Flag bit indicating if fault condition has been detected but FAULT has not been tripped yet.
Definition: drv_fault_handler.h:85
FAULT_MONITOR_STATUS_s::FaultStatus
volatile bool FaultStatus
Bit 0: Flag bit indicating if a FAULT condition has been tripped.
Definition: drv_fault_handler.h:146
FAULT_OBJECT_s::RecoveryResponse
volatile struct FLT_EVENT_RESPONSE_s RecoveryResponse
Settings defining the fault recovery event.
Definition: drv_fault_handler.h:138