From eb7d4fbd7e465dd1a4a8450111ec93af2dce936b Mon Sep 17 00:00:00 2001 From: "R. Steve McKown" Date: Sun, 14 Oct 2012 18:55:11 -0600 Subject: [PATCH] Add uprintf library; use it in tmimsp platforms --- tos/lib/uprintf/README.txt | 29 +++++++++++++++++++++++++++++ tos/lib/uprintf/Uprint.h | 21 +++++++++++++++++++++ tos/lib/uprintf/Uprint.nc | 18 ++++++++++++++++++ tos/lib/uprintf/UprintC.nc | 21 +++++++++++++++++++++ tos/lib/uprintf/UprintP.nc | 31 +++++++++++++++++++++++++++++++ tos/platforms/tmimsp/.family | 7 ++++--- 6 files changed, 124 insertions(+), 3 deletions(-) create mode 100644 tos/lib/uprintf/README.txt create mode 100644 tos/lib/uprintf/Uprint.h create mode 100644 tos/lib/uprintf/Uprint.nc create mode 100644 tos/lib/uprintf/UprintC.nc create mode 100644 tos/lib/uprintf/UprintP.nc diff --git a/tos/lib/uprintf/README.txt b/tos/lib/uprintf/README.txt new file mode 100644 index 00000000..dedf345b --- /dev/null +++ b/tos/lib/uprintf/README.txt @@ -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 index 00000000..0e05ebbc --- /dev/null +++ b/tos/lib/uprintf/Uprint.h @@ -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 + */ + +#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 index 00000000..33dd1204 --- /dev/null +++ b/tos/lib/uprintf/Uprint.nc @@ -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 +#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 index 00000000..04a38f25 --- /dev/null +++ b/tos/lib/uprintf/UprintC.nc @@ -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 index 00000000..5a8f083e --- /dev/null +++ b/tos/lib/uprintf/UprintP.nc @@ -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 +#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; + } +} diff --git a/tos/platforms/tmimsp/.family b/tos/platforms/tmimsp/.family index 0a6fd28a..71576bc3 100644 --- a/tos/platforms/tmimsp/.family +++ b/tos/platforms/tmimsp/.family @@ -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( -- 2.39.2