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

if (errno == 11) {<br />

fprintf (stdout, "this error ok, data not there yet.<br />

implementation for retries / timeout not done!\n");<br />

exit(1);<br />

}<br />

else {<br />

fprintf (stdout, "read error!\tbytes read: %d\terrno:<br />

%d\n", cnt, errno);<br />

}<br />

}<br />

printf("receive: -%p-\n", recvbuf);<br />

/*<br />

* delay to prevent overruns, will have to be<br />

implemented with ack - checking OR flag in hc11<br />

*/<br />

for(i = 0; i < 500000; i++)<br />

;<br />

/*sleep(1);*/<br />

}<br />

}<br />

/*<br />

* Original Author: Stan JK<br />

*<br />

* Modified by: Tony Truong<br />

*<br />

* File: mod_main.c<br />

*/<br />

#define _mod_main_owner<br />

#include "standard.h"<br />

void main( void )<br />

{<br />

DisableInterrupts();<br />

ResetStackPtr();<br />

/*<br />

* initialize all ports, set all directions as inputs and<br />

* clear all control registers<br />

*/<br />

PORTB = 0xff;<br />

PORTC = 0;<br />

PORTD = 0x20; /* keep SS* <strong>of</strong>f */<br />

DDRA = 0;<br />

DDRB = 0;<br />

DDRC = 0;<br />

DDRD = 0;<br />

SPCR = 0;<br />

SCCR1 = 0;<br />

SCCR2 = 0;<br />

RST = LOW;<br />

COPCR = 0; /* Disable watchdog */<br />

DDRC = PORTCdirection;<br />

DDRD = PORTDdirection;<br />

/*<br />

* set master mode<br />

* set SCK polarity at logic 1<br />

* set SCK phase to edge after 1 st to latch<br />

* set SPI clock rate<br />

* and enable SPI<br />

*/<br />

SPCR = MSTR | CPOL | CPHA | SPR | SPE;<br />

NIC_CS = HIGH;<br />

EEROM_CS = HIGH;<br />

RST = HIGH;<br />

- 51 -<br />

/*<br />

* wait for NIC to complete its internal reset<br />

* wait for approx 51.2 msec.<br />

*/<br />

*i = GetLowResTimeByte() + 100;<br />

while(*i != GetLowResTimeByte()) ;<br />

/*<br />

* Initialize utilities/layers and execute application:<br />

*/<br />

InitializeTimer();<br />

EnableInterrupts();<br />

InitializeSerial();<br />

/*<br />

* wait for initailize to compete<br />

*/<br />

if(InitializeEval()) {<br />

While(1)<br />

UpdateEval();<br />

}<br />

}<br />

/*<br />

* Original Author: Stan JK<br />

*<br />

* Modified and adapted for the MCHC11A1 by: Tony<br />

Truong<br />

*<br />

* File: evaluate.c<br />

*/<br />

#include "standard.h"<br />

/*<br />

* transmitter device to RS232 host command functionIDs<br />

*/<br />

#define ABORT_CMD ('A')<br />

#define DELAY_CMD ('D')<br />

#define NIC_ID_CMD ('N')<br />

#define PROGRESS_CMD ('P')<br />

#define QUERY_CMD ('Q')<br />

#define RUNNING_CMD ('R')<br />

#define STATS_CMD ('S')<br />

#define TRANS_START_CMD ('T')<br />

/*<br />

* transmitter device to remote device info field headers<br />

*/<br />

#define SETUP_PKT 0x01<br />

#define LOOPBACK_PKT 0x02<br />

#define COUNT_RESP_PKT 0x03<br />

#define RESET_COUNT 0x04<br />

#define GET_COUNT_PKT 0x05<br />

#define TRANS_PKT 0x0f<br />

/*<br />

* timer value based on 131msec/tick<br />

*/<br />

#define TWO_SECS 14<br />

void RecdRunningCmd(void);<br />

void RecdSetupPkt(void);<br />

void XmitOriginal(void);<br />

void StatsToHost(boolean recdPkts);<br />

boolean ProcessTransmitEnd(boolean forced);<br />

void ProcessValidPacket(void);<br />

booleans EV;<br />

booleans EV2;

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

Saved successfully!

Ooh no, something went wrong!