30.11.2012 Views

The Internet Power Line Adapter - University of Queensland

The Internet Power Line Adapter - University of Queensland

The Internet Power Line Adapter - University of Queensland

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />

CMPA #ISRXLEN * is it transmitting the<br />

length?<br />

BEQ ISRWLEN<br />

CMPA #ISRRCV * is it receiving the data?<br />

BEQ ISRR<br />

CMPA #ISRRLEN * is it receiving the<br />

length?<br />

BEQ ISRLEN<br />

BRA ISRDONE<br />

*-------------------------------------------------------------<br />

* write command: transfer length byte<br />

*-------------------------------------------------------------<br />

ISRWLEN LDX POINTER * Retrieve<br />

current index<br />

LDAA 0,X * Get<br />

length<br />

STAA LENGTH * Store length<br />

STAA SPDR * Start<br />

the transfer <strong>of</strong> the length<br />

WLWAIT LDAA SPSR * Wait for<br />

the transfer...<br />

BPL WLWAIT ...to finish<br />

LDAA #ISRX * Change<br />

the mode...<br />

STAA MODE ...to transmitting data<br />

INX<br />

STX POINTER<br />

BRA ISRDONE<br />

*--------------------------------------------------------------<br />

* write command: transfer data<br />

*--------------------------------------------------------------<br />

ISRW LDAA LENGTH * Test for<br />

the interrupt...<br />

CMPA COUNT ...after the last byte<br />

BEQ ISROFF<br />

LDX POINTER * Retrieve the current<br />

index<br />

LDAA 0,X * Get the<br />

data<br />

STAA SPDR * Start<br />

the transfer <strong>of</strong> the data<br />

INC COUNT *<br />

Increment number <strong>of</strong> data sent<br />

INX *<br />

Advance the index pointer<br />

STX POINTER<br />

WWAIT LDAA SPSR * Wait for the transfer...<br />

BPL WWAIT ...to finish<br />

BRA ISRDONE<br />

*--------------------------------------------------------------<br />

* read command: get the length byte<br />

*--------------------------------------------------------------<br />

ISRLEN LDAA #0 * Start the transfer with<br />

a...<br />

STAA SPDR ...dummy input <strong>of</strong> 0<br />

LWAIT LDAA SPSR * Wait for the transfer...<br />

BPL LWAIT ...to finish<br />

LDAA SPDR * Get the<br />

length value...<br />

STAA LENGTH ...and store it<br />

LDX POINTR2 * Get the store index<br />

pointer...<br />

STAA 0,X ...and<br />

store it<br />

INX *<br />

Advance the pointer<br />

STX POINTR2<br />

- 46 -<br />

LDAA #ISRRCV * Change the mode...<br />

STAA MODE ...to receiving data<br />

BRA ISRDONE<br />

* If you have read this please underline.<br />

*---------------------------------------------------------------<br />

* read command: get data and wait for interrupt after last<br />

byte<br />

*---------------------------------------------------------------<br />

ISRR LDAA LENGTH * Test for the interrupt...<br />

CMPA COUNT ...after the last byte<br />

BEQ ISROFF<br />

LDAA #0 * Start<br />

the transfer with a...<br />

STAA SPDR ...dummy input <strong>of</strong> 0<br />

RWAIT LDAA SPSR * Wait for the transfer...<br />

BPL RWAIT ...to finish<br />

LDX POINTR2 * Get the store index<br />

pointer<br />

LDAA SPDR * Get the<br />

data<br />

STAA 0,X * Store<br />

the data<br />

INX *<br />

Advance the store index pointer<br />

STX POINTR2<br />

INC COUNT *<br />

Increment the data count<br />

BRA ISRDONE<br />

*----------------------------------------------------------------<br />

ISROFF LDAA #ISRIDLE<br />

STAA MODE<br />

SEI<br />

ISRDONE PULX<br />

PULB<br />

PULA<br />

RTRN RTI * return<br />

from interrupt<br />

*****************************************************************<br />

**<br />

*--------------------------------------------------------------------<br />

* WRITE SUBROUTINE<br />

*--------------------------------------------------------------------<br />

WRITES LDAA MODE<br />

LDX POINTER<br />

LDAB 0,X * get the<br />

next byte<br />

STAB SPDR * start the<br />

SPI transfer<br />

INC COUNT<br />

* wait for the transfer to finish<br />

WRWAIT LDAA SPSR<br />

BPL WRWAIT<br />

INX<br />

STX POINTER<br />

RTS<br />

*--------------------------------------------------------------------<br />

* READ SUBROUTINE<br />

*--------------------------------------------------------------------<br />

* load dummy byte to start xfers<br />

READS LDAA #$00<br />

STAA SPDR<br />

* wait for spif (when xfer complete)<br />

ISRWAIT LDAA SPSR

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!