module ti.sysbios.heaps.HeapCallback

A heap that calls user supplied callback functions

The HeapCallback module enables users to provide a custom heap implementation by providing callback functions that will be invoked by HeapCallback for the various heap management functions. [ more ... ]
C synopsis target-domain sourced in ti/sysbios/heaps/HeapCallback.xdc
#include <ti/sysbios/heaps/HeapCallback.h>
Functions
Void
Void
Void
UArg 
Void
Functions common to all IHeap modules
Ptr 
Void 
Void 
Bool 
Functions common to all target instances
Functions common to all target modules
Typedefs
typedef Ptr 
typedef UArg 
typedef Void 
typedef Void 
typedef Void 
typedef UArg 
typedef Bool 
typedef struct
typedef struct
typedef struct
Constants
 
DETAILS
The HeapCallback module enables users to provide a custom heap implementation by providing callback functions that will be invoked by HeapCallback for the various heap management functions.
The user-supplied HeapCallback.initInstFxn is called during boot time to initialize any HeapCallback objects that were created in the .cfg file. The user-supplied HeapCallback.createInstFxn is called during runtime for any calls to HeapCallback_create(). Both of these functions return a context value (typically a pointer to an object managed by the user-supplied heap code). This context value is passed to subsequent user allocInstFxn, freeInstFxn, etc. functions.
HeapCallback_alloc(), HeapCallback_free() and HeapCallback_getStats() call the user-supplied allocInstFxn, freeInstFxn and getStatsInstFxn functions with the context value returned by initInstFxn or createInstFxn.
HeapCallback_delete() calls the user-supplied instDeleteFxn with the context returned by the createInstFxn.
EXAMPLES
Configuration example: The following XDC configuration statements creates a HeapCallback instance and plugs in the user defined functions.
  var HeapCallback = xdc.useModule('ti.sysbios.heaps.HeapCallback');

  var params = new HeapCallback.Params();
  params.arg = 1;
  HeapCallback.create(params);

  HeapCallback.initInstFxn = '&userInitFxn';
  HeapCallback.createInstFxn = '&userCreateFxn';
  HeapCallback.deleteInstFxn = '&userDeleteFxn';
  HeapCallback.allocInstFxn = '&userAllocFxn';
  HeapCallback.freeInstFxn = '&userFreeFxn';
  HeapCallback.getStatsInstFxn = '&userGetStatsFxn';
  HeapCallback.isBlockingInstFxn = '&userIsBlockingFxn';

 
typedef HeapCallback_AllocInstFxn

Instance alloc callback function signature

C synopsis target-domain
typedef Ptr (*HeapCallback_AllocInstFxn)(UArg,SizeT,SizeT);
 
DETAILS
This function takes the context return from createInstFxn(), the size to be allocated and the align value. The return value from this function is a pointer to the allocated memory block.
 
typedef HeapCallback_CreateInstFxn

Instance create callback function signature

C synopsis target-domain
typedef UArg (*HeapCallback_CreateInstFxn)(UArg);
 
DETAILS
HeapCallback.arg is passed as an argument to this function. The return value from this function (context) will be passed as an argument to the other instance functions.
 
typedef HeapCallback_DeleteInstFxn

Instance delete callback function signature

C synopsis target-domain
typedef Void (*HeapCallback_DeleteInstFxn)(UArg);
 
DETAILS
The context returned from createInstFxn() is passed as an argument to this function.
 
typedef HeapCallback_FreeInstFxn

Instance free callback function signature

C synopsis target-domain
typedef Void (*HeapCallback_FreeInstFxn)(UArg,Ptr,SizeT);
 
DETAILS
This function takes the context returned by createInstFxn() and a pointer to the buffer to be freed and the size to be freed.
 
typedef HeapCallback_GetStatsInstFxn

Instance getStats callback function signature

C synopsis target-domain
typedef Void (*HeapCallback_GetStatsInstFxn)(UArg,Memory_Stats*);
 
DETAILS
This function takes the context returned by createInstFxn() and a pointer to a memory stats object.
 
typedef HeapCallback_InitInstFxn

Instance init callback function signature

C synopsis target-domain
typedef UArg (*HeapCallback_InitInstFxn)(UArg);
 
DETAILS
`HeapCallback.arg is passed as an argument to this function. The return value from this function (context) will passed as an argument to the other instance functions.
 
typedef HeapCallback_IsBlockingInstFxn

Instance isblocking callback function signature

C synopsis target-domain
typedef Bool (*HeapCallback_IsBlockingInstFxn)(UArg);
 
DETAILS
The context return from createInstFxn() is passed as an argument to this function. The return value is 'TRUE' or 'FALSE'.
 
config HeapCallback_allocInstFxn  // module-wide

User supplied instance alloc function

C synopsis target-domain
extern const HeapCallback_AllocInstFxn HeapCallback_allocInstFxn;
 
DETAILS
This function is called when the HeapCallback.alloc is called.
This parameter is configured with a default alloc function. The default alloc function returns NULL.
 
config HeapCallback_createInstFxn  // module-wide

User supplied instance create function

C synopsis target-domain
extern const HeapCallback_CreateInstFxn HeapCallback_createInstFxn;
 
DETAILS
This function is called when the HeapCallback.create is called.
This parameter is configured with a default create function. The default create function returns 0.
 
config HeapCallback_deleteInstFxn  // module-wide

User supplied instance delete function

C synopsis target-domain
extern const HeapCallback_DeleteInstFxn HeapCallback_deleteInstFxn;
 
DETAILS
This function is called when the HeapCallback.delete is called.
This parameter is configured with a default delete function.
 
config HeapCallback_freeInstFxn  // module-wide

User supplied instance free function

C synopsis target-domain
extern const HeapCallback_FreeInstFxn HeapCallback_freeInstFxn;
 
DETAILS
This function is called when the HeapCallback.free is called.
This parameter is configured with a default free function.
 
config HeapCallback_getStatsInstFxn  // module-wide

User supplied getStat function

C synopsis target-domain
extern const HeapCallback_GetStatsInstFxn HeapCallback_getStatsInstFxn;
 
DETAILS
This function is called when the HeapCallback.getStat is called.
This parameter is configured with a default getStats function. The default getStats function does not make any changes to stats structure.
 
config HeapCallback_initInstFxn  // module-wide

User supplied init function

C synopsis target-domain
extern const HeapCallback_InitInstFxn HeapCallback_initInstFxn;
 
DETAILS
This function is called in Module startup for statically created instances. The user-supplied function must not do any memory allocations or call any module create functions (e.g., Semaphore_create()).
This parameter is configured with a default init function. The default init function returns NULL.
 
config HeapCallback_isBlockingInstFxn  // module-wide

User supplied isBlocking function

C synopsis target-domain
extern const HeapCallback_IsBlockingInstFxn HeapCallback_isBlockingInstFxn;
 
DETAILS
This function is called when the HeapCallback.isBlocking is called.
This parameter is configured with a default isBlocking function. The default isBlocking returns FALSE.
Module-Wide Built-Ins

C synopsis target-domain
Types_ModuleId HeapCallback_Module_id();
// Get this module's unique id
 
Bool HeapCallback_Module_startupDone();
// Test if this module has completed startup
 
IHeap_Handle HeapCallback_Module_heap();
// The heap from which this module allocates memory
 
Bool HeapCallback_Module_hasMask();
// Test whether this module has a diagnostics mask
 
Bits16 HeapCallback_Module_getMask();
// Returns the diagnostics mask for this module
 
Void HeapCallback_Module_setMask(Bits16 mask);
// Set the diagnostics mask for this module
Instance Object Types

C synopsis target-domain
typedef struct HeapCallback_Object HeapCallback_Object;
// Opaque internal representation of an instance object
 
typedef HeapCallback_Object *HeapCallback_Handle;
// Client reference to an instance object
 
typedef struct HeapCallback_Struct HeapCallback_Struct;
// Opaque client structure large enough to hold an instance object
 
HeapCallback_Handle HeapCallback_handle(HeapCallback_Struct *structP);
// Convert this instance structure pointer into an instance handle
 
HeapCallback_Struct *HeapCallback_struct(HeapCallback_Handle handle);
// Convert this instance handle into an instance structure pointer
Instance Config Parameters

C synopsis target-domain
typedef struct HeapCallback_Params {
// Instance config-params structure
    IInstance_Params *instance;
    // Common per-instance configs
    UArg arg;
    // User supplied argument for the user supplied create function
} HeapCallback_Params;
 
Void HeapCallback_Params_init(HeapCallback_Params *params);
// Initialize this config-params structure with supplier-specified defaults before instance creation
 
config HeapCallback_Params.arg  // instance

User supplied argument for the user supplied create function

C synopsis target-domain
      ...
    UArg arg;
 
DETAILS
This user supplied argument will be passed back as an argument to the createInstFxn function. It can be used by the HeapCallback.createInstFxn function at runtime to differentiate between the multiple Heap instances configured in the user config script.
The user can skip configuring this argument. In such a case, the default value 0 will be passed back as an argument to the createInstFxn function.
Runtime Instance Creation

C synopsis target-domain
HeapCallback_Handle HeapCallback_create(const HeapCallback_Params *params, Error_Block *eb);
// Allocate and initialize a new instance object and return its handle
 
Void HeapCallback_construct(HeapCallback_Struct *structP, const HeapCallback_Params *params);
// Initialize a new instance object inside the provided structure
ARGUMENTS
params — per-instance config params, or NULL to select default values (target-domain only)
eb — active error-handling block, or NULL to select default policy (target-domain only)
Instance Deletion

C synopsis target-domain
Void HeapCallback_delete(HeapCallback_Handle *handleP);
// Finalize and free this previously allocated instance object, setting the referenced handle to NULL
 
Void HeapCallback_destruct(HeapCallback_Struct *structP);
// Finalize the instance object inside the provided structure
 
HeapCallback_alloc()  // instance

Allocates a block of memory from the heap

C synopsis target-domain
Ptr HeapCallback_alloc(HeapCallback_Handle handle, SizeT size, SizeT align, Error_Block *eb);
 
ARGUMENTS
handle — handle of a previously-created HeapCallback instance object
size — size (in MADUs) of the block
align — alignment (in MADUs) of the block
eb — pointer to error block
DETAILS
This method returns a block of memory from the heap. It is called by the xdc.runtime.Memory.alloc() function.
RETURNS
Returns the address of the allocated memory.
 
HeapCallback_free()  // instance

Free a block of memory back to the heap

C synopsis target-domain
Void HeapCallback_free(HeapCallback_Handle handle, Ptr block, SizeT size);
 
ARGUMENTS
handle — handle of a previously-created HeapCallback instance object
block — non-NULL address of allocated block to free
size — size (in MADUs) of the block of memory to free
DETAILS
This method gives back a block of memory to a heap. It is called by the xdc.runtime.Memory.free() function.
 
HeapCallback_getContext()  // instance

Get the context returned from user supplied create function

C synopsis target-domain
UArg HeapCallback_getContext(HeapCallback_Handle handle);
 
ARGUMENTS
handle — handle of a previously-created HeapCallback instance object
 
HeapCallback_getStats()  // instance

Retrieve the statistics from the heap

C synopsis target-domain
Void HeapCallback_getStats(HeapCallback_Handle handle, Memory_Stats *stats);
 
ARGUMENTS
handle — handle of a previously-created HeapCallback instance object
stats — non-NULL pointer to an output buffer
DETAILS
The caller passes in a pointer to a xdc.runtime.Memory.Stats structure and getStats fills in this structure.
This function is called by the xdc.runtime.Memory.getStats() function.
 
HeapCallback_isBlocking()  // instance

Returns whether the heap may block during an alloc() or free()

C synopsis target-domain
Bool HeapCallback_isBlocking(HeapCallback_Handle handle);
 
ARGUMENTS
handle — handle of a previously-created HeapCallback instance object
RETURNS
If the heap might block, TRUE is returned. If the heap does not block, FALSE is returned.
Instance Convertors

C synopsis target-domain
IHeap_Handle HeapCallback_Handle_upCast(HeapCallback_Handle handle);
// unconditionally move one level up the inheritance hierarchy
 
HeapCallback_Handle HeapCallback_Handle_downCast(IHeap_Handle handle);
// conditionally move one level down the inheritance hierarchy; NULL upon failure
Instance Built-Ins

C synopsis target-domain
Int HeapCallback_Object_count();
// The number of statically-created instance objects
 
HeapCallback_Handle HeapCallback_Object_get(HeapCallback_Object *array, Int i);
// The handle of the i-th statically-created instance object (array == NULL)
 
HeapCallback_Handle HeapCallback_Object_first();
// The handle of the first dynamically-created instance object, or NULL
 
HeapCallback_Handle HeapCallback_Object_next(HeapCallback_Handle handle);
// The handle of the next dynamically-created instance object, or NULL
 
IHeap_Handle HeapCallback_Object_heap();
// The heap used to allocate dynamically-created instance objects
 
Types_Label *HeapCallback_Handle_label(HeapCallback_Handle handle, Types_Label *buf);
// The label associated with this instance object
 
String HeapCallback_Handle_name(HeapCallback_Handle handle);
// The name of this instance object
 
Configuration settings sourced in ti/sysbios/heaps/HeapCallback.xdc
var HeapCallback = xdc.useModule('ti.sysbios.heaps.HeapCallback');
module-wide config parameters
    HeapCallback.allocInstFxn// User supplied instance alloc function = Ptr(*)(UArg,SizeT,SizeT) '&ti_sysbios_heaps_HeapCallback_defaultAlloc';
    HeapCallback.createInstFxn// User supplied instance create function = UArg(*)(UArg) '&ti_sysbios_heaps_HeapCallback_defaultCreate';
    HeapCallback.deleteInstFxn// User supplied instance delete function = Void(*)(UArg) '&ti_sysbios_heaps_HeapCallback_defaultDelete';
    HeapCallback.freeInstFxn// User supplied instance free function = Void(*)(UArg,Ptr,SizeT) '&ti_sysbios_heaps_HeapCallback_defaultFree';
    HeapCallback.getStatsInstFxn// User supplied getStat function = Void(*)(UArg,Memory.Stats*) '&ti_sysbios_heaps_HeapCallback_defaultGetStats';
    HeapCallback.initInstFxn// User supplied init function = UArg(*)(UArg) '&ti_sysbios_heaps_HeapCallback_defaultInit';
    HeapCallback.isBlockingInstFxn// User supplied isBlocking function = Bool(*)(UArg) '&ti_sysbios_heaps_HeapCallback_defaultIsBlocking';
 
per-instance config parameters
    var params = new HeapCallback.Params// Instance config-params object;
per-instance creation
    var inst = HeapCallback.create// Create an instance-object(params);
 
 
config HeapCallback.allocInstFxn  // module-wide

User supplied instance alloc function

Configuration settings
HeapCallback.allocInstFxn = Ptr(*)(UArg,SizeT,SizeT) '&ti_sysbios_heaps_HeapCallback_defaultAlloc';
 
DETAILS
This function is called when the HeapCallback.alloc is called.
This parameter is configured with a default alloc function. The default alloc function returns NULL.
C SYNOPSIS
 
config HeapCallback.createInstFxn  // module-wide

User supplied instance create function

Configuration settings
HeapCallback.createInstFxn = UArg(*)(UArg) '&ti_sysbios_heaps_HeapCallback_defaultCreate';
 
DETAILS
This function is called when the HeapCallback.create is called.
This parameter is configured with a default create function. The default create function returns 0.
C SYNOPSIS
 
config HeapCallback.deleteInstFxn  // module-wide

User supplied instance delete function

Configuration settings
HeapCallback.deleteInstFxn = Void(*)(UArg) '&ti_sysbios_heaps_HeapCallback_defaultDelete';
 
DETAILS
This function is called when the HeapCallback.delete is called.
This parameter is configured with a default delete function.
C SYNOPSIS
 
config HeapCallback.freeInstFxn  // module-wide

User supplied instance free function

Configuration settings
HeapCallback.freeInstFxn = Void(*)(UArg,Ptr,SizeT) '&ti_sysbios_heaps_HeapCallback_defaultFree';
 
DETAILS
This function is called when the HeapCallback.free is called.
This parameter is configured with a default free function.
C SYNOPSIS
 
config HeapCallback.getStatsInstFxn  // module-wide

User supplied getStat function

Configuration settings
HeapCallback.getStatsInstFxn = Void(*)(UArg,Memory.Stats*) '&ti_sysbios_heaps_HeapCallback_defaultGetStats';
 
DETAILS
This function is called when the HeapCallback.getStat is called.
This parameter is configured with a default getStats function. The default getStats function does not make any changes to stats structure.
C SYNOPSIS
 
config HeapCallback.initInstFxn  // module-wide

User supplied init function

Configuration settings
HeapCallback.initInstFxn = UArg(*)(UArg) '&ti_sysbios_heaps_HeapCallback_defaultInit';
 
DETAILS
This function is called in Module startup for statically created instances. The user-supplied function must not do any memory allocations or call any module create functions (e.g., Semaphore_create()).
This parameter is configured with a default init function. The default init function returns NULL.
C SYNOPSIS
 
config HeapCallback.isBlockingInstFxn  // module-wide

User supplied isBlocking function

Configuration settings
HeapCallback.isBlockingInstFxn = Bool(*)(UArg) '&ti_sysbios_heaps_HeapCallback_defaultIsBlocking';
 
DETAILS
This function is called when the HeapCallback.isBlocking is called.
This parameter is configured with a default isBlocking function. The default isBlocking returns FALSE.
C SYNOPSIS
 
metaonly config HeapCallback.common$  // module-wide

Common module configuration parameters

Configuration settings
HeapCallback.common$ = Types.Common$ undefined;
 
DETAILS
All modules have this configuration parameter. Its name contains the '$' character to ensure it does not conflict with configuration parameters declared by the module. This allows new configuration parameters to be added in the future without any chance of breaking existing modules.
Instance Config Parameters

Configuration settings
var params = new HeapCallback.Params;
// Instance config-params object
    params.arg = UArg 0;
    // User supplied argument for the user supplied create function
 
config HeapCallback.Params.arg  // instance

User supplied argument for the user supplied create function

Configuration settings
var params = new HeapCallback.Params;
  ...
params.arg = UArg 0;
 
DETAILS
This user supplied argument will be passed back as an argument to the createInstFxn function. It can be used by the HeapCallback.createInstFxn function at runtime to differentiate between the multiple Heap instances configured in the user config script.
The user can skip configuring this argument. In such a case, the default value 0 will be passed back as an argument to the createInstFxn function.
C SYNOPSIS
Static Instance Creation

Configuration settings
var params = new HeapCallback.Params;
// Allocate instance config-params
params.config =   ...
// Assign individual configs
 
var inst = HeapCallback.create(params);
// Create an instance-object
ARGUMENTS
params — per-instance config params, or NULL to select default values (target-domain only)
eb — active error-handling block, or NULL to select default policy (target-domain only)
generated on Thu, 23 May 2019 00:22:23 GMT