示例#1
0
        private static bool Clear_BL_Flash()
        {
            byte num = 0x40;

            for (int i = 0x2000; i < m_upper_fw_addr; i += num)
            {
                Thread.Sleep(m_bootloader_delay);
                if (!Bootloader.Clear_64_Bytes_of_Flash((ushort)i))
                {
                    return(false);
                }
            }
            return(true);
        }
示例#2
0
        public static bool Clear_BL_Flash()
        {
            bool result = true;
            byte b      = 64;

            for (int i = 8192; i < 32768; i += (int)b)
            {
                if (!Bootloader.Clear_64_Bytes_of_Flash((ushort)i))
                {
                    result = false;
                    break;
                }
            }
            return(result);
        }
示例#3
0
        private static bool Clear_BL_Flash()
        {
            bool result = true;
            byte b      = 64;

            for (int i = 8192; i < Firmware.m_upper_fw_addr; i += (int)b)
            {
                Thread.Sleep(Firmware.m_bootloader_delay);
                if (!Bootloader.Clear_64_Bytes_of_Flash((ushort)i))
                {
                    result = false;
                    break;
                }
            }
            return(result);
        }
示例#4
0
        private static bool Write_BL_Flash(ref byte[] p_data)
        {
            int  num  = 0;
            byte num2 = 0x20;

            byte[] buffer = new byte[num2];
            for (int i = 0x2000; i < m_upper_fw_addr; i += num2)
            {
                Thread.Sleep(m_bootloader_delay);
                for (int j = 0; j < num2; j++)
                {
                    buffer[j] = p_data[num++];
                }
                if (!Bootloader.Write_32_Bytes_to_Flash((ushort)i, ref buffer))
                {
                    return(false);
                }
            }
            return(true);
        }
示例#5
0
        public static bool Write_BL_Flash(ref byte[] p_data)
        {
            bool result = true;
            int  num    = 0;
            byte b      = 32;

            byte[] array = new byte[(int)b];
            for (int i = 8192; i < 32768; i += (int)b)
            {
                for (int j = 0; j < (int)b; j++)
                {
                    array[j] = p_data[num++];
                }
                if (!Bootloader.Write_32_Bytes_to_Flash((ushort)i, ref array))
                {
                    result = false;
                    break;
                }
            }
            return(result);
        }
示例#6
0
        private static bool Read_BL_Flash(ushort p_start_addr, int p_byte_count, ref byte[] p_data)
        {
            bool result = true;
            bool flag   = false;
            int  num    = 0;

            byte[] array = new byte[58];
            ushort num2  = p_start_addr;
            int    num3  = p_byte_count / 58;

            if (p_byte_count % 58 != 0)
            {
                flag = true;
                num3++;
            }
            for (int i = 0; i < num3; i++)
            {
                Thread.Sleep(Firmware.m_bootloader_delay);
                byte b;
                if (i == num3 - 1 && flag)
                {
                    b = (byte)(p_byte_count % 58);
                }
                else
                {
                    b = 58;
                }
                if (!Bootloader.Read_One_BL_Flash_USB_Packet(num2, b, ref array))
                {
                    result = false;
                    break;
                }
                for (int j = 0; j < (int)b; j++)
                {
                    p_data[num++] = array[j];
                }
                num2 += (ushort)b;
            }
            return(result);
        }
示例#7
0
        public static bool Read_BL_Flash(ushort p_start_addr, int p_byte_count, ref byte[] p_data)
        {
            bool result = true;
            bool flag   = false;
            int  num    = 0;

            byte[] array = new byte[32];
            ushort num2  = p_start_addr;
            int    num3  = p_byte_count / 32;

            if (p_byte_count % 32 != 0)
            {
                flag = true;
                num3++;
            }
            for (int i = 0; i < num3; i++)
            {
                byte b;
                if (i == num3 - 1 && flag)
                {
                    b = (byte)(p_byte_count % 32);
                }
                else
                {
                    b = 32;
                }
                if (!Bootloader.Read_One_BL_Flash_USB_Packet(num2, b, ref array))
                {
                    result = false;
                    break;
                }
                Thread.Sleep(15);
                for (int j = 0; j < (int)b; j++)
                {
                    p_data[num++] = array[j];
                }
                num2 += (ushort)b;
            }
            return(result);
        }
示例#8
0
        private static bool Write_BL_Flash(ref byte[] p_data)
        {
            bool result = true;
            int  num    = 0;
            byte b      = 32;

            byte[] array = new byte[(int)b];
            for (int i = 8192; i < Firmware.m_upper_fw_addr; i += (int)b)
            {
                Thread.Sleep(Firmware.m_bootloader_delay);
                for (int j = 0; j < (int)b; j++)
                {
                    array[j] = p_data[num++];
                }
                if (!Bootloader.Write_32_Bytes_to_Flash((ushort)i, ref array))
                {
                    result = false;
                    break;
                }
            }
            return(result);
        }
示例#9
0
        private static bool Read_BL_Flash(ushort p_start_addr, int p_byte_count, ref byte[] p_data)
        {
            bool flag2 = false;
            int  num   = 0;

            byte[] buffer = new byte[0x3a];
            ushort num2   = p_start_addr;
            int    num3   = p_byte_count / 0x3a;
            byte   num4   = 0;

            if ((p_byte_count % 0x3a) != 0)
            {
                flag2 = true;
                num3++;
            }
            for (int i = 0; i < num3; i++)
            {
                Thread.Sleep(m_bootloader_delay);
                if ((i == (num3 - 1)) && flag2)
                {
                    num4 = (byte)(p_byte_count % 0x3a);
                }
                else
                {
                    num4 = 0x3a;
                }
                if (!Bootloader.Read_One_BL_Flash_USB_Packet(num2, num4, ref buffer))
                {
                    return(false);
                }
                for (int j = 0; j < num4; j++)
                {
                    p_data[num++] = buffer[j];
                }
                num2 = (ushort)(num2 + num4);
            }
            return(true);
        }
示例#10
0
        private static bool Force_PKS_Into_Prog_Mode_Cmd()
        {
            bool   flag = false;
            ushort num  = 0;

            byte[] array = new byte[0x41];
            Array.Clear(array, 0, array.Length);
            array[1] = 0x42;
            array[2] = 0;
            if (Bootloader.Retrieve_BL_FW_Version_Cmd(ref num))
            {
                return(true);
            }
            if (USBWrite.Send_Data_Packet_To_PICkitS(ref array))
            {
                restart_the_device();
                if (Bootloader.Retrieve_BL_FW_Version_Cmd(ref num))
                {
                    flag = true;
                }
            }
            return(flag);
        }
示例#11
0
        public static bool Load_Firmware(string p_file_name, int p_device_type, ref string p_error_str, ref int p_error_code)
        {
            bool flag = false;

            if (p_device_type == 2)
            {
                m_devicetype    = DEVICETYPE.LIN;
                m_upper_fw_addr = 0x4000;
            }
            else
            {
                m_devicetype    = DEVICETYPE.PKSA;
                m_upper_fw_addr = 0x8000;
            }
            m_array_size = m_upper_fw_addr - 0x2000;
            if (!parse_hex_file_put_in_array(p_file_name))
            {
                p_error_code = 1;
                p_error_str  = "Error - Could not read hex file - download aborted";
                return(flag);
            }
            if (!Force_PKS_Into_Prog_Mode_Cmd())
            {
                p_error_code = 2;
                p_error_str  = "Error - Could not enter programming mode prior to updating firmware - download aborted";
                return(flag);
            }
            bool flag2 = false;

            byte[] buffer = new byte[14];
            if (!Clear_BL_Flash())
            {
                flag2        = true;
                p_error_str  = "Error - clearing flash prior to writing firmware";
                p_error_code = 3;
            }
            else if (!Write_BL_Flash(ref m_flash_data_array))
            {
                p_error_str  = "Error - writing flash";
                flag2        = true;
                p_error_code = 4;
            }
            else if (!Bootloader.Write_BL_Config_Bytes(ref m_config_bytes_array, ref m_config_bool_array))
            {
                flag2        = true;
                p_error_str  = "Error - writing config bytes";
                p_error_code = 5;
            }
            else
            {
                copy_current_fw_array_into_prior_array();
                if (!Read_BL_Flash(0x2000, m_upper_fw_addr - 0x2000, ref m_flash_data_array))
                {
                    flag2        = true;
                    p_error_str  = "Error - reading flash.";
                    p_error_code = 6;
                }
                else
                {
                    for (int i = 0; i < m_array_size; i++)
                    {
                        if (m_flash_data_array[i] != m_prior_flash_data_array[i])
                        {
                            p_error_str  = string.Format("Error - Verification error:  flash byte {0:X2} reads as {1:X2}\nbut should be {2:X2}\n", i, m_flash_data_array[i], m_prior_flash_data_array[i]);
                            flag2        = true;
                            p_error_code = 8;
                            break;
                        }
                    }
                    if (Bootloader.Read_BL_Config_Data(ref buffer))
                    {
                        for (int j = 0; j < buffer.Length; j++)
                        {
                            if (m_config_bool_array[j] && (buffer[j] != m_config_bytes_array[j]))
                            {
                                p_error_str  = string.Format("Error - Verification error:  Config byte {0:X2} reads as {1:X2}\nbut should be {2:X2}\n", j, buffer[j], m_config_bytes_array[j]);
                                flag2        = true;
                                p_error_code = 9;
                                break;
                            }
                        }
                    }
                    else
                    {
                        flag2        = true;
                        p_error_str  = "Error - reading config bytes";
                        p_error_code = 7;
                    }
                }
            }
            if (!flag2)
            {
                if (m_devicetype == DEVICETYPE.LIN)
                {
                    p_error_str = string.Format("LIN firmware written and verified using hex file {0}.\n", p_file_name);
                }
                else
                {
                    p_error_str = string.Format("PICkit Serial firmware written and verified using hex file {0}.\n", p_file_name);
                }
                p_error_code = 0;
                flag         = true;
            }
            if (Bootloader.Issue_BL_Reset())
            {
                restart_the_device();
                return(flag);
            }
            p_error_code = 10;
            p_error_str  = "Error - sending BL Reset Command.  Firmware may not have been updated correctly.";
            return(false);
        }
示例#12
0
        public static bool Load_Firmware(string p_file_name, int p_device_type, ref string p_error_str, ref int p_error_code)
        {
            bool result = false;

            if (p_device_type == 2)
            {
                Firmware.m_devicetype    = Firmware.DEVICETYPE.LIN;
                Firmware.m_upper_fw_addr = 16384;
            }
            else
            {
                Firmware.m_devicetype    = Firmware.DEVICETYPE.PKSA;
                Firmware.m_upper_fw_addr = 32768;
            }
            Firmware.m_array_size = Firmware.m_upper_fw_addr - 8192;
            if (Firmware.parse_hex_file_put_in_array(p_file_name))
            {
                if (Firmware.Force_PKS_Into_Prog_Mode_Cmd())
                {
                    bool   flag  = false;
                    byte[] array = new byte[14];
                    if (Firmware.Clear_BL_Flash())
                    {
                        if (!Firmware.Write_BL_Flash(ref Firmware.m_flash_data_array))
                        {
                            p_error_str  = "Error - writing flash";
                            flag         = true;
                            p_error_code = 4;
                        }
                        else if (!Bootloader.Write_BL_Config_Bytes(ref Firmware.m_config_bytes_array, ref Firmware.m_config_bool_array))
                        {
                            flag         = true;
                            p_error_str  = "Error - writing config bytes";
                            p_error_code = 5;
                        }
                        else
                        {
                            Firmware.copy_current_fw_array_into_prior_array();
                            if (Firmware.Read_BL_Flash(8192, Firmware.m_upper_fw_addr - 8192, ref Firmware.m_flash_data_array))
                            {
                                for (int i = 0; i < Firmware.m_array_size; i++)
                                {
                                    if (Firmware.m_flash_data_array[i] != Firmware.m_prior_flash_data_array[i])
                                    {
                                        p_error_str  = string.Format("Error - Verification error:  flash byte {0:X2} reads as {1:X2}\nbut should be {2:X2}\n", i, Firmware.m_flash_data_array[i], Firmware.m_prior_flash_data_array[i]);
                                        flag         = true;
                                        p_error_code = 8;
                                        break;
                                    }
                                }
                                if (Bootloader.Read_BL_Config_Data(ref array))
                                {
                                    for (int j = 0; j < array.Length; j++)
                                    {
                                        if (Firmware.m_config_bool_array[j] && array[j] != Firmware.m_config_bytes_array[j])
                                        {
                                            p_error_str  = string.Format("Error - Verification error:  Config byte {0:X2} reads as {1:X2}\nbut should be {2:X2}\n", j, array[j], Firmware.m_config_bytes_array[j]);
                                            flag         = true;
                                            p_error_code = 9;
                                            break;
                                        }
                                    }
                                }
                                else
                                {
                                    flag         = true;
                                    p_error_str  = "Error - reading config bytes";
                                    p_error_code = 7;
                                }
                            }
                            else
                            {
                                flag         = true;
                                p_error_str  = "Error - reading flash.";
                                p_error_code = 6;
                            }
                        }
                    }
                    else
                    {
                        flag         = true;
                        p_error_str  = "Error - clearing flash prior to writing firmware";
                        p_error_code = 3;
                    }
                    if (!flag)
                    {
                        if (Firmware.m_devicetype == Firmware.DEVICETYPE.LIN)
                        {
                            p_error_str = string.Format("LIN firmware written and verified using hex file {0}.\n", p_file_name);
                        }
                        else
                        {
                            p_error_str = string.Format("PICkit Serial firmware written and verified using hex file {0}.\n", p_file_name);
                        }
                        p_error_code = 0;
                        result       = true;
                    }
                    if (Bootloader.Issue_BL_Reset())
                    {
                        Firmware.restart_the_device();
                    }
                    else
                    {
                        p_error_code = 10;
                        p_error_str  = "Error - sending BL Reset Command.  Firmware may not have been updated correctly.";
                        result       = false;
                    }
                }
                else
                {
                    p_error_code = 2;
                    p_error_str  = "Error - Could not enter programming mode prior to updating firmware - download aborted";
                }
            }
            else
            {
                p_error_code = 1;
                p_error_str  = "Error - Could not read hex file - download aborted";
            }
            return(result);
        }