private async Task EraseSpecial(STEraseMode mode)
{
/* command word */
var tx = new byte[4];
/* temporary storage for response bytes */
var tmp = new byte[1];
/* command code */
tx[0] = (byte)STCmds.ERASE;
/* checksum */
tx[1] = ComputeChecksum(tx, 0, 1);
/* erase single page */
tx[2] = (byte)((int)mode);
/* checksum */
tx[3] = (byte)~ComputeChecksum(tx, 2, 2);
/* try to send command and wait for response */
try {
/* send bytes */
await SerialWrite(tx, 0, 2);
/* wait for response code */
await SerialRead(tmp, 0, 1);
/* check response code */
if (tmp[0] != (byte)STResps.ACK)
throw new STBootException("Command Rejected");
/* send address */
await SerialWrite(tx, 2, 2);
/* wait for response code */
await SerialRead(tmp, 0, 1);
/* check response code */
if (tmp[0] != (byte)STResps.ACK)
throw new STBootException("Special Code Rejected");
/* oops, something baaad happened! */
} catch (Exception) {
/* release semaphore */
sem.Release();
/* re-throw */
throw;
}
/* release semaphore */
sem.Release();
}