From 06526c9bb19fa589e7a14c10d6f24629431cbaa4 Mon Sep 17 00:00:00 2001 From: "R. Steve McKown" Date: Thu, 4 Oct 2012 09:27:12 -0600 Subject: [PATCH] tmimsp platform family better uart abstraction --- tos/lib/misc/StdToResourceC.nc | 58 +++++++++++++++++ tos/platforms/tmimsp/.family | 2 + .../tmimsp/common/uart/ConsoleUart.h | 39 ++++++++++++ .../tmimsp/common/uart/ConsoleUartC.nc | 50 +++++++++++++++ .../tmimsp/common/uart/ConsoleUartConfigC.nc | 50 +++++++++++++++ .../tmimsp/common/uart/ConsoleUartImplP.nc | 63 +++++++++++++++++++ .../tmimsp/common/uart/ConsoleUartP.nc | 57 +++++++++++++++++ .../tmimsp/common/uart/DebugUartC.nc | 46 ++++++++++++++ .../common/{ => uart}/PlatformSerialC.nc | 6 +- .../tmimsp/common/{ => uart}/PlatformUartC.nc | 11 +--- 10 files changed, 371 insertions(+), 11 deletions(-) create mode 100644 tos/lib/misc/StdToResourceC.nc create mode 100644 tos/platforms/tmimsp/common/uart/ConsoleUart.h create mode 100644 tos/platforms/tmimsp/common/uart/ConsoleUartC.nc create mode 100644 tos/platforms/tmimsp/common/uart/ConsoleUartConfigC.nc create mode 100644 tos/platforms/tmimsp/common/uart/ConsoleUartImplP.nc create mode 100644 tos/platforms/tmimsp/common/uart/ConsoleUartP.nc create mode 100644 tos/platforms/tmimsp/common/uart/DebugUartC.nc rename tos/platforms/tmimsp/common/{ => uart}/PlatformSerialC.nc (96%) rename tos/platforms/tmimsp/common/{ => uart}/PlatformUartC.nc (89%) diff --git a/tos/lib/misc/StdToResourceC.nc b/tos/lib/misc/StdToResourceC.nc new file mode 100644 index 00000000..c6dd9adc --- /dev/null +++ b/tos/lib/misc/StdToResourceC.nc @@ -0,0 +1,58 @@ +/** + * Copyright © 2012, Titanium Mirror, Inc. + * All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * - Neither the name of Titanium Mirror, Inc nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * Implement resource acquisition via the StdControl interface. Created to + * implement PlatformSerialC's StdControl interface using USCI Uart's Resource + * interface. + * + * Avoid using with resources that cannot reliably respond with SUCCESS to + * Resource.immediateRequest(). In such cases, it's far smarter to just use the + * Resource interface directly. + * + * @author R. Steve McKown + */ + +generic module StdToResourceC() { + provides interface StdControl; + uses interface Resource; +} +implementation { + command error_t StdControl.start() + { + return call Resource.immediateRequest(); + } + + command error_t StdControl.stop() + { + return call Resource.release(); + } + + event void Resource.granted() {} +} diff --git a/tos/platforms/tmimsp/.family b/tos/platforms/tmimsp/.family index bda9749f..a068ee3f 100644 --- a/tos/platforms/tmimsp/.family +++ b/tos/platforms/tmimsp/.family @@ -9,6 +9,7 @@ push( @includes, qw( %F/common %F/common/chips/bq2403x %F/common/chips/cp210x + %F/common/uart %T/platforms/telosa %T/chips/msp430 %T/chips/msp430/adc12 @@ -23,6 +24,7 @@ push( @includes, qw( %T/lib/serial %T/lib/adc %T/lib/power + %T/lib/misc ) ); @opts = qw( diff --git a/tos/platforms/tmimsp/common/uart/ConsoleUart.h b/tos/platforms/tmimsp/common/uart/ConsoleUart.h new file mode 100644 index 00000000..06fb96a4 --- /dev/null +++ b/tos/platforms/tmimsp/common/uart/ConsoleUart.h @@ -0,0 +1,39 @@ +/** + * Copyright (c) 2008-2010, Titanium Mirror, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * - Neither the name of the Technische Universität Berlin nor the names + * of its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @author R. Steve McKown + */ + +#ifndef CONSOLE_UART_H +#define CONSOLE_UART_H + +#define CONSOLE_UART_RESOURCE "Console.Shared.Uart" + +#endif diff --git a/tos/platforms/tmimsp/common/uart/ConsoleUartC.nc b/tos/platforms/tmimsp/common/uart/ConsoleUartC.nc new file mode 100644 index 00000000..5dbb1452 --- /dev/null +++ b/tos/platforms/tmimsp/common/uart/ConsoleUartC.nc @@ -0,0 +1,50 @@ +/** + * Copyright (c) 2008-2010, Titanium Mirror, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * - Neither the name of the Technische Universität Berlin nor the names + * of its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @author R. Steve McKown + */ + +#include "ConsoleUart.h" + +generic configuration ConsoleUartC() { + provides { + interface Resource; + interface UartStream; + interface UartByte; + } +} +implementation { + enum { CLIENT = unique(CONSOLE_UART_RESOURCE) }; + + components ConsoleUartP; + Resource = ConsoleUartP.Resource[CLIENT]; + UartStream = ConsoleUartP.UartStream; + UartByte = ConsoleUartP.UartByte; +} diff --git a/tos/platforms/tmimsp/common/uart/ConsoleUartConfigC.nc b/tos/platforms/tmimsp/common/uart/ConsoleUartConfigC.nc new file mode 100644 index 00000000..9b362233 --- /dev/null +++ b/tos/platforms/tmimsp/common/uart/ConsoleUartConfigC.nc @@ -0,0 +1,50 @@ +/** + * Copyright (c) 2008-2010, Titanium Mirror, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * - Neither the name of the Technische Universität Berlin nor the names + * of its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +module ConsoleUartConfigC { + provides interface AsyncConfigure; +} +implementation { + const static msp430_usci_uart_t config = { + ctl0: UCMODE_0, /* async, lsb first, 8N1 */ + ctl1: UCSWRST | UCSSEL_3, /* clock uart from SMCLK */ + brx: UBRX_1MHZ_115200, + mctl: UMCTL_1MHZ_115200, + irtctl: 0, + irrctl: 0, + abctl: 0, + uclisten: FALSE, + ren: USCI_REN_NONE + }; + + async command const msp430_usci_uart_t* AsyncConfigure.get() + { + return &config; + } +} diff --git a/tos/platforms/tmimsp/common/uart/ConsoleUartImplP.nc b/tos/platforms/tmimsp/common/uart/ConsoleUartImplP.nc new file mode 100644 index 00000000..9e53e2a6 --- /dev/null +++ b/tos/platforms/tmimsp/common/uart/ConsoleUartImplP.nc @@ -0,0 +1,63 @@ +/** + * Copyright (c) 2008-2010, Titanium Mirror, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * - Neither the name of the Technische Universität Berlin nor the names + * of its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @author R. Steve McKown + */ + +#include "ConsoleUart.h" + +module ConsoleUartImplP { + uses { + interface ResourceDefaultOwner; + interface Resource as SubResource; + } +} +implementation { + async event void ResourceDefaultOwner.granted() + { + call SubResource.release(); + } + + async event void ResourceDefaultOwner.requested() + { + call SubResource.request(); + } + + async event void ResourceDefaultOwner.immediateRequested() + { + if (call SubResource.immediateRequest() == SUCCESS) + call ResourceDefaultOwner.release(); + } + + event void SubResource.granted() + { + call ResourceDefaultOwner.release(); + } +} diff --git a/tos/platforms/tmimsp/common/uart/ConsoleUartP.nc b/tos/platforms/tmimsp/common/uart/ConsoleUartP.nc new file mode 100644 index 00000000..301040df --- /dev/null +++ b/tos/platforms/tmimsp/common/uart/ConsoleUartP.nc @@ -0,0 +1,57 @@ +/** + * Copyright (c) 2008-2010, Titanium Mirror, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * - Neither the name of the Technische Universität Berlin nor the names + * of its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @author R. Steve McKown + */ + +#include "ConsoleUart.h" + +configuration ConsoleUartP { + provides { + interface Resource[uint8_t id]; + interface UartStream; + interface UartByte; + } +} +implementation { + components new SharedArbiterC(CONSOLE_UART_RESOURCE); + Resource = SharedArbiterC; + + components ConsoleUartImplP; + ConsoleUartImplP.ResourceDefaultOwner -> SharedArbiterC; + + components new Msp430UartA1C() as UartC; + UartStream = UartC; + UartByte = UartC; + ConsoleUartImplP.SubResource -> UartC; + + components ConsoleUartConfigC as ConfigC; + UartC.Configure -> ConfigC; +} diff --git a/tos/platforms/tmimsp/common/uart/DebugUartC.nc b/tos/platforms/tmimsp/common/uart/DebugUartC.nc new file mode 100644 index 00000000..2e7c0454 --- /dev/null +++ b/tos/platforms/tmimsp/common/uart/DebugUartC.nc @@ -0,0 +1,46 @@ +/** + * Copyright (c) 2008-2010, Titanium Mirror, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * - Neither the name of the Technische Universität Berlin nor the names + * of its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @author R. Steve McKown + */ + +configuration DebugUartC { + provides { + interface Resource; + interface UartStream; + interface UartByte; + } +} +implementation { + components new ConsoleUartC() as UartC; + Resource = UartC; + UartStream = UartC; + UartByte = UartC; +} diff --git a/tos/platforms/tmimsp/common/PlatformSerialC.nc b/tos/platforms/tmimsp/common/uart/PlatformSerialC.nc similarity index 96% rename from tos/platforms/tmimsp/common/PlatformSerialC.nc rename to tos/platforms/tmimsp/common/uart/PlatformSerialC.nc index a32ffa04..0a8d43b0 100644 --- a/tos/platforms/tmimsp/common/PlatformSerialC.nc +++ b/tos/platforms/tmimsp/common/uart/PlatformSerialC.nc @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2008-2010, Titanium Mirror, Inc. * All rights reserved. * @@ -27,7 +27,7 @@ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - /** +/** * @author R. Steve McKown */ @@ -41,7 +41,7 @@ implementation { UartStream = UartC; UartByte = UartC; - components PlatformSerialP; + components new StdToResourceC() as PlatformSerialP; StdControl = PlatformSerialP; PlatformSerialP.Resource -> UartC; } diff --git a/tos/platforms/tmimsp/common/PlatformUartC.nc b/tos/platforms/tmimsp/common/uart/PlatformUartC.nc similarity index 89% rename from tos/platforms/tmimsp/common/PlatformUartC.nc rename to tos/platforms/tmimsp/common/uart/PlatformUartC.nc index 10a7cec4..0388fe05 100644 --- a/tos/platforms/tmimsp/common/PlatformUartC.nc +++ b/tos/platforms/tmimsp/common/uart/PlatformUartC.nc @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2008-2010, Titanium Mirror, Inc. * All rights reserved. * @@ -27,7 +27,7 @@ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - /** +/** * @author R. Steve McKown */ @@ -39,13 +39,8 @@ configuration PlatformUartC { } } implementation { - components new Msp430UartA1C() as UartC; + components new ConsoleUartC() as UartC; Resource = UartC; UartStream = UartC; UartByte = UartC; - -#if 0 /* If you want to change the Uart's configuration... */ - components SomeConfigurationComponentC as ConfigC; - UartC.AsyncConfigure -> ConfigC; -#endif } -- 2.39.2