]> granicus.if.org Git - esp-idf/blob - components/bt/bluedroid/common/include/common/bt_defs.h
Merge branch 'feature/gcov_dbg_stubs' 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 #ifndef SIZE_MAX
30 #define SIZE_MAX                    254
31 #endif
32 /*Timer Related Defination*/
33
34 //by Snake.T
35 typedef void (TIMER_CBACK)(void *p_tle);
36 typedef struct _tle {
37     struct _tle  *p_next;
38     struct _tle  *p_prev;
39     TIMER_CBACK  *p_cback;
40     INT32         ticks;
41     INT32         ticks_initial;
42     TIMER_PARAM_TYPE   param;
43     TIMER_PARAM_TYPE   data;
44     UINT16        event;
45     UINT8         in_use;
46 } TIMER_LIST_ENT;
47
48 #define alarm_timer_t               uint32_t
49 #define alarm_timer_setfn(timer, cb, data)           \
50 do {                                                 \
51 } while (0)
52 #define alarm_timer_arm(timer, to, periodic)         \
53 do {                                                 \
54 } while (0)
55 #define alarm_timer_disarm(timer)                    \
56 do {                                                 \
57 } while (0)
58 #define alarm_timer_now()             (0)
59
60
61 /*Bluetooth Address*/
62 typedef struct {
63     uint8_t address[6];
64 } __attribute__ ((__packed__)) bt_bdaddr_t;
65
66 /** Bluetooth 128-bit UUID */
67 typedef struct {
68     uint8_t uu[16];
69 } bt_uuid_t;
70
71 /** Bluetooth Error Status */
72 /** We need to build on this */
73
74 /* relate to ESP_BT_STATUS_xxx in esp_bt_defs.h */
75 typedef enum {
76     BT_STATUS_SUCCESS = 0,
77     BT_STATUS_FAIL,
78     BT_STATUS_NOT_READY,
79     BT_STATUS_NOMEM,
80     BT_STATUS_BUSY,
81     BT_STATUS_DONE,        /* request already completed */
82     BT_STATUS_UNSUPPORTED,
83     BT_STATUS_PARM_INVALID,
84     BT_STATUS_UNHANDLED,
85     BT_STATUS_AUTH_FAILURE,
86     BT_STATUS_RMT_DEV_DOWN,
87     BT_STATUS_AUTH_REJECTED,
88     BT_STATUS_INVALID_STATIC_RAND_ADDR,
89     BT_STATUS_PENDING,
90     BT_STATUS_UNACCEPT_CONN_INTERVAL,
91     BT_STATUS_PARAM_OUT_OF_RANGE,
92     BT_STATUS_TIMEOUT,
93     BT_STATUS_MEMORY_FULL,
94 } bt_status_t;
95
96 #ifndef CPU_LITTLE_ENDIAN
97 #define CPU_LITTLE_ENDIAN
98 #endif
99
100 inline uint16_t swap_byte_16(uint16_t x)
101 {
102     return (((x & 0x00ffU) << 8) |
103             ((x & 0xff00U) >> 8));
104 }
105
106 inline uint32_t swap_byte_32(uint32_t x)
107 {
108     return (((x & 0x000000ffUL) << 24) |
109             ((x & 0x0000ff00UL) << 8) |
110             ((x & 0x00ff0000UL) >> 8) |
111             ((x & 0xff000000UL) >> 24));
112 }
113
114 #ifndef ntohs
115 inline uint16_t ntohs(uint16_t x)
116 {
117 #ifdef CPU_LITTLE_ENDIAN
118     return swap_byte_16(x);
119 #else
120     return x;
121 #endif
122 }
123 #endif /* #ifndef ntohs */
124
125 #ifndef htons
126 inline uint16_t htons(uint16_t x)
127 {
128 #ifdef CPU_LITTLE_ENDIAN
129     return swap_byte_16(x);
130 #else
131     return x;
132 #endif
133 }
134 #endif /* #ifndef htons */
135
136 #ifndef ntohl
137 inline uint32_t ntohl(uint32_t x)
138 {
139 #ifdef CPU_LITTLE_ENDIAN
140     return swap_byte_32(x);
141 #else
142     return x;
143 #endif
144 }
145 #endif /* #ifndef ntohl*/
146
147 #ifndef htonl
148 inline uint32_t htonl(uint32_t x)
149 {
150 #ifdef CPU_LITTLE_ENDIAN
151     return swap_byte_32(x);
152 #else
153     return x;
154 #endif
155 }
156 #endif /* #ifndef htonl*/
157
158 #endif /* _BT_DEFS_H_ */