1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

sys/*: replace #if ENABLE_DEBUG with IS_ACTIVE

This commit is contained in:
Bas Stottelaar 2020-10-23 00:40:57 +02:00
parent 9dd3b7a3ec
commit 922e2ac1c9
17 changed files with 207 additions and 221 deletions

View File

@ -312,13 +312,13 @@ static int _isotp_rcv_ff(struct isotp *isotp, struct can_frame *frame, int ae)
((uint8_t *)isotp->rx.snip->data)[isotp->rx.idx++] = frame->data[i]; ((uint8_t *)isotp->rx.snip->data)[isotp->rx.idx++] = frame->data[i];
} }
#if ENABLE_DEBUG if (IS_ACTIVE(ENABLE_DEBUG)) {
DEBUG("_isotp_rcv_ff: rx.buf="); DEBUG("_isotp_rcv_ff: rx.buf=");
for (unsigned i = 0; i < isotp->rx.idx; i++) { for (unsigned i = 0; i < isotp->rx.idx; i++) {
DEBUG("%02hhx", ((uint8_t *)isotp->rx.snip->data)[i]); DEBUG("%02hhx", ((uint8_t *)isotp->rx.snip->data)[i]);
}
DEBUG("\n");
} }
DEBUG("\n");
#endif
isotp->rx.sn = 1; isotp->rx.sn = 1;
@ -360,13 +360,13 @@ static int _isotp_rcv_cf(struct isotp *isotp, struct can_frame *frame, int ae)
} }
} }
#if ENABLE_DEBUG if (IS_ACTIVE(ENABLE_DEBUG)) {
DEBUG("_isotp_rcv_cf: rx.buf="); DEBUG("_isotp_rcv_cf: rx.buf=");
for (unsigned i = 0; i < isotp->rx.idx; i++) { for (unsigned i = 0; i < isotp->rx.idx; i++) {
DEBUG("%02hhx", ((uint8_t *)isotp->rx.snip->data)[i]); DEBUG("%02hhx", ((uint8_t *)isotp->rx.snip->data)[i]);
}
DEBUG("\n");
} }
DEBUG("\n");
#endif
if (isotp->rx.idx >= isotp->rx.snip->size) { if (isotp->rx.idx >= isotp->rx.snip->size) {
isotp->rx.state = ISOTP_IDLE; isotp->rx.state = ISOTP_IDLE;
@ -392,13 +392,13 @@ static int _isotp_rcv(struct isotp *isotp, struct can_frame *frame)
int ae = (isotp->opt.flags & CAN_ISOTP_EXTEND_ADDR) ? 1 : 0; int ae = (isotp->opt.flags & CAN_ISOTP_EXTEND_ADDR) ? 1 : 0;
uint8_t n_pci_type; uint8_t n_pci_type;
#if ENABLE_DEBUG if (IS_ACTIVE(ENABLE_DEBUG)) {
DEBUG("_isotp_rcv: id=%" PRIx32 " data=", frame->can_id); DEBUG("_isotp_rcv: id=%" PRIx32 " data=", frame->can_id);
for (int i = 0; i < frame->can_dlc; i++) { for (int i = 0; i < frame->can_dlc; i++) {
DEBUG("%02hhx", frame->data[i]); DEBUG("%02hhx", frame->data[i]);
}
DEBUG("\n");
} }
DEBUG("\n");
#endif
if (ae && frame->data[0] != isotp->opt.rx_ext_address) { if (ae && frame->data[0] != isotp->opt.rx_ext_address) {
return 1; return 1;
@ -448,13 +448,13 @@ static int _isotp_send_fc(struct isotp *isotp, int ae, uint8_t status)
isotp->rx.bs = 0; isotp->rx.bs = 0;
#if ENABLE_DEBUG if (IS_ACTIVE(ENABLE_DEBUG)) {
DEBUG("_isotp_send_fc: id=%" PRIx32 " data=", fc.can_id); DEBUG("_isotp_send_fc: id=%" PRIx32 " data=", fc.can_id);
for (int i = 0; i < fc.can_dlc; i++) { for (int i = 0; i < fc.can_dlc; i++) {
DEBUG("%02hhx", fc.data[i]); DEBUG("%02hhx", fc.data[i]);
}
DEBUG("\n");
} }
DEBUG("\n");
#endif
xtimer_set(&isotp->rx_timer, CAN_ISOTP_TIMEOUT_N_Ar); xtimer_set(&isotp->rx_timer, CAN_ISOTP_TIMEOUT_N_Ar);
isotp->rx.tx_handle = raw_can_send(isotp->entry.ifnum, &fc, isotp_pid); isotp->rx.tx_handle = raw_can_send(isotp->entry.ifnum, &fc, isotp_pid);

View File

@ -30,9 +30,7 @@
#include "assert.h" #include "assert.h"
#include "memarray.h" #include "memarray.h"
#ifdef MODULE_CAN_MBOX
#include "mbox.h" #include "mbox.h"
#endif
#define ENABLE_DEBUG 0 #define ENABLE_DEBUG 0
#include "debug.h" #include "debug.h"
@ -71,7 +69,7 @@ static void _insert_to_list(can_reg_entry_t **list, filter_el_t *el);
static filter_el_t *_find_filter_el(can_reg_entry_t *list, can_reg_entry_t *entry, canid_t can_id, canid_t mask, void *data); static filter_el_t *_find_filter_el(can_reg_entry_t *list, can_reg_entry_t *entry, canid_t can_id, canid_t mask, void *data);
static int _filter_is_used(unsigned int ifnum, canid_t can_id, canid_t mask); static int _filter_is_used(unsigned int ifnum, canid_t can_id, canid_t mask);
#if ENABLE_DEBUG #if IS_ACTIVE(ENABLE_DEBUG)
static void _print_filters(void) static void _print_filters(void)
{ {
for (int i = 0; i < (int)CAN_DLL_NUMOF; i++) { for (int i = 0; i < (int)CAN_DLL_NUMOF; i++) {
@ -84,7 +82,6 @@ static void _print_filters(void)
} }
} }
} }
#define PRINT_FILTERS() _print_filters() #define PRINT_FILTERS() _print_filters()
#else #else
#define PRINT_FILTERS() #define PRINT_FILTERS()
@ -214,13 +211,15 @@ int can_router_register(can_reg_entry_t *entry, canid_t can_id, canid_t mask, vo
filter_el_t *filter; filter_el_t *filter;
int ret; int ret;
#if ENABLE_DEBUG #ifdef MODULE_CAN_MBOX
if (entry->type == CAN_TYPE_DEFAULT) { if (IS_ACTIVE(ENABLE_DEBUG)) {
DEBUG("can_router_register: ifnum=%d, pid=%" PRIkernel_pid ", can_id=0x%" PRIx32 if (entry->type == CAN_TYPE_DEFAULT) {
", mask=0x%" PRIx32 ", data=%p\n", entry->ifnum, entry->target.pid, can_id, mask, param); DEBUG("can_router_register: ifnum=%d, pid=%" PRIkernel_pid ", can_id=0x%" PRIx32
} else if (entry->type == CAN_TYPE_MBOX) { ", mask=0x%" PRIx32 ", data=%p\n", entry->ifnum, entry->target.pid, can_id, mask, param);
DEBUG("can_router_register: ifnum=%d, mbox=%p, can_id=0x%" PRIx32 } else if (entry->type == CAN_TYPE_MBOX) {
", mask=0x%" PRIx32 ", data=%p\n", entry->ifnum, (void *)entry->target.mbox, can_id, mask, param); DEBUG("can_router_register: ifnum=%d, mbox=%p, can_id=0x%" PRIx32
", mask=0x%" PRIx32 ", data=%p\n", entry->ifnum, (void *)entry->target.mbox, can_id, mask, param);
}
} }
#endif #endif
@ -263,13 +262,15 @@ int can_router_unregister(can_reg_entry_t *entry, canid_t can_id,
filter_el_t *el; filter_el_t *el;
int ret; int ret;
#if ENABLE_DEBUG #ifdef MODULE_CAN_MBOX
if (entry->type == CAN_TYPE_DEFAULT) { if (IS_ACTIVE(ENABLE_DEBUG)) {
DEBUG("can_router_unregister: ifnum=%d, pid=%" PRIkernel_pid ", can_id=0x%" PRIx32 if (entry->type == CAN_TYPE_DEFAULT) {
", mask=0x%" PRIx32 ", data=%p", entry->ifnum, entry->target.pid, can_id, mask, param); DEBUG("can_router_unregister: ifnum=%d, pid=%" PRIkernel_pid ", can_id=0x%" PRIx32
} else if (entry->type == CAN_TYPE_MBOX) { ", mask=0x%" PRIx32 ", data=%p", entry->ifnum, entry->target.pid, can_id, mask, param);
DEBUG("can_router_unregister: ifnum=%d, mbox=%p, can_id=0x%" PRIx32 } else if (entry->type == CAN_TYPE_MBOX) {
", mask=0x%" PRIx32 ", data=%p\n", entry->ifnum, (void *)entry->target.mbox, can_id, mask, param); DEBUG("can_router_unregister: ifnum=%d, mbox=%p, can_id=0x%" PRIx32
", mask=0x%" PRIx32 ", data=%p\n", entry->ifnum, (void *)entry->target.mbox, can_id, mask, param);
}
} }
#endif #endif
@ -317,9 +318,8 @@ int can_router_dispatch_rx_indic(can_pkt_t *pkt)
int res = 0; int res = 0;
msg_t msg; msg_t msg;
msg.type = CAN_MSG_RX_INDICATION; msg.type = CAN_MSG_RX_INDICATION;
#if ENABLE_DEBUG
int msg_cnt = 0; int msg_cnt = 0;
#endif
DEBUG("can_router_dispatch_rx_indic: pkt=%p, ifnum=%d, can_id=%" PRIx32 "\n", DEBUG("can_router_dispatch_rx_indic: pkt=%p, ifnum=%d, can_id=%" PRIx32 "\n",
(void *)pkt, pkt->entry.ifnum, pkt->frame.can_id); (void *)pkt, pkt->entry.ifnum, pkt->frame.can_id);
@ -335,9 +335,11 @@ int can_router_dispatch_rx_indic(can_pkt_t *pkt)
PRIkernel_pid "\n", entry->target.pid); PRIkernel_pid "\n", entry->target.pid);
atomic_fetch_add(&pkt->ref_count, 1); atomic_fetch_add(&pkt->ref_count, 1);
msg.content.ptr = can_pkt_alloc_rx_data(&pkt->frame, sizeof(pkt->frame), el->data); msg.content.ptr = can_pkt_alloc_rx_data(&pkt->frame, sizeof(pkt->frame), el->data);
#if ENABLE_DEBUG
msg_cnt++; if (IS_ACTIVE(ENABLE_DEBUG)) {
#endif msg_cnt++;
}
if (!msg.content.ptr || (_send_msg(&msg, entry) <= 0)) { if (!msg.content.ptr || (_send_msg(&msg, entry) <= 0)) {
can_pkt_free_rx_data(msg.content.ptr); can_pkt_free_rx_data(msg.content.ptr);
atomic_fetch_sub(&pkt->ref_count, 1); atomic_fetch_sub(&pkt->ref_count, 1);
@ -349,9 +351,9 @@ int can_router_dispatch_rx_indic(can_pkt_t *pkt)
} }
} }
mutex_unlock(&lock); mutex_unlock(&lock);
#if ENABLE_DEBUG
DEBUG("can_router_dispatch_rx: msg send to %d threads\n", msg_cnt); DEBUG("can_router_dispatch_rx: msg send to %d threads\n", msg_cnt);
#endif
if (atomic_load(&pkt->ref_count) == 0) { if (atomic_load(&pkt->ref_count) == 0) {
can_pkt_free(pkt); can_pkt_free(pkt);
} }

View File

@ -45,15 +45,9 @@
#include "bitarithm.h" #include "bitarithm.h"
#include "ecc/golay2412.h" #include "ecc/golay2412.h"
#define ENABLE_DEBUG 0 #define ENABLE_DEBUG 0
#include "debug.h" #include "debug.h"
#if ENABLE_DEBUG
#define DEBUG_FEC_GOLAY2412 (1)
#else
#define DEBUG_FEC_GOLAY2412 (0)
#endif
/* generator matrix transposed [24 x 12] */ /* generator matrix transposed [24 x 12] */
static const uint32_t golay2412_Gt[24] = { static const uint32_t golay2412_Gt[24] = {
0x08ed, 0x01db, 0x03b5, 0x0769, 0x0ed1, 0x0da3, 0x0b47, 0x068f, 0x08ed, 0x01db, 0x03b5, 0x0769, 0x0ed1, 0x0da3, 0x0b47, 0x068f,
@ -75,7 +69,6 @@ static const uint32_t golay2412_H[12] = {
0x00008d1d, 0x00004a3b, 0x00002477, 0x00001ffe 0x00008d1d, 0x00004a3b, 0x00002477, 0x00001ffe
}; };
#if DEBUG_FEC_GOLAY2412
/* print string of bits to standard output */ /* print string of bits to standard output */
static inline void liquid_print_bitstring(uint32_t _x, static inline void liquid_print_bitstring(uint32_t _x,
uint32_t _n) uint32_t _n)
@ -86,7 +79,6 @@ static inline void liquid_print_bitstring(uint32_t _x,
printf("%" PRIu32, (_x >> (_n - i - 1)) & 1); printf("%" PRIu32, (_x >> (_n - i - 1)) & 1);
} }
} }
#endif
#ifndef NDEBUG #ifndef NDEBUG
static uint32_t block_get_enc_msg_len(uint32_t _dec_msg_len, static uint32_t block_get_enc_msg_len(uint32_t _dec_msg_len,
@ -107,16 +99,15 @@ static uint32_t block_get_enc_msg_len(uint32_t _dec_msg_len,
/* compute total number of bytes out: ceil(num_bits_out/8) */ /* compute total number of bytes out: ceil(num_bits_out/8) */
uint32_t num_bytes_out = num_bits_out / 8 + ((num_bits_out % 8) ? 1 : 0); uint32_t num_bytes_out = num_bits_out / 8 + ((num_bits_out % 8) ? 1 : 0);
#if DEBUG_FEC_GOLAY2412 DEBUG("block_get_enc_msg_len(%" PRIu32 ",%" PRIu32 ",%" PRIu32 ")\n",
printf("block_get_enc_msg_len(%" PRIu32 ",%" PRIu32 ",%" PRIu32 ")\n", _dec_msg_len, _m, _k); _dec_msg_len, _m, _k);
printf(" dec msg len : %" PRIu32 " bytes\n", _dec_msg_len); DEBUG(" dec msg len : %" PRIu32 " bytes\n", _dec_msg_len);
printf(" m : %" PRIu32 " bits\n", _m); DEBUG(" m : %" PRIu32 " bits\n", _m);
printf(" k : %" PRIu32 " bits\n", _k); DEBUG(" k : %" PRIu32 " bits\n", _k);
printf(" num bits in : %" PRIu32 " bits\n", num_bits_in); DEBUG(" num bits in : %" PRIu32 " bits\n", num_bits_in);
printf(" num blocks : %" PRIu32 "\n", num_blocks); DEBUG(" num blocks : %" PRIu32 "\n", num_blocks);
printf(" num bits out: %" PRIu32 " bits\n", num_bits_out); DEBUG(" num bits out: %" PRIu32 " bits\n", num_bits_out);
printf(" enc msg len : %" PRIu32 " bytes\n", num_bytes_out); DEBUG(" enc msg len : %" PRIu32 " bytes\n", num_bytes_out);
#endif
return num_bytes_out; return num_bytes_out;
} }
@ -187,84 +178,75 @@ static uint32_t golay2412_decode_symbol(uint32_t _sym_enc,
/* compute syndrome vector, s = r*H^T = ( H*r^T )^T */ /* compute syndrome vector, s = r*H^T = ( H*r^T )^T */
s = golay2412_matrix_mul(_sym_enc, _B, 12); s = golay2412_matrix_mul(_sym_enc, _B, 12);
#if DEBUG_FEC_GOLAY2412 if (IS_ACTIVE(ENABLE_DEBUG)) {
printf("s (syndrome vector): "); liquid_print_bitstring(s, 12); printf("\n"); printf("s (syndrome vector): ");
#endif liquid_print_bitstring(s, 12);
printf("\n");
}
/* compute weight of s (12 bits) */ /* compute weight of s (12 bits) */
uint8_t ws = bitarithm_bits_set_u32(s & 0x00000fff); uint8_t ws = bitarithm_bits_set_u32(s & 0x00000fff);
#if DEBUG_FEC_GOLAY2412 DEBUG("w(s) = %u\n", ws);
printf("w(s) = %u\n", ws);
#endif
/* step 2: */ /* step 2: */
e_hat = 0; e_hat = 0;
if (ws <= 3) { if (ws <= 3) {
#if DEBUG_FEC_GOLAY2412 DEBUG(" w(s) <= 3: estimating error vector as [s, 0(12)]\n");
printf(" w(s) <= 3: estimating error vector as [s, 0(12)]\n");
#endif
/* set e_hat = [s 0(12)] */ /* set e_hat = [s 0(12)] */
e_hat = (s << 12) & 0xfff000; e_hat = (s << 12) & 0xfff000;
} }
else { else {
/* step 3: search for p[i] s.t. w(s+p[i]) <= 2 */ /* step 3: search for p[i] s.t. w(s+p[i]) <= 2 */
#if DEBUG_FEC_GOLAY2412 DEBUG(" searching for w(s + p_i) <= 2...\n");
printf(" searching for w(s + p_i) <= 2...\n");
#endif
int8_t s_index = golay2412_parity_search(s, _A); int8_t s_index = golay2412_parity_search(s, _A);
if (s_index >= 0) { if (s_index >= 0) {
/* vector found! */ /* vector found! */
#if DEBUG_FEC_GOLAY2412 DEBUG(" w(s + p[%2i]) <= 2: estimating error vector as "
printf(" w(s + p[%2i]) <= 2: estimating error vector as [s+p[%2i]," "[s+p[%2i],u[%2i]]\n", s_index, s_index, s_index);
"u[%2i]]\n", s_index, s_index, s_index);
#endif
/* NOTE : uj = 1 << (12-j-1) */ /* NOTE : uj = 1 << (12-j-1) */
e_hat = ((s ^ _A[s_index]) << 12) | (1 << (11 - s_index)); e_hat = ((s ^ _A[s_index]) << 12) | (1 << (11 - s_index));
} }
else { else {
/* step 4: compute s*P */ /* step 4: compute s*P */
uint32_t sP = golay2412_matrix_mul(s, _A, 12); uint32_t sP = golay2412_matrix_mul(s, _A, 12);
#if DEBUG_FEC_GOLAY2412
printf("s*P: "); liquid_print_bitstring(sP, 12); printf("\n"); if (IS_ACTIVE(ENABLE_DEBUG)) {
#endif printf("s*P: ");
liquid_print_bitstring(sP, 12);
printf("\n");
}
/* compute weight of sP (12 bits) */ /* compute weight of sP (12 bits) */
uint8_t wsP = bitarithm_bits_set_u32(sP & 0x00000fff); uint8_t wsP = bitarithm_bits_set_u32(sP & 0x00000fff);
#if DEBUG_FEC_GOLAY2412 DEBUG("w(s*P) = %u\n", wsP);
printf("w(s*P) = %u\n", wsP);
#endif
if (wsP == 2 || wsP == 3) { if (wsP == 2 || wsP == 3) {
/* step 5: set e = [0, s*P] */ /* step 5: set e = [0, s*P] */
#if DEBUG_FEC_GOLAY2412 DEBUG(" w(s*P) in [2,3]: estimating error vector as "
printf(" w(s*P) in [2,3]: estimating error vector as [0(12), s*P]\n"); "[0(12), s*P]\n");
#endif
e_hat = sP; e_hat = sP;
} }
else { else {
/* step 6: search for p[i] s.t. w(s*P + p[i]) == 2... */ /* step 6: search for p[i] s.t. w(s*P + p[i]) == 2... */
DEBUG(" searching for w(s*P + p_i) == 2...\n");
#if DEBUG_FEC_GOLAY2412
printf(" searching for w(s*P + p_i) == 2...\n");
#endif
int8_t sP_index = golay2412_parity_search(sP, _A); int8_t sP_index = golay2412_parity_search(sP, _A);
if (sP_index >= 0) { if (sP_index >= 0) {
/* vector found! */ /* vector found! */
#if DEBUG_FEC_GOLAY2412 DEBUG(" w(s*P + p[%2i]) == 2: estimating error vector "
printf(" w(s*P + p[%2i]) == 2: estimating error vector as [u[%2i]," "as [u[%2i],s*P+p[%2i]]\n",
"s*P+p[%2i]]\n", sP_index, sP_index, sP_index); sP_index, sP_index, sP_index);
#endif
/* NOTE : uj = 1 << (12-j-1) /* NOTE : uj = 1 << (12-j-1)
* [ uj << 1 2 ] [ sP + p[j] ] */ * [ uj << 1 2 ] [ sP + p[j] ] */
e_hat = (1L << (23 - sP_index)) | (sP ^ _A[sP_index]); e_hat = (1L << (23 - sP_index)) | (sP ^ _A[sP_index]);
} }
else { else {
/* step 7: decoding error */ /* step 7: decoding error */
#if DEBUG_FEC_GOLAY2412 DEBUG(" **** decoding error\n");
printf(" **** decoding error\n");
#endif
} }
} }
} }
@ -272,14 +254,15 @@ static uint32_t golay2412_decode_symbol(uint32_t _sym_enc,
/* step 8: compute estimated transmitted message: v_hat = r + e_hat */ /* step 8: compute estimated transmitted message: v_hat = r + e_hat */
v_hat = _sym_enc ^ e_hat; v_hat = _sym_enc ^ e_hat;
#if DEBUG_FEC_GOLAY2412
printf("r (received vector): "); if (IS_ACTIVE(ENABLE_DEBUG)) {
liquid_print_bitstring(_sym_enc, 24); printf("\n"); printf("r (received vector): ");
printf("e-hat (estimated error vector): "); liquid_print_bitstring(_sym_enc, 24); printf("\n");
liquid_print_bitstring(e_hat, 24); printf("\n"); printf("e-hat (estimated error vector): ");
printf("v-hat (estimated tx vector): "); liquid_print_bitstring(e_hat, 24); printf("\n");
liquid_print_bitstring(v_hat, 24); printf("\n"); printf("v-hat (estimated tx vector): ");
#endif liquid_print_bitstring(v_hat, 24); printf("\n");
}
/* compute estimated original message: (last 12 bits of encoded message) */ /* compute estimated original message: (last 12 bits of encoded message) */
m_hat = v_hat & 0x0fff; m_hat = v_hat & 0x0fff;

View File

@ -332,40 +332,43 @@ static inline dhcpv6_opt_t *_opt_next(dhcpv6_opt_t *opt)
static bool _check_status_opt(dhcpv6_opt_status_t *status) static bool _check_status_opt(dhcpv6_opt_status_t *status)
{ {
/* DHCPV6_STATUS_SUCCESS is 0, so we don't need to fix byte order */ if (IS_ACTIVE(ENABLE_DEBUG)) {
#if ENABLE_DEBUG if ((status != NULL) && (status->code.u16 != DHCPV6_STATUS_SUCCESS)) {
if ((status != NULL) && (status->code.u16 != DHCPV6_STATUS_SUCCESS)) { size_t msg_len = byteorder_ntohs(status->len);
size_t msg_len = byteorder_ntohs(status->len); char msg[msg_len - 1];
char msg[msg_len - 1];
strncpy(msg, status->msg, msg_len - 2); strncpy(msg, status->msg, msg_len - 2);
DEBUG("DHCPv6 client: server returned error (%u) \"%s\"\n", DEBUG("DHCPv6 client: server returned error (%u) \"%s\"\n",
byteorder_ntohs(status->code), msg); byteorder_ntohs(status->code), msg);
}
} }
#endif
/* DHCPV6_STATUS_SUCCESS is 0, so we don't need to fix byte order */
return (status == NULL) || (status->code.u16 == DHCPV6_STATUS_SUCCESS); return (status == NULL) || (status->code.u16 == DHCPV6_STATUS_SUCCESS);
} }
static bool _check_cid_opt(dhcpv6_opt_duid_t *cid) static bool _check_cid_opt(dhcpv6_opt_duid_t *cid)
{ {
#if ENABLE_DEBUG if (IS_ACTIVE(ENABLE_DEBUG)) {
if ((byteorder_ntohs(cid->len) != duid_len) || if ((byteorder_ntohs(cid->len) != duid_len) ||
(memcmp(cid->duid, duid, duid_len) != 0)) { (memcmp(cid->duid, duid, duid_len) != 0)) {
DEBUG("DHCPv6 client: message is not for me\n"); DEBUG("DHCPv6 client: message is not for me\n");
}
} }
#endif
return ((byteorder_ntohs(cid->len) == duid_len) && return ((byteorder_ntohs(cid->len) == duid_len) &&
(memcmp(cid->duid, duid, duid_len) == 0)); (memcmp(cid->duid, duid, duid_len) == 0));
} }
static bool _check_sid_opt(dhcpv6_opt_duid_t *sid) static bool _check_sid_opt(dhcpv6_opt_duid_t *sid)
{ {
#if ENABLE_DEBUG if (IS_ACTIVE(ENABLE_DEBUG)) {
if ((byteorder_ntohs(sid->len) != server.duid_len) || if ((byteorder_ntohs(sid->len) != server.duid_len) ||
(memcmp(sid->duid, server.duid.u8, server.duid_len) != 0)) { (memcmp(sid->duid, server.duid.u8, server.duid_len) != 0)) {
DEBUG("DHCPv6 client: message is not from my server\n"); DEBUG("DHCPv6 client: message is not from my server\n");
}
} }
#endif
return ((byteorder_ntohs(sid->len) == server.duid_len) && return ((byteorder_ntohs(sid->len) == server.duid_len) &&
(memcmp(sid->duid, server.duid.u8, server.duid_len) == 0)); (memcmp(sid->duid, server.duid.u8, server.duid_len) == 0));
} }

View File

@ -25,14 +25,15 @@ uint16_t inet_csum_slice(uint16_t sum, const uint8_t *buf, uint16_t len, size_t
uint32_t csum = sum; uint32_t csum = sum;
DEBUG("inet_sum: sum = 0x%04" PRIx16 ", len = %" PRIu16, sum, len); DEBUG("inet_sum: sum = 0x%04" PRIx16 ", len = %" PRIu16, sum, len);
#if ENABLE_DEBUG
#ifdef MODULE_OD if (IS_ACTIVE(ENABLE_DEBUG)) {
DEBUG(", buf:\n"); if (IS_USED(MODULE_OD)) {
od_hex_dump(buf, len, OD_WIDTH_DEFAULT); DEBUG(", buf:\n");
#else od_hex_dump(buf, len, OD_WIDTH_DEFAULT);
DEBUG(", buf output only with od module\n"); } else {
#endif DEBUG(", buf output only with od module\n");
#endif }
}
if (len == 0) if (len == 0)
return csum; return csum;

View File

@ -25,6 +25,7 @@
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#include "od.h"
#include "timex.h" #include "timex.h"
#include "random.h" #include "random.h"
#include "periph/rtt.h" #include "periph/rtt.h"
@ -166,9 +167,6 @@ static gnrc_pktsnip_t *_recv(gnrc_netif_t *netif)
if (!(state->flags & NETDEV_IEEE802154_RAW)) { if (!(state->flags & NETDEV_IEEE802154_RAW)) {
gnrc_pktsnip_t *ieee802154_hdr, *netif_hdr; gnrc_pktsnip_t *ieee802154_hdr, *netif_hdr;
gnrc_netif_hdr_t *hdr; gnrc_netif_hdr_t *hdr;
#if ENABLE_DEBUG
char src_str[GNRC_NETIF_HDR_L2ADDR_PRINT_LEN];
#endif
size_t mhr_len = ieee802154_get_frame_hdr_len(pkt->data); size_t mhr_len = ieee802154_get_frame_hdr_len(pkt->data);
if (mhr_len == 0) { if (mhr_len == 0) {
@ -207,16 +205,19 @@ static gnrc_pktsnip_t *_recv(gnrc_netif_t *netif)
hdr->rssi = rx_info.rssi; hdr->rssi = rx_info.rssi;
gnrc_netif_hdr_set_netif(hdr, netif); gnrc_netif_hdr_set_netif(hdr, netif);
pkt->type = state->proto; pkt->type = state->proto;
#if ENABLE_DEBUG if (IS_ACTIVE(ENABLE_DEBUG)) {
DEBUG("_recv_ieee802154: received packet from %s of length %u\n", char src_str[GNRC_NETIF_HDR_L2ADDR_PRINT_LEN];
gnrc_netif_addr_to_str(src_str, sizeof(src_str),
gnrc_netif_hdr_get_src_addr(hdr), DEBUG("_recv_ieee802154: received packet from %s of length %u\n",
hdr->src_l2addr_len), gnrc_netif_addr_to_str(gnrc_netif_hdr_get_src_addr(hdr),
nread); hdr->src_l2addr_len,
#if defined(MODULE_OD) src_str),
od_hex_dump(pkt->data, nread, OD_WIDTH_DEFAULT); nread);
#endif
#endif if (IS_USED(MODULE_OD)) {
od_hex_dump(pkt->data, nread, OD_WIDTH_DEFAULT);
}
}
gnrc_pktbuf_remove_snip(pkt, ieee802154_hdr); gnrc_pktbuf_remove_snip(pkt, ieee802154_hdr);
pkt = gnrc_pkt_append(pkt, netif_hdr); pkt = gnrc_pkt_append(pkt, netif_hdr);
} }
@ -923,10 +924,8 @@ static void _lwmac_msg_handler(gnrc_netif_t *netif, msg_t *msg)
} }
#endif #endif
default: { default: {
#if ENABLE_DEBUG DEBUG("[LWMAC]: unknown message type 0x%04x "
DEBUG("[LWMAC]: unknown message type 0x%04x"
"(no message handler defined)\n", msg->type); "(no message handler defined)\n", msg->type);
#endif
break; break;
} }
} }

View File

@ -24,9 +24,7 @@
#define ENABLE_DEBUG 0 #define ENABLE_DEBUG 0
#include "debug.h" #include "debug.h"
#if defined(MODULE_OD) && ENABLE_DEBUG
#include "od.h" #include "od.h"
#endif
static int _send(gnrc_netif_t *netif, gnrc_pktsnip_t *pkt); static int _send(gnrc_netif_t *netif, gnrc_pktsnip_t *pkt);
static gnrc_pktsnip_t *_recv(gnrc_netif_t *netif); static gnrc_pktsnip_t *_recv(gnrc_netif_t *netif);
@ -138,9 +136,6 @@ static gnrc_pktsnip_t *_recv(gnrc_netif_t *netif)
/* Normal mode, try to parse the frame according to IEEE 802.15.4 */ /* Normal mode, try to parse the frame according to IEEE 802.15.4 */
gnrc_pktsnip_t *ieee802154_hdr, *netif_hdr; gnrc_pktsnip_t *ieee802154_hdr, *netif_hdr;
gnrc_netif_hdr_t *hdr; gnrc_netif_hdr_t *hdr;
#if ENABLE_DEBUG
char src_str[GNRC_NETIF_HDR_L2ADDR_PRINT_LEN];
#endif
size_t mhr_len = ieee802154_get_frame_hdr_len(pkt->data); size_t mhr_len = ieee802154_get_frame_hdr_len(pkt->data);
/* nread was checked for <= 0 before so we can safely cast it to /* nread was checked for <= 0 before so we can safely cast it to
@ -193,16 +188,18 @@ static gnrc_pktsnip_t *_recv(gnrc_netif_t *netif)
hdr->rssi = rx_info.rssi; hdr->rssi = rx_info.rssi;
gnrc_netif_hdr_set_netif(hdr, netif); gnrc_netif_hdr_set_netif(hdr, netif);
dev->driver->get(dev, NETOPT_PROTO, &pkt->type, sizeof(pkt->type)); dev->driver->get(dev, NETOPT_PROTO, &pkt->type, sizeof(pkt->type));
#if ENABLE_DEBUG if (IS_ACTIVE(ENABLE_DEBUG)) {
DEBUG("_recv_ieee802154: received packet from %s of length %u\n", char src_str[GNRC_NETIF_HDR_L2ADDR_PRINT_LEN];
gnrc_netif_addr_to_str(gnrc_netif_hdr_get_src_addr(hdr),
hdr->src_l2addr_len, DEBUG("_recv_ieee802154: received packet from %s of length %u\n",
src_str), gnrc_netif_addr_to_str(gnrc_netif_hdr_get_src_addr(hdr),
nread); hdr->src_l2addr_len,
#if defined(MODULE_OD) src_str),
od_hex_dump(pkt->data, nread, OD_WIDTH_DEFAULT); nread);
#endif if (IS_USED(MODULE_OD)) {
#endif od_hex_dump(pkt->data, nread, OD_WIDTH_DEFAULT);
}
}
gnrc_pktbuf_remove_snip(pkt, ieee802154_hdr); gnrc_pktbuf_remove_snip(pkt, ieee802154_hdr);
pkt = gnrc_pkt_append(pkt, netif_hdr); pkt = gnrc_pkt_append(pkt, netif_hdr);
} }

View File

@ -43,7 +43,7 @@
#define ENABLE_DEBUG 0 #define ENABLE_DEBUG 0
#include "debug.h" #include "debug.h"
#if ENABLE_DEBUG #if IS_ACTIVE(ENABLE_DEBUG)
#include "evtimer.h" #include "evtimer.h"
#endif #endif

View File

@ -57,15 +57,15 @@ gnrc_sixlowpan_ctx_t *gnrc_sixlowpan_ctx_lookup_addr(const ipv6_addr_t *addr)
mutex_unlock(&_ctx_mutex); mutex_unlock(&_ctx_mutex);
#if ENABLE_DEBUG if (IS_ACTIVE(ENABLE_DEBUG)) {
if (res != NULL) { if (res != NULL) {
DEBUG("6lo ctx: found context (%u, %s/%" PRIu8 ") ", DEBUG("6lo ctx: found context (%u, %s/%" PRIu8 ") ",
(res->flags_id & GNRC_SIXLOWPAN_CTX_FLAGS_CID_MASK), (res->flags_id & GNRC_SIXLOWPAN_CTX_FLAGS_CID_MASK),
ipv6_addr_to_str(ipv6str, &res->prefix, sizeof(ipv6str)), ipv6_addr_to_str(ipv6str, &res->prefix, sizeof(ipv6str)),
res->prefix_len); res->prefix_len);
DEBUG("for address %s\n", ipv6_addr_to_str(ipv6str, addr, sizeof(ipv6str))); DEBUG("for address %s\n", ipv6_addr_to_str(ipv6str, addr, sizeof(ipv6str)));
}
} }
#endif
return res; return res;
} }

View File

@ -923,16 +923,16 @@ static int _forward_frag(gnrc_pktsnip_t *pkt, gnrc_pktsnip_t *frag_hdr,
DEBUG("to (%s, %u)\n", DEBUG("to (%s, %u)\n",
gnrc_netif_addr_to_str(vrbe->super.dst, vrbe->super.dst_len, gnrc_netif_addr_to_str(vrbe->super.dst, vrbe->super.dst_len,
addr_str), vrbe->out_tag); addr_str), vrbe->out_tag);
#if ENABLE_DEBUG && defined(MODULE_OD) if (IS_ACTIVE(ENABLE_DEBUG) && IS_USED(MODULE_OD)) {
DEBUG("Original fragmentation header:\n"); DEBUG("Original fragmentation header:\n");
od_hex_dump(frag_hdr->data, frag_hdr->size, OD_WIDTH_DEFAULT);
DEBUG("IPHC headers + payload:\n");
frag_hdr = pkt;
while (frag_hdr) {
od_hex_dump(frag_hdr->data, frag_hdr->size, OD_WIDTH_DEFAULT); od_hex_dump(frag_hdr->data, frag_hdr->size, OD_WIDTH_DEFAULT);
frag_hdr = frag_hdr->next; DEBUG("IPHC headers + payload:\n");
frag_hdr = pkt;
while (frag_hdr) {
od_hex_dump(frag_hdr->data, frag_hdr->size, OD_WIDTH_DEFAULT);
frag_hdr = frag_hdr->next;
}
} }
#endif
gnrc_pktbuf_release(pkt); gnrc_pktbuf_release(pkt);
(void)frag_hdr; (void)frag_hdr;
(void)page; (void)page;

View File

@ -23,7 +23,7 @@
#define ENABLE_DEBUG 0 #define ENABLE_DEBUG 0
#include "debug.h" #include "debug.h"
#if ENABLE_DEBUG #if IS_ACTIVE(ENABLE_DEBUG)
static char addr_str[IPV6_ADDR_MAX_STR_LEN]; static char addr_str[IPV6_ADDR_MAX_STR_LEN];
#endif #endif

View File

@ -30,7 +30,7 @@
#define ENABLE_DEBUG 0 #define ENABLE_DEBUG 0
#include "debug.h" #include "debug.h"
#if ENABLE_DEBUG #if IS_ACTIVE(ENABLE_DEBUG)
static char addr_str[IPV6_ADDR_MAX_STR_LEN]; static char addr_str[IPV6_ADDR_MAX_STR_LEN];
#endif #endif

View File

@ -89,13 +89,13 @@ static int fib_find_entry(fib_table_t *table, uint8_t *dst, size_t dst_size,
int ret = -EHOSTUNREACH; int ret = -EHOSTUNREACH;
bool is_all_zeros_addr = true; bool is_all_zeros_addr = true;
#if ENABLE_DEBUG if (IS_ACTIVE(ENABLE_DEBUG)) {
DEBUG("[fib_find_entry] dst ="); DEBUG("[fib_find_entry] dst =");
for (size_t i = 0; i < dst_size; i++) { for (size_t i = 0; i < dst_size; i++) {
DEBUG(" %02x", dst[i]); DEBUG(" %02x", dst[i]);
}
DEBUG("\n");
} }
DEBUG("\n");
#endif
for (size_t i = 0; i < dst_size; ++i) { for (size_t i = 0; i < dst_size; ++i) {
if (dst[i] != 0) { if (dst[i] != 0) {
@ -175,15 +175,15 @@ static int fib_find_entry(fib_table_t *table, uint8_t *dst, size_t dst_size,
} }
} }
#if ENABLE_DEBUG if (IS_ACTIVE(ENABLE_DEBUG)) {
if (count > 0) { if (count > 0) {
DEBUG("[fib_find_entry] found prefix on interface %d:", entry_arr[0]->iface_id); DEBUG("[fib_find_entry] found prefix on interface %d:", entry_arr[0]->iface_id);
for (size_t i = 0; i < entry_arr[0]->global->address_size; i++) { for (size_t i = 0; i < entry_arr[0]->global->address_size; i++) {
DEBUG(" %02x", entry_arr[0]->global->address[i]); DEBUG(" %02x", entry_arr[0]->global->address[i]);
}
DEBUG("\n");
} }
DEBUG("\n");
} }
#endif
*entry_arr_size = count; *entry_arr_size = count;
return ret; return ret;

View File

@ -41,7 +41,7 @@
#define CONFIG_PTHREAD_REAPER_BASE_STACKSIZE (THREAD_STACKSIZE_IDLE) #define CONFIG_PTHREAD_REAPER_BASE_STACKSIZE (THREAD_STACKSIZE_IDLE)
#endif #endif
#if ENABLE_DEBUG #if IS_ACTIVE(ENABLE_DEBUG)
# define PTHREAD_REAPER_STACKSIZE ((CONFIG_PTHREAD_REAPER_BASE_STACKSIZE) + THREAD_EXTRA_STACKSIZE_PRINTF) # define PTHREAD_REAPER_STACKSIZE ((CONFIG_PTHREAD_REAPER_BASE_STACKSIZE) + THREAD_EXTRA_STACKSIZE_PRINTF)
# define PTHREAD_STACKSIZE THREAD_STACKSIZE_MAIN # define PTHREAD_STACKSIZE THREAD_STACKSIZE_MAIN
#else #else

View File

@ -28,11 +28,11 @@
timex_t timex_add(const timex_t a, const timex_t b) timex_t timex_add(const timex_t a, const timex_t b)
{ {
#if ENABLE_DEBUG if (IS_ACTIVE(ENABLE_DEBUG)) {
if (!timex_isnormalized(&a) || !timex_isnormalized(&b)) { if (!timex_isnormalized(&a) || !timex_isnormalized(&b)) {
puts("timex_add on denormalized value"); puts("timex_add on denormalized value");
}
} }
#endif
timex_t result; timex_t result;
result.seconds = a.seconds + b.seconds; result.seconds = a.seconds + b.seconds;
@ -52,22 +52,22 @@ timex_t timex_set(uint32_t seconds, uint32_t microseconds)
result.seconds = seconds; result.seconds = seconds;
result.microseconds = microseconds; result.microseconds = microseconds;
#if ENABLE_DEBUG if (IS_ACTIVE(ENABLE_DEBUG)) {
if (!timex_isnormalized(&result)) { if (!timex_isnormalized(&result)) {
puts("timex_set on denormalized value"); puts("timex_set on denormalized value");
}
} }
#endif
return result; return result;
} }
timex_t timex_sub(const timex_t a, const timex_t b) timex_t timex_sub(const timex_t a, const timex_t b)
{ {
#if ENABLE_DEBUG if (IS_ACTIVE(ENABLE_DEBUG)) {
if (!timex_isnormalized(&a) || !timex_isnormalized(&b)) { if (!timex_isnormalized(&a) || !timex_isnormalized(&b)) {
puts("timex_sub on denormalized value"); puts("timex_sub on denormalized value");
}
} }
#endif
timex_t result; timex_t result;
@ -85,11 +85,11 @@ timex_t timex_sub(const timex_t a, const timex_t b)
int timex_cmp(const timex_t a, const timex_t b) int timex_cmp(const timex_t a, const timex_t b)
{ {
#if ENABLE_DEBUG if (IS_ACTIVE(ENABLE_DEBUG)) {
if (!timex_isnormalized(&a) || !timex_isnormalized(&b)) { if (!timex_isnormalized(&a) || !timex_isnormalized(&b)) {
puts("timex_cmp on denormalized value"); puts("timex_cmp on denormalized value");
}
} }
#endif
if (a.seconds < b.seconds) { if (a.seconds < b.seconds) {
return -1; return -1;

View File

@ -31,7 +31,8 @@
#define ENABLE_DEBUG 0 #define ENABLE_DEBUG 0
#include "debug.h" #include "debug.h"
#if ENABLE_DEBUG
#if IS_ACTIVE(ENABLE_DEBUG)
/* Since some of these functions are called by printf, we can't really call /* Since some of these functions are called by printf, we can't really call
* printf from our functions or we end up in an infinite recursion. */ * printf from our functions or we end up in an infinite recursion. */
#include <unistd.h> /* for STDOUT_FILENO */ #include <unistd.h> /* for STDOUT_FILENO */

View File

@ -311,7 +311,7 @@ void ztimer_handler(ztimer_clock_t *clock)
{ {
DEBUG("ztimer_handler(): %p now=%" PRIu32 "\n", (void *)clock, clock->ops->now( DEBUG("ztimer_handler(): %p now=%" PRIu32 "\n", (void *)clock, clock->ops->now(
clock)); clock));
if (ENABLE_DEBUG) { if (IS_ACTIVE(ENABLE_DEBUG)) {
_ztimer_print(clock); _ztimer_print(clock);
} }
@ -364,7 +364,7 @@ void ztimer_handler(ztimer_clock_t *clock)
_ztimer_update(clock); _ztimer_update(clock);
if (ENABLE_DEBUG) { if (IS_ACTIVE(ENABLE_DEBUG)) {
_ztimer_print(clock); _ztimer_print(clock);
} }
DEBUG("ztimer_handler(): %p done.\n", (void *)clock); DEBUG("ztimer_handler(): %p done.\n", (void *)clock);