Digital Power Starter Kit 3 Firmware
dsPIC33C Buck 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 
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 
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 
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 
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 
131 typedef 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 } FAULT_OBJECT_t;
141  // end of group
143 
144 
145 // Public Fault Configuration Templates
146 extern volatile struct FAULT_OBJECT_s fltObjectClear;
147 
148 // Public Function Prototypes
149 extern volatile uint16_t drv_FaultHandler_CheckObject(volatile struct FAULT_OBJECT_s* fltobj);
150 
151 #endif /* FAULT_HANDLER_H */
152 
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::RecoveryResponse
volatile struct FLT_EVENT_RESPONSE_s RecoveryResponse
Settings defining the fault recovery event.
Definition: drv_fault_handler.h:138
FAULT_OBJECT_s::Status
volatile struct FLT_OBJECT_STATUS_s Status
Status word of this fault object.
Definition: drv_fault_handler.h:133
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::value
volatile uint16_t value
Definition: drv_fault_handler.h:92
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
fltObjectClear
volatile struct FAULT_OBJECT_s fltObjectClear
Clears the fault objects.
Definition: drv_fault_handler.c:56
FLT_EVENT_RESPONSE_s
This data structure defines the fault monitor event response object.
Definition: drv_fault_handler.h:118
FAULT_OBJECT_s::SourceObject
volatile struct FLT_COMPARE_OBJECT_s SourceObject
Object which should be monitored.
Definition: drv_fault_handler.h:135
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
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_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_OBJECT_STATUS_s::Enabled
volatile bool Enabled
Bit 15: Control bit enabling/disabling monitoring of the fault object.
Definition: drv_fault_handler.h:89
drv_FaultHandler_CheckObject
volatile uint16_t drv_FaultHandler_CheckObject(volatile struct FAULT_OBJECT_s *fltobj)
Check current fault status of a user-defined fault object.
Definition: drv_fault_handler.c:168
FLT_COMPARE_OBJECT_s
This data structure defines the data object which will be monitored by the fault handler.
Definition: drv_fault_handler.h:104
FLT_COMPARE_OBJECT_s::ptrObject
volatile uint16_t * ptrObject
Pointer to register or variable which should be monitored.
Definition: drv_fault_handler.h:106
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::Counter
volatile uint16_t Counter
Fault event counter (controlled by FAULT HANDLER)
Definition: drv_fault_handler.h:134
FAULT_OBJECT_s
This data structure is a collection of data structures for fault handling.
Definition: drv_fault_handler.h:131
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
FLT_OBJECT_STATUS_s::unsigned
volatile unsigned
Bit <7:2>: (reserved)
Definition: drv_fault_handler.h:86
FLT_OBJECT_STATUS_s::FaultStatus
volatile bool FaultStatus
Bit 0: Flag bit indicating if FAULT has been tripped.
Definition: drv_fault_handler.h:84
FLT_OBJECT_STATUS_s
This data structure defines the fault object status.
Definition: drv_fault_handler.h:80