AM263x Motor Control SDK  09.02.00
datalog.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2024 Texas Instruments Incorporated
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the
14  * distribution.
15  *
16  * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 //#############################################################################
33 
34 #ifndef DATALOG_H
35 #define DATALOG_H
36 
40 
41 // **************************************************************************
42 // the includes
43 
44 #include <stdlib.h>
45 #include <stdbool.h>
46 #include <stdint.h>
47 
48 #include <datalog_input.h> //User configured macros as input
49 
50 #ifndef IEEE754_TYPES
51 #define IEEE754_TYPES
52 
53 typedef float float32_t;
54 typedef double float64_t;
55 
56 #endif //IEEE754_TYPES
57 
66 #ifdef __cplusplus
67 extern "C" {
68 #endif
69 
70 
71 // **************************************************************************
72 // the defines
73 
74 typedef enum
75 {
76  manual, //Manual trigger when user provides True for flag_enableLogData/flag_enableLogOneShot
77  auto_trigger // when *iptr[0] crosses the trigger value data logging will be enabled
79 
80 
81 
84 #define DATALOG_DEFAULTS { \
85  {NULL, \
86  NULL, \
87  NULL, \
88  NULL}, \
89  true, \
90  false, \
91  0, \
92  DATA_LOG_BUFF_SIZE \
93  }
94 
95 // **************************************************************************
96 // the typedefs
97 
100 typedef struct _DATALOG_OBJ_
101 {
102 
103 #ifdef u_int32_t
104  int32_t datalogBuff[DATA_LOG_BUFF_NUM][DATA_LOG_BUFF_SIZE];
105  int32_t *iptr[DATA_LOG_BUFF_NUM];
106  int32_t prev_value;
107  int32_t trigValue;
108 #endif
109 
110 #ifdef u_uint32_t
111  uint32_t datalogBuff[DATA_LOG_BUFF_NUM][DATA_LOG_BUFF_SIZE];
112  uint32_t *iptr[DATA_LOG_BUFF_NUM];
113  uint32_t prev_value;
114  uint32_t trigValue;
115 #endif
116 
117 #ifdef u_int64_t
118  int64_t datalogBuff[DATA_LOG_BUFF_NUM][DATA_LOG_BUFF_SIZE];
119  int64_t *iptr[DATA_LOG_BUFF_NUM];
120  int64_t prev_value;
121  int64_t trigValue;
122 #endif
123 
124 #ifdef u_float64_t
127  float64_t prev_value;
128  float64_t trigValue;
129 #endif
130 
131 #ifdef u_float32_t
134  float32_t prev_value;
135  float32_t trigValue;
136 #endif
137 
138 #ifdef u_int16_t
139  int16_t datalogBuff[DATA_LOG_BUFF_NUM][DATA_LOG_BUFF_SIZE];
140  int16_t *iptr[DATA_LOG_BUFF_NUM];
141  int16_t prev_value;
142  int16_t trigValue;
143 #endif
144 
145 #ifdef u_uint16_t
146  uint16_t datalogBuff[DATA_LOG_BUFF_NUM][DATA_LOG_BUFF_SIZE];
147  uint16_t *iptr[DATA_LOG_BUFF_NUM];
148  uint16_t prev_value;
149  uint16_t trigValue;
150 #endif
151 
152 #ifdef u_int8_t
153  int8_t datalogBuff[DATA_LOG_BUFF_NUM][DATA_LOG_BUFF_SIZE];
154  int8_t *iptr[DATA_LOG_BUFF_NUM];
155  int8_t prev_value;
156  int8_t trigValue;
157 #endif
158 
159 #ifdef u_uint8_t
160  uint8_t datalogBuff[DATA_LOG_BUFF_NUM][DATA_LOG_BUFF_SIZE];
161  uint8_t *iptr[DATA_LOG_BUFF_NUM];
162  uint8_t prev_value;
163  uint8_t trigValue;
164 #endif
165 
166  int32_t cntr;
167  int32_t size;
168  int32_t skipCount;
169  int32_t preScalar;
170  int32_t status;
171  int32_t trigger;
174 } DATALOG_Obj;
175 
178 typedef struct _DATALOG_Obj_ *DATALOG_Handle;
179 
180 
183 extern DATALOG_Obj datalog;
185 
186 // **************************************************************************
187 // the globals
188 
189 // **************************************************************************
190 // the function prototypes
191 
198 extern DATALOG_Handle DATALOG_init(void *pMemory, const size_t numBytes, Trigger_type trigger, float32_t trig_value, int32_t scale);
199 
202 static inline void DATALOG_update(DATALOG_Handle handle)
203 {
204  DATALOG_Obj *obj = (DATALOG_Obj *)handle;
205 
206  if(obj->trigger == manual)
207  {
208  if(obj->flag_enableLogData == true)
209  {
210  obj->skipCount++;
211  if(obj->skipCount == obj->preScalar)
212  {
213  obj->skipCount = 0;
214 
215  if(obj->cntr >= obj->size)
216  {
217  obj->cntr = 0;
218  if(obj->flag_enableLogOneShot == true)
219  {
220 
221  obj->flag_enableLogData = false;
222  obj->flag_enableLogOneShot = false;
223  }
224  }
225  else {
226  for(int temp1 = 0; temp1 < DATA_LOG_BUFF_NUM; temp1++)
227  {
228  obj->datalogBuff[temp1][obj->cntr] = (*obj->iptr[temp1]);
229  }
230  }
231  obj->cntr++;
232  }
233  }
234  else if(obj->flag_enableLogOneShot == true)
235  {
236  obj->flag_enableLogData = true;
237  obj->cntr = 0;
238  }
239 
240  }
241 
242  else if (obj->trigger == auto_trigger)
243  {
244  switch(obj->status)
245  {
246  //
247  // wait for trigger
248  //
249  case 1:
250  if(*obj->iptr[0] > obj->trigValue && obj->prev_value <= obj->trigValue)
251  {
252  // rising edge detected start logging data
253  obj->status=2;
254  }
255  break;
256  case 2:
257  obj->skipCount++;
258  if(obj->skipCount==obj->preScalar)
259  {
260  obj->skipCount=0;
261  for(int temp1 = 0; temp1 < DATA_LOG_BUFF_NUM; temp1++)
262  {
263  obj->datalogBuff[temp1][obj->cntr] = (*obj->iptr[temp1]);
264  }
265  obj->cntr++;
266  if(obj->cntr == obj->size)
267  {
268  obj->cntr = 0;
269  obj->status = 1;
270  }
271  }
272  break;
273  }
274  }
275 
276  obj-> prev_value = *obj->iptr[0];
277 }
278 
279 #ifdef __cplusplus
280 }
281 #endif // extern "C"
282 
285 #endif // end of DATALOG_H definition
286 
datalog
DATALOG_Obj datalog
Defines the DATALOG object.
Definition: datalog.c:49
manual
@ manual
Definition: datalog.h:76
DATALOG_Obj::flag_enableLogData
bool flag_enableLogData
Manual trigger usage - For datalog to be initiated always to be true.
Definition: datalog.h:172
DATALOG_Obj::trigger
int32_t trigger
Trigger value used for Auto triger type.
Definition: datalog.h:171
DATALOG_update
static void DATALOG_update(DATALOG_Handle handle)
Updates the data logger.
Definition: datalog.h:202
datalog_input.h
float64_t
double float64_t
Definition: datalog.h:54
DATA_LOG_BUFF_NUM
#define DATA_LOG_BUFF_NUM
Definition: datalog_input.h:37
DATALOG_Obj::preScalar
int32_t preScalar
Parameter: How many datalog update to be skipped.
Definition: datalog.h:169
DATALOG_Obj::status
int32_t status
Status of auto trigger type state machine.
Definition: datalog.h:170
DATALOG_Obj::size
int32_t size
Parameter: Maximum data buffer.
Definition: datalog.h:167
datalogHandle
DATALOG_Handle datalogHandle
the handle for the Datalog object
Definition: datalog.c:50
float32_t
float float32_t
Definition: datalog.h:53
DATA_LOG_BUFF_SIZE
#define DATA_LOG_BUFF_SIZE
Definition: datalog_input.h:38
DATALOG_Handle
struct _DATALOG_Obj_ * DATALOG_Handle
Defines the DATALOG handle.
Definition: datalog.h:178
DATALOG_init
DATALOG_Handle DATALOG_init(void *pMemory, const size_t numBytes, Trigger_type trigger, float32_t trig_value, int32_t scale)
Initializes the data logger.
Definition: datalog.c:56
DATALOG_Obj
Defines the data logging (DATALOG) object.
Definition: datalog.h:101
Trigger_type
Trigger_type
Definition: datalog.h:75
DATALOG_Obj::skipCount
int32_t skipCount
used for prescalar counter
Definition: datalog.h:168
DATALOG_Obj::cntr
int32_t cntr
Variable: Data log counter.
Definition: datalog.h:166
float64_t
double float64_t
Definition: dcl_common.h:59
auto_trigger
@ auto_trigger
Definition: datalog.h:77
DATALOG_Obj::flag_enableLogOneShot
bool flag_enableLogOneShot
Manual trigger usage - For datalog once this need to be true.
Definition: datalog.h:173
float32_t
float float32_t
Definition: dcl_common.h:58