This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

LAUNCHXL-CC2640R2: bluetooth low energy, multitasking, Ti-RTOS, Memory allocation, Task management

Part Number: LAUNCHXL-CC2640R2

static void SimplePeripheral_taskFxn(UArg a0, UArg a1)
{
// Initialize application
SimplePeripheral_init();
// HCI_EXT_SetTxPowerCmd(TX_POWER_5_DBM);
Display_printf(dispHandle, 0, 0, "Serial Begin");
// Application main loop
for (;;)
{
uint32_t events;

// Waits for an event to be posted associated with the calling thread.
// Note that an event associated with a thread is posted when a
// message is queued to the message receive queue of the thread
events = Event_pend(syncEvent, Event_Id_NONE, SP_ALL_EVENTS,
ICALL_TIMEOUT_FOREVER);
// length = sprintf(output, "%d", events);
// Display_printf(dispHandle, 0, 10, output);

if (events)
{
ICall_EntityID dest;
ICall_ServiceEnum src;
ICall_HciExtEvt *pMsg = NULL;

// Fetch any available messages that might have been sent from the stack
if (ICall_fetchServiceMsg(&src, &dest,
(void **)&pMsg) == ICALL_ERRNO_SUCCESS)
{
uint8 safeToDealloc = TRUE;

if ((src == ICALL_SERVICE_CLASS_BLE) && (dest == selfEntity))
{
ICall_Stack_Event *pEvt = (ICall_Stack_Event *)pMsg;

// Check for BLE stack events first
if (pEvt->signature != 0xffff)
{
// Process inter-task message
safeToDealloc = SimplePeripheral_processStackMsg((ICall_Hdr *)pMsg);
}
}

if (pMsg && safeToDealloc)
{
ICall_freeMsg(pMsg);
}
}

// If RTOS queue is not empty, process app message.
if (events & SP_QUEUE_EVT)
{
while (!Queue_empty(appMsgQueueHandle))
{
spEvt_t *pMsg = (spEvt_t *)Util_dequeueMsg(appMsgQueueHandle);
if (pMsg)
{
// Process message.
SimplePeripheral_processAppMsg(pMsg);

// Free the space from the message.
ICall_free(pMsg);
}
}
}
}
}
}

/*

I am working on the ble project, However I am struggling hard to understand the different parrs of the program, i found abovementioned lines too complicate to understand,

can someone elaborate me or provide a link where this could be understand.

*/

  • Hi Dinesh,

    I'd recommend reviewing our SimpleLink Academy trainings to learn more about our BLE stack. They use Project Zero, not Simple Peripheral, but the overall structure is pretty similar.

    The way I understand the task function you've pasted here is that it waits for messages to come to the thread through the Event_pend call. These can be stack messages from the BLE stack or app messages from other threads. The function then passes these messages onto the relevant processing functions (SimplePeripheral_processStackMsg, SimplePeripheral_processAppMsg), frees the memory allocated for them and returns to wait on more calls.

    Best,

    Nate