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"
57 #include "paf_alg_print.h"
58 #include "paf_heapMgr.h"
60 #include "fwkPort.h"
62 // Symbolic constants for translating heap Ids to handles
63 #define HEAP_INTERNAL (HeapMem_Handle)pafHeapMgr_readHeapHandle(gPafHeapIdInt)
64 #define HEAP_INTERNAL1 (HeapMem_Handle)pafHeapMgr_readHeapHandle(gPafHeapIdInt1)
65 #define HEAP_EXTERNAL (HeapMem_Handle)pafHeapMgr_readHeapHandle(gPafHeapIdExt)
66 #define HEAP_INTERNAL1_SHM (HeapMem_Handle)pafHeapMgr_readHeapHandle(gPafHeapIdInt1Shm)
68 //
69 // Alpha code shortcut arrays
70 //
72 #ifndef execSTDAtBoot
73 #define execSTDAtBoot 0xc102
74 #endif
76 #ifndef execALTAtBoot
77 #define execALTAtBoot ((execSTDAtBoot) + (ACP_SERIES_ALT-ACP_SERIES_STD << 12))
78 #endif
80 #ifndef execOEMAtBoot
81 #define execOEMAtBoot ((execSTDAtBoot) + (ACP_SERIES_OEM-ACP_SERIES_STD << 12))
82 #endif
84 #ifndef execCUSAtBoot
85 #define execCUSAtBoot ((execSTDAtBoot) + (ACP_SERIES_CUS-ACP_SERIES_STD << 12))
86 #endif
88 const ACP_Unit atboot_sA[][2] =
89 {
90 { 0xc901, execSTDAtBoot, },
91 { 0xc901, execALTAtBoot, },
92 { 0xc901, execOEMAtBoot, },
93 { 0xc901, execCUSAtBoot, },
94 };
96 #ifndef execSTDAtTime
97 #define execSTDAtTime 0xc104
98 #endif
100 #ifndef execALTAtTime
101 #define execALTAtTime ((execSTDAtTime) + (ACP_SERIES_ALT-ACP_SERIES_STD << 12))
102 #endif
104 #ifndef execOEMAtTime
105 #define execOEMAtTime ((execSTDAtTime) + (ACP_SERIES_OEM-ACP_SERIES_STD << 12))
106 #endif
108 #ifndef execCUSAtTime
109 #define execCUSAtTime ((execSTDAtTime) + (ACP_SERIES_CUS-ACP_SERIES_STD << 12))
110 #endif
112 const ACP_Unit attime_sA[][2] =
113 {
114 { 0xc901, execSTDAtTime, },
115 { 0xc901, execALTAtTime, },
116 { 0xc901, execOEMAtTime, },
117 { 0xc901, execCUSAtTime, },
118 };
120 const PAF_AlphaIntervalProcessingStatus aipStatusInit =
121 {
122 sizeof (PAF_AlphaIntervalProcessingStatus),
123 3, // mode
124 0x99, // mask
125 100, // time (msec.)
126 };
128 Int gEnableRamReport = 0; // set this in main if RAM_REPORT is desired.
130 // Global debug counters */
131 Uint32 gTaskAipCnt=0;
133 LINNO_DEFN (alphaIntervalProcessingTask); /* Line number macros */
134 ERRNO_DEFN (alphaIntervalProcessingTask); /* Error number macros */
136 /*
137 * ======== taskAipFxn ========
138 * Alpha Interval Processing task function
139 */
140 Void taskAipFxn(
141 Int betaPrimeValue
142 )
143 {
144 Int mode;
145 ALG_Handle acpAlg;
146 ACP_Handle acp;
147 Int betaPrime;
148 Int betaPrimeOffset;
149 PAF_AlphaIntervalProcessingStatus aipStatus;
150 Int errno;
151 UInt32 curTime;
153 //System_printf("Enter taskAipFxn()\n");
154 Log_info0("Enter taskAipFxn()");
156 //
157 // Initialize
158 //
159 aipStatus = aipStatusInit;
161 LINNO_RPRT(alphaIntervalProcessingTask, -1);
163 // Create an ACP algorithm instance with trace enabled
164 ACP_MDS_init ();
166 if (!(acpAlg = (ALG_Handle )ACP_MDS_create (NULL)))
167 {
168 //LOG_printf(&trace, "AIP: ACP algorithm instance creation failed");
169 Log_info0("AIP: ACP algorithm instance creation failed");
170 LINNO_RPRT(alphaIntervalProcessingTask, __LINE__);
171 return;
172 }
174 acpAlg->fxns->algControl (acpAlg, ACP_GETBETAPRIMEOFFSET,
175 (IALG_Status *) &betaPrimeOffset);
176 betaPrime = betaPrimeOffset * betaPrimeValue;
178 acp = (ACP_Handle )acpAlg;
179 acp->fxns->attach(acp, ACP_SERIES_STD, STD_BETA_SYSINT+betaPrime,
180 (IALG_Status *)&aipStatus);
182 //LOG_printf(&trace, "AIP: ACP processing initialized");
183 Log_info0("AIP: ACP processing initialized");
185 if (gEnableRamReport)
186 {
187 PAF_ALG_memStatusPrint(HEAP_INTERNAL, HEAP_INTERNAL1, HEAP_EXTERNAL, HEAP_INTERNAL1_SHM);
188 }
190 // Set default stream
191 if (betaPrimeValue != 0)
192 {
193 ACP_Unit stream_s[2] = { 0xcd09, 0x0400, };
195 stream_s[1] += betaPrimeValue;
196 if (errno = acp->fxns->apply (acp, stream_s, NULL))
197 {
198 //LOG_printf(&trace, "AIP: at boot stream error 0x%04x sending 0x%x, 0x%x",
199 // errno, stream_s[0], stream_s[1]);
200 Log_info3("AIP: at boot stream error 0x%04x sending 0x%x, 0x%x",
201 errno, stream_s[0], stream_s[1]);
202 LINNO_RPRT(alphaIntervalProcessingTask, __LINE__);
203 return;
204 }
205 }
207 // Process at boot interval if mode is non-zero
208 if (mode = aipStatus.mode)
209 {
210 Int i;
211 Int mask = aipStatus.mask;
212 for (i=0; i < 4; i++)
213 {
214 if (mask & (0x01 << i))
215 {
216 //LOG_printf(&trace, "AIP: at boot %d: %x, %x", i, atboot_sA[i][0], atboot_sA[i][1]);
217 Log_info3("AIP: at boot %d: %x, %x", i, atboot_sA[i][0], atboot_sA[i][1]);
218 if (errno = acp->fxns->sequence(acp, atboot_sA[i], NULL))
219 {
220 //LOG_printf(&trace, "AIP: at boot series %d error (0x%04x) <ignored>", i, errno);
221 Log_info2("AIP: at boot series %d error (0x%04x) <ignored>", i, errno);
222 ERRNO_RPRT (alphaIntervalProcessingTask, errno);
223 }
224 else
225 {
226 //LOG_printf(&trace, "AIP: at boot series %d process", i);
227 Log_info1("AIP: at boot series %d process", i);
228 }
229 }
230 }
231 }
233 LINNO_RPRT(alphaIntervalProcessingTask, -2);
235 //
236 // Run until task is destroyed by the system
237 //
239 while (mode = aipStatus.mode)
240 {
241 Uns time, interval, elapsed, now, then;
243 while (((mode = aipStatus.mode) > 1) && ((time = aipStatus.time) > 0))
244 {
245 // Compute interval in system clock ticks,
246 // interval time expressed in msec.
247 // Note: time can be updated via alpha commands
248 interval = time * USEC_PER_MSEC / Clock_tickPeriod; //interval = (CLK_countspms() * time) / CLK_getprd();
250 // Compute elapsed time
251 now = Clock_getTicks(); //now = TSK_time ();
252 elapsed = now - then;
253 then = now;
255 if (interval > elapsed)
256 {
257 Task_sleep(interval - elapsed); //TSK_sleep (interval - elapsed);
258 }
260 if (mode > 2)
261 {
262 Int i;
263 Int mask = aipStatus.mask;
264 for (i=0; i < 4; i++)
265 {
266 if (mask & (0x10 << i))
267 {
268 if (errno = acp->fxns->sequence(acp, attime_sA[i], NULL))
269 {
270 // LOG_printf(&trace, "AIP: at time series %d error (0x%04x) <ignored>", i, errno);
271 // Log_info2("AIP: at time series %d error (0x%04x) <ignored>", i, errno);
272 ERRNO_RPRT (alphaIntervalProcessingTask, errno);
273 }
274 else
275 {
276 // LOG_printf(&trace, "AIP: at time series %d process", i);
277 // Log_info1("AIP: at time series %d process", i);
278 }
279 }
280 }
281 }
283 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 }