This repository has been archived by the owner on Sep 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
338 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<uint16_t> as Hour; | ||
uses interface Led7Segs<uint16_t> as Min; | ||
uses interface Led7Segs<uint16_t> as Sec; | ||
uses interface Led; | ||
uses interface Timer16<TMilli> 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: | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* -*- mode: nesc; mode: flyspell-prog; -*- */ | ||
|
||
configuration DisplayC { | ||
provides { | ||
interface Led7Segs<uint16_t> as Sec; | ||
interface Led7Segs<uint16_t> as Min; | ||
interface Led7Segs<uint16_t> 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: | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <tadashi.g.takaoka@gmail.com> | ||
*/ | ||
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: | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <tadashi.g.takaoka@gmail.com> | ||
*/ | ||
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: | ||
*/ |