Skip to content

CObjEBB programming model

jmcddn edited this page Aug 23, 2012 · 4 revisions

COBJ_EBBType(TYPE)

Macro Definition

#define COBJ_EBBType(TYPE)  			
  CObject(TYPE);  				
  typedef TYPE ## Ref *TYPE ## Id;  		
  CObjectDefine(TYPE) {  				
    CObjInterface(TYPE) *ft;  			
  }; 
  CObjInterface(TYPE)  

CObject(NAME)

Description

To define a C Object and the variables contained with, you use the CObject() macro.
Here is the syntax:

CObject( Object_Name ){ int var1; char *var2;}

To setup this CObject as an EBB, you initiate a local and root reference and bind the root reference to an registered EBBid.

EBBPrimMalloc(uintptr_t size, void *mem, EBB_MEM_POOL pool)

To create an instance of the CObject in memory and bind it to a local reference with the EBBPrimMalloc() function, found in /l0/MemMgrPrim.h.

EBBPrimMalloc(sizeof( Object_Name ), &repRef, EBB_MEM_DEFAULT);

Example

CObject(Console)  
{  
  COBJ_EBBFuncTbl(AnEbbType);  
  lrt_pic_src in;  
  lrt_pic_src out;  
  uintptr_t inEvent;  
  uintptr_t outEvent;   
};

CObjEBBBind(Id, Ref)

To make calls to a CObject, you must register it as an EBB by defining it root reference type and binding that reference to established EBBid. The CObjEBBBind() function is used to bind an CObject's root reference and EBBId.

Definition

static inline EBBRC    
CObjEBBBind(EBBId id, void *root){ return EBBBindPrimId(id, CObjEBBMissFunc, (EBBMissArg) root);}

Example

AllocAndBind(EBBId *id, EBBRepRef repRef)
{
  EBBRC rc;
  // define root reference type
  CObjEBBRootSharedRef rootRef;
  rc = CObjEBBRootSharedCreate(&rootRef, repRef);
  // Get a fresh EBBId
  rc = EBBAllocPrimId((EBBId *)id);
  // Bind id and reference
  rc = CObjEBBBind((EBBId)*id, rootRef);
  return EBBRC_OK;
}

CObjInterface(NAME)

CObjInterface macro inserts an named struct used for defining the interface (function tables) of CObjects.

Definition

#define CObjIfName(name) name ## _if
#define CObjInterface(name) struct CObjIfName(name)

CObjInterface(OBJ_NAME) produces the following code: struct OBJ_NAME_if

Example

CObjInterface() can initialize statically:

CObjInterface(CharStream) Console_ftable = {
  .putChar  = Console_putChar,
  .getChar  = Console_getChar,
  .inEvent  = (GenericEventFunc)Console_inEvent,
  .outEvent = (GenericEventFunc)Console_outEvent
};

or, within another object:

CObject(ConsTst) {
  CObjInterface(App) *ft;
};

COBJ_EBBFuncTbl(NAME)

COBJ_EBBFuncTbl is a simple macro for declaring a function table interface.

Definition

#define COBJ_EBBFuncTbl(TYPE) CObjInterface(TYPE) *ft;

Example

COBJ_EBBFuncTbl(OBJ_NAME) produces the following code: struct OBJ_NAME_if *ft;

COBJ_EBBCALL()

TO setup event handeling of an EBB, a few steps are required.

Definition

#define COBJ_EBBCALL(id, method, ...) \  
  (EBBId_DREF(id)->ft->method(EBBId_DREF(id), ##__VA_ARGS__))

Description

First, message the Event Manager to allocate a new event number. rc = COBJ_EBBCALL(theEventMgrPrimId, allocEventNo, &(myRef->myEventNum));

Next, register that event number with a PIC source and a function within your EBBs function table. rc = COBJ_EBBCALL(theEventMgrPrimId, registerHandler, myRef->myEventNum, *MyEBBid, COBJ_FUNCNUM(myRef, myEventFunc), &pic_src);

Finally, enable that event handle as we are ready to roll
rc = COBJ_EBBCALL(theEventMgrPrimId, eventEnable, myRef->myEventNum);

COBJ_FUNCNUM(ref, funcName)

A macro that returns the function number from the reference's function table. #define COBJ_FUNCNUM(ref, funcName) \ ( __builtin_offsetof( typeof(*(ref->ft)), funcName)/sizeof(COBJFunc) )



#TODO:

  • describe pic source setup & binding
  • EVENTFUNC()