*
* TODO: Implement error checking via UCxxSTAT
*
- * @author R. Steve McKown <smckown@gmail.com>
+ * @author R. Steve McKown <rsmckown@gmail.com>
*/
generic module Msp430SpiP(uint16_t blockSize) {
{
atomic {
/* Disable the device */
- call Registers.setCtl1(UCSYNC);
+ call Registers.setCtl1(UCSWRST);
/* Clear interrupts and interrupt flags. We only used Rx */
call Registers.clrIeRx();
call Registers.clrIfgRx();
/* Restore pins to their pre-configure state */
- if (is4pin() && (m_pins & PINS_STE))
+ if (is4pin() && (m_pins & (1 << PINS_STE)))
call STE.selectIOFunc();
- if (m_pins & PINS_SIMO)
+ if (m_pins & (1 << PINS_SIMO))
call SIMO.selectIOFunc();
- if (m_pins & PINS_SOMI)
+ if (m_pins & (1 << PINS_SOMI))
call SOMI.selectIOFunc();
- if (m_pins & PINS_CLK)
+ if (m_pins & (1 << PINS_CLK))
call CLK.selectIOFunc();
}
}
if (isBusy())
return 0;
else {
- while (!call Registers.getIfgTx());
+ while (!call Registers.getIfgTx() && !call Registers.getCtl1(UCSWRST));
call Registers.setTxbuf(byte);
- while(!call Registers.getIfgRx());
+ while(!call Registers.getIfgRx() && !call Registers.getCtl1(UCSWRST));
return call Registers.getRxbuf();
}
}
task void signalSendDone()
{
atomic {
- signal SpiPacket.sendDone(m_txBuf, m_rxBuf, m_len, SUCCESS);
m_len = 0;
+ signal SpiPacket.sendDone(m_txBuf, m_rxBuf, m_len, SUCCESS);
}
}
async event void Interrupts.rx(uint8_t byte)
{
if (m_rxBuf)
- m_rxBuf[m_pos - 1] = call Registers.getRxbuf();
- else
- call Registers.getRxbuf();
+ m_rxBuf[m_pos - 1] = byte;
if (m_pos < m_len)
sendData();