[Tinyos-2-commits] CVS: tinyos-2.x/tos/chips/msp430/usart Msp430Spi1C.nc, NONE, 1.1.4.2 Msp430SpiConfigure.nc, NONE, 1.1.4.2 Msp430SpiDma1P.nc, NONE, 1.1.4.2 Msp430SpiNoDma1P.nc, NONE, 1.1.4.2 Msp430Uart0C.nc, NONE, 1.1.4.2 Msp430Uart0P.nc, NONE, 1.1.4.2 Msp430Uart1P.nc, NONE, 1.1.4.2 Msp430UartConfigure.nc, NONE, 1.1.4.2 Msp430UartControl.nc, NONE, 1.1.4.2 Msp430Usart1C.nc, NONE, 1.1.4.2 Msp430UsartShare1P.nc, NONE, 1.1.4.2 HplMsp430Usart0C.nc, 1.1.2.8, 1.1.2.9 HplMsp430Usart0P.nc, 1.1.2.8, 1.1.2.9 HplMsp430Usart1C.nc, 1.1.2.7, 1.1.2.8 HplMsp430Usart1P.nc, 1.1.2.5, 1.1.2.6 HplMsp430UsartInterrupts.nc, 1.1.2.2, 1.1.2.3 HplMsp430Usart.nc, 1.1.2.4, 1.1.2.5 Msp430I2C0P.nc, 1.1.2.1, 1.1.2.2 Msp430I2CC.nc, 1.1.2.1, 1.1.2.2 Msp430I2CP.nc, 1.1.2.1, 1.1.2.2 Msp430Spi0C.nc, 1.1.2.9, 1.1.2.10 Msp430SpiDma0P.nc, 1.1.2.4, 1.1.2.5 Msp430SpiDmaP.nc, 1.1.2.3, 1.1.2.4 Msp430SpiNoDma0P.nc, 1.1.2.4, 1.1.2.5 Msp430SpiNoDmaP.nc, 1.1.2.3, 1.1.2.4 Msp430Uart1C.nc, 1.1.2.8, 1.1.2.9 Msp430UartP.nc, 1.1.2.7, 1.1.2.8 Msp430Usart0C.nc, 1.1.2.5, 1.1.2.6 msp430usart.h, 1.1.2.1, 1.1.2.2 Msp430UsartShare0P.nc, 1.1.2.5, 1.1.2.6 msp430baudrates.h, 1.1.2.1, NONE msp430UsartResource.h, 1.1.2.3, NONE

Philipp Huppertz phihup at users.sourceforge.net
Thu Aug 3 11:10:44 PDT 2006


Update of /cvsroot/tinyos/tinyos-2.x/tos/chips/msp430/usart
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv23626/tos/chips/msp430/usart

Modified Files:
      Tag: tinyos-2_0_devel-BRANCH
	HplMsp430Usart0C.nc HplMsp430Usart0P.nc HplMsp430Usart1C.nc 
	HplMsp430Usart1P.nc HplMsp430UsartInterrupts.nc 
	HplMsp430Usart.nc Msp430I2C0P.nc Msp430I2CC.nc Msp430I2CP.nc 
	Msp430Spi0C.nc Msp430SpiDma0P.nc Msp430SpiDmaP.nc 
	Msp430SpiNoDma0P.nc Msp430SpiNoDmaP.nc Msp430Uart1C.nc 
	Msp430UartP.nc Msp430Usart0C.nc msp430usart.h 
	Msp430UsartShare0P.nc 
Added Files:
      Tag: tinyos-2_0_devel-BRANCH
	Msp430Spi1C.nc Msp430SpiConfigure.nc Msp430SpiDma1P.nc 
	Msp430SpiNoDma1P.nc Msp430Uart0C.nc Msp430Uart0P.nc 
	Msp430Uart1P.nc Msp430UartConfigure.nc Msp430UartControl.nc 
	Msp430Usart1C.nc Msp430UsartShare1P.nc 
Removed Files:
      Tag: tinyos-2_0_devel-BRANCH
	msp430baudrates.h msp430UsartResource.h 
Log Message:
- new usart configure implementation moved from tos-2-msp430-usart-configure-candidate to devel_branch

--- NEW FILE: Msp430Spi1C.nc ---
/**
 * Copyright (c) 2005-2006 Arched Rock Corporation
 * 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 Arched Rock Corporation 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
 * ARCHED ROCK OR ITS 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 the SPI on USART0 for the MSP430. The current
 * implementation defaults not using the DMA and performing the SPI
 * transfers in software. To utilize the DMA, use Msp430SpiDma0P in
 * place of Msp430SpiNoDma0P.
 *
 * @author Jonathan Hui <jhui at archedrock.com>
 * @version $Revision: 1.1.4.2 $ $Date: 2006/08/03 18:10:41 $
 */

#include "msp430usart.h"

generic configuration Msp430Spi1C() {

  provides interface Resource;
  provides interface SpiByte;
  provides interface SpiPacket;

  uses interface Msp430SpiConfigure;
}

implementation {

  enum {
    CLIENT_ID = unique( MSP430_SPI1_BUS ),
  };

  components Msp430SpiNoDma1P as SpiP;
  Resource = SpiP.Resource[ CLIENT_ID ];
  SpiByte = SpiP.SpiByte;
  SpiPacket = SpiP.SpiPacket[ CLIENT_ID ];
  Msp430SpiConfigure = SpiP.Msp430SpiConfigure[ CLIENT_ID ];

  components new Msp430Usart1C() as UsartC;
  SpiP.ResourceConfigure[ CLIENT_ID ] <- UsartC.ResourceConfigure;
  SpiP.UsartResource[ CLIENT_ID ] -> UsartC.Resource;
  SpiP.UsartInterrupts -> UsartC.HplMsp430UsartInterrupts;

}

--- NEW FILE: Msp430SpiConfigure.nc ---
/*
 * Copyright (c) 2004-2006, Technische Universitaet Berlin
 * 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 Universitaet 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.
 */

/**
 * Interface used by Msp430Spi clients to reconfigure the SPI before use
 * @author Vlado Handziski <handzisk at tkn.tu-berlin.de>
 * @version $Revision: 1.1.4.2 $ $Date: 2006/08/03 18:10:41 $
 */

#include "msp430usart.h"

interface Msp430SpiConfigure {
  async command msp430_spi_config_t* getConfig();
}

--- NEW FILE: Msp430SpiDma1P.nc ---
/**
 * Copyright (c) 2005-2006 Arched Rock Corporation
 * 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 Arched Rock Corporation 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
 * ARCHED ROCK OR ITS 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 Jonathan Hui <jhui at archedrock.com>
 * @version $Revision: 1.1.4.2 $ $Date: 2006/08/03 18:10:41 $
 */

configuration Msp430SpiDma1P {

  provides interface Resource[ uint8_t id ];
  provides interface ResourceControl [uint8_t id];
  provides interface SpiByte;
  provides interface SpiPacket[ uint8_t id ];

  uses interface Resource as UsartResource[ uint8_t id ];
  uses interface Msp430SpiConfigure[ uint8_t id ];
  uses interface HplMsp430UsartInterrupts as UsartInterrupts;

}

implementation {

  components new Msp430SpiDmaP() as SpiP;
  Resource = SpiP.Resource;
  ResourceControl = SpiP.ResourceControl;
  Msp430SpiConfigure = SpiP.Msp430SpiConfigure;
  SpiByte = SpiP.SpiByte;
  SpiPacket = SpiP.SpiPacket;
  UsartResource = SpiP.UsartResource;
  UsartInterrupts = SpiP.UsartInterrupts;

  components HplMsp430Usart1C as UsartC;
  SpiP.Usart -> UsartC;

  components Msp430DmaC as DmaC;
  SpiP.DmaChannel1 -> DmaC.Channel1;
  SpiP.DmaChannel2 -> DmaC.Channel2;

  components LedsC as Leds;
  SpiP.Leds -> Leds;

}

--- NEW FILE: Msp430SpiNoDma1P.nc ---
/**
 * Copyright (c) 2005-2006 Arched Rock Corporation
 * 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 Arched Rock Corporation 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
 * ARCHED ROCK OR ITS 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 Jonathan Hui <jhui at archedrock.com>
 * @version $Revision: 1.1.4.2 $ $Date: 2006/08/03 18:10:41 $
 */

configuration Msp430SpiNoDma1P {

  provides interface Resource[ uint8_t id ];
  provides interface ResourceConfigure[uint8_t id ];
  provides interface SpiByte;
  provides interface SpiPacket[ uint8_t id ];

  uses interface Resource as UsartResource[ uint8_t id ];
  uses interface Msp430SpiConfigure[ uint8_t id ];
  uses interface HplMsp430UsartInterrupts as UsartInterrupts;

}

implementation {

  components new Msp430SpiNoDmaP() as SpiP;
  Resource = SpiP.Resource;
  ResourceConfigure = SpiP.ResourceConfigure;
  Msp430SpiConfigure = SpiP.Msp430SpiConfigure;
  SpiByte = SpiP.SpiByte;
  SpiPacket = SpiP.SpiPacket;
  UsartResource = SpiP.UsartResource;
  UsartInterrupts = SpiP.UsartInterrupts;

  components HplMsp430Usart1C as UsartC;
  SpiP.Usart -> UsartC;

  components LedsC as Leds;
  SpiP.Leds -> Leds;

}

--- NEW FILE: Msp430Uart0C.nc ---
/**
 * Copyright (c) 2005-2006 Arched Rock Corporation
 * 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 Arched Rock Corporation 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
 * ARCHED ROCK OR ITS 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 the UART on USART0 for the MSP430.
 * @author Vlado Handziski <handzisk at tkn.tu-berlin.de>
 * @author Jonathan Hui <jhui at archedrock.com>
 * @version $Revision: 1.1.4.2 $ $Date: 2006/08/03 18:10:41 $
 */

#include "msp430usart.h"

generic configuration Msp430Uart0C() {

  provides interface Resource;
  provides interface SerialByteComm;
  provides interface Msp430UartControl as UartControl;

  uses interface Msp430UartConfigure;
}

implementation {

  enum {
    CLIENT_ID = unique( MSP430_UARTO_BUS ),
  };

  components Msp430Uart0P as UartP;
  Resource = UartP.Resource[ CLIENT_ID ];
  SerialByteComm = UartP.SerialByteComm;
  UartControl = UartP.UartControl[ CLIENT_ID ];
  Msp430UartConfigure = UartP.Msp430UartConfigure[ CLIENT_ID ];

  components new Msp430Usart0C() as UsartC;
  UartP.ResourceConfigure[ CLIENT_ID ] <- UsartC.ResourceConfigure;
  UartP.UsartResource[ CLIENT_ID ] -> UsartC.Resource;
  UartP.UsartInterrupts -> UsartC.HplMsp430UsartInterrupts;

}

--- NEW FILE: Msp430Uart0P.nc ---
/**
 * Copyright (c) 2005-2006 Arched Rock Corporation
 * 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 Arched Rock Corporation 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
 * ARCHED ROCK OR ITS 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 Jonathan Hui <jhui at archedrock.com>
 * @author Vlado Handziski <handzisk at tkn.tu-berlin.de>
 * @version $Revision: 1.1.4.2 $ $Date: 2006/08/03 18:10:41 $
 */

configuration Msp430Uart0P {

  provides interface Resource[ uint8_t id ];
  provides interface ResourceConfigure[uint8_t id ];
  provides interface Msp430UartControl as UartControl[ uint8_t id ];
  provides interface SerialByteComm;

  uses interface Resource as UsartResource[ uint8_t id ];
  uses interface Msp430UartConfigure[ uint8_t id ];
  uses interface HplMsp430UsartInterrupts as UsartInterrupts;

}

implementation {

  components new Msp430UartP() as UartP;
  Resource = UartP.Resource;
  ResourceConfigure = UartP.ResourceConfigure;
  Msp430UartConfigure = UartP.Msp430UartConfigure;
  UartControl = UartP.UartControl;
  SerialByteComm = UartP.SerialByteComm;
  UsartResource = UartP.UsartResource;
  UsartInterrupts = UartP.UsartInterrupts;

  components HplMsp430Usart0C as UsartC;
  UartP.Usart -> UsartC;

  components LedsC as Leds;
  UartP.Leds -> Leds;

}

--- NEW FILE: Msp430Uart1P.nc ---
/**
 * Copyright (c) 2005-2006 Arched Rock Corporation
 * 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 Arched Rock Corporation 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
 * ARCHED ROCK OR ITS 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 Jonathan Hui <jhui at archedrock.com>
 * @author Vlado Handziski <handzisk at tkn.tu-berlin.de>
 * @version $Revision: 1.1.4.2 $ $Date: 2006/08/03 18:10:41 $
 */

configuration Msp430Uart1P {

  provides interface Resource[ uint8_t id ];
  provides interface ResourceConfigure[uint8_t id ];
  provides interface Msp430UartControl as UartControl[ uint8_t id ];
  provides interface SerialByteComm;

  uses interface Resource as UsartResource[ uint8_t id ];
  uses interface Msp430UartConfigure[ uint8_t id ];
  uses interface HplMsp430UsartInterrupts as UsartInterrupts;

}

implementation {

  components new Msp430UartP() as UartP;
  Resource = UartP.Resource;
  ResourceConfigure = UartP.ResourceConfigure;
  Msp430UartConfigure = UartP.Msp430UartConfigure;
  UartControl = UartP.UartControl;
  SerialByteComm = UartP.SerialByteComm;
  UsartResource = UartP.UsartResource;
  UsartInterrupts = UartP.UsartInterrupts;

  components HplMsp430Usart1C as UsartC;
  UartP.Usart -> UsartC;

  components LedsC as Leds;
  UartP.Leds -> Leds;

}

--- NEW FILE: Msp430UartConfigure.nc ---
/*
 * Copyright (c) 2004-2006, Technische Universitaet Berlin
 * 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 Universitaet 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.
 */

/**
 * Interface used by Msp430Uart clients to reconfigure the UART before use
 * @author Vlado Handziski <handzisk at tkn.tu-berlin.de>
 * @version $Revision: 1.1.4.2 $ $Date: 2006/08/03 18:10:41 $
 */

#include "msp430usart.h"

interface Msp430UartConfigure {
  async command msp430_uart_config_t* getConfig();
}

--- NEW FILE: Msp430UartControl.nc ---
/*
 * Copyright (c) 2004-2006, Technische Universitaet Berlin
 * 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 Universitaet 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.
 */

/**
 * Interface used by Msp430Uart clients to control/configure the Uart.
 *
 * @author Philipp Huppertz (huppertz at tkn.tu-berlin.de)
 */
interface Msp430UartControl {

  /**
  * Sets the Uart to Rx mode.
  */
  async command void setModeRx();
  
  /**
  * Sets the Uart to Tx mode.
  */
  async command void setModeTx();
  
  /**
  * Sets the Uart to duplex mode.
  */
  async command void setModeDuplex();
  
}

--- NEW FILE: Msp430Usart1C.nc ---
/**
 * Copyright (c) 2005-2006 Arched Rock Corporation
 * 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 Arched Rock Corporation 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
 * ARCHED ROCK OR ITS 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
 */

/**
 * Provides an interface for USART1 on the MSP430.
 *
 * @author Vlado Handziski <handisk at tkn.tu-berlin.de>
 * @author Jonathan Hui <jhui at archedrock.com>
 * @version $Revision: 1.1.4.2 $ $Date: 2006/08/03 18:10:41 $
 */

generic configuration Msp430Usart1C() {

  provides interface Resource;
  provides interface ArbiterInfo;
  provides interface HplMsp430Usart;
  provides interface HplMsp430UsartInterrupts;

  uses interface ResourceConfigure;
}

implementation {

  enum {
    CLIENT_ID = unique( MSP430_HPLUSART1_RESOURCE ),
  };

  components Msp430UsartShare1P as UsartShareP;

  Resource = UsartShareP.Resource[ CLIENT_ID ];
  ResourceConfigure = UsartShareP.ResourceConfigure[ CLIENT_ID ];
  ArbiterInfo = UsartShareP.ArbiterInfo;
  HplMsp430UsartInterrupts = UsartShareP.Interrupts[ CLIENT_ID ];

  components HplMsp430Usart1C as UsartC;
  HplMsp430Usart = UsartC;

}

--- NEW FILE: Msp430UsartShare1P.nc ---
/**
 * Copyright (c) 2005-2006 Arched Rock Corporation
 * 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 Arched Rock Corporation 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
 * ARCHED ROCK OR ITS 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 Vlado Handziski <handzisk at tkn.tu-berlin.de>
 * @author Jonathan Hui <jhui at archedrock.com>
 * @version $Revision: 1.1.4.2 $ $Date: 2006/08/03 18:10:41 $
 */

configuration Msp430UsartShare1P {

  provides interface HplMsp430UsartInterrupts as Interrupts[ uint8_t id ];
  provides interface Resource[ uint8_t id ];
  provides interface ArbiterInfo;

  uses interface ResourceConfigure[ uint8_t id ];
}

implementation {

  components new Msp430UsartShareP() as UsartShareP;
  Interrupts = UsartShareP;
  UsartShareP.RawInterrupts -> UsartC;

  components new FcfsArbiterC( MSP430_HPLUSART1_RESOURCE ) as ArbiterC;
  Resource = ArbiterC;
  ResourceConfigure = ArbiterC;
  ArbiterInfo = ArbiterC;
  UsartShareP.ArbiterInfo -> ArbiterC;

  components new AsyncStdControlPowerManagerC() as PowerManagerC;
  PowerManagerC.ResourceController -> ArbiterC;
	PowerManagerC.ArbiterInit -> ArbiterC;
	
  components HplMsp430Usart1C as UsartC;
  PowerManagerC.AsyncStdControl -> UsartC;
	
	components MainC;
	MainC.SoftwareInit -> ArbiterC;
	MainC.SoftwareInit -> PowerManagerC;
}

Index: HplMsp430Usart0C.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/chips/msp430/usart/HplMsp430Usart0C.nc,v
retrieving revision 1.1.2.8
retrieving revision 1.1.2.9
diff -C2 -d -r1.1.2.8 -r1.1.2.9
*** HplMsp430Usart0C.nc	1 Aug 2006 16:36:24 -0000	1.1.2.8
--- HplMsp430Usart0C.nc	3 Aug 2006 18:10:41 -0000	1.1.2.9
***************
*** 62,66 ****
   */
  
! #include "msp430UsartResource.h"
  
  configuration HplMsp430Usart0C {
--- 62,66 ----
   */
  
! #include "msp430usart.h"
  
  configuration HplMsp430Usart0C {

Index: HplMsp430Usart0P.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/chips/msp430/usart/HplMsp430Usart0P.nc,v
retrieving revision 1.1.2.8
retrieving revision 1.1.2.9
diff -C2 -d -r1.1.2.8 -r1.1.2.9
*** HplMsp430Usart0P.nc	1 Aug 2006 16:36:24 -0000	1.1.2.8
--- HplMsp430Usart0P.nc	3 Aug 2006 18:10:41 -0000	1.1.2.9
***************
*** 1,4 ****
! /*
!  * Copyright (c) 2005-2006 Arch Rock Corporation
   * All rights reserved.
   *
--- 1,4 ----
! /**
!  * Copyright (c) 2005-2006 Arched Rock Corporation
   * All rights reserved.
   *
***************
*** 12,16 ****
   *   documentation and/or other materials provided with the
   *   distribution.
!  * - Neither the name of the Arch Rock Corporation nor the names of
   *   its contributors may be used to endorse or promote products derived
   *   from this software without specific prior written permission.
--- 12,16 ----
   *   documentation and/or other materials provided with the
   *   distribution.
!  * - Neither the name of the Arched Rock Corporation nor the names of
   *   its contributors may be used to endorse or promote products derived
   *   from this software without specific prior written permission.
***************
*** 30,35 ****
   */
  
! /*
!  * Copyright (c) 2004-2005, Technische Universitat Berlin
   * All rights reserved.
   *
--- 30,35 ----
   */
  
! /**
!  * Copyright (c) 2004-2005, Technische Universitaet Berlin
   * All rights reserved.
   *
***************
*** 42,46 ****
   *   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 Universitat Berlin nor the names
   *   of its contributors may be used to endorse or promote products derived
   *   from this software without specific prior written permission.
--- 42,46 ----
   *   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 Universitaet Berlin nor the names
   *   of its contributors may be used to endorse or promote products derived
   *   from this software without specific prior written permission.
***************
*** 59,62 ****
--- 59,63 ----
   */
  
+ #include "msp430usart.h"
  /**
   * Implementation of USART0 lowlevel functionality - stateless.
***************
*** 64,68 ****
   *
   * @author: Jan Hauer <hauer at tkn.tu-berlin.de>
!  * @author: Jonathan Hui <jhui at archrock.com>
   * @author: Joe Polastre
   * @version $Revision$ $Date$
--- 65,70 ----
   *
   * @author: Jan Hauer <hauer at tkn.tu-berlin.de>
!  * @author: Jonathan Hui <jhui at archedrock.com>
!  * @author: Vlado Handziski <handzisk at tkn.tu-berlin.de>
   * @author: Joe Polastre
   * @version $Revision$ $Date$
***************
*** 73,77 ****
    provides interface HplMsp430Usart as Usart;
    provides interface HplMsp430UsartInterrupts as Interrupts;
!   provides interface HplMsp430I2CInterrupts as I2CInterrupts;
  
    uses interface HplMsp430GeneralIO as SIMO;
--- 75,80 ----
    provides interface HplMsp430Usart as Usart;
    provides interface HplMsp430UsartInterrupts as Interrupts;
! 	provides interface HplMsp430I2CInterrupts as I2CInterrupts;
! 
  
    uses interface HplMsp430GeneralIO as SIMO;
***************
*** 80,84 ****
--- 83,89 ----
    uses interface HplMsp430GeneralIO as URXD;
    uses interface HplMsp430GeneralIO as UTXD;
+ 	
  }
+ 
  implementation
  {
***************
*** 87,101 ****
    MSP430REG_NORACE(IFG1);
    MSP430REG_NORACE(U0TCTL);
    MSP430REG_NORACE(U0TXBUF);
  
!   uint16_t l_br;
!   uint8_t l_mctl;
!   uint8_t l_ssel;
!   
    TOSH_SIGNAL(UART0RX_VECTOR) {
      uint8_t temp = U0RXBUF;
      signal Interrupts.rxDone(temp);
    }
!   
    TOSH_SIGNAL(UART0TX_VECTOR) {
      if ( call Usart.isI2C() )
--- 92,105 ----
    MSP430REG_NORACE(IFG1);
    MSP430REG_NORACE(U0TCTL);
+   MSP430REG_NORACE(U0RCTL);
    MSP430REG_NORACE(U0TXBUF);
  
! 
! 
    TOSH_SIGNAL(UART0RX_VECTOR) {
      uint8_t temp = U0RXBUF;
      signal Interrupts.rxDone(temp);
    }
! 
    TOSH_SIGNAL(UART0TX_VECTOR) {
      if ( call Usart.isI2C() )
***************
*** 104,120 ****
        signal Interrupts.txDone();
    }
!   
    async command error_t AsyncStdControl.start() {
      return SUCCESS;
    }
!   
    async command error_t AsyncStdControl.stop() {
!     call Usart.disableSPI();
      call Usart.disableI2C();
!     call Usart.disableUART();
      return SUCCESS;
    }
  
!   async command bool Usart.isSPI() {
      atomic {
        return (U0CTL & SYNC) && (ME1 & USPIE0);
--- 108,175 ----
        signal Interrupts.txDone();
    }
! 
    async command error_t AsyncStdControl.start() {
      return SUCCESS;
    }
! 
    async command error_t AsyncStdControl.stop() {
!     call Usart.disableSpi();
      call Usart.disableI2C();
!     call Usart.disableUart();
      return SUCCESS;
    }
  
! 
!   async command void Usart.setUctl(msp430_uctl_t control) {
!     U0CTL=uctl2int(control);
!   }
! 
!   async command msp430_uctl_t Usart.getUctl() {
!     return int2uctl(U0CTL);
!   }
! 
!   async command void Usart.setUtctl(msp430_utctl_t control) {
!     U0TCTL=utctl2int(control);
!   }
! 
!   async command msp430_utctl_t Usart.getUtctl() {
!     return int2utctl(U0TCTL);
!   }
! 
!   async command void Usart.setUrctl(msp430_urctl_t control) {
!     U0RCTL=urctl2int(control);
!   }
! 
!   async command msp430_urctl_t Usart.getUrctl() {
!     return int2urctl(U0RCTL);
!   }
! 
!   async command void Usart.setUbr(uint16_t control) {
!     atomic {
!       U0BR0 = control & 0x00FF;
!       U0BR1 = (control >> 8) & 0x00FF;
!     }
!   }
! 
!   async command uint16_t Usart.getUbr() {
!     return (U0BR1 << 8) + U0BR0;
!   }
! 
!   async command void Usart.setUmctl(uint8_t control) {
!     U0MCTL=control;
!   }
! 
!   async command uint8_t Usart.getUmctl() {
!     return U0MCTL;
!   }
! 
!   async command void Usart.resetUsart(bool reset) {
!     if (reset)
!       SET_FLAG(U0CTL, SWRST);
!     else
!       CLR_FLAG(U0CTL, SWRST);
!   }
! 
!   async command bool Usart.isSpi() {
      atomic {
        return (U0CTL & SYNC) && (ME1 & USPIE0);
***************
*** 122,126 ****
    }
  
!   async command bool Usart.isUART() {
      atomic {
        return !(U0CTL & SYNC) && ((ME1 & UTXE0) && (ME1 & URXE0));
--- 177,181 ----
    }
  
!   async command bool Usart.isUart() {
      atomic {
        return !(U0CTL & SYNC) && ((ME1 & UTXE0) && (ME1 & URXE0));
***************
*** 128,132 ****
    }
  
!   async command bool Usart.isUARTtx() {
      atomic {
        return !(U0CTL & SYNC) && (ME1 & UTXE0);
--- 183,187 ----
    }
  
!   async command bool Usart.isUartTx() {
      atomic {
        return !(U0CTL & SYNC) && (ME1 & UTXE0);
***************
*** 134,138 ****
    }
  
!   async command bool Usart.isUARTrx() {
      atomic {
        return !(U0CTL & SYNC) && (ME1 & URXE0);
--- 189,193 ----
    }
  
!   async command bool Usart.isUartRx() {
      atomic {
        return !(U0CTL & SYNC) && (ME1 & URXE0);
***************
*** 141,157 ****
  
    async command bool Usart.isI2C() {
!     atomic {
!       return ((U0CTL & I2C) && (U0CTL & SYNC) && (U0CTL & I2CEN));
!     }
    }
  
    async command msp430_usartmode_t Usart.getMode() {
!     if (call Usart.isUART())
        return USART_UART;
!     else if (call Usart.isUARTrx())
        return USART_UART_RX;
!     else if (call Usart.isUARTtx())
        return USART_UART_TX;
!     else if (call Usart.isSPI())
        return USART_SPI;
      else if (call Usart.isI2C())
--- 196,216 ----
  
    async command bool Usart.isI2C() {
!     #ifndef __msp430_have_usart0_with_i2c
!       return FALSE;
!     #else
!       atomic {
!         return ((U0CTL & I2C) && (U0CTL & SYNC) && (U0CTL & I2CEN));
!       }
!     #endif
    }
  
    async command msp430_usartmode_t Usart.getMode() {
!     if (call Usart.isUart())
        return USART_UART;
!     else if (call Usart.isUartRx())
        return USART_UART_RX;
!     else if (call Usart.isUartTx())
        return USART_UART_TX;
!     else if (call Usart.isSpi())
        return USART_SPI;
      else if (call Usart.isI2C())
***************
*** 161,191 ****
    }
  
!   /**
!    * Sets the USART mode to one of the options from msp430_usartmode_t
!    * defined in MSP430Usart.h
!    */
!   async command void Usart.setMode(msp430_usartmode_t _mode) {
!     switch (_mode) {
!     case USART_UART:
!       call Usart.setModeUART();
!       break;
!     case USART_UART_RX:
!       call Usart.setModeUART_RX();
!       break;
!     case USART_UART_TX:
!       call Usart.setModeUART_TX();
!       break;
!     case USART_SPI:
!       call Usart.setModeSPI();
!       break;
!     case USART_I2C:
!       call Usart.setModeI2C();
!       break;
!     default:
!       break;
!     }
!   }
! 
!   async command void Usart.enableUART() {
      atomic{
        call UTXD.selectModuleFunc();
--- 220,224 ----
    }
  
!   async command void Usart.enableUart() {
      atomic{
        call UTXD.selectModuleFunc();
***************
*** 195,199 ****
    }
  
!   async command void Usart.disableUART() {
      ME1 &= ~(UTXE0 | URXE0);   // USART0 UART module enable
      atomic {
--- 228,232 ----
    }
  
!   async command void Usart.disableUart() {
      ME1 &= ~(UTXE0 | URXE0);   // USART0 UART module enable
      atomic {
***************
*** 204,213 ****
    }
  
!   async command void Usart.enableUARTTx() {
      call UTXD.selectModuleFunc();
      ME1 |= UTXE0;   // USART0 UART Tx module enable
    }
  
!   async command void Usart.disableUARTTx() {
      ME1 &= ~UTXE0;   // USART0 UART Tx module enable
      call UTXD.selectIOFunc();
--- 237,246 ----
    }
  
!   async command void Usart.enableUartTx() {
      call UTXD.selectModuleFunc();
      ME1 |= UTXE0;   // USART0 UART Tx module enable
    }
  
!   async command void Usart.disableUartTx() {
      ME1 &= ~UTXE0;   // USART0 UART Tx module enable
      call UTXD.selectIOFunc();
***************
*** 215,224 ****
    }
  
!   async command void Usart.enableUARTRx() {
      call URXD.selectModuleFunc();
      ME1 |= URXE0;   // USART0 UART Rx module enable
    }
  
!   async command void Usart.disableUARTRx() {
      ME1 &= ~URXE0;  // USART0 UART Rx module disable
      call URXD.selectIOFunc();
--- 248,257 ----
    }
  
!   async command void Usart.enableUartRx() {
      call URXD.selectModuleFunc();
      ME1 |= URXE0;   // USART0 UART Rx module enable
    }
  
!   async command void Usart.disableUartRx() {
      ME1 &= ~URXE0;  // USART0 UART Rx module disable
      call URXD.selectIOFunc();
***************
*** 226,232 ****
    }
  
!   async command void Usart.enableSPI() {
!     ME1 |= USPIE0;   // USART0 SPI module enable
!     //FIXME: Set pins in ModuleFunction?
      atomic {
        call SIMO.selectModuleFunc();
--- 259,263 ----
    }
  
!   async command void Usart.enableSpi() {
      atomic {
        call SIMO.selectModuleFunc();
***************
*** 234,240 ****
        call UCLK.selectModuleFunc();
      }
    }
  
!   async command void Usart.disableSPI() {
      ME1 &= ~USPIE0;   // USART0 SPI module disable
      atomic {
--- 265,272 ----
        call UCLK.selectModuleFunc();
      }
+     ME1 |= USPIE0;   // USART0 SPI module enable
    }
  
!   async command void Usart.disableSpi() {
      ME1 &= ~USPIE0;   // USART0 SPI module disable
      atomic {
***************
*** 246,443 ****
  
    async command void Usart.enableI2C() {
!     atomic U0CTL |= I2C | I2CEN | SYNC;
    }
  
    async command void Usart.disableI2C() {
!     atomic U0CTL &= ~(I2C | I2CEN | SYNC);
!   }
! 
!   async command void Usart.setModeSPI() {
!     // check if we are already in SPI mode
!     if (call Usart.isSPI())
        return;
  
-     call Usart.disableUART();
-     call Usart.disableI2C();
- 
-     atomic {
-       call SIMO.selectModuleFunc();
-       call SOMI.selectModuleFunc();
-       call UCLK.selectModuleFunc();
  
!       U0CTL = SWRST;
!       U0CTL |= CHAR | SYNC | MM;  // 8-bit char, SPI-mode, USART as master
!       U0CTL &= ~(0x20);
  
!       U0TCTL = STC ;     // 3-pin
!       U0TCTL |= CKPH;    // half-cycle delayed UCLK
  
!       U0TCTL &= ~(SSEL_0 | SSEL_1 | SSEL_2 | SSEL_3);
!       if (l_ssel & 0x80)
!         U0TCTL |= (l_ssel & 0x7F);
!       else
!         U0TCTL |= SSEL_SMCLK; // use SMCLK, assuming 1MHz
  
!       if (l_br != 0) {
!         U0BR0 = l_br & 0x0FF;
!         U0BR1 = (l_br >> 8) & 0x0FF;
!       }
!       else {
!         U0BR0 = 0x02;   // as fast as possible
!         U0BR1 = 0x00;
!       }
!       U0MCTL = 0;
  
-       ME1 |= USPIE0;   // USART SPI module enable
-       U0CTL &= ~SWRST;
  
!       IFG1 &= ~(UTXIFG0 | URXIFG0);
!       IE1 &= ~(UTXIE0 | URXIE0);  // interrupt disabled
      }
      return;
    }
  
-   void setUARTModeCommon() {
-     atomic {
-       U0CTL = SWRST;
-       U0CTL |= CHAR;  // 8-bit char, UART-mode
- 
-       U0RCTL &= ~URXEIE;  // even erroneous characters trigger interrupts
  
  
!       U0CTL = SWRST;
!       U0CTL |= CHAR;  // 8-bit char, UART-mode
! 
!       if (l_ssel & 0x80) {
!         U0TCTL &= ~SSEL_3;
!         U0TCTL |= (l_ssel & 0x7F);
!       }
!       else {
!         U0TCTL &= ~SSEL_3;
!         U0TCTL |= SSEL_ACLK; // use ACLK, assuming 32khz
!       }
! 
!       if ((l_mctl != 0) || (l_br != 0)) {
!         U0BR0 = l_br & 0x0FF;
!         U0BR1 = (l_br >> 8) & 0x0FF;
!         U0MCTL = l_mctl;
!       }
!       else {
!         U0BR0 = 0x03;   // 9600 baud
!         U0BR1 = 0x00;
!         U0MCTL = 0x4A;
!       }
  
!       ME1 &= ~USPIE0;   // USART0 SPI module disable
!       ME1 |= (UTXE0 | URXE0); //USART0 UART module enable;
  
!       U0CTL &= ~SWRST;
  
!       IFG1 &= ~(UTXIFG0 | URXIFG0);
!       IE1 &= ~(UTXIE0 | URXIE0);  // interrupt disabled
!     }
!     return;
    }
  
!   async command void Usart.setModeUART_TX() {
!     // check if we are already in UART mode
!     if (call Usart.getMode() == USART_UART_TX)
!       return;
  
!     call Usart.disableSPI();
      call Usart.disableI2C();
!     call Usart.disableUART();
  
      atomic {
        call UTXD.selectModuleFunc();
        call URXD.selectIOFunc();
      }
!     setUARTModeCommon();
      return;
    }
  
!   async command void Usart.setModeUART_RX() {
!     // check if we are already in UART mode
!     if (call Usart.getMode() == USART_UART_RX)
!       return;
  
!     call Usart.disableSPI();
      call Usart.disableI2C();
!     call Usart.disableUART();
! 
      atomic {
        call UTXD.selectIOFunc();
        call URXD.selectModuleFunc();
      }
!     setUARTModeCommon();
      return;
    }
  
!   async command void Usart.setModeUART() {
!     // check if we are already in UART mode
!     if (call Usart.getMode() == USART_UART)
!       return;
  
!     call Usart.disableSPI();
      call Usart.disableI2C();
!     call Usart.disableUART();
  
      atomic {
        call UTXD.selectModuleFunc();
        call URXD.selectModuleFunc();
      }
!     setUARTModeCommon();
      return;
    }
  
!   // i2c enable bit is not set by default
!   async command void Usart.setModeI2C() {
!     
!     // check if we are already in I2C mode
!     if (call Usart.getMode() == USART_I2C)
        return;
!     
!     atomic {
!       U0CTL &= ~(I2C | I2CEN | SYNC);
!       U0CTL = SWRST;
!       U0CTL |= SYNC | I2C;
!       U0CTL &= ~I2CEN;
!       
!       call Usart.disableUART();
!       call Usart.disableSPI();
!       call SIMO.makeInput();
!       call SIMO.selectModuleFunc();
!       call UCLK.makeInput();
!       call UCLK.selectModuleFunc();
!       
!       U0CTL |= MST;
!       I2CTCTL = I2CRM | I2CSSEL_2;
!       I2CPSC = 0x00;
!       I2CSCLH = 0x03;
!       I2CSCLL = 0x03;
  
!       U0CTL |= I2CEN;
!     }
!     
!   }
  
!   async command void Usart.setClockSource(uint8_t source) {
!     atomic {
!       l_ssel = source | 0x80;
!       U0TCTL &= ~SSEL_3;
!       U0TCTL |= (l_ssel & 0x7F);
!     }
!   }
  
!   async command void Usart.setClockRate(uint16_t baudrate, uint8_t mctl) {
!     atomic {
!       l_br = baudrate;
!       l_mctl = mctl;
!       U0BR0 = baudrate & 0x0FF;
!       U0BR1 = (baudrate >> 8) & 0x0FF;
!       U0MCTL = mctl;
!     }
    }
  
    async command bool Usart.isTxIntrPending(){
      if (IFG1 & UTXIFG0){
--- 278,460 ----
  
    async command void Usart.enableI2C() {
!     #ifndef __msp430_have_usart0_with_i2c
!       return;
!     #else
!       atomic U0CTL |= I2C | I2CEN | SYNC;
!     #endif
    }
  
    async command void Usart.disableI2C() {
!     #ifndef __msp430_have_usart0_with_i2c
        return;
+     #else
+       atomic U0CTL &= ~(I2C | I2CEN | SYNC);
+     #endif
+   }
  
  
!   void configSpi(msp430_spi_config_t* config) {
!     msp430_uctl_t uctl = call Usart.getUctl();
!     msp430_utctl_t utctl = call Usart.getUtctl();
  
!     uctl.clen = config->clen;
!     uctl.listen = config->listen;
!     uctl.mm = config->mm;
!     uctl.sync = 1;
  
!     utctl.ckph = config->ckph;
!     utctl.ckpl = config->ckpl;
!     utctl.ssel = config->ssel;
!     utctl.stc = config->stc;
  
!     call Usart.setUctl(uctl);
!     call Usart.setUtctl(utctl);
!     call Usart.setUbr(config->ubr);
!     call Usart.setUmctl(0x00);
!   }
  
  
!   async command void Usart.setModeSpi(msp430_spi_config_t* config) {
!     call Usart.disableUart();
!     call Usart.disableI2C();
!     atomic {
!       call Usart.resetUsart(TRUE);
!       configSpi(config);
!       call Usart.enableSpi();
!       call Usart.resetUsart(FALSE);
!       call Usart.clrIntr();
!       call Usart.disableIntr();
      }
      return;
    }
  
  
+   void configUart(msp430_uart_config_t* config) {
+     msp430_uctl_t uctl = call Usart.getUctl();
+     msp430_utctl_t utctl = call Usart.getUtctl();
+     msp430_urctl_t urctl = call Usart.getUrctl();
  
!     uctl.pena = config->pena;
!     uctl.pev = config->pev;
!     uctl.spb = config->spb;
!     uctl.clen = config->clen;
!     uctl.listen = config->listen;
!     uctl.sync = 0;
!     uctl.mm = config->mm;
  
!     utctl.ckpl = config->ckpl;
!     utctl.ssel = config->ssel;
!     utctl.urxse = config->urxse;
  
!     urctl.urxeie = config->urxeie;
!     urctl.urxwie = config->urxwie;
  
!     call Usart.setUctl(uctl);
!     call Usart.setUtctl(utctl);
!     call Usart.setUrctl(urctl);
!     call Usart.setUbr(config->ubr);
!     call Usart.setUmctl(config->umctl);
    }
  
!   async command void Usart.setModeUartTx(msp430_uart_config_t* config) {
  
!     call Usart.disableSpi();
      call Usart.disableI2C();
!     call Usart.disableUart();
  
      atomic {
        call UTXD.selectModuleFunc();
        call URXD.selectIOFunc();
+       call Usart.resetUsart(TRUE);
+       configUart(config);
+       call Usart.enableUartTx();
+       call Usart.resetUsart(FALSE);
+       call Usart.clrIntr();
+       call Usart.disableIntr();
      }
! 
      return;
    }
  
!   async command void Usart.setModeUartRx(msp430_uart_config_t* config) {
  
!     call Usart.disableSpi();
      call Usart.disableI2C();
!     call Usart.disableUart();
!     
      atomic {
        call UTXD.selectIOFunc();
        call URXD.selectModuleFunc();
+       call Usart.resetUsart(TRUE);
+       configUart(config);
+       call Usart.enableUartRx();
+       call Usart.resetUsart(FALSE);
+       call Usart.clrIntr();
+       call Usart.disableIntr();
      }
!     
      return;
    }
  
!   async command void Usart.setModeUart(msp430_uart_config_t* config) {
  
!     call Usart.disableSpi();
      call Usart.disableI2C();
!     call Usart.disableUart();
  
      atomic {
        call UTXD.selectModuleFunc();
        call URXD.selectModuleFunc();
+       call Usart.resetUsart(TRUE);
+       configUart(config);
+       call Usart.enableUart();
+       call Usart.resetUsart(FALSE);
+       call Usart.clrIntr();
+       call Usart.disableIntr();
      }
!     
      return;
    }
  
! 
!     // i2c enable bit is not set by default
!   async command void Usart.setModeI2C(msp430_i2c_config_t* config) {
!     #ifndef __msp430_have_usart0_with_i2c
        return;
!     #else
!       if (call Usart.getMode() == USART_I2C)
!         return;
  
!       call Usart.disableUart();
!       call Usart.disableSpi();
  
!       atomic {
!         call SIMO.makeInput();
!         call UCLK.makeInput();
!         call SIMO.selectModuleFunc();
!         call UCLK.selectModuleFunc();
  
!         IE1 &= ~(UTXIE0 | URXIE0);  // interrupt disable
! 
!         U0CTL = SWRST;
!         U0CTL |= SYNC | I2C;  // 7-bit addr, I2C-mode, USART as master
!         U0CTL &= ~I2CEN;
! 
!         U0CTL |= MST;
! 
!         I2CTCTL = I2CSSEL_2;        // use 1MHz SMCLK as the I2C reference
! 
!         I2CPSC = 0x00;              // I2C CLK runs at 1MHz/10 = 100kHz
!         I2CSCLH = 0x03;
!         I2CSCLL = 0x03;
! 
!         I2CIE = 0;                 // clear all I2C interrupt enables
!         I2CIFG = 0;                // clear all I2C interrupt flags
!       }
!       return;
!     #endif
    }
  
+ 
    async command bool Usart.isTxIntrPending(){
      if (IFG1 & UTXIFG0){
***************
*** 457,461 ****
    async command bool Usart.isRxIntrPending(){
      if (IFG1 & URXIFG0){
- //      IFG1 &= ~URXIFG0;
        return TRUE;
      }
--- 474,477 ----
***************
*** 463,485 ****
    }
  
!   async command error_t Usart.clrTxIntr(){
      IFG1 &= ~UTXIFG0;
-     return SUCCESS;
    }
  
!   async command error_t Usart.clrRxIntr() {
      IFG1 &= ~URXIFG0;
-     return SUCCESS;
    }
  
!   async command void Usart.disableRxIntr(){
      IE1 &= ~URXIE0;
    }
  
!   async command void Usart.disableTxIntr(){
      IE1 &= ~UTXIE0;
    }
  
!   async command void Usart.enableRxIntr(){
      atomic {
        IFG1 &= ~URXIFG0;
--- 479,507 ----
    }
  
!   async command void Usart.clrTxIntr(){
      IFG1 &= ~UTXIFG0;
    }
  
!   async command void Usart.clrRxIntr() {
      IFG1 &= ~URXIFG0;
    }
  
!   async command void Usart.clrIntr() {
!     IFG1 &= ~(UTXIFG0 | URXIFG0);
!   }
! 
!   async command void Usart.disableRxIntr() {
      IE1 &= ~URXIE0;
    }
  
!   async command void Usart.disableTxIntr() {
      IE1 &= ~UTXIE0;
    }
  
!   async command void Usart.disableIntr() {
!       IE1 &= ~(UTXIE0 | URXIE0);
!   }
! 
!   async command void Usart.enableRxIntr() {
      atomic {
        IFG1 &= ~URXIFG0;
***************
*** 488,492 ****
    }
  
!   async command void Usart.enableTxIntr(){
      atomic {
        IFG1 &= ~UTXIFG0;
--- 510,514 ----
    }
  
!   async command void Usart.enableTxIntr() {
      atomic {
        IFG1 &= ~UTXIFG0;
***************
*** 495,503 ****
    }
  
!   async command void Usart.tx(uint8_t data){
      atomic U0TXBUF = data;
    }
  
!   async command uint8_t Usart.rx(){
      uint8_t value;
      atomic value = U0RXBUF;
--- 517,532 ----
    }
  
!   async command void Usart.enableIntr() {
!     atomic {
!       IFG1 &= ~(UTXIFG0 | URXIFG0);
!       IE1 |= (UTXIE0 | URXIE0);
!     }
!   }
! 
!   async command void Usart.tx(uint8_t data) {
      atomic U0TXBUF = data;
    }
  
!   async command uint8_t Usart.rx() {
      uint8_t value;
      atomic value = U0RXBUF;
***************
*** 505,507 ****
--- 534,537 ----
    }
  
+ 	default async event void I2CInterrupts.fired() {}
  }

Index: HplMsp430Usart1C.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/chips/msp430/usart/HplMsp430Usart1C.nc,v
retrieving revision 1.1.2.7
retrieving revision 1.1.2.8
diff -C2 -d -r1.1.2.7 -r1.1.2.8
*** HplMsp430Usart1C.nc	19 Jun 2006 11:12:24 -0000	1.1.2.7
--- HplMsp430Usart1C.nc	3 Aug 2006 18:10:41 -0000	1.1.2.8
***************
*** 1,3 ****
! /*
   * "Copyright (c) 2000-2005 The Regents of the University  of California.
   * All rights reserved.
--- 1,34 ----
! /**
!  * Copyright (c) 2005-2006 Arched Rock Corporation
!  * 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 Arched Rock Corporation 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
!  * ARCHED ROCK OR ITS 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
!  */
! 
! /**
   * "Copyright (c) 2000-2005 The Regents of the University  of California.
   * All rights reserved.
***************
*** 21,40 ****
   * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
   * UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
-  *
   */
  
  /**
   * @author Joe Polastre
   */
  
! #include "msp430UsartResource.h"
  
  configuration HplMsp430Usart1C {
!   provides interface Init;
    provides interface HplMsp430Usart;
    provides interface HplMsp430UsartInterrupts;
!   provides interface Resource[ uint8_t id ];
!   provides interface ResourceController;
!   provides interface ArbiterInfo;
  }
  
--- 52,73 ----
   * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
   * UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
   */
  
  /**
+  * An HPL abstraction of USART1 on the MSP430.
+  *
+  * @author Jonathan Hui <jhui at archedrock.com>
   * @author Joe Polastre
+  * @version $Revision$ $Date$
   */
  
! #include "msp430usart.h"
  
  configuration HplMsp430Usart1C {
! 
!   provides interface AsyncStdControl;
    provides interface HplMsp430Usart;
    provides interface HplMsp430UsartInterrupts;
! 
  }
  
***************
*** 43,56 ****
    components HplMsp430Usart1P as HplUsartP;
    components HplMsp430GeneralIOC as GIO;
-   components new FcfsArbiterC(MSP430_HPLUSART1_RESOURCE) as Arbiter;
  
    HplMsp430Usart = HplUsartP;
    HplMsp430UsartInterrupts = HplUsartP;
  
-   Init = Arbiter;
-   Resource = Arbiter;
-   ResourceController = Arbiter;
-   ArbiterInfo = Arbiter;
- 
    HplUsartP.SIMO -> GIO.SIMO1;
    HplUsartP.SOMI -> GIO.SOMI1;
--- 76,84 ----
    components HplMsp430Usart1P as HplUsartP;
    components HplMsp430GeneralIOC as GIO;
  
+   AsyncStdControl = HplUsartP;
    HplMsp430Usart = HplUsartP;
    HplMsp430UsartInterrupts = HplUsartP;
  
    HplUsartP.SIMO -> GIO.SIMO1;
    HplUsartP.SOMI -> GIO.SOMI1;

Index: HplMsp430Usart1P.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/chips/msp430/usart/HplMsp430Usart1P.nc,v
retrieving revision 1.1.2.5
retrieving revision 1.1.2.6
diff -C2 -d -r1.1.2.5 -r1.1.2.6
*** HplMsp430Usart1P.nc	19 Jun 2006 11:12:24 -0000	1.1.2.5
--- HplMsp430Usart1P.nc	3 Aug 2006 18:10:41 -0000	1.1.2.6
***************
*** 1,47 ****
! /*
!  * Copyright (c) 2004-2005, Technische Universitat Berlin
   * 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 Universitat 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.
-  *
-  * - Revision -------------------------------------------------------------
-  * $Revision$
-  * $Date$
-  * ========================================================================
   */
  
  /**
!  * Implementation of USART0 lowlevel functionality - stateless.
   * Setting a mode will by default disable USART-Interrupts.
   *
!  * @author Jan Hauer (hauer at tkn.tu-berlin.de)
!  * @author Joe Polastre
   */
  
  module HplMsp430Usart1P {
    provides interface HplMsp430Usart as Usart;
!   provides interface HplMsp430UsartInterrupts as UsartInterrupts;
  
    uses interface HplMsp430GeneralIO as SIMO;
--- 1,78 ----
! /**
!  * Copyright (c) 2005-2006 Arched Rock Corporation
   * 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 Arched Rock Corporation 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
!  * ARCHED ROCK OR ITS 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
!  */
! 
! /**
!  * Copyright (c) 2004-2005, Technische Universitaet Berlin
!  * 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 Universitaet 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.
   */
  
+ #include "msp430usart.h"
  /**
!  * Implementation of USART1 lowlevel functionality - stateless.
   * Setting a mode will by default disable USART-Interrupts.
   *
!  * @author: Jan Hauer <hauer at tkn.tu-berlin.de>
!  * @author: Jonathan Hui <jhui at archedrock.com>
!  * @author: Vlado Handziski <handzisk at tkn.tu-berlin.de>
!  * @author: Joe Polastre
!  * @version $Revision$ $Date$
   */
  
  module HplMsp430Usart1P {
+   provides interface AsyncStdControl;
    provides interface HplMsp430Usart as Usart;
!   provides interface HplMsp430UsartInterrupts as Interrupts;
  
    uses interface HplMsp430GeneralIO as SIMO;
***************
*** 51,54 ****
--- 82,86 ----
    uses interface HplMsp430GeneralIO as UTXD;
  }
+ 
  implementation
  {
***************
*** 57,123 ****
    MSP430REG_NORACE(IFG2);
    MSP430REG_NORACE(U1TCTL);
    MSP430REG_NORACE(U1TXBUF);
!   
!   uint16_t l_br;
!   uint8_t l_mctl;
!   uint8_t l_ssel;
!   
    TOSH_SIGNAL(UART1RX_VECTOR) {
      uint8_t temp = U1RXBUF;
!     signal UsartInterrupts.rxDone(temp);
    }
  
    TOSH_SIGNAL(UART1TX_VECTOR) {
!     signal UsartInterrupts.txDone();
    }
  
!   async command bool Usart.isSPI() {
!     bool _ret = FALSE;
!     atomic{
!       if (ME2 & USPIE1)
! 	_ret = TRUE;
      }
-     return _ret;
    }
!   
!   async command bool Usart.isUART() {
!     bool _ret = FALSE;
      atomic {
!       if ((ME2 & UTXE1) && (ME2 & URXE1))
! 	_ret = TRUE;
      }
-     return _ret;
    }
!   
!   async command bool Usart.isUARTtx() {
!     bool _ret = FALSE;
      atomic {
!       if (ME2 & UTXE1)
! 	_ret = TRUE;
      }
-     return _ret;
    }
!   
!   async command bool Usart.isUARTrx() {
!     bool _ret = FALSE;
      atomic {
!       if (ME2 & URXE1)
! 	_ret = TRUE;
      }
-     return _ret;
    }
!   
    async command bool Usart.isI2C() {
!     return FALSE;
    }
!   
    async command msp430_usartmode_t Usart.getMode() {
!     if (call Usart.isUART())
        return USART_UART;
!     else if (call Usart.isUARTrx())
        return USART_UART_RX;
!     else if (call Usart.isUARTtx())
        return USART_UART_TX;
!     else if (call Usart.isSPI())
        return USART_SPI;
      else if (call Usart.isI2C())
--- 89,204 ----
    MSP430REG_NORACE(IFG2);
    MSP430REG_NORACE(U1TCTL);
+   MSP430REG_NORACE(U1RCTL);
    MSP430REG_NORACE(U1TXBUF);
! 
! 
! 
    TOSH_SIGNAL(UART1RX_VECTOR) {
      uint8_t temp = U1RXBUF;
!     signal Interrupts.rxDone(temp);
    }
  
    TOSH_SIGNAL(UART1TX_VECTOR) {
!     signal Interrupts.txDone();
    }
  
!   async command error_t AsyncStdControl.start() {
!     return SUCCESS;
!   }
! 
!   async command error_t AsyncStdControl.stop() {
!     call Usart.disableSpi();
!     call Usart.disableI2C();
!     call Usart.disableUart();
!     return SUCCESS;
!   }
! 
! 
!   async command void Usart.setUctl(msp430_uctl_t control) {
!     U1CTL=uctl2int(control);
!   }
! 
!   async command msp430_uctl_t Usart.getUctl() {
!     return int2uctl(U0CTL);
!   }
! 
!   async command void Usart.setUtctl(msp430_utctl_t control) {
!     U1TCTL=utctl2int(control);
!   }
! 
!   async command msp430_utctl_t Usart.getUtctl() {
!     return int2utctl(U1TCTL);
!   }
! 
!   async command void Usart.setUrctl(msp430_urctl_t control) {
!     U1RCTL=urctl2int(control);
!   }
! 
!   async command msp430_urctl_t Usart.getUrctl() {
!     return int2urctl(U1RCTL);
!   }
! 
!   async command void Usart.setUbr(uint16_t control) {
!     atomic {
!       U1BR0 = control & 0x00FF;
!       U1BR1 = (control >> 8) & 0x00FF;
      }
    }
! 
!   async command uint16_t Usart.getUbr() {
!     return (U1BR1 << 8) + U1BR0;
!   }
! 
!   async command void Usart.setUmctl(uint8_t control) {
!     U1MCTL=control;
!   }
! 
!   async command uint8_t Usart.getUmctl() {
!     return U1MCTL;
!   }
! 
!   async command void Usart.resetUsart(bool reset) {
!     if (reset)
!       SET_FLAG(U1CTL, SWRST);
!     else
!       CLR_FLAG(U1CTL, SWRST);
!   }
! 
!   async command bool Usart.isSpi() {
      atomic {
!       return (U1CTL & SYNC) && (ME2 & USPIE1);
      }
    }
! 
!   async command bool Usart.isUart() {
      atomic {
!       return !(U1CTL & SYNC) && ((ME2 & UTXE1) && (ME2 & URXE1));
      }
    }
! 
!   async command bool Usart.isUartTx() {
      atomic {
!       return !(U1CTL & SYNC) && (ME2 & UTXE1);
      }
    }
! 
!   async command bool Usart.isUartRx() {
!     atomic {
!       return !(U1CTL & SYNC) && (ME2 & URXE1);
!     }
!   }
! 
    async command bool Usart.isI2C() {
!       return FALSE;
    }
! 
    async command msp430_usartmode_t Usart.getMode() {
!     if (call Usart.isUart())
        return USART_UART;
!     else if (call Usart.isUartRx())
        return USART_UART_RX;
!     else if (call Usart.isUartTx())
        return USART_UART_TX;
!     else if (call Usart.isSpi())
        return USART_SPI;
      else if (call Usart.isI2C())
***************
*** 126,394 ****
        return USART_NONE;
    }
!   
!   /**
!    * Sets the USART mode to one of the options from msp430_usartmode_t
!    * defined in MSP430Usart.h
!    */
!   async command void Usart.setMode(msp430_usartmode_t _mode) {
!     switch (_mode) {
!     case USART_UART:
!       call Usart.setModeUART();
!       break;
!     case USART_UART_RX:
!       call Usart.setModeUART_RX();
!       break;
!     case USART_UART_TX:
!       call Usart.setModeUART_TX();
!       break;
!     case USART_SPI:
!       call Usart.setModeSPI();
!       break;
!     default:
!       break;
      }
-   }
-   
-   async command void Usart.enableUART() {
- //    TOSH_SEL_UTXD1_MODFUNC();
- //    TOSH_SEL_URXD1_MODFUNC();
      ME2 |= (UTXE1 | URXE1);   // USART1 UART module enable
    }
!   
!   async command void Usart.disableUART() {
!     ME2 &= ~(UTXE1 | URXE1);   // USART0 UART module enable
!     call UTXD.selectIOFunc();
!     call URXD.selectIOFunc();
    }
!   
!   async command void Usart.enableUARTTx() {
!     ME2 |= UTXE1;   // USART0 UART Tx module enable
    }
!   
!   async command void Usart.disableUARTTx() {
!     ME2 &= ~UTXE1;   // USART0 UART Tx module enable
      call UTXD.selectIOFunc();
    }
!   
!   async command void Usart.enableUARTRx() {
!     ME2 |= URXE1;   // USART0 UART Rx module enable
    }
!   
!   async command void Usart.disableUARTRx() {
!     ME2 &= ~URXE1;  // USART0 UART Rx module disable
      call URXD.selectIOFunc();
-   }
  
-   async command void Usart.enableSPI() {
-     ME2 |= USPIE1;   // USART0 SPI module enable
    }
-   
-   async command void Usart.disableSPI() {
-     ME2 &= ~USPIE1;   // USART0 SPI module disable
-     call SIMO.selectIOFunc();
-     call SOMI.selectIOFunc();
-     call UCLK.selectIOFunc();
-   }
-   
-   async command void Usart.enableI2C() { }
-   
-   async command void Usart.disableI2C() { }
  
!   async command void Usart.setModeSPI() {
!     // check if we are already in SPI mode
!     if (call Usart.getMode() == USART_SPI) 
!       return;
!     
!     call Usart.disableUART();
!     call Usart.disableI2C();
!     
      atomic {
        call SIMO.selectModuleFunc();
        call SOMI.selectModuleFunc();
        call UCLK.selectModuleFunc();
  
!       IE2 &= ~(UTXIE1 | URXIE1);  // interrupt disable    
  
!       U1CTL = SWRST;
!       U1CTL |= CHAR | SYNC | MM;  // 8-bit char, SPI-mode, USART as master
!       U1CTL &= ~(0x20); 
  
!       U1TCTL = STC ;     // 3-pin
!       U1TCTL |= CKPH;    // half-cycle delayed UCLK
  
-       if (l_ssel & 0x80) {
-         U1TCTL &= ~(SSEL_0 | SSEL_1 | SSEL_2 | SSEL_3);
-         U1TCTL |= (l_ssel & 0x7F); 
-       }
-       else {
-         U1TCTL &= ~(SSEL_0 | SSEL_1 | SSEL_2 | SSEL_3);
-         U1TCTL |= SSEL_SMCLK; // use SMCLK, assuming 1MHz
-       }
  
!       if (l_br != 0) {
!         U1BR0 = l_br & 0x0FF;
!         U1BR1 = (l_br >> 8) & 0x0FF;
!       }
!       else {
!         U1BR0 = 0x02;   // as fast as possible
!         U1BR1 = 0x00;
!       }
!       U1MCTL = 0;
  
!       ME2 &= ~(UTXE1 | URXE1); //USART UART module disable
!       ME2 |= USPIE1;   // USART SPI module enable
!       U1CTL &= ~SWRST;  
  
!       IFG2 &= ~(UTXIFG1 | URXIFG1);
!       IE2 &= ~(UTXIE1 | URXIE1);  // interrupt disabled    
      }
      return;
    }
-   
-   void setUARTModeCommon() {
-     atomic {
-       U1CTL = SWRST;  
-       U1CTL |= CHAR;  // 8-bit char, UART-mode
  
-       U1RCTL &= ~URXEIE;  // even erroneous characters trigger interrupts
  
!       
!       U1CTL = SWRST;
!       U1CTL |= CHAR;  // 8-bit char, UART-mode
  
!       if (l_ssel & 0x80) {
!         U1TCTL &= ~(SSEL_0 | SSEL_1 | SSEL_2 | SSEL_3);
!         U1TCTL |= (l_ssel & 0x7F); 
!       }
!       else {
!         U1TCTL &= ~(SSEL_0 | SSEL_1 | SSEL_2 | SSEL_3);
!         U1TCTL |= SSEL_ACLK; // use ACLK, assuming 32khz
!       }
  
!       if ((l_mctl != 0) || (l_br != 0)) {
!         U1BR0 = l_br & 0x0FF;
!         U1BR1 = (l_br >> 8) & 0x0FF;
!         U1MCTL = l_mctl;
!       }
!       else {
!         U1BR0 = 0x03;   // 9600 baud
!         U1BR1 = 0x00;
!         U1MCTL = 0x4A;
!       }
  
!       ME2 &= ~USPIE1;   // USART0 SPI module disable
!       ME2 |= (UTXE1 | URXE1); //USART0 UART module enable;
!       
!       U1CTL &= ~SWRST;
  
!       IFG2 &= ~(UTXIFG1 | URXIFG1);
!       IE2 &= ~(UTXIE1 | URXIE1);  // interrupt disabled
!     }
!     return;
    }
-   
-   async command void Usart.setModeUART_TX() {
-     // check if we are already in UART mode
-     if (call Usart.getMode() == USART_UART_TX) 
-       return;
  
!     call Usart.disableSPI();
      call Usart.disableI2C();
!     call Usart.disableUART();
  
!     atomic {   
        call UTXD.selectModuleFunc();
        call URXD.selectIOFunc();
      }
-     setUARTModeCommon();  
      return;
    }
-   
-   async command void Usart.setModeUART_RX() {
-     // check if we are already in UART mode
-     if (call Usart.getMode() == USART_UART_RX) 
-       return;
  
!     call Usart.disableSPI();
!     call Usart.disableI2C();
!     call Usart.disableUART();
  
      atomic {
        call UTXD.selectIOFunc();
        call URXD.selectModuleFunc();
      }
-     setUARTModeCommon(); 
      return;
    }
  
!   async command void Usart.setModeUART() {
!     // check if we are already in UART mode
!     if (call Usart.getMode() == USART_UART) 
!       return;
  
!     call Usart.disableSPI();
      call Usart.disableI2C();
!     call Usart.disableUART();
  
      atomic {
        call UTXD.selectModuleFunc();
        call URXD.selectModuleFunc();
      }
-     setUARTModeCommon();
      return;
    }
  
-   // i2c enable bit is not set by default
-   async command void Usart.setModeI2C() {
-     // check if we are already in I2C mode
-     if (call Usart.getMode() == USART_I2C) 
-       return;
- 
-     call Usart.disableUART();
-     call Usart.disableSPI();
  
!     atomic {
!       call SIMO.makeInput();
!       call UCLK.makeInput();
!       call SIMO.selectModuleFunc();
!       call UCLK.selectModuleFunc();
! 
!       IE2 &= ~(UTXIE1 | URXIE1);  // interrupt disable    
! 
!       U1CTL = SWRST;
!       U1CTL |= SYNC | I2C;  // 7-bit addr, I2C-mode, USART as master
!       U1CTL &= ~I2CEN;
! 
!       U1CTL |= MST;
! 
!       I2CTCTL = I2CSSEL_2;        // use 1MHz SMCLK as the I2C reference
! 
!       I2CPSC = 0x00;              // I2C CLK runs at 1MHz/10 = 100kHz
!       I2CSCLH = 0x03;
!       I2CSCLL = 0x03;
!       
!       I2CIE = 0;                 // clear all I2C interrupt enables
!       I2CIFG = 0;                // clear all I2C interrupt flags
!     }
      return;
    }
!  
!   async command void Usart.setClockSource(uint8_t source) {
!     atomic {
!       l_ssel = source | 0x80;
!       U1TCTL &= ~(SSEL_0 | SSEL_1 | SSEL_2 | SSEL_3);
!       U1TCTL |= (l_ssel & 0x7F); 
!     }
!   }
!   
!   async command void Usart.setClockRate(uint16_t baudrate, uint8_t mctl) {
!     atomic {
!       l_br = baudrate;
!       l_mctl = mctl;
!       U1BR0 = baudrate & 0x0FF;
!       U1BR1 = (baudrate >> 8) & 0x0FF;
!       U1MCTL = mctl;
!     }
!   }
  
    async command bool Usart.isTxIntrPending(){
--- 207,403 ----
        return USART_NONE;
    }
! 
!   async command void Usart.enableUart() {
!     atomic{
!       call UTXD.selectModuleFunc();
!       call URXD.selectModuleFunc();
      }
      ME2 |= (UTXE1 | URXE1);   // USART1 UART module enable
    }
! 
!   async command void Usart.disableUart() {
!     ME2 &= ~(UTXE1 | URXE1);   // USART1 UART module enable
!     atomic {
!       call UTXD.selectIOFunc();
!       call URXD.selectIOFunc();
!     }
! 
    }
! 
!   async command void Usart.enableUartTx() {
!     call UTXD.selectModuleFunc();
!     ME2 |= UTXE1;   // USART1 UART Tx module enable
    }
! 
!   async command void Usart.disableUartTx() {
!     ME2 &= ~UTXE1;   // USART1 UART Tx module enable
      call UTXD.selectIOFunc();
+ 
    }
! 
!   async command void Usart.enableUartRx() {
!     call URXD.selectModuleFunc();
!     ME2 |= URXE1;   // USART1 UART Rx module enable
    }
! 
!   async command void Usart.disableUartRx() {
!     ME2 &= ~URXE1;  // USART1 UART Rx module disable
      call URXD.selectIOFunc();
  
    }
  
!   async command void Usart.enableSpi() {
      atomic {
        call SIMO.selectModuleFunc();
        call SOMI.selectModuleFunc();
        call UCLK.selectModuleFunc();
+     }
+     ME2 |= USPIE1;   // USART1 SPI module enable
+   }
  
!   async command void Usart.disableSpi() {
!     ME2 &= ~USPIE1;   // USART1 SPI module disable
!     atomic {
!       call SIMO.selectIOFunc();
!       call SOMI.selectIOFunc();
!       call UCLK.selectIOFunc();
!     }
!   }
  
!   async command void Usart.enableI2C() {
!     return;
!   }
  
!   async command void Usart.disableI2C() {
!     return;
!  }
  
  
!   void configSpi(msp430_spi_config_t* config) {
!     msp430_uctl_t uctl = call Usart.getUctl();
!     msp430_utctl_t utctl = call Usart.getUtctl();
  
!     uctl.clen = config->clen;
!     uctl.listen = config->listen;
!     uctl.mm = config->mm;
!     uctl.sync = 1;
  
!     utctl.ckph = config->ckph;
!     utctl.ckpl = config->ckpl;
!     utctl.ssel = config->ssel;
!     utctl.stc = config->stc;
! 
!     call Usart.setUctl(uctl);
!     call Usart.setUtctl(utctl);
!     call Usart.setUbr(config->ubr);
!     call Usart.setUmctl(0x00);
!   }
! 
! 
!   async command void Usart.setModeSpi(msp430_spi_config_t* config) {
!     call Usart.disableUart();
!     call Usart.disableI2C();
!     atomic {
!       call Usart.resetUsart(TRUE);
!       configSpi(config);
!       call Usart.enableSpi();
!       call Usart.resetUsart(FALSE);
!       call Usart.clrIntr();
!       call Usart.disableIntr();
      }
      return;
    }
  
  
!   void configUart(msp430_uart_config_t* config) {
!     msp430_uctl_t uctl = call Usart.getUctl();
!     msp430_utctl_t utctl = call Usart.getUtctl();
!     msp430_urctl_t urctl = call Usart.getUrctl();
  
!     uctl.pena = config->pena;
!     uctl.pev = config->pev;
!     uctl.spb = config->spb;
!     uctl.clen = config->clen;
!     uctl.listen = config->listen;
!     uctl.sync = 0;
!     uctl.mm = config->mm;
  
!     utctl.ckpl = config->ckpl;
!     utctl.ssel = config->ssel;
!     utctl.urxse = config->urxse;
  
!     urctl.urxeie = config->urxeie;
!     urctl.urxwie = config->urxwie;
  
!     call Usart.setUctl(uctl);
!     call Usart.setUtctl(utctl);
!     call Usart.setUrctl(urctl);
!     call Usart.setUbr(config->ubr);
!     call Usart.setUmctl(config->umctl);
    }
  
!   async command void Usart.setModeUartTx(msp430_uart_config_t* config) {
! 
!     call Usart.disableSpi();
      call Usart.disableI2C();
!     call Usart.disableUart();
  
!     atomic {
        call UTXD.selectModuleFunc();
        call URXD.selectIOFunc();
+       call Usart.resetUsart(TRUE);
+       configUart(config);
+       call Usart.enableUartTx();
+       call Usart.resetUsart(FALSE);
+       call Usart.clrIntr();
+       call Usart.disableIntr();
      }
      return;
    }
  
!   async command void Usart.setModeUartRx(msp430_uart_config_t* config) {
  
+     call Usart.disableSpi();
+     call Usart.disableI2C();
+     call Usart.disableUart();
+     
      atomic {
        call UTXD.selectIOFunc();
        call URXD.selectModuleFunc();
+       call Usart.resetUsart(TRUE);
+       configUart(config);
+       call Usart.enableUartRx();
+       call Usart.resetUsart(FALSE);
+       call Usart.clrIntr();
+       call Usart.disableIntr();
      }
      return;
    }
  
!   async command void Usart.setModeUart(msp430_uart_config_t* config) {
  
!     call Usart.disableSpi();
      call Usart.disableI2C();
!     call Usart.disableUart();
  
      atomic {
        call UTXD.selectModuleFunc();
        call URXD.selectModuleFunc();
+       call Usart.resetUsart(TRUE);
+       configUart(config);
+       call Usart.enableUart();
+       call Usart.resetUsart(FALSE);
+       call Usart.clrIntr();
+       call Usart.disableIntr();
      }
      return;
    }
  
  
!     // i2c enable bit is not set by default
!   async command void Usart.setModeI2C(msp430_i2c_config_t* config) {
      return;
    }
! 
  
    async command bool Usart.isTxIntrPending(){
***************
*** 406,444 ****
      return FALSE;
    }
!   
    async command bool Usart.isRxIntrPending(){
      if (IFG2 & URXIFG1){
-       IFG2 &= ~URXIFG1;
        return TRUE;
      }
      return FALSE;
    }
!   
!   async command error_t Usart.clrTxIntr(){
!     IFG1 &= ~UTXIFG0;
!     return SUCCESS;
    }
  
!   async command error_t Usart.clrRxIntr() {
!     IFG1 &= ~URXIFG0;
!     return SUCCESS;
    }
!   
!   async command void Usart.disableRxIntr(){
!     IE2 &= ~URXIE1;    
    }
!   
!   async command void Usart.disableTxIntr(){
!     IE2 &= ~UTXIE1;  
    }
!   
!   async command void Usart.enableRxIntr(){
      atomic {
        IFG2 &= ~URXIFG1;
!       IE2 |= URXIE1;  
      }
    }
  
!   async command void Usart.enableTxIntr(){
      atomic {
        IFG2 &= ~UTXIFG1;
--- 415,458 ----
      return FALSE;
    }
! 
    async command bool Usart.isRxIntrPending(){
      if (IFG2 & URXIFG1){
        return TRUE;
      }
      return FALSE;
    }
! 
!   async command void Usart.clrTxIntr(){
!     IFG2 &= ~UTXIFG1;
    }
  
!   async command void Usart.clrRxIntr() {
!     IFG2 &= ~URXIFG1;
    }
! 
!   async command void Usart.clrIntr() {
!     IFG2 &= ~(UTXIFG1 | URXIFG1);
    }
! 
!   async command void Usart.disableRxIntr() {
!     IE2 &= ~URXIE1;
    }
! 
!   async command void Usart.disableTxIntr() {
!     IE2 &= ~UTXIE1;
!   }
! 
!   async command void Usart.disableIntr() {
!       IE2 &= ~(UTXIE1 | URXIE1);
!   }
! 
!   async command void Usart.enableRxIntr() {
      atomic {
        IFG2 &= ~URXIFG1;
!       IE2 |= URXIE1;
      }
    }
  
!   async command void Usart.enableTxIntr() {
      atomic {
        IFG2 &= ~UTXIFG1;
***************
*** 446,455 ****
      }
    }
!   
!   async command void Usart.tx(uint8_t data){
      atomic U1TXBUF = data;
    }
!   
!   async command uint8_t Usart.rx(){
      uint8_t value;
      atomic value = U1RXBUF;
--- 460,476 ----
      }
    }
! 
!   async command void Usart.enableIntr() {
!     atomic {
!       IFG2 &= ~(UTXIFG1 | URXIFG1);
!       IE2 |= (UTXIE1 | URXIE1);
!     }
!   }
! 
!   async command void Usart.tx(uint8_t data) {
      atomic U1TXBUF = data;
    }
! 
!   async command uint8_t Usart.rx() {
      uint8_t value;
      atomic value = U1RXBUF;

Index: HplMsp430UsartInterrupts.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/chips/msp430/usart/HplMsp430UsartInterrupts.nc,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -C2 -d -r1.1.2.2 -r1.1.2.3
*** HplMsp430UsartInterrupts.nc	1 Aug 2006 16:36:24 -0000	1.1.2.2
--- HplMsp430UsartInterrupts.nc	3 Aug 2006 18:10:41 -0000	1.1.2.3
***************
*** 53,56 ****
     */
    async event void rxDone(uint8_t data);
!   
  }
--- 53,57 ----
     */
    async event void rxDone(uint8_t data);
! 
  }
+ 

Index: HplMsp430Usart.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/chips/msp430/usart/HplMsp430Usart.nc,v
retrieving revision 1.1.2.4
retrieving revision 1.1.2.5
diff -C2 -d -r1.1.2.4 -r1.1.2.5
*** HplMsp430Usart.nc	15 Mar 2006 16:40:29 -0000	1.1.2.4
--- HplMsp430Usart.nc	3 Aug 2006 18:10:41 -0000	1.1.2.5
***************
*** 1,33 ****
  /*
!  * Copyright (c) 2004-2005, Technische Universität Berlin
   * 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.
   */
  
  /**
!  * Byte-level interface to control a USART. 
   * <p>The USART can be switched to SPI- or UART-mode. The interface follows
   * the convention of being stateless, thus a higher layer has to maintain
--- 1,33 ----
  /*
!  * Copyright (c) 2004-2005, Technische Universitaet Berlin
   * 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 Universitaet 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.
   */
  
  /**
!  * Byte-level interface to control a USART.
   * <p>The USART can be switched to SPI- or UART-mode. The interface follows
   * the convention of being stateless, thus a higher layer has to maintain
***************
*** 35,117 ****
   * data in the mode (SPI or UART) the USART has been set to before.
   *
   * @author Jan Hauer (hauer at tkn.tu-berlin.de)
   * @author Joe Polastre
   * @version $Revision$ $Date$
   */
!  
  #include "msp430usart.h"
  
  interface HplMsp430Usart {
  
!   /**
!    * Returns an enum value corresponding to the current mode of the
!    * USART module.  Allows one to read the module mode, change it, and
!    * then reset it back to its original state after use.
     */
!   async command msp430_usartmode_t getMode();
  
    /**
!    * Sets the USART mode to one of the options from msp430_usartmode_t
!    * defined in MSP430USART.h
!    *
!    * @return SUCCESS if the mode was changed
     */
!   async command void setMode(msp430_usartmode_t mode);
  
    /**
!    * Returns TRUE if the USART has UART TX mode enabled
     */
!   async command bool isUARTtx();
  
    /**
!    * Returns TRUE if the USART has UART RX mode enabled
     */
!   async command bool isUARTrx();
  
    /**
!    * Returns TRUE if the USART is set to UART mode (both RX and TX)
     */
!   async command bool isUART();
  
   /**
!    * Enables both the Rx and the Tx UART modules.
     */
!   async command void enableUART();
!   
   /**
!    * Disables both the Rx and the Tx UART modules.
     */
!   async command void disableUART();
!  
   /**
!    * Enables the UART TX functionality of the USART module.
     */
!   async command void enableUARTTx();
  
   /**
!    * Disables the UART TX module.
     */
!   async command void disableUARTTx();
  
   /**
!    * Enables the UART RX functionality of the USART module.
     */
!   async command void enableUARTRx();
  
   /**
!    * Disables the UART RX module.
     */
!   async command void disableUARTRx();
!   
   /**
!    * Enables the USART when in SPI mode.
     */
!   async command void enableSPI();
!   
   /**
!    * Disables the USART when in SPI mode.
     */
!   async command void disableSPI();
!   
    /**
     * Enables the I2C module (register flags)
--- 35,178 ----
   * data in the mode (SPI or UART) the USART has been set to before.
   *
+  * @author Vlado Handziski (handzisk at tkn.tu-berlin.de)
   * @author Jan Hauer (hauer at tkn.tu-berlin.de)
   * @author Joe Polastre
   * @version $Revision$ $Date$
   */
! 
  #include "msp430usart.h"
  
  interface HplMsp430Usart {
  
!    /**
!     * Sets the UxCTL Control Register
!     */
!    async command void setUctl(msp430_uctl_t control);
! 
!    /**
!     * Reads the UxCTL Control Register
!     */
!    async command msp430_uctl_t getUctl();
! 
!    /**
!     * Sets the UxTCTL Transmit Control Register
!     */
!    async command void setUtctl(msp430_utctl_t control);
! 
!    /**
!     * Reads the UxTCTL Transmit Control Register
!     */
!    async command msp430_utctl_t getUtctl();
! 
!    /**
!     * Sets the UxRCTL Receive Control Register
!     */
!    async command void setUrctl(msp430_urctl_t control);
! 
!    /**
!     * Reads the UxRCTL Receive Control Register
!     */
!    async command msp430_urctl_t getUrctl();
! 
!    /**
!     * Sets the UxBR0 and UxBR1 Baud Rate Control Registers
!     */
!    async command void setUbr(uint16_t ubr);
! 
!    /**
!     * Reads the UxBR0 and UxBR1 Baud Rate Control Registers
!     */
!    async command uint16_t getUbr();
! 
!    /**
!     * Sets the UxMCTL Modulation Control Register
!     */
!    async command void setUmctl(uint8_t umctl);
! 
!    /**
!     * Reads the UxMCTL Modulation Control Register
!     */
!    async command uint8_t getUmctl();
! 
!    /*
!    async command void setI2Cpsc(uint8_t control);
!    async command uint8_t getI2Cpsc();
! 
!    async command void setI2Csclh(uint8_t control);
!    async command uint8_t getI2Csclh();
! 
!    async command void setI2Cscll(uint8_t control);
!    async command uint8_t getI2Cscll();
! 
!    async command void setI2Coa(msp430_i2c_oa_t address);
!    async command msp430_i2c_oa_t getI2Coa();
! 
!    async command void setI2Ctctl(msp430_i2ctctl_t control);
!    async command msp430_usart_i2ctctl_t getI2Ctctl();
     */
! 
!    async command void resetUsart(bool reset);
  
    /**
!    * Returns an enum value corresponding to the current mode of the
!    * USART module.
     */
!   async command msp430_usartmode_t getMode();
  
    /**
!    * Returns TRUE if the USART has Uart TX mode enabled
     */
!   async command bool isUartTx();
  
    /**
!    * Returns TRUE if the USART has Uart RX mode enabled
     */
!   async command bool isUartRx();
  
    /**
!    * Returns TRUE if the USART is set to Uart mode (both RX and TX)
     */
!   async command bool isUart();
  
   /**
!    * Enables both the Rx and the Tx Uart modules.
     */
!   async command void enableUart();
! 
   /**
!    * Disables both the Rx and the Tx Uart modules.
     */
!   async command void disableUart();
! 
   /**
!    * Enables the Uart TX functionality of the USART module.
     */
!   async command void enableUartTx();
  
   /**
!    * Disables the Uart TX module.
     */
!   async command void disableUartTx();
  
   /**
!    * Enables the Uart RX functionality of the USART module.
     */
!   async command void enableUartRx();
  
   /**
!    * Disables the Uart RX module.
     */
!   async command void disableUartRx();
! 
   /**
!    * Enables the USART when in Spi mode.
     */
!   async command void enableSpi();
! 
   /**
!    * Disables the USART when in Spi mode.
     */
!   async command void disableSpi();
! 
    /**
     * Enables the I2C module (register flags)
***************
*** 125,154 ****
  
    /**
!    * Returns TRUE if the USART is set to SPI mode
     */
!   async command bool isSPI();
  
   /**
!    * Switches USART to SPI mode.
     */
!   async command void setModeSPI();
! 	
   /**
!    * Switches USART to UART TX mode (RX pins disabled).
     * Interrupts disabled by default.
!    */	
!   async command void setModeUART_TX();
! 	
   /**
!    * Switches USART to UART RX mode (TX pins disabled)..
     * Interrupts disabled by default.
!    */	
!   async command void setModeUART_RX();
  
   /**
!    * Switches USART to UART mode (RX and TX enabled)
     * Interrupts disabled by default.
!    */	
!   async command void setModeUART();
  
    /**
--- 186,215 ----
  
    /**
!    * Returns TRUE if the USART is set to Spi mode
     */
!   async command bool isSpi();
  
   /**
!    * Switches USART to Spi mode.
     */
!   async command void setModeSpi(msp430_spi_config_t* config);
! 
   /**
!    * Switches USART to Uart TX mode (RX pins disabled).
     * Interrupts disabled by default.
!    */
!   async command void setModeUartTx(msp430_uart_config_t* config);
! 
   /**
!    * Switches USART to Uart RX mode (TX pins disabled)..
     * Interrupts disabled by default.
!    */
!   async command void setModeUartRx(msp430_uart_config_t* config);
  
   /**
!    * Switches USART to Uart mode (RX and TX enabled)
     * Interrupts disabled by default.
!    */
!   async command void setModeUart(msp430_uart_config_t* config);
  
    /**
***************
*** 162,177 ****
     * I2C. Interrupts disabled by default.
     */
!   async command void setModeI2C();
!  
!   async command void setClockSource(uint8_t source);
! 
!   async command void setClockRate(uint16_t baudrate, uint8_t mctl);
  
    /* Dis/enabling of UTXIFG / URXIFG */
    async command void disableRxIntr();
    async command void disableTxIntr();
    async command void enableRxIntr();
    async command void enableTxIntr();
!  
    /**
     * TRUE if TX interrupt pending, flag must be cleared explicitly
--- 223,236 ----
     * I2C. Interrupts disabled by default.
     */
!   async command void setModeI2C(msp430_i2c_config_t* config);
  
    /* Dis/enabling of UTXIFG / URXIFG */
    async command void disableRxIntr();
    async command void disableTxIntr();
+   async command void disableIntr();
    async command void enableRxIntr();
    async command void enableTxIntr();
!   async command void enableIntr();
! 
    /**
     * TRUE if TX interrupt pending, flag must be cleared explicitly
***************
*** 187,199 ****
     * Clears RX interrupt pending flag
    */
!   async command error_t clrRxIntr();
  
    /**
     * Clears TX interrupt pending flag
     */
!   async command error_t clrTxIntr();
  
  
!   /** 
     * SUCCESS if the TX buffer is empty and all of the bits have been
     * shifted out
--- 246,262 ----
     * Clears RX interrupt pending flag
    */
!   async command void clrRxIntr();
  
    /**
     * Clears TX interrupt pending flag
     */
!   async command void clrTxIntr();
  
+   /**
+    * Clears both TX and RX interrupt pending flags
+    */
+   async command void clrIntr();
  
!   /**
     * SUCCESS if the TX buffer is empty and all of the bits have been
     * shifted out
***************
*** 205,209 ****
     * <code>txDone</done> is generated. Only then a new byte may be
     * transmitted, otherwise the previous byte will be overwritten.
!    * The mode of transmission (UART or SPI) depends on the current
     * state of the USART, which must be managed by a higher layer.
     *
--- 268,272 ----
     * <code>txDone</done> is generated. Only then a new byte may be
     * transmitted, otherwise the previous byte will be overwritten.
!    * The mode of transmission (Uart or Spi) depends on the current
     * state of the USART, which must be managed by a higher layer.
     *

Index: Msp430I2C0P.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/chips/msp430/usart/Attic/Msp430I2C0P.nc,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -C2 -d -r1.1.2.1 -r1.1.2.2
*** Msp430I2C0P.nc	1 Aug 2006 16:36:24 -0000	1.1.2.1
--- Msp430I2C0P.nc	3 Aug 2006 18:10:41 -0000	1.1.2.2
***************
*** 38,44 ****
--- 38,46 ----
    
    provides interface Resource[ uint8_t id ];
+ 	provides interface ResourceConfigure[uint8_t id ];
    provides interface I2CPacket<TI2CBasicAddr> as I2CBasicAddr;
    
    uses interface Resource as UsartResource[ uint8_t id ];
+ 	uses interface Msp430I2CConfigure[ uint8_t id ];
    uses interface HplMsp430I2CInterrupts as I2CInterrupts;
    
***************
*** 49,52 ****
--- 51,56 ----
    components Msp430I2CP as I2CP;
    Resource = I2CP.Resource;
+ 	ResourceConfigure = I2CP.ResourceConfigure;
+ 	Msp430SpiConfigure = I2CP.Msp430SpiConfigure;
    I2CBasicAddr = I2CP.I2CBasicAddr;
    UsartResource = I2CP.UsartResource;

Index: Msp430I2CC.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/chips/msp430/usart/Attic/Msp430I2CC.nc,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -C2 -d -r1.1.2.1 -r1.1.2.2
*** Msp430I2CC.nc	1 Aug 2006 16:36:24 -0000	1.1.2.1
--- Msp430I2CC.nc	3 Aug 2006 18:10:41 -0000	1.1.2.2
***************
*** 36,40 ****
  
  #include <I2C.h>
! #include "msp430UsartResource.h"
  
  generic configuration Msp430I2CC() {
--- 36,40 ----
  
  #include <I2C.h>
! #include "msp430usart.h"
  
  generic configuration Msp430I2CC() {
***************
*** 43,46 ****
--- 43,47 ----
    provides interface I2CPacket<TI2CBasicAddr> as I2CBasicAddr;
    
+ 	uses interface Msp430I2CConfigure;
  }
  
***************
*** 54,59 ****
--- 55,62 ----
    Resource = I2CP.Resource[ CLIENT_ID ];
    I2CBasicAddr = I2CP.I2CBasicAddr;
+ 	Msp430I2CConfigure = I2CP.Msp430I2CConfigure[ CLIENT_ID ];
    
    components new Msp430Usart0C() as UsartC;
+ 	I2CP.ResourceConfigure[ CLIENT_ID ] <- UsartC.ResourceConfigure;
    I2CP.UsartResource[ CLIENT_ID ] -> UsartC.Resource;
    I2CP.I2CInterrupts -> UsartC.HplMsp430I2CInterrupts;

Index: Msp430I2CP.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/chips/msp430/usart/Attic/Msp430I2CP.nc,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -C2 -d -r1.1.2.1 -r1.1.2.2
*** Msp430I2CP.nc	1 Aug 2006 16:36:24 -0000	1.1.2.1
--- Msp430I2CP.nc	3 Aug 2006 18:10:41 -0000	1.1.2.2
***************
*** 40,46 ****
--- 40,48 ----
    
    provides interface Resource[ uint8_t id ];
+ 	provides interface ResourceConfigure[ uint8_t id ];
    provides interface I2CPacket<TI2CBasicAddr> as I2CBasicAddr;
    
    uses interface Resource as UsartResource[ uint8_t id ];
+ 	uses interface Msp430I2CConfigure[ uint8_t id ];
    uses interface HplMsp430Usart as Usart;
    uses interface HplMsp430I2CInterrupts as I2CInterrupts;
***************
*** 90,93 ****
--- 92,102 ----
    }
    
+ 	async command void ResourceConfigure.configure[ uint8_t id ]() {
+ 		call Usart.setModeI2C(call Msp430I2CConfigure.getConfig[id]());
+ 	}
+ 
+ 	async command void ResourceConfigure.unconfigure[ uint8_t id ]() {
+ 	}
+ 	
    event void UsartResource.granted[ uint8_t id ]() {
      call Usart.setModeI2C();
***************
*** 97,102 ****
    default async command error_t UsartResource.request[ uint8_t id ]() { return FAIL; }
    default async command error_t UsartResource.immediateRequest[ uint8_t id ]() { return FAIL; }
!   default async command void UsartResource.release[ uint8_t id ]() {}
    default event void Resource.granted[ uint8_t id ]() {}
    
    async command error_t I2CBasicAddr.read( i2c_flags_t flags,
--- 106,114 ----
    default async command error_t UsartResource.request[ uint8_t id ]() { return FAIL; }
    default async command error_t UsartResource.immediateRequest[ uint8_t id ]() { return FAIL; }
! 	default async command void UsartResource.release[ uint8_t id ]() {}
    default event void Resource.granted[ uint8_t id ]() {}
+ 	default async command msp430_i2c_config_t* Msp430SpiConfigure.getConfig[uint8_t id]() {
+ 		return &msp430_i2c_default_config;
+ 	}
    
    async command error_t I2CBasicAddr.read( i2c_flags_t flags,

Index: Msp430Spi0C.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/chips/msp430/usart/Msp430Spi0C.nc,v
retrieving revision 1.1.2.9
retrieving revision 1.1.2.10
diff -C2 -d -r1.1.2.9 -r1.1.2.10
*** Msp430Spi0C.nc	20 Jun 2006 18:56:05 -0000	1.1.2.9
--- Msp430Spi0C.nc	3 Aug 2006 18:10:41 -0000	1.1.2.10
***************
*** 1,4 ****
! /*
!  * Copyright (c) 2005-2006 Arch Rock Corporation
   * All rights reserved.
   *
--- 1,4 ----
! /**
!  * Copyright (c) 2005-2006 Arched Rock Corporation
   * All rights reserved.
   *
***************
*** 12,16 ****
   *   documentation and/or other materials provided with the
   *   distribution.
!  * - Neither the name of the Arch Rock Corporation nor the names of
   *   its contributors may be used to endorse or promote products derived
   *   from this software without specific prior written permission.
--- 12,16 ----
   *   documentation and/or other materials provided with the
   *   distribution.
!  * - Neither the name of the Arched Rock Corporation nor the names of
   *   its contributors may be used to endorse or promote products derived
   *   from this software without specific prior written permission.
***************
*** 36,67 ****
   * place of Msp430SpiNoDma0P.
   *
!  * @author Jonathan Hui <jhui at archrock.com>
   * @version $Revision$ $Date$
   */
  
! #include "msp430UsartResource.h"
  
  generic configuration Msp430Spi0C() {
!   
    provides interface Resource;
    provides interface SpiByte;
    provides interface SpiPacket;
!   
  }
  
  implementation {
!   
    enum {
      CLIENT_ID = unique( MSP430_SPIO_BUS ),
    };
!   
    components Msp430SpiNoDma0P as SpiP;
    Resource = SpiP.Resource[ CLIENT_ID ];
    SpiByte = SpiP.SpiByte;
    SpiPacket = SpiP.SpiPacket[ CLIENT_ID ];
  
    components new Msp430Usart0C() as UsartC;
    SpiP.UsartResource[ CLIENT_ID ] -> UsartC.Resource;
    SpiP.UsartInterrupts -> UsartC.HplMsp430UsartInterrupts;
!   
  }
--- 36,70 ----
   * place of Msp430SpiNoDma0P.
   *
!  * @author Jonathan Hui <jhui at archedrock.com>
   * @version $Revision$ $Date$
   */
  
! #include "msp430usart.h"
  
  generic configuration Msp430Spi0C() {
! 
    provides interface Resource;
    provides interface SpiByte;
    provides interface SpiPacket;
! 
!   uses interface Msp430SpiConfigure;
  }
  
  implementation {
! 
    enum {
      CLIENT_ID = unique( MSP430_SPIO_BUS ),
    };
! 
    components Msp430SpiNoDma0P as SpiP;
    Resource = SpiP.Resource[ CLIENT_ID ];
    SpiByte = SpiP.SpiByte;
    SpiPacket = SpiP.SpiPacket[ CLIENT_ID ];
+   Msp430SpiConfigure = SpiP.Msp430SpiConfigure[ CLIENT_ID ];
  
    components new Msp430Usart0C() as UsartC;
+   SpiP.ResourceConfigure[ CLIENT_ID ] <- UsartC.ResourceConfigure;
    SpiP.UsartResource[ CLIENT_ID ] -> UsartC.Resource;
    SpiP.UsartInterrupts -> UsartC.HplMsp430UsartInterrupts;
! 
  }

Index: Msp430SpiDma0P.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/chips/msp430/usart/Msp430SpiDma0P.nc,v
retrieving revision 1.1.2.4
retrieving revision 1.1.2.5
diff -C2 -d -r1.1.2.4 -r1.1.2.5
*** Msp430SpiDma0P.nc	20 Jun 2006 18:56:05 -0000	1.1.2.4
--- Msp430SpiDma0P.nc	3 Aug 2006 18:10:41 -0000	1.1.2.5
***************
*** 1,4 ****
! /*
!  * Copyright (c) 2005-2006 Arch Rock Corporation
   * All rights reserved.
   *
--- 1,4 ----
! /**
!  * Copyright (c) 2005-2006 Arched Rock Corporation
   * All rights reserved.
   *
***************
*** 12,16 ****
   *   documentation and/or other materials provided with the
   *   distribution.
!  * - Neither the name of the Arch Rock Corporation nor the names of
   *   its contributors may be used to endorse or promote products derived
   *   from this software without specific prior written permission.
--- 12,16 ----
   *   documentation and/or other materials provided with the
   *   distribution.
!  * - Neither the name of the Arched Rock Corporation nor the names of
   *   its contributors may be used to endorse or promote products derived
   *   from this software without specific prior written permission.
***************
*** 31,67 ****
  
  /**
!  * @author Jonathan Hui <jhui at archrock.com>
   * @version $Revision$ $Date$
   */
  
  configuration Msp430SpiDma0P {
!   
    provides interface Resource[ uint8_t id ];
    provides interface SpiByte;
    provides interface SpiPacket[ uint8_t id ];
!   
    uses interface Resource as UsartResource[ uint8_t id ];
    uses interface HplMsp430UsartInterrupts as UsartInterrupts;
!   
  }
  
  implementation {
!   
    components new Msp430SpiDmaP() as SpiP;
    Resource = SpiP.Resource;
    SpiByte = SpiP.SpiByte;
    SpiPacket = SpiP.SpiPacket;
    UsartResource = SpiP.UsartResource;
    UsartInterrupts = SpiP.UsartInterrupts;
!   
    components HplMsp430Usart0C as UsartC;
    SpiP.Usart -> UsartC;
!   
    components Msp430DmaC as DmaC;
    SpiP.DmaChannel1 -> DmaC.Channel1;
    SpiP.DmaChannel2 -> DmaC.Channel2;
!   
    components LedsC as Leds;
    SpiP.Leds -> Leds;
!   
  }
--- 31,71 ----
  
  /**
!  * @author Jonathan Hui <jhui at archedrock.com>
   * @version $Revision$ $Date$
   */
  
  configuration Msp430SpiDma0P {
! 
    provides interface Resource[ uint8_t id ];
+   provides interface ResourceControl [uint8_t id];
    provides interface SpiByte;
    provides interface SpiPacket[ uint8_t id ];
! 
    uses interface Resource as UsartResource[ uint8_t id ];
+   uses interface Msp430SpiConfigure[ uint8_t id ];
    uses interface HplMsp430UsartInterrupts as UsartInterrupts;
! 
  }
  
  implementation {
! 
    components new Msp430SpiDmaP() as SpiP;
    Resource = SpiP.Resource;
+   ResourceControl = SpiP.ResourceControl;
+   Msp430SpiConfigure = SpiP.Msp430SpiConfigure;
    SpiByte = SpiP.SpiByte;
    SpiPacket = SpiP.SpiPacket;
    UsartResource = SpiP.UsartResource;
    UsartInterrupts = SpiP.UsartInterrupts;
! 
    components HplMsp430Usart0C as UsartC;
    SpiP.Usart -> UsartC;
! 
    components Msp430DmaC as DmaC;
    SpiP.DmaChannel1 -> DmaC.Channel1;
    SpiP.DmaChannel2 -> DmaC.Channel2;
! 
    components LedsC as Leds;
    SpiP.Leds -> Leds;
! 
  }

Index: Msp430SpiDmaP.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/chips/msp430/usart/Msp430SpiDmaP.nc,v
retrieving revision 1.1.2.3
retrieving revision 1.1.2.4
diff -C2 -d -r1.1.2.3 -r1.1.2.4
*** Msp430SpiDmaP.nc	20 Jun 2006 18:56:05 -0000	1.1.2.3
--- Msp430SpiDmaP.nc	3 Aug 2006 18:10:41 -0000	1.1.2.4
***************
*** 1,4 ****
! /*
!  * Copyright (c) 2005-2006 Arch Rock Corporation
   * All rights reserved.
   *
--- 1,4 ----
! /**
!  * Copyright (c) 2005-2006 Arched Rock Corporation
   * All rights reserved.
   *
***************
*** 12,16 ****
   *   documentation and/or other materials provided with the
   *   distribution.
!  * - Neither the name of the Arch Rock Corporation nor the names of
   *   its contributors may be used to endorse or promote products derived
   *   from this software without specific prior written permission.
--- 12,16 ----
   *   documentation and/or other materials provided with the
   *   distribution.
!  * - Neither the name of the Arched Rock Corporation nor the names of
   *   its contributors may be used to endorse or promote products derived
   *   from this software without specific prior written permission.
***************
*** 31,35 ****
  
  /**
!  * @author Jonathan Hui <jhui at archrock.com>
   * @version $Revision$ $Date$
   */
--- 31,35 ----
  
  /**
!  * @author Jonathan Hui <jhui at archedrock.com>
   * @version $Revision$ $Date$
   */
***************
*** 41,48 ****
    provides interface SpiByte;
    provides interface SpiPacket[ uint8_t id ];
!   
    uses interface Msp430DmaChannel as DmaChannel1;
    uses interface Msp430DmaChannel as DmaChannel2;
    uses interface Resource as UsartResource[ uint8_t id ];
    uses interface HplMsp430Usart as Usart;
    uses interface HplMsp430UsartInterrupts as UsartInterrupts;
--- 41,49 ----
    provides interface SpiByte;
    provides interface SpiPacket[ uint8_t id ];
! 
    uses interface Msp430DmaChannel as DmaChannel1;
    uses interface Msp430DmaChannel as DmaChannel2;
    uses interface Resource as UsartResource[ uint8_t id ];
+   uses interface Msp430SpiConfigure[uint8_t id ];
    uses interface HplMsp430Usart as Usart;
    uses interface HplMsp430UsartInterrupts as UsartInterrupts;
***************
*** 65,72 ****
  
    async command error_t Resource.immediateRequest[ uint8_t id ]() {
!     error_t error = call UsartResource.immediateRequest[ id ]();
!     if ( error == SUCCESS )
!       call Usart.setModeSPI();
!     return error;
    }
  
--- 66,70 ----
  
    async command error_t Resource.immediateRequest[ uint8_t id ]() {
!     return call UsartResource.immediateRequest[ id ]();
    }
  
***************
*** 79,84 ****
    }
  
    event void UsartResource.granted[ uint8_t id ]() {
-     call Usart.setModeSPI();
      signal Resource.granted[ id ]();
    }
--- 77,88 ----
    }
  
+   async command void ResourceConfigure.configure[ uint8_t id ]() {
+     call Usart.setModeSpi(call Msp430SpiConfigure.getConfig[id]());
+   }
+ 
+   async command void ResourceConfigure.unconfigure[ uint8_t id ]() {
+   }
+ 
    event void UsartResource.granted[ uint8_t id ]() {
      signal Resource.granted[ id ]();
    }
***************
*** 88,98 ****
    }
  
    default async command error_t UsartResource.request[ uint8_t id ]() { return FAIL; }
    default async command error_t UsartResource.immediateRequest[ uint8_t id ]() { return FAIL; }
    default async command void UsartResource.release[ uint8_t id ]() {}
    default event void Resource.granted[ uint8_t id ]() {}
  
    async command void SpiByte.write( uint8_t tx, uint8_t* rx ) {
!     
      call Usart.tx( tx );
      while( !call Usart.isRxIntrPending() );
--- 92,107 ----
    }
  
+   default async command error_t UsartResource.isOwner[ uint8_t id ]() { return FAIL; }
    default async command error_t UsartResource.request[ uint8_t id ]() { return FAIL; }
    default async command error_t UsartResource.immediateRequest[ uint8_t id ]() { return FAIL; }
    default async command void UsartResource.release[ uint8_t id ]() {}
+   default async command msp430_spi_config_t* Msp430SpiConfigure.getConfig[uint8_t id]() {
+     return &msp430_spi_default_config;
+   }
+ 
    default event void Resource.granted[ uint8_t id ]() {}
  
    async command void SpiByte.write( uint8_t tx, uint8_t* rx ) {
! 
      call Usart.tx( tx );
      while( !call Usart.isRxIntrPending() );
***************
*** 100,106 ****
  
    }
!   
!   async command error_t SpiPacket.send[ uint8_t id ]( uint8_t* tx_buf, 
! 						      uint8_t* rx_buf, 
  						      uint16_t len ) {
  
--- 109,115 ----
  
    }
! 
!   async command error_t SpiPacket.send[ uint8_t id ]( uint8_t* tx_buf,
! 						      uint8_t* rx_buf,
  						      uint16_t len ) {
  
***************
*** 147,155 ****
  
    async event void DmaChannel2.transferDone( error_t error ) {}
!  
    void signalDone( error_t error ) {
      signal SpiPacket.sendDone[ m_client ]( m_tx_buf, m_rx_buf, m_len, error );
    }
!   
    async event void UsartInterrupts.txDone() {}
    async event void UsartInterrupts.rxDone( uint8_t data ) {}
--- 156,164 ----
  
    async event void DmaChannel2.transferDone( error_t error ) {}
! 
    void signalDone( error_t error ) {
      signal SpiPacket.sendDone[ m_client ]( m_tx_buf, m_rx_buf, m_len, error );
    }
! 
    async event void UsartInterrupts.txDone() {}
    async event void UsartInterrupts.rxDone( uint8_t data ) {}

Index: Msp430SpiNoDma0P.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/chips/msp430/usart/Msp430SpiNoDma0P.nc,v
retrieving revision 1.1.2.4
retrieving revision 1.1.2.5
diff -C2 -d -r1.1.2.4 -r1.1.2.5
*** Msp430SpiNoDma0P.nc	20 Jun 2006 18:56:05 -0000	1.1.2.4
--- Msp430SpiNoDma0P.nc	3 Aug 2006 18:10:41 -0000	1.1.2.5
***************
*** 1,4 ****
! /*
!  * Copyright (c) 2005-2006 Arch Rock Corporation
   * All rights reserved.
   *
--- 1,4 ----
! /**
!  * Copyright (c) 2005-2006 Arched Rock Corporation
   * All rights reserved.
   *
***************
*** 12,16 ****
   *   documentation and/or other materials provided with the
   *   distribution.
!  * - Neither the name of the Arch Rock Corporation nor the names of
   *   its contributors may be used to endorse or promote products derived
   *   from this software without specific prior written permission.
--- 12,16 ----
   *   documentation and/or other materials provided with the
   *   distribution.
!  * - Neither the name of the Arched Rock Corporation nor the names of
   *   its contributors may be used to endorse or promote products derived
   *   from this software without specific prior written permission.
***************
*** 31,53 ****
  
  /**
!  * @author Jonathan Hui <jhui at archrock.com>
   * @version $Revision$ $Date$
   */
  
  configuration Msp430SpiNoDma0P {
!   
    provides interface Resource[ uint8_t id ];
    provides interface SpiByte;
    provides interface SpiPacket[ uint8_t id ];
!   
    uses interface Resource as UsartResource[ uint8_t id ];
    uses interface HplMsp430UsartInterrupts as UsartInterrupts;
!   
  }
  
  implementation {
!   
    components new Msp430SpiNoDmaP() as SpiP;
    Resource = SpiP.Resource;
    SpiByte = SpiP.SpiByte;
    SpiPacket = SpiP.SpiPacket;
--- 31,57 ----
  
  /**
!  * @author Jonathan Hui <jhui at archedrock.com>
   * @version $Revision$ $Date$
   */
  
  configuration Msp430SpiNoDma0P {
! 
    provides interface Resource[ uint8_t id ];
+   provides interface ResourceConfigure[uint8_t id ];
    provides interface SpiByte;
    provides interface SpiPacket[ uint8_t id ];
! 
    uses interface Resource as UsartResource[ uint8_t id ];
+   uses interface Msp430SpiConfigure[ uint8_t id ];
    uses interface HplMsp430UsartInterrupts as UsartInterrupts;
! 
  }
  
  implementation {
! 
    components new Msp430SpiNoDmaP() as SpiP;
    Resource = SpiP.Resource;
+   ResourceConfigure = SpiP.ResourceConfigure;
+   Msp430SpiConfigure = SpiP.Msp430SpiConfigure;
    SpiByte = SpiP.SpiByte;
    SpiPacket = SpiP.SpiPacket;
***************
*** 57,63 ****
    components HplMsp430Usart0C as UsartC;
    SpiP.Usart -> UsartC;
!   
    components LedsC as Leds;
    SpiP.Leds -> Leds;
!   
  }
--- 61,67 ----
    components HplMsp430Usart0C as UsartC;
    SpiP.Usart -> UsartC;
! 
    components LedsC as Leds;
    SpiP.Leds -> Leds;
! 
  }

Index: Msp430SpiNoDmaP.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/chips/msp430/usart/Msp430SpiNoDmaP.nc,v
retrieving revision 1.1.2.3
retrieving revision 1.1.2.4
diff -C2 -d -r1.1.2.3 -r1.1.2.4
*** Msp430SpiNoDmaP.nc	20 Jun 2006 18:56:05 -0000	1.1.2.3
--- Msp430SpiNoDmaP.nc	3 Aug 2006 18:10:41 -0000	1.1.2.4
***************
*** 1,4 ****
! /*
!  * Copyright (c) 2005-2006 Arch Rock Corporation
   * All rights reserved.
   *
--- 1,4 ----
! /**
!  * Copyright (c) 2005-2006 Arched Rock Corporation
   * All rights reserved.
   *
***************
*** 12,16 ****
   *   documentation and/or other materials provided with the
   *   distribution.
!  * - Neither the name of the Arch Rock Corporation nor the names of
   *   its contributors may be used to endorse or promote products derived
   *   from this software without specific prior written permission.
--- 12,16 ----
   *   documentation and/or other materials provided with the
   *   distribution.
!  * - Neither the name of the Arched Rock Corporation nor the names of
   *   its contributors may be used to endorse or promote products derived
   *   from this software without specific prior written permission.
***************
*** 31,35 ****
  
  /**
!  * @author Jonathan Hui <jhui at archrock.com>
   * @version $Revision$ $Date$
   */
--- 31,35 ----
  
  /**
!  * @author Jonathan Hui <jhui at archedrock.com>
   * @version $Revision$ $Date$
   */
***************
*** 37,46 ****
  
  generic module Msp430SpiNoDmaP() {
!   
    provides interface Resource[ uint8_t id ];
    provides interface SpiByte;
    provides interface SpiPacket[ uint8_t id ];
!   
    uses interface Resource as UsartResource[ uint8_t id ];
    uses interface HplMsp430Usart as Usart;
    uses interface HplMsp430UsartInterrupts as UsartInterrupts;
--- 37,48 ----
  
  generic module Msp430SpiNoDmaP() {
! 
    provides interface Resource[ uint8_t id ];
+   provides interface ResourceConfigure[ uint8_t id ];
    provides interface SpiByte;
    provides interface SpiPacket[ uint8_t id ];
! 
    uses interface Resource as UsartResource[ uint8_t id ];
+   uses interface Msp430SpiConfigure[ uint8_t id ];
    uses interface HplMsp430Usart as Usart;
    uses interface HplMsp430Us