• Join
  • Sign In with my.TI Login
Texas Instruments
  • Products
  • Applications
  • Tools & Software
  • Support & Community
  • Sample & Buy
  • About TI
Sample & Purchase Cart Sample & Purchase Cart
  • Search
  • Advanced
TI E2E™ Community
  • Support Forums
  • Blogs
  • Groups
  • Videos
  • 简体中文
  • More ...
TI Home » TI E2E Community » Support Forums » Low Power RF & Wireless Connectivity » Bluetooth® Applications » Stellaris Bluetopia Stack - Create Connection with specific Device using BLuetooth's Mac Address
Share
Low Power RF & Wireless Connectivity
  • Forums
  • Announcements
  • Files
  • E2E Wiki
Options
  • Subscribe via RSS

Forums

Stellaris Bluetopia Stack - Create Connection with specific Device using BLuetooth's Mac Address

This question is answered
long to
Posted by long to
on Mar 05 2012 21:29 PM
Prodigy80 points

Hi all,

I'm using bt_spp sample from bluetopia sample code.

I want to connect with only one specific bluetooth MAC Address. Can I do that?

At this moment, I will filter Mac Address in  DISC_Event_Callback function, but if there's a lot of bluetooth devices around, i don't think it works.

Can anyone help me?

bluetooth stack Bluetopia
Report Abuse
  • Reply
You have posted to a forum that requires a moderator to approve posts before they are publicly available.
All Replies
  • Stonestreet One Support
    Posted by Stonestreet One Support
    on Mar 09 2012 16:19 PM
    Verified Answer
    Verified by long to
    Genius3635 points

    Hello,

    Yes, you can connect to a specific MAC address. If you know the MAC address, you do not even need to initiate device discovery process. 

    The process is much straight forward if you know the SPP port number for the remote server.

    You can call SPPConnect with the MAC address of the device that you want to connect to as the parameter. You can use the macro ASSIGN_BD_ADDR defined in file BTBTypes.h to configure the input parameter to SPP Connect. You should also pass the correct SPP port number to the function SPP_Open_Remote_Port (defined as SPP_PORT_NUMBER in the sample code) which is called in SPPConnect function.

    If you do not know the SPP port number of the remote device, you will have to use SDP process to query the remote phone records and parse it to find the port number. If you need to do that, let us know and we can help further.

    Best Regards,

    Stonestreet One 

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • long to
    Posted by long to
    on Mar 09 2012 19:09 PM
    Prodigy80 points

    Hi,

    Thank you very much. That's what I need.

    What I am trying to do is that My bluetooth only can Connect to only one specific Phone. But I don't know the SPP port number.

    So please help me more.

    One more thing : Can we connect with the Phone, using Mac address when the Phone isn't in discoverable mode?

    I'm using my Bluetooth Earphone and see it can do it? But when I'm using the "Device discovery mode", i notice that I have to put my phone discoverable.

    Thanks and Regards

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • long to
    Posted by long to
    on Mar 20 2012 20:03 PM
    Prodigy80 points

    Hi Stonestreet One ,

    Any updates for me?

    Thanks and Regards

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Stonestreet One Support
    Posted by Stonestreet One Support
    on Mar 21 2012 16:36 PM
    Genius3635 points

    Hello,

    We will post the code to do SDP query to get RFCOMM port number here by Friday.

    Best Regards,

    Stonestreet One.

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Stonestreet One Support
    Posted by Stonestreet One Support
    on Mar 21 2012 16:39 PM
    Genius3635 points

    Hello,

    The device discovery mode is only to find the MAC address of the phone. If you know the MAC address of the phone and it is in the state to accept SPP connections then you can connect to it as mentioned earlier in the thread. 

    Best Regards,

    Stonestreet One. 

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Stonestreet One Support
    Posted by Stonestreet One Support
    on Mar 29 2012 09:28 AM
    Genius3635 points

    Hello,


    Please refer to this code to find the RFCOMM port number for the SPP server on a remote device that you should connect to.

    SDP process:

    Finding the RFCOMM port number for a service like SPP can be looked as a three step process.

    Step 1: Initiate the SDP process

    Step 2: Application receives the response via the callback

    Step 3: Application parses the response to find the server port number(s)

    Step 1: To initiate the SDP process we will use the function SPPServiceDiscovery(RemoteBDAddr). (Definition below)

    This takes the bluetooth address of the remote device as a parameter. This initiates the SDP process to find the Protocol descriptor attribute for SPP

    as it has the information about RFCOMM port numbers for SPP that you need to initiate a connection.

    ----

    Step 2: Once the SDP process is complete, the application will receive the response via the callback. (Definition below. )

    SPPServiceDiscovery is initiating a Service Search Attribute request (which means you are looking for an attribute or a range of attributes for a service like SPP)

    So we will receive a response that should throw us in the  case rdServiceSearchAttributeResponse: of the callback.

    In there we will invoke the ExtractRFCOMMPortNumber function. This function assumes that you have searched for Protocol Descriptor Attribute ID only, so is

    tightly knit with the SPPServiceDiscovery function. You may want to call this only when you are waiting on such a response. 

     ExtractRFCOMMPortNumber takes the response received and a pointer to array of intergers (size of 32 would be more than enough). 

    Memzero the array before passing the pointer as shown in the code. If the function returns zero, the array is populated with at least one server port.

    Loop through the array to find all the SPP ports advertised by the remote device. Stop when you hit a zero value as shown. 

    ---

    Step 3: ExtractRFCOMMPortNumber function (Definition below)

    This function parses the response and populates the passed array with any RFCOMM server port found. 

    Luckily, you can treat this function as a black box. If you are not getting the correct port numbers, please let us know how you are using the three steps.

    Hope this helps.

    Please let us know if you have any problem finding the server port number of a remote device. 

    Best Regards,

    Stonestreet One. 

    --------------------------------------------------------------

    in bluetooth.h

    Add:

    extern int SPPServiceDiscovery(BD_ADDR_t RemoteBDAddr);
    ------------------------------------------------------------
    in bluetooth.c
    Add:
    #define PROTOCOL_DESCRIPTOR_LIST_ATTR  0x0004
    .
    .
    static int ExtractRFCOMMPortNumber(SDP_Service_Search_Attribute_Response_Data_t *SDPServiceSearchAttributeResponse, int *PortList);
    static void BTPSAPI SDP_Event_Callback(unsigned int BluetoothStackID, unsigned int SDPRequestID, SDP_Response_Data_t *SDP_Response_Data, unsigned long CallbackParameter);
    .
    .
    .
    static void BTPSAPI SDP_EventCallback(
    unsigned int BluetoothStackID,
    unsigned int SDPRequestID,
    SDP_Response_Data_t *SDP_Response_Data,
    unsigned long CallbackParameter)
    {
    int Index;
    int ServerPort;
    int RFCOMMPortList[30];

    /* First, check to see if the required parameters appear to be */
    /* semi-valid. */
    if((SDP_Response_Data != NULL) && (BluetoothStackID))
    {
    /* The parameters appear to be semi-valid, now check to see what */
    /* type the incoming Event is. */
    switch(SDP_Response_Data->SDP_Response_Data_Type)
    {
    case rdTimeout:
    /* A SDP Timeout was received, display a message indicating */
    /* this. */
    Display(("\r\n"));
    Display(("SDP Timeout Received (Size = 0x%04X).\r\n", sizeof(SDP_Response_Data_t)));
    break;
    case rdConnectionError:
    /* A SDP Connection Error was received, display a message */
    /* indicating this. */
    Display(("\r\n"));
    Display(("SDP Connection Error Received (Size = 0x%04X).\r\n", sizeof(SDP_Response_Data_t)));
    break;
    case rdErrorResponse:
    /* A SDP error response was received, display all relevant */
    /* information regarding this event. */
    Display(("\r\n"));
    Display(("SDP Error Response Received (Size = 0x%04X) - Error Code: %d.\r\n", sizeof(SDP_Response_Data_t), SDP_Response_Data->SDP_Response_Data.SDP_Error_Response_Data.Error_Code));
    break;
    case rdServiceSearchResponse:
    /* A SDP Service Search Response was received, display all */
    /* relevant information regarding this event */
    Display(("\r\n"));
    Display(("SDP Service Search Response Received (Size = 0x%04X) - Record Count: %d\r\n", sizeof(SDP_Response_Data_t), SDP_Response_Data->SDP_Response_Data.SDP_Service_Search_Response_Data.Total_Service_Record_Count));

    /* First, check to see if any SDP Service Records were */
    /* found. */
    if(SDP_Response_Data->SDP_Response_Data.SDP_Service_Search_Response_Data.Total_Service_Record_Count)
    {
    Display(("Record Handles:\r\n"));

    for(Index = 0; (Word_t)Index < SDP_Response_Data->SDP_Response_Data.SDP_Service_Search_Response_Data.Total_Service_Record_Count; Index++)
    {
    Display(("Record %u: 0x%08X\r\n", (Index + 1), (unsigned int)SDP_Response_Data->SDP_Response_Data.SDP_Service_Search_Response_Data.Service_Record_List[Index]));
    }
    }
    else
    Display(("No SDP Service Records Found.\r\n"));
    break;
    case rdServiceAttributeResponse:
    /* A SDP Service Attribute Response was received, display */
    /* all relevant information regarding this event */
    Display(("\r\n"));
    Display(("SDP Service Attribute Response Received (Size = 0x%04X)\r\n", sizeof(SDP_Response_Data_t)));

    break;
    case rdServiceSearchAttributeResponse:
    /* A SDP Service Search Attribute Response was received, */
    /* display all relevant information regarding this event */
    Display(("\r\n"));
    Display(("SDP Service Search Attribute Response Received (Size = 0x%04X)\r\n", sizeof(SDP_Response_Data_t)));


    BTPS_MemInitialize(RFCOMMPortList, 0, sizeof(RFCOMMPortList));

    /* Call only when you queried for Attribute ID PROTOCOL DESCRIPTOR LIST (0x0004) */
    if(ExtractRFCOMMPortNumber(&SDP_Response_Data->SDP_Response_Data.SDP_Service_Search_Attribute_Response_Data, RFCOMMPortList) == 0)
    {
    Index = 0;

    while(RFCOMMPortList[Index])
    {
    Display(("RFCOMM Server Port Found at: %d", RFCOMMPortList[Index]));
    Index++;
    }
    }
    else
    {
    Display(("No RFCOMM Server found"));
    }


    break;
    default:
    /* An unknown/unexpected SDP event was received. */
    Display(("\r\n"));
    Display(("Unknown SDP Event.\r\n"));
    break;
    }
    }
    else
    {
    /* There was an error with one or more of the input parameters. */
    Display(("\r\n"));
    Display(("SDP callback data: Response_Data = NULL.\r\n"));
    }
    }

    /* The following function is responsible for issuing a Service Search*/
    /* Attribute Request to a Remote SDP Server. This function returns */
    /* zero if successful and a negative value if an error occurred. */
    int
    SPPServiceDiscovery(BD_ADDR_t RemoteBDAddr)
    {
    int Result;
    int ret_val;
    int Index;
    BD_ADDR_t NullADDR;
    SDP_UUID_Entry_t SDPUUIDEntry;
    SDP_Attribute_ID_List_Entry_t AttributeID;

    ASSIGN_BD_ADDR(NullADDR, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);

    /* First, check that valid Bluetooth Stack ID exists. */
    if(g_uiBluetoothStackID)
    {
    /* First let's build the UUID 32 value(s). */
    SDPUUIDEntry.SDP_Data_Element_Type = deUUID_16;
    ASSIGN_UUID_16(SDPUUIDEntry.UUID_Value.UUID_16, 0x11, 0x01);

    AttributeID.Attribute_Range = (Boolean_t)FALSE;
    AttributeID.Start_Attribute_ID = PROTOCOL_DESCRIPTOR_LIST_ATTR;
    AttributeID.End_Attribute_ID = 0;

    /* Finally submit the SDP Request. */
    Result = SDP_Service_Search_Attribute_Request(g_uiBluetoothStackID,
    RemoteBDAddr,
    1,
    &SDPUUIDEntry,
    1,
    &AttributeID,
    SDP_EventCallback,
    (unsigned long)0);

    if(Result > 0)
    {
    /* The SDP Request was submitted successfully. */
    Display(("SDP_Service_Search_Attribute_Request Success.\r\n"));

    /* Flag success to the caller. */
    ret_val = 0;
    }
    else
    {
    /* There was an error submitting the SDP Request. */
    Display(("SDP_Service_Search_Attribute_Request Failure: %d.\r\n"));

    /* Flag success to the caller. */
    ret_val = 0;
    }

    }
    else
    {
    /* No valid Bluetooth Stack ID exists. */
    ret_val = -1;
    }

    return(ret_val);
    }


    static int
    ExtractRFCOMMPortNumber(SDP_Service_Search_Attribute_Response_Data_t *SDPServiceSearchAttributeResponse, int *RFCOMMPortList)
    {
    int NumberOfAttributes;
    int NumberOfRecords;
    int RFCOMMChannel;
    int RetVal=-1;
    int Index;
    int RecordIndex;
    int NumberElements;
    int PortCount=0;
    UUID_128_t UUID_128;
    UUID_128_t RFCOMM_UUID;
    SDP_Data_Element_t *SDP_Data_Element;
    SDP_Data_Element_t *SDP_Data_Element1;

    SDP_ASSIGN_RFCOMM_UUID_128(RFCOMM_UUID);

    /* This is a response received when we queried Attribute ID 0x04 */
    NumberOfRecords = SDPServiceSearchAttributeResponse->Number_Service_Records;

    Display(("Number of Records: %d ", NumberOfRecords));

    for(RecordIndex = 0; RecordIndex < NumberOfRecords; RecordIndex++)
    {
    NumberOfAttributes = SDPServiceSearchAttributeResponse->SDP_Service_Attribute_Response_Data[RecordIndex].Number_Attribute_Values;

    if(NumberOfAttributes)
    {
    SDP_Data_Element = SDPServiceSearchAttributeResponse->SDP_Service_Attribute_Response_Data[RecordIndex].SDP_Service_Attribute_Value_Data[0].SDP_Data_Element;

    if((SDP_Data_Element->SDP_Data_Element_Type == deSequence) && (SDP_Data_Element->SDP_Data_Element_Length))
    {
    /* Data Element Sequence Exists, now */
    /* let's loop through the Data Element */
    /* Sequence. */
    for(Index=0; Index < SDP_Data_Element->SDP_Data_Element_Length;Index++)
    {
    if(((SDP_Data_Element1 = &(SDP_Data_Element->SDP_Data_Element.SDP_Data_Element_Sequence[Index])) != NULL) && (SDP_Data_Element1->SDP_Data_Element_Type == deSequence) && ((NumberElements = SDP_Data_Element1->SDP_Data_Element_Length) > 0) && ((SDP_Data_Element1 = SDP_Data_Element1->SDP_Data_Element.SDP_Data_Element_Sequence) != NULL))
    {
    if((SDP_Data_Element1->SDP_Data_Element_Type == deUUID_16) || (SDP_Data_Element1->SDP_Data_Element_Type == deUUID_32) || (SDP_Data_Element1->SDP_Data_Element_Type == deUUID_128))
    {
    /* Initialize the BASE UUID. */
    SDP_ASSIGN_BASE_UUID(UUID_128);

    switch(SDP_Data_Element1->SDP_Data_Element_Type)
    {
    case deUUID_16:
    /* First normal-lize the*/
    /* 16 Bit UUID to 128 */
    /* Bits. */
    ASSIGN_UUID_16_TO_UUID_128(UUID_128, SDP_Data_Element1->SDP_Data_Element.UUID_16);
    break;
    case deUUID_32:
    /* First normal-lize the*/
    /* 32 Bit UUID to 128 */
    /* Bits. */
    ASSIGN_UUID_32_TO_UUID_128(UUID_128, SDP_Data_Element1->SDP_Data_Element.UUID_32);
    break;
    case deUUID_128:
    /* Simply assign the */
    /* 128 Bit UUID to the */
    /* UUID value. */
    UUID_128 = SDP_Data_Element1->SDP_Data_Element.UUID_128;
    break;
    }

    /* Now let's check to see if */
    /* there is a match to RFCOMM */
    if((COMPARE_UUID_128(RFCOMM_UUID, UUID_128)) && (NumberElements > 1))
    {
    if(SDP_Data_Element1[1].SDP_Data_Element_Type == deUnsignedInteger1Byte)
    {
    RFCOMMChannel = SDP_Data_Element1[1].SDP_Data_Element.UnsignedInteger1Byte;

    /* Add server port to return data */
    RFCOMMPortList[PortCount] = RFCOMMChannel;
    PortCount++;
    RetVal = 0;
    }
    }
    }
    else
    {
    /* Some unknown Protocol */
    /* Descriptor, so just ignore */
    /* it. */
    }
    }
    }
    }
    }

    }

    return(RetVal);
    }
    ------------------------------------------------------------
    in bt_spp.c/where you want to initiate the SDP process
     BD_ADDR_t RemoteBDAddr;
    .
    .

    //You can also populate the variable another way, maybe use it from the inquiry data.
    // Code below shows how to hard-code it. 
     ASSIGN_BD_ADDR(RemoteBDAddr, 0x00, 0x19, 0x0E, 0x01, 0x64, 0x38);

    SPPServiceDiscovery(RemoteBDAddr);
    ------------------------------------------------------------------------------------------------------
    
    
    
    
    
    
    
    
    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • long to
    Posted by long to
    on Apr 02 2012 19:38 PM
    Prodigy80 points

    oh, I'll try.

    Thank you very much.

    I really appreciate it.

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • long to
    Posted by long to
    on Apr 06 2012 22:43 PM
    Prodigy80 points

    Hi StonestreetOne,

    I'm trying to implement your instruction but not success.

    I'm testing this function with my Android Phone.

    After  SPPServiceDiscovery(RemoteBDAddr);

    I got SDP_Service_Search_Attribute_Request Success.

    But after that, I received "Invalid size" in void BTPSAPI *BTPS_AllocateMemory(unsigned long MemorySize) with MemorySize =0

    and then SDP_EventCallback throw me into case rdConnectionError:

    I wrote an app on my Android phone, and I can debug that somehow there's a connection reaching from Kit but I don't know why it doesn't work

    Can you help me out?

    Thanks and Regards

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Stonestreet One Support
    Posted by Stonestreet One Support
    on Apr 17 2012 16:21 PM
    Verified Answer
    Verified by long to
    Genius3635 points

    Hello,

    Please make the following changes to two functions in BTPSKRNL.c The new functions are added at the end of this post. 

    static void *_Malloc(unsigned long Size)
    and
    [If you are using the safeRTOS version, noOS will not have this] Boolean_t BTPSAPI BTPS_WaitEvent(Event_t Event, unsigned long Timeout)
    
    
    Once you change those,  please try again. If you are still seeing the problem, then increase the memory for your application in bt_ucfg.h by changing the value of MEMORY_BUFFER_SIZE
    Try (24*1024)  
    #define MEMORY_BUFFER_SIZE             (24*1024)
    
    
    Let us know the observations and we will discuss it further.
    
    
    Best Regards,
    Stonestreet One.
    
    
    
    

    ----

     /* The following function is used to allocate a fragment of memory */
    /* from a large buffer. The function takes as its parameter the size*/
    /* in bytes of the fragment to be allocated. The function tries to */
    /* avoid fragmentation by obtaining memory requests larger than */
    /* LARGE_SIZE from the end of the buffer, while small fragments are */
    /* taken from the start of the buffer. */
    static void *_Malloc(unsigned long Size)
    {
    void *ret_val;
    HeapInfo_t *HeapInfoPtr;

    /* Verify that the heap has been initialized. */
    if(!HeapHead)
    HeapInit();

    /* Next make sure that the caller is actually requesting memory to be*/
    /* allocated. */
    if((Size) && (HeapHead))
    {
    /* Initialize the info pointer to the beginning of the list. */
    HeapInfoPtr = HeapHead;

    /* Make the size a multiple of the Alignment Size. */
    if(Size % ALIGNMENT_SIZE)
    Size += (ALIGNMENT_SIZE-(Size % ALIGNMENT_SIZE));

    /* Loop until we have looped back to the start of the list. */
    while(((Size >= LARGE_SIZE) && (HeapInfoPtr->Prev != HeapHead)) || ((Size < LARGE_SIZE) && (HeapInfoPtr->Next != HeapHead)))
    {
    /* Check to see if the current entry is free and is large */
    /* enough to hold the data being requested. */
    if((HeapInfoPtr->FragmentState == fsInUse) || (HeapInfoPtr->Size < Size))
    {
    /* If the requested size is larger then the limit then */
    /* search backwards for an available buffer, else go */
    /* forward. This will hopefully help to reduce */
    /* fragmentataion problems. */
    if(Size >= LARGE_SIZE)
    HeapInfoPtr = HeapInfoPtr->Prev;
    else
    HeapInfoPtr = HeapInfoPtr->Next;
    }
    else
    break;
    }

    /* Check to see if we are pointing to a block that is large */
    /* enough for the request. */
    if((HeapInfoPtr->FragmentState == fsFree) && (HeapInfoPtr->Size >= Size))
    {
    /* Check to see if we need to slit this into two entries. */
    /* * NOTE * If there is not enough room to make another entry */
    /* then we will not adjust the size of this entry to */
    /* match the amount requested. */
    if(HeapInfoPtr->Size > (Size + HEAP_INFO_DATA_SIZE(MINIMUM_MEMORY_SIZE)))
    {
    /* There will be enough left over to create another entry. */
    /* We need to insert a new entry into the list, so create a */
    /* new entry and link them by the Previous and Next */
    /* pointers. */
    if(Size >= LARGE_SIZE)
    ret_val = &((unsigned char *)HeapInfoPtr)[HEAP_INFO_DATA_SIZE(HeapInfoPtr->Size) - HEAP_INFO_DATA_SIZE(Size)];
    else
    ret_val = &((unsigned char *)HeapInfoPtr)[HEAP_INFO_DATA_SIZE(Size)];

    ((HeapInfo_t *)ret_val)->Next = HeapInfoPtr->Next;
    ((HeapInfo_t *)ret_val)->Prev = HeapInfoPtr;
    (HeapInfoPtr->Next)->Prev = (HeapInfo_t *)ret_val;
    HeapInfoPtr->Next = (HeapInfo_t *)ret_val;

    if(Size >= LARGE_SIZE)
    {
    HeapInfoPtr->Size -= HEAP_INFO_DATA_SIZE(Size);
    HeapInfoPtr = HeapInfoPtr->Next;
    HeapInfoPtr->FragmentState = fsInUse;
    HeapInfoPtr->Size = Size;
    }
    else
    {
    ((HeapInfo_t *)ret_val)->FragmentState = fsFree;
    ((HeapInfo_t *)ret_val)->Size = (HeapInfoPtr->Size - HEAP_INFO_DATA_SIZE(Size));
    HeapInfoPtr->Size = Size;
    HeapInfoPtr->FragmentState = fsInUse;
    }
    }
    else
    {
    /* Mark the buffer as In Use. */
    HeapInfoPtr->FragmentState = fsInUse;
    }

    /* Get the address of the start of RAM. */
    ret_val = (void *)&HeapInfoPtr->Data;
    }
    else
    ret_val = NULL;
    }
    else
    ret_val = NULL;

    return(ret_val);
    }
    ------------
     /* The following function is responsible for waiting for the */
    /* specified Event to become Signalled. This function accepts as */
    /* input the Event Handle to wait for, and the Timeout (specified */
    /* in Milliseconds) to wait for the Event to become Signalled. This */
    /* function returns TRUE if the Event was set to the Signalled */
    /* State (in the Timeout specified) or FALSE if either there was an */
    /* error OR the Event was not set to the Signalled State in the */
    /* specified Timeout. It should be noted that Signalls have a */
    /* special property in that multiple Threads can be waiting for the */
    /* Event to become Signalled and ALL calls to BTPS_WaitEvent() will */
    /* return TRUE whenever the state of the Event becomes Signalled. */
    Boolean_t BTPSAPI BTPS_WaitEvent(Event_t Event, unsigned long Timeout)
    {
    long Result;
    Boolean_t ret_val = FALSE;
    Byte_t Msg;
    unsigned long WaitTime;

    /* Verify that the parameter passed in appears valid. */
    if(Event)
    {
    if(Timeout == BTPS_INFINITE_WAIT)
    {
    WaitTime = portMAX_DELAY;
    }
    else
    {
    WaitTime = MILLISECONDS_TO_TICKS(Timeout);
    }

    do
    {
    /* Get a packet from the queue. */
    Result = xQueueReceive(((EventHeader_t *)Event)->EventHandle, &Msg, WaitTime);
    }while((Result == errSCHEDULER_IS_SUSPENDED) || ((Timeout == BTPS_INFINITE_WAIT) && (Result == errQUEUE_EMPTY)));

    if((Result != pdPASS) && (Result != errQUEUE_EMPTY))
    DBG_MSG(DBG_ZONE_BTPSKRNL,("Wait Event Error: %d, Timeout %d\n", Result, Timeout));
    else
    {
    /* Only reset the event if the wait was successful. */
    if(Result == pdPASS)
    xQueueSend(((EventHeader_t *)Event)->EventHandle, &Msg, 0);
    }
    ret_val = (Boolean_t)(Result == pdPASS);
    }
    else
    DBG_MSG(DBG_ZONE_BTPSKRNL,("NULL Event"));

    return(ret_val);
    }
    ---------------------------------------
    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
TI E2E™ Community
  • Support Forums
  • Blogs
  • Videos
  • Groups
  • Site Support & Feedback
  • Settings
TI E2E™ Community Groups
  • TI University Program
  • Make the Switch
  • Microcontroller Projects
  • Motor Drive & Control
Other Communities
  • Deyisupport
  • Designsomething.org
  • beagleboard.org
  • TI on Element 14
  • TI on TechXchangeSM
Other Technical & Support Resources
  • WEBENCH® Design Center
  • Product Information Centers
  • Technical Documents
  • TI Design Network
  • TI Technical Articles
  • TI Training

All content and materials on this site are provided "as is". TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with regard to these materials, including but not limited to all implied warranties and conditions of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with respect to these materials. No license, either express or implied, by estoppel or otherwise, is granted by TI. Use of the information on this site may require a license from a third party, or a license from TI.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms of Use of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms of Use of this site. TI, its suppliers and providers of content reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

Follow Us Texas Instruments on Facebook Texas Instruments on Twitter Texas Instruments on LinkedIn Texas Instruments on Google+
TI Worldwide | Contact Us | my.TI Login | Site Map | Corporate Citizenship | mobile m.ti.com (Mobile Version)

TI is a global semiconductor design and manufacturing company. Innovate with 100,000+ analog ICs and
embedded processors, along with software, tools and the industry’s largest sales/support staff.

© Copyright 1995-2013 Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy Policy | Terms of Use