1.17.11.8 NVM_CallbackRegister Function

C

void NVM_CallbackRegister( NVM_CALLBACK callback, uintptr_t context )

Summary

Sets the pointer to the function (and it's context) to be called when the operation is complete.

Description

This function sets the pointer to a client function to be called "back" when the NVM has completed an operation and is ready to receive new command. It also passes a context value that is passed into the callback function when it is called. This function is available only when the library is generated with interrupt option (in MHC) enabled.

Precondition

Interrupt option in MHC should have been enabled

Parameters

Param Description
callback A pointer to a function with a calling signature defined by the NVM_CALLBACK data type.
context A value (usually a pointer) passed (unused) into the function identified by the callback parameter.

Returns

None.

Example

typedef struct
{
    bool operationComplete;
    
} APP_DATA;

// Callback is called when an operation completes.
void APP_NVMCallback(uintptr_t context)
{
    APP_DATA * appData = (APP_DATA *)context;
    appData->operationComplete = true;
}

// Function calls in main thread.
APP_DATA myAppData;
myAppData.operationComplete = false;

// Register the callback
NVM_CallbackRegister(APP_NVMCallback, &myAppData);

// Perform some operation.
NVM_PageErase(SOME_PAGE_ALIGNED_ADDRESS);

// Now wait for the operation to complete.
while(!myAppData.operationComplete);

Remarks

The context value may be set to NULL if it is not required. Note that the value of NULL will still be passed to the callback function. To disable the callback function, pass a NULL for the callback parameter. See the NVM_CALLBACK type definition for additional information.