using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using System.Threading;
namespace PolyNCBeta {
public static class Wiznet5100 {
static OutputPort reset = new OutputPort((Cpu.Pin)FEZCerbuino.Pin.Digital.D9, true);
static InterruptPort interrupt = new InterruptPort((Cpu.Pin)FEZCerbuino.Pin.Digital.D8, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeLevelLow);
static SPI.Configuration config = new SPI.Configuration((Cpu.Pin)FEZCerbuino.Pin.Digital.D10,
false, // Chip Select, active-low
1, // 1 millisecond setup time
1, // 1 millisecond hold time
true, // Clock low on idle
true, // Data valid on falling edge
625, // 5Mhz Clock Rate
SPI.SPI_module.SPI1);
static SPI port = new SPI(config);
static byte[] commonBuffer = new byte[]{
0x00, //Mode Register: index 0, 4 bytes long
0x00,
0x00,
0x00,
0x00, //Gateway Address: index 4: 7 bytes long
0x00,
0x01,
0x00, // IP starts at index 7
0x00,
0x00,
0x00
};
const int GATEWAY_ADDRESS = 4;
public static byte[] Gateway{
get {
Read(GATEWAY_ADDRESS, 7);
return new byte[]{ commonBuffer[GATEWAY_ADDRESS + 3],
commonBuffer[GATEWAY_ADDRESS + 4],
commonBuffer[GATEWAY_ADDRESS + 5],
commonBuffer[GATEWAY_ADDRESS + 6]};
}
set{
value.CopyTo(commonBuffer, GATEWAY_ADDRESS + 3);
Write(GATEWAY_ADDRESS, 7);
}
}
public static void Reset() {
reset.Write(false);
Thread.Sleep(10);
reset.Write(true);
}
static void Write(int fromOffset, int length){
commonBuffer[fromOffset] = 0xF0;
port.WriteRead(commonBuffer, fromOffset, length, new byte[0], 0, 0, 0);
}
static void Read(int fromOffset, int length) {
commonBuffer[fromOffset] = 0x0F;
port.WriteRead(commonBuffer, fromOffset, length, commonBuffer, fromOffset + 3, length - 3, 3);
}
}
}
The beginnings of craziness. Just to clarify that last value in the WriteRead: startReadOffset :- The offset in time, measured in transacted elements from writeBuffer, when to start reading back data into readBuffer. This means that the system will only start putting values into the read buffer AFTER a certain number of write buffer values have been sent; Is that correct?