AM263x Motor Control SDK  09.02.00
dcl_fdlog.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_FDLOG_H_
34 #define _DCL_FDLOG_H_
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
70 #include "../dcl_common.h"
71 
74 typedef _DCL_VOLATILE struct dcl_fdlog
75 {
79  uint32_t size;
81 
82 /******************** macro definitions ********************/
85 #define FDLOG_DEFAULTS {0x0,0x0,0x0,0}
86 
92 #define DCL_getLogSize(buf) ((buf)->size)
93 
99 #define DCL_getLogIndex(buf) ((uint32_t)((buf)->dptr - (buf)->fptr))
100 
106 #define DCL_getLogRemain(buf) ((int32_t)((buf)->lptr - (buf)->dptr))
107 
108 /******************** inline functions ********************/
109 
116 void DCL_setLogIndex(DCL_FDLOG *buf, uint32_t idx)
117 {
118  if(idx < buf->size)
119  {
120  buf->dptr = buf->fptr + idx;
121  }
122 }
123 
129 void DCL_deleteLog(DCL_FDLOG *buf) { buf->dptr = buf->fptr = buf->lptr = NULL; buf->size = 0; }
130 
135 void DCL_resetLog(DCL_FDLOG *buf) { buf->dptr = buf->fptr; }
136 
145 {
146  uint32_t size = DCL_getLogSize(buf);
147  float32_t* mem = buf->fptr;
148  DCL_resetLog(buf);
149  while (size--) *mem++ = data;
150 }
151 
155 #define DCL_clearLog(buf) DCL_fillLog(buf,0.0f)
156 
165 void DCL_initLog(DCL_FDLOG *buf, float32_t *addr, uint32_t size)
166 {
167  buf->size = size;
168  buf->fptr = addr;
169  buf->lptr = addr + size - 1;
170  DCL_resetLog(buf);
171 }
172 
184 {
185  // save existing data
186  float32_t rv = *(buf->dptr);
187 
188  // write new data to log
189  *(buf->dptr++) = data;
190 
191  // check for end of buffer & wrap if necessary
192  if (buf->dptr > buf->lptr) DCL_resetLog(buf);
193 
194  return(rv);
195 }
196 
205 {
206  float32_t rv = *(buf->dptr++);
207 
208  // check for end of buffer & wrap if necessary
209  if (buf->dptr > buf->lptr) DCL_resetLog(buf);
210 
211  return(rv);
212 }
213 
222 {
223  uint32_t size = DCL_getLogSize(src);
224  if (size != DCL_getLogSize(dst))
225  {
226  return;
227  }
228 
229  float32_t* src_ptr = src->fptr;
230  float32_t* dst_ptr = dst->fptr;
231  while (size--) *(dst_ptr++) = *(src_ptr++);
232  DCL_setLogIndex(dst, DCL_getLogIndex(src));
233 }
234 
237 #ifdef __cplusplus
238 }
239 #endif // extern "C"
240 
241 #endif // _DCL_FDLOG_H_
242 
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
DCL_resetLog
_DCL_CODE_ACCESS void DCL_resetLog(DCL_FDLOG *buf)
Resets the data index pointer to start of buffer.
Definition: dcl_fdlog.h:135
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_fdlog::lptr
float32_t * lptr
Pointer to last buffer element.
Definition: dcl_fdlog.h:77
FDLOG
_DCL_VOLATILE struct dcl_fdlog FDLOG
dcl_fdlog::dptr
float32_t * dptr
Current data index pointer.
Definition: dcl_fdlog.h:78
_DCL_CODE_ACCESS
#define _DCL_CODE_ACCESS
Defines the scope of dcl functions.
Definition: dcl_common.h:63
DCL_getLogSize
#define DCL_getLogSize(buf)
Obtain the total size of buffer.
Definition: dcl_fdlog.h:92
DCL_readLog
_DCL_CODE_ACCESS float32_t DCL_readLog(DCL_FDLOG *buf)
Reads a data point from the buffer and then advances the indexing pointer, wrapping if necessary.
Definition: dcl_fdlog.h:204
DCL_fillLog
_DCL_CODE_ACCESS void DCL_fillLog(DCL_FDLOG *buf, float32_t data)
Fills the buffer with a given data value and resets the data index pointer to the start of the buffer...
Definition: dcl_fdlog.h:144
dcl_fdlog
Defines the data logger strcture for 32-bit float.
Definition: dcl_fdlog.h:75
DCL_getLogIndex
#define DCL_getLogIndex(buf)
Index of the current pointer (zero-indexed)
Definition: dcl_fdlog.h:99
DCL_setLogIndex
_DCL_CODE_ACCESS void DCL_setLogIndex(DCL_FDLOG *buf, uint32_t idx)
Sets index of the current pointer (zero-indexed)
Definition: dcl_fdlog.h:116
DCL_FDLOG
_DCL_VOLATILE struct dcl_fdlog DCL_FDLOG
_DCL_VOLATILE
#define _DCL_VOLATILE
Defines volatile for DCL strctures.
Definition: dcl_common.h:79
dcl_fdlog::fptr
float32_t * fptr
Pointer to first buffer element.
Definition: dcl_fdlog.h:76
DCL_deleteLog
_DCL_CODE_ACCESS void DCL_deleteLog(DCL_FDLOG *buf)
Resets all structure pointers to null value.
Definition: dcl_fdlog.h:129
dcl_fdlog::size
uint32_t size
The size of buffer.
Definition: dcl_fdlog.h:79
DCL_copyLog
_DCL_CODE_ACCESS void DCL_copyLog(DCL_FDLOG *src, DCL_FDLOG *dst)
Copies the contents of one log (src) into another (dst). Both logs must have the same size.
Definition: dcl_fdlog.h:221
float32_t
float float32_t
Definition: dcl_common.h:58
NULL
#define NULL
Definition: dcl_macro.h:50