3      Copyright (C) Dean Camera, 2011. 
   5   dean [at] fourwalledcubicle [dot] com 
  10   Copyright 2011  Dean Camera (dean [at] fourwalledcubicle [dot] com) 
  12   Permission to use, copy, modify, distribute, and sell this 
  13   software and its documentation for any purpose is hereby granted 
  14   without fee, provided that the above copyright notice appear in 
  15   all copies and that both that the copyright notice and this 
  16   permission notice and warranty disclaimer appear in supporting 
  17   documentation, and that the name of the author not be used in 
  18   advertising or publicity pertaining to distribution of the 
  19   software without specific, written prior permission. 
  21   The author disclaim all warranties with regard to this 
  22   software, including all implied warranties of merchantability 
  23   and fitness.  In no event shall the author be liable for any 
  24   special, indirect or consequential damages or any damages 
  25   whatsoever resulting from loss of use, data or profits, whether 
  26   in an action of contract, negligence or other tortious action, 
  27   arising out of or in connection with the use or performance of 
  33  *  Main module for the Bluetooth stack. This module contains the overall Bluetooth 
  34  *  stack state variables and the main Bluetooth stack management functions. 
  37 #include "BluetoothStack.h" 
  39 /** Bluetooth device connection information structure. Once connected to a remote device, this structure tracks the 
  40  *  connection state of the individual L2CAP channels. 
  42 Bluetooth_Connection_t Bluetooth_Connection 
= { IsConnected
: false }; 
  44 /** Bluetooth device state information structure. This structure contains details on the current Bluetooth stack 
  47 Bluetooth_Stack_State_t Bluetooth_State     
= { IsInitialized
: false }; 
  49 /** Bluetooth stack initialization function. This function must be called once to initialize the Bluetooth stack, 
  50  *  ready for connection to remote devices. 
  52  *  \note This function only begins the initialization process; the stack is initialized as the main Bluetooth stack 
  53  *        management task is repeatedly called. The initialization process ends when the IsInitialized element of the 
  54  *        \ref Bluetooth_State structure becomes true and the \ref Bluetooth_StackInitialized() callback fires. 
  56 void Bluetooth_Stack_Init(void) 
  58         /* Reset the HCI state machine - this will reset the adapter and stack when the Bluetooth stack task is called */ 
  59         Bluetooth_State
.CurrentHCIState 
= Bluetooth_Init
; 
  60         Bluetooth_State
.NextHCIState    
= Bluetooth_Init
; 
  63 /** Bluetooth stack management task. This task must be repeatedly called to maintain the Bluetooth stack and any connection 
  64  *  to remote Bluetooth devices, including both the HCI control layer and the ACL channel layer. 
  66 void Bluetooth_Stack_USBTask(void) 
  68         if (USB_HostState 
!= HOST_STATE_Configured
)