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 />

#define WTIX 0x0f /* NPDU_Field Write with Index */<br />

#define WRS46 0x46 /* DLL_Access_Control Write */<br />

#define RRS4 0x84 /* DLL_Rc_Link_Status Read */<br />

/*<br />

* Access control flags<br />

*/<br />

#define ENABLE_AUTO_RETRY 0x80 /* bit in NIC<br />

DLL_Access_Control structure */<br />

#define ENABLE_IMMEDIATE_RETRY 0x40<br />

#define ADRUNACK_TRIES_4 0x02<br />

#define DELAY_100MS 0x10<br />

#define DELAY_200MS 0x20<br />

#define DELAY_300MS 0x30<br />

/*<br />

* ServiceISR transmit/receive state machine states<br />

*/<br />

#define ISR_IDLE 0<br />

#define ISR_XMIT_LEN 1<br />

#define ISR_XMIT_BUF 2<br />

#define ISR_RCV_LEN 3<br />

#define ISR_RCV_BUF 4<br />

#define ISR_ATTN 5<br />

#define packetReceived (LL.b2)<br />

#define rawPacketReceived (LL.b3)<br />

#define receivePacketPending (LL.b4)<br />

#define receiveHeaderPending (LL.b5)<br />

void ReadCommand (uint8 command, @near uint8*<br />

rawData, uint8* length);<br />

void WriteCommand(uint8 command, @near uint8*<br />

rawData, uint8 length);<br />

uint8 basicTransmitStatus;<br />

uint8 ISRstate;<br />

TRANS_BFR transBfr;<br />

boolean delayTimerRunning;<br />

uint8 delayTimer;<br />

boolean UseWTI;<br />

uint8 NICtype;<br />

uint8 GetNICtype ( void )<br />

{<br />

/*<br />

* ID values in "status read" info from NIC<br />

*/<br />

#define P200_ID 0x03<br />

#define P300_ID 0x04<br />

#define ID_MASK 0x0f<br />

uint8 statusStore[6]; /* for "status read" info */<br />

uint8 len; /* length <strong>of</strong> expected data */<br />

/*<br />

** execute "status read" command and set NICtype<br />

accordingly<br />

*/<br />

ReadCommand(SR,statusStore,&len);<br />

NICtype = UNKNOWN_NIC;<br />

statusStore[5] &= ID_MASK;<br />

if(statusStore[5] & P300_ID)<br />

NICtype = P300;<br />

return NICtype;<br />

}<br />

uint8 InitializeLL ( void )<br />

{<br />

uint8 save[2]; /* local store */<br />

/*<br />

* initialize flags<br />

*/<br />

- 58 -<br />

UseDelay = FALSE;<br />

delayTimerRunning = FALSE;<br />

UseWTI = FALSE;<br />

/*<br />

* write current "config" to NIC<br />

*/<br />

WriteCommand(LW,&config.modeByte,size<strong>of</strong>(CONFIG));<br />

/*<br />

* ignore extended service CEBus packets<br />

*/<br />

save[0] = 0;<br />

save[1] = IGNORE_EXTENDED;<br />

WriteCommand(CW,save,2);<br />

save[0] = ENABLE_AUTO_RETRY |<br />

ENABLE_IMMEDIATE_RETRY | ADRUNACK_TRIES_4;<br />

WriteCommand(WRS46,save,1);<br />

/*<br />

* Initialize logical link semaphores/flags<br />

*/<br />

basicTransmitStatus = IDLE;<br />

TxBfrAvailable = TRUE;<br />

RxBfrAvailable = TRUE;<br />

receivePacketPending = FALSE;<br />

receiveHeaderPending = FALSE;<br />

packetReceived = FALSE;<br />

rawPacketReceived = FALSE;<br />

return TRUE;<br />

}<br />

boolean ReceivePacket ( void )<br />

{<br />

if(packetReceived) {<br />

packetReceived = FALSE;<br />

return TRUE;<br />

} else {<br />

return FALSE;<br />

}<br />

}<br />

boolean ReceiveRawPacket ( void )<br />

{<br />

if(rawPacketReceived) {<br />

rawPacketReceived = FALSE;<br />

return TRUE;<br />

} else {<br />

return FALSE;<br />

}<br />

}<br />

interrupt void ServiceISR( void )<br />

{<br />

/*<br />

switch(ISRstate) {<br />

case ISR_XMIT_LEN:<br />

SPDR = transBfr.len;<br />

while(!spif) ; /* wait for transfer complete */<br />

ISRstate = ISR_XMIT_BUF; /* change state */<br />

break;<br />

case ISR_XMIT_BUF:<br />

if(transBfr.index == transBfr.len) {<br />

ISRstate = ISR_IDLE; /* done */<br />

} else {<br />

SPDR = transBfr.buf[transBfr.index];<br />

transBfr.index++;<br />

while(!spif) ; /* wait for transfer complete */

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

Saved successfully!

Ooh no, something went wrong!