Example #1
0
        public void ReadTestMemory()
        {
            byte[] upload_buffer = new byte[KONST.UploadBufferSize];

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

            prepTestMem();

            do
            {
                //Pk2.RunScriptUploadNoLen2(KONST.TESTMEM_RD, scriptRunsToFillUpload);
                Pk2.RunScriptUploadNoLen(KONST.TESTMEM_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;
                    }
                    TestMemory[wordsRead++] = memWord;
                }
            } while (wordsRead < FormPICkit2.TestMemoryWords);

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