| 1 | /*************************************************************************** |
|---|
| 2 | * (c)2007-2011 Broadcom Corporation |
|---|
| 3 | * |
|---|
| 4 | * This program is the proprietary software of Broadcom Corporation and/or its licensors, |
|---|
| 5 | * and may only be used, duplicated, modified or distributed pursuant to the terms and |
|---|
| 6 | * conditions of a separate, written license agreement executed between you and Broadcom |
|---|
| 7 | * (an "Authorized License"). Except as set forth in an Authorized License, Broadcom grants |
|---|
| 8 | * no license (express or implied), right to use, or waiver of any kind with respect to the |
|---|
| 9 | * Software, and Broadcom expressly reserves all rights in and to the Software and all |
|---|
| 10 | * intellectual property rights therein. IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU |
|---|
| 11 | * HAVE NO RIGHT TO USE THIS SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY |
|---|
| 12 | * NOTIFY BROADCOM AND DISCONTINUE ALL USE OF THE SOFTWARE. |
|---|
| 13 | * |
|---|
| 14 | * Except as expressly set forth in the Authorized License, |
|---|
| 15 | * |
|---|
| 16 | * 1. This program, including its structure, sequence and organization, constitutes the valuable trade |
|---|
| 17 | * secrets of Broadcom, and you shall use all reasonable efforts to protect the confidentiality thereof, |
|---|
| 18 | * and to use this information only in connection with your use of Broadcom integrated circuit products. |
|---|
| 19 | * |
|---|
| 20 | * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS" |
|---|
| 21 | * AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, REPRESENTATIONS OR |
|---|
| 22 | * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO |
|---|
| 23 | * THE SOFTWARE. BROADCOM SPECIFICALLY DISCLAIMS ANY AND ALL IMPLIED WARRANTIES |
|---|
| 24 | * OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, |
|---|
| 25 | * LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION |
|---|
| 26 | * OR CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING OUT OF |
|---|
| 27 | * USE OR PERFORMANCE OF THE SOFTWARE. |
|---|
| 28 | * |
|---|
| 29 | * 3. TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM OR ITS |
|---|
| 30 | * LICENSORS BE LIABLE FOR (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR |
|---|
| 31 | * EXEMPLARY DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO YOUR |
|---|
| 32 | * USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM HAS BEEN ADVISED OF |
|---|
| 33 | * THE POSSIBILITY OF SUCH DAMAGES; OR (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT |
|---|
| 34 | * ACTUALLY PAID FOR THE SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE |
|---|
| 35 | * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF ESSENTIAL PURPOSE OF |
|---|
| 36 | * ANY LIMITED REMEDY. |
|---|
| 37 | * |
|---|
| 38 | * $brcm_Workfile: nexus_base_os.h $ |
|---|
| 39 | * $brcm_Revision: 5 $ |
|---|
| 40 | * $brcm_Date: 5/3/11 5:09p $ |
|---|
| 41 | * |
|---|
| 42 | * Revision History: |
|---|
| 43 | * |
|---|
| 44 | * $brcm_Log: /nexus/base/include/nexus_base_os.h $ |
|---|
| 45 | * |
|---|
| 46 | * 5 5/3/11 5:09p erickson |
|---|
| 47 | * SW7420-1819: repartition so NFE is a standard feature |
|---|
| 48 | * |
|---|
| 49 | * 4 3/16/11 10:11a erickson |
|---|
| 50 | * SW7420-1642: add NEXUS_Base_Settings.driverModuleInit and |
|---|
| 51 | * .driverModuleUninit |
|---|
| 52 | * |
|---|
| 53 | * 3 9/23/10 2:12p erickson |
|---|
| 54 | * SW7420-943: refactor for driver/firmware partitioning |
|---|
| 55 | * |
|---|
| 56 | * 2 9/15/10 3:39p jtna |
|---|
| 57 | * SW7420-1004: add synthunk for CORE and PLATFORM |
|---|
| 58 | * |
|---|
| 59 | * 1 7/14/10 11:59a erickson |
|---|
| 60 | * SW7405-4621: split out nexus_base_os.h |
|---|
| 61 | * |
|---|
| 62 | ***************************************************************************/ |
|---|
| 63 | #ifndef NEXUS_BASE_OS_H |
|---|
| 64 | #define NEXUS_BASE_OS_H |
|---|
| 65 | |
|---|
| 66 | /* This is part of the public API. */ |
|---|
| 67 | #include "bstd.h" |
|---|
| 68 | #include "bkni.h" |
|---|
| 69 | #include "bkni_multi.h" |
|---|
| 70 | #include "nexus_base_types.h" /* this is also public API */ |
|---|
| 71 | |
|---|
| 72 | /** |
|---|
| 73 | SW services provided by base which can be used inside and outside nexus. |
|---|
| 74 | This is symlinked in nexus/modules/core for use outside nexus. |
|---|
| 75 | This file should not contain any nexus internals, including NEXUS_ModuleHandle, ISR context or magnum non-basemodules. |
|---|
| 76 | **/ |
|---|
| 77 | |
|---|
| 78 | #ifdef __cplusplus |
|---|
| 79 | extern "C" |
|---|
| 80 | { |
|---|
| 81 | #endif |
|---|
| 82 | |
|---|
| 83 | /** |
|---|
| 84 | Summary: |
|---|
| 85 | Handle for a thread. |
|---|
| 86 | |
|---|
| 87 | Description: |
|---|
| 88 | |
|---|
| 89 | See Also: |
|---|
| 90 | NEXUS_Thread_Create |
|---|
| 91 | **/ |
|---|
| 92 | typedef struct NEXUS_Thread *NEXUS_ThreadHandle; |
|---|
| 93 | |
|---|
| 94 | /** |
|---|
| 95 | Summary: |
|---|
| 96 | Settings used for creating a thread |
|---|
| 97 | |
|---|
| 98 | Description: |
|---|
| 99 | |
|---|
| 100 | See Also: |
|---|
| 101 | NEXUS_Thread_GetDefaultSettings |
|---|
| 102 | NEXUS_Thread_Create |
|---|
| 103 | **/ |
|---|
| 104 | typedef struct NEXUS_ThreadSettings |
|---|
| 105 | { |
|---|
| 106 | unsigned priority; /* 0=highest, 100=lowest */ |
|---|
| 107 | size_t stackSize; /* In Bytes, may be rounded up to OS minimum */ |
|---|
| 108 | } NEXUS_ThreadSettings; |
|---|
| 109 | |
|---|
| 110 | /** |
|---|
| 111 | Summary: |
|---|
| 112 | Get default settings for the structure. |
|---|
| 113 | |
|---|
| 114 | Description: |
|---|
| 115 | This is required in order to make application code resilient to the addition of new strucutre members in the future. |
|---|
| 116 | |
|---|
| 117 | See Also: |
|---|
| 118 | NEXUS_Thread_Create |
|---|
| 119 | **/ |
|---|
| 120 | void NEXUS_Thread_GetDefaultSettings( |
|---|
| 121 | NEXUS_ThreadSettings *pSettings /* [out] Default Settings for OS */ |
|---|
| 122 | ); |
|---|
| 123 | |
|---|
| 124 | /** |
|---|
| 125 | Summary: |
|---|
| 126 | Create a thread. |
|---|
| 127 | |
|---|
| 128 | Description: |
|---|
| 129 | |
|---|
| 130 | See Also: |
|---|
| 131 | NEXUS_Thread_Destroy |
|---|
| 132 | NEXUS_Thread_GetDefaultSettings |
|---|
| 133 | **/ |
|---|
| 134 | NEXUS_ThreadHandle NEXUS_Thread_Create( |
|---|
| 135 | const char *pThreadName, /* Thread Name, optional */ |
|---|
| 136 | void (*pThreadFunc)(void *), /* Thread Main Routine */ |
|---|
| 137 | void *pContext, /* Context provided to callback */ |
|---|
| 138 | const NEXUS_ThreadSettings *pSettings /* Thread Settings */ |
|---|
| 139 | ); |
|---|
| 140 | |
|---|
| 141 | /** |
|---|
| 142 | Summary: |
|---|
| 143 | Destroy a thread after its function has exited. |
|---|
| 144 | |
|---|
| 145 | Description: |
|---|
| 146 | This does not cancel the execution of the pThreadFunc. pThreadFunc must exit on its own, then |
|---|
| 147 | NEXUS_Thread_Destroy can clean up the resources. |
|---|
| 148 | |
|---|
| 149 | See Also: |
|---|
| 150 | NEXUS_Thread_Create |
|---|
| 151 | **/ |
|---|
| 152 | void NEXUS_Thread_Destroy( |
|---|
| 153 | NEXUS_ThreadHandle thread /* Thread Handle, returned from NEXUS_Thread_Create() */ |
|---|
| 154 | ); |
|---|
| 155 | |
|---|
| 156 | /** |
|---|
| 157 | Summary: |
|---|
| 158 | Activate gathering of run-time software profile information. |
|---|
| 159 | Profiling support shall be enabled at the compile time. |
|---|
| 160 | **/ |
|---|
| 161 | NEXUS_Error NEXUS_Profile_Start(void); |
|---|
| 162 | |
|---|
| 163 | /** |
|---|
| 164 | Summary: |
|---|
| 165 | Finishes gathering of run-time software profile information and prints report. |
|---|
| 166 | **/ |
|---|
| 167 | void NEXUS_Profile_Stop( |
|---|
| 168 | const char *name /* title of the profile report */ |
|---|
| 169 | ); |
|---|
| 170 | |
|---|
| 171 | /** |
|---|
| 172 | Summary: |
|---|
| 173 | Mark thread that could originate profiling samples |
|---|
| 174 | **/ |
|---|
| 175 | void NEXUS_Profile_MarkThread( |
|---|
| 176 | const char *name /* thread name */ |
|---|
| 177 | ); |
|---|
| 178 | |
|---|
| 179 | /** |
|---|
| 180 | Summary: |
|---|
| 181 | Flush the data cache for an address range. |
|---|
| 182 | |
|---|
| 183 | Description: |
|---|
| 184 | This function will flush and invalidate the address range provided |
|---|
| 185 | from the data cache. It is guaranteed that at least the address range |
|---|
| 186 | provided will be flushed, however larger amounts may be flushed depending |
|---|
| 187 | on the CPU and underlying OS primitives available. |
|---|
| 188 | ****************************************************************************/ |
|---|
| 189 | void NEXUS_FlushCache( |
|---|
| 190 | const void *address, /* cached address to flush */ |
|---|
| 191 | size_t size /* size in bytes to flush */ |
|---|
| 192 | ); |
|---|
| 193 | |
|---|
| 194 | /** |
|---|
| 195 | Summary: |
|---|
| 196 | Returns the value for an environment variable. |
|---|
| 197 | |
|---|
| 198 | Description: |
|---|
| 199 | The implementation of this function varies by OS. |
|---|
| 200 | For Linux user mode, this will be environment variables set in the shell. |
|---|
| 201 | For Linux kernel mode, it could be insmod parameters. |
|---|
| 202 | |
|---|
| 203 | Returns: |
|---|
| 204 | A null-terminated string for the environment variable. |
|---|
| 205 | NULL means that it does not exist. |
|---|
| 206 | |
|---|
| 207 | See Also: |
|---|
| 208 | NEXUS_SetEnv |
|---|
| 209 | */ |
|---|
| 210 | const char *NEXUS_GetEnv( |
|---|
| 211 | const char *name |
|---|
| 212 | ); |
|---|
| 213 | |
|---|
| 214 | /** |
|---|
| 215 | Summary: |
|---|
| 216 | Sets the value for an environment variable. |
|---|
| 217 | |
|---|
| 218 | Description: |
|---|
| 219 | If value is NULL, the internal state for the given name will be cleared. |
|---|
| 220 | |
|---|
| 221 | See Also: |
|---|
| 222 | NEXUS_GetEnv |
|---|
| 223 | */ |
|---|
| 224 | void NEXUS_SetEnv( |
|---|
| 225 | const char *name, |
|---|
| 226 | const char *value |
|---|
| 227 | ); |
|---|
| 228 | |
|---|
| 229 | |
|---|
| 230 | /** |
|---|
| 231 | Summary: |
|---|
| 232 | Convert a null-terminated ASCII string to an integer. |
|---|
| 233 | |
|---|
| 234 | Description: |
|---|
| 235 | Nexus wrapper for C89,Posix.1 atoi(3) function |
|---|
| 236 | */ |
|---|
| 237 | int NEXUS_atoi(const char *str); |
|---|
| 238 | |
|---|
| 239 | /** |
|---|
| 240 | Summary: |
|---|
| 241 | Standard string functions |
|---|
| 242 | **/ |
|---|
| 243 | int NEXUS_P_Base_StrCmp(const char *str1, const char *str2); |
|---|
| 244 | int b_strlen(const char *s); |
|---|
| 245 | char *b_strncpy(char *dest, const char *src, int n); |
|---|
| 246 | |
|---|
| 247 | /** |
|---|
| 248 | Summary: |
|---|
| 249 | Settings passed into NEXUS_Base_Init |
|---|
| 250 | |
|---|
| 251 | Description: |
|---|
| 252 | NEXUS_Base_Settings must be defined in nexus_base_os.h because NEXUS_Base_GetDefaultSettings is OS-specific. |
|---|
| 253 | **/ |
|---|
| 254 | typedef struct NEXUS_Base_Settings |
|---|
| 255 | { |
|---|
| 256 | NEXUS_ThreadSettings threadSettings[NEXUS_ModulePriority_eMax]; |
|---|
| 257 | |
|---|
| 258 | /* callbacks for per-module driver registration */ |
|---|
| 259 | NEXUS_Error (*driverModuleInit)(void *context, NEXUS_ModuleHandle module, const char *name, const NEXUS_ModuleSettings *pSettings); |
|---|
| 260 | void (*driverModuleUninit)(void *context, NEXUS_ModuleHandle module, const char *name, const NEXUS_ModuleSettings *pSettings); |
|---|
| 261 | void *procContext; |
|---|
| 262 | } NEXUS_Base_Settings; |
|---|
| 263 | |
|---|
| 264 | /** |
|---|
| 265 | Summary: |
|---|
| 266 | Get default settings for the structure. |
|---|
| 267 | |
|---|
| 268 | Description: |
|---|
| 269 | The implementation of NEXUS_Base_GetDefaultSettings is OS-specific so that threading can be customized. |
|---|
| 270 | **/ |
|---|
| 271 | void NEXUS_Base_GetDefaultSettings( |
|---|
| 272 | NEXUS_Base_Settings *pSettings /* [out] Default Settings */ |
|---|
| 273 | ); |
|---|
| 274 | |
|---|
| 275 | /** |
|---|
| 276 | Summary: |
|---|
| 277 | Used for profiling |
|---|
| 278 | **/ |
|---|
| 279 | const char *NEXUS_P_Base_Os_GetTaskNameFromStack(const unsigned long *stack); |
|---|
| 280 | |
|---|
| 281 | /** |
|---|
| 282 | Summary: |
|---|
| 283 | Used for profiling |
|---|
| 284 | **/ |
|---|
| 285 | void NEXUS_P_Base_Os_MarkThread(const char *name); |
|---|
| 286 | |
|---|
| 287 | /** |
|---|
| 288 | NEXUS_P_Base_Scheduler_Status is used by the internal and external scheduler interface. |
|---|
| 289 | **/ |
|---|
| 290 | typedef struct NEXUS_P_Base_Scheduler_Status { |
|---|
| 291 | bool exit; /* scheduler has to exit */ |
|---|
| 292 | bool idle; /* there is no activite in the scheduler */ |
|---|
| 293 | unsigned timeout; /* timer's timeout (miliseconds) */ |
|---|
| 294 | } NEXUS_P_Base_Scheduler_Status; |
|---|
| 295 | |
|---|
| 296 | #ifdef __cplusplus |
|---|
| 297 | } |
|---|
| 298 | #endif |
|---|
| 299 | |
|---|
| 300 | #endif /* !defined NEXUS_BASE_OS_H */ |
|---|
| 301 | |
|---|
| 302 | |
|---|