The new IS_ENABLED macro allows exposing conditionally enabled code always to the compiler, even though it may not ultimately end up being built. This is in particular useful for letting the compiler catch any logging format string errors. Introduce a new BT_DBG_ENABLED macro that c-files need to define before including <bluetooth/log.h> in order to choose whether BT_DBG() logs are enabled or not. When no Bluetooth logs are enabled the patch also modifies the log macros to have the format strings checked with the help of the __printf_like annotation and empty static inline functions. Change-Id: Ie6bc8e10727b5b306f3ed0f94089a07a22583d9b Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
54 lines
1.4 KiB
C
54 lines
1.4 KiB
C
/* log.c - logging helpers */
|
|
|
|
/*
|
|
* Copyright (c) 2016 Intel Corporation
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
/* 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>
|
|
#include <stdint.h>
|
|
#include <zephyr.h>
|
|
#include <misc/util.h>
|
|
|
|
const char *bt_hex(const void *buf, size_t len)
|
|
{
|
|
static const char hex[] = "0123456789abcdef";
|
|
static char hexbufs[4][129];
|
|
static uint8_t curbuf;
|
|
const uint8_t *b = buf;
|
|
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;
|
|
}
|