Beispiel #1
0
        public static bool Configure_PICkitSerial_For_I2CSlave_Auto_Mode(byte p_slave_addr, byte p_slave_mask, byte p_array_byte_count, ref byte[] p_profile_array, ref string p_result_str)
        {
            byte[] array  = new byte[65];
            byte[] array2 = new byte[255];
            byte[] array3 = new byte[65];
            bool   result = false;
            string text   = "";

            Array.Clear(array, 0, array.Length);
            Array.Clear(array3, 0, array3.Length);
            Mode.update_status_packet_data(7, ref array3);
            array3[23] = 2;
            array3[29] = p_slave_addr;
            array3[30] = p_slave_mask;
            USBWrite.configure_outbound_control_block_packet(ref array, ref text, ref array3);
            USBWrite.Send_Cold_Reset_Cmd();
            bool flag = USBWrite.Send_Data_Packet_To_PICkitS(ref array);

            Array.Clear(array2, 0, array2.Length);
            array2[0] = 0;
            array2[1] = 5;
            array2[2] = p_array_byte_count;
            for (int i = 3; i < (int)(p_array_byte_count + 3); i++)
            {
                array2[i] = p_profile_array[i - 3];
            }
            USBWrite.Send_Script_To_PICkitS(ref array2);
            USBWrite.Send_Warm_Reset_Cmd();
            if (flag)
            {
                if (USBWrite.Update_Status_Packet())
                {
                    Utilities.m_flags.g_status_packet_mutex.WaitOne();
                    int j;
                    for (j = 7; j < 31; j++)
                    {
                        if (Constants.STATUS_PACKET_DATA[j] != array[j - 5])
                        {
                            p_result_str = string.Format("Byte {0} failed verification in config block write.\n Value reads {1:X2}, but should be {2:X2}.", j - 7, Constants.STATUS_PACKET_DATA[j], array[j - 5]);
                            break;
                        }
                    }
                    if (j == 31)
                    {
                        result       = true;
                        p_result_str = string.Format("PICkit Serial Analyzer correctly updated.", new object[0]);
                    }
                    Utilities.m_flags.g_status_packet_mutex.ReleaseMutex();
                }
                else
                {
                    p_result_str = string.Format("Error requesting config verification - Config Block may not be updated correctly", new object[0]);
                }
            }
            else
            {
                p_result_str = string.Format("Error sending config packet - Config Block may not be updated correctly", new object[0]);
            }
            return(result);
        }
Beispiel #2
0
        public static bool Configure_PICkitSerial_For_I2CSlave_Auto_Mode(byte p_slave_addr, byte p_slave_mask, byte p_array_byte_count, ref byte[] p_profile_array, ref string p_result_str)
        {
            bool flag = false;

            byte[] array   = new byte[0x41];
            byte[] buffer2 = new byte[0xff];
            byte[] buffer3 = new byte[0x41];
            bool   flag2   = false;
            string str     = "";
            int    index   = 0;

            Array.Clear(array, 0, array.Length);
            Array.Clear(buffer3, 0, buffer3.Length);
            Mode.update_status_packet_data(7, ref buffer3);
            buffer3[0x17] = 2;
            buffer3[0x1d] = p_slave_addr;
            buffer3[30]   = p_slave_mask;
            USBWrite.configure_outbound_control_block_packet(ref array, ref str, ref buffer3);
            USBWrite.Send_Cold_Reset_Cmd();
            flag = USBWrite.Send_Data_Packet_To_PICkitS(ref array);
            Array.Clear(buffer2, 0, buffer2.Length);
            buffer2[0] = 0;
            buffer2[1] = 5;
            buffer2[2] = p_array_byte_count;
            for (int i = 3; i < (p_array_byte_count + 3); i++)
            {
                buffer2[i] = p_profile_array[i - 3];
            }
            USBWrite.Send_Script_To_PICkitS(ref buffer2);
            USBWrite.Send_Warm_Reset_Cmd();
            if (!flag)
            {
                p_result_str = string.Format("Error sending config packet - Config Block may not be updated correctly", new object[0]);
                return(flag2);
            }
            if (!USBWrite.Update_Status_Packet())
            {
                p_result_str = string.Format("Error requesting config verification - Config Block may not be updated correctly", new object[0]);
                return(flag2);
            }
            Utilities.m_flags.g_status_packet_mutex.WaitOne();
            index = 7;
            while (index < 0x1f)
            {
                if (Constants.STATUS_PACKET_DATA[index] != array[index - 5])
                {
                    p_result_str = string.Format("Byte {0} failed verification in config block write.\n Value reads {1:X2}, but should be {2:X2}.", index - 7, Constants.STATUS_PACKET_DATA[index], array[index - 5]);
                    break;
                }
                index++;
            }
            if (index == 0x1f)
            {
                flag2        = true;
                p_result_str = string.Format("PICkit Serial Analyzer correctly updated.", new object[0]);
            }
            Utilities.m_flags.g_status_packet_mutex.ReleaseMutex();
            return(flag2);
        }
Beispiel #3
0
        public static bool Configure_PICkitSerial(int p_mode, bool p_reset)
        {
            bool   flag = false;
            string str  = "";
            string str2 = "";

            byte[] array   = new byte[0x41];
            byte[] buffer2 = new byte[0x41];
            if (Utilities.m_flags.HID_read_handle != IntPtr.Zero)
            {
                Array.Clear(array, 0, array.Length);
                Array.Clear(buffer2, 0, buffer2.Length);
                Mode.update_status_packet_data(p_mode, ref buffer2);
                USBWrite.configure_outbound_control_block_packet(ref array, ref str, ref buffer2);
                flag = USBWrite.write_and_verify_config_block(ref array, ref str2, p_reset, ref str);
            }
            return(flag);
        }
Beispiel #4
0
        public static bool Configure_PICkitSerial(int p_mode, bool p_reset)
        {
            bool   result = false;
            string text   = "";
            string text2  = "";

            byte[] array  = new byte[65];
            byte[] array2 = new byte[65];
            if (Utilities.m_flags.HID_DeviceReady != false)            //(Utilities.m_flags.HID_read_handle != IntPtr.Zero)
            {
                Array.Clear(array, 0, array.Length);
                Array.Clear(array2, 0, array2.Length);
                Mode.update_status_packet_data(p_mode, ref array2);
                USBWrite.configure_outbound_control_block_packet(ref array, ref text, ref array2);
                result = USBWrite.write_and_verify_config_block(ref array, ref text2, p_reset, ref text);
            }
            return(result);
        }
Beispiel #5
0
        public static bool Configure_PICkitSerial_For_LINSlave_Mode(byte p_array_byte_count, ref byte[] p_profile_array, ref string p_result_str, bool p_autobaud, ref int p_error_code)
        {
            bool flag = false;

            byte[] array   = new byte[0x41];
            byte[] buffer2 = new byte[0xff];
            byte[] buffer3 = new byte[0x41];
            bool   flag2   = false;
            byte   num     = 0;
            byte   num2    = 0;
            string str     = "";
            int    index   = 0;

            p_error_code = 0;
            Array.Clear(array, 0, array.Length);
            Array.Clear(buffer3, 0, buffer3.Length);
            byte num4 = Number_Of_Bytes_In_CBUF3(ref num, ref num2);

            if (p_array_byte_count > num4)
            {
                p_result_str = string.Format("Byte count of {0} greater than allowed value of {1}.", p_array_byte_count, num4);
                p_error_code = 1;
                return(flag);
            }
            USBWrite.Clear_CBUF(3);
            if (p_autobaud)
            {
                Mode.update_status_packet_data(10, ref buffer3);
            }
            else
            {
                Mode.update_status_packet_data(0x13, ref buffer3);
            }
            USBWrite.configure_outbound_control_block_packet(ref array, ref str, ref buffer3);
            USBWrite.Send_Cold_Reset_Cmd();
            flag = USBWrite.Send_Data_Packet_To_PICkitS(ref array);
            USBWrite.Send_Warm_Reset_Cmd();
            Array.Clear(buffer2, 0, buffer2.Length);
            buffer2[0] = 0;
            buffer2[1] = 5;
            buffer2[2] = p_array_byte_count;
            for (int i = 3; i < (p_array_byte_count + 3); i++)
            {
                buffer2[i] = p_profile_array[i - 3];
            }
            USBWrite.Send_Script_To_PICkitS(ref buffer2);
            buffer3[0x17] = (byte)(buffer3[0x17] | 0x20);
            USBWrite.configure_outbound_control_block_packet(ref array, ref str, ref buffer3);
            if (!USBWrite.Send_Data_Packet_To_PICkitS(ref array))
            {
                p_error_code = 2;
                p_result_str = string.Format("Error sending config packet - Config Block may not be updated correctly", new object[0]);
                return(flag2);
            }
            if (!USBWrite.Update_Status_Packet())
            {
                p_result_str = string.Format("Error requesting config verification - Config Block may not be updated correctly", new object[0]);
                return(flag2);
            }
            Utilities.m_flags.g_status_packet_mutex.WaitOne();
            index = 7;
            while (index < 0x1f)
            {
                if (Constants.STATUS_PACKET_DATA[index] != array[index - 5])
                {
                    p_error_code = 3;
                    p_result_str = string.Format("Byte {0} failed verification in config block write.\n Value reads {1:X2}, but should be {2:X2}.", index - 7, Constants.STATUS_PACKET_DATA[index], array[index - 5]);
                    break;
                }
                index++;
            }
            if (index == 0x1f)
            {
                flag2        = true;
                p_result_str = string.Format("PICkit Serial Analyzer correctly updated.", new object[0]);
            }
            Utilities.m_flags.g_status_packet_mutex.ReleaseMutex();
            return(flag2);
        }
Beispiel #6
0
        public static bool Configure_PICkitSerial_For_LINSlave_Mode(byte p_array_byte_count, ref byte[] p_profile_array, ref string p_result_str, bool p_autobaud, ref int p_error_code)
        {
            bool flag = false;

            byte[] array  = new byte[65];
            byte[] array2 = new byte[255];
            byte[] array3 = new byte[65];
            bool   result = false;
            byte   b      = 0;
            byte   b2     = 0;
            string text   = "";

            p_error_code = 0;
            Array.Clear(array, 0, array.Length);
            Array.Clear(array3, 0, array3.Length);
            byte b3 = LIN.Number_Of_Bytes_In_CBUF3(ref b, ref b2);

            if (p_array_byte_count > b3)
            {
                p_result_str = string.Format("Byte count of {0} greater than allowed value of {1}.", p_array_byte_count, b3);
                p_error_code = 1;
                return(flag);
            }
            USBWrite.Clear_CBUF(3);
            if (p_autobaud)
            {
                Mode.update_status_packet_data(10, ref array3);
            }
            else
            {
                Mode.update_status_packet_data(19, ref array3);
            }
            USBWrite.configure_outbound_control_block_packet(ref array, ref text, ref array3);
            USBWrite.Send_Cold_Reset_Cmd();
            flag = USBWrite.Send_Data_Packet_To_PICkitS(ref array);
            USBWrite.Send_Warm_Reset_Cmd();
            Array.Clear(array2, 0, array2.Length);
            array2[0] = 0;
            array2[1] = 5;
            array2[2] = p_array_byte_count;
            for (int i = 3; i < (int)(p_array_byte_count + 3); i++)
            {
                array2[i] = p_profile_array[i - 3];
            }
            USBWrite.Send_Script_To_PICkitS(ref array2);
            byte[] expr_F9_cp_0 = array3;
            int    expr_F9_cp_1 = 23;

            expr_F9_cp_0[expr_F9_cp_1] |= 32;
            USBWrite.configure_outbound_control_block_packet(ref array, ref text, ref array3);
            flag = USBWrite.Send_Data_Packet_To_PICkitS(ref array);
            if (flag)
            {
                if (USBWrite.Update_Status_Packet())
                {
                    Utilities.m_flags.g_status_packet_mutex.WaitOne();
                    int j;
                    for (j = 7; j < 31; j++)
                    {
                        if (Constants.STATUS_PACKET_DATA[j] != array[j - 5])
                        {
                            p_error_code = 3;
                            p_result_str = string.Format("Byte {0} failed verification in config block write.\n Value reads {1:X2}, but should be {2:X2}.", j - 7, Constants.STATUS_PACKET_DATA[j], array[j - 5]);
                            break;
                        }
                    }
                    if (j == 31)
                    {
                        result       = true;
                        p_result_str = string.Format("PICkit Serial Analyzer correctly updated.", new object[0]);
                    }
                    Utilities.m_flags.g_status_packet_mutex.ReleaseMutex();
                }
                else
                {
                    p_result_str = string.Format("Error requesting config verification - Config Block may not be updated correctly", new object[0]);
                }
            }
            else
            {
                p_error_code = 2;
                p_result_str = string.Format("Error sending config packet - Config Block may not be updated correctly", new object[0]);
            }
            return(result);
        }