datalogIF.h
Go to the documentation of this file.
1 //#############################################################################
2 // $TI Release: MotorControl SDK v1.00.00.00 $
3 // $Release Date: Mon Mar 11 18:37:40 CDT 2019 $
4 // $Copyright:
5 // Copyright (C) 2017-2019 Texas Instruments Incorporated - http://www.ti.com/
6 //
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions
9 // are met:
10 //
11 // Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 //
14 // Redistributions in binary form must reproduce the above copyright
15 // notice, this list of conditions and the following disclaimer in the
16 // documentation and/or other materials provided with the
17 // distribution.
18 //
19 // Neither the name of Texas Instruments Incorporated nor the names of
20 // its contributors may be used to endorse or promote products derived
21 // from this software without specific prior written permission.
22 //
23 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 // $
35 //#############################################################################
36 
37 #ifndef DATALOG_H
38 #define DATALOG_H
39 
44 
45 
46 //*****************************************************************************
47 //
48 // If building with a C++ compiler, make all of the definitions in this header
49 // have a C binding.
50 //
51 //*****************************************************************************
52 #ifdef __cplusplus
53 extern "C"
54 {
55 #endif
56 
57 //*****************************************************************************
58 //
61 //
62 //*****************************************************************************
63 
64 // the includes
65 #include <math.h>
66 
67 // system
68 #include "stdbool.h" // needed for bool type, true/false
69 #if !defined(__TMS320C28XX_CLA__)
70 #include "string.h" // needed for size_t typedef
71 #endif
72 #include "stdint.h" // needed for C99 data types
73 
74 // **************************************************************************
75 // the defines
76 #if defined(DATALOGI4_EN) || defined(DATALOGF2_EN)
77 
79 
80 #if defined(DATALOGF2_EN)
81 #define DATA_LOG_BUFF_SIZE 200 // Must be intergral times of (20)
82 #define DATA_SIZE_EXT 2 //
83 
84 #define DATA_LOG_BUFF_NUM 2 // = 2 for F28002x or = 4 for other devices
85 
86 #define DLOG_BURST_SIZE 20 // write 200 to the register for
87  // a burst size of 20
88 
89 #define DLOG_TRANSFER_SIZE (1 + 2* DATA_LOG_BUFF_SIZE / DLOG_BURST_SIZE)
90  // 200->21, 300->32
91 
92 #elif defined(DATALOGI4_EN)
93 #define DATA_LOG_BUFF_SIZE 200 //**20
94 #define DATA_SIZE_EXT 20 //
95 
96 #define DATA_LOG_BUFF_NUM 4 // = 2 for F28002x or = 4 for other devices
97 
98 #define DLOG_BURST_SIZE 20 // write 200 to the register for
99  // a burst size of 20
100 
101 #define DLOG_TRANSFER_SIZE 10 // [(MEM_BUFFER_SIZE/(BURST)]
102 #endif // DATALOGI4_EN
103 
104 #define DLOG_WRAP_SIZE DLOG_TRANSFER_SIZE + 1
105 
106 #define DATA_LOG_SCALE_FACTOR 10 // update every 10 times
107 
108 // **************************************************************************
109 // the typedefs
110 
113 typedef struct _DATALOG_OBJ_
114 {
115 #if defined(DATALOGF2_EN)
116  volatile float32_t *iptr[DATA_LOG_BUFF_NUM];
117 #elif defined(DATALOGI4_EN)
118  volatile int16_t *iptr[DATA_LOG_BUFF_NUM];
119 #endif // DATALOGI4_EN
120 
121  uint16_t cntr;
122  uint16_t size;
123  uint16_t scaleCnt;
124  uint16_t scaleFactor;
125  uint16_t faultCount[DATA_LOG_BUFF_NUM];
126  int16_t maxValue[DATA_LOG_BUFF_NUM];
127  int16_t minValue[DATA_LOG_BUFF_NUM];
128  bool flagEnable[DATA_LOG_BUFF_NUM];
129 } DATALOG_Obj;
130 
133 typedef struct _DATALOG_Obj_ *DATALOG_Handle;
134 
135 // **************************************************************************
136 // the globals
137 #if defined(DATALOGF2_EN)
138 extern float32_t datalogBuff1[DATA_LOG_BUFF_SIZE + DATA_SIZE_EXT];
139 extern float32_t datalogBuff2[DATA_LOG_BUFF_SIZE + DATA_SIZE_EXT];
140 #elif defined(DATALOGI4_EN)
141 extern int16_t datalogBuff1[DATA_LOG_BUFF_SIZE + DATA_SIZE_EXT];
142 extern int16_t datalogBuff2[DATA_LOG_BUFF_SIZE + DATA_SIZE_EXT];
143 extern int16_t datalogBuff3[DATA_LOG_BUFF_SIZE + DATA_SIZE_EXT];
144 extern int16_t datalogBuff4[DATA_LOG_BUFF_SIZE + DATA_SIZE_EXT];
145 #endif // DATALOGI4_EN
146 
149 extern DATALOG_Obj datalog;
151 
152 // **************************************************************************
153 // the globals
154 
155 // **************************************************************************
156 // the function prototypes
157 
160 extern DATALOG_Handle DATALOGIF_init(void *pMemory, const size_t numBytes);
161 
164 static inline bool DATALOGIF_enable(DATALOG_Handle handle)
165 {
166  DATALOG_Obj *obj = (DATALOG_Obj *)handle;
167  bool enableFlag = false;
168 
169  obj->scaleCnt++;
170 
171  if(obj->scaleCnt >= obj->scaleFactor)
172  {
173  enableFlag = true;
174  obj->scaleCnt = 0;
175  }
176 
177  return(enableFlag);
178 }
179 
180 
183 static inline void DATALOGIF_setPrescalar(DATALOG_Handle handle, uint16_t prescalar)
184 {
185  DATALOG_Obj *obj = (DATALOG_Obj *)handle;
186 
187  obj->scaleFactor = prescalar;
188 
189  return;
190 }
191 
194 static inline void DATALOGIF_update(DATALOG_Handle handle)
195 {
196  DATALOG_Obj *obj = (DATALOG_Obj *)handle;
197 
198  obj->scaleCnt++;
199 
200  if(obj->scaleCnt >= obj->scaleFactor)
201  {
202  if(obj->cntr >= obj->size)
203  {
204  obj->cntr = 0;
205  }
206 
207 #if defined(DATALOGF2_EN)
208  datalogBuff1[obj->cntr] = (*obj->iptr[0]);
209  datalogBuff2[obj->cntr] = (*obj->iptr[1]);
210 #elif defined(DATALOGI4_EN)
211  datalogBuff1[obj->cntr] = (*obj->iptr[0]);
212  datalogBuff2[obj->cntr] = (*obj->iptr[1]);
213  datalogBuff3[obj->cntr] = (*obj->iptr[2]);
214  datalogBuff4[obj->cntr] = (*obj->iptr[3]);
215 #endif // DATALOGI4_EN
216 
217  obj->cntr++;
218  obj->scaleCnt = 0;
219  }
220 
221  return;
222 }
223 
226 static inline void DATALOGIF_updateWithDMA(DATALOG_Handle handle)
227 {
228  DATALOG_Obj *obj = (DATALOG_Obj *)handle;
229 
230  uint16_t number = obj->size - 1;
231 
232 #if defined(DATALOGF2_EN)
233  datalogBuff1[obj->size] = (*obj->iptr[0]);
234  datalogBuff1[number] = (*obj->iptr[0]);
235  datalogBuff2[obj->size] = (*obj->iptr[1]);
236  datalogBuff2[number] = (*obj->iptr[1]);
237 #elif defined(DATALOGI4_EN)
238  datalogBuff1[obj->size] = (*obj->iptr[0]);
239 
240  if((datalogBuff1[number] > obj->maxValue[0]) ||
241  (datalogBuff1[number] < obj->minValue[0]))
242  {
243  obj->faultCount[0]++;
244  }
245 
246  datalogBuff2[obj->size] = (*obj->iptr[1]);
247 
248  if((datalogBuff2[number] > obj->maxValue[1]) ||
249  (datalogBuff2[number] < obj->minValue[1]))
250  {
251  obj->faultCount[1]++;
252  }
253 
254  datalogBuff3[obj->size] = (*obj->iptr[2]);
255 
256  if((datalogBuff3[number] > obj->maxValue[2]) ||
257  (datalogBuff3[number] < obj->minValue[2]))
258  {
259  obj->faultCount[2]++;
260  }
261 
262  datalogBuff4[obj->size] = (*obj->iptr[3]);
263 
264  if((datalogBuff4[number] > obj->maxValue[3]) ||
265  (datalogBuff4[number] < obj->minValue[3]))
266  {
267  obj->faultCount[3]++;
268  }
269 #endif // DATALOGI4_EN
270 
271  return;
272 }
273 #endif // DATALOGI4_EN || DATALOGF2_EN
274 
275 //*****************************************************************************
276 //
277 // Close the Doxygen group.
279 //
280 //*****************************************************************************
281 
282 //*****************************************************************************
283 //
284 // Mark the end of the C bindings section for C++ compilers.
285 //
286 //*****************************************************************************
287 #ifdef __cplusplus
288 }
289 #endif
290 
291 #endif // end of DATALOG_H definition
292 
datalog
DATALOG_Obj datalog
Defines the DATALOG object.
DATALOG_Obj
struct _DATALOG_OBJ_ DATALOG_Obj
Defines the data logging (DATALOG) object.
float32_t
float float32_t
Definition: sfra_f32.h:42
_DATALOG_OBJ_::iptr
float32_t * iptr[4]
Input: First input pointer.
Definition: datalog.h:91
DATA_LOG_BUFF_NUM
#define DATA_LOG_BUFF_NUM
Definition: datalog.h:62
DATALOG_Handle
struct _DATALOG_Obj_ * DATALOG_Handle
Defines the DATALOG handle.
Definition: datalog.h:101
_DATALOG_OBJ_::size
uint16_t size
Parameter: Maximum data buffer.
Definition: datalog.h:96
datalogBuff2
float32_t datalogBuff2[400+2]
math.h
DATA_LOG_BUFF_SIZE
#define DATA_LOG_BUFF_SIZE
Definition: datalog.h:64
_DATALOG_OBJ_
Defines the data logging (DATALOG) object.
Definition: datalog.h:89
datalogBuff1
float32_t datalogBuff1[400+2]
_DATALOG_OBJ_::cntr
uint16_t cntr
Variable: Data log counter.
Definition: datalog.h:95
datalogHandle
DATALOG_Handle datalogHandle
datalogBuff3
float32_t datalogBuff3[400+2]
datalogBuff4
float32_t datalogBuff4[400+2]

Copyright 2023, Texas Instruments Incorporated