Jump to main content

##

# 2.27.13 DBGU_ReadCallbackRegister Function

## C

    /* Non-blocking mode */

    void DBGU_ReadCallbackRegister( DBGU_CALLBACK callback, uintptr_t context )

    /* Ring buffer mode */

    void DBGU_ReadCallbackRegister( DBGU_RING_BUFFER_CALLBACK callback, uintptr_t context)

## Summary

Sets the pointer to the function (and it's context) to be called when the given DBGU's read events occur.

## Description

This function sets the pointer to a client function to be called "back" when the given DBGU's read events occur. It also passes a context value (usually a pointer to a context structure) that is passed into the function when it is called.

## Precondition

DBGU_Initialize must have been called for the associated DBGU instance.

## Parameters

Param | Description
--- | ---
callback | Pointer to the function that will be called when a read request has completed. Setting this to NULL will disable the callback feature.
context | A value (usually a pointer) passed (unused) into the function identified by the callback parameter.

## Returns

None.

## Example

Non-blocking mode

    void DBGUReadEventHandler ( uintptr_t context )
    {
        if(DBGU_ERROR_NONE != DBGU_ErrorGet())
        {
            //Handle error case
        }
        else
        {
            //Transfer completed successfully
        }
    }

    DBGU_ReadCallbackRegister(DBGUReadEventHandler, (uintptr_t) NULL);

Ring buffer mode

    uint8_t rxBuffer[50];
    uint32_t nBytes;

    void DBGUReadEventHandler(DBGU_EVENT event, uintptr_t context )
    {
        uint32_t nBytesAvailable = 0;

        if (event == DBGU_EVENT_READ_THRESHOLD_REACHED)
        {
            // Receiver should have the thershold number of bytes in the receive buffer
            nBytesAvailable = DBGU_ReadCountGet();

            nBytesRead += DBGU_Read((uint8_t*)&rxBuffer[nBytesRead], nBytesAvailable);
        }
    }

    //----------------------------------------------------------//

    // Register a callback for read events
    DBGU_ReadCallbackRegister(DBGUReadEventHandler, (uintptr_t) NULL);

    // Set a threshold value to receive a callback after every 10 characters are received
    DBGU_ReadThresholdSet(10);

    // Enable RX event notifications
    DBGU_ReadNotificationEnable(true, false);

## Remarks

None