]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/performance-audio-sr.git/blob - pdk_k2g_1_0_1_0_eng/packages/ti/board/diag/icss_emac/src/icss_emac_osal.h
Change pdk_k2g_1_0_1 directory name in preparation for updating RSTC plugin
[processor-sdk/performance-audio-sr.git] / pdk_k2g_1_0_1_0_eng / packages / ti / board / diag / icss_emac / src / icss_emac_osal.h
1 /**
2  *   @file  icss_emac_osal.h
3  *
4  *   @brief
5  *      This is the sample OS Adaptation layer which is used by the ICSS_EMAC
6  *      driver. The OSAL layer can be ported in either of the following
7  *      manners to a native OS:
8  *
9  *      <b> Approach 1: </b>
10  *      @n  Use Prebuilt Libraries
11  *           - Ensure that the provide an implementation of all
12  *             Osal_XXX API for their native OS.
13  *           - Link the prebuilt libraries with their application.
14  *           - Refer to the "example" directory for an example of this
15  *       @n <b> Pros: </b>
16  *           - Customers can reuse prebuilt TI provided libraries
17  *       @n <b> Cons: </b>
18  *           - Level of indirection in the API to get to the actual OS call
19  *
20  *      <b> Approach 2: </b>
21  *      @n  Rebuilt Library
22  *           - Create a copy of this file and modify it to directly
23  *             inline the native OS calls
24  *           - Rebuild the ICSS_EMAC Driver library; ensure that the Include
25  *             path points to the directory where the copy of this file
26  *             has been provided.
27  *           - Please refer to the "test" directory for an example of this
28  *       @n <b> Pros: </b>
29  *           - Optimizations can be done to remove the level of indirection
30  *       @n <b> Cons: </b>
31  *           - ICSS_EMAC Libraries need to be rebuilt by the customer.
32  *
33  *  \par
34  *  NOTE:
35  *      (C) Copyright 2014 Texas Instruments, Inc.
36  *
37  *  Redistribution and use in source and binary forms, with or without
38  *  modification, are permitted provided that the following conditions
39  *  are met:
40  *
41  *    Redistributions of source code must retain the above copyright
42  *    notice, this list of conditions and the following disclaimer.
43  *
44  *    Redistributions in binary form must reproduce the above copyright
45  *    notice, this list of conditions and the following disclaimer in the
46  *    documentation and/or other materials provided with the
47  *    distribution.
48  *
49  *    Neither the name of Texas Instruments Incorporated nor the names of
50  *    its contributors may be used to endorse or promote products derived
51  *    from this software without specific prior written permission.
52  *
53  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
54  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
55  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
56  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
57  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
58  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
59  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
60  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
61  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
62  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
63  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
64  *
65  *  \par
66 */
67 #ifndef __ICSS_EMAC_OSAL_H__
68 #define __ICSS_EMAC_OSAL_H__
70 #ifndef _COMMON_OSAL_DATATYPES_
71 #define _COMMON_OSAL_DATATYPES_
74 #define OSAL_OK  0
75 #define OSAL_FAILURE -1
76 #define OSAL_TIMEOUT 2
80 typedef void (*TimerP_Fxn)(uintptr_t arg);
82 typedef  void *TimerP_Handle;
85 typedef struct TimerP_Params {
86     char *name;
87     uint32_t periodType;
88     uint32_t freqLo;
89     uint32_t freqHi;
90     uint32_t startMode;
91     uint32_t runMode;
92     uint32_t period;
93     void* arg;
94 } TimerP_Params;
98 /*!
99  *  @brief    Status codes for SemaphoreP APIs
100  */
101 typedef enum SemaphoreP_Status {
102     /*! API completed successfully */
103     SemaphoreP_OK = 0,
104     /*! API failed */
105     SemaphoreP_FAILURE = -1,
106     /*! API failed because of a timeout */
107     SemaphoreP_TIMEOUT = -2
108 } SemaphoreP_Status;
110 /*!
111  *  @brief    Wait forever define
112  */
113 #define SemaphoreP_WAIT_FOREVER  (~(0))
115 /*!
116  *  @brief    No wait define
117  */
118 #define SemaphoreP_NO_WAIT       (0)
121 /*!
122  *  @brief    Opaque client reference to an instance of a SemaphoreP
123  *
124  *  A SemaphoreP_Handle returned from the SemaphoreP_create represents that
125  *  instance and  is used in the other instance based functions (e.g.
126  *  SemaphoreP_post or SemaphoreP_pend, etc.).
127  */
128 typedef  void *SemaphoreP_Handle;
130 /*!
131  *  @brief    Mode of the semaphore
132  */
133 typedef enum SemaphoreP_Mode {
134     SemaphoreP_Mode_COUNTING = 0x0,
135     SemaphoreP_Mode_BINARY   = 0x1
136 } SemaphoreP_Mode;
138 /*!
139  *  @brief    Basic SemaphoreP Parameters
140  *
141  *  Structure that contains the parameters are passed into SemaphoreP_create
142  *  when creating a SemaphoreP instance. The SemaphoreP_Params_init function
143  *  should be used to initialize the fields to default values before the
144  *  application sets the fields manually. The SemaphoreP default parameters are
145  *  noted in SemaphoreP_Params_init.
146  */
147 typedef struct SemaphoreP_Params {
148     char *name;           /*!< Name of the semaphore instance. Memory must
149                                persist for the life of the semaphore instance */
150     SemaphoreP_Mode mode; /*!< Mode for the semaphore */
151     uint32_t maxCount;    /*!< The max count allowed for counting semaphore */
152 } SemaphoreP_Params;
154 /*!
155  *  @brief    Opaque client reference to an instance of a HwiP
156  *
157  *  A HwiP_Handle returned from the HwiP_create represents that instance.
158  */
159 typedef  void *HwiP_Handle;
161 /*!
162  *  @brief    Status codes for HwiP APIs
163  */
164 typedef enum HwiP_Status {
165     HwiP_OK = 0,
166     HwiP_FAILURE = -1
167 } HwiP_Status;
170 /*!
171  *  @brief  Prototype for the entry function for a hardware interrupt
172  */
173 typedef void (*HwiP_Fxn)(uintptr_t arg);
175 /*!
176  *  @brief    Basic HwiP Parameters
177  *
178  *  Structure that contains the parameters passed into ::HwiP_create
179  *  when creating a HwiP instance. The ::HwiP_Params_init function should
180  *  be used to initialize the fields to default values before the application sets
181  *  the fields manually. The HwiP default parameters are noted in
182  *  HwiP_Params_init.
183  */
184 typedef struct HwiP_Params {
185     char      *name;      /*!< Name of the clock instance. Memory must
186                                persist for the life of the clock instance.
187                                This can be used for debugging purposes, or
188                                set to NULL if not needed. */
189     uintptr_t  arg;       /*!< Argument passed into the Hwi function. */
190     uint32_t   priority;  /*!< Device specific priority. */
191     uint32_t   evtId;     /*!< Event Id. */
192 } HwiP_Params;
195 #define OSAL_Assert(expr)  {                      \
196                              if(expr)             \
197                              {                    \
198                                 while(1);         \
199                              }                    \
200                            }
202 #endif /* _COMMON_OSAL_DATATYPES_ */
203 /**********************************************************************
204  ************************* Extern Declarations ************************
205  **********************************************************************/
207 /* #include <string.h> is here because there used to be
208  * memcpy/memset prototypes here.  This #include prevents warnings in
209  * other code that unintentionally worked because of these prototypes
210  */
211 #include <string.h>
213 extern SemaphoreP_Handle SemaphoreP_create(unsigned int count,
214                                            SemaphoreP_Params *params);
215 extern SemaphoreP_Status SemaphoreP_delete(SemaphoreP_Handle handle);
216 extern void SemaphoreP_Params_init(SemaphoreP_Params *params);
217 extern SemaphoreP_Status SemaphoreP_pend(SemaphoreP_Handle handle,
218                                          uint32_t timeout);
219 extern SemaphoreP_Status SemaphoreP_post(SemaphoreP_Handle handle);
221 extern uintptr_t HwiP_disable(void);
222 extern void HwiP_restore(uint32_t key);
224 extern HwiP_Status HwiP_delete(HwiP_Handle handle);
226 extern void HwiP_disableInterrupt(int interruptNum);
227 extern void HwiP_enableInterrupt(int interruptNum);
229 extern HwiP_Handle HwiP_create(int interruptNum, HwiP_Fxn hwiFxn,
230                                HwiP_Params *params);
231 extern void HwiP_Params_init(HwiP_Params *params);
235 #define ICSS_EMAC_osalCreateBlockingLock(x,y)        SemaphoreP_create(x,y)
238 #define ICSS_EMAC_osalDeleteBlockingLock(X)       SemaphoreP_delete(X)
241 #define ICSS_EMAC_osalSemParamsInit(x)  SemaphoreP_Params_init(x)
244 #define ICSS_EMAC_osalPendLock(X,Y)         SemaphoreP_pend(X,Y)
247 #define ICSS_EMAC_osalPostLock(X)     SemaphoreP_post(X)
250 #define ICSS_EMAC_osalHardwareIntDisable() HwiP_disable()
253 #define ICSS_EMAC_osalHardwareIntRestore(X) HwiP_restore(X)
256 #define ICSS_EMAC_osalHardwareIntDestruct(X)  HwiP_delete(X)
259 #define ICSS_EMAC_osalRegisterInterrupt(X,Y,Z)     HwiP_create(X,Y,Z)
262 #define ICSS_EMAC_osalHwiParamsInit(X)             HwiP_Params_init(X)
264 #endif /* __ICSS_EMAC_OSAL_H__ */