cancel
Showing results for 
Search instead for 
Did you mean: 

Smart Bluetooth

Anonymous
Not applicable

Is there a way to setup a vendor designed asynchronous event?

For example, if the application receives data from the peripheral uart from a sensor and I just want to queue the data but send an event within the application to notify another callback to parse this data ... is there a built in mechanism or function to register for this type of event or interrupt?

For instance something similar to the Timer callbacks ....

0 Likes
1 Solution
ArvindS_76
Employee

Yes, there is a way to do this. See <SDK>/Wiced-Smart/bleapp/utils/bleappevent.h, bleappevt_serialize(). This function lets you serialize a callback function to the application thread. Here is some pseudo-code:

INT32 serialized_callback(void* context)

{

    // Application thread context serialized callback.

    // Do something with context (which is &ctxt).

    return BLE_APP_EVENT_NO_ACTION;

}

// Global context structure to pass data from async event to serialized callback.

struct my_context ctxt;

void handle_async_event(void)

{

    ctxt.x = 1;

    ctxt.y = 2;

  

    // Serialize a callback to the app thread. The pointer to ctxt will be passed to serialized_callback.

    bleappevt_serialize(serialized_callback, (void*)&ctxt);

}

You can also dynamically allocate a buffer from a pool and pass a pointer to the serialized callback using:

#include "cfa.h"

INT32 serialized_callback(void* context)

{

    // Application thread context serialized callback.

    // Do something with context (which is p_ctxt).

    // ctxt was allocated from the default pool, so let the system free it.

    // You can also cfa_mm_Free() this buffer and return BLE_APP_EVENT_NO_ACTION.

    return BLE_APP_EVENT_FREE_BUFFER;

}

void handle_async_event(void)

{

    struct my_context * p_ctxt = cfa_mm_Alloc(sizeof(my_context));

    p_ctxt->x = 1;

    p_ctxt->y = 2;

   

    // Serialize a callback to the app thread. The pointer to ctxt will be passed to serialized_callback.

    bleappevt_serialize(serialized_callback, (void*)p_ctxt);

}

View solution in original post

1 Reply
ArvindS_76
Employee

Yes, there is a way to do this. See <SDK>/Wiced-Smart/bleapp/utils/bleappevent.h, bleappevt_serialize(). This function lets you serialize a callback function to the application thread. Here is some pseudo-code:

INT32 serialized_callback(void* context)

{

    // Application thread context serialized callback.

    // Do something with context (which is &ctxt).

    return BLE_APP_EVENT_NO_ACTION;

}

// Global context structure to pass data from async event to serialized callback.

struct my_context ctxt;

void handle_async_event(void)

{

    ctxt.x = 1;

    ctxt.y = 2;

  

    // Serialize a callback to the app thread. The pointer to ctxt will be passed to serialized_callback.

    bleappevt_serialize(serialized_callback, (void*)&ctxt);

}

You can also dynamically allocate a buffer from a pool and pass a pointer to the serialized callback using:

#include "cfa.h"

INT32 serialized_callback(void* context)

{

    // Application thread context serialized callback.

    // Do something with context (which is p_ctxt).

    // ctxt was allocated from the default pool, so let the system free it.

    // You can also cfa_mm_Free() this buffer and return BLE_APP_EVENT_NO_ACTION.

    return BLE_APP_EVENT_FREE_BUFFER;

}

void handle_async_event(void)

{

    struct my_context * p_ctxt = cfa_mm_Alloc(sizeof(my_context));

    p_ctxt->x = 1;

    p_ctxt->y = 2;

   

    // Serialize a callback to the app thread. The pointer to ctxt will be passed to serialized_callback.

    bleappevt_serialize(serialized_callback, (void*)p_ctxt);

}

View solution in original post