use PROGMEM on AVR architecture for log_ facilities

This commit is contained in:
matthias.ringwald@gmail.com 2014-12-03 22:33:36 +00:00
parent 7fe7736638
commit 20ea11b9fd
3 changed files with 34 additions and 8 deletions

View File

@ -56,11 +56,19 @@ static inline void __log_unused(const char *format, ...) {
#define __log_unused(...)
#endif
#ifdef __AVR__
#define HCI_DUMP_LOG(format, ...) hci_dump_log_P(PSTR(format), ## __VA_ARGS__)
#define PRINTF(format, ...) printf_P(PSTR(format), ## __VA_ARGS__)
#else
#define HCI_DUMP_LOG(format, ...) hci_dump_log(format, ## __VA_ARGS__)
#define PRINTF(format, ...) printf(format, ## __VA_ARGS__)
#endif
#ifdef ENABLE_LOG_DEBUG
#ifdef HAVE_HCI_DUMP
#define log_debug(format, ...) hci_dump_log(format, ## __VA_ARGS__)
#define log_debug(format, ...) HCI_DUMP_LOG(format, ## __VA_ARGS__)
#else
#define log_debug(format, ...) printf(format "\n", ## __VA_ARGS__)
#define log_debug(format, ...) PRINTF(format "\n", ## __VA_ARGS__)
#endif
#else
#define log_debug(...) __log_unused(__VA_ARGS__)
@ -68,9 +76,9 @@ static inline void __log_unused(const char *format, ...) {
#ifdef ENABLE_LOG_INFO
#ifdef HAVE_HCI_DUMP
#define log_info(format, ...) hci_dump_log(format, ## __VA_ARGS__)
#define log_info(format, ...) HCI_DUMP_LOG(format, ## __VA_ARGS__)
#else
#define log_info(format, ...) printf(format "\n", ## __VA_ARGS__)
#define log_info(format, ...) PRINTF(format "\n", ## __VA_ARGS__)
#endif
#else
#define log_info(...) __log_unused(__VA_ARGS__)
@ -78,9 +86,9 @@ static inline void __log_unused(const char *format, ...) {
#ifdef ENABLE_LOG_ERROR
#ifdef HAVE_HCI_DUMP
#define log_error(format, ...) hci_dump_log(format, ## __VA_ARGS__)
#define log_error(format, ...) HCI_DUMP_LOG(format, ## __VA_ARGS__)
#else
#define log_error(format, ...) printf(format "\n", ## __VA_ARGS__)
#define log_error(format, ...) PRINTF(format "\n", ## __VA_ARGS__)
#endif
#else
#define log_error(...) __log_unused(__VA_ARGS__)

View File

@ -236,9 +236,7 @@ void hci_dump_packet(uint8_t packet_type, uint8_t in, uint8_t *packet, uint16_t
}
void hci_dump_log(const char * format, ...){
if (dump_file < 0) return; // not activated yet
va_list argptr;
va_start(argptr, format);
#ifdef EMBEDDED
@ -252,6 +250,18 @@ void hci_dump_log(const char * format, ...){
va_end(argptr);
}
#ifdef __AVR__
void hci_dump_log_P(PGM_P format, ...){
if (dump_file < 0) return; // not activated yet
va_list argptr;
va_start(argptr, format);
printf_P(PSTR("LOG -- "));
vfprintf_P(stdout, format, argptr);
printf_P(PSTR("\n"));
va_end(argptr);
}
#endif
void hci_dump_close(){
#ifndef EMBEDDED
close(dump_file);

View File

@ -47,6 +47,10 @@
#include <stdint.h>
#ifdef __AVR__
#include <avr/progmem.h>
#endif
#if defined __cplusplus
extern "C" {
#endif
@ -63,6 +67,10 @@ void hci_dump_packet(uint8_t packet_type, uint8_t in, uint8_t *packet, uint16_t
void hci_dump_log(const char * format, ...);
void hci_dump_close(void);
#ifdef __AVR__
void hci_dump_log_P(PGM_P format, ...);
#endif
#if defined __cplusplus
}
#endif