From 477b0d9d71b3ea6d81baacd2902889ef2b004f08 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Sun, 27 Feb 2011 11:35:59 +0900 Subject: [PATCH] Add MAX549 driver and test --- .../msp430-small/max549/Clock/ClockAppC.nc | 69 +++++++++++++++ .../tests/msp430-small/max549/Clock/ClockC.nc | 84 ++++++++++++++++++ .../msp430-small/max549/Clock/DisplayC.nc | 40 +++++++++ apps/tests/msp430-small/max549/Clock/Makefile | 8 ++ tos/chips/max549/Max549.nc | 51 +++++++++++ tos/chips/max549/Max549P.nc | 86 +++++++++++++++++++ 6 files changed, 338 insertions(+) create mode 100644 apps/tests/msp430-small/max549/Clock/ClockAppC.nc create mode 100644 apps/tests/msp430-small/max549/Clock/ClockC.nc create mode 100644 apps/tests/msp430-small/max549/Clock/DisplayC.nc create mode 100644 apps/tests/msp430-small/max549/Clock/Makefile create mode 100644 tos/chips/max549/Max549.nc create mode 100644 tos/chips/max549/Max549P.nc diff --git a/apps/tests/msp430-small/max549/Clock/ClockAppC.nc b/apps/tests/msp430-small/max549/Clock/ClockAppC.nc new file mode 100644 index 0000000..f6e7a20 --- /dev/null +++ b/apps/tests/msp430-small/max549/Clock/ClockAppC.nc @@ -0,0 +1,69 @@ +/* -*- mode: nesc; mode: flyspell-prog; -*- */ +/* Copyright (c) 2010, Tadashi G. Takaoka + * 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 Tadashi G. Takaoka 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 HOLDER 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. + */ + +configuration ClockAppC { +} +implementation { + components MainC; + components ClockC as App; + components DisplayC; + components LedC; + components new Timer16MilliC() as Timer; + + components new Max549P() as Max549; + components PlatformSpiC as SpiC; + components HplMsp430GeneralIOC as GpioC; + components new Msp430GpioC() as Max549CS; + + Max549CS -> GpioC.Port13; + Max549.Boot -> MainC.Boot; + Max549.CS -> Max549CS; + Max549.SpiByte -> SpiC; + Max549.SpiControl -> SpiC; + App.Max549 -> Max549; + + App.Boot -> MainC.Boot; + App.Timer -> Timer; + App.Sec -> DisplayC.Sec; + App.Min -> DisplayC.Min; + App.Hour -> DisplayC.Hour; + App.Led -> LedC.Led0; +} + +/* + * Local Variables: + * c-file-style: "bsd" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: set et ts=4 sw=4: + */ diff --git a/apps/tests/msp430-small/max549/Clock/ClockC.nc b/apps/tests/msp430-small/max549/Clock/ClockC.nc new file mode 100644 index 0000000..4482285 --- /dev/null +++ b/apps/tests/msp430-small/max549/Clock/ClockC.nc @@ -0,0 +1,84 @@ +/* -*- mode: nesc; mode: flyspell-prog; -*- */ +/* Copyright (c) 2011, Tadashi G. Takaoka + * 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 Tadashi G. Takaoka 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 HOLDER 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 ClockC { + uses interface Led7Segs as Hour; + uses interface Led7Segs as Min; + uses interface Led7Segs as Sec; + uses interface Led; + uses interface Timer16 as Timer; + uses interface Boot; + uses interface Max549; +} +implementation { + uint8_t deciSec; + uint8_t sec; + uint8_t min; + uint8_t hour; + + event void Boot.booted() { + call Timer.startPeriodic(100); + } + + event void Timer.fired() { + ++deciSec; + if (deciSec == 10) { + deciSec = 0; + ++sec; + if (sec == 60) { + sec = 0; + min++; + if (min == 60) { + min = 0; + hour++; + if (hour == 24) + hour = 0; + } + } + } + call Led.set(deciSec < 1); + call Max549.outA(sec); + call Max549.outB(min); + call Sec.decimal0(sec); + call Min.decimal0(min); + call Hour.decimal0(hour); + } +} + +/* + * Local Variables: + * c-file-style: "bsd" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: set et ts=4 sw=4: + */ diff --git a/apps/tests/msp430-small/max549/Clock/DisplayC.nc b/apps/tests/msp430-small/max549/Clock/DisplayC.nc new file mode 100644 index 0000000..8669f7d --- /dev/null +++ b/apps/tests/msp430-small/max549/Clock/DisplayC.nc @@ -0,0 +1,40 @@ +/* -*- mode: nesc; mode: flyspell-prog; -*- */ + +configuration DisplayC { + provides { + interface Led7Segs as Sec; + interface Led7Segs as Min; + interface Led7Segs as Hour; + } +} +implementation { + components MainC; + components GpioConf as GpioC; + components PlatformSpiC as SpiC; + components new Max6951P("HH:MM:SS") as LED8Digits; + components new Led7SegsC("HH:MM:SS", 2, uint16_t) as S; + components new Led7SegsC("HH:MM:SS", 2, uint16_t) as M; + components new Led7SegsC("HH:MM:SS", 2, uint16_t) as H; + + Sec = S; + Min = M; + Hour = H; + + LED8Digits.Boot -> MainC.Boot; + LED8Digits.CS -> GpioC.STE; + LED8Digits.SpiByte -> SpiC; + LED8Digits.SpiControl -> SpiC; + + S.Led7Seg -> LED8Digits; + M.Led7Seg -> LED8Digits; + H.Led7Seg -> LED8Digits; +} + +/* + * Local Variables: + * c-file-style: "bsd" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: set et ts=4 sw=4: + */ diff --git a/apps/tests/msp430-small/max549/Clock/Makefile b/apps/tests/msp430-small/max549/Clock/Makefile new file mode 100644 index 0000000..4e57c62 --- /dev/null +++ b/apps/tests/msp430-small/max549/Clock/Makefile @@ -0,0 +1,8 @@ +# -*- mode: makefile-gmake; mode: flyspell-prog; -*- + +COMPONENT=ClockAppC +PFLAGS+=-I$(TOSDIR)/chips/max6951 +PFLAGS+=-I$(TOSDIR)/chips/max549 +include $(MAKERULES) + +# vim: set noet ts=8 sw=8: diff --git a/tos/chips/max549/Max549.nc b/tos/chips/max549/Max549.nc new file mode 100644 index 0000000..b6cd5af --- /dev/null +++ b/tos/chips/max549/Max549.nc @@ -0,0 +1,51 @@ +/* -*- mode: nesc; mode: flyspell-prog; -*- */ +/* Copyright (c) 2011, Tadashi G. Takaoka + * 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 Tadashi G. Takaoka 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 HOLDER 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. + */ + +/** An interface of MAX549 2ch 8-bit DAC + * + * @author Tadashi G. Takaoka + */ +interface Max549 { + async command void outA(uint8_t data); + async command void outB(uint8_t data); + async command void outAB(uint8_t data); + async command void shutdown(); +} + +/* + * Local Variables: + * c-file-style: "bsd" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: set et ts=4 sw=4: + */ diff --git a/tos/chips/max549/Max549P.nc b/tos/chips/max549/Max549P.nc new file mode 100644 index 0000000..2fcfd43 --- /dev/null +++ b/tos/chips/max549/Max549P.nc @@ -0,0 +1,86 @@ +/* -*- mode: nesc; mode: flyspell-prog; -*- */ +/* Copyright (c) 2011, Tadashi G. Takaoka + * 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 Tadashi G. Takaoka 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 HOLDER 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. + */ + +/** An implementation of MAX549 2ch 8-bit DAC + * + * @author Tadashi G. Takaoka + */ +generic module Max549P() { + provides interface Max549; + uses { + interface StdControl as SpiControl; + interface SpiByte; + interface GeneralIO as CS; + interface Boot; + } +} +implementation { + void write(unsigned data) { + call CS.clr(); + call SpiByte.write(data >> 8); + call SpiByte.write(data); + call CS.set(); + } + + void event Boot.booted() { + atomic { + call CS.set(); + call CS.makeOutput(); + call SpiControl.start(); + } + } + + async command void Max549.outA(uint8_t data) { + write(0x0900 | data); + } + + async command void Max549.outB(uint8_t data) { + write(0x0a00 | data); + } + + async command void Max549.outAB(uint8_t data) { + write(0x0b00 | data); + } + + async command void Max549.shutdown() { + write(0x1000); + } +} + +/* + * Local Variables: + * c-file-style: "bsd" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: set et ts=4 sw=4: + */