AM263x Motor Control SDK  09.02.00
dcl_mlog.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 #ifndef _DCL_MLOG_H_
34 #define _DCL_MLOG_H_
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
48 #include "dcl_fdlog.h"
49 #include "../dcl_common.h"
50 
53 #define MLOG_CHANS 4
54 
57 typedef enum dcl_mlog_states
58 {
60  MLOG_IDLE = 1,
61  MLOG_ARMED = 2,
65 
68 typedef _DCL_VOLATILE struct dcl_mlog
69 {
74  uint32_t tScale;
75  uint32_t sCount;
76  uint32_t mode;
78 
82 #define MLOG_DEFAULTS { { FDLOG_DEFAULTS, FDLOG_DEFAULTS, FDLOG_DEFAULTS, FDLOG_DEFAULTS }, \
83  { 0x0, 0x0, 0x0, 0x0 }, \
84  0.1, -0.1, 1, 1, MLOG_invalid }
85 
96 void DCL_initMLOG(DCL_MLOG *q, float32_t *addr, uint32_t size, float32_t tmax, float32_t tmin, uint32_t div)
97 {
98  int i;
99  for (i = 0; i < MLOG_CHANS; i++)
100  {
101  // assign and clear capture frame, and initialize index to end of lead frame
102  DCL_initLog(&(q->captFrame[i]), (addr + i*size), size);
103  DCL_clearLog(&(q->captFrame[i]));
104  }
105 
106  q->trigMax = tmax;
107  q->trigMin = tmin;
108  q->tScale = div;
109  q->sCount = div;
110  q->mode = MLOG_IDLE;
111 }
112 
119 {
120  int i;
121  for (i = 0; i < MLOG_CHANS; i++)
122  {
123  DCL_clearLog(&(q->captFrame[i]));
124  }
125 
126  q->mode = MLOG_IDLE;
127 }
128 
135 uint16_t DCL_armMLOG(DCL_MLOG *q)
136 {
137  q->mode = (q->mode == MLOG_IDLE) ? MLOG_ARMED : MLOG_IDLE;
138  return(q->mode);
139 }
140 
147 uint16_t DCL_runMLOG(DCL_MLOG *q)
148 {
149  // skip sample unless counter reaches zero
150  if (--(q->sCount) != 0)
151  {
152  return(q->mode);
153  }
154 
155  int i;
156  switch(q->mode)
157  {
158  // MLOG not initialised
159  case MLOG_INVALID:
160  // idle: do nothing
161  case MLOG_IDLE:
162  // complete: do nothing - results available in capture buffer
163  case MLOG_COMPLETE:
164  default:
165  break;
166 
167  // armed: ready to begin capturing when either trigger threshold is crossed
168  case MLOG_ARMED:
169  // check for trigger condition
170  if ((*(q->data[0]) > q->trigMax) || (*(q->data[0]) < q->trigMin))
171  {
172  for (i = 0; i < MLOG_CHANS; i++)
173  {
174  DCL_writeLog(&(q->captFrame[i]), *(q->data[i]));
175  }
176  q->mode = MLOG_CAPTURE;
177  }
178  break;
179 
180  // capture mode: acquiring data
181  case MLOG_CAPTURE:
182  // check for full capture frame
183  if (q->captFrame[0].dptr == q->captFrame[0].fptr)
184  {
185  q->mode = MLOG_COMPLETE;
186  }
187  else
188  {
189  // log data channels
190  for (i = 0; i < MLOG_CHANS; i++)
191  {
192  DCL_writeLog(&(q->captFrame[i]), *(q->data[i]));
193  }
194  }
195  break;
196  }
197  q->sCount = q->tScale;
198  return(q->mode);
199 }
200 
203 #ifdef __cplusplus
204 }
205 #endif // extern "C"
206 
207 #endif // _DCL_MLOG_H_
dcl_mlog::trigMax
float32_t trigMax
Upper trigger threshold.
Definition: dcl_mlog.h:72
dcl_mlog::data
float32_t * data[MLOG_CHANS]
Data channel pointers.
Definition: dcl_mlog.h:71
DCL_mlog_states
DCL_mlog_states
Enumerated MLOG operating modes.
Definition: dcl_mlog.h:58
MLOG_COMPLETE
@ MLOG_COMPLETE
Full data frame captured and available for read-out.
Definition: dcl_mlog.h:63
DCL_resetMLOG
_DCL_CODE_ACCESS void DCL_resetMLOG(DCL_MLOG *q)
Resets the MLOG module: clears all frame buffers and sets idle mode.
Definition: dcl_mlog.h:118
DCL_writeLog
_DCL_CODE_ACCESS float32_t DCL_writeLog(DCL_FDLOG *buf, float32_t data)
Writes a data point into the buffer and advances the indexing pointer, wrapping if necessary....
Definition: dcl_fdlog.h:183
MLOG_ARMED
@ MLOG_ARMED
Armed: capturing monitor frame data and waiting for trigger.
Definition: dcl_mlog.h:61
DCL_initLog
_DCL_CODE_ACCESS void DCL_initLog(DCL_FDLOG *buf, float32_t *addr, uint32_t size)
Assigns the buffer pointers to a memory block or array and sets the data index pointer to the first a...
Definition: dcl_fdlog.h:165
dcl_mlog::captFrame
DCL_FDLOG captFrame[MLOG_CHANS]
Capture data frames.
Definition: dcl_mlog.h:70
DCL_MLOG
_DCL_VOLATILE struct dcl_mlog DCL_MLOG
_DCL_CODE_ACCESS
#define _DCL_CODE_ACCESS
Defines the scope of dcl functions.
Definition: dcl_common.h:63
DCL_runMLOG
_DCL_CODE_ACCESS uint16_t DCL_runMLOG(DCL_MLOG *q)
Runs the MLOG module.
Definition: dcl_mlog.h:147
MLOG_IDLE
@ MLOG_IDLE
Memory initialised but module not armed.
Definition: dcl_mlog.h:60
DCL_clearLog
#define DCL_clearLog(buf)
Clears the buffer contents by writing 0 to all elements and resets the data index pointer to the star...
Definition: dcl_fdlog.h:155
MLOG_INVALID
@ MLOG_INVALID
Buffer pointers not initialised.
Definition: dcl_mlog.h:59
DCL_armMLOG
_DCL_CODE_ACCESS uint16_t DCL_armMLOG(DCL_MLOG *q)
Changes the MLOG mode to "MLOG_ARMED". Only valid if current operating mode is "MLOG_IDLE".
Definition: dcl_mlog.h:135
dcl_mlog::trigMin
float32_t trigMin
Lower trigger threshold.
Definition: dcl_mlog.h:73
dcl_mlog::sCount
uint32_t sCount
Sample counter.
Definition: dcl_mlog.h:75
MLOG
_DCL_VOLATILE struct dcl_mlog MLOG
DCL_FDLOG
_DCL_VOLATILE struct dcl_fdlog DCL_FDLOG
DCL_initMLOG
_DCL_CODE_ACCESS void DCL_initMLOG(DCL_MLOG *q, float32_t *addr, uint32_t size, float32_t tmax, float32_t tmin, uint32_t div)
Initializes the MLOG module.
Definition: dcl_mlog.h:96
MLOG_CHANS
#define MLOG_CHANS
Defines the number of MLOG channels.
Definition: dcl_mlog.h:53
_DCL_VOLATILE
#define _DCL_VOLATILE
Defines volatile for DCL strctures.
Definition: dcl_common.h:79
MLOG_CAPTURE
@ MLOG_CAPTURE
Triggered: logging data into capture frame.
Definition: dcl_mlog.h:62
dcl_mlog
Defines the MLOG structure.
Definition: dcl_mlog.h:69
dcl_fdlog.h
Defines a 32-bit floating-point data logger strcture and related functions.
dcl_mlog::mode
uint32_t mode
Operating mode.
Definition: dcl_mlog.h:76
float32_t
float float32_t
Definition: dcl_common.h:58
dcl_mlog::tScale
uint32_t tScale
Number of samples per log write.
Definition: dcl_mlog.h:74