MotorWare f2806x Module API Documentation
float/filter_fo.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2013, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the 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 "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
37 
38 
39 // **************************************************************************
40 // the includes
41 
43 
44 
45 
46 // **************************************************************************
47 // the defines
48 
49 
50 #ifdef __TMS320C28XX_CLA__
51 #pragma CODE_SECTION(FILTER_FO_getDenCoeffs,"Cla1Prog2");
52 #pragma CODE_SECTION(FILTER_FO_getInitialConditions,"Cla1Prog2");
53 #pragma CODE_SECTION(FILTER_FO_getNumCoeffs,"Cla1Prog2");
54 #pragma CODE_SECTION(FILTER_FO_init,"Cla1Prog2");
55 #pragma CODE_SECTION(FILTER_FO_setDenCoeffs,"Cla1Prog2");
56 #pragma CODE_SECTION(FILTER_FO_setInitialConditions,"Cla1Prog2");
57 #pragma CODE_SECTION(FILTER_FO_setNumCoeffs,"Cla1Prog2");
58 #endif
59 
60 
61 // **************************************************************************
62 // the globals
63 
64 
65 // **************************************************************************
66 // the functions
67 
68 
70 {
71  FILTER_FO_Obj *obj = (FILTER_FO_Obj *)handle;
72 
73 
74  *pa1 = obj->a1;
75 
76  return;
77 } // end of FILTER_FO_getDenCoeffs() function
78 
79 
81 {
82  FILTER_FO_Obj *obj = (FILTER_FO_Obj *)handle;
83 
84 
85  *px1 = obj->x1;
86 
87  *py1 = obj->y1;
88 
89  return;
90 } // end of FILTER_FO_getInitialConditions() function
91 
92 
94 {
95  FILTER_FO_Obj *obj = (FILTER_FO_Obj *)handle;
96 
97 
98  *pb0 = obj->b0;
99  *pb1 = obj->b1;
100 
101  return;
102 } // end of FILTER_FO_getNumCoeffs() function
103 
104 
105 FILTER_FO_Handle FILTER_FO_init(void *pMemory,const size_t numBytes)
106 {
107  FILTER_FO_Handle handle;
108 
109 
110  if((int16_t)numBytes < (int16_t)sizeof(FILTER_FO_Obj))
111  {
112  /*LDRA_INSPECTED 95 S MR12 11.3 "Below typecasting to NULL has no issues"*/
113  return((FILTER_FO_Handle)NULL);
114  }
115  // assign the handle
116  /*LDRA_INSPECTED 94 S MR12 11.3 "Below typecasting to void * has no issues"*/
117  /*LDRA_INSPECTED 95 S MR12 11.3 "Below typecasting to void * no issues"*/
118  handle = (FILTER_FO_Handle)pMemory;
119 
120  /*LDRA_INSPECTED 71 S MR12 11.3 "Always, address of a static object is passed, so ok for wider scope"*/
121  return(handle);
122 } // end of FILTER_FO_init() function
123 
124 
126 {
127  FILTER_FO_Obj *obj = (FILTER_FO_Obj *)handle;
128 
129 
130  obj->a1 = a1;
131 
132  return;
133 } // end of FILTER_FO_setDenCoeffs() function
134 
135 
137 {
138  FILTER_FO_Obj *obj = (FILTER_FO_Obj *)handle;
139 
140 
141  obj->x1 = x1;
142 
143  obj->y1 = y1;
144 
145  return;
146 } // end of FILTER_FO_setInitialConditions() function
147 
148 
150 {
151  FILTER_FO_Obj *obj = (FILTER_FO_Obj *)handle;
152 
153 
154  obj->b0 = b0;
155  obj->b1 = b1;
156 
157  return;
158 } // end of FILTER_FO_setNumCoeffs() function
159 
160 
161 // end of file
162 
163 
164 
Contains the public interface to the first-order filter (FILTER_FO) module routines.
_iq b1
the numerator filter coefficient value for z^(-1)
Definition: 32b/filter_fo.h:76
_iq a1
the denominator filter coefficient value for z^(-1)
Definition: 32b/filter_fo.h:73
void FILTER_FO_getInitialConditions(FILTER_FO_Handle handle, float_t *px1, float_t *py1)
Gets the initial conditions of the first-order filter.
void FILTER_FO_getNumCoeffs(FILTER_FO_Handle handle, float_t *pb0, float_t *pb1)
Gets the first-order filter numerator coefficients.
struct _FILTER_FO_Obj_ * FILTER_FO_Handle
Defines the first-order filter (FILTER_FO) handle.
Definition: 32b/filter_fo.h:86
Defines the first-order filter (FILTER_FO) object.
Definition: 32b/filter_fo.h:71
_iq x1
the input value at time sample n=-1
Definition: 32b/filter_fo.h:78
FILTER_FO_Handle FILTER_FO_init(void *pMemory, const size_t numBytes)
Initializes the first-order filter.
void FILTER_FO_setNumCoeffs(FILTER_FO_Handle handle, const float_t b0, const float_t b1)
Sets the first-order filter numerator coefficients.
void FILTER_FO_getDenCoeffs(FILTER_FO_Handle handle, float_t *pa1)
Gets the first-order filter denominator coefficients.
_iq b0
the numerator filter coefficient value for z^0
Definition: 32b/filter_fo.h:75
void FILTER_FO_setDenCoeffs(FILTER_FO_Handle handle, const float_t a1)
Sets the first-order filter denominator coefficients.
_iq y1
the output value at time sample n=-1
Definition: 32b/filter_fo.h:80
void FILTER_FO_setInitialConditions(FILTER_FO_Handle handle, const float_t x1, const float_t y1)
Sets the initial conditions of the first-order filter.
Defines the first-order filter (FILTER_FO) object.
float float_t
Defines the portable data type for 32 bit, signed floating-point data.
Definition: types.h:121