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  *********************************************************************************/
132 
133  volatile struct FLT_OBJECT_STATUS_s Status;
134  volatile uint16_t Counter;
139 
140 };
141 typedef struct FAULT_OBJECT_s FAULT_OBJECT_t;
142 
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 };
154 
155 /**********************************************************************************
156  * @struct FAULT_MONITOR_s
157  * @brief Common fault monitor settings
158  *********************************************************************************/
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 
volatile bool Enabled
Bit 15: Control bit enabling/disabling monitoring of the fault object.
volatile uint16_t Counter
Fault event counter (controlled by FAULT HANDLER)
volatile uint16_t(* FaultRecovery)(void)
Function pointer to the common fault recovery function.
enum FLT_COMPARE_TYPE_e CompareType
Bit <10:8>: Fault check comparison type control bits.
volatile struct FLT_COMPARE_OBJECT_s ReferenceObject
Reference object the source should be compared with.
volatile unsigned
Bit <15:2>: (reserved)
volatile struct FLT_OBJECT_STATUS_s Status
Status word of this fault object.
volatile uint16_t FaultStatusList
Status word encoding individual fault object states in order of their list index.
volatile uint16_t * ptrObject
Pointer to register or variable which should be monitored.
volatile uint16_t FaultRecoveryCounter
Most recent number of fault recovery attempts.
volatile uint16_t value
Fault monitor status word.
volatile struct FAULT_MONITOR_STATUS_s Status
Status word of the fault monitor.
volatile uint16_t eventThreshold
Bit mask will be &-ed with source as value (use 0xFFFF for full value comparison)
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 uint16_t compareThreshold
Signal level at which the fault condition will be detected.
volatile unsigned
Bit <7:2>: (reserved)
volatile uint16_t(* ptrResponseFunction)(void)
pointer to a user-defined function called when a defined fault monitoring event is detected
volatile struct FLT_COMPARE_OBJECT_s SourceObject
Object which should be monitored.
volatile uint16_t value
volatile bool FaultLatch
Bit 1: Flag bit indicating if a latched FAULT condition has been enforced.
volatile uint16_t bitMask
Bit mask will be &-ed with source as value (use 0xFFFF for full value comparison)
volatile struct FLT_EVENT_RESPONSE_s TripResponse
Settings defining the fault trip event.
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.
volatile struct FLT_EVENT_RESPONSE_s RecoveryResponse
Settings defining the fault recovery event.