MotorWare f2806x Module API Documentation
fem.h
Go to the documentation of this file.
1 #ifndef _FEM_H_
2 #define _FEM_H_
3 
9 
10 
11 // **************************************************************************
12 // the includes
13 #include <math.h>
14 
16 
17 
20 
23 
24 
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 
31 // **************************************************************************
32 // the defines
33 
34 
35 // **************************************************************************
36 // the typedefs
37 
40 typedef struct _FEM_Obj_
41 {
42  uint32_t timerPeriod_cnts;
43  uint32_t cnt_z0;
44  uint32_t cnt_z1;
45  uint32_t deltaCnt;
46 
47  uint32_t maxDeltaCnt;
48  uint32_t minDeltaCnt;
49 
51 
52  uint32_t errorCnt;
53 
55 } FEM_Obj;
56 
57 
60 typedef struct _FEM_Obj_ *FEM_Handle;
61 
62 
63 // **************************************************************************
64 // the globals
65 
66 
67 // **************************************************************************
68 // the function prototypes
69 
70 
74 static inline uint32_t FEM_getCnt_z0(FEM_Handle handle)
75 {
76  FEM_Obj *obj = (FEM_Obj *)handle;
77 
78  return(obj->cnt_z0);
79 } // end of FEM_getCnt_z0() function
80 
81 
85 static inline uint32_t FEM_getCnt_z1(FEM_Handle handle)
86 {
87  FEM_Obj *obj = (FEM_Obj *)handle;
88 
89  return(obj->cnt_z1);
90 } // end of FEM_getCnt_z1() function
91 
92 
96 static inline uint32_t FEM_getDeltaCnt(FEM_Handle handle)
97 {
98  FEM_Obj *obj = (FEM_Obj *)handle;
99 
100  return(obj->deltaCnt);
101 } // end of FEM_getDeltaCnt() function
102 
103 
107 static inline uint32_t FEM_getErrorCnt(FEM_Handle handle)
108 {
109  FEM_Obj *obj = (FEM_Obj *)handle;
110 
111  return(obj->errorCnt);
112 } // end of FEM_getErrorCnt() function
113 
114 
118 static inline bool FEM_getFlag_freqError(FEM_Handle handle)
119 {
120  FEM_Obj *obj = (FEM_Obj *)handle;
121 
122  return(obj->flag_freqError);
123 } // end of FEM_getFlag_freqError() function
124 
125 
129 static inline uint32_t FEM_getMaxDeltaCnt(FEM_Handle handle)
130 {
131  FEM_Obj *obj = (FEM_Obj *)handle;
132 
133  return(obj->maxDeltaCnt);
134 } // end of FEM_getMaxDeltaCnt() function
135 
136 
140 static inline uint32_t FEM_getMaxDeltaCntObserved(FEM_Handle handle)
141 {
142  FEM_Obj *obj = (FEM_Obj *)handle;
143 
144  return(obj->maxDeltaCntObserved);
145 } // end of FEM_getMaxDeltaCntObserved() function
146 
147 
151 static inline uint32_t FEM_getMinDeltaCnt(FEM_Handle handle)
152 {
153  FEM_Obj *obj = (FEM_Obj *)handle;
154 
155  return(obj->minDeltaCnt);
156 } // end of FEM_getMinDeltaCnts() function
157 
158 
162 static inline uint32_t FEM_getTimerPeriod(FEM_Handle handle)
163 {
164  FEM_Obj *obj = (FEM_Obj *)handle;
165 
166  return(obj->timerPeriod_cnts);
167 } // end of FEM_getTimerPeriod() function
168 
169 
174 extern FEM_Handle FEM_init(void *pMemory,const size_t numBytes);
175 
176 
180 static inline bool FEM_isFreqError(FEM_Handle handle)
181 {
182  FEM_Obj *obj = (FEM_Obj *)handle;
183 
184  return(obj->flag_freqError);
185 } // end of FEM_isFreqError() function
186 
187 
191 static inline void FEM_setCnt_z0(FEM_Handle handle,const uint32_t cnt)
192 {
193  FEM_Obj *obj = (FEM_Obj *)handle;
194 
195  obj->cnt_z0 = cnt;
196 
197  return;
198 } // end of FEM_setCnt_z0() function
199 
200 
204 static inline void FEM_setCnt_z1(FEM_Handle handle,const uint32_t cnt)
205 {
206  FEM_Obj *obj = (FEM_Obj *)handle;
207 
208  obj->cnt_z1 = cnt;
209 
210  return;
211 } // end of FEM_setCnt_z1() function
212 
213 
217 static inline void FEM_setDeltaCnt(FEM_Handle handle,const uint32_t deltaCnt)
218 {
219  FEM_Obj *obj = (FEM_Obj *)handle;
220 
221  obj->deltaCnt = deltaCnt;
222 
223  return;
224 } // end of FEM_setDeltaCnt() function
225 
226 
230 static inline void FEM_setErrorCnt(FEM_Handle handle,const uint32_t numErrors)
231 {
232  FEM_Obj *obj = (FEM_Obj *)handle;
233 
234  obj->errorCnt = numErrors;
235 
236  return;
237 } // end of FEM_setErrorCnt() function
238 
239 
243 static inline void FEM_setFlag_freqError(FEM_Handle handle,const bool state)
244 {
245  FEM_Obj *obj = (FEM_Obj *)handle;
246 
247  obj->flag_freqError = state;
248 
249  return;
250 } // end of FEM_setFlag_freqError() function
251 
252 
256 static inline void FEM_setMaxDeltaCnt(FEM_Handle handle,const uint32_t maxDeltaCnt)
257 {
258  FEM_Obj *obj = (FEM_Obj *)handle;
259 
260  obj->maxDeltaCnt = maxDeltaCnt;
261 
262  return;
263 } // end of FEM_setMaxDeltaCnt() function
264 
265 
269 static inline void FEM_setMaxDeltaCntObserved(FEM_Handle handle,const uint32_t maxDeltaCnt)
270 {
271  FEM_Obj *obj = (FEM_Obj *)handle;
272 
274 
275  return;
276 } // end of FEM_setMaxDeltaCntObserved() function
277 
278 
282 static inline void FEM_setMinDeltaCnt(FEM_Handle handle,const uint32_t minDeltaCnt)
283 {
284  FEM_Obj *obj = (FEM_Obj *)handle;
285 
286  obj->minDeltaCnt = minDeltaCnt;
287 
288  return;
289 } // end of FEM_setMinDeltaCnt() function
290 
291 
298 void FEM_setParams(FEM_Handle handle,
299  const float_t timerFreq_Hz,
300  const uint32_t timerPeriod_cnts,
301  const float_t spFreq_Hz,
302  const float_t maxError_Hz);
303 
304 
308 static inline void FEM_setTimerPeriod(FEM_Handle handle,const uint32_t timerPeriod_cnts)
309 {
310  FEM_Obj *obj = (FEM_Obj *)handle;
311 
313 
314  return;
315 } // end of FEM_setTimerPeriod() function
316 
317 
320 static inline void FEM_incrErrorCnt(FEM_Handle handle)
321 {
322  uint32_t errorCnt = FEM_getErrorCnt(handle);
323 
324  errorCnt++;
325 
326  FEM_setErrorCnt(handle,errorCnt);
327 
328  return;
329 } // end of FEM_incrErrorCnt() function
330 
331 
334 static inline void FEM_run(FEM_Handle handle)
335 {
336  uint32_t timerPeriod = FEM_getTimerPeriod(handle);
337  uint32_t maxDeltaCnt = FEM_getMaxDeltaCnt(handle);
339  uint32_t minDeltaCnt = FEM_getMinDeltaCnt(handle);
340  uint32_t cnt_z0 = FEM_getCnt_z0(handle);
341  uint32_t cnt_z1 = FEM_getCnt_z1(handle);
342 
343  uint32_t deltaCnt;
344 
345 
346  // compute the actual frequency
347  // handle wrap around of the timer count
348  // NOTE: count down timer
349  if(cnt_z0 > cnt_z1)
350  {
351  deltaCnt = cnt_z1 + timerPeriod - cnt_z0 + 1;
352  }
353  else
354  {
355  deltaCnt = cnt_z1 - cnt_z0 + 1;
356  }
357 
358 
359  // store the value
360  FEM_setDeltaCnt(handle,deltaCnt);
361 
362 
363  // keep track of the maximum delta count observed
364  if(deltaCnt > maxDeltaCntObserved)
365  {
366  // store the value
367  FEM_setMaxDeltaCntObserved(handle,deltaCnt);
368  }
369 
370 
371  // check for an error
372  if((deltaCnt < minDeltaCnt) || (deltaCnt > maxDeltaCnt))
373  {
374  // set the flag
375  FEM_setFlag_freqError(handle,true);
376 
377  // increment the counter
378  FEM_incrErrorCnt(handle);
379  }
380  else
381  {
382  // set the flag
383  FEM_setFlag_freqError(handle,false);
384  }
385 
386  return;
387 } // end of FEM_run() function
388 
389 
393 static inline void FEM_updateCnts(FEM_Handle handle,const uint32_t cnt)
394 {
395  uint32_t cnt_z0 = FEM_getCnt_z0(handle);
396 
397  FEM_setCnt_z1(handle,cnt_z0);
398  FEM_setCnt_z0(handle,cnt);
399 
400  return;
401 } // end of FEM_updateCnts() function
402 
403 
404 
405 #ifdef __cplusplus
406 }
407 #endif // extern "C"
408 
410 
411 #endif // end of _FEM_H_ definition
412 
413 
uint32_t maxDeltaCntObserved
the maximum delta counts observed, cnts
Definition: fem.h:50
Contains the public interface to the types definitions.
uint32_t maxDeltaCnt
the maximum delta count allowed, cnts
Definition: fem.h:47
uint32_t cnt_z1
the previous timer count value, cnts
Definition: fem.h:44
static void FEM_setFlag_freqError(FEM_Handle handle, const bool state)
Sets the state of the frequency error flag.
Definition: fem.h:243
static uint32_t FEM_getCnt_z1(FEM_Handle handle)
Gets the previous count value.
Definition: fem.h:85
static uint32_t FEM_getCnt_z0(FEM_Handle handle)
Gets the current count value.
Definition: fem.h:74
static uint32_t FEM_getDeltaCnt(FEM_Handle handle)
Gets the latest delta count measured, cnts.
Definition: fem.h:96
static uint32_t FEM_getErrorCnt(FEM_Handle handle)
Gets the frequency error count.
Definition: fem.h:107
struct _FEM_Obj_ FEM_Obj
Defines the frequency of execution monitoring (FEM) object.
static void FEM_setDeltaCnt(FEM_Handle handle, const uint32_t deltaCnt)
Sets the delta count value.
Definition: fem.h:217
static void FEM_setMinDeltaCnt(FEM_Handle handle, const uint32_t minDeltaCnt)
Sets the minimum delta count, cnts.
Definition: fem.h:282
void FEM_setParams(FEM_Handle handle, const float_t timerFreq_Hz, const uint32_t timerPeriod_cnts, const float_t spFreq_Hz, const float_t maxError_Hz)
Sets the frequency of execution monitoring parameters, cnts.
Definition: fem.c:35
static uint32_t FEM_getMinDeltaCnt(FEM_Handle handle)
Gets the minimum delta count allowed, cnts.
Definition: fem.h:151
static void FEM_run(FEM_Handle handle)
Runs the frequency of execution monitoring.
Definition: fem.h:334
bool flag_freqError
a flag to denote that a frequency error has occurred
Definition: fem.h:54
static uint32_t FEM_getTimerPeriod(FEM_Handle handle)
Gets the timer period, cnts.
Definition: fem.h:162
static void FEM_setErrorCnt(FEM_Handle handle, const uint32_t numErrors)
Sets the error count.
Definition: fem.h:230
uint32_t cnt_z0
the current timer count value, cnts
Definition: fem.h:43
static bool FEM_isFreqError(FEM_Handle handle)
Gets the state of the frequency error flag.
Definition: fem.h:180
uint32_t minDeltaCnt
the minimum delta count allowed, cnts
Definition: fem.h:48
static void FEM_incrErrorCnt(FEM_Handle handle)
Increments the error counter.
Definition: fem.h:320
static bool FEM_getFlag_freqError(FEM_Handle handle)
Gets the state of the frequency error flag.
Definition: fem.h:118
uint32_t deltaCnt
the latest delta count value, cnts
Definition: fem.h:45
static uint32_t FEM_getMaxDeltaCnt(FEM_Handle handle)
Gets the maximum delta count allowed, cnts.
Definition: fem.h:129
static void FEM_setMaxDeltaCntObserved(FEM_Handle handle, const uint32_t maxDeltaCnt)
Sets the maximum delta count observed, cnts.
Definition: fem.h:269
Defines the frequency of execution monitoring (FEM) object.
Definition: fem.h:40
static void FEM_setCnt_z0(FEM_Handle handle, const uint32_t cnt)
Sets the current count value.
Definition: fem.h:191
static void FEM_updateCnts(FEM_Handle handle, const uint32_t cnt)
Updates the current and previous count values.
Definition: fem.h:393
static uint32_t FEM_getMaxDeltaCntObserved(FEM_Handle handle)
Gets the maximum delta count observed, cnts.
Definition: fem.h:140
uint32_t errorCnt
denotes the number of frequency errors that have been detected
Definition: fem.h:52
static void FEM_setMaxDeltaCnt(FEM_Handle handle, const uint32_t maxDeltaCnt)
Sets the maximum delta count, cnts.
Definition: fem.h:256
static void FEM_setCnt_z1(FEM_Handle handle, const uint32_t cnt)
Sets the previous count value.
Definition: fem.h:204
uint32_t timerPeriod_cnts
the timer period, cnts
Definition: fem.h:42
struct _FEM_Obj_ * FEM_Handle
Defines the FEM handle.
Definition: fem.h:60
FEM_Handle FEM_init(void *pMemory, const size_t numBytes)
Initializes the frequency of execution monitoring (FEM) object.
Definition: fem.c:21
static void FEM_setTimerPeriod(FEM_Handle handle, const uint32_t timerPeriod_cnts)
Sets the timer period, cnts.
Definition: fem.h:308
float float_t
Defines the portable data type for 32 bit, signed floating-point data.
Definition: types.h:121