1 //###########################################################################
2 //
3 // FILE:   F2837xD_Ipc_Driver_Lite.c
4 //
5 // TITLE:  F2837xD Inter-Processor Communication (IPC) Lite API Driver
6 //         Functions.
7 //
8 // DESCRIPTION:
9 //         API functions for inter-processor communications between
10 //         CPU1 control system and CPU2 control system (Lite version). The IPC
11 //         Lite functions only allow for basic functions such as data writes,
12 //         reads, bit setting, and bit clearing.  The Lite functions do not
13 //         require the usage of the MSG RAM's or shared memories and can only
14 //         be used with a single IPC interrupt channel.  Commands can only
15 //         be processed one at a time without queuing.
16 //         The driver functions in this file are available only as
17 //         sample functions for application development.  Due to the generic
18 //         nature of these functions and the cycle overhead inherent to a
19 //         function call, the code is not intended to be used in cases where
20 //         maximum efficiency is required in a system.
21 //
22 // NOTE:   This source code is used by both CPUs. That is both CPU1 and CPU2
23 //         cores use this code.
24 //         The active debug CPU will be referred to as Local CPU and the other
25 //         CPU will be referred to as Remote CPU.
26 //         When using this source code in CPU1, the term "local"
27 //         will mean CPU1 and the term "remote" CPU will be mean CPU2.
28 //         When using this source code in CPU2, the term "local"
29 //         will mean CPU2 and the term "remote" CPU will be mean CPU1.
30 //
31 //         The abbreviations LtoR and RtoL  within the function names mean
32 //         Local to Remote and Remote to Local respectively.
33 //
34 //###########################################################################
35 // $TI Release: F2837xD Support Library v3.05.00.00 $
36 // $Release Date: Tue Jun 26 03:15:23 CDT 2018 $
37 // $Copyright:
38 // Copyright (C) 2013-2018 Texas Instruments Incorporated - http://www.ti.com/
39 //
40 // Redistribution and use in source and binary forms, with or without
41 // modification, are permitted provided that the following conditions
42 // are met:
43 //
44 //   Redistributions of source code must retain the above copyright
45 //   notice, this list of conditions and the following disclaimer.
46 //
47 //   Redistributions in binary form must reproduce the above copyright
48 //   notice, this list of conditions and the following disclaimer in the
49 //   documentation and/or other materials provided with the
50 //   distribution.
51 //
52 //   Neither the name of Texas Instruments Incorporated nor the names of
53 //   its contributors may be used to endorse or promote products derived
54 //   from this software without specific prior written permission.
55 //
56 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
57 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
58 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
59 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
60 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
61 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
62 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
63 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
64 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
65 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
66 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
67 // $
68 //###########################################################################
69 
70 //*****************************************************************************
71 //! \addtogroup ipc_lite_api IPC-Lite API Drivers
72 //! @{
73 //*****************************************************************************
74 #include "F2837xD_device.h"
75 #include "F2837xD_Ipc_drivers.h"
76 
77 //
78 // Function Prototypes
79 //
80 void DelayLoop (void);
81 
82 //*****************************************************************************
83 //
84 //! Reads single word data result of Local to Remote IPC command
85 //!
86 //! \param pvData is a pointer to the 16/32-bit variable where the result data
87 //! will be stored.
88 //! \param usLength designates 16- or 32-bit read.
89 //! \param ulStatusFlag indicates the Local to Remote CPU Flag number mask used
90 //!  to report the status of the command sent back from the Remote CPU. If
91 //!  a status flag was not used with the command call, set this parameter to 0.
92 //!
93 //! Allows the caller to read the 16/32-bit data result of non-blocking IPC
94 //! functions from the IPCREMOTEREPLY register if the status flag is cleared
95 //! indicating the IPC command was successfully interpreted. If the status flag
96 //! is not cleared, the command was not recognized, and the function will
97 //! return STATUS_FAIL. To determine what data is read from a call to this
98 //! function, see the descriptions of the non-blocking IPC functions.
99 //! The \e usLength parameter accepts the following values: \b
100 //! IPC_LENGTH_16_BITS or \b IPC_LENGTH_32_BITS. The  \e ulStatusFlag parameter
101 //! accepts any of the flag values \b IPC_FLAG1 - \b IPC_FLAG32 and \b NO_FLAG.
102 //! The function returns \b STATUS_PASS or \b STATUS_FAIL.
103 //!
104 //! \return status of command (0=success, 1=error)
105 //
106 //*****************************************************************************
107 uint16_t
IPCLiteLtoRGetResult(void * pvData,uint16_t usLength,uint32_t ulStatusFlag)108 IPCLiteLtoRGetResult (void *pvData, uint16_t usLength, uint32_t ulStatusFlag)
109 {
110     uint16_t returnStatus;
111 
112     //
113     // If Remote System never acknowledged Status Task, indicates command
114     // failure.
115     //
116     if (IpcRegs.IPCFLG.all & ulStatusFlag)
117     {
118         returnStatus = STATUS_FAIL;
119     }
120     else
121     {
122         //
123         // Read data.
124         //
125         if (usLength == IPC_LENGTH_16_BITS)
126         {
127             *(uint16_t *)pvData = IpcRegs.IPCREMOTEREPLY;
128         }
129         else if (usLength == IPC_LENGTH_32_BITS)
130         {
131             *(uint32_t *)pvData =  IpcRegs.IPCREMOTEREPLY;
132         }
133 
134         returnStatus = STATUS_PASS;
135     }
136 
137     return returnStatus;
138 }
139 
140 //*****************************************************************************
141 //
142 //! Reads either a 16- or 32-bit data word from the remote CPU System address
143 //!
144 //! \param ulFlag specifies Local to Remote IPC Flag number mask used to
145 //!        indicate a command is being sent.
146 //! \param ulAddress specifies the remote address to read from
147 //! \param usLength designates 16- or 32-bit read (1 = 16-bit, 2 = 32-bit)
148 //! \param ulStatusFlag indicates the Local to Remote Flag number mask used to
149 //!  report the status of the command sent back from the remote system.
150 //!
151 //! This function will allow the Local CPU System to read 16/32-bit data from
152 //! the Remote CPU System into the IPCREMOTEREPLY register. After calling this
153 //! function, a call to \e IPCLiteLtoRGetResult() will read the data value in
154 //! the IPCREMOTEREPLY register into a 16- or 32-bit variable in the local CPU
155 //! application.
156 //! The \e usLength parameter accepts the following values: \b
157 //! IPC_LENGTH_16_BITS or \b IPC_LENGTH_32_BITS. The \e ulStatusFlag parameter
158 //! accepts any one of the flag values \b IPC_FLAG1 - \b IPC_FLAG32 and \b
159 //! NO_FLAG. The function returns \b STATUS_PASS if the command is successful
160 //! or \b STATUS_FAIL if the request or status flags are unavailable.
161 //!
162 //! \return status of command (0=success, 1=error)
163 //
164 //*****************************************************************************
165 uint16_t
IPCLiteLtoRDataRead(uint32_t ulFlag,uint32_t ulAddress,uint16_t usLength,uint32_t ulStatusFlag)166 IPCLiteLtoRDataRead(uint32_t ulFlag, uint32_t ulAddress, uint16_t usLength,
167                     uint32_t ulStatusFlag)
168 {
169     uint16_t returnStatus;
170 
171     //
172     // Return false if IPC Local to Remote request or status flags are not
173     // available.
174     //
175     if (IpcRegs.IPCFLG.all & (ulFlag | ulStatusFlag))
176     {
177         returnStatus = STATUS_FAIL;
178     }
179     else
180     {
181         //
182         // Set up read command, address, and word length.
183         //
184         if (usLength == IPC_LENGTH_16_BITS)
185         {
186             IpcRegs.IPCSENDCOM = IPC_DATA_READ_16;
187         }
188         else if (usLength == IPC_LENGTH_32_BITS)
189         {
190             IpcRegs.IPCSENDCOM = IPC_DATA_READ_32;
191         }
192         IpcRegs.IPCSENDADDR = ulAddress;
193 
194         //
195         // Force IPC event on selected request task and enable status-checking.
196         //
197         IpcRegs.IPCSET.all |= (ulFlag | ulStatusFlag);
198 
199         returnStatus = STATUS_PASS;
200     }
201 
202     return returnStatus;
203 }
204 
205 //*****************************************************************************
206 //
207 //! Sets the designated bits in a 16/32-bit data word at the remote CPU system
208 //! address
209 //!
210 //! \param ulFlag specifies Local to Remote IPC Flag number mask used to
211 //!        indicate a command is being sent.
212 //! \param ulAddress specifies the Remote address to write to.
213 //! \param ulMask specifies the 16/32-bit mask for bits which should be set at
214 //!  remote ulAddress. For 16-bit mask, only the lower 16-bits of ulMask are
215 //!  considered.
216 //! \param usLength specifies the length of the \e ulMask (1 = 16-bit, 2 =
217 //! 32-bit).
218 //! \param ulStatusFlag indicates the Local to Remote Flag number mask used to
219 //!        report the status of the command sent back from the Remote system.
220 //!
221 //! This function will allow the Local CPU system to set bits specified by the
222 //! \e usMask variable in a 16/32-bit word on the Remote CPU system. The data
223 //! word at /e ulAddress after the set bits command is then read into the
224 //! IPCREMOTEREPLY register. After calling this function, a call to \e
225 //! IPCLiteLtoRGetResult() will read the data value in the IPCREMOTEREPLY
226 //! register into a 16/32-bit variable in the Local CPU application.
227 //! The \e usLength parameter accepts the following values: \b
228 //! IPC_LENGTH_16_BITS or \b IPC_LENGTH_32_BITS. The \e ulStatusFlag parameter
229 //! accepts any one of the flag values \b IPC_FLAG1 - \b IPC_FLAG32 and \b
230 //! NO_FLAG. The function returns \b STATUS_PASS if the command is successful
231 //! or \b STATUS_FAIL if the request or status flags are unavailable.
232 //!
233 //! \return status of command (0=success, 1=error)
234 //
235 //*****************************************************************************
236 uint16_t
IPCLiteLtoRSetBits(uint32_t ulFlag,uint32_t ulAddress,uint32_t ulMask,uint16_t usLength,uint32_t ulStatusFlag)237 IPCLiteLtoRSetBits(uint32_t ulFlag, uint32_t ulAddress, uint32_t ulMask,
238                    uint16_t usLength, uint32_t ulStatusFlag)
239 {
240     uint16_t returnStatus;
241 
242     //
243     // Return false if IPC Local to Remote request or status flags are not
244     // available.
245     //
246     if (IpcRegs.IPCFLG.all & (ulFlag | ulStatusFlag))
247     {
248         returnStatus = STATUS_FAIL;
249     }
250     else
251     {
252         if (usLength == IPC_LENGTH_16_BITS)
253         {
254             //
255             // Set up 16-bit set bits command, address, and mask.
256             //
257             IpcRegs.IPCSENDCOM = IPC_SET_BITS_16;
258             IpcRegs.IPCSENDADDR = ulAddress;
259             IpcRegs.IPCSENDDATA = ulMask & (0x0000FFFF);
260         }
261         else if (usLength == IPC_LENGTH_32_BITS)
262         {
263             //
264             // Set up 32-bit set bits command, address, and mask.
265             //
266             IpcRegs.IPCSENDCOM = IPC_SET_BITS_32;
267             IpcRegs.IPCSENDADDR = ulAddress;
268             IpcRegs.IPCSENDDATA = ulMask;
269         }
270 
271         //
272         // Force IPC event on selected request task and enable status-checking.
273         //
274         IpcRegs.IPCSET.all |= (ulFlag | ulStatusFlag);
275 
276         returnStatus = STATUS_PASS;
277     }
278 
279     return returnStatus;
280 }
281 
282 //*****************************************************************************
283 //
284 //! Sets the designated bits in a 16/32-bit write-protected data word at
285 //! the Remote CPU system address
286 //!
287 //! \param ulFlag specifies Local to Remote IPC Flag number mask used to
288 //!        indicate a command is being sent.
289 //! \param ulAddress specifies the Remote CPU write-protected address to write
290 //!        to.
291 //! \param ulMask specifies the 16/32-bit mask for bits which should be set at
292 //!  Remote CPU ulAddress.For 16-bit mask, only the lower 16-bits of ulMask are
293 //!  considered.
294 //! \param usLength specifies the length of the \e ulMask (1 = 16-bit, 2 =
295 //! 32-bit).
296 //! \param ulStatusFlag indicates the Local to Remote Flag number mask used to
297 //!        report the status of the command sent back from the Master system.
298 //!
299 //! This function will allow the Local CPU system to set bits specified by the
300 //! \e usMask variable in a write-protected 16/32-bit word on the REmote CPU
301 //! system.
302 //! The data word at /e ulAddress after the set bits command is then read into
303 //! the IPCREMOTEREPLY register. After calling this function, a call to
304 //! \e IPCLiteLtoRGetResult() will read the data value in the IPCREMOTEREPLY
305 //! register into a 16/32-bit variable in the Local application.
306 //! The \e usLength parameter accepts the following values: \b
307 //! IPC_LENGTH_16_BITS or \b IPC_LENGTH_32_BITS. The \e ulStatusFlag parameter
308 //! accepts any one of the flag values \b IPC_FLAG1 - \b IPC_FLAG32 and \b
309 //! NO_FLAG. The function returns \b STATUS_PASS if the command is successful
310 //! or \b STATUS_FAIL if the request or status flags are unavailable.
311 //!
312 //! \return status of command (0=success, 1=error)
313 //
314 //*****************************************************************************
315 uint16_t
IPCLiteLtoRSetBits_Protected(uint32_t ulFlag,uint32_t ulAddress,uint32_t ulMask,uint16_t usLength,uint32_t ulStatusFlag)316 IPCLiteLtoRSetBits_Protected (uint32_t ulFlag, uint32_t ulAddress,
317                               uint32_t ulMask, uint16_t usLength,
318                               uint32_t ulStatusFlag)
319 {
320     uint16_t returnStatus;
321 
322     //
323     // Return false if IPC Local to Remote request or status flags are not
324     // available.
325     //
326     if (IpcRegs.IPCFLG.all & (ulFlag | ulStatusFlag))
327     {
328         returnStatus = STATUS_FAIL;
329     }
330     else
331     {
332         if (usLength == IPC_LENGTH_16_BITS)
333         {
334             //
335             // Set up 16-bit set bits command, address, and mask.
336             //
337             IpcRegs.IPCSENDCOM = IPC_SET_BITS_16_PROTECTED;
338             IpcRegs.IPCSENDADDR = ulAddress;
339             IpcRegs.IPCSENDDATA = ulMask & (0x0000FFFF);
340         }
341         else if (usLength == IPC_LENGTH_32_BITS)
342         {
343             //
344             // Set up 32-bit set bits command, address, and mask.
345             //
346             IpcRegs.IPCSENDCOM = IPC_SET_BITS_32_PROTECTED;
347             IpcRegs.IPCSENDADDR = ulAddress;
348             IpcRegs.IPCSENDDATA = ulMask;
349         }
350 
351         //
352         // Force IPC event on selected request task and enable status-checking.
353         //
354         IpcRegs.IPCSET.all |= (ulFlag | ulStatusFlag);
355 
356         returnStatus = STATUS_PASS;
357     }
358 
359     return returnStatus;
360 }
361 
362 //*****************************************************************************
363 //
364 //! Sets the designated bits in a 16/32-bit data word at the remote CPU system
365 //! address
366 //!
367 //! \param ulFlag specifies Local to Remote IPC Flag number mask used to
368 //!        indicate a command is being sent.
369 //! \param ulAddress specifies the Remote CPU address to write to.
370 //! \param ulMask specifies the 16/32-bit mask for bits which should be set at
371 //! the remote CPU ulAddress. (For 16-bit mask, only the lower 16-bits of
372 //! ulMask are considered.
373 //! \param usLength specifies the length of the \e ulMask (1 = 16-bit, 2 =
374 //! 32-bit).
375 //! \param ulStatusFlag indicates the Local to Remote Flag number mask used to
376 //! report the status of the command sent back from the Master system.
377 //!
378 //! This function will allow the Local CPU system to set bits specified by the
379 //! \e usMask variable in a 16/32-bit word on the Remote CPU system. The data
380 //! word at /e ulAddress after the set bits command is then read into the
381 //! IPCREMOTEREPLY register. After calling this function, a call to \e
382 //! IPCLiteLtoRGetResult() will read the data value in the IPCREMOTEREPLY
383 //! register into a 16/32-bit variable in the Local CPU application.
384 //! The \e usLength parameter accepts the following values: \b
385 //! IPC_LENGTH_16_BITS or \b IPC_LENGTH_32_BITS. The \e ulStatusFlag parameter
386 //! accepts any one of the flag values \b IPC_FLAG1 - \b IPC_FLAG32 and \b
387 //! NO_FLAG. The function returns \b STATUS_PASS if the command is successful
388 //! or \b STATUS_FAIL if the request or status flags are unavailable.
389 //!
390 //! \return status of command (0=success, 1=error)
391 //
392 //*****************************************************************************
393 uint16_t
IPCLiteLtoRClearBits(uint32_t ulFlag,uint32_t ulAddress,uint32_t ulMask,uint16_t usLength,uint32_t ulStatusFlag)394 IPCLiteLtoRClearBits(uint32_t ulFlag, uint32_t ulAddress, uint32_t ulMask,
395                      uint16_t usLength, uint32_t ulStatusFlag)
396 {
397     uint16_t returnStatus;
398 
399     //
400     // Return false if IPC Local to Remote request or status flags are not
401     // available.
402     //
403     if (IpcRegs.IPCFLG.all & (ulFlag | ulStatusFlag))
404     {
405         returnStatus = STATUS_FAIL;
406     }
407     else
408     {
409         if (usLength == IPC_LENGTH_16_BITS)
410         {
411             //
412             // Set up 16-bit set bits command, address, and mask.
413             //
414             IpcRegs.IPCSENDCOM = IPC_CLEAR_BITS_16;
415             IpcRegs.IPCSENDADDR = ulAddress;
416             IpcRegs.IPCSENDDATA = ulMask & (0x0000FFFF);
417         }
418         else if (usLength == IPC_LENGTH_32_BITS)
419         {
420             //
421             // Set up 32-bit set bits command, address, and mask.
422             //
423             IpcRegs.IPCSENDCOM = IPC_CLEAR_BITS_32;
424             IpcRegs.IPCSENDADDR = ulAddress;
425             IpcRegs.IPCSENDDATA = ulMask;
426         }
427 
428         //
429         // Force IPC event on selected request task and enable status-checking.
430         //
431         IpcRegs.IPCSET.all |= (ulFlag | ulStatusFlag);
432 
433         returnStatus = STATUS_PASS;
434     }
435 
436     return returnStatus;
437 }
438 
439 //*****************************************************************************
440 //
441 //! Clears the designated bits in a 16/32-bit write-protected data word at
442 //! Remote CPU system address
443 //!
444 //! \param ulFlag specifies Local to Remote IPC Flag number mask used to
445 //! indicate a command is being sent.
446 //! \param ulAddress specifies the Remote CPU write-protected address to write
447 //! to.
448 //! \param ulMask specifies the 16/32-bit mask for bits which should be cleared
449 //! at Remote CPU ulAddress.For 16-bit mask, only the lower 16-bits of ulMask
450 //! are considered.
451 //! \param usLength specifies the length of the \e ulMask (1 = 16-bit, 2 =
452 //! 32-bit).
453 //! \param ulStatusFlag indicates the Local to Remote Flag number mask used to
454 //! report the status of the command sent back from the Master system.
455 //!
456 //! This function will allow the Local CPU system to clear bits specified by
457 //! the \e usMask variable in a write-protected 16/32-bit word on the Remote
458 //! CPU system.
459 //! The data word at /e ulAddress after the clear bits command is then read
460 //! into the IPCREMOTEREPLY register. After calling this function, a call to
461 //! \e IPCLiteLtoRGetResult() will read the data value in the IPCREMOTEREPLY
462 //! register into a 16/32-bit variable in the Local CPU application.
463 //! The \e usLength parameter accepts the following values: \b
464 //! IPC_LENGTH_16_BITS or \b IPC_LENGTH_32_BITS. The \e ulStatusFlag parameter
465 //! accepts any one of the flag values \b IPC_FLAG1 - \b IPC_FLAG32 and \b
466 //! NO_FLAG. The function returns \b STATUS_PASS if the command is successful
467 //! or \b STATUS_FAIL if the request or status flags are unavailable.
468 //!
469 //! \return status of command (0=success, 1=error)
470 //
471 //*****************************************************************************
472 uint16_t
IPCLiteLtoRClearBits_Protected(uint32_t ulFlag,uint32_t ulAddress,uint32_t ulMask,uint16_t usLength,uint32_t ulStatusFlag)473 IPCLiteLtoRClearBits_Protected (uint32_t ulFlag, uint32_t ulAddress,
474                                 uint32_t ulMask, uint16_t usLength,
475                                 uint32_t ulStatusFlag)
476 {
477     uint16_t returnStatus;
478 
479     //
480     // Return false if IPC Local to Remote request or status flags are not
481     // available.
482     //
483     if (IpcRegs.IPCFLG.all & (ulFlag | ulStatusFlag))
484     {
485         returnStatus = STATUS_FAIL;
486     }
487     else
488     {
489         if (usLength == IPC_LENGTH_16_BITS)
490         {
491             //
492             // Set up 16-bit set bits command, address, and mask.
493             //
494             IpcRegs.IPCSENDCOM = IPC_CLEAR_BITS_16_PROTECTED;
495             IpcRegs.IPCSENDADDR = ulAddress;
496             IpcRegs.IPCSENDDATA = ulMask & (0x0000FFFF);
497         }
498         else if (usLength == IPC_LENGTH_32_BITS)
499         {
500             //
501             // Set up 32-bit set bits command, address, and mask.
502             //
503             IpcRegs.IPCSENDCOM = IPC_CLEAR_BITS_32_PROTECTED;
504             IpcRegs.IPCSENDADDR = ulAddress;
505             IpcRegs.IPCSENDDATA = ulMask;
506         }
507 
508         //
509         // Force IPC event on selected request task and enable status-checking.
510         //
511         IpcRegs.IPCSET.all |= (ulFlag | ulStatusFlag);
512 
513         returnStatus = STATUS_PASS;
514     }
515 
516     return returnStatus;
517 }
518 
519 //*****************************************************************************
520 //
521 //! Writes a 16/32-bit data word to Remote CPU System address
522 //!
523 //! \param ulFlag specifies Local to Remote IPC Flag number mask used to
524 //! indicate a command is being sent.
525 //! \param ulAddress specifies the Remote CPU address to write to
526 //! \param ulData specifies the 16/32-bit word which will be written.
527 //! For 16-bit words, only the lower 16-bits of ulData will be considered by
528 //! the master system.
529 //! \param usLength is the length of the word to write (0 = 16-bits, 1 =
530 //! 32-bits)
531 //! \param ulStatusFlag indicates the Local to Remote Flag number mask used to
532 //! report the status of the command sent back from the Remote CPU  system.
533 //!
534 //! This function will allow the Local CPU System to write a 16/32-bit word
535 //! via the \e ulData variable to an address on the Remote CPU System.
536 //! The \e usLength parameter accepts the following values: \b
537 //! IPC_LENGTH_16_BITS or \b IPC_LENGTH_32_BITS. The \e ulStatusFlag parameter
538 //! accepts any one of the flag values \b IPC_FLAG1 - \b IPC_FLAG32 and \b
539 //! NO_FLAG. The function returns \b STATUS_PASS if the command is successful
540 //! or \b STATUS_FAIL if the request or status flags are unavailable.
541 //!
542 //! \return status of command (0=success, 1=error)
543 //
544 //*****************************************************************************
545 uint16_t
IPCLiteLtoRDataWrite(uint32_t ulFlag,uint32_t ulAddress,uint32_t ulData,uint16_t usLength,uint32_t ulStatusFlag)546 IPCLiteLtoRDataWrite(uint32_t ulFlag, uint32_t ulAddress, uint32_t ulData,
547                      uint16_t usLength, uint32_t ulStatusFlag)
548 {
549     uint16_t returnStatus;
550 
551     //
552     // Return false if IPC Local to Remote request or status flags are not
553     // available.
554     //
555     if (IpcRegs.IPCFLG.all & (ulFlag | ulStatusFlag))
556     {
557         returnStatus = STATUS_FAIL;
558     }
559     else
560     {
561         //
562         // Set up data write command, address, and data. For 16-bit write,
563         // Master system will look at lower 16-bits only.
564         //
565         if (usLength == IPC_LENGTH_16_BITS)
566         {
567             IpcRegs.IPCSENDCOM = IPC_DATA_WRITE_16;
568         }
569         else if (usLength == IPC_LENGTH_32_BITS)
570         {
571             IpcRegs.IPCSENDCOM = IPC_DATA_WRITE_32;
572         }
573         IpcRegs.IPCSENDADDR = ulAddress;
574         IpcRegs.IPCSENDDATA = ulData;
575 
576         //
577         // Force IPC event on selected request task and enable status-checking
578         //
579         IpcRegs.IPCSET.all |= (ulFlag | ulStatusFlag);
580 
581         returnStatus = STATUS_PASS;
582     }
583 
584     return returnStatus;
585 }
586 
587 //*****************************************************************************
588 //
589 //! Writes a 16/32-bit data word to a protected Remote CPU System address
590 //!
591 //! \param ulFlag specifies Local to Remote IPC Flag number mask used to
592 //! indicate a command is being sent.
593 //! \param ulAddress specifies the Remote CPU address to write to
594 //! \param ulData specifies the 16/32-bit word which will be written.
595 //! For 16-bit words, only the lower 16-bits of ulData will be considered by
596 //! the master system.
597 //! \param usLength is the length of the word to write (0 = 16-bits, 1 =
598 //! 32-bits)
599 //! \param ulStatusFlag indicates the Local to Remote Flag number mask used to
600 //! report the status of the command sent back from the Master  system.
601 //!
602 //! This function will allow the Local CPU System to write a 16/32-bit word
603 //! via the \e ulData variable to a write-protected address on the Remote CPU
604 //! System. The \e usLength parameter accepts the following values: \b
605 //! IPC_LENGTH_16_BITS or \b IPC_LENGTH_32_BITS. The \e ulStatusFlag parameter
606 //! accepts any one of the flag values \b IPC_FLAG1 - \b IPC_FLAG32 and \b
607 //! NO_FLAG. The function returns \b STATUS_PASS if the command is successful
608 //! or \b STATUS_FAIL if the request or status flags are unavailable.
609 //!
610 //! \return status of command (0=success, 1=error)
611 //
612 //*****************************************************************************
613 uint16_t
IPCLiteLtoRDataWrite_Protected(uint32_t ulFlag,uint32_t ulAddress,uint32_t ulData,uint16_t usLength,uint32_t ulStatusFlag)614 IPCLiteLtoRDataWrite_Protected(uint32_t ulFlag, uint32_t ulAddress,
615                                uint32_t ulData, uint16_t usLength,
616                                uint32_t ulStatusFlag)
617 {
618     uint16_t returnStatus;
619 
620     //
621     // Return false if IPC Local to Remote request or status flags are not
622     // available.
623     //
624     if (IpcRegs.IPCFLG.all & (ulFlag | ulStatusFlag))
625     {
626         returnStatus = STATUS_FAIL;
627     }
628     else
629     {
630         //
631         // Set up data write command, address, and data. For 16-bit write, Master
632         // system will look at lower 16-bits only.
633         //
634         if (usLength == IPC_LENGTH_16_BITS)
635         {
636             IpcRegs.IPCSENDCOM = IPC_DATA_WRITE_16_PROTECTED;
637         }
638         else if (usLength == IPC_LENGTH_32_BITS)
639         {
640             IpcRegs.IPCSENDCOM = IPC_DATA_WRITE_32_PROTECTED;
641         }
642         IpcRegs.IPCSENDADDR = ulAddress;
643         IpcRegs.IPCSENDDATA = ulData;
644 
645         //
646         // Force IPC event on selected request task and enable status-checking
647         //
648         IpcRegs.IPCSET.all |= (ulFlag | ulStatusFlag);
649 
650         returnStatus = STATUS_PASS;
651     }
652 
653     return returnStatus;
654 }
655 
656 //*****************************************************************************
657 //
658 //! Calls a Remote CPU function with 1 optional parameter and an optional
659 //! return value.
660 //!
661 //! \param ulFlag specifies Local to Remote IPC Flag number mask used to
662 //! indicate a command is being sent.
663 //! \param ulAddress specifies the Remote CPU function address
664 //! \param ulParam specifies the 32-bit optional parameter value
665 //! \param ulStatusFlag indicates the Local to Remote Flag number mask used to
666 //! report the status of the command sent back from the control  system.
667 //!
668 //! This function will allow the Local CPU system to call a function on the
669 //! Remote CPU. The \e ulParam variable is a single optional 32-bit parameter
670 //! to pass to the function. The \e ulFlag parameter accepts any one of the
671 //! flag values \b IPC_FLAG1 - \b IPC_FLAG32. The \e ulStatusFlag parameter
672 //! accepts any other one of the flag values \b IPC_FLAG1 - \b IPC_FLAG32
673 //! and \b NO_FLAG. The function returns \b STATUS_PASS if the command is
674 //! successful or \b STATUS_FAIL if the request or status flags are unavailable.
675 //!
676 //! \return status of command (0=success, 1=error)
677 //
678 //*****************************************************************************
679 uint16_t
IPCLiteLtoRFunctionCall(uint32_t ulFlag,uint32_t ulAddress,uint32_t ulParam,uint32_t ulStatusFlag)680 IPCLiteLtoRFunctionCall(uint32_t ulFlag, uint32_t ulAddress, uint32_t ulParam,
681                         uint32_t ulStatusFlag)
682 {
683     uint16_t returnStatus;
684 
685     //
686     // Return false if IPC Remote to Local request or status flags are not
687     // available.
688     //
689     if (IpcRegs.IPCFLG.all & (ulFlag | ulStatusFlag))
690     {
691         returnStatus = STATUS_FAIL;
692     }
693     else
694     {
695         //
696         // Set up function call command, address, and parameter.
697         //
698         IpcRegs.IPCSENDCOM = IPC_FUNC_CALL;
699         IpcRegs.IPCSENDADDR = ulAddress;
700         IpcRegs.IPCSENDDATA = ulParam;
701 
702         //
703         // Force IPC event on selected request task and enable status-checking
704         //
705         IpcRegs.IPCSET.all |= (ulFlag | ulStatusFlag);
706 
707         returnStatus = STATUS_PASS;
708     }
709 
710     return returnStatus;
711 }
712 
713 //*****************************************************************************
714 //
715 //! Slave Requests Master R/W/Exe Access to Shared SARAM.
716 //!
717 //! \param ulFlag specifies Local to Remote IPC Flag number mask used to
718 //! indicate a command is being sent.
719 //! \param ulMask specifies the 32-bit mask for the GSxMEMSEL RAM control
720 //! register to indicate which GSx SARAM blocks the Slave is requesting master
721 //! access to.
722 //! \param ulMaster specifies whether CPU1 or CPU2 should be the master of the
723 //! GSx RAM.
724 //! \param ulStatusFlag indicates the Local to Remote Flag number mask used to
725 //! report the status of the command sent back from the Master  system.
726 //!
727 //! This function will allow the slave CPU System to request slave or master
728 //! mastership of any of the GSx Shared SARAM blocks.
729 //! The \e ulMaster parameter accepts the following values:
730 //! \b IPC_GSX_CPU2_MASTER or \b IPC_GSX_CPU1_MASTER. The \e ulStatusFlag
731 //! parameter accepts any one of the flag values \b IPC_FLAG1 - \b IPC_FLAG32
732 //! and \b NO_FLAG. The function returns \b STATUS_PASS if the command is
733 //! successful or \b STATUS_FAIL if the request or status flags are unavailable.
734 //! \note This function calls the \e IPCLiteLtoRSetBits_Protected() or the
735 //! \e IPCLiteLtoRClearBits_Protected function, and therefore in order to
736 //! process this function, the above 2 functions should be ready to be called
737 //! on the master system to process this command.
738 //!
739 //! \return status of command (0=success, 1=error)
740 //
741 //*****************************************************************************
742 uint16_t
IPCLiteReqMemAccess(uint32_t ulFlag,uint32_t ulMask,uint16_t ulMaster,uint32_t ulStatusFlag)743 IPCLiteReqMemAccess (uint32_t ulFlag, uint32_t ulMask, uint16_t ulMaster,
744                      uint32_t ulStatusFlag)
745 {
746     uint16_t status;
747     uint32_t GSxMSEL_REGaddress = (uint32_t)(&MemCfgRegs.GSxMSEL.all);
748     if (ulMaster == IPC_GSX_CPU2_MASTER)
749     {
750         status =
751             IPCLiteLtoRSetBits_Protected (ulFlag, GSxMSEL_REGaddress, ulMask,
752                                           IPC_LENGTH_32_BITS,
753                                           ulStatusFlag);
754     }
755     else if (ulMaster == IPC_GSX_CPU1_MASTER)
756     {
757         status =
758             IPCLiteLtoRClearBits_Protected (ulFlag, GSxMSEL_REGaddress, ulMask,
759                                             IPC_LENGTH_32_BITS,
760                                             ulStatusFlag);
761     }
762 
763     return status;
764 }
765 
766 //*****************************************************************************
767 //
768 //! Reads either a 16- or 32-bit data word from the Local CPU system address
769 //!
770 //! \param ulFlag specifies Remote to Local IPC Flag number mask used to
771 //! indicate a command is being sent.
772 //! \param ulStatusFlag indicates the Remote to Local Flag number mask used to
773 //! report the status of the command sent back from the control  system.
774 //!
775 //! This function will allow the Remote CPU system to read 16/32-bit data from
776 //! the Local CPU system. The \e ulFlag parameter accepts any one of the
777 //! flag values \b IPC_FLAG1 - \b IPC_FLAG32, and the \e ulStatusFlag parameter
778 //! accepts any other one of the flag values \b IPC_FLAG1 - \b IPC_FLAG32 and
779 //! \b NO_FLAG.
780 //
781 //*****************************************************************************
782 void
IPCLiteRtoLDataRead(uint32_t ulFlag,uint32_t ulStatusFlag)783 IPCLiteRtoLDataRead(uint32_t ulFlag, uint32_t ulStatusFlag)
784 {
785 
786     uint32_t* pulRAddress;
787     uint16_t* pusRAddress;
788 
789     //
790     // Wait until IPC Remote to Local request task is flagged
791     //
792     while (!(IpcRegs.IPCSTS.all & ulFlag))
793     {
794     }
795 
796     //
797     // If the command and data length are correct for this function:
798     // Then read from requested address and write 16/32-bit data
799     // to IPCLOCALREPLY. Acknowledge the status flag
800     // and the task flag.
801     //
802     if (IpcRegs.IPCRECVCOM == IPC_DATA_READ_16)
803     {
804         //
805         // Perform 16-bit read.
806         //
807         pusRAddress = (uint16_t *)IpcRegs.IPCRECVADDR;
808         IpcRegs.IPCLOCALREPLY = (uint32_t)(*pusRAddress);
809         IpcRegs.IPCACK.all |= (ulStatusFlag | ulFlag);
810     }
811     else if (IpcRegs.IPCRECVCOM == IPC_DATA_READ_32)
812     {
813         pulRAddress = (uint32_t *)IpcRegs.IPCRECVADDR;
814         IpcRegs.IPCLOCALREPLY = *pulRAddress;
815         IpcRegs.IPCACK.all |= (ulStatusFlag | ulFlag);
816     }
817 
818     //
819     // Otherwise, only acknowledge the task flag.
820     //(Indicates to Remote CPU there was an error)
821     //
822     else
823     {
824         IpcRegs.IPCACK.all |= (ulFlag);
825     }
826 }
827 
828 //*****************************************************************************
829 //
830 //! Sets the designated bits in a 16/32-bit data word at the Local CPU system
831 //! address
832 //!
833 //! \param ulFlag specifies Remote to Local IPC Flag number mask used to
834 //! indicate a command is being sent.
835 //! \param ulStatusFlag indicates the Remote to Local Flag number mask used to
836 //! report the status of the command sent back from the control system.
837 //!
838 //! This function will allow the Remote CPU system to set bits specified by a
839 //! mask variable in a 16/32-bit word on the Local CPU system, and then read
840 //! back the word into the IPCLOCALREPLY register. The \e ulFlag parameter
841 //! accepts any one of the flag values \b IPC_FLAG1 - \b IPC_FLAG32, and the
842 //! \e ulStatusFlag parameter accepts any other one of the flag values \b
843 //! IPC_FLAG1 - \b IPC_FLAG32 and \b NO_FLAG.
844 //
845 //*****************************************************************************
846 void
IPCLiteRtoLSetBits(uint32_t ulFlag,uint32_t ulStatusFlag)847 IPCLiteRtoLSetBits(uint32_t ulFlag, uint32_t ulStatusFlag)
848 {
849 
850     uint16_t* pusAddress;
851     uint32_t* pulAddress;
852 
853     //
854     // Wait until IPC Remote to Local request task is flagged
855     //
856     while (!(IpcRegs.IPCSTS.all & ulFlag))
857     {
858     }
859 
860     //
861     // If the command is correct for this function:
862     // Then set the mask bits at the requested address
863     // and write back the 16/32-bit data to IPCLOCALREPLY.
864     // Acknowledge the status flag and the task flag.
865     //
866     if (IpcRegs.IPCRECVCOM == IPC_SET_BITS_16)
867     {
868         pusAddress = (uint16_t *)IpcRegs.IPCRECVADDR;;
869         *pusAddress |= (uint16_t)IpcRegs.IPCRECVDATA;
870         IpcRegs.IPCLOCALREPLY = (uint32_t)*pusAddress;
871 
872         IpcRegs.IPCACK.all |= (ulStatusFlag | ulFlag);
873     }
874     else if (IpcRegs.IPCRECVCOM == IPC_SET_BITS_32)
875     {
876         pulAddress = (uint32_t *)IpcRegs.IPCRECVADDR;;
877         *pulAddress |= (uint32_t)IpcRegs.IPCRECVDATA;
878         IpcRegs.IPCLOCALREPLY = *pulAddress;
879 
880         IpcRegs.IPCACK.all |= (ulStatusFlag | ulFlag);
881     }
882 
883     //
884     // Otherwise, only acknowledge the task flag.
885     // (Indicates to Remote CPU there was an error)
886     //
887     else
888     {
889         IpcRegs.IPCACK.all |= (ulFlag);
890     }
891 }
892 
893 //*****************************************************************************
894 //
895 //! Sets the designated bits in a 16-bit data word at the Local CPU system
896 //! write-protected address
897 //!
898 //! \param ulFlag specifies Remote to Local IPC Flag number mask used to
899 //! indicate a command is being sent.
900 //! \param ulStatusFlag indicates the Remote to Local Flag number mask used to
901 //! report the status of the command sent back from the control system.
902 //!
903 //! This function will allow the Remote CPU system to set bits specified by a
904 //! mask variable in a write-protected 16/32-bit word on the Local CPU system,
905 //! and then read back the word into the IPCLOCALREPLY register. The \e ulFlag
906 //! parameter accepts any one of the flag values \b IPC_FLAG1 - \b IPC_FLAG32,
907 //! and the \e ulStatusFlag parameter accepts any other one of the flag values
908 //! \b IPC_FLAG1 - \b IPC_FLAG32 and \b NO_FLAG.
909 //
910 //*****************************************************************************
911 void
IPCLiteRtoLSetBits_Protected(uint32_t ulFlag,uint32_t ulStatusFlag)912 IPCLiteRtoLSetBits_Protected (uint32_t ulFlag, uint32_t ulStatusFlag)
913 {
914 
915     uint16_t* pusAddress;
916     uint32_t* pulAddress;
917 
918     //
919     // Wait until IPC Remote to Local request task is flagged
920     //
921     while (!(IpcRegs.IPCSTS.all & ulFlag))
922     {
923     }
924 
925     //
926     // If the command is correct for this function:
927     // Then enable write access with EALLOW and
928     // set the mask bits at the requested address.
929     // Write back the 16-bit data to IPCLOCALREPLY.
930     // Restore write-protection with EDIS.
931     // Acknowledge the status flag and the task flag.
932     //
933 
934     EALLOW;
935 
936     if (IpcRegs.IPCRECVCOM == IPC_SET_BITS_16_PROTECTED)
937     {
938         pusAddress = (uint16_t *)IpcRegs.IPCRECVADDR;
939         *pusAddress |= (uint16_t)IpcRegs.IPCRECVDATA;
940         IpcRegs.IPCLOCALREPLY = (uint32_t)*pusAddress;
941 
942         IpcRegs.IPCACK.all |= (ulStatusFlag | ulFlag);
943     }
944     else if (IpcRegs.IPCRECVCOM == IPC_SET_BITS_32_PROTECTED)
945     {
946         pulAddress = (uint32_t *)IpcRegs.IPCRECVADDR;
947         *pulAddress |= (uint32_t)IpcRegs.IPCRECVDATA;
948         IpcRegs.IPCLOCALREPLY = *pulAddress;
949 
950         IpcRegs.IPCACK.all |= (ulStatusFlag | ulFlag);
951     }
952 
953     //
954     // Otherwise, only acknowledge the task flag.
955     //(Indicates to the Remote CPU there was an error)
956     //
957     else
958     {
959         IpcRegs.IPCACK.all |= (ulFlag);
960     }
961 
962     EDIS;
963 }
964 
965 //*****************************************************************************
966 //
967 //! Clears the designated bits in a 16/32-bit data word at Local CPU system
968 //! address
969 //!
970 //! \param ulFlag specifies Remote to Local IPC Flag number mask used to
971 //! indicate a command is being sent.
972 //! \param ulStatusFlag indicates the Remote to Local Flag number mask used to
973 //! report the status of the command sent back from the control system.
974 //!
975 //! This function will allow the Remote CPU system to clear bits specified by a
976 //! mask variable in a 16/32-bit word on the Local CPU system, and then read
977 //! back the word into the IPCLOCALREPLY register. The \e ulFlag
978 //! parameter accepts any one of the flag values \b IPC_FLAG1 - \b IPC_FLAG32,
979 //! and the \e ulStatusFlag parameter accepts any other one of the flag values
980 //! \b IPC_FLAG1 - \b IPC_FLAG32 and \b NO_FLAG.
981 //
982 //*****************************************************************************
983 void
IPCLiteRtoLClearBits(uint32_t ulFlag,uint32_t ulStatusFlag)984 IPCLiteRtoLClearBits(uint32_t ulFlag, uint32_t ulStatusFlag)
985 {
986     uint16_t* pusAddress;
987     uint32_t* pulAddress;
988 
989     //
990     // Wait until IPC Remote to Local request task is flagged
991     //
992     while (!(IpcRegs.IPCSTS.all & ulFlag))
993     {
994     }
995 
996     //
997     // If the command is correct for this function:
998     // Then clear the mask bits at the requested address
999     // and write back the 16/32-bit data to IPCLOCALREPLY.
1000     // Acknowledge the status flag and the task flag.
1001     //
1002     if (IpcRegs.IPCRECVCOM == IPC_CLEAR_BITS_16)
1003     {
1004         pusAddress = (uint16_t *)IpcRegs.IPCRECVADDR;;
1005         *pusAddress &= ~((uint16_t)IpcRegs.IPCRECVDATA);
1006         IpcRegs.IPCLOCALREPLY = (uint32_t)*pusAddress;
1007 
1008         IpcRegs.IPCACK.all |= (ulStatusFlag | ulFlag);
1009     }
1010     else if (IpcRegs.IPCRECVCOM == IPC_CLEAR_BITS_32)
1011     {
1012         pulAddress = (uint32_t *)IpcRegs.IPCRECVADDR;
1013         *pulAddress &= ~((uint32_t)IpcRegs.IPCRECVDATA);
1014         IpcRegs.IPCLOCALREPLY = *pulAddress;
1015 
1016         IpcRegs.IPCACK.all |= (ulStatusFlag | ulFlag);
1017     }
1018 
1019     //
1020     // Otherwise, only acknowledge the task flag.
1021     // (Indicates to Remote CPU there was an error)
1022     //
1023     else
1024     {
1025         IpcRegs.IPCACK.all |= (ulFlag);
1026     }
1027 }
1028 
1029 //*****************************************************************************
1030 //
1031 //! Clears the designated bits in a 16/32-bit data word at the Local CPU system
1032 //! write-protected address
1033 //!
1034 //! \param ulFlag specifies Remote to Local IPC Flag number mask used to
1035 //! indicate a command is being sent.
1036 //! \param ulStatusFlag indicates the Remote to Local Flag number mask used to
1037 //! report the status of the command sent back from the control system.
1038 //!
1039 //! This function will allow the Remote CPU system to clear bits specified by a
1040 //! mask variable in a 16/32-bit word on the Local CPU system, and then read
1041 //! back the word into the IPCLOCALREPLY register. The \e ulFlag
1042 //! parameter accepts any one of the flag values \b IPC_FLAG1 - \b IPC_FLAG32,
1043 //! and the \e ulStatusFlag parameter accepts any other one of the flag values
1044 //! \b IPC_FLAG1 - \b IPC_FLAG32 and \b NO_FLAG.
1045 //
1046 //*****************************************************************************
1047 void
IPCLiteRtoLClearBits_Protected(uint32_t ulFlag,uint32_t ulStatusFlag)1048 IPCLiteRtoLClearBits_Protected (uint32_t ulFlag, uint32_t ulStatusFlag)
1049 {
1050     uint16_t* pusAddress;
1051     uint32_t* pulAddress;
1052 
1053     //
1054     // Wait until IPC Remote to Local request task is flagged
1055     //
1056     while (!(IpcRegs.IPCSTS.all & ulFlag))
1057     {
1058     }
1059 
1060     //
1061     // If the command is correct for this function:
1062     // Then enable write access with EALLOW and
1063     // clear the mask bits at the requested address.
1064     // Write back the 16/32-bit data to IPCLOCALREPLY.
1065     // Restore the status of the EALLOW register.
1066     // Acknowledge the status flag and the task flag.
1067     //
1068     EALLOW;
1069 
1070     if (IpcRegs.IPCRECVCOM == IPC_CLEAR_BITS_16_PROTECTED)
1071     {
1072 
1073         pusAddress = (uint16_t *)IpcRegs.IPCRECVADDR;;
1074         *pusAddress &= ~((uint16_t)IpcRegs.IPCRECVDATA);
1075         IpcRegs.IPCLOCALREPLY = (uint32_t)*pusAddress;
1076 
1077         IpcRegs.IPCACK.all |= (ulStatusFlag | ulFlag);
1078     }
1079     else if (IpcRegs.IPCRECVCOM == IPC_CLEAR_BITS_32_PROTECTED)
1080     {
1081 
1082         pulAddress = (uint32_t *)IpcRegs.IPCRECVADDR;;
1083         *pulAddress &= ~((uint32_t)IpcRegs.IPCRECVDATA);
1084         IpcRegs.IPCLOCALREPLY = (uint32_t)*pulAddress;
1085 
1086         IpcRegs.IPCACK.all |= (ulStatusFlag | ulFlag);
1087     }
1088 
1089     //
1090     // Otherwise, only acknowledge the task flag.
1091     // (Indicates to Remote CPU there was an error)
1092     //
1093     else
1094     {
1095         IpcRegs.IPCACK.all |= (ulFlag);
1096     }
1097 
1098     EDIS;
1099 }
1100 
1101 //*****************************************************************************
1102 //
1103 //! Writes a 16/32-bit data word to Local CPU system address
1104 //!
1105 //! \param ulFlag specifies Remote to Local IPC Flag number mask used to
1106 //! indicate a command is being sent.
1107 //! \param ulStatusFlag indicates the Remote to Local Flag number mask used to
1108 //! report the status of the command sent back from the control system.
1109 //!
1110 //! This function will allow the Remote CPU system to write a 16/32-bit word
1111 //! to an address on the Local CPU system. The \e ulFlag
1112 //! parameter accepts any one of the flag values \b IPC_FLAG1 - \b IPC_FLAG32,
1113 //! and the \e ulStatusFlag parameter accepts any other one of the flag values
1114 //! \b IPC_FLAG1 - \b IPC_FLAG32 and \b NO_FLAG.
1115 //
1116 //*****************************************************************************
1117 void
IPCLiteRtoLDataWrite(uint32_t ulFlag,uint32_t ulStatusFlag)1118 IPCLiteRtoLDataWrite(uint32_t ulFlag, uint32_t ulStatusFlag)
1119 {
1120     uint32_t* pulAddress;
1121     uint16_t* pusAddress;
1122 
1123     //
1124     // Wait until IPC Remote to Local request task is flagged
1125     //
1126     while (!(IpcRegs.IPCSTS.all & ulFlag))
1127     {
1128     }
1129 
1130     //
1131     // If the command is correct for this function:
1132     // Then write the 16/32-bit data to the requested address
1133     // and write back the 16/32-bit data to IPCLOCALREPLY.
1134     // Acknowledge the status flag and the task flag.
1135     //
1136     if (IpcRegs.IPCRECVCOM == IPC_DATA_WRITE_16)
1137     {
1138         pusAddress = (uint16_t *)IpcRegs.IPCRECVADDR;;
1139         *pusAddress = (uint16_t)IpcRegs.IPCRECVDATA;
1140         IpcRegs.IPCLOCALREPLY = (uint32_t)*pusAddress;
1141 
1142         IpcRegs.IPCACK.all |= (ulStatusFlag | ulFlag);
1143     }
1144     else if (IpcRegs.IPCRECVCOM == IPC_DATA_WRITE_32)
1145     {
1146         pulAddress = (uint32_t *)IpcRegs.IPCRECVADDR;;
1147         *pulAddress = IpcRegs.IPCRECVDATA;
1148         IpcRegs.IPCLOCALREPLY = *pulAddress;
1149 
1150         IpcRegs.IPCACK.all |= (ulStatusFlag | ulFlag);
1151 
1152     }
1153 
1154     //
1155     // Otherwise, only acknowledge the task flag.
1156     // (Indicates to Remote CPU there was an error)
1157     //
1158     else
1159     {
1160         IpcRegs.IPCACK.all |= (ulFlag);
1161     }
1162 }
1163 
1164 //*****************************************************************************
1165 //
1166 //! Writes a 16/32-bit data word to a write-protected Local CPU system address
1167 //!
1168 //! \param ulFlag specifies Remote to Local IPC Flag number mask used to
1169 //! indicate a command is being sent.
1170 //! \param ulStatusFlag indicates the Remote to Local Flag number mask used to
1171 //! report the status of the command sent back from the control system.
1172 //!
1173 //! This function will allow the Remote CPU system to write a 16/32-bit word
1174 //! to an address on the Local CPU system. The \e ulFlag
1175 //! parameter accepts any one of the flag values \b IPC_FLAG1 - \b IPC_FLAG32,
1176 //! and the \e ulStatusFlag parameter accepts any other one of the flag values
1177 //! \b IPC_FLAG1 - \b IPC_FLAG32 and \b NO_FLAG.
1178 //
1179 //*****************************************************************************
1180 void
IPCLiteRtoLDataWrite_Protected(uint32_t ulFlag,uint32_t ulStatusFlag)1181 IPCLiteRtoLDataWrite_Protected(uint32_t ulFlag, uint32_t ulStatusFlag)
1182 {
1183     uint32_t* pulAddress;
1184     uint16_t* pusAddress;
1185 
1186     //
1187     // Wait until IPC Remote to Local request task is flagged
1188     //
1189     while (!(IpcRegs.IPCSTS.all & ulFlag))
1190     {
1191     }
1192 
1193     //
1194     // If the command is correct for this function:
1195     // Then enable write access with EALLOW and
1196     // write the 16/32-bit data to the requested address
1197     // and write back the 16/32-bit data to IPCLOCALREPLY.
1198     // Acknowledge the status flag and the task flag.
1199     //
1200     EALLOW;
1201 
1202     if (IpcRegs.IPCRECVCOM == IPC_DATA_WRITE_16_PROTECTED)
1203     {
1204         pusAddress = (uint16_t *)IpcRegs.IPCRECVADDR;;
1205         *pusAddress = (uint16_t)IpcRegs.IPCRECVDATA;
1206         IpcRegs.IPCLOCALREPLY = (uint32_t)*pusAddress;
1207 
1208         IpcRegs.IPCACK.all |= (ulStatusFlag | ulFlag);
1209     }
1210     else if (IpcRegs.IPCRECVCOM == IPC_DATA_WRITE_32_PROTECTED)
1211     {
1212         pulAddress = (uint32_t *)IpcRegs.IPCRECVADDR;
1213         *pulAddress = IpcRegs.IPCRECVDATA;
1214         IpcRegs.IPCLOCALREPLY = *pulAddress;
1215 
1216         IpcRegs.IPCACK.all |= (ulStatusFlag | ulFlag);
1217 
1218     }
1219 
1220     //
1221     // Otherwise, only acknowledge the task flag.
1222     // (Indicates to Remote CPU there was an error)
1223     //
1224     else
1225     {
1226         IpcRegs.IPCACK.all |= (ulFlag);
1227     }
1228 
1229     //
1230     // Restore write-protection status.
1231     //
1232     EDIS;
1233 }
1234 
1235 //*****************************************************************************
1236 //
1237 //! Calls a Local CPU function with a single optional parameter and return
1238 //! value.
1239 //!
1240 //! \param ulFlag specifies Remote to Local IPC Flag number mask used to
1241 //! indicate a command is being sent.
1242 //! \param ulStatusFlag indicates the Remote to Local Flag number mask used to
1243 //! report the status of the command sent back from the control system.
1244 //!
1245 //! This function will allow the Remote CPU system to call a Local CPU function
1246 //! with a single optional parameter and places an optional return value in the
1247 //! IPCLOCALREPLY register. The \e ulFlag parameter accepts any one of the flag
1248 //! values \b IPC_FLAG1 - \b IPC_FLAG32, and  the \e ulStatusFlag parameter
1249 //! accepts any other one of the flag values \b IPC_FLAG1 - \b IPC_FLAG32 and
1250 //! \b NO_FLAG.
1251 //
1252 //*****************************************************************************
1253 void
IPCLiteRtoLFunctionCall(uint32_t ulFlag,uint32_t ulStatusFlag)1254 IPCLiteRtoLFunctionCall(uint32_t ulFlag, uint32_t ulStatusFlag)
1255 {
1256     //
1257     // Wait until IPC Remote to Local request task is flagged
1258     //
1259     while (!(IpcRegs.IPCSTS.all & ulFlag))
1260     {
1261     }
1262 
1263     //
1264     // If the command is correct for this function:
1265     // Then call function at requested address
1266     // and if there is a return value, insert into
1267     // IPCLOCALREPLY register.
1268     // Acknowledge the status flag and the task flag.
1269     //
1270     if (IpcRegs.IPCRECVCOM == IPC_FUNC_CALL)
1271     {
1272         tfIpcFuncCall func_call = (tfIpcFuncCall)IpcRegs.IPCRECVADDR;
1273         IpcRegs.IPCLOCALREPLY = func_call(IpcRegs.IPCRECVDATA);
1274 
1275         IpcRegs.IPCACK.all |= (ulStatusFlag | ulFlag);
1276     }
1277 
1278     //
1279     // Otherwise, only acknowledge the task flag.
1280     //(Indicates to Remote CPU there was an error)
1281     //
1282     else
1283     {
1284         IpcRegs.IPCACK.all |= (ulFlag);
1285     }
1286 }
1287 
DelayLoop(void)1288 void DelayLoop (void)
1289 {
1290     __asm(" nop");
1291     __asm(" nop");
1292     __asm(" nop");
1293     __asm(" nop");
1294     __asm(" nop");
1295 }
1296 
1297 //*****************************************************************************
1298 // Close the Doxygen group.
1299 //! @}
1300 //*****************************************************************************
1301 
1302 
1303