add progmem compatible debug and info functions

This commit is contained in:
optixx 2009-08-28 12:30:16 +02:00
parent 710aa2d53a
commit bb1367c243
5 changed files with 72 additions and 5 deletions

View File

@ -43,7 +43,7 @@
#define USB_CRC_CHECK 0x01
#define TRANSFER_BUFFER_SIZE 0x200
#define FORMAT_BUFFER_LEN 0x0FF
#define HW_VERSION "2.6"
#define SW_VERSION "1.0"

View File

@ -20,11 +20,11 @@
#include <stdlib.h>
#include <stdint.h>
#include <avr/pgmspace.h>
#include "debug.h"
#include "uart.h"
#include "config.h"
extern FILE uart_stdout;
@ -46,4 +46,23 @@ void debug(int level, char* format, ...) {
}
#endif
#ifndef NO_INFO
uint8_t buffer_debug[FORMAT_BUFFER_LEN];
#endif
#if defined(NO_DEBUG) && defined(__GNUC__)
#else
void debug_P(int level, PGM_P format, ...) {
#ifdef NO_DEBUG
#else
va_list args;
if (!(debug_level & level))
return;
strlcpy_P(buffer_debug,format,FORMAT_BUFFER_LEN);
va_start(args, format);
vprintf(buffer_debug, args);
va_end(args);
#endif
}
#endif

View File

@ -26,7 +26,7 @@
#include <stdlib.h>
#include <stdint.h>
#include <stdarg.h>
#include <avr/pgmspace.h>
#if defined(NO_DEBUG) && defined(__GNUC__)
/* gcc's cpp has extensions; it allows for macros with a variable number of
@ -39,5 +39,17 @@ void debug(int level, char *format, ...);
#endif
#if defined(NO_DEBUG) && defined(__GNUC__)
/* gcc's cpp has extensions; it allows for macros with a variable number of
arguments. We use this extension here to preprocess pmesg away. */
#define debug_P(level, format, args...) ((void)0)
#else
void debug_P(int level, PGM_P format, ...);
/* print a message, if it is considered significant enough.
Adapted from [K&R2], p. 174 */
#endif
#endif /* DEBUG_H */

View File

@ -20,9 +20,12 @@
#include <stdlib.h>
#include <stdint.h>
#include <avr/pgmspace.h>
#include "info.h"
#include "uart.h"
#include "config.h"
@ -46,4 +49,26 @@ void info(char* format, ...) {
}
#endif
#ifndef NO_INFO
uint8_t buffer_info[FORMAT_BUFFER_LEN];
#endif
#if defined(NO_INFO) && defined(__GNUC__)
#define info(format, args...) ((void)0)
#else
void info_P(PGM_P format, ...) {
#ifdef NO_INFO
#else
strlcpy_P(buffer_info,format,FORMAT_BUFFER_LEN);
va_list args;
va_start(args, format);
vprintf(buffer_info, args);
va_end(args);
#endif
}
#endif

View File

@ -26,7 +26,7 @@
#include <stdlib.h>
#include <stdint.h>
#include <stdarg.h>
#include <avr/pgmspace.h>
#if defined(NO_INFO) && defined(__GNUC__)
/* gcc's cpp has extensions; it allows for macros with a variable number of
@ -39,4 +39,15 @@ void info(char *format, ...);
#endif
#if defined(NO_INFO) && defined(__GNUC__)
/* gcc's cpp has extensions; it allows for macros with a variable number of
arguments. We use this extension here to preprocess pmesg away. */
#define info_P(format, args...) ((void)0)
#else
void info_P(PGM_P format, ...);
/* print a message, if it is considered significant enough.
Adapted from [K&R2], p. 174 */
#endif
#endif