]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/pdk.git/blob - packages/ti/osal/arch/core/c7x/Arch_util.c
[OSAL]: Added testcase for task sub module
[processor-sdk/pdk.git] / packages / ti / osal / arch / core / c7x / Arch_util.c
1 /*
2  * Copyright (c) 2016-2018, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * *  Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  *
12  * *  Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * *  Neither the name of Texas Instruments Incorporated nor the names of
17  *    its contributors may be used to endorse or promote products derived
18  *    from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 /*
33  *  ======== Arch_util.c ========
34  */
37 #include <stdint.h>
38 #include <stdbool.h>
39 #include <stdlib.h>
40 #include <c7x.h> 
41 #include <ti/osal/src/nonos/Nonos_config.h>
42 #include <ti/csl/tistdtypes.h>
44 /* Local structure definition */
45 typedef struct HwiP_nonOs_s {
46     Bool        used;
47     Hwi_Struct  hwi;
48 } HwiP_nonOs;
50 /* Local hwi structures */
51 static HwiP_nonOs hwiStructs[OSAL_NONOS_CONFIGNUM_HWI] = {0};
53 /*
54  * Dummy function to check size during compile time
55  *  ======== HwiP_compileTime_SizeChk ========
56  */
58 void OsalArch_compileTime_SizeChk(void)
59 {
60     #pragma diag_suppress 179
61     OSAL_COMPILE_TIME_SIZE_CHECK (sizeof(HwiP_nonOs),OSAL_NONOS_HWIP_SIZE_BYTES);
62 }
64 static bool gFirstTime = (bool)false;
65 //TODO: Integrate to CSL once C7x arch is supported
66 //static CSL_IntcContext               gContext;
67 //static CSL_IntcEventHandlerRecord    gEventRecord[OSAL_NONOS_CONFIGNUM_HWI];
69 /* This function enables the interrupt for a given interrupt number */
70 void OsalArch_enableInterrupt(uint32_t intNum)
71 {
72     //TODO: Integrate to CSL once C7x arch is supported
73     return;
74 }
76 /* This function disables the interrupt for a given interrupt number */
77 void OsalArch_disableInterrupt(uint32_t intNum)
78 {
79     //TODO: Integrate to CSL once C7x arch is supported
80     return;
81 }
83 /* Below function clears interrupt in the chip level */
84 void OsalArch_clearInterrupt(uint32_t intNum)
85 {
86     //TODO: Integrate to CSL once C7x arch is supported
87     return;
88 }
89 /* Below function globally disable interrupt in the chip level */
90 uintptr_t OsalArch_globalDisableInterrupt(void)
91 {
92   //TODO: Integrate to CSL once C7x arch is supported
93   return 0;
94 }
96 /* Below function globally restore interrupt in the chip level */
97 void OsalArch_globalRestoreInterrupt (uintptr_t restoreValue)
98 {
99     //TODO: Integrate to CSL once C7x arch is supported
102 /* Below function registers the interrupt for a given ISR */
103 HwiP_Handle OsalArch_HwiPCreate(uint32_t interruptNum, HwiP_Fxn hwiFxn,
104                           const HwiP_Params *params)
106     Hwi_Struct                   *hwi_handle = (Hwi_Struct *) NULL_PTR;
107     //CSL_IntcParam                 vectId;
109     uint32_t          i;
110     uintptr_t         key;
111     uintptr_t         temp;
112     HwiP_nonOs       *hwiPool;
113     uint32_t          maxHwi;
114     HwiP_Handle       retHandle;
116     /* Check if user has specified any memory block to be used, which gets
117      * the precedence over the internal static memory block
118      */
119     if ((uintptr_t)NULL_PTR != gOsal_HwAttrs.extHwiPBlock.base)
120     {
121         /* pick up the external memory block configured */
122         hwiPool        = (HwiP_nonOs *) gOsal_HwAttrs.extHwiPBlock.base;
123         temp           = ((uintptr_t) hwiPool) + gOsal_HwAttrs.extHwiPBlock.size;
124         maxHwi         = (uint32_t)(temp/(sizeof(Hwi_Struct)));
125     }
126     else
127     {
128         /* Pick up the internal static memory block */
129         hwiPool        = (HwiP_nonOs *) &hwiStructs[0];
130         maxHwi         = OSAL_NONOS_CONFIGNUM_HWI;
131     }
133     if (NULL_PTR == params)
134     {
135         retHandle = (HwiP_Handle)(NULL_PTR);
136     }
137     else
138     {
139         key = OsalArch_globalDisableInterrupt();
140         for (i = 0U; i < maxHwi; i++) {
141             if (FALSE == hwiPool[i].used) {
142                 hwiPool[i].used = TRUE;
143                 break;
144             }
145         }
146         OsalArch_globalRestoreInterrupt(key);
148         if (i != maxHwi)
149         {
150             hwi_handle = &(hwiPool[i].hwi);
151             retHandle  = (HwiP_Handle)&hwiPool[i];
152         }
153         else
154         {
155             retHandle  = (HwiP_Handle)(NULL_PTR);
156         }
158         if ((Hwi_Struct *) NULL_PTR != hwi_handle)
159         {
160             //if (FALSE == gFirstTime) {
161             //  /* record the index in the handle */
162             //  gContext.numEvtEntries      = OSAL_NONOS_CONFIGNUM_HWI;
163             //  gContext.eventhandlerRecord = gEventRecord;
164             //  //TODO: Integrate to CSL once C7x arch is supported
165             //  //CSL_intcInit(&gContext);
166             //  gFirstTime = TRUE;
167       //}
169              //TODO: Integrate to CSL once C7x arch is supported
170              //CSL_intcGlobalNmiEnable();
171              //CSL_intcGlobalEnable(NULL_PTR);
172              //vectId = (CSL_IntcParam)interruptNum;
173              //
174              //hwi_handle->handle = CSL_intcOpen (&hwi_handle->intcObj, params->evtId, &vectId, NULL_PTR);
175              //
176              //if(hwi_handle->handle != NULL_PTR)
177              //{
178              //    CSL_IntcEventHandlerRecord  evtHandler;
179              //    evtHandler.handler = (CSL_IntcEventHandler)hwiFxn;
180              //    evtHandler.arg     = (void *) params->arg;
181              //
182              //    CSL_intcPlugEventHandler(hwi_handle->handle, &evtHandler);
183              //    CSL_intcHwControl(hwi_handle->handle,CSL_INTC_CMD_EVTCLEAR,NULL_PTR);
184              //    CSL_intcHwControl(hwi_handle->handle,CSL_INTC_CMD_EVTENABLE,NULL_PTR);
185              //}
186              //else
187              //{
188              //    /* Free the pool */
189              //    hwiPool[i].used = FALSE;
190              //    retHandle = (HwiP_Handle *) NULL_PTR;
191              //}
192        }
193     }
195     return ( (HwiP_Handle) (retHandle) );  /* _TMS320C6X */
198 HwiP_Status OsalArch_HwiPDelete(HwiP_Handle handle)
200     //TODO: Integrate to CSL once C7x arch is supported
201     //CSL_Status  status = CSL_SOK;
202     HwiP_nonOs *hwi_hnd = (HwiP_nonOs*) handle;
203     uintptr_t   key;
204     HwiP_Status ret_val = HwiP_OK;
206     /* mark that handle as free */
207     key = OsalArch_globalDisableInterrupt();
208     if (TRUE == hwi_hnd->used)
209     {
210         hwi_hnd->used = FALSE;
211     }
212     else
213     {
214         ret_val = HwiP_FAILURE;
215     }
216     OsalArch_globalRestoreInterrupt(key);
217     //status = CSL_intcClose(hwi_hnd->hwi.handle);
219     //if (CSL_SOK == status)
220     //{
221     //  ret_val = (HwiP_OK);
222     //}
223     //else
224     //{
225     //  ret_val = (HwiP_FAILURE);
226     //}
227     return (ret_val);
230 /*
231  *  ======== HwiP_getHandle ========
232  *  Returns the HwiP handle associated with an interrupt number
233   */
234 HwiP_Handle OsalArch_getHandle(uint32_t interruptNum)
236    Hwi_Struct *handle= (Hwi_Struct *) NULL_PTR;
237    return((HwiP_Handle)handle);
239 /*
240  *  ======== HwiP_getEventId ========
241  *  Returns the Event ID associated with an interrupt
242   */
243 uint32_t OsalArch_getEventId(uint32_t interruptNum)
245     return CSL_INVALID_EVENT_ID;
248 /* Below function posts the interrupt */
249 int32_t OsalArch_postInterrupt(uint32_t intrNum)
251     return (-1);
254 /* Return the cycle frequency used for timeStamp */
255 uint32_t osalArch_TimeStampGetFreqKHz(void)
257     /* TSCH/TSCL runs at CPU speed*/
258     return (gOsal_HwAttrs.cpuFreqKHz);
261 /* Osal time stamp provider implementations */
262 void osalArch_TimestampGet64(TimeStamp_Struct *tStamp)
264     uintptr_t  key;
265     uint64_t   cycle, cycleHi;
266     uint32_t   lo, hi;
268     key     = HwiP_disable();
269 #if !defined (HOST_EMULATION)
270     cycle   = __TSC;
271 #else
272     /* Not supported in host emulation mode */
273     cycle   = 0U;
274 #endif
275     cycleHi = ((uint64_t)(cycle >> 32U));
277     /* get the lo and hi parts */
278     lo    = ((uint32_t)(cycle   & ((uint32_t)(0xFFFFFFFFU))));
279     hi    = ((uint32_t)(cycleHi & ((uint32_t)(0xFFFFFFFFU))));
281     tStamp->lo         = lo;
282     tStamp->hi         = hi;
284     /* restore */
285     HwiP_restore(key);
288 void osalArch_TimestampCcntAutoRefresh(uintptr_t arg)
290     return;
293 /* Nothing past this point */