]> granicus.if.org Git - esp-idf/blob - components/bt/bluedroid/common/include/common/bt_defs.h
Merge branch 'doc/versions' into 'master'
[esp-idf] / components / bt / bluedroid / common / include / common / bt_defs.h
1 // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 /**
16  * common/bt_defs.h    Defines useful API for whole Bluedroid
17  *
18  */
19 #ifndef _BT_DEFS_H_
20 #define _BT_DEFS_H_
21
22 #include <stdlib.h>
23 #include <stdint.h>
24 #include "common/bt_trace.h"
25 #include "common/bt_target.h"
26
27 #define UNUSED(x)                   (void)(x)
28
29 /*Timer Related Defination*/
30
31 //by Snake.T
32 typedef void (TIMER_CBACK)(void *p_tle);
33 typedef struct _tle {
34     struct _tle  *p_next;
35     struct _tle  *p_prev;
36     TIMER_CBACK  *p_cback;
37     INT32         ticks;
38     INT32         ticks_initial;
39     TIMER_PARAM_TYPE   param;
40     TIMER_PARAM_TYPE   data;
41     UINT16        event;
42     UINT8         in_use;
43 } TIMER_LIST_ENT;
44
45 #define alarm_timer_t               uint32_t
46 #define alarm_timer_setfn(timer, cb, data)           \
47 do {                                                 \
48 } while (0)
49 #define alarm_timer_arm(timer, to, periodic)         \
50 do {                                                 \
51 } while (0)
52 #define alarm_timer_disarm(timer)                    \
53 do {                                                 \
54 } while (0)
55 #define alarm_timer_now()             (0)
56
57
58 /*Bluetooth Address*/
59 typedef struct {
60     uint8_t address[6];
61 } __attribute__ ((__packed__)) bt_bdaddr_t;
62
63 /** Bluetooth 128-bit UUID */
64 typedef struct {
65     uint8_t uu[16];
66 } bt_uuid_t;
67
68 /** Bluetooth Error Status */
69 /** We need to build on this */
70
71 /* relate to ESP_BT_STATUS_xxx in esp_bt_defs.h */
72 typedef enum {
73     BT_STATUS_SUCCESS = 0,
74     BT_STATUS_FAIL,
75     BT_STATUS_NOT_READY,
76     BT_STATUS_NOMEM,
77     BT_STATUS_BUSY,
78     BT_STATUS_DONE,        /* request already completed */
79     BT_STATUS_UNSUPPORTED,
80     BT_STATUS_PARM_INVALID,
81     BT_STATUS_UNHANDLED,
82     BT_STATUS_AUTH_FAILURE,
83     BT_STATUS_RMT_DEV_DOWN,
84     BT_STATUS_AUTH_REJECTED,
85     BT_STATUS_INVALID_STATIC_RAND_ADDR,
86     BT_STATUS_PENDING,
87     BT_STATUS_UNACCEPT_CONN_INTERVAL,
88     BT_STATUS_PARAM_OUT_OF_RANGE,
89     BT_STATUS_TIMEOUT,
90     BT_STATUS_MEMORY_FULL,
91 } bt_status_t;
92
93 #ifndef CPU_LITTLE_ENDIAN
94 #define CPU_LITTLE_ENDIAN
95 #endif
96
97 inline uint16_t swap_byte_16(uint16_t x)
98 {
99     return (((x & 0x00ffU) << 8) |
100             ((x & 0xff00U) >> 8));
101 }
102
103 inline uint32_t swap_byte_32(uint32_t x)
104 {
105     return (((x & 0x000000ffUL) << 24) |
106             ((x & 0x0000ff00UL) << 8) |
107             ((x & 0x00ff0000UL) >> 8) |
108             ((x & 0xff000000UL) >> 24));
109 }
110
111 #ifndef ntohs
112 inline uint16_t ntohs(uint16_t x)
113 {
114 #ifdef CPU_LITTLE_ENDIAN
115     return swap_byte_16(x);
116 #else
117     return x;
118 #endif
119 }
120 #endif /* #ifndef ntohs */
121
122 #ifndef htons
123 inline uint16_t htons(uint16_t x)
124 {
125 #ifdef CPU_LITTLE_ENDIAN
126     return swap_byte_16(x);
127 #else
128     return x;
129 #endif
130 }
131 #endif /* #ifndef htons */
132
133 #ifndef ntohl
134 inline uint32_t ntohl(uint32_t x)
135 {
136 #ifdef CPU_LITTLE_ENDIAN
137     return swap_byte_32(x);
138 #else
139     return x;
140 #endif
141 }
142 #endif /* #ifndef ntohl*/
143
144 #ifndef htonl
145 inline uint32_t htonl(uint32_t x)
146 {
147 #ifdef CPU_LITTLE_ENDIAN
148     return swap_byte_32(x);
149 #else
150     return x;
151 #endif
152 }
153 #endif /* #ifndef htonl*/
154
155 #endif /* _BT_DEFS_H_ */