*
*/
-module Atm128SpiP {
+module Atm128SpiP @safe() {
provides {
interface Init;
interface SpiByte;
+ interface FastSpiByte;
interface SpiPacket;
interface Resource[uint8_t id];
}
}
}
implementation {
- uint8_t* txBuffer;
- uint8_t* rxBuffer;
uint16_t len;
+ uint8_t* COUNT_NOK(len) txBuffer;
+ uint8_t* COUNT_NOK(len) rxBuffer;
uint16_t pos;
enum {
}
async command uint8_t SpiByte.write( uint8_t tx ) {
+ /* There is no need to enable the SPI bus and update the power state
+ here since that must have been done when the resource was granted.
+ However there seems to be a bug somewhere in the radio driver for
+ the MicaZ platform so we cannot remove the following two lines
+ before that problem is resolved. (Miklos Maroti) */
call Spi.enableSpi(TRUE);
call McuPowerState.update();
+
call Spi.write( tx );
while ( !( SPSR & 0x80 ) );
return call Spi.read();
}
+ inline async command void FastSpiByte.splitWrite(uint8_t data) {
+ call Spi.write(data);
+ }
+
+ inline async command uint8_t FastSpiByte.splitRead() {
+ while( !( SPSR & 0x80 ) )
+ ;
+ return call Spi.read();
+ }
+
+ inline async command uint8_t FastSpiByte.splitReadWrite(uint8_t data) {
+ uint8_t b;
+
+ while( !( SPSR & 0x80 ) )
+ ;
+ b = call Spi.read();
+ call Spi.write(data);
+
+ return b;
+ }
+
+ inline async command uint8_t FastSpiByte.write(uint8_t data) {
+ call Spi.write(data);
+ while( !( SPSR & 0x80 ) )
+ ;
+ return call Spi.read();
+ }
/**
* This component sends SPI packets in chunks of size SPI_ATOMIC_SIZE
error_t sendNextPart() {
uint16_t end;
uint16_t tmpPos;
- uint8_t* tx;
- uint8_t* rx;
+ uint16_t myLen;
+ uint8_t* COUNT_NOK(myLen) tx;
+ uint8_t* COUNT_NOK(myLen) rx;
atomic {
+ myLen = len;
tx = txBuffer;
rx = rxBuffer;
tmpPos = pos;
task void zeroTask() {
- uint8_t* rx;
- uint8_t* tx;
uint16_t myLen;
+ uint8_t* COUNT_NOK(myLen) rx;
+ uint8_t* COUNT_NOK(myLen) tx;
+
atomic {
+ myLen = len;
rx = rxBuffer;
tx = txBuffer;
- myLen = len;
rxBuffer = NULL;
txBuffer = NULL;
len = 0;
uint16_t bufLen) {
uint8_t discard;
atomic {
+ len = bufLen;
txBuffer = writeBuf;
rxBuffer = readBuf;
- len = bufLen;
pos = 0;
}
if (bufLen > 0) {
sendNextPart();
}
else {
- uint8_t* rx;
- uint8_t* tx;
- uint16_t myLen;
uint8_t discard;
+ uint16_t myLen;
+ uint8_t* COUNT_NOK(myLen) rx;
+ uint8_t* COUNT_NOK(myLen) tx;
atomic {
+ myLen = len;
rx = rxBuffer;
tx = txBuffer;
- myLen = len;
rxBuffer = NULL;
txBuffer = NULL;
len = 0;