Oops - light weight ring buffer documentation used \ref instead of \param to document...
[pub/USBasp.git] / Demos / Host / Incomplete / BluetoothHost / Lib / BluetoothACLPackets.c
index 818caac..df8dfc5 100644 (file)
   this software.
 */
 
   this software.
 */
 
+/** \file
+ *
+ *  Bluetooth L2CAP layer management code. This module managed the creation,
+ *  configuration and teardown of L2CAP channels, and manages packet reception
+ *  and sending to and from other Bluetooth devices.
+ */
+
 /*
        TODO: Make SendPacket respect receiver's MTU
        TODO: Make ReceivePacket stitch together MTU fragments (?)
        TODO: Add channel opened/closed callbacks
 /*
        TODO: Make SendPacket respect receiver's MTU
        TODO: Make ReceivePacket stitch together MTU fragments (?)
        TODO: Add channel opened/closed callbacks
-       TODO: Figure out why delay is needed in connection for services
  */
 
 #define  INCLUDE_FROM_BLUETOOTH_ACLPACKETS_C
  */
 
 #define  INCLUDE_FROM_BLUETOOTH_ACLPACKETS_C
@@ -228,8 +234,10 @@ uint8_t Bluetooth_SendPacket(void* Data, const uint16_t DataLen, Bluetooth_Chann
        DataHeader.DestinationChannel         = (Channel == NULL) ? BT_CHANNEL_SIGNALING : Channel->RemoteNumber;
 
        Pipe_SelectPipe(BLUETOOTH_DATA_OUT_PIPE);
        DataHeader.DestinationChannel         = (Channel == NULL) ? BT_CHANNEL_SIGNALING : Channel->RemoteNumber;
 
        Pipe_SelectPipe(BLUETOOTH_DATA_OUT_PIPE);
+
+       Pipe_WaitUntilReady();
        Pipe_Unfreeze();
        Pipe_Unfreeze();
-       
+
        /* Write the packet contents to the pipe so that it can be sent to the remote device */
        Pipe_Write_Stream_LE(&ACLPacketHeader, sizeof(ACLPacketHeader));
        Pipe_Write_Stream_LE(&DataHeader, sizeof(DataHeader));
        /* Write the packet contents to the pipe so that it can be sent to the remote device */
        Pipe_Write_Stream_LE(&ACLPacketHeader, sizeof(ACLPacketHeader));
        Pipe_Write_Stream_LE(&DataHeader, sizeof(DataHeader));
@@ -248,7 +256,7 @@ uint8_t Bluetooth_SendPacket(void* Data, const uint16_t DataLen, Bluetooth_Chann
        return BT_SENDPACKET_NoError;
 }
 
        return BT_SENDPACKET_NoError;
 }
 
-/** Opens a bluetooth channel to the currently connected remote device, so that data can be exchanged.
+/** Opens a Bluetooth channel to the currently connected remote device, so that data can be exchanged.
  *
  *  \note The channel is not immediately opened when this function returns - it must undergo a two way
  *        connection and configuration process first as the main Bluetooth stack processing task is
  *
  *  \note The channel is not immediately opened when this function returns - it must undergo a two way
  *        connection and configuration process first as the main Bluetooth stack processing task is
@@ -311,7 +319,7 @@ Bluetooth_Channel_t* Bluetooth_OpenChannel(const uint16_t PSM)
        return ChannelData;
 }
 
        return ChannelData;
 }
 
-/** Closes a bluetooth channel that is open to the currently connected remote device, so that no further data
+/** Closes a Bluetooth channel that is open to the currently connected remote device, so that no further data
  *  can be exchanged.
  *
  *  \note The channel is not immediately closed when this function returns - it must undergo an asynchronous
  *  can be exchanged.
  *
  *  \note The channel is not immediately closed when this function returns - it must undergo an asynchronous
@@ -369,8 +377,6 @@ static inline void Bluetooth_Signal_ConnectionReq(const BT_Signal_Header_t* cons
        BT_ACL_DEBUG(2, "-- PSM: 0x%04X", ConnectionRequest.PSM);
        BT_ACL_DEBUG(2, "-- Source Channel: 0x%04X", ConnectionRequest.SourceChannel);
 
        BT_ACL_DEBUG(2, "-- PSM: 0x%04X", ConnectionRequest.PSM);
        BT_ACL_DEBUG(2, "-- Source Channel: 0x%04X", ConnectionRequest.SourceChannel);
 
-       _delay_ms(15); // TODO - Determine why this is needed
-       
        /* Try to retrieve the existing channel's information structure if it exists */
        Bluetooth_Channel_t* ChannelData = Bluetooth_GetChannelData(ConnectionRequest.SourceChannel, CHANNEL_SEARCH_REMOTENUMBER);
 
        /* Try to retrieve the existing channel's information structure if it exists */
        Bluetooth_Channel_t* ChannelData = Bluetooth_GetChannelData(ConnectionRequest.SourceChannel, CHANNEL_SEARCH_REMOTENUMBER);