Esempio n. 1
0
        private byte[] readCpuBlock(UInt16 address, int length, FlashAccessType flashType = FlashAccessType.Direct)
        {
            var buffer = new byte[4];

            buffer[0]   = (byte)(address & 0xFF);
            buffer[1]   = (byte)((address >> 8) & 0xFF);
            buffer[2]   = (byte)(length & 0xFF);
            buffer[3]   = (byte)((length >> 8) & 0xFF);
            cpuReadDone = false;
            switch (flashType)
            {
            case FlashAccessType.FirstFlash:
            case FlashAccessType.Direct:
                sendData(Command.COMMAND_PRG_READ_REQUEST, buffer);
                break;

            case FlashAccessType.CoolboyGPIO:
                sendData(Command.COMMAND_COOLBOY_READ_REQUEST, buffer);
                break;
            }
            for (int t = 0; t < Timeout; t += 5)
            {
                Thread.Sleep(5);
                if (cpuReadDone)
                {
                    return(prgRecvData);
                }
            }
            throw new IOException("Read timeout");
        }
Esempio n. 2
0
        public void ErasePrgFlash(FlashAccessType flashType)
        {
            switch (flashType)
            {
            case FlashAccessType.FirstFlash:
                sendData(Command.COMMAND_PRG_FLASH_ERASE_REQUEST, new byte[0]);
                break;

            case FlashAccessType.CoolboyGPIO:
                sendData(Command.COMMAND_COOLBOY_ERASE_REQUEST, new byte[0]);
                break;

            case FlashAccessType.Direct:
                sendData(Command.COMMAND_COOLGIRL_ERASE_SECTOR_REQUEST, new byte[0]);
                break;
            }
            cpuWriteDoneCounter = 0;
            for (int t = 0; t < Timeout; t += 5)
            {
                Thread.Sleep(5);
                if (cpuWriteDoneCounter != 0)
                {
                    return;
                }
            }
            throw new IOException("Write timeout");
        }
Esempio n. 3
0
        public byte[] ReadCpu(UInt16 address, int length, FlashAccessType flashType)
        {
            var result = new List <byte>();

            while (length > 0)
            {
                result.AddRange(readCpuBlock(address, Math.Min(MaxReadPacketSize, length), flashType));
                address += MaxReadPacketSize;
                length  -= MaxReadPacketSize;
            }
            return(result.ToArray());
        }
Esempio n. 4
0
        private void writePrgFlashBlock(UInt16 address, byte[] data, bool wait, FlashAccessType flashType)
        {
            int length = data.Length;
            var buffer = new byte[4 + length];

            buffer[0] = (byte)(address & 0xFF);
            buffer[1] = (byte)((address >> 8) & 0xFF);
            buffer[2] = (byte)(length & 0xFF);
            buffer[3] = (byte)((length >> 8) & 0xFF);
            Array.Copy(data, 0, buffer, 4, length);
            if (wait)
            {
                cpuWriteDoneCounter = 0;
            }
            switch (flashType)
            {
            case FlashAccessType.FirstFlash:
                sendData(Command.COMMAND_PRG_FLASH_WRITE_REQUEST, buffer);
                break;

            case FlashAccessType.CoolboyGPIO:
                sendData(Command.COMMAND_COOLBOY_WRITE_REQUEST, buffer);
                break;

            case FlashAccessType.Direct:
                sendData(Command.COMMAND_COOLGIRL_WRITE_REQUEST, buffer);
                break;
            }
            if (wait)
            {
                for (int t = 0; t < Timeout; t += 5)
                {
                    Thread.Sleep(5);
                    if (cpuWriteDoneCounter != 0)
                    {
                        return;
                    }
                }
                throw new IOException("Write timeout");
            }
        }
Esempio n. 5
0
        public void WritePrgFlash(UInt16 address, byte[] data, FlashAccessType flashType = FlashAccessType.FirstFlash, bool accelerated = false)
        {
            int wlength      = data.Length;
            int pos          = 0;
            int writeCounter = 0;

            cpuWriteDoneCounter = 0;
            while (wlength > 0)
            {
                var wdata = new byte[Math.Min(MaxWritePacketSize, wlength)];
                Array.Copy(data, pos, wdata, 0, wdata.Length);
                if (containsNotFF(data))
                {
                    writePrgFlashBlock(address, wdata, !accelerated, flashType);
                    writeCounter++;
                    if (accelerated)
                    {
                        Thread.Sleep(40);
                    }
                }
                address += MaxWritePacketSize;
                pos     += MaxWritePacketSize;
                wlength -= MaxWritePacketSize;
                //Console.WriteLine("{0} / {1}", writeCounter, prgWriteDoneCounter);
            }
            if (accelerated)
            {
                for (int t = 0; t < Timeout; t += 5)
                {
                    Thread.Sleep(5);
                    if (cpuWriteDoneCounter >= writeCounter)
                    {
                        return;
                    }
                }
                throw new IOException("Write timeout");
            }
        }