mirror of
https://github.com/polhenarejos/pico-keys-sdk
synced 2026-06-10 11:59:05 +02:00
Optimitzations to reduce number of interruptions.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
71
src/debug.h
71
src/debug.h
@@ -19,32 +19,53 @@
|
||||
#define _DEBUG_H_
|
||||
|
||||
#if defined(DEBUG_APDU) && DEBUG_APDU == 1
|
||||
#define DEBUG_PAYLOAD(_p, _s) { \
|
||||
printf("Payload %s (%zu bytes) [%s:%d]:\n", #_p, (size_t)(_s), __FILE__, __LINE__); \
|
||||
for (size_t _i = 0; _i < (size_t)(_s); _i += 16) { \
|
||||
printf("%" PRIxPTR "h : ", (uintptr_t) (_i + _p)); \
|
||||
for (size_t _j = 0; _j < 16; _j++) { \
|
||||
if (_j < (size_t)(_s) - _i) printf("%02X ", (_p)[_i + _j]); \
|
||||
else printf(" "); \
|
||||
if (_j == 7) printf(" "); \
|
||||
} printf(": "); \
|
||||
for (size_t _j = 0; _j < 16; _j++) { \
|
||||
if (_j < (size_t)(_s) - _i && (_p)[_i + _j] > 32 && (_p)[_i + _j] != 127 && (_p)[_i + _j] < 176) printf("%c", (_p)[_i + _j]); \
|
||||
else printf(" "); \
|
||||
if (_j == 7) printf(" "); \
|
||||
} \
|
||||
printf("\n"); \
|
||||
} printf("\n"); \
|
||||
}
|
||||
#define DEBUG_DATA(_p, _s) { \
|
||||
printf("Data %s (%zu bytes) [%s:%d]:\n", #_p, (size_t)(_s), __FILE__, __LINE__); \
|
||||
char *_tmp = (char *) calloc(2 * (_s) + 1, sizeof(char)); \
|
||||
for (size_t _i = 0; _i < (size_t)(_s); _i++) { \
|
||||
sprintf(&_tmp[2 * _i], "%02X", (_p)[_i]); \
|
||||
} \
|
||||
printf("%s\n", _tmp); \
|
||||
free(_tmp); \
|
||||
#include <inttypes.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
static inline void debug_payload_impl(const char *name, const uint8_t *p, size_t s, const char *file, int line) {
|
||||
printf("Payload %s (%zu bytes) [%s:%d]:\n", name, s, file, line);
|
||||
for (size_t i = 0; i < s; i += 16) {
|
||||
printf("%" PRIxPTR "h : ", (uintptr_t)(p + i));
|
||||
for (size_t j = 0; j < 16; j++) {
|
||||
if (j < s - i) {
|
||||
printf("%02X ", p[i + j]);
|
||||
}
|
||||
else {
|
||||
printf(" ");
|
||||
}
|
||||
if (j == 7) {
|
||||
printf(" ");
|
||||
}
|
||||
}
|
||||
printf(": ");
|
||||
for (size_t j = 0; j < 16; j++) {
|
||||
if (j < s - i && p[i + j] > 32 && p[i + j] != 127 && p[i + j] < 176) {
|
||||
printf("%c", p[i + j]);
|
||||
}
|
||||
else {
|
||||
printf(" ");
|
||||
}
|
||||
if (j == 7) {
|
||||
printf(" ");
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
static inline void debug_data_impl(const char *name, const uint8_t *p, size_t s, const char *file, int line) {
|
||||
printf("Data %s (%zu bytes) [%s:%d]:\n", name, s, file, line);
|
||||
for (size_t i = 0; i < s; i++) {
|
||||
printf("%02X", p[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
#define DEBUG_PAYLOAD(_p, _s) debug_payload_impl(#_p, (const uint8_t *)(_p), (size_t)(_s), __FILE__, __LINE__)
|
||||
#define DEBUG_DATA(_p, _s) debug_data_impl(#_p, (const uint8_t *)(_p), (size_t)(_s), __FILE__, __LINE__)
|
||||
|
||||
#else
|
||||
#define DEBUG_PAYLOAD(_p, _s)
|
||||
|
||||
Reference in New Issue
Block a user