]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tos/chips/msp430/usci/HplMsp430UsciRegP.nc
msp430 usci: add setIfgTx(), setIfgRx()
[tinyos-2.x.git] / tos / chips / msp430 / usci / HplMsp430UsciRegP.nc
index cde8ae1acbc44247886d0cbc6e9a0402329c840d..fcd3c10e0b388e6fc72f3acacff8724055df0ca2 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 register interface to USCI peripherals.  The interface abstracts the
  * differences between pysical devices (aka addresses) such that a user of
  * the interface can equally use any USCI device, providing the device
  * provides the necessary capabilities.  For example, I2C is only available
  * on USCI_Bx ports.
- * 
+ *
  * @author R. Steve McKown <rsmckown@gmail.com>
  */
+
 #include "Msp430Usci.h"
 #include "msp430hardware.h"
 
@@ -57,8 +57,8 @@ generic module HplMsp430UsciRegP(
     uint16_t I2Csa_addr,       /* B devices only */
     uint16_t Ie_addr,
     uint16_t Ifg_addr,
-    uint16_t UCAxRXIFG,        /* We rely on xIE and xIFG at same bit positions */
-    uint16_t UCAxTXIFG
+    uint16_t UCxxRXIFG,        /* We rely on xIE and xIFG at same bit positions */
+    uint16_t UCxxTXIFG
     ) @safe() {
   provides interface HplMsp430UsciReg as Registers;
 }
@@ -85,66 +85,72 @@ implementation
   #define UCxxIe (*TCAST(volatile uint8_t* ONE, Ie_addr))
   #define UCxxIfg (*TCAST(volatile uint8_t* ONE, Ifg_addr))
 
+#if 0
   #define ASSIGNBITS(reg, mask, value) \
                (reg = ((reg) & ~(mask)) | ((value) & (mask)))
+#endif
 
   #define RENDER(name) \
-       command volatile uint8_t* Registers.ptr##name() { \
+       async command volatile uint8_t* Registers.ptr##name() { \
                return &UCxx##name; \
        } \
-       command uint8_t Registers.get##name(uint8_t mask) { \
+       async command uint8_t Registers.get##name(uint8_t mask) { \
                return READ_FLAG(UCxx##name, mask); \
        } \
-       command void Registers.set##name(uint8_t mask) { \
+       async command void Registers.set##name(uint8_t mask) { \
                SET_FLAG(UCxx##name, mask); \
        } \
-       command void Registers.clr##name(uint8_t mask) { \
+       async command void Registers.clr##name(uint8_t mask) { \
                CLR_FLAG(UCxx##name, mask); \
        } \
-       command void Registers.assign##name(uint8_t mask, uint8_t value) { \
-               ASSIGNBITS(UCxx##name, mask, value); \
+       async command void Registers.assign##name(uint8_t value) { \
+               UCxx##name = value; \
        }
 
   #define RENDER_A(name) \
-       command volatile uint8_t* Registers.ptr##name() { \
+       async command volatile uint8_t* Registers.ptr##name() { \
                return &UCAx##name; \
        } \
-       command uint8_t Registers.get##name(uint8_t mask) { \
+       async command uint8_t Registers.get##name(uint8_t mask) { \
                if (IS_USCI_Ax) \
                        return READ_FLAG(UCAx##name, mask); \
+               else \
+                       return 0; \
        } \
-       command void Registers.set##name(uint8_t mask) { \
+       async command void Registers.set##name(uint8_t mask) { \
                if (IS_USCI_Ax) \
                        SET_FLAG(UCAx##name, mask); \
        } \
-       command void Registers.clr##name(uint8_t mask) { \
+       async command void Registers.clr##name(uint8_t mask) { \
                if (IS_USCI_Ax) \
                        CLR_FLAG(UCAx##name, mask); \
        } \
-       command void Registers.assign##name(uint8_t mask, uint8_t value) { \
+       async command void Registers.assign##name(uint8_t value) { \
                if (IS_USCI_Ax) \
-                       ASSIGNBITS(UCAx##name, mask, value); \
+                       UCAx##name = value; \
        }
 
   #define RENDER_B(name) \
-       command volatile uint8_t* Registers.ptr##name() { \
+       async command volatile uint8_t* Registers.ptr##name() { \
                return &UCBx##name; \
        } \
-       command uint8_t Registers.get##name(uint8_t mask) { \
+       async command uint8_t Registers.get##name(uint8_t mask) { \
                if (IS_USCI_Bx) \
                        return READ_FLAG(UCBx##name, mask); \
+               else \
+                       return 0; \
        } \
-       command void Registers.set##name(uint8_t mask) { \
+       async command void Registers.set##name(uint8_t mask) { \
                if (IS_USCI_Bx) \
                        SET_FLAG(UCBx##name, mask); \
        } \
-       command void Registers.clr##name(uint8_t mask) { \
+       async command void Registers.clr##name(uint8_t mask) { \
                if (IS_USCI_Bx) \
                        CLR_FLAG(UCBx##name, mask); \
        } \
-       command void Registers.assign##name(uint8_t mask, uint8_t value) { \
+       async command void Registers.assign##name(uint8_t value) { \
                if (IS_USCI_Bx) \
-                       ASSIGNBITS(UCBx##name, mask, value); \
+                       UCBx##name = value; \
        }
 
 #if 0
@@ -167,7 +173,7 @@ implementation
   MSP430REG_NORACE(UCxIfg);
 #endif
 
-  command msp430_usci_mode_t Registers.getMode()
+  async command msp430_usci_mode_t Registers.getMode()
   {
     if (READ_FLAG(UCxxCtl0, UCSYNC)) {
       if (READ_FLAG(UCxxCtl0, UCMODE_3) == UCMODE_3)
@@ -179,13 +185,17 @@ implementation
     }
   }
 
-  command bool Registers.setMode(msp430_usci_mode_t mode)
+  /* Doesn't really set the mode, but checks the mode for the device and inits
+   * the device.
+   */
+  async command bool Registers.setMode(msp430_usci_mode_t mode)
   {
     if (mode == USCI_UART && IS_USCI_Bx)
       return FALSE;
     if (mode == USCI_I2C && IS_USCI_Ax)
       return FALSE;
-    SET_FLAG(UCxxCtl0, UCSYNC);
+    SET_FLAG(UCxxCtl1, UCSWRST);
+    return TRUE;
   }
 
   RENDER(Ctl0);
@@ -197,28 +207,28 @@ implementation
   RENDER(Stat);
 
   /* RENDER(Rxbuf); */
-  command volatile uint8_t* Registers.ptrRxbuf()
+  async command volatile uint8_t* Registers.ptrRxbuf()
   {
     return &UCxxRxbuf;
   }
 
-  command uint8_t Registers.getRxbuf()
+  async command uint8_t Registers.getRxbuf()
   {
     return UCxxRxbuf;
   }
 
   /* RENDER(Txbuf); */
-  command volatile uint8_t* Registers.ptrTxbuf()
+  async command volatile uint8_t* Registers.ptrTxbuf()
   {
     return &UCxxTxbuf;
   }
 
-  command uint8_t Registers.getTxbuf()
+  async command uint8_t Registers.getTxbuf()
   {
     return UCxxTxbuf;
   }
 
-  command void Registers.setTxbuf(uint8_t byte)
+  async command void Registers.setTxbuf(uint8_t byte)
   {
     UCxxTxbuf = byte;
   }
@@ -226,68 +236,98 @@ implementation
   RENDER_A(Abctl);
   RENDER_A(Irtctl);
   RENDER_A(Irrctl);
-  RENDER_B(I2Coa);
-  RENDER_B(I2Csa);
+
+  /* RENDER_B(I2Coa); */
+  async command volatile uint8_t* Registers.ptrI2Coa()
+  {
+    return &UCBxI2Coa;
+  }
+
+  async command uint16_t Registers.readI2Coa()
+  {
+    return UCBxI2Coa;
+  }
+
+  async command void Registers.assignI2Coa(uint16_t addr)
+  {
+    UCBxI2Coa = addr;
+  }
+
+  /* RENDER_B(I2Csa); */
+  async command volatile uint8_t* Registers.ptrI2Csa()
+  {
+    return &UCBxI2Csa;
+  }
+
+  async command uint16_t Registers.readI2Csa()
+  {
+    return UCBxI2Csa;
+  }
+
+  async command void Registers.assignI2Csa(uint16_t addr)
+  {
+    UCBxI2Csa = addr;
+  }
 
   /* RENDER(Ie); */
-  command bool Registers.getIeRx()
+  async command bool Registers.getIeRx()
   {
-    return READ_FLAG(UCxxIe, UCAxRXIFG);
+    return READ_FLAG(UCxxIe, UCxxRXIFG);
   }
 
-  command void Registers.setIeRx()
+  async command void Registers.setIeRx()
   {
-    SET_FLAG(UCxxIe, UCAxRXIFG);
+    SET_FLAG(UCxxIe, UCxxRXIFG);
   }
 
-  command void Registers.clrIeRx()
+  async command void Registers.clrIeRx()
   {
-    CLR_FLAG(UCxxIe, UCAxRXIFG);
+    CLR_FLAG(UCxxIe, UCxxRXIFG);
   }
 
-  command bool Registers.getIeTx()
+  async command bool Registers.getIeTx()
   {
-    return READ_FLAG(UCxxIe, UCAxTXIFG);
+    return READ_FLAG(UCxxIe, UCxxTXIFG);
   }
 
-  command void Registers.setIeTx()
+  async command void Registers.setIeTx()
   {
-    SET_FLAG(UCxxIe, UCAxTXIFG);
+    SET_FLAG(UCxxIe, UCxxTXIFG);
   }
 
-  command void Registers.clrIeTx()
+  async command void Registers.clrIeTx()
   {
-    CLR_FLAG(UCxxIe, UCAxTXIFG);
+    CLR_FLAG(UCxxIe, UCxxTXIFG);
   }
 
   /* RENDER(Ifg); */
-  command bool Registers.getIfgRx()
+  async command bool Registers.getIfgRx()
   {
-    return READ_FLAG(UCxxIfg, UCAxRXIFG);
+    return READ_FLAG(UCxxIfg, UCxxRXIFG);
   }
 
-  command void Registers.setIfgRx()
+  async command void Registers.setIfgRx()
   {
-    SET_FLAG(UCxxIfg, UCAxRXIFG);
+    SET_FLAG(UCxxIfg, UCxxRXIFG);
   }
 
-  command void Registers.clrIfgRx()
+  async command void Registers.clrIfgRx()
   {
-    CLR_FLAG(UCxxIfg, UCAxRXIFG);
+    CLR_FLAG(UCxxIfg, UCxxRXIFG);
   }
 
-  command bool Registers.getIfgTx()
+  async command bool Registers.getIfgTx()
   {
-    return READ_FLAG(UCxxIfg, UCAxTXIFG);
+    return READ_FLAG(UCxxIfg, UCxxTXIFG);
   }
 
-  command void Registers.setIfgTx()
+  async command void Registers.setIfgTx()
   {
-    SET_FLAG(UCxxIfg, UCAxTXIFG);
+    SET_FLAG(UCxxIfg, UCxxTXIFG);
   }
 
-  command void Registers.clrIfgTx()
+  async command void Registers.clrIfgTx()
   {
-    CLR_FLAG(UCxxIfg, UCAxTXIFG);
+    CLR_FLAG(UCxxIfg, UCxxTXIFG);
   }
 }