2 /*
3 Copyright (c) 2017, Texas Instruments Incorporated - http://www.ti.com/
4 All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the
16 * distribution.
17 *
18 * Neither the name of Texas Instruments Incorporated nor the names of
19 * its contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *
34 */
36 /*
37 * ======== alphaIntervalProc.c ========
38 */
40 #include <xdc/std.h>
41 #include <xdc/cfg/global.h>
42 #include <xdc/runtime/Log.h>
43 #include <xdc/runtime/System.h>
44 #include <ti/sysbios/knl/Clock.h>
45 #include <ti/sysbios/knl/Task.h>
46 #include <ti/sysbios/hal/Timer.h>
48 #include <acp.h>
49 #include <acp_mds.h>
51 //#include <acptype.h>
52 #include <acpbeta.h>
53 //#include <pafstd_a.h>
55 #include "logp.h"
56 #include "pafaip.h"
58 #include "fwkPort.h"
60 //#define MEMSTAT_REPORT
61 #ifdef MEMSTAT_REPORT
62 #include "paf_heapMgr.h"
63 #include "paf_alg_print.h"
64 #endif /* MEMSTAT_REPORT */
66 //
67 // Alpha code shortcut arrays
68 //
70 #ifndef execSTDAtBoot
71 #define execSTDAtBoot 0xc102
72 #endif
74 #ifndef execALTAtBoot
75 #define execALTAtBoot ((execSTDAtBoot) + (ACP_SERIES_ALT-ACP_SERIES_STD << 12))
76 #endif
78 #ifndef execOEMAtBoot
79 #define execOEMAtBoot ((execSTDAtBoot) + (ACP_SERIES_OEM-ACP_SERIES_STD << 12))
80 #endif
82 #ifndef execCUSAtBoot
83 #define execCUSAtBoot ((execSTDAtBoot) + (ACP_SERIES_CUS-ACP_SERIES_STD << 12))
84 #endif
86 const ACP_Unit atboot_sA[][2] =
87 {
88 { 0xc901, execSTDAtBoot, },
89 { 0xc901, execALTAtBoot, },
90 { 0xc901, execOEMAtBoot, },
91 { 0xc901, execCUSAtBoot, },
92 };
94 #ifndef execSTDAtTime
95 #define execSTDAtTime 0xc104
96 #endif
98 #ifndef execALTAtTime
99 #define execALTAtTime ((execSTDAtTime) + (ACP_SERIES_ALT-ACP_SERIES_STD << 12))
100 #endif
102 #ifndef execOEMAtTime
103 #define execOEMAtTime ((execSTDAtTime) + (ACP_SERIES_OEM-ACP_SERIES_STD << 12))
104 #endif
106 #ifndef execCUSAtTime
107 #define execCUSAtTime ((execSTDAtTime) + (ACP_SERIES_CUS-ACP_SERIES_STD << 12))
108 #endif
110 const ACP_Unit attime_sA[][2] =
111 {
112 { 0xc901, execSTDAtTime, },
113 { 0xc901, execALTAtTime, },
114 { 0xc901, execOEMAtTime, },
115 { 0xc901, execCUSAtTime, },
116 };
118 const PAF_AlphaIntervalProcessingStatus aipStatusInit =
119 {
120 sizeof (PAF_AlphaIntervalProcessingStatus),
121 3, // mode
122 0x99, // mask
123 100, // time (msec.)
124 };
126 // Global debug counters */
127 Uint32 gTaskAipCnt=0;
129 LINNO_DEFN (alphaIntervalProcessingTask); /* Line number macros */
130 ERRNO_DEFN (alphaIntervalProcessingTask); /* Error number macros */
132 /*
133 * ======== taskAipFxn ========
134 * Alpha Interval Processing task function
135 */
136 Void taskAipFxn(
137 Int betaPrimeValue
138 )
139 {
140 Int mode;
141 ALG_Handle acpAlg;
142 ACP_Handle acp;
143 Int betaPrime;
144 Int betaPrimeOffset;
145 PAF_AlphaIntervalProcessingStatus aipStatus;
146 Int errno;
147 // debug
148 //UInt32 curTime;
150 //System_printf("Enter taskAipFxn()\n");
151 Log_info0("Enter taskAipFxn()");
153 //
154 // Initialize
155 //
156 aipStatus = aipStatusInit;
158 LINNO_RPRT(alphaIntervalProcessingTask, -1);
160 // Create an ACP algorithm instance with trace enabled
161 ACP_MDS_init ();
163 if (!(acpAlg = (ALG_Handle )ACP_MDS_create (NULL)))
164 {
165 //LOG_printf(&trace, "AIP: ACP algorithm instance creation failed");
166 Log_info0("AIP: ACP algorithm instance creation failed");
167 LINNO_RPRT(alphaIntervalProcessingTask, __LINE__);
168 return;
169 }
171 acpAlg->fxns->algControl (acpAlg, ACP_GETBETAPRIMEOFFSET,
172 (IALG_Status *) &betaPrimeOffset);
173 betaPrime = betaPrimeOffset * betaPrimeValue;
175 acp = (ACP_Handle )acpAlg;
176 acp->fxns->attach(acp, ACP_SERIES_STD, STD_BETA_SYSINT+betaPrime,
177 (IALG_Status *)&aipStatus);
179 //LOG_printf(&trace, "AIP: ACP processing initialized");
180 Log_info0("AIP: ACP processing initialized");
182 #ifdef MEMSTAT_REPORT
183 // Output current heap memory usage
184 PAF_ALG_memStatusPrint("AIP RAM REPORT",
185 PAF_HEAP_INT, PAF_HEAP_INT1, PAF_HEAP_EXT,
186 PAF_HEAP_INT1_SHM, PAF_HEAP_EXT_SHM, PAF_HEAP_EXT_NONCACHED_SHM);
187 #endif
189 // Set default stream
190 if (betaPrimeValue != 0)
191 {
192 ACP_Unit stream_s[2] = { 0xcd09, 0x0400, };
194 stream_s[1] += betaPrimeValue;
195 if (errno = acp->fxns->apply (acp, stream_s, NULL))
196 {
197 //LOG_printf(&trace, "AIP: at boot stream error 0x%04x sending 0x%x, 0x%x",
198 // errno, stream_s[0], stream_s[1]);
199 Log_info3("AIP: at boot stream error 0x%04x sending 0x%x, 0x%x",
200 errno, stream_s[0], stream_s[1]);
201 LINNO_RPRT(alphaIntervalProcessingTask, __LINE__);
202 return;
203 }
204 }
206 // Process at boot interval if mode is non-zero
207 if (mode = aipStatus.mode)
208 {
209 Int i;
210 Int mask = aipStatus.mask;
211 for (i=0; i < 4; i++)
212 {
213 if (mask & (0x01 << i))
214 {
215 //LOG_printf(&trace, "AIP: at boot %d: %x, %x", i, atboot_sA[i][0], atboot_sA[i][1]);
216 Log_info3("AIP: at boot %d: %x, %x", i, atboot_sA[i][0], atboot_sA[i][1]);
217 if (errno = acp->fxns->sequence(acp, atboot_sA[i], NULL))
218 {
219 //LOG_printf(&trace, "AIP: at boot series %d error (0x%04x) <ignored>", i, errno);
220 Log_info2("AIP: at boot series %d error (0x%04x) <ignored>", i, errno);
221 ERRNO_RPRT (alphaIntervalProcessingTask, errno);
222 }
223 else
224 {
225 //LOG_printf(&trace, "AIP: at boot series %d process", i);
226 Log_info1("AIP: at boot series %d process", i);
227 }
228 }
229 }
230 }
232 LINNO_RPRT(alphaIntervalProcessingTask, -2);
234 //
235 // Run until task is destroyed by the system
236 //
238 while (mode = aipStatus.mode)
239 {
240 Uns time, interval, elapsed, now, then;
242 while (((mode = aipStatus.mode) > 1) && ((time = aipStatus.time) > 0))
243 {
244 // Compute interval in system clock ticks,
245 // interval time expressed in msec.
246 // Note: time can be updated via alpha commands
247 interval = time * USEC_PER_MSEC / Clock_tickPeriod; //interval = (CLK_countspms() * time) / CLK_getprd();
249 // Compute elapsed time
250 now = Clock_getTicks(); //now = TSK_time ();
251 elapsed = now - then;
252 then = now;
254 if (interval > elapsed)
255 {
256 Task_sleep(interval - elapsed); //TSK_sleep (interval - elapsed);
257 }
259 if (mode > 2)
260 {
261 Int i;
262 Int mask = aipStatus.mask;
263 for (i=0; i < 4; i++)
264 {
265 if (mask & (0x10 << i))
266 {
267 if (errno = acp->fxns->sequence(acp, attime_sA[i], NULL))
268 {
269 // LOG_printf(&trace, "AIP: at time series %d error (0x%04x) <ignored>", i, errno);
270 // Log_info2("AIP: at time series %d error (0x%04x) <ignored>", i, errno);
271 ERRNO_RPRT (alphaIntervalProcessingTask, errno);
272 }
273 else
274 {
275 // LOG_printf(&trace, "AIP: at time series %d process", i);
276 // Log_info1("AIP: at time series %d process", i);
277 }
278 }
279 }
280 }
282 gTaskAipCnt++;
284 //curTime = Clock_getTicks();
285 //System_printf("System time in taskAipFxn = %lu\n", (ULong)curTime);
286 //Log_info1("System time in taskAipFxn = %u", curTime);
287 }
288 }
290 // Block until re-prioritized when mode or time is zero
291 LINNO_RPRT(alphaIntervalProcessingTask, __LINE__);
292 Task_setPri(Task_self(), -1); //TSK_setpri( TSK_self(), -1);
293 Task_yield(); //TSK_yield();
295 //System_printf("Exit taskAipFxn()\n");
296 Log_info0("Exit taskAipFxn()");
297 }