Пример #1
0
 public static void ResetBuffers()
 {
     DeviceBuffers = new DeviceData(DevFile.PartsList[ActivePart].ProgramMem,
                                     DevFile.PartsList[ActivePart].EEMem,
                                     DevFile.PartsList[ActivePart].ConfigWords,
                                     DevFile.PartsList[ActivePart].UserIDWords,
                                     DevFile.Families[GetActiveFamily()].BlankValue,
                                     DevFile.Families[GetActiveFamily()].EEMemAddressIncrement,
                                     DevFile.Families[GetActiveFamily()].UserIDBytes,
                                     DevFile.PartsList[ActivePart].ConfigBlank,
                                     DevFile.PartsList[ActivePart].ConfigMasks[KONST.OSCCAL_MASK]);
 }
Пример #2
0
        public static DeviceData CloneBuffers(DeviceData copyFrom)
        {
            DeviceData newBuffers = new DeviceData(DevFile.PartsList[ActivePart].ProgramMem,
                                            DevFile.PartsList[ActivePart].EEMem,
                                            DevFile.PartsList[ActivePart].ConfigWords,
                                            DevFile.PartsList[ActivePart].UserIDWords,
                                            DevFile.Families[GetActiveFamily()].BlankValue,
                                            DevFile.Families[GetActiveFamily()].EEMemAddressIncrement,
                                            DevFile.Families[GetActiveFamily()].UserIDBytes,
                                            DevFile.PartsList[ActivePart].ConfigBlank,
                                            DevFile.PartsList[ActivePart].ConfigMasks[KONST.OSCCAL_MASK]);

            // clone all the data
            for (int i = 0; i < copyFrom.ProgramMemory.Length; i++)
            {
                newBuffers.ProgramMemory[i] = copyFrom.ProgramMemory[i];
            }
            for (int i = 0; i < copyFrom.EEPromMemory.Length; i++)
            {
                newBuffers.EEPromMemory[i] = copyFrom.EEPromMemory[i];
            }
            for (int i = 0; i < copyFrom.ConfigWords.Length; i++)
            {
                newBuffers.ConfigWords[i] = copyFrom.ConfigWords[i];
            }
            for (int i = 0; i < copyFrom.UserIDs.Length; i++)
            {
                newBuffers.UserIDs[i] = copyFrom.UserIDs[i];
            }
            newBuffers.OSCCAL = copyFrom.OSCCAL;
            newBuffers.OSCCAL = copyFrom.BandGap;

            return newBuffers;
        }
Пример #3
0
        private bool blankCheckDevice()
        {
            if (Pk2.FamilyIsKeeloq() || Pk2.FamilyIsMCP())
            {
                displayStatusWindow.Text = "Blank Check not supported for this device type.";
                statusWindowColor = Constants.StatusColor.yellow;
                updateGUI(KONST.DontUpdateMemDisplays);
                return false; // abort
            }

            if (!preProgrammingCheck(Pk2.GetActiveFamily()))
            {
                return false; // abort
            }

            if (Pk2.FamilyIsPIC32())
            {
                if (P32.PIC32BlankCheck())
                {
                    statusWindowColor = Constants.StatusColor.green;
                    conditionalVDDOff();
                    updateGUI(KONST.UpdateMemoryDisplays);
                    return true;
                }
                else
                {
                    statusWindowColor = Constants.StatusColor.red;
                    conditionalVDDOff();
                    updateGUI(KONST.UpdateMemoryDisplays);
                    return true;
                }
            }

            DeviceData blankDevice = new DeviceData(Pk2.DevFile.PartsList[Pk2.ActivePart].ProgramMem,
                Pk2.DevFile.PartsList[Pk2.ActivePart].EEMem,
                Pk2.DevFile.PartsList[Pk2.ActivePart].ConfigWords,
                Pk2.DevFile.PartsList[Pk2.ActivePart].UserIDWords,
                Pk2.DevFile.Families[Pk2.GetActiveFamily()].BlankValue,
                Pk2.DevFile.Families[Pk2.GetActiveFamily()].EEMemAddressIncrement,
                Pk2.DevFile.Families[Pk2.GetActiveFamily()].UserIDBytes,
                Pk2.DevFile.PartsList[Pk2.ActivePart].ConfigBlank,
                Pk2.DevFile.PartsList[Pk2.ActivePart].ConfigMasks[KONST.OSCCAL_MASK]);

            // handle situation where configs are in program memory.
            int configLocation = (int)Pk2.DevFile.PartsList[Pk2.ActivePart].ConfigAddr /
                Pk2.DevFile.Families[Pk2.GetActiveFamily()].ProgMemHexBytes;
            int configWords = Pk2.DevFile.PartsList[Pk2.ActivePart].ConfigWords;
            if (configLocation < Pk2.DevFile.PartsList[Pk2.ActivePart].ProgramMem)
                for (int i = 0; i < configWords; i++)
                {
                    uint template = blankDevice.ProgramMemory[configLocation + i] & 0xFFFF0000;
                    if (Pk2.DevFile.Families[Pk2.GetActiveFamily()].BlankValue == 0xFFFF)
                    {
                        template |= 0xF000;
                    }
                    blankDevice.ProgramMemory[configLocation + i] =
                            (template | Pk2.DevFile.PartsList[Pk2.ActivePart].ConfigBlank[i]);
                }

            displayStatusWindow.Text = "Checking if Device is blank:\n";
            //displayStatusWindow.Update();
            this.Update();

            Pk2.SetMCLRTemp(true);     // assert /MCLR to prevent code execution before programming mode entered.
            Pk2.VddOn();

            byte[] upload_buffer = new byte[KONST.UploadBufferSize];

            //Check Program Memory ----------------------------------------------------------------------------
            displayStatusWindow.Text += "Program Memory... ";
            //displayStatusWindow.Update();
            this.Update();

            if (useProgExec33())
            {
                if (!PE33.PE33BlankCheck(displayStatusWindow.Text))
                {
                    conditionalVDDOff();
                    displayStatusWindow.Text = "Program Memory is not blank.";
                    statusWindowColor = Constants.StatusColor.red;
                    updateGUI(KONST.UpdateMemoryDisplays);
                    return false;
                }
            }
            else if (useProgExec24F())
            {
                if (!PE24.PE24FBlankCheck(displayStatusWindow.Text))
                {
                    conditionalVDDOff();
                    statusWindowColor = Constants.StatusColor.red;
                    updateGUI(KONST.UpdateMemoryDisplays);
                    return false;
                }
            }
            else
            {
                Pk2.RunScript(KONST.PROG_ENTRY, 1);

                if ((Pk2.DevFile.PartsList[Pk2.ActivePart].ProgMemAddrSetScript != 0)
                        && (Pk2.DevFile.PartsList[Pk2.ActivePart].ProgMemAddrBytes != 0))
                { // if prog mem address set script exists for this part
                    if (Pk2.FamilyIsEEPROM())
                    {
                        Pk2.DownloadAddress3MSBFirst(eeprom24BitAddress(0, KONST.WRITE_BIT));
                        Pk2.RunScript(KONST.PROGMEM_ADDRSET, 1);
                        if (eeprom_CheckBusErrors())
                        {
                            return false;
                        }
                    }
                    else
                    {
                        Pk2.DownloadAddress3(0);
                        Pk2.RunScript(KONST.PROGMEM_ADDRSET, 1);
                    }
                }

                int bytesPerWord = Pk2.DevFile.Families[Pk2.GetActiveFamily()].BytesPerLocation;
                int scriptRunsToFillUpload = KONST.UploadBufferSize /
                    (Pk2.DevFile.PartsList[Pk2.ActivePart].ProgMemRdWords * bytesPerWord);
                int wordsPerLoop = scriptRunsToFillUpload * Pk2.DevFile.PartsList[Pk2.ActivePart].ProgMemRdWords;
                int wordsRead = 0;

                progressBar1.Value = 0;     // reset bar
                progressBar1.Maximum = (int)Pk2.DevFile.PartsList[Pk2.ActivePart].ProgramMem / wordsPerLoop;

                do
                {
                    if (Pk2.FamilyIsEEPROM())
                    {
                        if ((Pk2.DevFile.PartsList[Pk2.ActivePart].ConfigMasks[KONST.PROTOCOL_CFG] == KONST.I2C_BUS)
                            && (wordsRead > Pk2.DevFile.PartsList[Pk2.ActivePart].ConfigMasks[KONST.ADR_MASK_CFG])
                            && (wordsRead % (Pk2.DevFile.PartsList[Pk2.ActivePart].ConfigMasks[KONST.ADR_MASK_CFG] + 1) == 0))
                        {
                            Pk2.DownloadAddress3MSBFirst(eeprom24BitAddress(wordsRead, KONST.WRITE_BIT));
                            Pk2.RunScript(KONST.PROGMEM_ADDRSET, 1);
                        }
                        Pk2.Download3Multiples(eeprom24BitAddress(wordsRead, KONST.READ_BIT), scriptRunsToFillUpload,
                                    Pk2.DevFile.PartsList[Pk2.ActivePart].ProgMemRdWords);
                    }
                    //Pk2.RunScriptUploadNoLen2(KONST.PROGMEM_RD, scriptRunsToFillUpload);
                    Pk2.RunScriptUploadNoLen(KONST.PROGMEM_RD, scriptRunsToFillUpload);
                    Array.Copy(Pk2.Usb_read_array, 1, upload_buffer, 0, KONST.USB_REPORTLENGTH);
                    //Pk2.GetUpload();
                    Pk2.UploadDataNoLen();
                    Array.Copy(Pk2.Usb_read_array, 1, upload_buffer, KONST.USB_REPORTLENGTH, KONST.USB_REPORTLENGTH);
                    int uploadIndex = 0;
                    for (int word = 0; word < wordsPerLoop; word++)
                    {
                        int bite = 0;
                        uint memWord = (uint)upload_buffer[uploadIndex + bite++];
                        if (bite < bytesPerWord)
                        {
                            memWord |= (uint)upload_buffer[uploadIndex + bite++] << 8;
                        }
                        if (bite < bytesPerWord)
                        {
                            memWord |= (uint)upload_buffer[uploadIndex + bite++] << 16;
                        }
                        if (bite < bytesPerWord)
                        {
                            memWord |= (uint)upload_buffer[uploadIndex + bite++] << 24;
                        }
                        uploadIndex += bite;
                        // shift if necessary
                        if (Pk2.DevFile.Families[Pk2.GetActiveFamily()].ProgMemShift > 0)
                        {
                            memWord = (memWord >> 1) & Pk2.DevFile.Families[Pk2.GetActiveFamily()].BlankValue;
                        }

                        // if OSCCAL save, force last word to be blank
                        if ((Pk2.DevFile.PartsList[Pk2.ActivePart].OSSCALSave)
                                && wordsRead == (Pk2.DevFile.PartsList[Pk2.ActivePart].ProgramMem - 1))
                        {
                            memWord = Pk2.DevFile.Families[Pk2.GetActiveFamily()].BlankValue;
                        }
                        if (memWord != blankDevice.ProgramMemory[wordsRead++])
                        {
                            Pk2.RunScript(KONST.PROG_EXIT, 1);
                            conditionalVDDOff();
                            if (Pk2.FamilyIsEEPROM())
                            {
                                displayStatusWindow.Text = "EEPROM is not blank starting at address\n";
                            }
                            else
                            {
                                displayStatusWindow.Text = "Program Memory is not blank starting at address\n";
                            }
                            displayStatusWindow.Text += string.Format("0x{0:X6}",
                                (--wordsRead * Pk2.DevFile.Families[Pk2.GetActiveFamily()].AddressIncrement));
                            statusWindowColor = Constants.StatusColor.red;
                            updateGUI(KONST.UpdateMemoryDisplays);
                            return false;
                        }

                        if (wordsRead == Pk2.DevFile.PartsList[Pk2.ActivePart].ProgramMem)
                        {
                            break; // for cases where ProgramMemSize%WordsPerLoop != 0
                        }
                        if (((wordsRead % 0x8000) == 0)
                                && (Pk2.DevFile.PartsList[Pk2.ActivePart].ProgMemAddrSetScript != 0)
                                && (Pk2.DevFile.PartsList[Pk2.ActivePart].ProgMemAddrBytes != 0)
                                && (Pk2.DevFile.Families[Pk2.GetActiveFamily()].BlankValue > 0xFFFF))
                        { //PIC24 must update TBLPAG
                            Pk2.DownloadAddress3(0x10000 * (wordsRead / 0x8000));
                            Pk2.RunScript(KONST.PROGMEM_ADDRSET, 1);
                            break;
                        }
                    }
                    progressBar1.PerformStep();
                } while (wordsRead < Pk2.DevFile.PartsList[Pk2.ActivePart].ProgramMem);
                Pk2.RunScript(KONST.PROG_EXIT, 1);
            }

            //Check EEPROM ------------------------------------------------------------------------------------
            if (Pk2.DevFile.PartsList[Pk2.ActivePart].EEMem > 0)
            {
                displayStatusWindow.Text += "EE... ";
                this.Update();
                Pk2.RunScript(KONST.PROG_ENTRY, 1);

                if (Pk2.DevFile.PartsList[Pk2.ActivePart].EERdPrepScript > 0)
                {
                    if (Pk2.DevFile.Families[Pk2.GetActiveFamily()].EEMemHexBytes == 4)
                    { // 16-bit parts
                        Pk2.DownloadAddress3((int)(Pk2.DevFile.PartsList[Pk2.ActivePart].EEAddr / 2));
                    }
                    else
                    {
                        Pk2.DownloadAddress3(0);
                    }
                    Pk2.RunScript(KONST.EE_RD_PREP, 1);
                }

                int bytesPerLoc = Pk2.DevFile.Families[Pk2.GetActiveFamily()].EEMemBytesPerWord;
                uint eeBlank = getEEBlank();
                int scriptRuns2FillUpload = KONST.UploadBufferSize /
                    (Pk2.DevFile.PartsList[Pk2.ActivePart].EERdLocations * bytesPerLoc);
                int locPerLoop = scriptRuns2FillUpload * Pk2.DevFile.PartsList[Pk2.ActivePart].EERdLocations;
                int locsRead = 0;

                progressBar1.Value = 0;     // reset bar
                progressBar1.Maximum = (int)Pk2.DevFile.PartsList[Pk2.ActivePart].EEMem / locPerLoop;
                do
                {
                    //Pk2.RunScriptUploadNoLen2(KONST.EE_RD, scriptRuns2FillUpload);
                    Pk2.RunScriptUploadNoLen(KONST.EE_RD, scriptRuns2FillUpload);
                    Array.Copy(Pk2.Usb_read_array, 1, upload_buffer, 0, KONST.USB_REPORTLENGTH);
                    //Pk2.GetUpload();
                    Pk2.UploadDataNoLen();
                    Array.Copy(Pk2.Usb_read_array, 1, upload_buffer, KONST.USB_REPORTLENGTH, KONST.USB_REPORTLENGTH);
                    int uploadIndex = 0;
                    for (int word = 0; word < locPerLoop; word++)
                    {
                        int bite = 0;
                        uint memWord = (uint)upload_buffer[uploadIndex + bite++];
                        if (bite < bytesPerLoc)
                        {
                            memWord |= (uint)upload_buffer[uploadIndex + bite++] << 8;
                        }
                        uploadIndex += bite;
                        // shift if necessary
                        if (Pk2.DevFile.Families[Pk2.GetActiveFamily()].ProgMemShift > 0)
                        {
                            memWord = (memWord >> 1) & eeBlank;
                        }
                        locsRead++;
                        if (memWord != eeBlank)
                        {
                            Pk2.RunScript(KONST.PROG_EXIT, 1);
                            conditionalVDDOff();
                            displayStatusWindow.Text = "EE Data Memory is not blank starting at address\n";
                            if (eeBlank == 0xFFFF)
                            {
                                displayStatusWindow.Text += string.Format("0x{0:X4}", (--locsRead * 2));
                            }
                            else
                            {
                                displayStatusWindow.Text += string.Format("0x{0:X4}", --locsRead);
                            }
                            statusWindowColor = Constants.StatusColor.red;
                            updateGUI(KONST.UpdateMemoryDisplays);
                            return false;
                        }
                        if (locsRead >= Pk2.DevFile.PartsList[Pk2.ActivePart].EEMem)
                        {
                            break; // for cases where ProgramMemSize%WordsPerLoop != 0
                        }
                    }
                    progressBar1.PerformStep();
                } while (locsRead < Pk2.DevFile.PartsList[Pk2.ActivePart].EEMem);
                Pk2.RunScript(KONST.PROG_EXIT, 1);
            }

            //Check User IDs ----------------------------------------------------------------------------------
            if ((Pk2.DevFile.PartsList[Pk2.ActivePart].UserIDWords > 0) &&
                !Pk2.DevFile.PartsList[Pk2.ActivePart].BlankCheckSkipUsrIDs)
            {
                displayStatusWindow.Text += "UserIDs... ";
                this.Update();
                Pk2.RunScript(KONST.PROG_ENTRY, 1);
                if (Pk2.DevFile.PartsList[Pk2.ActivePart].UserIDRdPrepScript > 0)
                {
                    Pk2.RunScript(KONST.USERID_RD_PREP, 1);
                }
                int bytesPerWord = Pk2.DevFile.Families[Pk2.GetActiveFamily()].UserIDBytes;
                int wordsRead = 0;
                int bufferIndex = 0;
                Pk2.RunScriptUploadNoLen(KONST.USERID_RD, 1);
                Array.Copy(Pk2.Usb_read_array, 1, upload_buffer, 0, KONST.USB_REPORTLENGTH);
                if ((Pk2.DevFile.PartsList[Pk2.ActivePart].UserIDWords * bytesPerWord) > KONST.USB_REPORTLENGTH)
                {
                    Pk2.UploadDataNoLen();
                    Array.Copy(Pk2.Usb_read_array, 1, upload_buffer, KONST.USB_REPORTLENGTH, KONST.USB_REPORTLENGTH);
                }
                Pk2.RunScript(KONST.PROG_EXIT, 1);
                do
                {
                    int bite = 0;
                    uint memWord = (uint)upload_buffer[bufferIndex + bite++];
                    if (bite < bytesPerWord)
                    {
                        memWord |= (uint)upload_buffer[bufferIndex + bite++] << 8;
                    }
                    if (bite < bytesPerWord)
                    {
                        memWord |= (uint)upload_buffer[bufferIndex + bite++] << 16;
                    }
                    if (bite < bytesPerWord)
                    {
                        memWord |= (uint)upload_buffer[bufferIndex + bite++] << 24;
                    }
                    bufferIndex += bite;
                    // shift if necessary
                    if (Pk2.DevFile.Families[Pk2.GetActiveFamily()].ProgMemShift > 0)
                    {
                        memWord = ((memWord >> 1) & Pk2.DevFile.Families[Pk2.GetActiveFamily()].BlankValue);
                    }
                    wordsRead++;
                    uint blank = Pk2.DevFile.Families[Pk2.GetActiveFamily()].BlankValue;
                    if (bytesPerWord == 1)
                    {
                        blank &= 0xFF;
                    }
                    if (memWord != blank)
                    {
                        conditionalVDDOff();
                        displayStatusWindow.Text = "User IDs are not blank.";
                        statusWindowColor = Constants.StatusColor.red;
                        updateGUI(KONST.UpdateMemoryDisplays);
                        return false;
                    }
                } while (wordsRead < Pk2.DevFile.PartsList[Pk2.ActivePart].UserIDWords);
            }

            // Blank Check Configuration --------------------------------------------------------------------
            if ((configWords > 0) && (configLocation > Pk2.DevFile.PartsList[Pk2.ActivePart].ProgramMem))
            { // Don't read config words for any part where they are stored in program memory.
                displayStatusWindow.Text += "Config... ";
                //displayStatusWindow.Update();
                this.Update();
                Pk2.RunScript(KONST.PROG_ENTRY, 1);
                Pk2.RunScript(KONST.CONFIG_RD, 1);
                Pk2.UploadData();
                Pk2.RunScript(KONST.PROG_EXIT, 1);
                int bufferIndex = 2;                    // report starts on index 1, which is #bytes uploaded.
                for (int word = 0; word < configWords; word++)
                {
                    uint config = (uint)Pk2.Usb_read_array[bufferIndex++];
                    config |= (uint)Pk2.Usb_read_array[bufferIndex++] << 8;
                    if (Pk2.DevFile.Families[Pk2.GetActiveFamily()].ProgMemShift > 0)
                    {
                        config = (config >> 1) & Pk2.DevFile.Families[Pk2.GetActiveFamily()].BlankValue;
                    }
                    config &= Pk2.DevFile.PartsList[Pk2.ActivePart].ConfigMasks[word];
                    int configBlank = Pk2.DevFile.PartsList[Pk2.ActivePart].ConfigMasks[word]
                                       & Pk2.DevFile.PartsList[Pk2.ActivePart].ConfigBlank[word];
                    if (configBlank != config)
                    {
                        conditionalVDDOff();
                        displayStatusWindow.Text = "Configuration is not blank.";
                        statusWindowColor = Constants.StatusColor.red;
                        updateGUI(KONST.UpdateMemoryDisplays);
                        return false;
                    }
                }
            }

            Pk2.RunScript(KONST.PROG_EXIT, 1);
            conditionalVDDOff();

            statusWindowColor = Constants.StatusColor.green;
            displayStatusWindow.Text = "Device is Blank.";

            updateGUI(KONST.UpdateMemoryDisplays);

            return true;
        }