1 /**
2 * @file tf_utils.h
3 *
4 * @brief
5 * This has defintions internal utility functions for traceframework.
6 *
7 * ============================================================================
8 * @n (C) Copyright 2012-2013, Texas Instruments, Inc.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 *
14 * Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 *
17 * Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the
20 * distribution.
21 *
22 * Neither the name of Texas Instruments Incorporated nor the names of
23 * its contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 *
38 */
40 #ifndef __TF_UTILS_H_
41 #define __TF_UTILS_H_
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
48 #include <string.h>
49 #include "contract_osal.h"
50 #include "consumer.h"
52 /*
53 * ============================================================================
54 * tf_contract_reg32_r
55 *
56 * Description: reads a 32 bit value from the tf_contract to the local variable ptr
57 *
58 * param[in] localVarPtr
59 * Pointer to the local variable
60 *
61 * param[in] globalVarPtr
62 * Pointer to the global variable
63 *
64 * return
65 * none
66 *
67 * =============================================================================
68 */
69 static void tf_contract_reg32_r(uint32_t* localVarPtr, uint32_t* globalVarPtr);
71 /*
72 * ============================================================================
73 * tf_contract_reg32_w
74 *
75 * Description: write a 32 bit value from the local variable to the global memory
76 *
77 * param[in] localVarPtr
78 * Pointer to the local variable
79 *
80 * param[in] globalVarPtr
81 * Pointer to the global variable
82 *
83 * return
84 * none
85 *
86 * =============================================================================
87 */
88 static void tf_contract_reg32_w(uint32_t* localVarPtr, uint32_t* globalVarPtr);
91 /*
92 * ============================================================================
93 * tf_contract_update_bytes
94 *
95 * Description:
96 * write a size bytes to global memory
97 *
98 * param[in] sharedMemAddr
99 * Pointer to the local variable
100 *
101 * param[in] localMemAddr
102 * Pointer to the global variable
103 *
104 * param[in] size
105 * Pointer to the global variable
106 *
107 * return
108 * none
109 *
110 * =============================================================================
111 */
112 static void tf_contract_update_bytes(void* sharedMemAddr, void* localMemAddr, size_t size);
114 /*
115 * ============================================================================
116 * tf_contract_update_smem
117 *
118 * Description:
119 * write a size bytes to global memory
120 *
121 * param[in] sharedMemAddr
122 * Pointer to the local variable
123 *
124 * param[in] localMemAddr
125 * Pointer to the global variable
126 *
127 * param[in] size
128 * Pointer to the global variable
129 *
130 * return
131 * none
132 *
133 * =============================================================================
134 */
135 static void tf_contract_update_smem(void* sharedMemAddr, void* localMemAddr, size_t size);
137 /*
138 * ============================================================================
139 * tf_cons_update_global_lfb
140 *
141 * Description:
142 * increment a variable
143 *
144 * param[in] localVar
145 * local variable
146 *
147 * param[in] globalVar
148 * global variable to be incremented
149 *
150 * param[in] maxSize
151 * decrement value
152 *
153 * return
154 * none
155 *
156 * =============================================================================
157 */
159 static void tf_cons_update_global_lfb(tf_consumer_HANDLE cHandle);
161 /*
162 * ============================================================================
163 * tf_contract_increment_var
164 *
165 * Description:
166 * increment a variable
167 *
168 * param[in] localVar
169 * local variable
170 *
171 * param[in] globalVar
172 * global variable to be incremented
173 *
174 * param[in] maxSize
175 * Increment value
176 *
177 * return
178 * none
179 *
180 * =============================================================================
181 */
182 #define tf_contract_increment_var(localVar, globalVar, maxSize) \
183 { \
184 localVar = globalVar; \
185 localVar++; \
186 if(localVar >= maxSize) \
187 localVar = 0; \
188 globalVar = localVar; \
189 }
191 /*
192 * ============================================================================
193 * tf_contract_decrement_var
194 *
195 * Description:
196 * increment a variable
197 *
198 * param[in] localVar
199 * local variable
200 *
201 * param[in] globalVar
202 * global variable to be incremented
203 *
204 * param[in] maxSize
205 * decrement value
206 *
207 * return
208 * none
209 *
210 * =============================================================================
211 */
212 #define tf_contract_decrement_var(localVar, globalVar, maxSize) \
213 { \
214 localVar = globalVar; \
215 localVar--; \
216 if(localVar < 0) \
217 localVar = maxSize; \
218 globalVar = localVar; \
219 }
222 #ifdef __cplusplus
223 }
224 #endif
226 #endif /* __TF_UTILS_H_ */
227 /* Nothing past this point */