Ejemplo n.º 1
0
        private bool LoadRamHex(string fileName)
        {
            TTransaction m_Xaction = new TTransaction();
            // A .hex file is already in the correct format for the FX2 RAM
            bool rVal = false;

            if (fileName == "VendAX")
            {
                rVal = Util.ParseHexData(VendAX, FwImage, ref ImageLen, ref FwOffset);
            }
            else
            {
                rVal = Util.ParseHexFile(fileName, FwImage, ref ImageLen, ref FwOffset);
            }

            if (rVal)
            {
                ControlEndPt.Target  = CyConst.TGT_DEVICE;
                ControlEndPt.ReqType = CyConst.REQ_VENDOR;
                ControlEndPt.ReqCode = 0xA0;
                ControlEndPt.Index   = 0;

                Reset(1); // Halt

                ushort chunk  = 2048;
                byte[] buffer = new byte[chunk];

                for (ushort i = FwOffset; i < ImageLen; i += chunk)
                {
                    ControlEndPt.Value = i;
                    int len = ((i + chunk) < ImageLen) ? chunk : ImageLen - i;
                    Array.Copy(FwImage, i, buffer, 0, len);

                    ControlEndPt.Write(ref buffer, ref len);

                    if (m_bRecording && (m_script_file_name != null))
                    {
                        m_Xaction.AltIntfc  = m_AltIntfc;
                        m_Xaction.ConfigNum = m_ConfigNum;
                        m_Xaction.IntfcNum  = m_IntfcNum;
                        m_Xaction.EndPtAddr = ControlEndPt.Address;
                        m_Xaction.Tag       = 0;

                        m_Xaction.bReqType   = (byte)(ControlEndPt.Direction | ControlEndPt.ReqType | ControlEndPt.Target);
                        m_Xaction.CtlReqCode = ControlEndPt.ReqCode;
                        m_Xaction.wValue     = ControlEndPt.Value;
                        m_Xaction.wIndex     = ControlEndPt.Index;
                        m_Xaction.DataLen    = (uint)len;
                        m_Xaction.Timeout    = ControlEndPt.TimeOut / 1000;
                        m_Xaction.RecordSize = (uint)len + TTransaction.TotalHeaderSize;

                        //Write m_Xaction and buffer
                        m_Xaction.WriteToStream(m_script_file_name);
                        m_Xaction.WriteFromBuffer(m_script_file_name, ref buffer, ref len);
                    }
                }

                Reset(0); // Run

                return(true);
            }

            else
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
        private bool LoadRamHex(string fname, bool blow)
        {
            TTransaction m_Xaction = new TTransaction();

            list.Clear();
            list1.Clear();

            string line, sOffset, tmp;
            int    v;

            FileStream   fs = new FileStream(fname, FileMode.Open, FileAccess.Read);
            StreamReader sr = new StreamReader(fs);

            while (!sr.EndOfStream)
            {
                list.Add(sr.ReadLine());
            }
            sr.Close();
            fs.Close();

            int Ramsize = 0x4000;

            // Delete non-data records
            for (int i = list.Count - 1; i >= 0; i--)
            {
                line = (string)list[i];
                if (line.Length > 0)
                {
                    tmp = line.Substring(7, 2);   // Get the Record Type into v
                    v   = (int)Util.HexToInt(tmp);
                    if (v != 0)
                    {
                        list.Remove(list[i]);           // Data records are type == 0
                    }
                }
            }

            for (int i = 0; i < list.Count; i++)
            {
                line = (string)list[i];

                // Remove comments
                v = line.IndexOf("//");
                if (v > -1)
                {
                    line = line.Substring(0, v - 1);
                }

                // Build string that just contains the offset followed by the data bytes
                if (line.Length > 0)
                {
                    // Get the offset
                    sOffset = line.Substring(3, 4);

                    // Get the string of data chars
                    tmp = line.Substring(1, 2);
                    v   = (int)Util.HexToInt(tmp) * 2;
                    string s = line.Substring(9, v);

                    list1.Add(sOffset + s);
                }
            }

            if (blow)
            {
                Reset(1);
            }

            byte   Reqcode = blow ? (byte)0xA0 : (byte)0xA3;
            ushort windex  = 0;

            int    iindex     = 0;
            string Datastring = "";
            int    nxtoffset  = 0;
            int    xferLen    = 0;
            ushort wvalue     = 0;

            foreach (string lines in list1)
            {
                line = lines.Substring(0, 4);
                ushort offset = (ushort)Util.HexToInt(line);

                int slen = lines.Length;

                int no_bytes = (slen - 4) / 2;
                int lastaddr = offset + no_bytes;

                //if (blow && (offset < Ramsize) && (lastaddr > Ramsize))
                //    no_bytes = Ramsize - offset;

                //if (!blow && (offset < Ramsize) && (lastaddr > Ramsize))
                //{
                //    no_bytes = lastaddr - (int)Ramsize;
                //    string s = "xxxx" + lines.Substring(slen - (no_bytes * 2), no_bytes * 2);

                //    list1[iindex] = s;
                //    offset = (ushort)Ramsize;
                //    line = "4000";
                //}

                //if ((blow && (offset < Ramsize)) || (!blow && (offset >= Ramsize)))
                if ((blow && (lastaddr < Ramsize)) || (!blow && (lastaddr >= Ramsize)))
                {
                    xferLen += no_bytes;

                    if ((offset == nxtoffset) && (xferLen < 0x1000))
                    {
                        Datastring += lines.Substring(4, no_bytes * 2);
                    }
                    else
                    {
                        int len = Datastring.Length;


                        if (!len.Equals(0))
                        {
                            int    bufLen = len / 2;
                            byte[] buf    = new byte[bufLen];
                            string d;

                            for (int j = 0; j < bufLen; j++)
                            {
                                d      = Datastring.Substring(j * 2, 2);
                                buf[j] = (byte)Util.HexToInt(d);
                            }

                            ControlEndPt.Target    = CyConst.TGT_DEVICE;
                            ControlEndPt.ReqType   = CyConst.REQ_VENDOR;
                            ControlEndPt.Direction = CyConst.DIR_TO_DEVICE;
                            ControlEndPt.ReqCode   = Reqcode;
                            ControlEndPt.Value     = wvalue;
                            ControlEndPt.Index     = windex;

                            ControlEndPt.Write(ref buf, ref bufLen);
                            if (m_bRecording && (m_script_file_name != null))
                            {
                                m_Xaction.AltIntfc  = m_AltIntfc;
                                m_Xaction.ConfigNum = m_ConfigNum;
                                m_Xaction.IntfcNum  = m_IntfcNum;
                                m_Xaction.EndPtAddr = ControlEndPt.Address;
                                m_Xaction.Tag       = 0;

                                m_Xaction.bReqType   = (byte)(ControlEndPt.Direction | ControlEndPt.ReqType | ControlEndPt.Target);
                                m_Xaction.CtlReqCode = ControlEndPt.ReqCode;
                                m_Xaction.wValue     = ControlEndPt.Value;
                                m_Xaction.wIndex     = ControlEndPt.Index;
                                m_Xaction.DataLen    = (uint)bufLen;
                                m_Xaction.Timeout    = ControlEndPt.TimeOut / 1000;
                                m_Xaction.RecordSize = (uint)bufLen + TTransaction.TotalHeaderSize;

                                //Write m_Xaction and buffer
                                m_Xaction.WriteToStream(m_script_file_name);
                                m_Xaction.WriteFromBuffer(m_script_file_name, ref buf, ref bufLen);
                            }
                        }

                        wvalue     = (ushort)Util.HexToInt(line);
                        Datastring = lines.Substring(4, no_bytes * 2);
                        xferLen    = no_bytes;
                    }

                    nxtoffset = offset + no_bytes;
                }
                iindex++;
            }

            int len1 = Datastring.Length;

            if (!len1.Equals(0))
            {
                int    bufLen = len1 / 2;
                byte[] buf1   = new byte[bufLen];
                string d;

                for (int j = 0; j < bufLen; j++)
                {
                    d       = Datastring.Substring(j * 2, 2);
                    buf1[j] = (byte)Util.HexToInt(d);
                }


                ControlEndPt.Target    = CyConst.TGT_DEVICE;
                ControlEndPt.ReqType   = CyConst.REQ_VENDOR;
                ControlEndPt.Direction = CyConst.DIR_TO_DEVICE;
                ControlEndPt.ReqCode   = Reqcode;
                ControlEndPt.Value     = wvalue;
                ControlEndPt.Index     = windex;

                ControlEndPt.Write(ref buf1, ref bufLen);

                if (m_bRecording && (m_script_file_name != null))
                {
                    m_Xaction.AltIntfc  = m_AltIntfc;
                    m_Xaction.ConfigNum = m_ConfigNum;
                    m_Xaction.IntfcNum  = m_IntfcNum;
                    m_Xaction.EndPtAddr = ControlEndPt.Address;
                    m_Xaction.Tag       = 0;

                    m_Xaction.bReqType   = (byte)(ControlEndPt.Direction | ControlEndPt.ReqType | ControlEndPt.Target);
                    m_Xaction.CtlReqCode = ControlEndPt.ReqCode;
                    m_Xaction.wValue     = ControlEndPt.Value;
                    m_Xaction.wIndex     = ControlEndPt.Index;
                    m_Xaction.DataLen    = (uint)bufLen;
                    m_Xaction.Timeout    = ControlEndPt.TimeOut / 1000;
                    m_Xaction.RecordSize = (uint)bufLen + TTransaction.TotalHeaderSize;

                    //Write m_Xaction and buffer
                    m_Xaction.WriteToStream(m_script_file_name);
                    m_Xaction.WriteFromBuffer(m_script_file_name, ref buf1, ref bufLen);
                }
            }

            if (blow)
            {
                Reset(0);
            }

            return(true);
        }