[Tinyos-2-commits] CVS: tinyos-2.x/tos/chips/mm74hc595
MM74HC595C.nc, NONE, 1.1.2.1 MM74HC595ImplP.nc, NONE,
1.1.2.1 MM74HC595P.nc, NONE, 1.1.2.1
Henri DF
henridf at users.sourceforge.net
Wed Jun 7 12:40:07 PDT 2006
Update of /cvsroot/tinyos/tinyos-2.x/tos/chips/mm74hc595
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv4523/mm74hc595
Added Files:
Tag: tinyos-2_0_devel-BRANCH
MM74HC595C.nc MM74HC595ImplP.nc MM74HC595P.nc
Log Message:
Driver for the Fairchild MM74HC595 8-bit shift register (single in multiple out)
--- NEW FILE: MM74HC595C.nc ---
/*
* Copyright (c) 2006, Ecole Polytechnique Federale de Lausanne (EPFL),
* Switzerland.
* 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 Ecole Polytechnique Federale de Lausanne (EPFL)
* 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.
*
* ========================================================================
*/
/*
* This configuration provides 'virtual' output pins using the
* mm74hc595 Serial-In Parallel-Out (SIPO) chip from Fairchild Semiconductor.
*
* This driver expects to find a HPL module called HplMM74HC595PinsC (that should
* be implemented for a platform or sensorboard) providing GeneralIO interfaces for
* the three physical pins of the MM74HC595 that it uses.
*
* These virtual output pins are presented as implementing the
* GeneralIO interface. Calling GeneralIO.makeOutput() or GeneralIO.makeInput()
* has no effect -- these pins are always outputs.
*
* @author Henri Dubois-Ferriere
*
*/
configuration MM74HC595C {
provides interface GeneralIO as VirtualPin0; // Q_A on MM74HC595 datasheet
provides interface GeneralIO as VirtualPin1; // Q_B
provides interface GeneralIO as VirtualPin2; // Q_C
provides interface GeneralIO as VirtualPin3; // Q_D
provides interface GeneralIO as VirtualPin4; // Q_E
provides interface GeneralIO as VirtualPin5; // Q_F
provides interface GeneralIO as VirtualPin6; // Q_G
provides interface GeneralIO as VirtualPin7; // Q_H
}
implementation {
components MM74HC595ImplP, HplMM74HC595PinsC;
MM74HC595ImplP.Ser -> HplMM74HC595C.Ser;
MM74HC595ImplP.Sck -> HplMM74HC595C.Sck;
MM74HC595ImplP.Rck -> HplMM74HC595C.Rck;
components MainC;
MainC.SoftwareInit -> MM74HC595ImplP.Init;
components BusyWaitMicroC;
MM74HC595ImplP.BusyWait -> BusyWaitMicroC;
components new MM74HC595P(0) as VPin0;
VPin0.set -> MM74HC595ImplP.set;
VPin0.get -> MM74HC595ImplP.get;
VPin0.toggle -> MM74HC595ImplP.toggle;
VPin0.clr -> MM74HC595ImplP.clr;
VirtualPin0 = VPin0;
components new MM74HC595P(1) as VPin1;
VPin1.set -> MM74HC595ImplP.set;
VPin1.get -> MM74HC595ImplP.get;
VPin1.toggle -> MM74HC595ImplP.toggle;
VPin1.clr -> MM74HC595ImplP.clr;
VirtualPin1 = VPin1;
components new MM74HC595P(2) as VPin2;
VPin2.set -> MM74HC595ImplP.set;
VPin2.get -> MM74HC595ImplP.get;
VPin2.toggle -> MM74HC595ImplP.toggle;
VPin2.clr -> MM74HC595ImplP.clr;
VirtualPin2 = VPin2;
components new MM74HC595P(3) as VPin3;
VPin3.set -> MM74HC595ImplP.set;
VPin3.get -> MM74HC595ImplP.get;
VPin3.toggle -> MM74HC595ImplP.toggle;
VPin3.clr -> MM74HC595ImplP.clr;
VirtualPin3 = VPin3;
components new MM74HC595P(4) as VPin4;
VPin4.set -> MM74HC595ImplP.set;
VPin4.get -> MM74HC595ImplP.get;
VPin4.toggle -> MM74HC595ImplP.toggle;
VPin4.clr -> MM74HC595ImplP.clr;
VirtualPin4 = VPin4;
components new MM74HC595P(5) as VPin5;
VPin5.set -> MM74HC595ImplP.set;
VPin5.get -> MM74HC595ImplP.get;
VPin5.toggle -> MM74HC595ImplP.toggle;
VPin5.clr -> MM74HC595ImplP.clr;
VirtualPin5 = VPin5;
components new MM74HC595P(6) as VPin6;
VPin6.set -> MM74HC595ImplP.set;
VPin6.get -> MM74HC595ImplP.get;
VPin6.toggle -> MM74HC595ImplP.toggle;
VPin6.clr -> MM74HC595ImplP.clr;
VirtualPin6 = VPin6;
components new MM74HC595P(7) as VPin7;
VPin7.set -> MM74HC595ImplP.set;
VPin7.get -> MM74HC595ImplP.get;
VPin7.toggle -> MM74HC595ImplP.toggle;
VPin7.clr -> MM74HC595ImplP.clr;
VirtualPin7 = VPin7;
}
--- NEW FILE: MM74HC595ImplP.nc ---
/*
* Copyright (c) 2006, Ecole Polytechnique Federale de Lausanne (EPFL),
* Switzerland.
* 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 Ecole Polytechnique Federale de Lausanne (EPFL)
* 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.
*
* ========================================================================
*/
/*
* mm74hc595 driver internals.
*
* @author Henri Dubois-Ferriere
*
*/
module MM74HC595ImplP
{
provides interface Init @atleastonce();
provides async command void set(uint8_t pin);
provides async command bool get(uint8_t pin);
provides async command void clr(uint8_t pin);
provides async command void toggle(uint8_t pin);
uses interface GeneralIO as Ser;
uses interface GeneralIO as Rck;
uses interface GeneralIO as Sck;
uses interface BusyWait<TMicro, uint16_t>;
}
implementation
{
enum {
npins = 8
};
uint8_t state;
void writeState() {
uint8_t i, s;
atomic s = state;
call Rck.clr();
for (i = 0; i < npins; i++) {
call Sck.clr();
if (s & 0x80) {
call Ser.set();
} else {
call Ser.clr();
}
call Sck.set();
s <<= 1;
}
call Rck.set();
call Sck.clr();
call Ser.clr();
call Rck.clr();
}
command error_t Init.init() {
state = 0;
call Ser.makeOutput();
call Sck.makeOutput();
call Rck.makeOutput();
call Sck.clr();
call Rck.clr();
call Ser.clr();
writeState();
return SUCCESS;
}
async command void set(uint8_t pin) {
atomic {
state |= (1 << pin);
writeState();
}
}
async command bool get(uint8_t pin) {
atomic return (state >> pin) & 1;
}
async command void clr(uint8_t pin) {
atomic {
state &= ~(1 << pin);
writeState();
}
}
async command void toggle(uint8_t pin) {
if (call get(pin))
call clr(pin);
else
call set(pin);
}
}
--- NEW FILE: MM74HC595P.nc ---
/*
* Copyright (c) 2006, Ecole Polytechnique Federale de Lausanne (EPFL),
* Switzerland.
* 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 Ecole Polytechnique Federale de Lausanne (EPFL)
* 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 Henri Dubois-Ferriere
*
* This is an internal module of the mm74hc595 Serial-In Parallel-Out (SIPO) driver.
* Do not wire to this -- use MM74HC595C instead.
*
*/
generic module MM74HC595P(uint8_t outaddr)
{
provides interface GeneralIO;
uses async command void set(uint8_t pin);
uses async command bool get(uint8_t pin);
uses async command void clr(uint8_t pin);
uses async command void toggle(uint8_t pin);
}
implementation
{
async command void GeneralIO.set() {
call set(outaddr);
}
async command bool GeneralIO.get() {
return call get(outaddr);
}
async command void GeneralIO.clr() {
call clr(outaddr);
}
async command void GeneralIO.toggle() {
call toggle(outaddr);
}
async command void GeneralIO.makeInput() {
}
async command void GeneralIO.makeOutput() {
}
}
More information about the Tinyos-2-commits
mailing list