Update file header copyrights for 2012.
[pub/USBasp.git] / Demos / Host / Incomplete / BluetoothHost / Lib / BluetoothStack.c
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2012.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.lufa-lib.org
7 */
8
9 /*
10 Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
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.
20
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
28 this software.
29 */
30
31 /** \file
32 *
33 * Main module for the Bluetooth stack. This module contains the overall Bluetooth
34 * stack state variables and the main Bluetooth stack management functions.
35 */
36
37 #include "BluetoothStack.h"
38
39 /** Bluetooth device connection information structure. Once connected to a remote device, this structure tracks the
40 * connection state of the individual L2CAP channels.
41 */
42 Bluetooth_Connection_t Bluetooth_Connection = { IsConnected: false };
43
44 /** Bluetooth device state information structure. This structure contains details on the current Bluetooth stack
45 * state.
46 */
47 Bluetooth_Stack_State_t Bluetooth_State = { IsInitialized: false };
48
49 /** Bluetooth stack initialization function. This function must be called once to initialize the Bluetooth stack,
50 * ready for connection to remote devices.
51 *
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.
55 */
56 void Bluetooth_Stack_Init(void)
57 {
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;
61 }
62
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.
65 */
66 void Bluetooth_Stack_USBTask(void)
67 {
68 if (USB_HostState != HOST_STATE_Configured)
69 return;
70
71 Bluetooth_HCITask();
72 Bluetooth_ACLTask();
73 }
74