1.2.6.4.5 SRV_USI_CallbackRegister Function

C

void SRV_USI_CallbackRegister( 
    SRV_USI_HANDLE handle,
    SRV_USI_PROTOCOL_ID protocol, 
    SRV_USI_CALLBACK callback)

Summary

Registers a function to be called back when a new message is received and it belongs to the specified USI protocol.

Description

This function allows a client to register an event handling function to be called back when a new message is received and it belongs to the specified USI protocol.

One USI instance can have different callbacks for different USI protocols.

The callback once set, persists until the client closes the USI service instance or sets another callback (which could be a NULL pointer to indicate no callback).

Precondition

SRV_USI_Open must have been called to obtain a valid opened service handle.

Returns

None.

Example

void APP_USIPhyProtocolEventHandler(uint8_t *pData, size_t length)
{
    /* Message received from external tool */
}

// 'handle', returned from SRV_USI_Open previously called
SRV_USI_CallbackRegister(handle, SRV_USI_PROT_ID_PHY, APP_USIPhyProtocolEventHandler);

Remarks

If the client only needs to send USI messages (not receive them), it does not need to register a callback.

The USI service manages the peripheral interrupts internally, but the registered function is called inside SRV_USI_Tasks, which simplifies the thread safety management at client level.