source: svn/trunk/newcon3bcm2_21bu/nexus/base/include/nexus_base.h @ 2

Last change on this file since 2 was 2, checked in by jglee, 11 years ago

first commit

  • Property svn:executable set to *
File size: 35.3 KB
Line 
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/*=***********************
175Nexus Base is an internal component of Nexus. It is not a module. It is not callable by applications.
176
177Nexus Base provides the following features to modules:
178
1791. Module locking
180Each module creates a handle which is uses for locking.
181See NEXUS_LockModule.
182
1832. Callback support
184Invoke callbacks which are given with NEXUS_CallbackDesc.
185NEXUS_TaskCallback and NEXUS_IsrCallback set up handles which can be used to fire a callback from task or isr context.
186
1873. Events
188Receive a synchronized task callback when a BKNI_EventHandle is set.
189See NEXUS_RegisterEvent.
190
1914. Timers
192Receive a synchronized task callback after a specified time interval.
193See NEXUS_ScheduleTimer.
194
1955. Synchronized callback handler
196Receive a syncrhroniized task callback after other nexus component issued asynchronous callback
197
198See 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
205BERR_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/**
216Summary:
217Get the last error on a thread.
218
219Description:
220This is not implemented for all OS's.
221**/
222void NEXUS_GetLastError_Os(BERR_Code *code);
223
224/**
225Summary:
226Initialize the Nexus Base Core.
227
228Description:
229This is called from Platform initialization code.
230It should be called after magnum initialization and prior to  NEXUS_Base_Init
231
232See Also:
233NEXUS_Base_Init
234NEXUS_Base_Core_Uninit
235**/
236NEXUS_Error NEXUS_Base_Core_Init(void);
237
238/**
239Summary:
240Uninit the Nexus Base Core.
241
242Description:
243This is called from Platform uninitialization code.
244It should be called after NEXUS_Base_Uninit and prior to magnum uninitialization
245
246See Also:
247NEXUS_Base_Core_Init
248NEXUS_Base_Uninit
249**/
250void NEXUS_Base_Core_Uninit(void);
251
252/**
253Summary:
254Initialize the Nexus Base.
255
256Description:
257This is called from Platform initialization code.
258
259See Also:
260NEXUS_Base_Uninit
261**/
262NEXUS_Error NEXUS_Base_Init(
263    const NEXUS_Base_Settings *pSettings
264    );
265
266/**
267Summary:
268Uninit the Nexus Base.
269
270Description:
271This is called from Platform uninitialization code.
272
273See Also:
274NEXUS_Base_Init
275**/
276void NEXUS_Base_Uninit(void);
277
278/**
279Summary:
280Get default settings for the structure.
281
282Description:
283This is required in order to make application code resilient to the addition of new strucutre members in the future.
284
285See Also:
286NEXUS_Module_Create
287**/
288void NEXUS_Module_GetDefaultSettings(
289    NEXUS_ModuleSettings *pSettings    /* [out] Default Settings */
290    );
291
292/**
293Summary:
294Create a new Nexus module.
295
296Description:
297This is called by each module's Init function.
298See Nexus_Architecture for an in-depth discussion of Nexus Modules.
299The NEXUS_ModuleHandle is required to use Base services.
300
301Returns:
302A handle for the module
303
304See Also:
305NEXUS_Module_Destroy
306NEXUS_VideoDecoderModule_Init - one usage example
307**/
308NEXUS_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/**
315Summary:
316Destroy a Nexus module.
317
318Description:
319
320See Also:
321NEXUS_Module_Create
322NEXUS_VideoDecoderModule_Uninit - one usage example
323**/
324void NEXUS_Module_Destroy(
325    NEXUS_ModuleHandle module
326    );
327
328/**
329Summary:
330Get module name
331**/
332const char *NEXUS_Module_GetName(NEXUS_ModuleHandle module);
333
334/**
335Summary:
336Get settings passed into NEXUS_Module_Create
337**/
338void NEXUS_Module_GetSettings(
339    NEXUS_ModuleHandle module,
340    NEXUS_ModuleSettings *pSettings    /* [out] */
341    );
342
343/**
344Summary:
345Macro to lock the current module.
346
347Description:
348This is called by the synchronization thunk. It should never be called from inside module code.
349NEXUS_MODULE_SELF must be defined to be a reference to the NEXUS_ModuleHandle for the current module.
350
351See Also:
352NEXUS_TryLockModule
353NEXUS_UnlockModule
354**/
355#define NEXUS_LockModule() NEXUS_Module_Lock(NEXUS_MODULE_SELF)
356
357/**
358Summary:
359Macro to try to lock the current module.
360
361Description:
362NEXUS_MODULE_SELF must be defined to be a reference to the NEXUS_ModuleHandle for the current module.
363
364See Also:
365NEXUS_LockModule
366NEXUS_UnlockModule
367**/
368#define NEXUS_TryLockModule() NEXUS_Module_TryLock(NEXUS_MODULE_SELF)
369
370/**
371Summary:
372Unlock the current module.
373
374Description:
375This is called by the synchronization thunk. It should never be called from inside module code.
376NEXUS_MODULE_SELF must be defined to be a reference to the NEXUS_ModuleHandle for the current module.
377
378See Also:
379**/
380#define NEXUS_UnlockModule() NEXUS_Module_Unlock(NEXUS_MODULE_SELF)
381
382/**
383Summary:
384Assert that the current module is locked.
385
386Description:
387This is useful inside private API functions to ensure that the caller has properly
388locked the module before calling.
389
390It has little value inside public API functions because the synchronization thunk
391already guarantees that the module is locked.
392
393NEXUS_MODULE_SELF must be defined to be a reference to the NEXUS_ModuleHandle for the current module.
394
395See Also:
396NEXUS_LockModule
397**/
398#define NEXUS_ASSERT_MODULE() BDBG_ASSERT(NEXUS_Module_Assert(NEXUS_MODULE_SELF))
399
400/**
401Summary:
402Actual function called by NEXUS_ASSERT_MODULE macro.
403
404Description:
405
406See Also:
407NEXUS_ASSERT_MODULE
408**/
409bool NEXUS_Module_Assert(
410    NEXUS_ModuleHandle module
411    );
412
413/**
414Summary:
415Actual function called by NEXUS_LockModule macro.
416
417Description:
418
419See Also:
420NEXUS_LockModule
421**/
422void NEXUS_Module_Lock_Tagged(
423    NEXUS_ModuleHandle module,  /* Module Handle */
424    const char *pFileName,
425    unsigned lineNumber
426    );
427
428/**
429Summary:
430Actual function called by NEXUS_TryLockModule macro.
431
432Description:
433
434See Also:
435NEXUS_TryLockModule
436**/
437bool NEXUS_Module_TryLock_Tagged(
438    NEXUS_ModuleHandle module,   /* Module Handle */
439    const char *pFileName,
440    unsigned lineNumber
441    );
442
443/**
444Summary:
445Actual function called by NEXUS_UnlockModule macro.
446
447Description:
448
449See Also:
450NEXUS_UnlockModule
451**/
452void NEXUS_Module_Unlock_Tagged(
453    NEXUS_ModuleHandle module,   /* Module Handle */
454    const char *pFileName,
455    unsigned lineNumber
456    );
457
458/**
459Summary:
460Declare that this module will make downcalls into the specified module.
461
462Description:
463This is a recommended call to help enforce no circular calls between modules.
464See Nexus_Architecture.doc for an in-depth discussion of down calls.
465NEXUS_MODULE_SELF must be defined to be a reference to the NEXUS_ModuleHandle for the current module.
466
467See Also:
468**/
469#define NEXUS_UseModule(module) NEXUS_Module_Use(NEXUS_MODULE_SELF, (module), __FILE__, __LINE__)
470
471/**
472Summary:
473Actual function called by NEXUS_UseModule macro.
474
475Description:
476
477See Also:
478NEXUS_UseModule
479**/
480void 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/**
488Get/set current heap for current client in the module.
489
490There can only be one client active in a module at a time. The thunk stores the client's current module and trusted/untrusted
491state. Nexus modules can retrieve the current heap. Modules should never assume they can use g_pCoreHandles->heap[0] as a default.
492**/
493void NEXUS_Module_SetCurrentClient(NEXUS_ModuleHandle module, NEXUS_HeapHandle heap, bool untrusted);
494NEXUS_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.
500This 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/**
504Summary:
505Settings for Nexus Callback.
506
507Description:
508
509See Also:
510NEXUS_TaskCallback_Create
511**/
512typedef struct NEXUS_CallbackSettings  {
513    NEXUS_ModulePriority priority;
514} NEXUS_CallbackSettings;
515
516/**
517Summary:
518Get default settings for the structure.
519
520Description:
521This is required in order to make application code resilient to the addition of new strucutre members in the future.
522
523See Also:
524NEXUS_TaskCallback_Create
525**/
526void NEXUS_Callback_GetDefaultSettings(
527    NEXUS_CallbackSettings *pSettings /* [out] */
528);
529
530/**
531Summary:
532IsrCallback handle obtained from NEXUS_IsrCallback_Create.
533
534Description:
535IsrCallback functions are used to help with firing task level callback from the interrupt context.
536To fire task callback from the interrupt context, calls NEXUS_IsrCallback_Create function to
537preallocation single NEXUS_IsrCallbackHandle for each NEXUS_CallbackDesc, then user uses
538NEXUS_IsrCallback_Fire function in order to fire callback.
539
540See Also:
541NEXUS_IsrCallback_Create
542**/
543typedef struct NEXUS_IsrCallback *NEXUS_IsrCallbackHandle;
544
545/**
546Summary:
547Create an IsrCallback object so that callbacks can be invoked from an ISR function.
548
549Description:
550NEXUS_MODULE_SELF must be defined to be a reference to the NEXUS_ModuleHandle for the current module.
551
552See Also:
553NEXUS_IsrCallback_Destroy
554**/
555#define NEXUS_IsrCallback_Create(handler, settings) NEXUS_Module_IsrCallback_Create(NEXUS_MODULE_SELF,(handler), (settings), __FILE__,__LINE__)
556
557/**
558Summary:
559Destroy the IsrCallback object.
560
561Description:
562NEXUS_MODULE_SELF must be defined to be a reference to the NEXUS_ModuleHandle for the current module.
563
564See Also:
565NEXUS_IsrCallback_Create
566**/
567#define NEXUS_IsrCallback_Destroy(callback) NEXUS_Module_IsrCallback_Destroy(NEXUS_MODULE_SELF,(callback))
568
569/**
570Summary:
571Set the callback function for this IsrCallback instance.
572
573Description:
574
575See Also:
576NEXUS_IsrCallback_Create
577**/
578#define NEXUS_IsrCallback_Set(callback, pDesc) NEXUS_Module_IsrCallback_Set((callback), (pDesc))
579
580/**
581Summary:
582Fire the current callback from an ISR function.
583
584Description:
585NEXUS_MODULE_SELF must be defined to be a reference to the NEXUS_ModuleHandle for the current module.
586
587See Also:
588NEXUS_IsrCallback_Set
589**/
590#define NEXUS_IsrCallback_Fire_isr(callback) NEXUS_Module_IsrCallback_Fire_isr(NEXUS_MODULE_SELF, (callback))
591
592/**
593Summary:
594Actual function called by NEXUS_IsrCallback_Create.
595
596Description:
597
598See Also:
599NEXUS_IsrCallback_Create
600**/
601NEXUS_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/**
610Summary:
611Actual function called by NEXUS_IsrCallback_Destroy.
612
613Description:
614
615See Also:
616NEXUS_IsrCallback_Destroy
617**/
618void NEXUS_Module_IsrCallback_Destroy(
619        NEXUS_ModuleHandle module,
620        NEXUS_IsrCallbackHandle callback
621        );
622
623/**
624Summary:
625Actual function called by NEXUS_IsrCallback_Set.
626
627Description:
628
629See Also:
630NEXUS_IsrCallback_Set
631**/
632void NEXUS_Module_IsrCallback_Set(
633        NEXUS_IsrCallbackHandle callback,
634        const NEXUS_CallbackDesc *pDesc
635        );
636
637/**
638Summary:
639Actual function called by NEXUS_IsrCallback_Fire_isr.
640
641Description:
642
643See Also:
644NEXUS_IsrCallback_Fire_isr
645**/
646void NEXUS_Module_IsrCallback_Fire_isr(
647    NEXUS_ModuleHandle module,
648    NEXUS_IsrCallbackHandle callback /* preallocated IsrCallback */
649    );
650
651
652/**
653Summary:
654IsrCallback handle obtained from NEXUS_IsrCallback_Create.
655
656Description:
657IsrCallback functions are used to fire task level callback from the task context.
658To fire task callback from the tasj context, call NEXUS_TaskCallback_Create function to
659preallocation single NEXUS_TaskCallbackHandle for each NEXUS_CallbackDesc, then user uses
660NEXUS_TaskCallback_Fire function in order to fire callback.
661
662See Also:
663NEXUS_IsrCallback_Create
664**/
665typedef struct NEXUS_TaskCallback *NEXUS_TaskCallbackHandle;
666
667/**
668Summary:
669Create an TaskCallback object so that callbacks can be invoked from the task context
670
671Description:
672NEXUS_MODULE_SELF must be defined to be a reference to the NEXUS_ModuleHandle for the current module.
673
674See Also:
675NEXUS_TaskCallback_Destroy
676**/
677#define NEXUS_TaskCallback_Create(handler, settings) NEXUS_Module_TaskCallback_Create(NEXUS_MODULE_SELF,(handler),(settings),__FILE__,__LINE__)
678
679/**
680Summary:
681Destroy the TaskCallback object.
682
683Description:
684NEXUS_MODULE_SELF must be defined to be a reference to the NEXUS_ModuleHandle for the current module.
685
686See Also:
687NEXUS_TaskCallback_Create
688**/
689#define NEXUS_TaskCallback_Destroy(callback) NEXUS_Module_TaskCallback_Destroy(NEXUS_MODULE_SELF,(callback))
690
691/**
692Summary:
693Set the callback function for this TaskCallback instance.
694
695Description:
696
697See Also:
698NEXUS_TaskCallback_Create
699**/
700#define NEXUS_TaskCallback_Set(callback, pDesc) NEXUS_Module_TaskCallback_Set((callback), (pDesc))
701
702/**
703Summary:
704Fire the current callback.
705
706Description:
707NEXUS_MODULE_SELF must be defined to be a reference to the NEXUS_ModuleHandle for the current module.
708
709See Also:
710NEXUS_TaskCallback_Set
711**/
712#define NEXUS_TaskCallback_Fire(callback) NEXUS_Module_TaskCallback_Fire(NEXUS_MODULE_SELF, (callback))
713
714/**
715Summary:
716Actual function called by NEXUS_TaskCallback_Create.
717
718Description:
719
720See Also:
721NEXUS_TaskCallback_Create
722**/
723NEXUS_TaskCallbackHandle
724NEXUS_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/**
733Summary:
734Actual function called by NEXUS_TaskCallback_Set.
735
736Description:
737
738See Also:
739NEXUS_TaskCallback_Set
740**/
741void NEXUS_Module_TaskCallback_Set(
742        NEXUS_TaskCallbackHandle handle,
743        const NEXUS_CallbackDesc *pDesc
744        );
745
746/**
747Summary:
748Actual function called by NEXUS_TaskCallback_Destroy.
749
750Description:
751
752See Also:
753NEXUS_TaskCallback_Destroy
754**/
755void NEXUS_Module_TaskCallback_Destroy(
756        NEXUS_ModuleHandle module,
757        NEXUS_TaskCallbackHandle callback
758        );
759
760/**
761Summary:
762Actual function called by NEXUS_TaskCallback_Fire.
763
764Description:
765
766See Also:
767NEXUS_TaskCallback_Fire
768**/
769void NEXUS_Module_TaskCallback_Fire(
770        NEXUS_ModuleHandle module,
771        NEXUS_TaskCallbackHandle callback
772        );
773
774
775/**
776Summary:
777Request that a module's function is called whenever an event is set.
778
779Description:
780Base will lock the module before calling the callback.
781NEXUS_MODULE_SELF must be defined to be a reference to the NEXUS_ModuleHandle for the current module.
782The event is a BKNI_EventHandle. Events are set with BKNI_SetEvent.
783If set an event is set multiple times in rapid succession, you may only receive one callback.
784
785See Also:
786NEXUS_UnregisterEvent
787NEXUS_Module_RegisterEvent
788**/
789#define NEXUS_RegisterEvent(event, callback, context) \
790    NEXUS_Module_RegisterEvent(NEXUS_MODULE_SELF, event, callback, context, __FILE__, __LINE__)
791
792/**
793Summary:
794Unregister the callback set up by NEXUS_RegisterEvent
795
796Description:
797NEXUS_MODULE_SELF must be defined to be a reference to the NEXUS_ModuleHandle for the current module.
798
799See Also:
800NEXUS_RegisterEvent
801NEXUS_Module_UnregisterEvent
802**/
803#define NEXUS_UnregisterEvent(event) \
804    NEXUS_Module_UnregisterEvent(NEXUS_MODULE_SELF, event, __FILE__, __LINE__)
805
806
807/**
808Summary:
809Initialize NEXUS_CallbackDesc structure
810
811Description:
812This is required in order to make application code resilient to the addition of new strucutre members in the future.
813**/
814void NEXUS_CallbackDesc_Init(
815    NEXUS_CallbackDesc *desc /* [out] */
816    );
817
818/**
819Summary:
820Handle obtained from NEXUS_RegisterEvent
821
822Description:
823
824See Also:
825NEXUS_RegisterEvent
826**/
827typedef struct NEXUS_EventCallback *NEXUS_EventCallbackHandle;
828
829/**
830Summary:
831Actual function called by NEXUS_RegisterEvent macro.
832
833Description:
834
835See Also:
836NEXUS_RegisterEvent
837**/
838NEXUS_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/**
848Summary:
849Actual function called by NEXUS_UnregisterEvent macro.
850
851Description:
852
853See Also:
854NEXUS_UnregisterEvent
855**/
856void 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/**
864Summary:
865Handle for a timer.
866
867Description:
868
869See Also:
870NEXUS_ScheduleTimer
871**/
872typedef struct NEXUS_Timer *NEXUS_TimerHandle;
873
874/**
875Summary:
876Schedule a callback after an elapsed time.
877
878Description:
879Base will lock the module before calling the callback function.
880Timers are one-shot and are self-cancelling. If you want a recurring timer, you should call NEXUS_ScheduleTimer from inside your time callback.
881
882See Also:
883NEXUS_CancelTimer
884**/
885#define NEXUS_ScheduleTimer(delayMs, callback, context) \
886    NEXUS_Module_ScheduleTimer(NEXUS_MODULE_SELF, delayMs, callback, context, __FILE__, __LINE__)
887
888/**
889Summary:
890Cancel a timer.
891
892Description:
893
894See Also:
895NEXUS_ScheduleTimer
896**/
897#define NEXUS_CancelTimer(timer) \
898    NEXUS_Module_CancelTimer(NEXUS_MODULE_SELF, timer, __FILE__, __LINE__)
899
900/**
901Summary:
902Actual function called by NEXUS_ScheduleTimer macro.
903
904Description:
905
906See Also:
907NEXUS_ScheduleTimer
908**/
909NEXUS_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/**
919Summary:
920Actual function called by NEXUS_CancelTimer macro.
921
922Description:
923
924See Also:
925NEXUS_CancelTimer
926**/
927void 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/**
935Summary:
936ISR variant of NEXUS_FlushCache
937
938Description:
939
940See Also:
941NEXUS_FlushCache
942**/
943#define NEXUS_FlushCache_isr NEXUS_FlushCache
944
945/**
946Summary:
947Stop all callbacks associated with this interface handle.
948Wait for any running callbacks to finish, and ensure that no other callbacks for this handle are fired.
949**/
950void NEXUS_Base_P_StopCallbacks(
951        void *interfaceHandle
952        );
953
954/**
955Summary:
956Re-enable all callbacks for this interface handle.
957All interfaces default to being already started.
958If you call StopCallbacks followed by StartCallbacks, no pending callbacks will be lost. <<maybe>>
959**/
960void NEXUS_Base_P_StartCallbacks(
961        void *interfaceHandle
962        );
963
964#include "nexus_base_os_types.h"
965
966/**
967Summary:
968Returns the current timestamp
969**/
970void NEXUS_Time_Get(
971    NEXUS_Time *time
972    );
973
974/**
975Summary:
976Returns difference in milliseconds between two timestamps obtained with b_time_get.
977
978Description:
979It's recomended that code would use this function in a way that it could return
980only positive values (where applicable, it helps in handling wraparound conditions)
981**/
982long NEXUS_Time_Diff(
983    const NEXUS_Time *future,
984    const NEXUS_Time *past
985    );
986
987/**
988Summary:
989Adds delta in milliseconds to the timestamp
990**/
991void NEXUS_Time_Add(
992    NEXUS_Time *time,
993    long delta_ms /* milliseconds */
994    );
995
996/**
997Summary:
998Give address mapping data for a block of memory to allow address/offset conversion using functions in nexus_base_mmap.h.
999
1000Description:
1001Multiple calls to NEXUS_P_AddMap can be made to specify a set of memory blocks.
1002
1003See Also: NEXUS_AddrToOffset NEXUS_OffsetToCachedAddr NEXUS_OffsetToUncachedAddr
1004**/
1005NEXUS_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/**
1013Summary:
1014In both arguments are not NULL, then works the same as standard strcmp.
1015Otherwise returns 0 if both str1 and str2 are NULL and returns not 0 if only one argument is NULL.
1016**/
1017int NEXUS_StrCmp(
1018        const char *str1, 
1019        const char *str2
1020        );
1021
1022/**
1023Summary:
1024Returns size of the structure or union member
1025**/
1026#define NEXUS_SIZEOF(type, field) sizeof(((type *)0)->field)
1027
1028/**
1029Summary:
1030Returns 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/**
1036Summary:
1037Validates 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/**
1042Summary:
1043Validates that size of two structure is identical
1044**/
1045#define NEXUS_ASSERT_STRUCTURE(type1, type2) BDBG_CASSERT(sizeof(type1)==sizeof(type2))
1046
1047/**
1048Summary:
1049    Synchronized callback handler.
1050
1051Description:
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
1055See Also:
1056NEXUS_CallbackHandler_Init
1057NEXUS_CallbackHandler_Shutdown
1058NEXUS_CallbackHandler_PrepareCallback
1059NEXUS_CallbackHandler_SetGuard
1060 **/
1061typedef struct NEXUS_CallbackHandler NEXUS_CallbackHandler;
1062
1063/**
1064Summary:
1065Initializes callback handler
1066
1067Description:
1068Initializes callback handler with callbadk and context passed to the callback function.
1069Base will lock the module before calling the callback function.
1070
1071NEXUS_CallbackHandler_Init should be called once and only once, prior to any other refference to the callback handler.
1072
1073See Also:
1074NEXUS_CallbackHandler_Shutdown
1075NEXUS_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/**
1080Summary:
1081Releases resources assiciated with the callback handler
1082
1083Description:
1084
1085See Also:
1086NEXUS_CallbackHandler_Init
1087**/
1088#define NEXUS_CallbackHandler_Shutdown(h) NEXUS_Base_P_CallbackHandler_Shutdown(&(h))
1089
1090/**
1091Summary:
1092Links NEXUS_CallbackDesc with NEXUS_CallbackHandler
1093
1094Description:
1095Initializes 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
1097See Also:
1098NEXUS_CallbackHandler_Init
1099NEXUS_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/**
1106Summary:
1107Stops deffered callbacks
1108
1109Description:
1110
1111See Also:
1112NEXUS_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/**
1119Summary:
1120Sets guard function
1121
1122Description:
1123Guear 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
1125functions.
1126
1127See Also:
1128NEXUS_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 */
1135void NEXUS_Base_P_CallbackHandler_Init(NEXUS_CallbackHandler *handler, NEXUS_ModuleHandle module, void (*pCallback)(void *), void *pContext,const char *pFileName,unsigned lineNumber);
1136void NEXUS_Base_P_CallbackHandler_Dispatch(void *context, int arg);
1137void NEXUS_Base_P_CallbackHandler_Stop(NEXUS_CallbackHandler *handler);
1138void NEXUS_Base_P_CallbackHandler_Shutdown(NEXUS_CallbackHandler *handler);
1139
1140BDBG_OBJECT_ID_DECLARE(NEXUS_CallbackHandler); 
1141
1142struct 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/**
1155nexus/base exposes an external scheduler interface used in linux kernel mode and in the proxy.
1156See nexus/platform/PLATFORM/src/linuxkernel/nexus_driver_callbacks.c for linux kernel mode usage.
1157See 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
1162NEXUS_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
1170typedef 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
1176void NEXUS_P_Base_GetSchedulerConfig(
1177    NEXUS_ModulePriority priority,
1178    NEXUS_Base_Scheduler_Config *config /* [out] */
1179    );
1180
1181typedef 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/**
1187Summary:
1188Datatype embedded into the objects that support reference counting
1189
1190See Also:
1191NEXUS_REFCNT_INIT
1192**/
1193
1194typedef struct NEXUS_RefCnt {
1195    int ref_cnt;
1196    const NEXUS_RefCntDescriptor *descriptor;
1197} NEXUS_RefCnt;
1198
1199
1200void NEXUS_RefCntObj_P_Init(NEXUS_RefCnt *cnt, const NEXUS_RefCntDescriptor *descriptor);
1201void NEXUS_RefCntObj_P_Acquire_Tagged(void *object, const NEXUS_RefCntDescriptor *descriptor, NEXUS_ModuleHandle module, const char *pFileName, unsigned lineNumber);
1202void NEXUS_RefCntObj_P_Release_Tagged(void *object, const NEXUS_RefCntDescriptor *descriptor, NEXUS_ModuleHandle module, const char *pFileName, unsigned lineNumber);
1203
1204/**
1205Summary:
1206Declares functions that are part of implementation for object reference counting.
1207
1208Description:
1209NEXUS_REFCNT_CLASS_DECLARE should be placed into the header file inside the modules 'priv' directory.
1210
1211See Also:
1212NEXUS_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/**
1220Summary:
1221Defines functions and data that are part of implementation for object reference counting.
1222
1223Description:
1224NEXUS_REFCNT_CLASS_MAKE should be placed into C file that is a part of modules implementation
1225
1226See Also:
1227NEXUS_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/**
1238Summary:
1239This macro should be used to initialize reference counted object
1240
1241Description:
1242When intializes reference counter is set to 1, and used of NEXUS_REFCNT_RELEASE would cause call to the object finalizer (private destructor).
1243To properly support reference counting, public destructor/close API should be reduced just to call into the NEXUS_REFCNT_RELEASE,
1244and proper destructor (private destructor) should be linked by means of NEXUS_REFCNT_CLASS_MAKE.
1245
1246See Also:
1247NEXUS_REFCNT_ACQUIRE
1248NEXUS_REFCNT_RELEASE
1249**/
1250#define NEXUS_REFCNT_INIT(type, cnt) NEXUS_RefCntObj_P_Init(cnt,  &type##_RefCnt_Descriptor)
1251
1252/**
1253Summary:
1254This macro is used to inform that object of said type is used and can't be destroyed
1255
1256Description:
1257**/
1258#define NEXUS_REFCNT_ACQUIRE(type,object) type##_RefCnt_P_Acquire_Tagged(object, NEXUS_MODULE_SELF, __FILE__, __LINE__)
1259
1260/**
1261Summary:
1262This macro is used to inform that object of said type is unused and can be safely destroyed
1263
1264Description:
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
Note: See TracBrowser for help on using the repository browser.