]> oss.titaniummirror.com Git - tinyos-2.x.git/commitdiff
Add uprintf library; use it in tmimsp platforms
authorR. Steve McKown <rsmckown@gmail.com>
Mon, 15 Oct 2012 00:55:11 +0000 (18:55 -0600)
committerR. Steve McKown <rsmckown@gmail.com>
Mon, 15 Oct 2012 00:55:11 +0000 (18:55 -0600)
tos/lib/uprintf/README.txt [new file with mode: 0644]
tos/lib/uprintf/Uprint.h [new file with mode: 0644]
tos/lib/uprintf/Uprint.nc [new file with mode: 0644]
tos/lib/uprintf/UprintC.nc [new file with mode: 0644]
tos/lib/uprintf/UprintP.nc [new file with mode: 0644]
tos/platforms/tmimsp/.family

diff --git a/tos/lib/uprintf/README.txt b/tos/lib/uprintf/README.txt
new file mode 100644 (file)
index 0000000..dedf345
--- /dev/null
@@ -0,0 +1,29 @@
+The UprintC component uses the uprintf() function.  The MSP430 libc provides
+uprintf(), which can be trivially created for any other platform.  The benefits
+of uprintf are:
+
+* No internal buffer; data are written as the format string is parsed.
+* By using a pointer to a putc() function, the function is usable for
+  multiple UARTs, when appropriate.
+
+An example of using UprintC is shown below.
+
+configuration AppC {
+  ...
+  components PlatformUartC as UartC;
+  AppP.UartResource -> UartC;
+  AppP.UartByte -> UartC;
+
+  components new UprintC();
+  AppP.Uprint -> UprintC;
+  UprintC.UartByte  -> UartC;
+  ...
+}
+
+module AppP {
+  ...
+  #define cprintf(fmt, args...) uprintf(call Uprint.uptr(), fmt, ## args)
+  ...
+  cprintf("Hello, world!\r\n");
+  ...
+}
diff --git a/tos/lib/uprintf/Uprint.h b/tos/lib/uprintf/Uprint.h
new file mode 100644 (file)
index 0000000..0e05ebb
--- /dev/null
@@ -0,0 +1,21 @@
+/* Copyright (c) 2006-2009 by Sporian Microsystems, Inc.
+ * All Rights Reserved.
+ *
+ * This document is the proprietary and confidential property of Sporian
+ * Microsystems, Inc.  All use, distribution, reproduction or re-distribution
+ * is disallowed without the prior express written consent of Sporian
+ * Microsystems, Inc.
+ */
+
+/**
+ * Simple dbgprintf helper
+ *
+ * @author R. Steve McKown <rsmckown@gmail.com>
+ */
+
+#ifndef UPRINT_H
+#define UPRINT_H
+
+typedef int (*uprint_ptr_t)();
+
+#endif /* end of include guard: UPRINT_H */
diff --git a/tos/lib/uprintf/Uprint.nc b/tos/lib/uprintf/Uprint.nc
new file mode 100644 (file)
index 0000000..33dd120
--- /dev/null
@@ -0,0 +1,18 @@
+/* Copyright (c) 2012 by Sporian Microsystems, Inc.
+ * All Rights Reserved.
+ *
+ * This document is the proprietary and confidential property of Sporian
+ * Microsystems, Inc.  All use, distribution, reproduction or re-distribution
+ * is disallowed without the prior express written consent of Sporian
+ * Microsystems, Inc.
+ */
+
+/* A shim for putc to enable uprintf.
+ */
+
+#include <stdarg.h>
+#include "Uprint.h"
+
+interface Uprint {
+  async command uprint_ptr_t uptr();
+}
diff --git a/tos/lib/uprintf/UprintC.nc b/tos/lib/uprintf/UprintC.nc
new file mode 100644 (file)
index 0000000..04a38f2
--- /dev/null
@@ -0,0 +1,21 @@
+/* Copyright (c) 2006-2009 by Sporian Microsystems, Inc.
+ * All Rights Reserved.
+ *
+ * This document is the proprietary and confidential property of Sporian
+ * Microsystems, Inc.  All use, distribution, reproduction or re-distribution
+ * is disallowed without the prior express written consent of Sporian
+ * Microsystems, Inc.
+ */
+
+/* A shim for printf on a uart.
+ */
+
+generic configuration UprintC() {
+  provides interface Uprint;
+  uses interface UartByte;
+}
+implementation {
+  components new UprintP();
+  Uprint = UprintP;
+  UartByte = UprintP;
+}
diff --git a/tos/lib/uprintf/UprintP.nc b/tos/lib/uprintf/UprintP.nc
new file mode 100644 (file)
index 0000000..5a8f083
--- /dev/null
@@ -0,0 +1,31 @@
+/* Copyright (c) 2006-2007 by Sporian Microsystems, Inc.
+ * All Rights Reserved.
+ *
+ * This document is the proprietary and confidential property of Sporian
+ * Microsystems, Inc.  All use, distribution, reproduction or re-distribution
+ * is disallowed without the prior express written consent of Sporian
+ * Microsystems, Inc.
+ */
+
+/* A shim for printf on a uart.
+ */
+
+#include <stdarg.h>
+#include "Uprint.h"
+
+generic module UprintP() {
+  provides interface Uprint;
+  uses interface UartByte;
+}
+implementation {
+  int uart_putc(int c)
+  {
+    call UartByte.send((uint8_t)c);
+    return c;
+  }
+
+  async command uprint_ptr_t Uprint.uptr()
+  {
+    return uart_putc;
+  }
+}
index 0a6fd28ac1e57dee61e8fb8cf63e49b730440a73..71576bc33f9a45bb51d3d8d6b2dce2b1172df7b3 100644 (file)
@@ -22,11 +22,12 @@ push( @includes, qw(
   %T/chips/bq2403x
   %T/chips/cp210x
   %T/chips/stm25p
-  %T/lib/timer
-  %T/lib/serial
   %T/lib/adc
-  %T/lib/power
   %T/lib/misc
+  %T/lib/power
+  %T/lib/serial
+  %T/lib/timer
+  %T/lib/uprintf
 ) );
 
 @opts = qw(