AM263x Digital Power SDK  09.01.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 
70 #ifdef __cplusplus
71 extern "C" {
72 #endif
73 
74 
75 // **************************************************************************
76 // the defines
77 
78 typedef enum
79 {
80  manual, //Manual trigger when user provides True for flag_enableLogData/flag_enableLogOneShot
81  auto_trigger // when *iptr[0] crosses the trigger value data logging will be enabled
83 
84 
85 
88 #define DATALOG_DEFAULTS { \
89  {NULL, \
90  NULL, \
91  NULL, \
92  NULL}, \
93  true, \
94  false, \
95  0, \
96  DATA_LOG_BUFF_SIZE \
97  }
98 
99 // **************************************************************************
100 // the typedefs
101 
104 typedef struct _DATALOG_OBJ_
105 {
106 
107 #ifdef u_int32_t
108  int32_t datalogBuff[DATA_LOG_BUFF_NUM][DATA_LOG_BUFF_SIZE];
109  int32_t *iptr[DATA_LOG_BUFF_NUM];
110  int32_t prev_value;
111  int32_t trigValue;
112 #endif
113 
114 #ifdef u_uint32_t
115  uint32_t datalogBuff[DATA_LOG_BUFF_NUM][DATA_LOG_BUFF_SIZE];
116  uint32_t *iptr[DATA_LOG_BUFF_NUM];
117  uint32_t prev_value;
118  uint32_t trigValue;
119 #endif
120 
121 #ifdef u_int64_t
122  int64_t datalogBuff[DATA_LOG_BUFF_NUM][DATA_LOG_BUFF_SIZE];
123  int64_t *iptr[DATA_LOG_BUFF_NUM];
124  int64_t prev_value;
125  int64_t trigValue;
126 #endif
127 
128 #ifdef u_float64_t
131  float64_t prev_value;
132  float64_t trigValue;
133 #endif
134 
135 #ifdef u_float32_t
138  float32_t prev_value;
139  float32_t trigValue;
140 #endif
141 
142 #ifdef u_int16_t
143  int16_t datalogBuff[DATA_LOG_BUFF_NUM][DATA_LOG_BUFF_SIZE];
144  int16_t *iptr[DATA_LOG_BUFF_NUM];
145  int16_t prev_value;
146  int16_t trigValue;
147 #endif
148 
149 #ifdef u_uint16_t
150  uint16_t datalogBuff[DATA_LOG_BUFF_NUM][DATA_LOG_BUFF_SIZE];
151  uint16_t *iptr[DATA_LOG_BUFF_NUM];
152  uint16_t prev_value;
153  uint16_t trigValue;
154 #endif
155 
156 #ifdef u_int8_t
157  int8_t datalogBuff[DATA_LOG_BUFF_NUM][DATA_LOG_BUFF_SIZE];
158  int8_t *iptr[DATA_LOG_BUFF_NUM];
159  int8_t prev_value;
160  int8_t trigValue;
161 #endif
162 
163 #ifdef u_uint8_t
164  uint8_t datalogBuff[DATA_LOG_BUFF_NUM][DATA_LOG_BUFF_SIZE];
165  uint8_t *iptr[DATA_LOG_BUFF_NUM];
166  uint8_t prev_value;
167  uint8_t trigValue;
168 #endif
169 
170  int32_t cntr;
171  int32_t size;
172  int32_t skipCount;
173  int32_t preScalar;
174  int32_t status;
175  int32_t trigger;
178 } DATALOG_Obj;
179 
182 typedef struct _DATALOG_Obj_ *DATALOG_Handle;
183 
184 
187 extern DATALOG_Obj datalog;
189 
190 // **************************************************************************
191 // the globals
192 
193 // **************************************************************************
194 // the function prototypes
195 
202 extern DATALOG_Handle DATALOG_init(void *pMemory, const size_t numBytes, Trigger_type trigger, float32_t trig_value, int32_t scale);
203 
206 static inline void DATALOG_update(DATALOG_Handle handle)
207 {
208  DATALOG_Obj *obj = (DATALOG_Obj *)handle;
209 
210  if(obj->trigger == manual)
211  {
212  if(obj->flag_enableLogData == true)
213  {
214  obj->skipCount++;
215  if(obj->skipCount == obj->preScalar)
216  {
217  obj->skipCount = 0;
218 
219  if(obj->cntr >= obj->size)
220  {
221  obj->cntr = 0;
222  if(obj->flag_enableLogOneShot == true)
223  {
224 
225  obj->flag_enableLogData = false;
226  obj->flag_enableLogOneShot = false;
227  }
228  }
229  else {
230  for(int temp1 = 0; temp1 < DATA_LOG_BUFF_NUM; temp1++)
231  {
232  obj->datalogBuff[temp1][obj->cntr] = (*obj->iptr[temp1]);
233  }
234  }
235  obj->cntr++;
236  }
237  }
238  else if(obj->flag_enableLogOneShot == true)
239  {
240  obj->flag_enableLogData = true;
241  obj->cntr = 0;
242  }
243 
244  }
245 
246  else if (obj->trigger == auto_trigger)
247  {
248  switch(obj->status)
249  {
250  //
251  // wait for trigger
252  //
253  case 1:
254  if(*obj->iptr[0] > obj->trigValue && obj->prev_value <= obj->trigValue)
255  {
256  // rising edge detected start logging data
257  obj->status=2;
258  }
259  break;
260  case 2:
261  obj->skipCount++;
262  if(obj->skipCount==obj->preScalar)
263  {
264  obj->skipCount=0;
265  for(int temp1 = 0; temp1 < DATA_LOG_BUFF_NUM; temp1++)
266  {
267  obj->datalogBuff[temp1][obj->cntr] = (*obj->iptr[temp1]);
268  }
269  obj->cntr++;
270  if(obj->cntr == obj->size)
271  {
272  obj->cntr = 0;
273  obj->status = 1;
274  }
275  }
276  break;
277  }
278  }
279 
280  obj-> prev_value = *obj->iptr[0];
281 }
282 
283 #ifdef __cplusplus
284 }
285 #endif // extern "C"
286 
289 #endif // end of DATALOG_H definition
290 
datalog
DATALOG_Obj datalog
Defines the DATALOG object.
Definition: datalog.c:49
manual
@ manual
Definition: datalog.h:80
DATALOG_Obj::flag_enableLogData
bool flag_enableLogData
Manual trigger usage - For datalog to be initiated always to be true.
Definition: datalog.h:176
DATALOG_Obj::trigger
int32_t trigger
Trigger value used for Auto triger type.
Definition: datalog.h:175
DATALOG_update
static void DATALOG_update(DATALOG_Handle handle)
Updates the data logger.
Definition: datalog.h:206
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:173
DATALOG_Obj::status
int32_t status
Status of auto trigger type state machine.
Definition: datalog.h:174
DATALOG_Obj::size
int32_t size
Parameter: Maximum data buffer.
Definition: datalog.h:171
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:182
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:105
Trigger_type
Trigger_type
Definition: datalog.h:79
DATALOG_Obj::skipCount
int32_t skipCount
used for prescalar counter
Definition: datalog.h:172
DATALOG_Obj::cntr
int32_t cntr
Variable: Data log counter.
Definition: datalog.h:170
float64_t
double float64_t
Definition: dcl_common.h:55
auto_trigger
@ auto_trigger
Definition: datalog.h:81
DATALOG_Obj::flag_enableLogOneShot
bool flag_enableLogOneShot
Manual trigger usage - For datalog once this need to be true.
Definition: datalog.h:177
float32_t
float float32_t
Defines single,double precision data type. Note: Assumes ABI to be TI_EABI, does not support legacy T...
Definition: dcl_common.h:54