AM263x Digital Power SDK  09.01.00
dcl_fdlog.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2023 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 {
78  uint32_t size;
80 
81 /******************** macro definitions ********************/
82 
88 #define DCL_getLogSize(buf) ((buf)->size)
89 
95 #define DCL_getLogIndex(buf) ((uint32_t)((buf)->dptr - (buf)->fptr))
96 
102 #define DCL_getLogRemain(buf) ((buf)->size - DCL_getLogIndex(buf))
103 
110 void DCL_setLogIndex(DCL_FDLOG *buf, uint32_t idx)
111 {
112  if(idx < buf->size)
113  {
114  buf->dptr = buf->fptr + idx;
115  }
116 }
117 
118 /******************** inline functions ********************/
119 
125 void DCL_deleteLog(DCL_FDLOG *buf) { buf->dptr = buf->fptr = NULL; buf->size = 0; }
126 
131 void DCL_resetLog(DCL_FDLOG *buf) { buf->dptr = buf->fptr; }
132 
141 {
142  uint32_t length = DCL_getLogSize(buf);
143  float32_t* mem = buf->fptr;
144  DCL_resetLog(buf);
145  while (length--) *mem++ = data;
146 }
147 
151 #define DCL_clearLog(buf) DCL_fillLog(buf,0)
152 
161 void DCL_initLog(DCL_FDLOG *buf, float32_t *addr, uint32_t size)
162 {
163  buf->fptr = addr;
164  buf->size = size;
165  DCL_resetLog(buf);
166 }
167 
179 {
180  // save existing data
181  float32_t rv = *(buf->dptr);
182 
183  // write new data to log
184  *(buf->dptr++) = data;
185 
186  // check for end of buffer & wrap if necessary
187  if (DCL_getLogIndex(buf) > (buf->size - 1)) DCL_resetLog(buf);
188 
189  return(rv);
190 }
191 
200 {
201  float32_t rv = *(buf->dptr++);
202 
203  // check for end of buffer & wrap if necessary
204  if (DCL_getLogIndex(buf) > (buf->size - 1)) DCL_resetLog(buf);
205 
206  return(rv);
207 }
208 
217 {
218  uint32_t length = DCL_getLogSize(src);
219  if (length != DCL_getLogSize(dst))
220  {
221  return;
222  }
223 
224  float32_t* src_ptr = src->fptr;
225  float32_t* dst_ptr = dst->fptr;
226  while (length--) *(dst_ptr++) = *(src_ptr++);
227  DCL_setLogIndex(dst, DCL_getLogIndex(src));
228 }
229 
232 #ifdef __cplusplus
233 }
234 #endif // extern "C"
235 
236 #endif // _DCL_FDLOG_H_
237 
238 /* end of file */
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:178
DCL_resetLog
_DCL_CODE_ACCESS void DCL_resetLog(DCL_FDLOG *buf)
Resets the data index pointer to start of buffer.
Definition: dcl_fdlog.h:131
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:161
dcl_fdlog::dptr
float32_t * dptr
Current data index pointer.
Definition: dcl_fdlog.h:77
_DCL_CODE_ACCESS
#define _DCL_CODE_ACCESS
Defines the scope of dcl functions (static inline/extern inline/none)
Definition: dcl_common.h:58
DCL_getLogSize
#define DCL_getLogSize(buf)
Obtain the total size of buffer.
Definition: dcl_fdlog.h:88
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:199
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:140
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:95
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:110
DCL_FDLOG
_DCL_VOLATILE struct dcl_fdlog DCL_FDLOG
_DCL_VOLATILE
#define _DCL_VOLATILE
Defines volatile for DCL strctures Flags can be defined in dcl.h or user files before including DCL l...
Definition: dcl_common.h:71
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:125
dcl_fdlog::size
uint32_t size
The size of buffer.
Definition: dcl_fdlog.h:78
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 length.
Definition: dcl_fdlog.h:216
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
NULL
#define NULL
Definition: dcl_aux.h:50