| 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.h $ |
|---|
| 39 | * $brcm_Revision: 35 $ |
|---|
| 40 | * $brcm_Date: 12/15/11 1:23p $ |
|---|
| 41 | * |
|---|
| 42 | * Revision History: |
|---|
| 43 | * |
|---|
| 44 | * $brcm_Log: /nexus/base/include/nexus_base.h $ |
|---|
| 45 | * |
|---|
| 46 | * 35 12/15/11 1:23p vsilyaev |
|---|
| 47 | * SW7420-2085: Assert on object validity before accessing reference |
|---|
| 48 | * counter |
|---|
| 49 | * |
|---|
| 50 | * 34 11/29/11 11:37a erickson |
|---|
| 51 | * SW7420-2129: store current default heap per module |
|---|
| 52 | * |
|---|
| 53 | * 33 11/4/11 1:54p vsilyaev |
|---|
| 54 | * SW7231-439: Improved debuggability |
|---|
| 55 | * |
|---|
| 56 | * 32 10/7/11 1:49p vsilyaev |
|---|
| 57 | * SW7420-2085: Added support for object reference counting |
|---|
| 58 | * |
|---|
| 59 | * 31 9/14/11 2:10p erickson |
|---|
| 60 | * SW7405-5478: add NEXUS_Module_GetName for debug |
|---|
| 61 | * |
|---|
| 62 | * 30 5/3/11 5:07p erickson |
|---|
| 63 | * SW7420-1819: repartition so NFE is a standard feature |
|---|
| 64 | * |
|---|
| 65 | * 29 4/20/11 7:56p jtna |
|---|
| 66 | * SW7425-365: added back previous definition of NEXUS_OFFSETOF as comment |
|---|
| 67 | * for reference |
|---|
| 68 | * |
|---|
| 69 | * 28 4/20/11 7:43p jtna |
|---|
| 70 | * SW7425-365: change NEXUS_OFFSETOF macro to use offsetof macro, to |
|---|
| 71 | * silence build warnings |
|---|
| 72 | * |
|---|
| 73 | * 27 4/19/11 12:23p vsilyaev |
|---|
| 74 | * SW7405-5221: Route nexus BERR_TRACE through common route |
|---|
| 75 | * |
|---|
| 76 | * 26 4/4/11 6:14p vsilyaev |
|---|
| 77 | * SW7405-5221: Added option to forward debug output to FIFO |
|---|
| 78 | * |
|---|
| 79 | * 25 3/28/11 3:45p vsilyaev |
|---|
| 80 | * SW7335-1214: Added NEXUS_CallbackHandler framework |
|---|
| 81 | * |
|---|
| 82 | * 24 1/19/11 11:11a erickson |
|---|
| 83 | * SW7420-1123: add NEXUS_Module_GetSettings |
|---|
| 84 | * |
|---|
| 85 | * 23 12/16/10 4:04p vsilyaev |
|---|
| 86 | * SW7425-40: Added macros to verify memory layour of structure members |
|---|
| 87 | * |
|---|
| 88 | * 22 11/15/10 3:11p vsilyaev |
|---|
| 89 | * SW7405-4996: Added NEXUS_StrCmp |
|---|
| 90 | * |
|---|
| 91 | * 21 11/3/10 4:16p erickson |
|---|
| 92 | * SW7420-1223: refactor for application use of pointer/offset conversion |
|---|
| 93 | * functions |
|---|
| 94 | * |
|---|
| 95 | * 20 9/23/10 2:12p erickson |
|---|
| 96 | * SW7420-943: refactor for driver/firmware partitioning |
|---|
| 97 | * |
|---|
| 98 | * 19 9/15/10 3:38p jtna |
|---|
| 99 | * SW7420-1004: added BERR_StoreError and NEXUS_GetLastError_Os |
|---|
| 100 | * |
|---|
| 101 | * 18 7/14/10 11:59a erickson |
|---|
| 102 | * SW7405-4621: split out nexus_base_os.h |
|---|
| 103 | * |
|---|
| 104 | * 17 7/14/10 10:27a erickson |
|---|
| 105 | * SW7405-4621: narrow #include to minimum |
|---|
| 106 | * |
|---|
| 107 | * 16 8/10/09 11:55a erickson |
|---|
| 108 | * PR57475: added comment that NEXUS_SetEnv(name, NULL) is supported |
|---|
| 109 | * |
|---|
| 110 | * 15 6/18/09 11:49a vsilyaev |
|---|
| 111 | * PR 54926: Added debug options to the module settings |
|---|
| 112 | * |
|---|
| 113 | * 14 4/8/09 4:31p vsilyaev |
|---|
| 114 | * PR 54016: Added support for precompiled header |
|---|
| 115 | * |
|---|
| 116 | * 13 1/26/09 11:06a erickson |
|---|
| 117 | * PR35457: clarify comment |
|---|
| 118 | * |
|---|
| 119 | * 12 10/3/08 11:18a vsilyaev |
|---|
| 120 | * PR 45361: Fixed BTRC and BPROFILE support with -std=c89 |
|---|
| 121 | * |
|---|
| 122 | * 11 9/22/08 3:26p vsilyaev |
|---|
| 123 | * PR 42318: Removed bkni_multi.h |
|---|
| 124 | * |
|---|
| 125 | * 10 9/22/08 3:24p vsilyaev |
|---|
| 126 | * PR 42318: Use linux specific files for linux specific prototypes |
|---|
| 127 | * |
|---|
| 128 | * 9 6/10/08 3:29p vsilyaev |
|---|
| 129 | * PR 43184: Added support for Start/Stop callbacks in linux kernel/user |
|---|
| 130 | * proxy mode |
|---|
| 131 | * |
|---|
| 132 | * 8 6/9/08 7:11p vsilyaev |
|---|
| 133 | * PR 43184: Changed phase of detection for outstanding callbacks |
|---|
| 134 | * |
|---|
| 135 | * 7 6/5/08 2:19p vsilyaev |
|---|
| 136 | * PR 42318: Rearranged scheduller to share the same context in user and |
|---|
| 137 | * kernel mode, this allows to serve callback from kernel to user with |
|---|
| 138 | * single transition kernel<->user |
|---|
| 139 | * |
|---|
| 140 | * 6 4/8/08 10:40a vsilyaev |
|---|
| 141 | * PR 41083: Added bprofile support |
|---|
| 142 | * |
|---|
| 143 | * 5 3/17/08 12:46p erickson |
|---|
| 144 | * PR40103: remove NEXUS_QueueCallback |
|---|
| 145 | * |
|---|
| 146 | * 4 2/28/08 10:41p vsilyaev |
|---|
| 147 | * PR 40103: Added interfaceHandle and settings for the |
|---|
| 148 | * NEXUS_IsrCallbackCreate |
|---|
| 149 | * |
|---|
| 150 | * 3 2/28/08 9:39p vsilyaev |
|---|
| 151 | * PR 40103: Added NEXUS_TaskCallback functions |
|---|
| 152 | * |
|---|
| 153 | * 2 2/25/08 2:58p erickson |
|---|
| 154 | * PR39786: correct comment |
|---|
| 155 | * |
|---|
| 156 | * 1 1/18/08 2:12p jgarrett |
|---|
| 157 | * PR 38808: Merging to main branch |
|---|
| 158 | * |
|---|
| 159 | * Nexus_Devel/22 11/28/07 2:11p erickson |
|---|
| 160 | * PR35457: doc update |
|---|
| 161 | * |
|---|
| 162 | ***************************************************************************/ |
|---|
| 163 | #ifndef NEXUS_BASE_H |
|---|
| 164 | #define NEXUS_BASE_H |
|---|
| 165 | |
|---|
| 166 | #include "bstd.h" |
|---|
| 167 | #include "bkni.h" |
|---|
| 168 | #include "bkni_multi.h" |
|---|
| 169 | #include "nexus_base_types.h" /* base types which are also available to applications via nexus_core symlink */ |
|---|
| 170 | #include "nexus_base_os.h" /* functions that must be implemented in OS abstraction */ |
|---|
| 171 | #include "nexus_base_mmap.h" /* functions for nexus_base_mmap.c */ |
|---|
| 172 | #include "nexus_base_driver.h" /* types that must be used by platform/driver code */ |
|---|
| 173 | |
|---|
| 174 | /*=*********************** |
|---|
| 175 | Nexus Base is an internal component of Nexus. It is not a module. It is not callable by applications. |
|---|
| 176 | |
|---|
| 177 | Nexus Base provides the following features to modules: |
|---|
| 178 | |
|---|
| 179 | 1. Module locking |
|---|
| 180 | Each module creates a handle which is uses for locking. |
|---|
| 181 | See NEXUS_LockModule. |
|---|
| 182 | |
|---|
| 183 | 2. Callback support |
|---|
| 184 | Invoke callbacks which are given with NEXUS_CallbackDesc. |
|---|
| 185 | NEXUS_TaskCallback and NEXUS_IsrCallback set up handles which can be used to fire a callback from task or isr context. |
|---|
| 186 | |
|---|
| 187 | 3. Events |
|---|
| 188 | Receive a synchronized task callback when a BKNI_EventHandle is set. |
|---|
| 189 | See NEXUS_RegisterEvent. |
|---|
| 190 | |
|---|
| 191 | 4. Timers |
|---|
| 192 | Receive a synchronized task callback after a specified time interval. |
|---|
| 193 | See NEXUS_ScheduleTimer. |
|---|
| 194 | |
|---|
| 195 | 5. Synchronized callback handler |
|---|
| 196 | Receive a syncrhroniized task callback after other nexus component issued asynchronous callback |
|---|
| 197 | |
|---|
| 198 | See nexus_base_os.h for threads and misc functions callable inside and outside nexus. |
|---|
| 199 | *************************/ |
|---|
| 200 | |
|---|
| 201 | #ifdef __cplusplus |
|---|
| 202 | #error Internal header file cannot be built by C++ compiler |
|---|
| 203 | #endif |
|---|
| 204 | |
|---|
| 205 | BERR_Code BERR_StoreError_tagged(const char *file, unsigned lineno, const char *error, BERR_Code rc); |
|---|
| 206 | #define BERR_StoreError(rc) (BERR_StoreError_tagged(__FILE__, __LINE__, #rc, rc)) |
|---|
| 207 | |
|---|
| 208 | #if BDBG_DEBUG_BUILD |
|---|
| 209 | /* nexus redefines BERR_TRACE from magnum's berr.h */ |
|---|
| 210 | #undef BERR_TRACE |
|---|
| 211 | #define BERR_TRACE(rc) BERR_StoreError_tagged(__FILE__, __LINE__, #rc, (rc)) |
|---|
| 212 | #endif |
|---|
| 213 | |
|---|
| 214 | |
|---|
| 215 | /** |
|---|
| 216 | Summary: |
|---|
| 217 | Get the last error on a thread. |
|---|
| 218 | |
|---|
| 219 | Description: |
|---|
| 220 | This is not implemented for all OS's. |
|---|
| 221 | **/ |
|---|
| 222 | void NEXUS_GetLastError_Os(BERR_Code *code); |
|---|
| 223 | |
|---|
| 224 | /** |
|---|
| 225 | Summary: |
|---|
| 226 | Initialize the Nexus Base Core. |
|---|
| 227 | |
|---|
| 228 | Description: |
|---|
| 229 | This is called from Platform initialization code. |
|---|
| 230 | It should be called after magnum initialization and prior to NEXUS_Base_Init |
|---|
| 231 | |
|---|
| 232 | See Also: |
|---|
| 233 | NEXUS_Base_Init |
|---|
| 234 | NEXUS_Base_Core_Uninit |
|---|
| 235 | **/ |
|---|
| 236 | NEXUS_Error NEXUS_Base_Core_Init(void); |
|---|
| 237 | |
|---|
| 238 | /** |
|---|
| 239 | Summary: |
|---|
| 240 | Uninit the Nexus Base Core. |
|---|
| 241 | |
|---|
| 242 | Description: |
|---|
| 243 | This is called from Platform uninitialization code. |
|---|
| 244 | It should be called after NEXUS_Base_Uninit and prior to magnum uninitialization |
|---|
| 245 | |
|---|
| 246 | See Also: |
|---|
| 247 | NEXUS_Base_Core_Init |
|---|
| 248 | NEXUS_Base_Uninit |
|---|
| 249 | **/ |
|---|
| 250 | void NEXUS_Base_Core_Uninit(void); |
|---|
| 251 | |
|---|
| 252 | /** |
|---|
| 253 | Summary: |
|---|
| 254 | Initialize the Nexus Base. |
|---|
| 255 | |
|---|
| 256 | Description: |
|---|
| 257 | This is called from Platform initialization code. |
|---|
| 258 | |
|---|
| 259 | See Also: |
|---|
| 260 | NEXUS_Base_Uninit |
|---|
| 261 | **/ |
|---|
| 262 | NEXUS_Error NEXUS_Base_Init( |
|---|
| 263 | const NEXUS_Base_Settings *pSettings |
|---|
| 264 | ); |
|---|
| 265 | |
|---|
| 266 | /** |
|---|
| 267 | Summary: |
|---|
| 268 | Uninit the Nexus Base. |
|---|
| 269 | |
|---|
| 270 | Description: |
|---|
| 271 | This is called from Platform uninitialization code. |
|---|
| 272 | |
|---|
| 273 | See Also: |
|---|
| 274 | NEXUS_Base_Init |
|---|
| 275 | **/ |
|---|
| 276 | void NEXUS_Base_Uninit(void); |
|---|
| 277 | |
|---|
| 278 | /** |
|---|
| 279 | Summary: |
|---|
| 280 | Get default settings for the structure. |
|---|
| 281 | |
|---|
| 282 | Description: |
|---|
| 283 | This is required in order to make application code resilient to the addition of new strucutre members in the future. |
|---|
| 284 | |
|---|
| 285 | See Also: |
|---|
| 286 | NEXUS_Module_Create |
|---|
| 287 | **/ |
|---|
| 288 | void NEXUS_Module_GetDefaultSettings( |
|---|
| 289 | NEXUS_ModuleSettings *pSettings /* [out] Default Settings */ |
|---|
| 290 | ); |
|---|
| 291 | |
|---|
| 292 | /** |
|---|
| 293 | Summary: |
|---|
| 294 | Create a new Nexus module. |
|---|
| 295 | |
|---|
| 296 | Description: |
|---|
| 297 | This is called by each module's Init function. |
|---|
| 298 | See Nexus_Architecture for an in-depth discussion of Nexus Modules. |
|---|
| 299 | The NEXUS_ModuleHandle is required to use Base services. |
|---|
| 300 | |
|---|
| 301 | Returns: |
|---|
| 302 | A handle for the module |
|---|
| 303 | |
|---|
| 304 | See Also: |
|---|
| 305 | NEXUS_Module_Destroy |
|---|
| 306 | NEXUS_VideoDecoderModule_Init - one usage example |
|---|
| 307 | **/ |
|---|
| 308 | NEXUS_ModuleHandle NEXUS_Module_Create( |
|---|
| 309 | const char *pModuleName, /* Module Name -- Should be unique across all modules */ |
|---|
| 310 | const NEXUS_ModuleSettings *pSettings /* Module Settings */ |
|---|
| 311 | ); |
|---|
| 312 | |
|---|
| 313 | |
|---|
| 314 | /** |
|---|
| 315 | Summary: |
|---|
| 316 | Destroy a Nexus module. |
|---|
| 317 | |
|---|
| 318 | Description: |
|---|
| 319 | |
|---|
| 320 | See Also: |
|---|
| 321 | NEXUS_Module_Create |
|---|
| 322 | NEXUS_VideoDecoderModule_Uninit - one usage example |
|---|
| 323 | **/ |
|---|
| 324 | void NEXUS_Module_Destroy( |
|---|
| 325 | NEXUS_ModuleHandle module |
|---|
| 326 | ); |
|---|
| 327 | |
|---|
| 328 | /** |
|---|
| 329 | Summary: |
|---|
| 330 | Get module name |
|---|
| 331 | **/ |
|---|
| 332 | const char *NEXUS_Module_GetName(NEXUS_ModuleHandle module); |
|---|
| 333 | |
|---|
| 334 | /** |
|---|
| 335 | Summary: |
|---|
| 336 | Get settings passed into NEXUS_Module_Create |
|---|
| 337 | **/ |
|---|
| 338 | void NEXUS_Module_GetSettings( |
|---|
| 339 | NEXUS_ModuleHandle module, |
|---|
| 340 | NEXUS_ModuleSettings *pSettings /* [out] */ |
|---|
| 341 | ); |
|---|
| 342 | |
|---|
| 343 | /** |
|---|
| 344 | Summary: |
|---|
| 345 | Macro to lock the current module. |
|---|
| 346 | |
|---|
| 347 | Description: |
|---|
| 348 | This is called by the synchronization thunk. It should never be called from inside module code. |
|---|
| 349 | NEXUS_MODULE_SELF must be defined to be a reference to the NEXUS_ModuleHandle for the current module. |
|---|
| 350 | |
|---|
| 351 | See Also: |
|---|
| 352 | NEXUS_TryLockModule |
|---|
| 353 | NEXUS_UnlockModule |
|---|
| 354 | **/ |
|---|
| 355 | #define NEXUS_LockModule() NEXUS_Module_Lock(NEXUS_MODULE_SELF) |
|---|
| 356 | |
|---|
| 357 | /** |
|---|
| 358 | Summary: |
|---|
| 359 | Macro to try to lock the current module. |
|---|
| 360 | |
|---|
| 361 | Description: |
|---|
| 362 | NEXUS_MODULE_SELF must be defined to be a reference to the NEXUS_ModuleHandle for the current module. |
|---|
| 363 | |
|---|
| 364 | See Also: |
|---|
| 365 | NEXUS_LockModule |
|---|
| 366 | NEXUS_UnlockModule |
|---|
| 367 | **/ |
|---|
| 368 | #define NEXUS_TryLockModule() NEXUS_Module_TryLock(NEXUS_MODULE_SELF) |
|---|
| 369 | |
|---|
| 370 | /** |
|---|
| 371 | Summary: |
|---|
| 372 | Unlock the current module. |
|---|
| 373 | |
|---|
| 374 | Description: |
|---|
| 375 | This is called by the synchronization thunk. It should never be called from inside module code. |
|---|
| 376 | NEXUS_MODULE_SELF must be defined to be a reference to the NEXUS_ModuleHandle for the current module. |
|---|
| 377 | |
|---|
| 378 | See Also: |
|---|
| 379 | **/ |
|---|
| 380 | #define NEXUS_UnlockModule() NEXUS_Module_Unlock(NEXUS_MODULE_SELF) |
|---|
| 381 | |
|---|
| 382 | /** |
|---|
| 383 | Summary: |
|---|
| 384 | Assert that the current module is locked. |
|---|
| 385 | |
|---|
| 386 | Description: |
|---|
| 387 | This is useful inside private API functions to ensure that the caller has properly |
|---|
| 388 | locked the module before calling. |
|---|
| 389 | |
|---|
| 390 | It has little value inside public API functions because the synchronization thunk |
|---|
| 391 | already guarantees that the module is locked. |
|---|
| 392 | |
|---|
| 393 | NEXUS_MODULE_SELF must be defined to be a reference to the NEXUS_ModuleHandle for the current module. |
|---|
| 394 | |
|---|
| 395 | See Also: |
|---|
| 396 | NEXUS_LockModule |
|---|
| 397 | **/ |
|---|
| 398 | #define NEXUS_ASSERT_MODULE() BDBG_ASSERT(NEXUS_Module_Assert(NEXUS_MODULE_SELF)) |
|---|
| 399 | |
|---|
| 400 | /** |
|---|
| 401 | Summary: |
|---|
| 402 | Actual function called by NEXUS_ASSERT_MODULE macro. |
|---|
| 403 | |
|---|
| 404 | Description: |
|---|
| 405 | |
|---|
| 406 | See Also: |
|---|
| 407 | NEXUS_ASSERT_MODULE |
|---|
| 408 | **/ |
|---|
| 409 | bool NEXUS_Module_Assert( |
|---|
| 410 | NEXUS_ModuleHandle module |
|---|
| 411 | ); |
|---|
| 412 | |
|---|
| 413 | /** |
|---|
| 414 | Summary: |
|---|
| 415 | Actual function called by NEXUS_LockModule macro. |
|---|
| 416 | |
|---|
| 417 | Description: |
|---|
| 418 | |
|---|
| 419 | See Also: |
|---|
| 420 | NEXUS_LockModule |
|---|
| 421 | **/ |
|---|
| 422 | void NEXUS_Module_Lock_Tagged( |
|---|
| 423 | NEXUS_ModuleHandle module, /* Module Handle */ |
|---|
| 424 | const char *pFileName, |
|---|
| 425 | unsigned lineNumber |
|---|
| 426 | ); |
|---|
| 427 | |
|---|
| 428 | /** |
|---|
| 429 | Summary: |
|---|
| 430 | Actual function called by NEXUS_TryLockModule macro. |
|---|
| 431 | |
|---|
| 432 | Description: |
|---|
| 433 | |
|---|
| 434 | See Also: |
|---|
| 435 | NEXUS_TryLockModule |
|---|
| 436 | **/ |
|---|
| 437 | bool NEXUS_Module_TryLock_Tagged( |
|---|
| 438 | NEXUS_ModuleHandle module, /* Module Handle */ |
|---|
| 439 | const char *pFileName, |
|---|
| 440 | unsigned lineNumber |
|---|
| 441 | ); |
|---|
| 442 | |
|---|
| 443 | /** |
|---|
| 444 | Summary: |
|---|
| 445 | Actual function called by NEXUS_UnlockModule macro. |
|---|
| 446 | |
|---|
| 447 | Description: |
|---|
| 448 | |
|---|
| 449 | See Also: |
|---|
| 450 | NEXUS_UnlockModule |
|---|
| 451 | **/ |
|---|
| 452 | void NEXUS_Module_Unlock_Tagged( |
|---|
| 453 | NEXUS_ModuleHandle module, /* Module Handle */ |
|---|
| 454 | const char *pFileName, |
|---|
| 455 | unsigned lineNumber |
|---|
| 456 | ); |
|---|
| 457 | |
|---|
| 458 | /** |
|---|
| 459 | Summary: |
|---|
| 460 | Declare that this module will make downcalls into the specified module. |
|---|
| 461 | |
|---|
| 462 | Description: |
|---|
| 463 | This is a recommended call to help enforce no circular calls between modules. |
|---|
| 464 | See Nexus_Architecture.doc for an in-depth discussion of down calls. |
|---|
| 465 | NEXUS_MODULE_SELF must be defined to be a reference to the NEXUS_ModuleHandle for the current module. |
|---|
| 466 | |
|---|
| 467 | See Also: |
|---|
| 468 | **/ |
|---|
| 469 | #define NEXUS_UseModule(module) NEXUS_Module_Use(NEXUS_MODULE_SELF, (module), __FILE__, __LINE__) |
|---|
| 470 | |
|---|
| 471 | /** |
|---|
| 472 | Summary: |
|---|
| 473 | Actual function called by NEXUS_UseModule macro. |
|---|
| 474 | |
|---|
| 475 | Description: |
|---|
| 476 | |
|---|
| 477 | See Also: |
|---|
| 478 | NEXUS_UseModule |
|---|
| 479 | **/ |
|---|
| 480 | void NEXUS_Module_Use( |
|---|
| 481 | NEXUS_ModuleHandle upModule, /* source module handle */ |
|---|
| 482 | NEXUS_ModuleHandle downModule, /* source module handle */ |
|---|
| 483 | const char *pFileName, |
|---|
| 484 | unsigned lineNumber |
|---|
| 485 | ); |
|---|
| 486 | |
|---|
| 487 | /** |
|---|
| 488 | Get/set current heap for current client in the module. |
|---|
| 489 | |
|---|
| 490 | There can only be one client active in a module at a time. The thunk stores the client's current module and trusted/untrusted |
|---|
| 491 | state. Nexus modules can retrieve the current heap. Modules should never assume they can use g_pCoreHandles->heap[0] as a default. |
|---|
| 492 | **/ |
|---|
| 493 | void NEXUS_Module_SetCurrentClient(NEXUS_ModuleHandle module, NEXUS_HeapHandle heap, bool untrusted); |
|---|
| 494 | NEXUS_HeapHandle NEXUS_Module_GetDefaultHeap(NEXUS_ModuleHandle module, bool boundsHeap); |
|---|
| 495 | |
|---|
| 496 | /* DefaultHeap for current module & client. never NULL. helper macro for module code. */ |
|---|
| 497 | #define NEXUS_P_DefaultHeap(HEAP) ((HEAP)?(HEAP):NEXUS_Module_GetDefaultHeap(NEXUS_MODULE_SELF, false)) |
|---|
| 498 | |
|---|
| 499 | /* DefaultBoundsHeap for current module & client. never NULL if client is untrusted. helper macro for module code. |
|---|
| 500 | This may be NULL for trusted code because bounded is not required and may not be possible. */ |
|---|
| 501 | #define NEXUS_P_DefaultBoundsHeap(HEAP) ((HEAP)?(HEAP):NEXUS_Module_GetDefaultHeap(NEXUS_MODULE_SELF, true)) |
|---|
| 502 | |
|---|
| 503 | /** |
|---|
| 504 | Summary: |
|---|
| 505 | Settings for Nexus Callback. |
|---|
| 506 | |
|---|
| 507 | Description: |
|---|
| 508 | |
|---|
| 509 | See Also: |
|---|
| 510 | NEXUS_TaskCallback_Create |
|---|
| 511 | **/ |
|---|
| 512 | typedef struct NEXUS_CallbackSettings { |
|---|
| 513 | NEXUS_ModulePriority priority; |
|---|
| 514 | } NEXUS_CallbackSettings; |
|---|
| 515 | |
|---|
| 516 | /** |
|---|
| 517 | Summary: |
|---|
| 518 | Get default settings for the structure. |
|---|
| 519 | |
|---|
| 520 | Description: |
|---|
| 521 | This is required in order to make application code resilient to the addition of new strucutre members in the future. |
|---|
| 522 | |
|---|
| 523 | See Also: |
|---|
| 524 | NEXUS_TaskCallback_Create |
|---|
| 525 | **/ |
|---|
| 526 | void NEXUS_Callback_GetDefaultSettings( |
|---|
| 527 | NEXUS_CallbackSettings *pSettings /* [out] */ |
|---|
| 528 | ); |
|---|
| 529 | |
|---|
| 530 | /** |
|---|
| 531 | Summary: |
|---|
| 532 | IsrCallback handle obtained from NEXUS_IsrCallback_Create. |
|---|
| 533 | |
|---|
| 534 | Description: |
|---|
| 535 | IsrCallback functions are used to help with firing task level callback from the interrupt context. |
|---|
| 536 | To fire task callback from the interrupt context, calls NEXUS_IsrCallback_Create function to |
|---|
| 537 | preallocation single NEXUS_IsrCallbackHandle for each NEXUS_CallbackDesc, then user uses |
|---|
| 538 | NEXUS_IsrCallback_Fire function in order to fire callback. |
|---|
| 539 | |
|---|
| 540 | See Also: |
|---|
| 541 | NEXUS_IsrCallback_Create |
|---|
| 542 | **/ |
|---|
| 543 | typedef struct NEXUS_IsrCallback *NEXUS_IsrCallbackHandle; |
|---|
| 544 | |
|---|
| 545 | /** |
|---|
| 546 | Summary: |
|---|
| 547 | Create an IsrCallback object so that callbacks can be invoked from an ISR function. |
|---|
| 548 | |
|---|
| 549 | Description: |
|---|
| 550 | NEXUS_MODULE_SELF must be defined to be a reference to the NEXUS_ModuleHandle for the current module. |
|---|
| 551 | |
|---|
| 552 | See Also: |
|---|
| 553 | NEXUS_IsrCallback_Destroy |
|---|
| 554 | **/ |
|---|
| 555 | #define NEXUS_IsrCallback_Create(handler, settings) NEXUS_Module_IsrCallback_Create(NEXUS_MODULE_SELF,(handler), (settings), __FILE__,__LINE__) |
|---|
| 556 | |
|---|
| 557 | /** |
|---|
| 558 | Summary: |
|---|
| 559 | Destroy the IsrCallback object. |
|---|
| 560 | |
|---|
| 561 | Description: |
|---|
| 562 | NEXUS_MODULE_SELF must be defined to be a reference to the NEXUS_ModuleHandle for the current module. |
|---|
| 563 | |
|---|
| 564 | See Also: |
|---|
| 565 | NEXUS_IsrCallback_Create |
|---|
| 566 | **/ |
|---|
| 567 | #define NEXUS_IsrCallback_Destroy(callback) NEXUS_Module_IsrCallback_Destroy(NEXUS_MODULE_SELF,(callback)) |
|---|
| 568 | |
|---|
| 569 | /** |
|---|
| 570 | Summary: |
|---|
| 571 | Set the callback function for this IsrCallback instance. |
|---|
| 572 | |
|---|
| 573 | Description: |
|---|
| 574 | |
|---|
| 575 | See Also: |
|---|
| 576 | NEXUS_IsrCallback_Create |
|---|
| 577 | **/ |
|---|
| 578 | #define NEXUS_IsrCallback_Set(callback, pDesc) NEXUS_Module_IsrCallback_Set((callback), (pDesc)) |
|---|
| 579 | |
|---|
| 580 | /** |
|---|
| 581 | Summary: |
|---|
| 582 | Fire the current callback from an ISR function. |
|---|
| 583 | |
|---|
| 584 | Description: |
|---|
| 585 | NEXUS_MODULE_SELF must be defined to be a reference to the NEXUS_ModuleHandle for the current module. |
|---|
| 586 | |
|---|
| 587 | See Also: |
|---|
| 588 | NEXUS_IsrCallback_Set |
|---|
| 589 | **/ |
|---|
| 590 | #define NEXUS_IsrCallback_Fire_isr(callback) NEXUS_Module_IsrCallback_Fire_isr(NEXUS_MODULE_SELF, (callback)) |
|---|
| 591 | |
|---|
| 592 | /** |
|---|
| 593 | Summary: |
|---|
| 594 | Actual function called by NEXUS_IsrCallback_Create. |
|---|
| 595 | |
|---|
| 596 | Description: |
|---|
| 597 | |
|---|
| 598 | See Also: |
|---|
| 599 | NEXUS_IsrCallback_Create |
|---|
| 600 | **/ |
|---|
| 601 | NEXUS_IsrCallbackHandle NEXUS_Module_IsrCallback_Create( |
|---|
| 602 | NEXUS_ModuleHandle module, |
|---|
| 603 | void *interfaceHandle, |
|---|
| 604 | const NEXUS_CallbackSettings *pSettings, |
|---|
| 605 | const char *pFileName, |
|---|
| 606 | unsigned lineNumber |
|---|
| 607 | ); |
|---|
| 608 | |
|---|
| 609 | /** |
|---|
| 610 | Summary: |
|---|
| 611 | Actual function called by NEXUS_IsrCallback_Destroy. |
|---|
| 612 | |
|---|
| 613 | Description: |
|---|
| 614 | |
|---|
| 615 | See Also: |
|---|
| 616 | NEXUS_IsrCallback_Destroy |
|---|
| 617 | **/ |
|---|
| 618 | void NEXUS_Module_IsrCallback_Destroy( |
|---|
| 619 | NEXUS_ModuleHandle module, |
|---|
| 620 | NEXUS_IsrCallbackHandle callback |
|---|
| 621 | ); |
|---|
| 622 | |
|---|
| 623 | /** |
|---|
| 624 | Summary: |
|---|
| 625 | Actual function called by NEXUS_IsrCallback_Set. |
|---|
| 626 | |
|---|
| 627 | Description: |
|---|
| 628 | |
|---|
| 629 | See Also: |
|---|
| 630 | NEXUS_IsrCallback_Set |
|---|
| 631 | **/ |
|---|
| 632 | void NEXUS_Module_IsrCallback_Set( |
|---|
| 633 | NEXUS_IsrCallbackHandle callback, |
|---|
| 634 | const NEXUS_CallbackDesc *pDesc |
|---|
| 635 | ); |
|---|
| 636 | |
|---|
| 637 | /** |
|---|
| 638 | Summary: |
|---|
| 639 | Actual function called by NEXUS_IsrCallback_Fire_isr. |
|---|
| 640 | |
|---|
| 641 | Description: |
|---|
| 642 | |
|---|
| 643 | See Also: |
|---|
| 644 | NEXUS_IsrCallback_Fire_isr |
|---|
| 645 | **/ |
|---|
| 646 | void NEXUS_Module_IsrCallback_Fire_isr( |
|---|
| 647 | NEXUS_ModuleHandle module, |
|---|
| 648 | NEXUS_IsrCallbackHandle callback /* preallocated IsrCallback */ |
|---|
| 649 | ); |
|---|
| 650 | |
|---|
| 651 | |
|---|
| 652 | /** |
|---|
| 653 | Summary: |
|---|
| 654 | IsrCallback handle obtained from NEXUS_IsrCallback_Create. |
|---|
| 655 | |
|---|
| 656 | Description: |
|---|
| 657 | IsrCallback functions are used to fire task level callback from the task context. |
|---|
| 658 | To fire task callback from the tasj context, call NEXUS_TaskCallback_Create function to |
|---|
| 659 | preallocation single NEXUS_TaskCallbackHandle for each NEXUS_CallbackDesc, then user uses |
|---|
| 660 | NEXUS_TaskCallback_Fire function in order to fire callback. |
|---|
| 661 | |
|---|
| 662 | See Also: |
|---|
| 663 | NEXUS_IsrCallback_Create |
|---|
| 664 | **/ |
|---|
| 665 | typedef struct NEXUS_TaskCallback *NEXUS_TaskCallbackHandle; |
|---|
| 666 | |
|---|
| 667 | /** |
|---|
| 668 | Summary: |
|---|
| 669 | Create an TaskCallback object so that callbacks can be invoked from the task context |
|---|
| 670 | |
|---|
| 671 | Description: |
|---|
| 672 | NEXUS_MODULE_SELF must be defined to be a reference to the NEXUS_ModuleHandle for the current module. |
|---|
| 673 | |
|---|
| 674 | See Also: |
|---|
| 675 | NEXUS_TaskCallback_Destroy |
|---|
| 676 | **/ |
|---|
| 677 | #define NEXUS_TaskCallback_Create(handler, settings) NEXUS_Module_TaskCallback_Create(NEXUS_MODULE_SELF,(handler),(settings),__FILE__,__LINE__) |
|---|
| 678 | |
|---|
| 679 | /** |
|---|
| 680 | Summary: |
|---|
| 681 | Destroy the TaskCallback object. |
|---|
| 682 | |
|---|
| 683 | Description: |
|---|
| 684 | NEXUS_MODULE_SELF must be defined to be a reference to the NEXUS_ModuleHandle for the current module. |
|---|
| 685 | |
|---|
| 686 | See Also: |
|---|
| 687 | NEXUS_TaskCallback_Create |
|---|
| 688 | **/ |
|---|
| 689 | #define NEXUS_TaskCallback_Destroy(callback) NEXUS_Module_TaskCallback_Destroy(NEXUS_MODULE_SELF,(callback)) |
|---|
| 690 | |
|---|
| 691 | /** |
|---|
| 692 | Summary: |
|---|
| 693 | Set the callback function for this TaskCallback instance. |
|---|
| 694 | |
|---|
| 695 | Description: |
|---|
| 696 | |
|---|
| 697 | See Also: |
|---|
| 698 | NEXUS_TaskCallback_Create |
|---|
| 699 | **/ |
|---|
| 700 | #define NEXUS_TaskCallback_Set(callback, pDesc) NEXUS_Module_TaskCallback_Set((callback), (pDesc)) |
|---|
| 701 | |
|---|
| 702 | /** |
|---|
| 703 | Summary: |
|---|
| 704 | Fire the current callback. |
|---|
| 705 | |
|---|
| 706 | Description: |
|---|
| 707 | NEXUS_MODULE_SELF must be defined to be a reference to the NEXUS_ModuleHandle for the current module. |
|---|
| 708 | |
|---|
| 709 | See Also: |
|---|
| 710 | NEXUS_TaskCallback_Set |
|---|
| 711 | **/ |
|---|
| 712 | #define NEXUS_TaskCallback_Fire(callback) NEXUS_Module_TaskCallback_Fire(NEXUS_MODULE_SELF, (callback)) |
|---|
| 713 | |
|---|
| 714 | /** |
|---|
| 715 | Summary: |
|---|
| 716 | Actual function called by NEXUS_TaskCallback_Create. |
|---|
| 717 | |
|---|
| 718 | Description: |
|---|
| 719 | |
|---|
| 720 | See Also: |
|---|
| 721 | NEXUS_TaskCallback_Create |
|---|
| 722 | **/ |
|---|
| 723 | NEXUS_TaskCallbackHandle |
|---|
| 724 | NEXUS_Module_TaskCallback_Create( |
|---|
| 725 | NEXUS_ModuleHandle module, |
|---|
| 726 | void *interfaceHandle, |
|---|
| 727 | const NEXUS_CallbackSettings *pSettings, |
|---|
| 728 | const char *pFileName, |
|---|
| 729 | unsigned lineNumber |
|---|
| 730 | ); |
|---|
| 731 | |
|---|
| 732 | /** |
|---|
| 733 | Summary: |
|---|
| 734 | Actual function called by NEXUS_TaskCallback_Set. |
|---|
| 735 | |
|---|
| 736 | Description: |
|---|
| 737 | |
|---|
| 738 | See Also: |
|---|
| 739 | NEXUS_TaskCallback_Set |
|---|
| 740 | **/ |
|---|
| 741 | void NEXUS_Module_TaskCallback_Set( |
|---|
| 742 | NEXUS_TaskCallbackHandle handle, |
|---|
| 743 | const NEXUS_CallbackDesc *pDesc |
|---|
| 744 | ); |
|---|
| 745 | |
|---|
| 746 | /** |
|---|
| 747 | Summary: |
|---|
| 748 | Actual function called by NEXUS_TaskCallback_Destroy. |
|---|
| 749 | |
|---|
| 750 | Description: |
|---|
| 751 | |
|---|
| 752 | See Also: |
|---|
| 753 | NEXUS_TaskCallback_Destroy |
|---|
| 754 | **/ |
|---|
| 755 | void NEXUS_Module_TaskCallback_Destroy( |
|---|
| 756 | NEXUS_ModuleHandle module, |
|---|
| 757 | NEXUS_TaskCallbackHandle callback |
|---|
| 758 | ); |
|---|
| 759 | |
|---|
| 760 | /** |
|---|
| 761 | Summary: |
|---|
| 762 | Actual function called by NEXUS_TaskCallback_Fire. |
|---|
| 763 | |
|---|
| 764 | Description: |
|---|
| 765 | |
|---|
| 766 | See Also: |
|---|
| 767 | NEXUS_TaskCallback_Fire |
|---|
| 768 | **/ |
|---|
| 769 | void NEXUS_Module_TaskCallback_Fire( |
|---|
| 770 | NEXUS_ModuleHandle module, |
|---|
| 771 | NEXUS_TaskCallbackHandle callback |
|---|
| 772 | ); |
|---|
| 773 | |
|---|
| 774 | |
|---|
| 775 | /** |
|---|
| 776 | Summary: |
|---|
| 777 | Request that a module's function is called whenever an event is set. |
|---|
| 778 | |
|---|
| 779 | Description: |
|---|
| 780 | Base will lock the module before calling the callback. |
|---|
| 781 | NEXUS_MODULE_SELF must be defined to be a reference to the NEXUS_ModuleHandle for the current module. |
|---|
| 782 | The event is a BKNI_EventHandle. Events are set with BKNI_SetEvent. |
|---|
| 783 | If set an event is set multiple times in rapid succession, you may only receive one callback. |
|---|
| 784 | |
|---|
| 785 | See Also: |
|---|
| 786 | NEXUS_UnregisterEvent |
|---|
| 787 | NEXUS_Module_RegisterEvent |
|---|
| 788 | **/ |
|---|
| 789 | #define NEXUS_RegisterEvent(event, callback, context) \ |
|---|
| 790 | NEXUS_Module_RegisterEvent(NEXUS_MODULE_SELF, event, callback, context, __FILE__, __LINE__) |
|---|
| 791 | |
|---|
| 792 | /** |
|---|
| 793 | Summary: |
|---|
| 794 | Unregister the callback set up by NEXUS_RegisterEvent |
|---|
| 795 | |
|---|
| 796 | Description: |
|---|
| 797 | NEXUS_MODULE_SELF must be defined to be a reference to the NEXUS_ModuleHandle for the current module. |
|---|
| 798 | |
|---|
| 799 | See Also: |
|---|
| 800 | NEXUS_RegisterEvent |
|---|
| 801 | NEXUS_Module_UnregisterEvent |
|---|
| 802 | **/ |
|---|
| 803 | #define NEXUS_UnregisterEvent(event) \ |
|---|
| 804 | NEXUS_Module_UnregisterEvent(NEXUS_MODULE_SELF, event, __FILE__, __LINE__) |
|---|
| 805 | |
|---|
| 806 | |
|---|
| 807 | /** |
|---|
| 808 | Summary: |
|---|
| 809 | Initialize NEXUS_CallbackDesc structure |
|---|
| 810 | |
|---|
| 811 | Description: |
|---|
| 812 | This is required in order to make application code resilient to the addition of new strucutre members in the future. |
|---|
| 813 | **/ |
|---|
| 814 | void NEXUS_CallbackDesc_Init( |
|---|
| 815 | NEXUS_CallbackDesc *desc /* [out] */ |
|---|
| 816 | ); |
|---|
| 817 | |
|---|
| 818 | /** |
|---|
| 819 | Summary: |
|---|
| 820 | Handle obtained from NEXUS_RegisterEvent |
|---|
| 821 | |
|---|
| 822 | Description: |
|---|
| 823 | |
|---|
| 824 | See Also: |
|---|
| 825 | NEXUS_RegisterEvent |
|---|
| 826 | **/ |
|---|
| 827 | typedef struct NEXUS_EventCallback *NEXUS_EventCallbackHandle; |
|---|
| 828 | |
|---|
| 829 | /** |
|---|
| 830 | Summary: |
|---|
| 831 | Actual function called by NEXUS_RegisterEvent macro. |
|---|
| 832 | |
|---|
| 833 | Description: |
|---|
| 834 | |
|---|
| 835 | See Also: |
|---|
| 836 | NEXUS_RegisterEvent |
|---|
| 837 | **/ |
|---|
| 838 | NEXUS_EventCallbackHandle NEXUS_Module_RegisterEvent( |
|---|
| 839 | NEXUS_ModuleHandle module, /* Module Handle */ |
|---|
| 840 | BKNI_EventHandle event, /* Event To Be Registered. See BKNI_CreateEvent. */ |
|---|
| 841 | void (*pCallback)(void *), /* Callback Function */ |
|---|
| 842 | void *pContext, /* Context provided to callback */ |
|---|
| 843 | const char *pFileName, |
|---|
| 844 | unsigned lineNumber |
|---|
| 845 | ); |
|---|
| 846 | |
|---|
| 847 | /** |
|---|
| 848 | Summary: |
|---|
| 849 | Actual function called by NEXUS_UnregisterEvent macro. |
|---|
| 850 | |
|---|
| 851 | Description: |
|---|
| 852 | |
|---|
| 853 | See Also: |
|---|
| 854 | NEXUS_UnregisterEvent |
|---|
| 855 | **/ |
|---|
| 856 | void NEXUS_Module_UnregisterEvent( |
|---|
| 857 | NEXUS_ModuleHandle module, /* Module Handle */ |
|---|
| 858 | NEXUS_EventCallbackHandle event, /* Event callback To Be Unregistered */ |
|---|
| 859 | const char *pFileName, |
|---|
| 860 | unsigned lineNumber |
|---|
| 861 | ); |
|---|
| 862 | |
|---|
| 863 | /** |
|---|
| 864 | Summary: |
|---|
| 865 | Handle for a timer. |
|---|
| 866 | |
|---|
| 867 | Description: |
|---|
| 868 | |
|---|
| 869 | See Also: |
|---|
| 870 | NEXUS_ScheduleTimer |
|---|
| 871 | **/ |
|---|
| 872 | typedef struct NEXUS_Timer *NEXUS_TimerHandle; |
|---|
| 873 | |
|---|
| 874 | /** |
|---|
| 875 | Summary: |
|---|
| 876 | Schedule a callback after an elapsed time. |
|---|
| 877 | |
|---|
| 878 | Description: |
|---|
| 879 | Base will lock the module before calling the callback function. |
|---|
| 880 | Timers are one-shot and are self-cancelling. If you want a recurring timer, you should call NEXUS_ScheduleTimer from inside your time callback. |
|---|
| 881 | |
|---|
| 882 | See Also: |
|---|
| 883 | NEXUS_CancelTimer |
|---|
| 884 | **/ |
|---|
| 885 | #define NEXUS_ScheduleTimer(delayMs, callback, context) \ |
|---|
| 886 | NEXUS_Module_ScheduleTimer(NEXUS_MODULE_SELF, delayMs, callback, context, __FILE__, __LINE__) |
|---|
| 887 | |
|---|
| 888 | /** |
|---|
| 889 | Summary: |
|---|
| 890 | Cancel a timer. |
|---|
| 891 | |
|---|
| 892 | Description: |
|---|
| 893 | |
|---|
| 894 | See Also: |
|---|
| 895 | NEXUS_ScheduleTimer |
|---|
| 896 | **/ |
|---|
| 897 | #define NEXUS_CancelTimer(timer) \ |
|---|
| 898 | NEXUS_Module_CancelTimer(NEXUS_MODULE_SELF, timer, __FILE__, __LINE__) |
|---|
| 899 | |
|---|
| 900 | /** |
|---|
| 901 | Summary: |
|---|
| 902 | Actual function called by NEXUS_ScheduleTimer macro. |
|---|
| 903 | |
|---|
| 904 | Description: |
|---|
| 905 | |
|---|
| 906 | See Also: |
|---|
| 907 | NEXUS_ScheduleTimer |
|---|
| 908 | **/ |
|---|
| 909 | NEXUS_TimerHandle NEXUS_Module_ScheduleTimer( |
|---|
| 910 | NEXUS_ModuleHandle module, /* Module Handle */ |
|---|
| 911 | unsigned delayMs, /* Delay in Milliseconds */ |
|---|
| 912 | void (*pCallback)(void *), /* Callback function */ |
|---|
| 913 | void *pContext, /* Context provided to callback */ |
|---|
| 914 | const char *pFileName, |
|---|
| 915 | unsigned lineNumber |
|---|
| 916 | ); |
|---|
| 917 | |
|---|
| 918 | /** |
|---|
| 919 | Summary: |
|---|
| 920 | Actual function called by NEXUS_CancelTimer macro. |
|---|
| 921 | |
|---|
| 922 | Description: |
|---|
| 923 | |
|---|
| 924 | See Also: |
|---|
| 925 | NEXUS_CancelTimer |
|---|
| 926 | **/ |
|---|
| 927 | void NEXUS_Module_CancelTimer( |
|---|
| 928 | NEXUS_ModuleHandle module, /* Module Handle */ |
|---|
| 929 | NEXUS_TimerHandle timer, /* Timer to be cancelled */ |
|---|
| 930 | const char *pFileName, |
|---|
| 931 | unsigned lineNumber |
|---|
| 932 | ); |
|---|
| 933 | |
|---|
| 934 | /** |
|---|
| 935 | Summary: |
|---|
| 936 | ISR variant of NEXUS_FlushCache |
|---|
| 937 | |
|---|
| 938 | Description: |
|---|
| 939 | |
|---|
| 940 | See Also: |
|---|
| 941 | NEXUS_FlushCache |
|---|
| 942 | **/ |
|---|
| 943 | #define NEXUS_FlushCache_isr NEXUS_FlushCache |
|---|
| 944 | |
|---|
| 945 | /** |
|---|
| 946 | Summary: |
|---|
| 947 | Stop all callbacks associated with this interface handle. |
|---|
| 948 | Wait for any running callbacks to finish, and ensure that no other callbacks for this handle are fired. |
|---|
| 949 | **/ |
|---|
| 950 | void NEXUS_Base_P_StopCallbacks( |
|---|
| 951 | void *interfaceHandle |
|---|
| 952 | ); |
|---|
| 953 | |
|---|
| 954 | /** |
|---|
| 955 | Summary: |
|---|
| 956 | Re-enable all callbacks for this interface handle. |
|---|
| 957 | All interfaces default to being already started. |
|---|
| 958 | If you call StopCallbacks followed by StartCallbacks, no pending callbacks will be lost. <<maybe>> |
|---|
| 959 | **/ |
|---|
| 960 | void NEXUS_Base_P_StartCallbacks( |
|---|
| 961 | void *interfaceHandle |
|---|
| 962 | ); |
|---|
| 963 | |
|---|
| 964 | #include "nexus_base_os_types.h" |
|---|
| 965 | |
|---|
| 966 | /** |
|---|
| 967 | Summary: |
|---|
| 968 | Returns the current timestamp |
|---|
| 969 | **/ |
|---|
| 970 | void NEXUS_Time_Get( |
|---|
| 971 | NEXUS_Time *time |
|---|
| 972 | ); |
|---|
| 973 | |
|---|
| 974 | /** |
|---|
| 975 | Summary: |
|---|
| 976 | Returns difference in milliseconds between two timestamps obtained with b_time_get. |
|---|
| 977 | |
|---|
| 978 | Description: |
|---|
| 979 | It's recomended that code would use this function in a way that it could return |
|---|
| 980 | only positive values (where applicable, it helps in handling wraparound conditions) |
|---|
| 981 | **/ |
|---|
| 982 | long NEXUS_Time_Diff( |
|---|
| 983 | const NEXUS_Time *future, |
|---|
| 984 | const NEXUS_Time *past |
|---|
| 985 | ); |
|---|
| 986 | |
|---|
| 987 | /** |
|---|
| 988 | Summary: |
|---|
| 989 | Adds delta in milliseconds to the timestamp |
|---|
| 990 | **/ |
|---|
| 991 | void NEXUS_Time_Add( |
|---|
| 992 | NEXUS_Time *time, |
|---|
| 993 | long delta_ms /* milliseconds */ |
|---|
| 994 | ); |
|---|
| 995 | |
|---|
| 996 | /** |
|---|
| 997 | Summary: |
|---|
| 998 | Give address mapping data for a block of memory to allow address/offset conversion using functions in nexus_base_mmap.h. |
|---|
| 999 | |
|---|
| 1000 | Description: |
|---|
| 1001 | Multiple calls to NEXUS_P_AddMap can be made to specify a set of memory blocks. |
|---|
| 1002 | |
|---|
| 1003 | See Also: NEXUS_AddrToOffset NEXUS_OffsetToCachedAddr NEXUS_OffsetToUncachedAddr |
|---|
| 1004 | **/ |
|---|
| 1005 | NEXUS_Error NEXUS_P_AddMap( |
|---|
| 1006 | uint32_t offset, /* physical offset in memory */ |
|---|
| 1007 | void *cached, /* cached address */ |
|---|
| 1008 | void *uncached, /* uncached address */ |
|---|
| 1009 | size_t length /* size in bytes */ |
|---|
| 1010 | ); |
|---|
| 1011 | |
|---|
| 1012 | /** |
|---|
| 1013 | Summary: |
|---|
| 1014 | In both arguments are not NULL, then works the same as standard strcmp. |
|---|
| 1015 | Otherwise returns 0 if both str1 and str2 are NULL and returns not 0 if only one argument is NULL. |
|---|
| 1016 | **/ |
|---|
| 1017 | int NEXUS_StrCmp( |
|---|
| 1018 | const char *str1, |
|---|
| 1019 | const char *str2 |
|---|
| 1020 | ); |
|---|
| 1021 | |
|---|
| 1022 | /** |
|---|
| 1023 | Summary: |
|---|
| 1024 | Returns size of the structure or union member |
|---|
| 1025 | **/ |
|---|
| 1026 | #define NEXUS_SIZEOF(type, field) sizeof(((type *)0)->field) |
|---|
| 1027 | |
|---|
| 1028 | /** |
|---|
| 1029 | Summary: |
|---|
| 1030 | Returns offset of the structure member |
|---|
| 1031 | **/ |
|---|
| 1032 | #define NEXUS_OFFSETOF(type, field) offsetof(type, field) |
|---|
| 1033 | /* #define NEXUS_OFFSETOF(type, field) ((uint8_t *)(&((type *)0)->field) - (uint8_t *)0) */ /* this definition generates compiler warnings on 2.6.37 kernel toolchain */ |
|---|
| 1034 | |
|---|
| 1035 | /** |
|---|
| 1036 | Summary: |
|---|
| 1037 | Validates that members of two different structures have indentical representation |
|---|
| 1038 | **/ |
|---|
| 1039 | #define NEXUS_ASSERT_FIELD(type1, field1, type2, field2) BDBG_CASSERT(NEXUS_OFFSETOF(type1, field1)==NEXUS_OFFSETOF(type2,field2) && NEXUS_SIZEOF(type1,field1)==NEXUS_SIZEOF(type2,field2)) |
|---|
| 1040 | |
|---|
| 1041 | /** |
|---|
| 1042 | Summary: |
|---|
| 1043 | Validates that size of two structure is identical |
|---|
| 1044 | **/ |
|---|
| 1045 | #define NEXUS_ASSERT_STRUCTURE(type1, type2) BDBG_CASSERT(sizeof(type1)==sizeof(type2)) |
|---|
| 1046 | |
|---|
| 1047 | /** |
|---|
| 1048 | Summary: |
|---|
| 1049 | Synchronized callback handler. |
|---|
| 1050 | |
|---|
| 1051 | Description: |
|---|
| 1052 | NEXUS_CallbackHandler provides way for the nexus module to set a handler for the asynchronous callback that its execution serialized with the rest of module API's. |
|---|
| 1053 | For specific needs NEXUS_CallbackHandler allowes to set a guard function that could be called without serialization and could guard execution of main handler. |
|---|
| 1054 | |
|---|
| 1055 | See Also: |
|---|
| 1056 | NEXUS_CallbackHandler_Init |
|---|
| 1057 | NEXUS_CallbackHandler_Shutdown |
|---|
| 1058 | NEXUS_CallbackHandler_PrepareCallback |
|---|
| 1059 | NEXUS_CallbackHandler_SetGuard |
|---|
| 1060 | **/ |
|---|
| 1061 | typedef struct NEXUS_CallbackHandler NEXUS_CallbackHandler; |
|---|
| 1062 | |
|---|
| 1063 | /** |
|---|
| 1064 | Summary: |
|---|
| 1065 | Initializes callback handler |
|---|
| 1066 | |
|---|
| 1067 | Description: |
|---|
| 1068 | Initializes callback handler with callbadk and context passed to the callback function. |
|---|
| 1069 | Base will lock the module before calling the callback function. |
|---|
| 1070 | |
|---|
| 1071 | NEXUS_CallbackHandler_Init should be called once and only once, prior to any other refference to the callback handler. |
|---|
| 1072 | |
|---|
| 1073 | See Also: |
|---|
| 1074 | NEXUS_CallbackHandler_Shutdown |
|---|
| 1075 | NEXUS_CallbackHandler_PrepareCallback |
|---|
| 1076 | **/ |
|---|
| 1077 | #define NEXUS_CallbackHandler_Init(h, callback, context) NEXUS_Base_P_CallbackHandler_Init(&(h), NEXUS_MODULE_SELF, callback, context, __FILE__, __LINE__) |
|---|
| 1078 | |
|---|
| 1079 | /** |
|---|
| 1080 | Summary: |
|---|
| 1081 | Releases resources assiciated with the callback handler |
|---|
| 1082 | |
|---|
| 1083 | Description: |
|---|
| 1084 | |
|---|
| 1085 | See Also: |
|---|
| 1086 | NEXUS_CallbackHandler_Init |
|---|
| 1087 | **/ |
|---|
| 1088 | #define NEXUS_CallbackHandler_Shutdown(h) NEXUS_Base_P_CallbackHandler_Shutdown(&(h)) |
|---|
| 1089 | |
|---|
| 1090 | /** |
|---|
| 1091 | Summary: |
|---|
| 1092 | Links NEXUS_CallbackDesc with NEXUS_CallbackHandler |
|---|
| 1093 | |
|---|
| 1094 | Description: |
|---|
| 1095 | Initializes NEXUS_CallbackDesc so asynchronous callback would get routed through a base layer, where it serialiazed with the module context and delivered to the user provided callback handler. |
|---|
| 1096 | |
|---|
| 1097 | See Also: |
|---|
| 1098 | NEXUS_CallbackHandler_Init |
|---|
| 1099 | NEXUS_CallbackHandler_Stop |
|---|
| 1100 | **/ |
|---|
| 1101 | #define NEXUS_CallbackHandler_PrepareCallback(h, _callback) do { BDBG_OBJECT_ASSERT(&(h), NEXUS_CallbackHandler);(_callback).context=&(h);(_callback).callback=NEXUS_Base_P_CallbackHandler_Dispatch;} while(0) |
|---|
| 1102 | |
|---|
| 1103 | |
|---|
| 1104 | |
|---|
| 1105 | /** |
|---|
| 1106 | Summary: |
|---|
| 1107 | Stops deffered callbacks |
|---|
| 1108 | |
|---|
| 1109 | Description: |
|---|
| 1110 | |
|---|
| 1111 | See Also: |
|---|
| 1112 | NEXUS_CallbackHandler_PrepareCallback |
|---|
| 1113 | **/ |
|---|
| 1114 | #define NEXUS_CallbackHandler_Stop(h) NEXUS_Base_P_CallbackHandler_Stop(&(h)) |
|---|
| 1115 | |
|---|
| 1116 | #define NEXUS_CALLBACK_DEFLECTED NEXUS_MAKE_ERR_CODE(0x200, 0) |
|---|
| 1117 | |
|---|
| 1118 | /** |
|---|
| 1119 | Summary: |
|---|
| 1120 | Sets guard function |
|---|
| 1121 | |
|---|
| 1122 | Description: |
|---|
| 1123 | Guear function could be executed without serializing with the module context, and if returns error code other then NEXUS_SUCCESS |
|---|
| 1124 | (for example NEXUS_CALLBACK_DEFLECTED), callback would not get executed. It's important that guard function should not call any blocking |
|---|
| 1125 | functions. |
|---|
| 1126 | |
|---|
| 1127 | See Also: |
|---|
| 1128 | NEXUS_CallbackHandler_Init |
|---|
| 1129 | **/ |
|---|
| 1130 | #define NEXUS_CallbackHandler_SetGuard(h, guard) do { BDBG_OBJECT_ASSERT(&(h), NEXUS_CallbackHandler);(h).pCallbackGuard = guard;} while(0) |
|---|
| 1131 | |
|---|
| 1132 | |
|---|
| 1133 | |
|---|
| 1134 | /* internal function to handle all callback dispatched inside nexus */ |
|---|
| 1135 | void NEXUS_Base_P_CallbackHandler_Init(NEXUS_CallbackHandler *handler, NEXUS_ModuleHandle module, void (*pCallback)(void *), void *pContext,const char *pFileName,unsigned lineNumber); |
|---|
| 1136 | void NEXUS_Base_P_CallbackHandler_Dispatch(void *context, int arg); |
|---|
| 1137 | void NEXUS_Base_P_CallbackHandler_Stop(NEXUS_CallbackHandler *handler); |
|---|
| 1138 | void NEXUS_Base_P_CallbackHandler_Shutdown(NEXUS_CallbackHandler *handler); |
|---|
| 1139 | |
|---|
| 1140 | BDBG_OBJECT_ID_DECLARE(NEXUS_CallbackHandler); |
|---|
| 1141 | |
|---|
| 1142 | struct NEXUS_CallbackHandler { |
|---|
| 1143 | const char *pFileName; |
|---|
| 1144 | unsigned lineNumber; |
|---|
| 1145 | BDBG_OBJECT(NEXUS_CallbackHandler) |
|---|
| 1146 | NEXUS_ModuleHandle module; /* module associated with the callback handler */ |
|---|
| 1147 | NEXUS_Error (*pCallbackGuard)(void *); /* optional callback that is executed prior to acquiring module lock, it called unsycnrhonized */ |
|---|
| 1148 | void (*pCallback)(void *); /* Callback Function */ |
|---|
| 1149 | void *pContext; /* Context provided to callback */ |
|---|
| 1150 | NEXUS_TimerHandle timer; |
|---|
| 1151 | }; |
|---|
| 1152 | |
|---|
| 1153 | #if (NEXUS_BASE_OS_linuxkernel && defined(NEXUS_MODE_driver)) || NEXUS_BASE_MODE_PROXY |
|---|
| 1154 | /** |
|---|
| 1155 | nexus/base exposes an external scheduler interface used in linux kernel mode and in the proxy. |
|---|
| 1156 | See nexus/platform/PLATFORM/src/linuxkernel/nexus_driver_callbacks.c for linux kernel mode usage. |
|---|
| 1157 | See nexus/platform/PLATFORM/src/linuxuser.proxy/nexus_platform_os.c for linux proxy usage. |
|---|
| 1158 | **/ |
|---|
| 1159 | #define NEXUS_BASE_EXTERNAL_SCHEDULER 1 |
|---|
| 1160 | #endif |
|---|
| 1161 | |
|---|
| 1162 | NEXUS_Error NEXUS_P_Base_ExternalScheduler_Step( |
|---|
| 1163 | NEXUS_ModulePriority priority, |
|---|
| 1164 | unsigned timeout, |
|---|
| 1165 | NEXUS_P_Base_Scheduler_Status *status, /* [out] */ |
|---|
| 1166 | bool (*complete)(void *context), |
|---|
| 1167 | void *context |
|---|
| 1168 | ); |
|---|
| 1169 | |
|---|
| 1170 | typedef struct NEXUS_Base_Scheduler_Config { |
|---|
| 1171 | const char *name; |
|---|
| 1172 | const NEXUS_ThreadSettings *pSettings; |
|---|
| 1173 | BKNI_MutexHandle callback_lock; /* callback that is acquired when callback active */ |
|---|
| 1174 | } NEXUS_Base_Scheduler_Config; |
|---|
| 1175 | |
|---|
| 1176 | void NEXUS_P_Base_GetSchedulerConfig( |
|---|
| 1177 | NEXUS_ModulePriority priority, |
|---|
| 1178 | NEXUS_Base_Scheduler_Config *config /* [out] */ |
|---|
| 1179 | ); |
|---|
| 1180 | |
|---|
| 1181 | typedef struct NEXUS_RefCntDescriptor { |
|---|
| 1182 | unsigned offset; /* used to convert from the NEXUS_RefCnt to the object */ |
|---|
| 1183 | void (*finalizer)(void *); |
|---|
| 1184 | } NEXUS_RefCntDescriptor; |
|---|
| 1185 | |
|---|
| 1186 | /** |
|---|
| 1187 | Summary: |
|---|
| 1188 | Datatype embedded into the objects that support reference counting |
|---|
| 1189 | |
|---|
| 1190 | See Also: |
|---|
| 1191 | NEXUS_REFCNT_INIT |
|---|
| 1192 | **/ |
|---|
| 1193 | |
|---|
| 1194 | typedef struct NEXUS_RefCnt { |
|---|
| 1195 | int ref_cnt; |
|---|
| 1196 | const NEXUS_RefCntDescriptor *descriptor; |
|---|
| 1197 | } NEXUS_RefCnt; |
|---|
| 1198 | |
|---|
| 1199 | |
|---|
| 1200 | void NEXUS_RefCntObj_P_Init(NEXUS_RefCnt *cnt, const NEXUS_RefCntDescriptor *descriptor); |
|---|
| 1201 | void NEXUS_RefCntObj_P_Acquire_Tagged(void *object, const NEXUS_RefCntDescriptor *descriptor, NEXUS_ModuleHandle module, const char *pFileName, unsigned lineNumber); |
|---|
| 1202 | void NEXUS_RefCntObj_P_Release_Tagged(void *object, const NEXUS_RefCntDescriptor *descriptor, NEXUS_ModuleHandle module, const char *pFileName, unsigned lineNumber); |
|---|
| 1203 | |
|---|
| 1204 | /** |
|---|
| 1205 | Summary: |
|---|
| 1206 | Declares functions that are part of implementation for object reference counting. |
|---|
| 1207 | |
|---|
| 1208 | Description: |
|---|
| 1209 | NEXUS_REFCNT_CLASS_DECLARE should be placed into the header file inside the modules 'priv' directory. |
|---|
| 1210 | |
|---|
| 1211 | See Also: |
|---|
| 1212 | NEXUS_REFCNT_CLASS_MAKE |
|---|
| 1213 | **/ |
|---|
| 1214 | |
|---|
| 1215 | #define NEXUS_REFCNT_CLASS_DECLARE(type) \ |
|---|
| 1216 | void type##_RefCnt_P_Acquire_Tagged(type##Handle object, NEXUS_ModuleHandle origin, const char *pFileName, unsigned lineNumber); \ |
|---|
| 1217 | void type##_RefCnt_P_Release_Tagged(type##Handle object, NEXUS_ModuleHandle origin, const char *pFileName, unsigned lineNumber) |
|---|
| 1218 | |
|---|
| 1219 | /** |
|---|
| 1220 | Summary: |
|---|
| 1221 | Defines functions and data that are part of implementation for object reference counting. |
|---|
| 1222 | |
|---|
| 1223 | Description: |
|---|
| 1224 | NEXUS_REFCNT_CLASS_MAKE should be placed into C file that is a part of modules implementation |
|---|
| 1225 | |
|---|
| 1226 | See Also: |
|---|
| 1227 | NEXUS_REFCNT_CLASS_DECLARE |
|---|
| 1228 | **/ |
|---|
| 1229 | |
|---|
| 1230 | #define NEXUS_REFCNT_CLASS_MAKE(type, field, destructor) \ |
|---|
| 1231 | static void type##_Finalizer(void *object) {NEXUS_ASSERT_MODULE(); destructor(object); } \ |
|---|
| 1232 | static const NEXUS_RefCntDescriptor type##_RefCnt_Descriptor = {NEXUS_OFFSETOF(struct type, field), type##_Finalizer}; \ |
|---|
| 1233 | void type##_RefCnt_P_Acquire_Tagged(type##Handle object, NEXUS_ModuleHandle origin, const char *pFileName, unsigned lineNumber) {NEXUS_ModuleHandle target = NEXUS_MODULE_SELF; BDBG_OBJECT_ASSERT(object, type);NEXUS_RefCntObj_P_Acquire_Tagged(object, &type##_RefCnt_Descriptor, origin==target?NULL:target, pFileName, lineNumber);} \ |
|---|
| 1234 | void type##_RefCnt_P_Release_Tagged(type##Handle object, NEXUS_ModuleHandle origin, const char *pFileName, unsigned lineNumber) {NEXUS_ModuleHandle target = NEXUS_MODULE_SELF; BDBG_OBJECT_ASSERT(object, type); NEXUS_RefCntObj_P_Release_Tagged(object, &type##_RefCnt_Descriptor, origin==target?NULL:target, pFileName, lineNumber);} \ |
|---|
| 1235 | extern int __ref_cnt_unused |
|---|
| 1236 | |
|---|
| 1237 | /** |
|---|
| 1238 | Summary: |
|---|
| 1239 | This macro should be used to initialize reference counted object |
|---|
| 1240 | |
|---|
| 1241 | Description: |
|---|
| 1242 | When intializes reference counter is set to 1, and used of NEXUS_REFCNT_RELEASE would cause call to the object finalizer (private destructor). |
|---|
| 1243 | To properly support reference counting, public destructor/close API should be reduced just to call into the NEXUS_REFCNT_RELEASE, |
|---|
| 1244 | and proper destructor (private destructor) should be linked by means of NEXUS_REFCNT_CLASS_MAKE. |
|---|
| 1245 | |
|---|
| 1246 | See Also: |
|---|
| 1247 | NEXUS_REFCNT_ACQUIRE |
|---|
| 1248 | NEXUS_REFCNT_RELEASE |
|---|
| 1249 | **/ |
|---|
| 1250 | #define NEXUS_REFCNT_INIT(type, cnt) NEXUS_RefCntObj_P_Init(cnt, &type##_RefCnt_Descriptor) |
|---|
| 1251 | |
|---|
| 1252 | /** |
|---|
| 1253 | Summary: |
|---|
| 1254 | This macro is used to inform that object of said type is used and can't be destroyed |
|---|
| 1255 | |
|---|
| 1256 | Description: |
|---|
| 1257 | **/ |
|---|
| 1258 | #define NEXUS_REFCNT_ACQUIRE(type,object) type##_RefCnt_P_Acquire_Tagged(object, NEXUS_MODULE_SELF, __FILE__, __LINE__) |
|---|
| 1259 | |
|---|
| 1260 | /** |
|---|
| 1261 | Summary: |
|---|
| 1262 | This macro is used to inform that object of said type is unused and can be safely destroyed |
|---|
| 1263 | |
|---|
| 1264 | Description: |
|---|
| 1265 | **/ |
|---|
| 1266 | #define NEXUS_REFCNT_RELEASE(type,object) type##_RefCnt_P_Release_Tagged(object, NEXUS_MODULE_SELF, __FILE__, __LINE__) |
|---|
| 1267 | |
|---|
| 1268 | #endif /* !defined NEXUS_BASE_H */ |
|---|
| 1269 | |
|---|