]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tos/chips/msp430/usart/Msp430SpiNoDmaP.nc
Swapping HEAD and DEVEL branches
[tinyos-2.x.git] / tos / chips / msp430 / usart / Msp430SpiNoDmaP.nc
index e35880103c09f94fa58c1183638403d5b3e1a29c..57102aaf7d0dccd839aa3ea623c0ff2aefca9152 100644 (file)
@@ -1,5 +1,5 @@
-/*
- * Copyright (c) 2005-2006 Arch Rock Corporation
+/**
+ * Copyright (c) 2005-2006 Arched Rock Corporation
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -11,7 +11,7 @@
  *   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 Arch Rock Corporation nor the names of
+ * - 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.
  *
  */
 
 /**
- * @author Jonathan Hui <jhui@archrock.com>
+ * @author Jonathan Hui <jhui@archedrock.com>
  * @version $Revision$ $Date$
  */
 
 
 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 HplMsp430UsartInterrupts as UsartInterrupts;
   uses interface Leds;
@@ -49,55 +51,70 @@ generic module Msp430SpiNoDmaP() {
 }
 
 implementation {
-  
+
   enum {
     SPI_ATOMIC_SIZE = 2,
   };
-  
+
   norace uint8_t* m_tx_buf;
   norace uint8_t* m_rx_buf;
   norace uint16_t m_len;
   norace uint16_t m_pos;
   norace uint8_t m_client;
-  
+
   void signalDone();
   task void signalDone_task();
 
   async command error_t Resource.immediateRequest[ uint8_t id ]() {
-    error_t result = call UsartResource.immediateRequest[ id ]();
-    if ( result == SUCCESS )
-      call Usart.setModeSPI();
-    return result;
+    return call UsartResource.immediateRequest[ id ]();
   }
-  
+
   async command error_t Resource.request[ uint8_t id ]() {
     return call UsartResource.request[ id ]();
   }
-  
+
   async command uint8_t Resource.isOwner[ uint8_t id ]() {
     return call UsartResource.isOwner[ id ]();
   }
-  
-  async command void Resource.release[ uint8_t id ]() {
-    call UsartResource.release[ id ]();
+
+  async command error_t Resource.release[ uint8_t id ]() {
+    return call UsartResource.release[ id ]();
+  }
+
+  async command void ResourceConfigure.configure[ uint8_t id ]() {
+    call Usart.setModeSpi(call Msp430SpiConfigure.getConfig[id]());
+  }
+
+  async command void ResourceConfigure.unconfigure[ uint8_t id ]() {
+    call Usart.resetUsart(TRUE);
+    call Usart.disableSpi();
+    call Usart.resetUsart(FALSE);
   }
 
   event void UsartResource.granted[ uint8_t id ]() {
-    call Usart.setModeSPI();
     signal Resource.granted[ id ]();
   }
 
-  async command void SpiByte.write( uint8_t tx, uint8_t* rx ) {
-    call Usart.disableRxIntr();
+  async command uint8_t SpiByte.write( uint8_t tx ) {
+    uint8_t byte;
+    // we are in spi mode which is configured to have turned off interrupts
+    //call Usart.disableRxIntr();
     call Usart.tx( tx );
     while( !call Usart.isRxIntrPending() );
-    *rx = call Usart.rx();
-    call Usart.enableRxIntr();
+    call Usart.clrRxIntr();
+    byte = call Usart.rx();
+    //call Usart.enableRxIntr();
+    return byte;
   }
 
+  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 error_t UsartResource.immediateRequest[ uint8_t id ]() { return FAIL; }
+  default async command error_t UsartResource.release[ uint8_t id ]() { return FAIL; }
+  default async command msp430_spi_union_config_t* Msp430SpiConfigure.getConfig[uint8_t id]() {
+    return &msp430_spi_default_config;
+  }
+
   default event void Resource.granted[ uint8_t id ]() {}
 
   void continueOp() {
@@ -114,8 +131,10 @@ implementation {
 
       while ( ++m_pos < end ) {
         while( !call Usart.isTxIntrPending() );
+        call Usart.clrTxIntr();
         call Usart.tx( m_tx_buf ? m_tx_buf[ m_pos ] : 0 );
         while( !call Usart.isRxIntrPending() );
+        call Usart.clrRxIntr();
         tmp = call Usart.rx();
         if ( m_rx_buf )
           m_rx_buf[ m_pos - 1 ] = tmp;
@@ -127,7 +146,7 @@ implementation {
   async command error_t SpiPacket.send[ uint8_t id ]( uint8_t* tx_buf,
                                                       uint8_t* rx_buf,
                                                       uint16_t len ) {
-    
+
     m_client = id;
     m_tx_buf = tx_buf;
     m_rx_buf = rx_buf;
@@ -151,7 +170,7 @@ implementation {
   }
 
   async event void UsartInterrupts.rxDone( uint8_t data ) {
-    
+
     if ( m_rx_buf )
       m_rx_buf[ m_pos-1 ] = data;
 
@@ -164,7 +183,7 @@ implementation {
   }
 
   void signalDone() {
-    signal SpiPacket.sendDone[ m_client ]( m_tx_buf, m_rx_buf, m_len, 
+    signal SpiPacket.sendDone[ m_client ]( m_tx_buf, m_rx_buf, m_len,
                                           SUCCESS );
   }