Hello,
I am having difficulty sending the same message to multiple tasks while using TI BLE Stack version 1.4. I have the following code to accomplish sending a message to multiple tasks. The problem I am running into is that after the first osal_msg_send call, I get the following error message (printed from my code):
[OpMode.c:911] ERROR: Failed to send 'Change Mode' Message to Task 0xb (Status (0x5) 'INVALID_MSG_POINTER')
Which makes some sense, because the receiving tasks call osal_msg_deallocate after processing the OSAL message. I could forsee getting around this issue by allocating in the loop, but I believe OSAL should be able to handle this. So, long story short, is there a way to send a OSAL message to multiple tasks (w/o allocating memory for each message sent)?
/// Op-Mode Connection Change Request Message typedef struct { osal_event_hdr_t hdr; ///< OSAL Message Header bool connect; ///< True to connect, False to disconnect const char* pFile; ///< The calling file name (could use __FILE__) uint16 lineNo; ///< The calling line number (could use __LINE__) } OpModeConnectMsg_t; static OpModeResult_t SendConnectionChange( bool connect, const char* pFile, const uint16 lineNo ) { OpModeResult_t result = OP_MODE_RESULT_ERROR; OpModeConnectMsg_t* pMsg; TRACE_FLOW( THIS_FILE, __LINE__, TRACE_ENABLE, "Send Connection Change (0x%x) Request from %s:%d", connect, pFile, lineNo ); pMsg = (OpModeConnectMsg_t*) osal_msg_allocate( sizeof( OpModeConnectMsg_t ) ); if ( pMsg != NULL ) { pMsg->hdr.event = OP_MODE_CONNECTION_CHANGE_REQUEST; pMsg->connect = connect; pMsg->pFile = pFile; pMsg->lineNo = lineNo; result = OP_MODE_RESULT_OK; SendMsgToRegistered( (uint8*) pMsg, "Connection Change", THIS_FILE, __LINE__ ); } return ( result ); } static void SendMsgToRegistered( uint8* pMsg, const char* pDescription, const char* pFile, const uint16 lineNo ) { uint8 status; uint8 i; for ( i = 0; i < numRegisteredTasks; i++ ) { if ( registeredTasks[i] == INVALID_TASK_ID ) { continue; } status = osal_msg_send( registeredTasks[i], pMsg ); if ( status != SUCCESS ) { TRACE_ERROR( pFile, lineNo, TRACE_ENABLE, "Failed to send '%s' Message to Task 0x%x " \ "(Status (0x%x) '%s')", pDescription, registeredTasks[i], status, StatusToString( status ) ); } else { TRACE_FLOW( pFile, lineNo, TRACE_ENABLE, "Sent '%s' Message to Task 0x%x", pDescription, registeredTasks[i] ); } } }