callout: replace printf printf_P
authorFabrice Desclaux <serpilliere@droids-corp.org>
Tue, 21 Feb 2012 18:27:33 +0000 (19:27 +0100)
committerFabrice Desclaux <serpilliere@droids-corp.org>
Tue, 21 Feb 2012 18:27:33 +0000 (19:27 +0100)
callout.c

index 1b4ffe9..d87d9f7 100644 (file)
--- a/callout.c
+++ b/callout.c
@@ -37,6 +37,8 @@
 #include <stdint.h>
 #include <aversive/queue.h>
 #include <inttypes.h>
+#include <aversive.h>
+#include <aversive/pgmspace.h>
 
 #include "callout.h"
 
 #endif
 
 #ifdef CALLOUT_DEBUG
-#define callout_dprintf(fmt, ...) printf("%s(): " fmt, __FUNCTION__, \
+#define callout_dprintf_P(fmt, ...) printf_P(PSTR("%s(): " fmt), __FUNCTION__, \
                                         __VA_ARGS__)
 #else
-#define callout_dprintf(...) do { } while (0)
+#define callout_dprintf_P(...) do { } while (0)
 #endif
 
 /* Initialize a callout manager */
@@ -80,7 +82,7 @@ callout_add(struct callout_manager *cm, struct callout *tim)
 {
        struct callout *t;
 
-       callout_dprintf("cm=%p tim=%p\n", cm, tim);
+       callout_dprintf_P(PSTR("cm=%p tim=%p\r\n"), cm, tim);
 
        /* list is empty */
        if (TAILQ_EMPTY(&cm->pending_list)) {
@@ -113,7 +115,7 @@ callout_add(struct callout_manager *cm, struct callout *tim)
 static void
 callout_del(struct callout_manager *cm, struct callout *tim)
 {
-       callout_dprintf("cm=%p tim=%p\n", cm, tim);
+       callout_dprintf_P(PSTR("cm=%p tim=%p\r\n"), cm, tim);
        TAILQ_REMOVE(&cm->pending_list, tim, next);
 }
 
@@ -122,8 +124,8 @@ static int
 __callout_reset(struct callout_manager *cm, struct callout *tim, uint16_t expire,
                uint16_t period, callout_cb_t fct, void *arg)
 {
-       callout_dprintf("cm=%p tim=%p expire=%d period=%d\n",
-                       cm, tim, expire, period);
+       callout_dprintf_P(PSTR("cm=%p tim=%p expire=%d period=%d\r\n"),
+                         cm, tim, expire, period);
 
        __TIMER_STAT_ADD(cm, reset, 1);
        cm->updated = 1;
@@ -161,7 +163,7 @@ callout_reset(struct callout_manager *cm, struct callout *tim, uint16_t ticks,
 void
 callout_stop(struct callout_manager *cm, struct callout *tim)
 {
-       callout_dprintf("cm=%p tim=%p\n", cm, tim);
+       callout_dprintf_P(PSTR("cm=%p tim=%p\r\n"), cm, tim);
 
        __TIMER_STAT_ADD(cm, stop, 1);
        cm->updated = 1;
@@ -187,7 +189,7 @@ void callout_manage(struct callout_manager *cm)
        struct callout *tim;
        uint16_t cur_time = cm->get_time();
 
-       callout_dprintf("cm=%p\n", cm);
+       callout_dprintf_P(PSTR("cm=%p\r\n"), cm);
 
        TAILQ_INIT(&expired_list);
        __TIMER_STAT_ADD(cm, manage, 1);
@@ -237,14 +239,14 @@ void callout_manage(struct callout_manager *cm)
 void callout_dump_stats(struct callout_manager *cm)
 {
 #ifdef CALLOUT_STATS
-       printf("Timer statistics:\n");
-       printf("  reset = %d\n", cm->stats.reset);
-       printf("  stop = %d\n", cm->stats.stop);
-       printf("  manage = %d\n", cm->stats.manage);
-       printf("  pending = %d\n", cm->stats.pending);
-       printf("  running = %d\n", cm->stats.running);
+       printf_P(PSTR("Timer statistics:\r\n"));
+       printf_P(PSTR("  reset = %d\r\n"), cm->stats.reset);
+       printf_P(PSTR("  stop = %d\r\n"), cm->stats.stop);
+       printf_P(PSTR("  manage = %d\r\n"), cm->stats.manage);
+       printf_P(PSTR("  pending = %d\r\n"), cm->stats.pending);
+       printf_P(PSTR("  running = %d\r\n"), cm->stats.running);
 #else
-       printf("No timer statistics, CALLOUT_STATS is disabled\n");
+       printf_P(PSTR("No timer statistics, CALLOUT_STATS is disabled\r\n"));
 #endif
 }
 
@@ -272,7 +274,7 @@ static void cb1(struct callout_manager *cm, struct callout *tim, void *arg)
        static int cnt;
        arg = arg; /* silent compiler */
 
-       printf("cb1\n");
+       printf_P(PSTR("cb1\r\n"));
        callout_dump_stats(cm);
        if (++cnt >= 4)
                callout_stop(cm, tim);
@@ -283,7 +285,7 @@ static void cb2(struct callout_manager *cm, struct callout *tim, void *arg)
        static int cnt;
        struct callout *t3 = arg;
 
-       printf("cb2\n");
+       printf_P(PSTR("cb2\r\n"));
        if (++cnt < 3)
                callout_reset(cm, tim, 5, SINGLE, cb2, arg);
        else
@@ -296,7 +298,7 @@ static void cb3(struct callout_manager *cm, struct callout *tim, void *arg)
        tim = tim; /* silent compiler */
        arg = arg; /* silent compiler */
 
-       printf("cb3\n");
+       printf_P(PSTR("cb3\r\n"));
 }
 
 int main(void)