]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/pdk.git/blob - packages/ti/drv/pa/example/emacExample/k2e/c66/bios/singlecore_osal.c
pa-lld: add to PDK
[processor-sdk/pdk.git] / packages / ti / drv / pa / example / emacExample / k2e / c66 / bios / singlecore_osal.c
1 /**
2  *   @file  singlecore_osal.c
3  *
4  *   @brief   
5  *      This is a sample OS Abstraction Layer (AL) file implemented
6  *      using XDC/BIOS APIs.
7  *
8  *      System integrator is advised to review these implementations and
9  *      modify them to suit it to application requirements.
10  *
11  *      This OSAL implementation uses the <b> Approach 1 </b> documented.
12  *
13  *  \par
14  *  ============================================================================
15  *  @n   (C) Copyright 2009, Texas Instruments, Inc.
16  * 
17  *  Redistribution and use in source and binary forms, with or without 
18  *  modification, are permitted provided that the following conditions 
19  *  are met:
20  *
21  *    Redistributions of source code must retain the above copyright 
22  *    notice, this list of conditions and the following disclaimer.
23  *
24  *    Redistributions in binary form must reproduce the above copyright
25  *    notice, this list of conditions and the following disclaimer in the 
26  *    documentation and/or other materials provided with the   
27  *    distribution.
28  *
29  *    Neither the name of Texas Instruments Incorporated nor the names of
30  *    its contributors may be used to endorse or promote products derived
31  *    from this software without specific prior written permission.
32  *
33  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
34  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
35  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
36  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
37  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
38  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
39  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
40  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
41  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
42  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
43  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44  *
45 */
46 /* Standard C-native includes  */
47 #include <stdlib.h>
48 #include <string.h>
50 /* XDC/BIOS includes */
51 #include <xdc/std.h>
52 #include <xdc/runtime/IHeap.h>
53 #include <xdc/runtime/System.h>
54 #include <xdc/runtime/Memory.h>
55 #include <xdc/runtime/Error.h>
57 #include <ti/sysbios/BIOS.h>
58 #include <ti/sysbios/hal/Hwi.h>
59 #include <ti/sysbios/knl/Task.h>
60 #include <ti/sysbios/knl/Semaphore.h>
61 #include <ti/sysbios/heaps/HeapBuf.h>
62 #include <ti/sysbios/heaps/HeapMem.h>
64 #include <xdc/cfg/global.h>
66 /* CSL CHIP, SEM Functional layer includes */
67 #include <ti/csl/csl_chip.h>
68 #include <ti/csl/csl_semAux.h>
70 /* CSL Cache module includes */
71 #include <ti/csl/csl_cacheAux.h>
72 /* CSL XMC module includes */
73 #include <ti/csl/csl_xmcAux.h>
75 /**********************************************************************
76  ****************************** Defines *******************************
77  **********************************************************************/
79 #define     MAX_NUM_CORES       1
81 /* Hardware Semaphore to synchronize access from
82  * multiple applications (PA applications and non-PASS applications)
83  * across different cores to the QMSS library.
84  */
85 #define     QMSS_HW_SEM         3 
87 /* Hardware Semaphore to synchronize access from
88  * multiple applications (PASS applications and non-PASS applications)
89  * across different cores to the CPPI library.
90  */
91 #define     CPPI_HW_SEM         4 
93 /* Hardware Semaphore to synchronize access from
94  * multiple applications (PASS applications and non-PASS applications)
95  * across different cores to the PA library.
96  */
97 #define     PA_HW_SEM           5 
99 #undef L2_CACHE
100 #ifdef L2_CACHE
101     /* Invalidate L2 cache. This should invalidate L1D as well. 
102      * Wait until operation is complete. */    
103 #define SYS_CACHE_INV(addr, size, code)    CACHE_invL2 (addr, size, code)
105     /* Writeback L2 cache. This should Writeback L1D as well. 
106      * Wait until operation is complete. */ 
107 #define SYS_CACHE_WB(addr, size, code)     CACHE_wbL2 (addr, size, code)
109 #else       
110     /* Invalidate L1D cache and wait until operation is complete. 
111      * Use this approach if L2 cache is not enabled */    
112 #define SYS_CACHE_INV(addr, size, code)    CACHE_invL1d (addr, size, code)
113     /* Writeback L1D cache and wait until operation is complete. 
114      * Use this approach if L2 cache is not enabled */    
115 #define SYS_CACHE_WB(addr, size, code)     CACHE_wbL1d (addr, size, code)
117 #endif
120 /**********************************************************************
121  ************************** Global Variables **************************
122  **********************************************************************/
123 UInt32      cpswCppiMallocCounter   =   0;
124 UInt32      cpswCppiFreeCounter     =   0;
125 UInt32      cpswQmssMallocCounter   =   0;
126 UInt32      cpswQmssFreeCounter     =   0;
127 uint32_t    rmMallocCounter         =   0;
128 uint32_t    rmFreeCounter           =   0;
129 UInt32      coreKey [MAX_NUM_CORES];
131 /**********************************************************************
132  *********************** CPPI OSAL Functions **************************
133  **********************************************************************/
135 /**
136  * ============================================================================
137  *  @n@b Osal_cppiCsEnter
138  *
139  *  @b  brief
140  *  @n  This API ensures multi-core and multi-threaded
141  *      synchronization to the caller.
142  *
143  *      This is a BLOCKING API.
144  *
145  *      This API ensures multi-core synchronization between
146  *      multiple processes trying to access CPPI shared
147  *      library at the same time.
148  *
149  *  @param[in]  
150  *  @n  None
151  *
152  *  @return     
153  *  @n  Handle used to lock critical section
154  * =============================================================================
155  */
156 Ptr Osal_cppiCsEnter (Void)
158     /* Get the hardware semaphore. 
159      *
160      * Acquire Multi core CPPI synchronization lock 
161      */
162     while ((CSL_semAcquireDirect (CPPI_HW_SEM)) == 0);
164     /* Disable all interrupts and OS scheduler. 
165      *
166      * Acquire Multi threaded / process synchronization lock.
167      */
168     coreKey [CSL_chipReadReg (CSL_CHIP_DNUM)] = Hwi_disable();
170     return NULL;
173 /**
174  * ============================================================================
175  *  @n@b Osal_cppiCsExit
176  *
177  *  @b  brief
178  *  @n  This API needs to be called to exit a previously
179  *      acquired critical section lock using @a Osal_cppiCsEnter ()
180  *      API. It resets the multi-core and multi-threaded lock,
181  *      enabling another process/core to grab CPPI access.
182  *
183  *  @param[in]  CsHandle
184  *      Handle for unlocking critical section.
185  *
186  *  @return     None
187  * =============================================================================
188  */
189 Void Osal_cppiCsExit (Ptr CsHandle)
191     /* Enable all interrupts and enables the OS scheduler back on.
192      *
193      * Release multi-threaded / multi-process lock on this core.
194      */
195     Hwi_restore(coreKey [CSL_chipReadReg (CSL_CHIP_DNUM)]);
197     /* Release the hardware semaphore 
198      *
199      * Release multi-core lock.
200      */ 
201     CSL_semReleaseSemaphore (CPPI_HW_SEM);
203     return;
206 /**
207  * ============================================================================
208  *  @n@b Osal_cppiMalloc
209  *
210  *  @b  brief
211  *  @n  This API allocates a memory block of a given
212  *      size specified by input parameter 'num_bytes'.
213  *
214  *      This API should allocate memory from shared memory if the test applications
215  *      are to be run on multiple cores.
216  *
217  *  @param[in]  num_bytes
218  *      Number of bytes to be allocated.
219  *
220  *  @return
221  *      Allocated block address
222  * =============================================================================
223  */
224 Ptr Osal_cppiMalloc (UInt32 num_bytes)
226         Error_Block         errorBlock;
228     /* Increment the allocation counter. */
229     cpswCppiMallocCounter++;    
231         /* Allocate memory.  */
232         return Memory_alloc(NULL, num_bytes, 0, &errorBlock);
235 /**
236  * ============================================================================
237  *  @n@b Osal_cppiFree
238  *
239  *  @b  brief
240  *  @n  This API frees and restores a given memory location 
241  *      pointer 'dataPtr' of size 'num_bytes' to its
242  *      original heap location. Frees up memory allocated using 
243  *      @a Osal_cppiMalloc ()
244  *
245  *  @param[in]  dataPtr
246  *      Pointer to the memory block to be cleaned up.
247  *
248  *  @param[in]  num_bytes
249  *      Size of the memory block to be cleaned up.
250  *
251  *  @return
252  *      Not Applicable
253  * =============================================================================
254  */
255 Void Osal_cppiFree (Ptr dataPtr, UInt32 num_bytes)
257     /* Increment the free counter. */
258     cpswCppiFreeCounter++;      
260     /* Free up the memory */
261     if (dataPtr)
262     {
263         /* Convert the global address to local address since
264          * thats what the heap understands.
265          */
266         Memory_free(NULL, dataPtr, num_bytes);
267     }
270 /**
271  *  @b Description
272  *  @n  
273  *      The function is used to indicate that a block of memory is 
274  *      about to be accessed. If the memory block is cached then this 
275  *      indicates that the application would need to ensure that the 
276  *      cache is updated with the data from the actual memory.
277  *
278  *  @param[in]  blockPtr
279  *       Address of the block which is to be invalidated
280  *
281  *  @param[in]  size
282  *       Size of the block to be invalidated
284  *  @retval
285  *      Not Applicable
286  */
287 void Osal_cppiBeginMemAccess (void *blockPtr, uint32_t size)
290     uint32_t    key;
292     /* Disable Interrupts */
293     key = Hwi_disable();
295     /* Cleanup the prefetch buffer also. */
296     CSL_XMC_invalidatePrefetchBuffer();
297     
298     SYS_CACHE_INV (blockPtr, size, CACHE_FENCE_WAIT);
299     
300     asm   (" nop      4");
301     asm   (" nop      4");
302     asm   (" nop      4");
303     asm   (" nop      4");
304     
305     /* Reenable Interrupts. */
306     Hwi_restore(key);
307     
308     return;
311 /**
312  *  @b Description
313  *  @n  
314  *      The function is used to indicate that the block of memory has 
315  *      finished being accessed. If the memory block is cached then the 
316  *      application would need to ensure that the contents of the cache 
317  *      are updated immediately to the actual memory. 
318  *
319  *  @param[in]  blockPtr
320  *       Address of the block which is to be written back
321  *
322  *  @param[in]  size
323  *       Size of the block to be written back
325  *  @retval
326  *      Not Applicable
327  */
328 void Osal_cppiEndMemAccess (void *blockPtr, uint32_t size)
330     uint32_t    key;
332     /* Disable Interrupts */
333     key = Hwi_disable();
335     SYS_CACHE_WB (blockPtr, size, CACHE_FENCE_WAIT);
337     asm   (" nop      4");
338     asm   (" nop      4");
339     asm   (" nop      4");
340     asm   (" nop      4");
341     
342     /* Reenable Interrupts. */
343     Hwi_restore(key);
344     return;
347 /**********************************************************************
348  *********************** QMSS OSAL Functions **************************
349  **********************************************************************/
351 /**
352  * ============================================================================
353  *  @n@b Osal_qmssCsEnter
354  *
355  *  @b  brief
356  *  @n  This API ensures multi-core and multi-threaded
357  *      synchronization to the caller.
358  *
359  *      This is a BLOCKING API.
360  *
361  *      This API ensures multi-core synchronization between
362  *      multiple processes trying to access QMSS shared
363  *      library at the same time.
364  *
365  *  @param[in]  None
366  *
367  *  @return     
368  *      Handle used to lock critical section
369  * =============================================================================
370  */
371 Ptr Osal_qmssCsEnter (Void)
373     /* Get the hardware semaphore. 
374      *
375      * Acquire Multi core QMSS synchronization lock 
376      */
377     while ((CSL_semAcquireDirect (QMSS_HW_SEM)) == 0);
379     /* Disable all interrupts and OS scheduler. 
380      *
381      * Acquire Multi threaded / process synchronization lock.
382      */
383     coreKey [CSL_chipReadReg (CSL_CHIP_DNUM)] = Hwi_disable();
385     return NULL;
388 /**
389  * ============================================================================
390  *  @n@b Osal_qmssCsExit
391  *
392  *  @b  brief
393  *  @n  This API needs to be called to exit a previously
394  *      acquired critical section lock using @a Osal_cpswQmssCsEnter ()
395  *      API. It resets the multi-core and multi-threaded lock,
396  *      enabling another process/core to grab QMSS access.
397  *
398  *  @param[in]  CsHandle
399  *      Handle for unlocking critical section.
400  *
401  *  @return     None
402  * =============================================================================
403  */
404 Void Osal_qmssCsExit (Ptr CsHandle)
406     /* Enable all interrupts and enables the OS scheduler back on.
407      *
408      * Release multi-threaded / multi-process lock on this core.
409      */
410     Hwi_restore(coreKey [CSL_chipReadReg (CSL_CHIP_DNUM)]);
412     /* Release the hardware semaphore 
413      *
414      * Release multi-core lock.
415      */ 
416     CSL_semReleaseSemaphore (QMSS_HW_SEM);
418     return;
421  /**
422  * ============================================================================
423  *  @n@b Osal_qmssAccCsEnter
424  *
425  *  @b  brief
426  *  @n  This API ensures multi-core and multi-threaded
427  *      synchronization to the caller.
428  *
429  *      This is a BLOCKING API.
430  *
431  *      This API ensures multi-core synchronization between
432  *      multiple processes trying to access QMSS shared
433  *      library at the same time.
434  *
435  *  @param[in]  None
436  *
437  *  @return     
438  *      Handle used to lock critical section
439  * =============================================================================
440  */
441 Ptr Osal_qmssAccCsEnter (Void)
443     /* This is a suboptimal implementation for this OSAL, please refer to
444          * QMSS examples for optimal implementation of this function 
445          */
447   return (Osal_qmssCsEnter());
450 /**
451  * ============================================================================
452  *  @n@b Osal_qmssAccCsExit
453  *
454  *  @b  brief
455  *  @n  This API needs to be called to exit a previously
456  *      acquired critical section lock using @a Osal_qmssAccCsEnter ()
457  *      API. It resets the multi-core and multi-threaded lock,
458  *      enabling another process/core to grab QMSS access.
459  *
460  *  @param[in]  CsHandle
461  *      Handle for unlocking critical section.
462  *
463  *  @return     None
464  * =============================================================================
465  */
466 Void Osal_qmssAccCsExit (Ptr CsHandle)
468     /* This is a suboptimal implementation for this OSAL, please refer to
469          * QMSS examples for optimal implementation of this function 
470          */   
471    Osal_qmssCsExit(CsHandle);
472    return;
474 /**
475  * ============================================================================
476  *  @n@b Osal_qmssMtCsEnter
477  *
478  *  @b  brief
479  *  @n  This API ensures ONLY multi-threaded
480  *      synchronization to the QMSS user.
481  *
482  *      This is a BLOCKING API.
483  *
484  *  @param[in] None
485  *
486  *  @return     
487  *       Handle used to lock critical section
488  * =============================================================================
489  */
490 Ptr Osal_qmssMtCsEnter (Void)
492     /* Disable all interrupts and OS scheduler. 
493      *
494      * Acquire Multi threaded / process synchronization lock.
495      */
496     //coreKey [CSL_chipReadReg (CSL_CHIP_DNUM)] = Hwi_disable();
498     return NULL;
501 /**
502  * ============================================================================
503  *  @n@b Osal_qmssMtCsExit
504  *
505  *  @b  brief
506  *  @n  This API needs to be called to exit a previously
507  *      acquired critical section lock using @a Osal_cpswQmssMtCsEnter ()
508  *      API. It resets the multi-threaded lock, enabling another process
509  *      on the current core to grab it.
510  *
511  *  @param[in]  CsHandle
512  *      Handle for unlocking critical section.
513  *
514  *  @return     None
515  * =============================================================================
516  */
517 Void Osal_qmssMtCsExit (Ptr CsHandle)
519     /* Enable all interrupts and enables the OS scheduler back on.
520      *
521      * Release multi-threaded / multi-process lock on this core.
522      */
523     //Hwi_restore(key);
525     return;
528 /**
529  * ============================================================================
530  *  @n@b Osal_qmssMalloc
531  *
532  *  @b  brief
533  *  @n  This API allocates a memory block of a given
534  *      size specified by input parameter 'num_bytes'.
535  *
536  *  @param[in]  num_bytes
537  *      Number of bytes to be allocated.
538  *
539  *  @return
540  *      Allocated block address
541  * =============================================================================
542  */
543 Ptr Osal_qmssMalloc (UInt32 num_bytes)
545         Error_Block         errorBlock;
547     /* Increment the allocation counter. */
548     cpswQmssMallocCounter++;    
550         /* Allocate memory.  */
551         return Memory_alloc(NULL, num_bytes, 0, &errorBlock);
554 /**
555  * ============================================================================
556  *  @n@b Osal_qmssFree
557  *
558  *  @b  brief
559  *  @n  This API frees and restores a given memory location 
560  *      pointer 'dataPtr' of size 'num_bytes' to its
561  *      original heap location. Frees up memory allocated using 
562  *      @a Osal_qmssMalloc ()
563  *
564  *  @param[in]  dataPtr
565  *      Pointer to the memory block to be cleaned up.
566  *
567  *  @param[in]  num_bytes
568  *      Size of the memory block to be cleaned up.
569  *
570  *  @return
571  *      Not Applicable
572  * =============================================================================
573  */
574 Void Osal_qmssFree (Ptr dataPtr, UInt32 num_bytes)
576     /* Increment the free counter. */
577     cpswQmssFreeCounter++;      
579     /* Free up the memory */
580     if (dataPtr)
581     {
582         /* Convert the global address to local address since
583          * thats what the heap understands.
584          */
585         Memory_free(NULL, dataPtr, num_bytes);
586     }
589 /**
590  *  @b Description
591  *  @n  
592  *      The function is used to indicate that a block of memory is 
593  *      about to be accessed. If the memory block is cached then this 
594  *      indicates that the application would need to ensure that the 
595  *      cache is updated with the data from the actual memory.
596  *
597  *  @param[in]  blockPtr
598  *       Address of the block which is to be invalidated
599  *
600  *  @param[in]  size
601  *       Size of the block to be invalidated
603  *  @retval
604  *      Not Applicable
605  */
606 void Osal_qmssBeginMemAccess (void *blockPtr, uint32_t size)
608     uint32_t    key;
610     /* Disable Interrupts */
611     key = Hwi_disable();
613     /* Cleanup the prefetch buffer also. */
614     CSL_XMC_invalidatePrefetchBuffer();
615     
616     SYS_CACHE_INV (blockPtr, size, CACHE_FENCE_WAIT);
617     
618     asm   (" nop      4");
619     asm   (" nop      4");
620     asm   (" nop      4");
621     asm   (" nop      4");
622     
623     /* Reenable Interrupts. */
624     Hwi_restore(key);
625     
626     return;
629 /**
630  *  @b Description
631  *  @n  
632  *      The function is used to indicate that the block of memory has 
633  *      finished being accessed. If the memory block is cached then the 
634  *      application would need to ensure that the contents of the cache 
635  *      are updated immediately to the actual memory. 
636  *
637  *  @param[in]  blockPtr
638  *       Address of the block which is to be written back
639  *
640  *  @param[in]  size
641  *       Size of the block to be written back
643  *  @retval
644  *      Not Applicable
645  */
646 void Osal_qmssEndMemAccess (void *blockPtr, uint32_t size)
648     uint32_t    key;
650     /* Disable Interrupts */
651     key = Hwi_disable();
653     SYS_CACHE_WB (blockPtr, size, CACHE_FENCE_WAIT);
655     asm   (" nop      4");
656     asm   (" nop      4");
657     asm   (" nop      4");
658     asm   (" nop      4");
659     
660     /* Reenable Interrupts. */
661     Hwi_restore(key);
662     return;
665 /**********************************************************************
666  *********************** PASS OSAL Functions **************************
667  **********************************************************************/
668  
669 /**
670  * @brief  This macro is used to alert the application that the PA is
671  *         going to access table memory. The application must ensure
672  *         cache coherency 
673  *
674  *
675  * <b> Prototype: </b>
676  *  The following is the C prototype for the expected OSAL API.
677  *
678  *  @verbatim
679         void Osal_paBeginMemAccess (void* addr, uint32_t sizeWords)
680     @endverbatim
681  *
682  *  <b> Parameters </b>
683  *  @n  The address of the table to be accessed
684  *  @n  The number of bytes in the table
685  *
686  *  @note PA will make nested calls to this function for memory access
687  *        protection of different memory tables. 
688  */
690 void Osal_paBeginMemAccess (Ptr addr, UInt32 size)
692     uint32_t    key;
693     
694     /* Disable Interrupts */
695     key = Hwi_disable();
697     /* Cleanup the prefetch buffer also. */
698     CSL_XMC_invalidatePrefetchBuffer();
699     
700     SYS_CACHE_INV (addr, size, CACHE_FENCE_WAIT);
701     
702     asm   (" nop      4");
703     asm   (" nop      4");
704     asm   (" nop      4");
705     asm   (" nop      4");
706     
707     /* Reenable Interrupts. */
708     Hwi_restore(key);
712 /**
713  * @brief  This macro is used to alert the application that the PA
714  *         has completed access to table memory. This call will always
715  *         be made following a call to Osal_paBeginMemAccess and have
716  *         the same parameters
717  *
718  * <b> Prototype: </b>
719  *  The following is the C prototype for the expected OSAL API.
720  *
721  *  @verbatim
722         void Osal_paEndMemAccess (void* addr, uint32_t sizeWords)
723     @endverbatim
724  *
725  *  <b> Parameters </b>
726  *  @n The address of the table to be accessed
727  *  @n The number of bytes in the table
728  *
729  *  @note PA will make nested calls to this function for memory access
730  *        protection of different memory tables. 
731  */
733 void Osal_paEndMemAccess (Ptr addr, UInt32 size)
735     uint32_t    key;
736     
737     /* Disable Interrupts */
738     key = Hwi_disable();
739     
740     SYS_CACHE_WB (addr, size, CACHE_FENCE_WAIT);
742     asm   (" nop      4");
743     asm   (" nop      4");
744     asm   (" nop      4");
745     asm   (" nop      4");
746     
747     /* Reenable Interrupts. */
748     Hwi_restore(key);
749     
753 /**
754  *  @b Description
755  *  @n  
756  *      The function is used to enter a critical section.
757  *      Function protects against 
758  *
759  *      access from multiple threads on single core
760  *      and
761  *      access from multiple cores 
762  *
763  *  @param[in]  key
764  *      Key used to lock the critical section.
765  *
766  *  @retval
767  *      Not Applicable
768  */
769 Void Osal_paMtCsEnter (uint32_t *key)
772     /* Get the hardware semaphore. 
773      *
774      * Acquire Multi core PA synchronization lock 
775      */
776      while ((CSL_semAcquireDirect (PA_HW_SEM)) == 0);
777      *key = 0;
780 /**
781  *  @b Description
782  *  @n  
783  *      The function is used to exit a critical section 
784  *      protected using Osal_salldCsEnter() API.
785  *
786  *  @param[in]  key
787  *      Key used to unlock the critical section.
788  *
789  *  @retval
790  *      Not Applicable
791  */
792 Void Osal_paMtCsExit (uint32_t key)
794     /* Release the hardware semaphore */
795     CSL_semReleaseSemaphore (PA_HW_SEM);
798 /**
799  *  @b Description
800  *  @n
801  *      The function is used to allocate a memory block of the specified size.
802  *
803  *  @param[in]  num_bytes
804  *      Number of bytes to be allocated.
805  *
806  *  @retval
807  *      Allocated block address
808  */
809 void *Osal_rmMalloc (uint32_t num_bytes)
811         Error_Block     errorBlock;
813     /* Increment the allocation counter. */
814     rmMallocCounter++;
816         /* Allocate memory. */
817         return Memory_alloc(NULL, num_bytes, 0, &errorBlock);
820 /**
821  *  @b Description
822  *  @n
823  *      The function is used to free a memory block of the specified size.
824  *
825  *  @param[in]  ptr
826  *      Pointer to the memory block to be cleaned up.
827  *
828  *  @param[in]  size
829  *      Size of the memory block to be cleaned up.
830  *
831  *  @retval
832  *      Not Applicable
833  */
834 void Osal_rmFree (void *ptr, uint32_t size)
836     /* Increment the free counter. */
837     rmFreeCounter++;
838         Memory_free(NULL, ptr, size);
841 /* FUNCTION PURPOSE: Critical section enter
842  ***********************************************************************
843  * DESCRIPTION: The function is used to enter a critical section.
844  *              Function protects against
845  *
846  *              access from multiple cores
847  *              and
848  *              access from multiple threads on single core
849  */
850 void *Osal_rmCsEnter(void)
853     return NULL;
856 /* FUNCTION PURPOSE: Critical section exit
857  ***********************************************************************
858  * DESCRIPTION: The function is used to exit a critical section
859  *              protected using Osal_cppiCsEnter() API.
860  */
861 void Osal_rmCsExit(void *CsHandle)
866 /* FUNCTION PURPOSE: Multi-threaded critical section enter
867 ***********************************************************************
868 * DESCRIPTION: The function is used to enter a multi-threaded critical
869 *              section. Function protects against 
870  *      
871  *              access from multiple threads on single core
872 */  
873 void *Osal_rmMtCsEnter(void *mtSemObj)
876     return NULL;
879 /* FUNCTION PURPOSE: Multi-threaded critical section exit
880 ***********************************************************************
881 * DESCRIPTION: The function is used to exit a multi-threaded critical
882 *              section protected using Osal_rmMtCsEnter() API.
883 */  
884 void Osal_rmMtCsExit(void *mtSemObj, void *CsHandle)
889 /* FUNCTION PURPOSE: Critical section exit
890  ***********************************************************************
891  * DESCRIPTION: The function is used to indicate that a block of memory is
892  *              about to be accessed. If the memory block is cached then this
893  *              indicates that the application would need to ensure that the
894  *              cache is updated with the data from the actual memory.
895  */
896 void Osal_rmBeginMemAccess(void *ptr, uint32_t size)
898     uint32_t    key;
900     /* Disable Interrupts */
901     key = Hwi_disable();
903     /* Cleanup the prefetch buffer also. */
904     CSL_XMC_invalidatePrefetchBuffer();
906 #ifdef L2_CACHE
907     /* Invalidate L2 cache. This should invalidate L1D as well.
908      * Wait until operation is complete. */
909     CACHE_invL2 (ptr, size, CACHE_FENCE_WAIT);
910 #else
911     /* Invalidate L1D cache and wait until operation is complete.
912      * Use this approach if L2 cache is not enabled */
913     CACHE_invL1d (ptr, size, CACHE_FENCE_WAIT);
914 #endif
916     /* Reenable Interrupts. */
917     Hwi_restore(key);
919     return;
922 /* FUNCTION PURPOSE: Critical section exit
923  ***********************************************************************
924  * DESCRIPTION: The function is used to indicate that the block of memory has
925  *              finished being accessed. If the memory block is cached then the
926  *              application would need to ensure that the contents of the cache
927  *              are updated immediately to the actual memory.
928  */
929 void Osal_rmEndMemAccess(void *ptr, uint32_t size)
931     uint32_t    key;
933     /* Disable Interrupts */
934     key = Hwi_disable();
936 #ifdef L2_CACHE
937     /* Writeback L2 cache. This should Writeback L1D as well.
938      * Wait until operation is complete. */
939     CACHE_wbL2 (ptr, size, CACHE_FENCE_WAIT);
941 #else
942     /* Writeback L1D cache and wait until operation is complete.
943      * Use this approach if L2 cache is not enabled */
944     CACHE_wbL1d (ptr, size, CACHE_FENCE_WAIT);
945 #endif
947     /* Reenable Interrupts. */
948     Hwi_restore(key);
950     return;
953 /**
954  *  @b Description
955  *  @n
956  *      The function is used to create a task blocking object
957  *      capable of blocking the task a RM instance is running
958  *      within
959  *
960  *  @retval
961  *      Allocated task blocking object
962  */
963 void *Osal_rmTaskBlockCreate(void)
965     Semaphore_Params semParams;
967     Semaphore_Params_init(&semParams);
968     return((void *)Semaphore_create(0, &semParams, NULL));
971 /**
972  *  @b Description
973  *  @n
974  *      The function is used to block a task whose context a
975  *      RM instance is running within.
976  *
977  *  @param[in]  handle
978  *      Task blocking object handle.
979  *
980  *  @retval
981  *      Not Applicable
982  */
983 void Osal_rmTaskBlock(void *handle)
985     Semaphore_pend((Semaphore_Handle)handle, BIOS_WAIT_FOREVER);
988 /**
989  *  @b Description
990  *  @n
991  *      The function is used to unblock a task whose context a
992  *      RM instance is running within.
993  *
994  *  @param[in]  handle
995  *      Task blocking object handle.
996  *
997  *  @retval
998  *      Not Applicable
999  */
1000 void Osal_rmTaskUnblock(void *handle)
1002     Semaphore_post((Semaphore_Handle)handle);
1005 /**
1006  *  @b Description
1007  *  @n
1008  *      The function is used to delete a task blocking object
1009  *      provided to a RM instance
1010  *
1011  *  @param[in]  handle
1012  *      Task blocking object handle.
1013  *
1014  *  @retval
1015  *      Not Applicable
1016  */
1017 void Osal_rmTaskBlockDelete(void *handle)
1019     Semaphore_delete((Semaphore_Handle *)&handle);
1022 /**
1023  *  @b Description
1024  *  @n
1025  *      The function is the RM OSAL Logging API which logs
1026  *      the messages on the console.
1027  *
1028  *  @param[in]  fmt
1029  *      Formatted String.
1030  *
1031  *  @retval
1032  *      Not Applicable
1033  */
1034 void Osal_rmLog (char *fmt, ... )
1036     VaList ap;
1038     va_start(ap, fmt);
1039     System_vprintf(fmt, ap);
1040     va_end(ap);