2016-07-04 00:37:38 +08:00
|
|
|
/* log.c - logging helpers */
|
|
|
|
|
|
|
|
/*
|
2017-05-10 22:27:16 +08:00
|
|
|
* Copyright (c) 2017 Nordic Semiconductor ASA
|
2016-07-04 00:37:38 +08:00
|
|
|
* Copyright (c) 2016 Intel Corporation
|
|
|
|
*
|
2017-01-19 09:01:01 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2016-07-04 00:37:38 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Helper for printk parameters to convert from binary to hex.
|
|
|
|
* We declare multiple buffers so the helper can be used multiple times
|
|
|
|
* in a single printk call.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stddef.h>
|
Introduce new sized integer typedefs
This is a start to move away from the C99 {u}int{8,16,32,64}_t types to
Zephyr defined u{8,16,32,64}_t and s{8,16,32,64}_t. This allows Zephyr
to define the sized types in a consistent manor across all the
architectures we support and not conflict with what various compilers
and libc might do with regards to the C99 types.
We introduce <zephyr/types.h> as part of this and have it include
<stdint.h> for now until we transition all the code away from the C99
types.
We go with u{8,16,32,64}_t and s{8,16,32,64}_t as there are some
existing variables defined u8 & u16 as well as to be consistent with
Zephyr naming conventions.
Jira: ZEP-2051
Change-Id: I451fed0623b029d65866622e478225dfab2c0ca8
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-04-19 23:32:08 +08:00
|
|
|
#include <zephyr/types.h>
|
2016-10-21 18:04:56 +08:00
|
|
|
#include <zephyr.h>
|
2016-07-04 00:37:38 +08:00
|
|
|
#include <misc/util.h>
|
2017-05-10 22:27:16 +08:00
|
|
|
#include <bluetooth/bluetooth.h>
|
|
|
|
#include <bluetooth/hci.h>
|
2016-07-04 00:37:38 +08:00
|
|
|
|
|
|
|
const char *bt_hex(const void *buf, size_t len)
|
|
|
|
{
|
|
|
|
static const char hex[] = "0123456789abcdef";
|
|
|
|
static char hexbufs[4][129];
|
2017-04-21 01:00:29 +08:00
|
|
|
static u8_t curbuf;
|
|
|
|
const u8_t *b = buf;
|
2016-07-04 00:37:38 +08:00
|
|
|
unsigned int mask;
|
|
|
|
char *str;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
mask = irq_lock();
|
|
|
|
str = hexbufs[curbuf++];
|
|
|
|
curbuf %= ARRAY_SIZE(hexbufs);
|
|
|
|
irq_unlock(mask);
|
|
|
|
|
|
|
|
len = min(len, (sizeof(hexbufs[0]) - 1) / 2);
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
str[i * 2] = hex[b[i] >> 4];
|
|
|
|
str[i * 2 + 1] = hex[b[i] & 0xf];
|
|
|
|
}
|
|
|
|
|
|
|
|
str[i * 2] = '\0';
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
2017-05-10 22:27:16 +08:00
|
|
|
|
|
|
|
#if defined(CONFIG_BLUETOOTH_DEBUG)
|
|
|
|
const char *bt_addr_str(const bt_addr_t *addr)
|
|
|
|
{
|
|
|
|
static char bufs[2][18];
|
|
|
|
static u8_t cur;
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
str = bufs[cur++];
|
|
|
|
cur %= ARRAY_SIZE(bufs);
|
|
|
|
bt_addr_to_str(addr, str, sizeof(bufs[cur]));
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *bt_addr_le_str(const bt_addr_le_t *addr)
|
|
|
|
{
|
|
|
|
static char bufs[2][27];
|
|
|
|
static u8_t cur;
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
str = bufs[cur++];
|
|
|
|
cur %= ARRAY_SIZE(bufs);
|
|
|
|
bt_addr_le_to_str(addr, str, sizeof(bufs[cur]));
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_BLUETOOTH_DEBUG */
|
|
|
|
|