]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tos/chips/msp430/usci/HplMsp430UsciInt1P.nc
Fix TMI copyright attributions
[tinyos-2.x.git] / tos / chips / msp430 / usci / HplMsp430UsciInt1P.nc
index 5fa0291ca8255daaa7a2f7fbc11c28afb78b1862..f6caca02be3731b5a43aea36c2e11cd5c8fed8a1 100644 (file)
@@ -10,7 +10,7 @@
  * - 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
+ * - Neither the name of the Titanium Mirror, Inc. nor the names
  *   of its contributors may be used to endorse or promote products derived
  *   from this software without specific prior written permission.
  *
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
+
 /**
  * HPL interrupt interface for the USCI1 peripheral.
- * 
+ *
  * @author R. Steve McKown <rsmckown@gmail.com>
  */
+
 #include "Msp430Usci.h"
 #include "msp430hardware.h"
 
@@ -60,37 +60,54 @@ implementation
    * modes.
    */
   TOSH_SIGNAL(USCIAB1RX_VECTOR) {
-    if (READ_FLAG(UC1IFG, UCA1RXIFG)) {
+    if (READ_FLAG(UC1IFG & UC1IE, UCA1RXIE)) {
       volatile uint8_t c = UCA1RXBUF; /* read to clear UCA1RXIFG */
       if (READ_FLAG(UCA1CTL1, UCBRK)) {
-       UCA1CTL1 &= ~UCBRK;
+       CLR_FLAG(UCA1CTL1, UCBRK);
        if (READ_FLAG(UCA1CTL0, UCMODE_3) == UCMODE_3)
-         UCA1CTL1 &= ~UCDORM;
+         CLR_FLAG(UCA1CTL1, UCDORM);
        signal IntA.brk();
       } else
        signal IntA.rx(c);
-    } else if (READ_FLAG(UC1IFG, UCB1RXIFG))
+    } else if (READ_FLAG(UC1IFG & UC1IE, UCB1RXIE)) {
       signal IntB.rx(UCB1RXBUF); /* read clears UCB1RXIFG */
-    else if (READ_FLAG(UCB1STAT, UCALIFG))
+
+    /* FIXME: the arbitration of I2C interrupts are not vetted.  If, for example
+     * the UCALIFG bit gets set and neither it nor the corresponding interrupt
+     * enable bit is never unset, then an ISR configured for UCSTTIFG or
+     * UCSTPIFG will never be signalled.
+     */
+
+    } else if (READ_FLAG(UCB1STAT, UCALIFG)) {
+      CLR_FLAG(UCB1STAT, UCALIFG);
       signal IntB.i2cCal();
-    else if (READ_FLAG(UCB1STAT, UCNACKIFG))
-      signal IntB.i2cNak();
-    else if (READ_FLAG(UCB1STAT, UCSTTIFG))
+    } else if (READ_FLAG(UCB1STAT, UCNACKIFG)) {
+      CLR_FLAG(UCB1STAT, UCNACKIFG);
+      CLR_FLAG(UC1IFG, UCB1TXIFG); /* Errata USCI25; 'reset' means clear? */
+      signal IntB.i2cNack();
+    } else if (READ_FLAG(UCB1STAT, UCSTTIFG)) {
+      CLR_FLAG(UCB1STAT, UCSTTIFG);
       signal IntB.i2cStart();
-    else if (READ_FLAG(UCB1STAT, UCSTPIFG))
+    } else if (READ_FLAG(UCB1STAT, UCSTPIFG)) {
+      CLR_FLAG(UCB1STAT, UCSTPIFG);
       signal IntB.i2cStop();
+    }
   }
-  
+
   /* This interrupt vector signals transmit events.  USCI_A1 can receive events
    * for UART and SPI modes, while USCI_B1 can receive events for I2C and SPI
    * modes.
    */
   TOSH_SIGNAL(USCIAB1TX_VECTOR) {
-    if (READ_FLAG(UC1IFG, UCB1RXIFG))
-      signal IntB.rx(UCB1RXBUF); /* I2C receive */
-    else if (READ_FLAG(UC1IFG, UCA1TXIFG))
+    if (READ_FLAG(UC1IFG & UC1IE, UCB1RXIE))
+      /* I2C receive.  Do not read UCB1RXBUF here, as the code receiving
+       * IntB.rx() may first need to set stop and/or start bits.  The receiver
+       * must read UCB1RXBUF.
+       */
+      signal IntB.rx(0);
+    else if (READ_FLAG(UC1IFG & UC1IE, UCA1TXIFG))
       signal IntA.tx();
-    else if (READ_FLAG(UC1IFG, UCB1TXIFG))
+    else if (READ_FLAG(UC1IFG & UC1IE, UCB1TXIFG))
       signal IntB.tx();
   }
 
@@ -99,7 +116,7 @@ implementation
   default async event void IntA.tx() {}
   /* i2c is not available for A devices, so the below are never signalled */
   default async event void IntA.i2cCal() {}
-  default async event void IntA.i2cNak() {}
+  default async event void IntA.i2cNack() {}
   default async event void IntA.i2cStart() {}
   default async event void IntA.i2cStop() {}
 
@@ -108,7 +125,7 @@ implementation
   default async event void IntB.rx(uint8_t byte) {}
   default async event void IntB.tx() {}
   default async event void IntB.i2cCal() {}
-  default async event void IntB.i2cNak() {}
+  default async event void IntB.i2cNack() {}
   default async event void IntB.i2cStart() {}
   default async event void IntB.i2cStop() {}
 }