/*********************************************************************
 * @fn      Audio_AddService
 *
 * @brief   Initializes the Audio Profile service by registering
 *          GATT attributes with the GATT server.
 *
 * @return  SUCCESS, bleMemAllocError, or return value of
 *          GATTServApp_RegisterService
 */
bStatus_t Audio_AddService(void)
{
  uint8 status = SUCCESS;

  // Allocate Audio Cmd Client Characteristic Configuration table
  audioProfileStartConfig = (gattCharCfg_t *)ICall_malloc(sizeof(gattCharCfg_t)*
                                                          linkDBNumConns );
  if (audioProfileStartConfig == NULL)
  {
    return bleMemAllocError;
  }

  // Initialize Audio Cmd Client Characteristic Configuration attributes
  GATTServApp_InitCharCfg(INVALID_CONNHANDLE, audioProfileStartConfig);

  // Allocate Audio Stream Client Characteristic Configuration table
  audioProfileAudioConfig = (gattCharCfg_t *)ICall_malloc(sizeof(gattCharCfg_t)*
                                                          linkDBNumConns);
  if (audioProfileAudioConfig == NULL)
  {
    return bleMemAllocError;
  }

  // Initialize Audio Stream Client Characteristic Configuration attributes
  GATTServApp_InitCharCfg(INVALID_CONNHANDLE, audioProfileAudioConfig);

  // Register GATT attribute list and CBs with GATT Server App
  status = GATTServApp_RegisterService(audioProfileAttrTbl,
                                       GATT_NUM_ATTRS(audioProfileAttrTbl),
                                       GATT_MAX_ENCRYPT_KEY_SIZE,
                                       &audioProfileCBs);

  return status;
}
/*********************************************************************
 * @fn      OADTarget_addService
 *
 * @brief   Initializes the OAD Service by registering GATT attributes
 *          with the GATT server. Only call this function once.
 *
 * @return  The return value of GATTServApp_RegisterForMsg().
 */
bStatus_t OADTarget_addService(void)
{
  // Allocate Client Characteristic Configuration table
  oadImgIdentifyConfig = (gattCharCfg_t *)ICall_malloc(sizeof(gattCharCfg_t) *
                                                       linkDBNumConns);
  if (oadImgIdentifyConfig == NULL)
  {
    return (bleMemAllocError);
  }
  
  // Allocate Client Characteristic Configuration table
  oadImgBlockConfig = (gattCharCfg_t *)ICall_malloc(sizeof(gattCharCfg_t) *
                                                    linkDBNumConns);
  
  if (oadImgBlockConfig == NULL)
  {
    // Free already allocated data
    ICall_free(oadImgIdentifyConfig);
    
    return (bleMemAllocError);
  }
  
  // Initialize Client Characteristic Configuration attributes
  GATTServApp_InitCharCfg(INVALID_CONNHANDLE, oadImgIdentifyConfig);
  GATTServApp_InitCharCfg(INVALID_CONNHANDLE, oadImgBlockConfig);

  return GATTServApp_RegisterService(oadAttrTbl, GATT_NUM_ATTRS(oadAttrTbl), 
                                     GATT_MAX_ENCRYPT_KEY_SIZE, &oadCBs);
}
Example #3
0
/*********************************************************************
 * @fn      SimpleBLEPeripheral_ObserverStateChangeCB
 *
 * @brief   Peripheral observer event callback function.
 *
 * @param   pEvent - pointer to event structure
 *
 * @return  TRUE if safe to deallocate event message, FALSE otherwise.
 */
static void SimpleBLEPeripheral_ObserverStateChangeCB(gapPeripheralObserverRoleEvent_t *pEvent)
{

  sbpEvt_t *pMsg;

  // Create dynamic pointer to message.
  if ((pMsg = ICall_malloc(sizeof(sbpEvt_t))))
  {
    pMsg->hdr.event = SBP_OBSERVER_STATE_CHANGE_EVT;
    pMsg->hdr.state = SUCCESS;

    switch(pEvent->gap.opcode)
    {
    case GAP_DEVICE_INFO_EVENT:
      {
        gapDeviceInfoEvent_t *pDevInfoMsg;

        pDevInfoMsg = ICall_malloc(sizeof(gapDeviceInfoEvent_t));
        memcpy(pDevInfoMsg, pEvent, sizeof(gapDeviceInfoEvent_t));

        pDevInfoMsg->pEvtData = ICall_malloc(pEvent->deviceInfo.dataLen);
        memcpy(pDevInfoMsg->pEvtData, pEvent->deviceInfo.pEvtData, pEvent->deviceInfo.dataLen);
        
        pMsg->pData = (uint8 *)pDevInfoMsg;
      }
      break;

    case GAP_DEVICE_DISCOVERY_EVENT:
      {
        gapDevDiscEvent_t *pDevDiscMsg;

        pDevDiscMsg = ICall_malloc(sizeof(gapDevDiscEvent_t));
        memcpy(pDevDiscMsg, pEvent, sizeof(gapDevDiscEvent_t));

        pDevDiscMsg->pDevList = ICall_malloc((pEvent->discCmpl.numDevs)*sizeof(gapDevRec_t));
        memcpy(pDevDiscMsg->pDevList, pEvent->discCmpl.pDevList, (pEvent->discCmpl.numDevs)*sizeof(gapDevRec_t));
        
        pMsg->pData = (uint8 *)pDevDiscMsg;
      }
      break;

    default:
      break;
    }

    // Enqueue the message.
    Util_enqueueMsg(appMsgQueue, sem, (uint8*)pMsg);
  }

  // Free the stack message
  ICall_freeMsg(pEvent);
}
Example #4
0
/*********************************************************************
 * @fn      HeartRate_AddService
 *
 * @brief   Initializes the Heart Rate service by registering
 *          GATT attributes with the GATT server.
 *
 * @param   services - services to add. This is a bit map and can
 *                     contain more than one service.
 *
 * @return  Success or Failure
 */
bStatus_t HeartRate_AddService(uint32 services)
{
  uint8 status;

  // Allocate Client Characteristic Configuration table
  heartRateMeasClientCharCfg = (gattCharCfg_t *)ICall_malloc( sizeof(gattCharCfg_t) *
                                                              linkDBNumConns );
  if ( heartRateMeasClientCharCfg == NULL )
  {
    return ( bleMemAllocError );
  }
  
  // Initialize Client Characteristic Configuration attributes.
  GATTServApp_InitCharCfg(INVALID_CONNHANDLE, heartRateMeasClientCharCfg);

  if (services & HEARTRATE_SERVICE)
  {
    // Register GATT attribute list and CBs with GATT Server App.
    status = GATTServApp_RegisterService(heartRateAttrTbl, 
                                         GATT_NUM_ATTRS(heartRateAttrTbl),
                                         GATT_MAX_ENCRYPT_KEY_SIZE,
                                         &heartRateCBs);
  }
  else
  {
    status = SUCCESS;
  }

  return (status);
}
Example #5
0
/*********************************************************************
 * @fn      SK_AddService
 *
 * @brief   Initializes the Simple Key service by registering
 *          GATT attributes with the GATT server.
 *
 * @param   services - services to add. This is a bit map and can
 *                     contain more than one service.
 *
 * @return  Success or Failure
 */
bStatus_t SK_AddService(uint32 services)
{
  uint8 status = SUCCESS;

  // Allocate Client Characteristic Configuration table
  skConfig = (gattCharCfg_t *)ICall_malloc(sizeof(gattCharCfg_t) *
                                            linkDBNumConns);
  if (skConfig == NULL)
  {
    return (bleMemAllocError);
  }
  
  // Initialize Client Characteristic Configuration attributes
  GATTServApp_InitCharCfg(INVALID_CONNHANDLE, skConfig); 
  
  if (services & SK_SERVICE)
  {
    // Register GATT attribute list and CBs with GATT Server App
    status = GATTServApp_RegisterService(simplekeysAttrTbl, 
                                         GATT_NUM_ATTRS(simplekeysAttrTbl),
                                         GATT_MAX_ENCRYPT_KEY_SIZE,
                                         &skCBs);
  }

  return (status);
}
/*********************************************************************
 * @fn      RunningSensor_serviceCB
 *
 * @brief   Callback function for RSC service.
 *
 * @param   event       - service event
 * @param   pNewCummVal - pointer to new total distance data
 *                        if specified by event.  NULL otherwise.
 *
 * @return  SUCCESS if operation successful. FAILURE, otherwise.
 */
static bStatus_t RunningSensor_serviceCB(uint8_t event, uint32_t *pNewCummVal)
{
  if ((event == RSC_CMD_START_SENS_CALIB) && 
      (sensorFlags[sensorFlagsIdx] != RSC_FLAGS_AT_REST))
  {
    // Induce a calibration error for conformance testing.
    return (FAILURE);
  }
  
  // Allocate message data.
  uint32_t *pData;
  
  if ((pData = ICall_malloc(sizeof(uint32_t)))) 
  {
    if (pNewCummVal != 0)
    {
      *pData = *pNewCummVal;
    }
    else
    {
      *pData = 0;
    }
  }
  
  RunningSensor_enqueueMsg(RSC_SERVICE_EVT, event, (uint8_t *)pData);
  
  return SUCCESS;
}
Example #7
0
/*******************************************************************************
 * @fn      SensorTag_processOadWriteCB
 *
 * @brief   Process a write request to the OAD profile.
 *
 * @param   event      - event type:
 *                       OAD_WRITE_IDENTIFY_REQ
 *                       OAD_WRITE_BLOCK_REQ
 * @param   connHandle - the connection Handle this request is from.
 * @param   pData      - pointer to data for processing and/or storing.
 *
 * @return  None.
 */
static void SensorTag_processOadWriteCB(uint8_t event, uint16_t connHandle,
                                           uint8_t *pData)
{
  oadTargetWrite_t *oadWriteEvt = ICall_malloc( sizeof(oadTargetWrite_t) + \
                                             sizeof(uint8_t) * OAD_PACKET_SIZE);

  if ( oadWriteEvt != NULL )
  {
    oadWriteEvt->event = event;
    oadWriteEvt->connHandle = connHandle;

    oadWriteEvt->pData = (uint8_t *)(&oadWriteEvt->pData + 1);
    memcpy(oadWriteEvt->pData, pData, OAD_PACKET_SIZE);

    Queue_enqueue(hOadQ, (Queue_Elem *)oadWriteEvt);

    // Post the application's semaphore.
    Semaphore_post(sem);
  }
  else
  {
    // Fail silently.
  }

}
Example #8
0
/*********************************************************************
 * @fn      Util_enqueueMsg
 *
 * @brief   Creates a queue node and puts the node in RTOS queue.
 *
 * @param   msgQueue - queue handle.
 * @param   sem - thread's event processing semaphore that queue is
 *                associated with.
 * @param   pMsg - pointer to message to be queued
 *
 * @return  TRUE if message was queued, FALSE otherwise.
 */
uint8_t Util_enqueueMsg(Queue_Handle msgQueue, Semaphore_Handle sem,
                        uint8_t *pMsg)
{
  queueRec_t *pRec;
  
  // Allocated space for queue node.
#ifdef USE_ICALL
  if (pRec = ICall_malloc(sizeof(queueRec_t)))
#else
  if (pRec = (queueRec_t *)malloc(sizeof(queueRec_t)))
#endif
  {
    pRec->pData = pMsg;
  
    Queue_enqueue(msgQueue, &pRec->_elem);
    
    // Wake up the application thread event handler.
    if (sem)
    {
      Semaphore_post(sem);
    }
    
    return TRUE;
  }
  
  // Free the message.
#ifdef USE_ICALL
  ICall_free(pMsg);
#else
  free(pMsg);
#endif
  
  return FALSE;
}
/*********************************************************************
 * @fn      ClimbProfile_AddService
 *
 * @brief   Initializes the Simple Profile service by registering
 *          GATT attributes with the GATT server.
 *
 * @param   services - services to add. This is a bit map and can
 *                     contain more than one service.
 *
 * @return  Success or Failure
 */
bStatus_t ClimbProfile_AddService( uint32 services )
{
  uint8 status;

  // Allocate Client Characteristic Configuration table
  climbProfileChar1Config = (gattCharCfg_t *)ICall_malloc( sizeof(gattCharCfg_t) *
                                                            linkDBNumConns );
  if ( climbProfileChar1Config == NULL )
  {     
    return ( bleMemAllocError );
  }
  
  // Initialize Client Characteristic Configuration attributes
  GATTServApp_InitCharCfg( INVALID_CONNHANDLE, climbProfileChar1Config );

  if ( services & CLIMBPROFILE_SERVICE )
  {
    // Register GATT attribute list and CBs with GATT Server App
    status = GATTServApp_RegisterService( climbProfileAttrTbl,
                                          GATT_NUM_ATTRS( climbProfileAttrTbl ),
                                          GATT_MAX_ENCRYPT_KEY_SIZE,
                                          &climbProfileCBs );
  }
  else
  {
    status = SUCCESS;
  }

  return ( status );
}
// Pass in size get a pointer to dynamically allocated buffer.
void *SNP_malloc(uint16_t size)
{
#ifdef SNP_LOCAL
  return ICall_malloc(size);
#else //!SNP_LOCAL
  return malloc(size);
#endif //SNP_LOCAL
}
Example #11
0
/*********************************************************************
 * @fn      BloodPressure_AddService
 *
 * @brief   Initializes the BloodPressure   service by registering
 *          GATT attributes with the GATT server.
 *
 * @param   services - services to add. This is a bit map and can
 *                     contain more than one service.
 *
 * @return  Success or Failure
 */
bStatus_t BloodPressure_AddService(uint32 services)
{
  uint8 status;

  // Allocate Client Characteristic Configuration table
  bloodPressureMeasConfig = (gattCharCfg_t *)ICall_malloc( sizeof(gattCharCfg_t) *
                                                           linkDBNumConns );
  if ( bloodPressureMeasConfig == NULL )
  {
    return ( bleMemAllocError );
  }
  
  // Allocate Client Characteristic Configuration table
  bloodPressureIMeasConfig = (gattCharCfg_t *)ICall_malloc( sizeof(gattCharCfg_t) *
                                                            linkDBNumConns );
  if ( bloodPressureIMeasConfig == NULL )
  {
    // Free already allocated data
    ICall_free( bloodPressureMeasConfig );
    
    return ( bleMemAllocError );
  }

  // Initialize Client Characteristic Configuration attributes.
  GATTServApp_InitCharCfg(INVALID_CONNHANDLE, bloodPressureMeasConfig);
  GATTServApp_InitCharCfg(INVALID_CONNHANDLE, bloodPressureIMeasConfig);
  
  if (services & BLOODPRESSURE_SERVICE)
  {
    // Register GATT attribute list and CBs with GATT Server App.
    status = GATTServApp_RegisterService(bloodPressureAttrTbl, 
                                         GATT_NUM_ATTRS(bloodPressureAttrTbl),
                                         GATT_MAX_ENCRYPT_KEY_SIZE,
                                         &bloodPressureCBs);
  }
  else
  {
    status = SUCCESS;
  }
  
  return (status);
}
// ----------------------------------------------------------------------------
//! \brief      Bundles message into Transport Layer frame and NPIMSG_msg_t
//!             container.  This is the MT specific version of this function.
//!
//!             This function frames the passed in buffer with an MT SOF and FCS
//!             bytes.  It then bundles the message in an NPIMSG_msg_t
//!             container.
//!
//!             Note: becauase the SOF and FCS are added, the passed in buffer
//!             is copied to a new buffer and then the passed in buffer is
//!             free'd.
//!
//! \param  pIncomingMsg     Pointer to message buffer.
//!
//! \return     void
// ----------------------------------------------------------------------------
NPIMSG_msg_t *NPIFrame_frameMsg(uint8_t *pIncomingMsg)
{
    uint8_t *payload;

    NPIMSG_msg_t *npiMsg = (NPIMSG_msg_t *)ICall_malloc(sizeof(NPIMSG_msg_t));

    if(npiMsg != NULL)
    {
        // extract the message length from the MT header bytes.
        uint8_t inMsgLen = pIncomingMsg[MTRPC_POS_LEN] + MTRPC_FRAME_HDR_SZ;

        // allocate a new buffer that is the incoming buffer length + 2
        // additional bytes for the SOF and FCS bytes.
        if((npiMsg->pBuf = (uint8_t *)ICall_allocMsg(inMsgLen + 2)) != NULL)
        {
            // mark the start of frame.
            npiMsg->pBuf[0] = MT_SOF;
            payload = npiMsg->pBuf + 1;

            // copy the incoming buffer into the newly created buffer
            memcpy(payload, pIncomingMsg, inMsgLen);

            // calculate and capture the FCS in the final byte.
            npiMsg->pBuf[inMsgLen + 1] = npiframe_calcMTFCS(npiMsg->pBuf + 1,
                                                            inMsgLen);
#if defined(NPI_SREQRSP)
            // document message type (SYNC or ASYNC) in the NPI container.
            if((pIncomingMsg[MTRPC_POS_CMD0] & MTRPC_CMD_TYPE_MASK) == MTRPC_CMD_SRSP)
            {
                npiMsg->msgType = NPIMSG_Type_SYNCRSP;
            }
            else
            {
                npiMsg->msgType = NPIMSG_Type_ASYNC;
            }
#else
            npiMsg->msgType = NPIMSG_Type_ASYNC;
#endif
            // capture the included buffer size in the NPI container.
            npiMsg->pBufSize = inMsgLen + 2;
        }
        else
        {
            // abort and free allocated memory.
            ICall_free(npiMsg);
            npiMsg = NULL;
        }
    }

    /* No matter what happened, give back incoming buffer */
    ICall_freeMsg(pIncomingMsg);

    return(npiMsg);
}
/*********************************************************************
 * @fn      CyclingSensor_serviceCB
 *
 * @brief   Callback function for CSC service.
 *
 * @param   event       - service event
 * @param   pNewCummVal - pointer to new total distance data
 *                        if specified by event.  NULL otherwise.
 *
 * @return  SUCCESS if operation successful. FAILURE, otherwise.
 */
static void CyclingSensor_serviceCB(uint8_t event, uint32_t *pNewCummVal)
{
  uint32_t *pData;
  
  // Allocate message data
  if ((pData = ICall_malloc(sizeof(uint32_t))))
  {
    *pData = (pNewCummVal != NULL) ? *pNewCummVal : 0;
  
    // Queue the event.
    CyclingSensor_enqueueMsg(CSC_SERVICE_EVT, event, (uint8_t *)pData);
  }
}
Example #14
0
/*********************************************************************
 * @fn      trainingTag_enqueueMsg
 *
 * @brief   Creates a message and puts the message in RTOS queue.
 *
 * @param   event  - message event.
 * @param   status - message status.
 *
 * @return  None.
 */
static void trainingTag_enqueueMsg(uint8_t event, uint8_t status)
{
  tTagEvt_t *pMsg;

  // Create dynamic pointer to message.
  if (pMsg = ICall_malloc(sizeof(tTagEvt_t)))
  {
    pMsg->event = event;
    pMsg->status = status;

    // Enqueue the message.
    Util_enqueueMsg(appMsgQueue, sem, (uint8*)pMsg);
  }
}
Example #15
0
/*********************************************************************
 * @fn      SimpleBLEBroadcaster_stateChangeCB
 *
 * @brief   Callback from GAP Role indicating a role state change.
 *
 * @param   newState - new state
 *
 * @return  none
 */
static void SimpleBLEBroadcaster_stateChangeCB(gaprole_States_t newState)
{
  sbbEvt_t *pMsg;
  
  // Create dynamic pointer to message.
  if (pMsg = ICall_malloc(sizeof(sbbEvt_t)))
  {
    pMsg->hdr.event = SBB_STATE_CHANGE_EVT;
    pMsg->hdr.state = newState;
    
    // Enqueue the message.
    Util_enqueueMsg(appMsgQueue, sem, (uint8*)pMsg);
  }
}
Example #16
0
/*********************************************************************
 * @fn      SimpleBLEPeripheral_enqueueMsg
 *
 * @brief   Creates a message and puts the message in RTOS queue.
 *
 * @param   event - message event.
 * @param   state - message state.
 *
 * @return  None.
 */
static void SimpleBLEPeripheral_enqueueMsg(uint8_t event, uint8_t state, uint8_t *pData)
{
  sbpEvt_t *pMsg;

  // Create dynamic pointer to message.
  if ((pMsg = ICall_malloc(sizeof(sbpEvt_t))))
  {
    pMsg->hdr.event = event;
    pMsg->hdr.state = state;

    // Enqueue the message.
    Util_enqueueMsg(appMsgQueue, sem, (uint8*)pMsg);
  }
}
Example #17
0
/*********************************************************************
 * @fn      SimplePropBeacon_enqueueMsg
 *
 * @brief   Creates a message and puts the message in RTOS queue.
 *
 * @param   event - message event.
 * @param   state - message state.
 *
 * @return  None.
 */
static void SimplePropBeacon_enqueueMsg(uint8_t event, uint8_t state)
{
  spbEvt_t *pMsg;

  // Create dynamic pointer to message.
  if ((pMsg = ICall_malloc(sizeof(spbEvt_t))))
  {
    pMsg->hdr.event = event;
    pMsg->hdr.state = state;

    // Enqueue the message.
    Util_enqueueMsg(appMsgQueue, sem, (uint8*)pMsg);
  }
}
/*********************************************************************
 * @fn      glucCollCentral_pairStateCB
 *
 * @brief   Pairing state callback.
 *
 * @param   connHandle - connection handle
 * @param   state      - pairing state
 * @param   status     - pairing status
 *
 * @return  none
 */
static void glucCollCentral_pairStateCB(uint16_t connHandle, uint8_t state,
                                        uint8_t status)
{
  uint8_t *psEvt;
  
  // Allocate message data.
  if ((psEvt = ICall_malloc(sizeof(uint8_t))))
  {
    *psEvt = status;
        
    // Queue the event.
    glucCollCentral_enqueueMsg(GLUCOLL_PAIRING_STATE_EVT, state, psEvt);
  }
}
Example #19
0
/**
 *  SNP_setAdvData
 *
 */
uint8_t SNP_setAdvData(snpSetAdvDataReq_t *pReq, uint8_t len)
{
  uint8_t status = 0;
  uint8_t *pDataPtr;
  
  //Device must be started, or the set adv command will failed.
  VOID GAPRole_StartDevice(&SNP_gapRoleCBs);  
  
  if(pReq->type < SNP_ADV_DATA_MAX_IDX)
  {
    pDataPtr = advPtrTable[pReq->type].pData;
    if(pDataPtr)
    {
      ICall_free(advPtrTable[pReq->type].pData);
    }
    advPtrTable[pReq->type].pData = pDataPtr = ICall_malloc(len);
    if(pDataPtr)
    {
      advPtrTable[pReq->type].length = len;
      memcpy(pDataPtr, pReq->pData, len);
      if(pReq->type == SNP_ADV_DATA_SCAN_RSP_IDX)
      {
        status = GAPRole_SetParameter(GAPROLE_SCAN_RSP_DATA, len, pDataPtr);
      }
      else if(pReq->type == SNP_ADV_DATA_NON_CONN_IDX)
      {
        status = GAPRole_SetParameter(GAPROLE_ADVERT_DATA, len, pDataPtr);
      }
      else if(pReq->type == SNP_ADV_DATA_CONN_IDX)
      {
        uint8_t value;
        GAPRole_GetParameter(GAPROLE_STATE, &value);
        if(value == GAPROLE_CONNECTED_ADV)
        {
          status = GAPRole_SetParameter(GAPROLE_ADVERT_DATA, len, pDataPtr);        
        }      
      }
    }
    else
    {
      status = SNP_OUT_OF_RESOURCES;
    }      
  }
  else
  {
    //Error, bad type
    status = SNP_INVALID_PARAMS;
  }  
  return status;
}
/*********************************************************************
 * @fn      glucCollCentral_passcodeCB
 *
 * @brief   Passcode callback.
 *
 * @param   deviceAddr - device address
 * @param   connHandle - connection handle
 * @param   uiInputs   - input passcode
 * @param   uiOutputs  - display passcode
 *
 * @return  none
 */
static void glucCollCentral_passcodeCB(uint8_t *deviceAddr, uint16_t connHandle,
                                       uint8_t uiInputs, uint8_t uiOutputs)
{
  uint8_t *pcEvt;
  
  // Allocate message data.
  if ((pcEvt = ICall_malloc(sizeof(uint8_t) * 2)))
  {
    pcEvt[0] = uiInputs;
    pcEvt[1] = uiOutputs;
    
    // Queue the event.
    glucCollCentral_enqueueMsg(GLUCOLL_PASSCODE_NEEDED_EVT, 0, pcEvt);
  }
}
Example #21
0
/*******************************************************************************
 * @fn      SensorTag_enqueueMsg
 *
 * @brief   Creates a message and puts the message in RTOS queue.
 *
 * @param   event - message event.
 * @param   serviceID - service identifier
 * @param   paramID - parameter identifier
 *
 * @return  none
 */
static void SensorTag_enqueueMsg(uint8_t event, uint8_t serviceID, uint8_t paramID)
{
  stEvt_t *pMsg;

  // Create dynamic pointer to message.
  if (pMsg = ICall_malloc(sizeof(stEvt_t)))
  {
    pMsg->event = event;
    pMsg->serviceID = serviceID;
    pMsg->paramID = paramID;

    // Enqueue the message.
    Util_enqueueMsg(appMsgQueue, sem, (uint8_t*)pMsg);
  }
}
/*********************************************************************
 * @fn      DualImageConcept_enqueueMsg
 *
 * @brief   Creates a message and puts the message in RTOS queue.
 *
 * @param   event  - message event.
 * @param   state  - message state.
 * @param   pData  - message data pointer.
 *
 * @return  None.
 */
static void DualImageConcept_enqueueMsg(uint8_t event, uint8_t state, 
                                        uint8_t *pData)
{
  dicEvt_t *pMsg;
  
  // Create dynamic pointer to message.
  if ((pMsg = ICall_malloc(sizeof(dicEvt_t))))
  {
    pMsg->hdr.event = event;
    pMsg->hdr.state = state;
    pMsg->pData = pData;
    
    // Enqueue the message.
    Util_enqueueMsg(appMsgQueue, sem, (uint8*)pMsg);
  }
}
/*********************************************************************
 * @fn      HidEmuKbd_enqueueMsg
 *
 * @brief   Creates a message and puts the message in RTOS queue.
 *
 * @param   event  - message event.
 * @param   state  - message state.
 *
 * @return  TRUE or FALSE
 */
static uint8_t HidEmuKbd_enqueueMsg(uint16_t event, uint8_t state)
{
  hidEmuKbdEvt_t *pMsg;

  // Create dynamic pointer to message.
  if (pMsg = ICall_malloc(sizeof(hidEmuKbdEvt_t)))
  {
    pMsg->hdr.event = event;
    pMsg->hdr.state = state;

    // Enqueue the message.
    return Util_enqueueMsg(appMsgQueue, sem, (uint8_t *)pMsg);
  }

  return FALSE;
}
Example #24
0
/*********************************************************************
 * @fn      Util_enqueueMsg
 *
 * @brief   Creates a queue node and puts the node in RTOS queue.
 *
 * @param   msgQueue - queue handle.
 * @param   sem - thread's event processing semaphore that queue is
 *                associated with.
 * @param   pMsg - pointer to message to be queued
 *
 * @return  TRUE if message was queued, FALSE otherwise.
 */
uint8_t Util_enqueueMsg(Queue_Handle msgQueue, 
#ifdef ICALL_EVENTS
                        Event_Handle event,
#else //!ICALL_EVENTS
                        Semaphore_Handle sem,
#endif //ICALL_EVENTS
                        uint8_t *pMsg)
{
  queueRec_t *pRec;

  // Allocated space for queue node.
#ifdef USE_ICALL
  if ((pRec = ICall_malloc(sizeof(queueRec_t))))
#else
  if ((pRec = (queueRec_t *)malloc(sizeof(queueRec_t))))
#endif
  {
    pRec->pData = pMsg;

    // This is an atomic operation
    Queue_put(msgQueue, &pRec->_elem);

    // Wake up the application thread event handler.
#ifdef ICALL_EVENTS
    if (event)
    {
      Event_post(event, UTIL_QUEUE_EVENT_ID);
    }
#else //!ICALL_EVENTS
    if (sem)
    {
      Semaphore_post(sem);
    }
#endif //ICALL_EVENTS

    return TRUE;
  }

  // Free the message.
#ifdef USE_ICALL
  ICall_free(pMsg);
#else
  free(pMsg);
#endif

  return FALSE;
}
Example #25
0
/*********************************************************************
 * @fn      simpleTopology_enqueueMsg
 *
 * @brief   Creates a message and puts the message in RTOS queue.
 *
 * @param   event - message event.
 * @param   state - message state.
 *
 * @return  None.
 */
static uint8_t simpleTopology_enqueueMsg(uint16_t event, uint8_t status, uint8_t *pData)
{
  sbtEvt_t *pMsg = ICall_malloc(sizeof(sbtEvt_t));

  // Create dynamic pointer to message.
  if (pMsg)
  {
    pMsg->event = event;
    pMsg->status = status;
    pMsg->pData = pData;

    // Enqueue the message.
    return Util_enqueueMsg(appMsgQueue, sem, (uint8*)pMsg);
  }
  
  return FALSE;
}
Example #26
0
/*********************************************************************
 * @fn      ProxReporter_AddService
 *
 * @brief   Initializes the Proximity Reporter service by
 *          registering GATT attributes with the GATT server.
 *          Only call this function once.
 *
 * @param   services - services to add. This is a bit map and can
 *                     contain more than one service.
 *
 * @return   Success or Failure
 */
bStatus_t ProxReporter_AddService(uint32 services)
{
  uint8 status = SUCCESS;

  if (services & PP_LINK_LOSS_SERVICE)
  {
    // Register Link Loss attribute list and CBs with GATT Server App.
    status = GATTServApp_RegisterService(linkLossAttrTbl, 
                                         GATT_NUM_ATTRS(linkLossAttrTbl),
                                         GATT_MAX_ENCRYPT_KEY_SIZE,
                                         &proxReporterCBs);
  }

  if ((status == SUCCESS) && (services & PP_IM_ALETR_SERVICE))
  {
    // Register Link Loss attribute list and CBs with GATT Server App.
    status = GATTServApp_RegisterService(imAlertAttrTbl, 
                                         GATT_NUM_ATTRS(imAlertAttrTbl),
                                         GATT_MAX_ENCRYPT_KEY_SIZE,
                                         &proxReporterCBs);
  }
  
  if ((status == SUCCESS)  && (services & PP_TX_PWR_LEVEL_SERVICE))
  {
    // Allocate Client Characteristic Configuration table
    txPwrLevelConfig = (gattCharCfg_t *)ICall_malloc( sizeof(gattCharCfg_t) *
                                                      linkDBNumConns );
    if ( txPwrLevelConfig != NULL )
    {   
      // Initialize Client Characteristic Configuration attributes.
      GATTServApp_InitCharCfg(INVALID_CONNHANDLE, txPwrLevelConfig); 
      
      // Register Tx Power Level attribute list and CBs with GATT Server App.
      status = GATTServApp_RegisterService(txPwrLevelAttrTbl, 
                                           GATT_NUM_ATTRS(txPwrLevelAttrTbl),
                                           GATT_MAX_ENCRYPT_KEY_SIZE,
                                           &proxReporterCBs);
    }
    else
    {
      status = bleMemAllocError;
    }
  }

  return (status);
}
/*********************************************************************
 * @fn      glucCollCentral_enqueueMsg
 *
 * @brief   Creates a message and puts the message in RTOS queue.
 *
 * @param   event - message event.
 * @param   state - message state.
 * @param   pData - message data pointer.
 *
 * @return  TRUE or FALSE
 */
static uint8_t glucCollCentral_enqueueMsg(uint8_t event, uint8_t state, 
                                          uint8_t *pData)
{
  glucCollEvt_t *pMsg;
  
  // Create dynamic pointer to message.
  if (pMsg = ICall_malloc(sizeof(glucCollEvt_t)))
  {
    pMsg->hdr.event = event;
    pMsg->hdr.state = state;
    pMsg->pData = pData;

    // Enqueue the message.
    return Util_enqueueMsg(appMsgQueue, sem, (uint8_t *)pMsg);
  }

  return FALSE;
}
/*********************************************************************
 * @fn      AHRS_addService
 *
 * @brief   Initializes the AHRS Profile service by registering
 *          GATT attributes with the GATT server.
 *
 * @return  Success or Failure
 */
bStatus_t AHRS_addService(void)
{
  // Allocate Client Characteristic Configuration table
  sensorDataConfig = (gattCharCfg_t *)ICall_malloc(sizeof(gattCharCfg_t) *
                                                    linkDBNumConns);
  if (sensorDataConfig == NULL)
  {
    return (bleMemAllocError);
  }
  
  // Register with Link DB to receive link status change callback
  GATTServApp_InitCharCfg(INVALID_CONNHANDLE, sensorDataConfig);

  // Register GATT attribute list and CBs with GATT Server App
  return GATTServApp_RegisterService(sensorAttrTable,
                                     GATT_NUM_ATTRS (sensorAttrTable),
                                     GATT_MAX_ENCRYPT_KEY_SIZE,
                                     &sensorCBs);
}
Example #29
0
/*********************************************************************
* @fn      CcService_addService
*
* @brief   Initializes the service by registering
*          GATT attributes with the GATT server.
*
* @return  Success or Failure
*/
bStatus_t CcService_addService(void)
{
  // Allocate Client Characteristic Configuration table
  ccDataConfig = (gattCharCfg_t *)ICall_malloc(sizeof(gattCharCfg_t) *
                                                linkDBNumConns);
  if (ccDataConfig == NULL)
  {
    return (bleMemAllocError);
  }
  
  // Initialize Client Characteristic Configuration attributes
  GATTServApp_InitCharCfg(INVALID_CONNHANDLE, ccDataConfig);
  
  // Register GATT attribute list and CBs with GATT Server App
  return GATTServApp_RegisterService(ccServiceAttrTbl,
                                     GATT_NUM_ATTRS(ccServiceAttrTbl),
                                     GATT_MAX_ENCRYPT_KEY_SIZE,
                                     &ccServiceCBs);
}
/**
 *  @fn          SNP_mallocNPIFrame
 *
 *  @brief       allocate a NPI Frame.  called in SNP_LOCAL only.
 *
 *  @param[in]   len    : length in bytes
 *
 *  @return  None.
 */
_npiFrame_t *SNP_mallocNPIFrame(uint16_t len)
{
  _npiFrame_t *pMsg;

  // Allocate memory for NPI Frame
  pMsg = (_npiFrame_t *)ICall_malloc(sizeof(_npiFrame_t) + len);

  if (pMsg != NULL)
  {
      // Assign Data Length of Frame
      pMsg->dataLen = len;

      // Assign pData to first byte of payload
      // Pointer arithmetic of + 1 is equal to sizeof(_npiFrame_t) bytes
      // then cast to unsigned char * for pData
      pMsg->pData = (unsigned char *)(pMsg + 1);
  }

  return pMsg;
}