public Bitbuffer TPI_constructsendmessage(byte b) { Bitbuffer buf = new Bitbuffer(); buf.enqueuebit(0); // ST buf.enqueuebyte_LSBfirst(b); // D0..D7 buf.enqueuebit(buf.parity(b)); // P buf.enqueuebit(1); // SP1 buf.enqueuebit(2); // SP2 return(buf); }
public byte TPI_receivebyte_skipIDLE() { D_HIGH(); //flush(); Bitbuffer buf = receivebits(_TPIidlebits + 12); buf.discardUntil0(); int countbits = 0; while (buf.length < 12) { System.Diagnostics.Debug.Print("TPI_receivebyte_skipIDLE: Have to read more bits..."); countbits += 12 - buf.length; Bitbuffer buf2 = receivebits(12 - buf.length); for (int i = 0; i < buf2.length; i++) { buf.enqueuebit(buf2[i]); } buf.discardUntil0(); if (countbits > 128 + 2 + 50) { System.Diagnostics.Debug.Print("TPI_receivebyte_skipIDLE: Too many IDLE bits"); throw new System.Exception("Target: Too many IDLE bits. Target is not responding."); } } buf.dequeuebit(); // ST byte result = buf.dequeuebyte_LSBfirst(); //buf.dequeuebit(); // P //buf.dequeuebit(); // SP1 //buf.dequeuebit(); // SP2 return(result); }
public void TPI_BREAK() { Bitbuffer buf = new Bitbuffer(); for (int i = 0; i < 12; i++) { buf.enqueuebit(1); } sendbits(buf); }
public void TPI_IDLE(int numidlebits) { Bitbuffer buf = new Bitbuffer(); for (int i = 0; i < numidlebits; i++) { buf.enqueuebit(1); } sendbits(buf); }
public Bitbuffer receivebits(int numbits) { #if true int bytes = (int)Math.Ceiling(numbits / 8.0); byte[] rawdat = receivedata(new byte[bytes], numbits); return(new Bitbuffer(rawdat, numbits)); #else Bitbuffer data = new Bitbuffer(); for (int i = 0; i < len; i++) { C_LOW(); flush(); C_HIGH(); flush(); data.enqueuebit(Q_READ()); } return(data); #endif }
public byte TPI_receivebyte() { D_HIGH(); //flush(); Bitbuffer buf = receivebits(12); buf.discardUntil0(); while (buf.length < 12) { Bitbuffer buf2 = receivebits(12 - buf.length); for (int i = 0; i < buf2.length; i++) { buf.enqueuebit(buf2[i]); } buf.discardUntil0(); } buf.dequeuebit(); // ST byte result = buf.dequeuebyte_LSBfirst(); //buf.dequeuebit(); // P //buf.dequeuebit(); // SP1 //buf.dequeuebit(); // SP2 return(result); }
public override void PageWrite(int address, byte[] bs, bool fastWrite) // 64 bytes in a page { condition_START(); WRITE(); bool isACK = true; if (fastWrite) { skipACK(); } else { isACK = isAcknowledged(); // recv ACK } senddata(new byte[] { (byte)(address >> 8) }); if (fastWrite) { skipACK(); } else { isACK = isAcknowledged(); // recv ACK } senddata(new byte[] { (byte)(address & 255) }); if (fastWrite) { skipACK(); } else { isACK = isAcknowledged(); // recv ACK } if (fastWrite) { Bitbuffer buf = new Bitbuffer(); foreach (byte b in bs) { buf.enqueuebyte_MSBfirst(b); // send byte buf.enqueuebit(1); // skip ACK } sendbits(buf); } else { foreach (byte b in bs) { senddata(new byte[] { b }); if (fastWrite) { skipACK(); } else { isACK = isAcknowledged(); // recv ACK } } } condition_STOP(); if (fastWrite) { System.Threading.Thread.Sleep(4); // write time = 5ms } else { WaitBusy(); } condition_STOP(); }