blob: 36dab624bceedb0dff07fb15ac2b605fe5419592 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
/**
*******************************************************************************
*
* @file atm_co_utils.h
*
* @brief ATM bluetooth framework common utility functions
*
* Copyright (C) Atmosic 2020
*
*******************************************************************************
*/
#pragma once
/**
*******************************************************************************
* @defgroup ATM_CO_UTILS Common utilities
* @ingroup ATM_BTFM
* @brief ATM bluetooth framework common utility functions
*
* This module contains the common utilities functions and macros
* used by the bluetooth framework API.
*
* @{
*******************************************************************************
*/
#include "gap.h"
#include "co_utils.h"
#ifdef __cplusplus
extern "C" {
#endif
/// Macro to create a for-loop for a co_list
#define FOR_CO_LIST(co_list, type, hdlr) \
for (type hdlr = (type)co_list_pick(&co_list); hdlr; \
hdlr = (type)co_list_next(&hdlr->hdr)) \
/// Macro to create a for-loop for pop co_list FIFO
#define FOR_CO_LIST_POP(co_list, type, hdlr) \
for (type hdlr = (type)co_list_pop_front(&co_list); hdlr; \
hdlr = (type)co_list_pop_front(&co_list)) \
/// Redefine struct gap_bdaddr to gap_bdaddr_t
typedef struct gap_bdaddr gap_bdaddr_t;
/**
*******************************************************************************
* @brief Convert data type from bd_addr_t to struct bd_addr
* @param[in] addr address to convert
*
* @return addr pointer using struct bd_addr data type
*******************************************************************************
*/
__INLINE struct bd_addr const *atm_co_convert_bd_addr_type(bd_addr_t const *addr)
{
return (struct bd_addr const *)addr;
}
__INLINE bool atm_co_gap_addr_compare(gap_bdaddr_t const *addr1,
gap_bdaddr_t const *addr2)
{
return addr1 && addr2 && (addr1->addr_type == addr2->addr_type) &&
co_bdaddr_compare(atm_co_convert_bd_addr_type(&addr1->addr),
atm_co_convert_bd_addr_type(&addr2->addr));
}
/**
* @brief Covert 16 bits data endian.
*/
#define ATM_CO_BSWAP16(val16) (((val16 << 8) & 0xFF00) | ((val16 >> 8) & 0xFF))
__INLINE int atm_co_popcount(uint32_t x)
{
#ifdef __GNUC__
return __builtin_popcount(x);
#else
int i = 0;
for (; x; x &= x - 1) {
i++;
}
return i;
#endif
}
#ifdef __cplusplus
}
#endif
/// @} ATM_CO_UTILS
|