Beispiel #1
0
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
#if DEBUG_HU
#else
            PcieDriver.ClosePcieDevice();
#endif
        }
Beispiel #2
0
        private void dgvRegWrite_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (0 == e.ColumnIndex)
            {
                uint   fpgaAddrData, fpgaWriteData;
                bool   isCheck     = (bool)dgvRegWrite.Rows[e.RowIndex].Cells[0].EditedFormattedValue;
                string fpgaAddr    = (string)dgvRegWrite.Rows[e.RowIndex].Cells[1].EditedFormattedValue;
                string fpgaIsCheck = (string)dgvRegWrite.Rows[e.RowIndex].Cells[2].EditedFormattedValue;
                string fpgaNoCheck = (string)dgvRegWrite.Rows[e.RowIndex].Cells[3].EditedFormattedValue;

                fpgaAddr = fpgaAddr.Remove(0, 2);
                if ("" == fpgaAddr)
                {
                    MessageBox.Show("地址栏不能为空!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                fpgaAddrData = Convert.ToUInt32(fpgaAddr, 16);

                if (true == isCheck)
                {
                    if ("" == fpgaIsCheck)
                    {
                        MessageBox.Show("数据栏不能为空!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                    fpgaWriteData = Convert.ToUInt32(fpgaIsCheck);
                }
                else
                {
                    if ("" == fpgaNoCheck)
                    {
                        MessageBox.Show("数据栏不能为空!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                    fpgaWriteData = Convert.ToUInt32(fpgaNoCheck);
                }

                txtStatus.Text += "写入...\n0x" + fpgaAddr + ":" + fpgaWriteData.ToString() + "\n";
#if DEBUG_HU
                txtStatus.Text += "成功!\n";
#else
                if (PcieDriver.SetDeviceRegister(fpgaAddrData, fpgaWriteData))
                {
                    txtStatus.Text += "成功!\n";
                }
                else
                {
                    txtStatus.Text += "失败!\n";
                    txtStatus.Text += PcieDriver.GetLastDeviceError() + "\n";
                }
#endif
            }
        }
Beispiel #3
0
        private void btnDebugSet_Click(object sender, EventArgs e)
        {
            String addrStr = tboxDebugAddr.Text;
            String dataStr = tboxDebugData.Text;
            UInt32 barX    = 0;
            UInt32 addr    = 0;
            UInt32 data    = 0;

            try
            {
                barX = Convert.ToUInt32(tboxBarX.Text);

                if (addrStr.StartsWith("0x"))
                {
                    addrStr = addrStr.Remove(0, 2);
                    addr    = Convert.ToUInt32(addrStr, 16);
                }
                else
                {
                    addr = Convert.ToUInt32(addrStr);
                }

                if (dataStr.StartsWith("0x"))
                {
                    dataStr = dataStr.Remove(0, 2);
                    data    = Convert.ToUInt32(dataStr, 16);
                }
                else
                {
                    data = Convert.ToUInt32(dataStr);
                }
            }
            catch (Exception ex)
            {
                txtStatus.Text += ex.Message;
                return;
            }

            txtStatus.Text += "写入...\n bar:" + barX + "  0x" + addrStr + ":" + data + "\n";
#if DEBUG_ZHU
            txtStatus.Text += "成功!\n";
#else
            if (PcieDriver.SetDebugRegister(barX, addr, data))
            {
                txtStatus.Text += "成功!\n";
            }
            else
            {
                txtStatus.Text += "失败!\n";
                txtStatus.Text += PcieDriver.GetLastDeviceError() + "\n";
            }
#endif
        }
Beispiel #4
0
 public static bool SetPcieReg(PcieRegAddr addr, UInt32 data, out string errorMsg)
 {
     if (addr == PcieRegAddr.FadingSize || addr == PcieRegAddr.ArbWaveSize)
     {
         data = data * 8 / 512 - 1;
     }
     if (!PcieDriver.SetDeviceRegister((UInt32)addr, data))
     {
         errorMsg = PcieDriver.GetLastDeviceError();
         return(false);
     }
     errorMsg = "";
     return(true);
 }
Beispiel #5
0
        private void Form1_Load(object sender, EventArgs e)
        {
#if DEBUG_HU
            txtStatus.Text = "打开Pcie驱动成功!\n";
#else
            if (PcieDriver.OpenPcieDevice() == false)
            {
                txtStatus.Text  = "打开Pcie驱动失败!\n";
                txtStatus.Text += PcieDriver.GetLastDeviceError() + "\n";
                MessageBox.Show("打开Pcie驱动失败!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                txtStatus.Text = "打开Pcie驱动成功!\n";
            }
#endif
        }
Beispiel #6
0
        public static bool DMATransferFile(string filePath, out string errorMsg)
        {
            try
            {
                FileStream   fStream    = new FileStream(filePath, FileMode.Open, FileAccess.Read);
                BinaryReader bReader    = new BinaryReader(fStream);
                long         bufSizeMax = PcieDriver.MAX_BUF_SIZE;
                uint         bufCount   = (uint)(fStream.Length / bufSizeMax);
                uint         lenExtra   = (uint)(fStream.Length % bufSizeMax);
                uint         alignByte  = 0x400;
                if ((lenExtra & (alignByte - 1)) != 0)
                {
                    lenExtra = lenExtra & ~(alignByte - 1) + alignByte;
                }

                byte[] buf;
                for (int i = 0; i < bufCount; i++)
                {
                    buf = new byte[bufSizeMax];
                    buf = bReader.ReadBytes(buf.Length);
                    if (!PcieDriver.DmaToDevice(buf))
                    {
                        errorMsg = PcieDriver.GetLastDeviceError();
                        return(false);
                    }
                }
                if (lenExtra > 0)
                {
                    buf = new byte[lenExtra];
                    bReader.ReadBytes((int)lenExtra).CopyTo(buf, 0);
                    if (!PcieDriver.DmaToDevice(buf))
                    {
                        errorMsg = PcieDriver.GetLastDeviceError();
                        return(false);
                    }
                }
                errorMsg = "";
                return(true);
            }
            catch (Exception ex)
            {
                errorMsg = ex.Message;
                return(false);
            }
        }
Beispiel #7
0
        private void btnReadFPGA_Click(object sender, EventArgs e)
        {
            string addrStr = tboxReadAddr.Text;
            UInt32 addr    = 0;

            UInt32[] data = new UInt32[1];

            try
            {
                if (addrStr.StartsWith("0x"))
                {
                    addr = Convert.ToUInt32(addrStr, 16);
                }
                else
                {
                    addr = Convert.ToUInt32(addrStr);
                }
            }
            catch (Exception ex)
            {
                txtStatus.Text += ex.Message;
                return;
            }

            txtStatus.Text += "读取FPGA寄存器:" + addrStr + "\n";
#if DEBUG_ZHU
            data[0]         = 15;
            txtStatus.Text += "--> 得到:" + data[0] + "\n";
#else
            if (PcieDriver.ReadPFGARegister(addr, data))
            {
                txtStatus.Text += "--> 得到:" + data[0] + "\n";
            }
            else
            {
                txtStatus.Text += "失败!\n";
                txtStatus.Text += PcieDriver.GetLastDeviceError() + "\n";
            }
#endif
            tboxReadData.Text = "0x" + data[0].ToString("x");
        }
Beispiel #8
0
        /// <summary>
        /// 设置Pcie设备寄存器值
        /// </summary>
        public bool SetPcieReg(PcieReg regAddr, uint regData, out string errorMsg)
        {
            switch (regAddr)
            {
            case PcieReg.FadingSize:
            {
                if (!PcieDriver.SetDeviceRegister((uint)regAddr, regData * 8 / 512 - 1))
                {
                    errorMsg = PcieDriver.GetLastDeviceError();
                    return(false);
                }
                errorMsg = "";
                break;
            }

            case PcieReg.ArbWaveSize:
            {
                if (!PcieDriver.SetDeviceRegister((uint)regAddr, regData * 8 / 512 - 1))
                {
                    errorMsg = PcieDriver.GetLastDeviceError();
                    return(false);
                }
                errorMsg = "";
                break;
            }

            default:
            {
                if (!PcieDriver.SetDeviceRegister((uint)regAddr, regData))
                {
                    errorMsg = PcieDriver.GetLastDeviceError();
                    return(false);
                }
                errorMsg = "";
                break;
            }
            }
            return(true);
        }
Beispiel #9
0
        private void bgwDmaTransfer_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            timerDmaTransfer.Stop();

            double dmaSec = Math.Round(swDmaTime.Elapsed.TotalSeconds, 2);

            txtDmaTime.Text = Convert.ToString(dmaSec);
            swDmaTime.Reset();

            dmaSpeedMB   = 0;
            dmaCompleted = 0;
            dmaTransfer.ShowProgress(dmaSpeedMB, dmaCompleted);
            dmaTransfer.Hide();

            if ((bool)e.Result)
            {
                txtStatus.Text += "DMA传输完成!\n";
            }
            else
            {
                txtStatus.Text += "DMA传输失败!\n";
                txtStatus.Text += PcieDriver.GetLastDeviceError() + "\n";
            }
        }
Beispiel #10
0
        private void btnPreloading_Click(object sender, EventArgs e)
        {
            String       filePath = tboxDSPFilePath.Text;
            FileStream   fs       = null;
            BinaryReader br       = null;

            byte[] buf;

            try
            {
                fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
                br = new BinaryReader(fs);

                buf = new byte[fs.Length];
                buf = br.ReadBytes(buf.Length);

#if DEBUG_ZHU
                txtStatus.Text += "--> 预加载成功!\n";
#else
                if (PcieDriver.DspProloading(buf))
                {
                    txtStatus.Text += "--> 预加载成功!\n";
                }
                else
                {
                    txtStatus.Text += "预加载失败!\n";
                    txtStatus.Text += PcieDriver.GetLastDeviceError() + "\n";
                }
#endif
            }
            catch (Exception ex)
            {
                txtStatus.Text += "预加载失败!\n";
                txtStatus.Text += ex.Message + "\n";
            }
        }
Beispiel #11
0
        private void bgwDmaTransfer_DoWork(object sender, DoWorkEventArgs e)
        {
            FileStream   fs = null;
            BinaryReader br = null;

            e.Result = true;

            try
            {
                byte[] buf;
                long   bufSizeMax;
                uint   bufCount, lenExtra, alignByte = 0x400;

                string dmaFilePath = e.Argument as string;
                bufSizeMax = PcieDriver.MAX_BUF_SIZE;

                fs = new FileStream(dmaFilePath, FileMode.Open, FileAccess.Read);
                br = new BinaryReader(fs);

                bufCount = (uint)(fs.Length / bufSizeMax);
                lenExtra = (uint)(fs.Length % bufSizeMax);
                if ((lenExtra & (alignByte - 1)) != 0)
                {
                    lenExtra = (lenExtra & ~(alignByte - 1)) + alignByte;
                }

                if (bufCount > 0)
                {
                    for (uint ii = 0; ii < bufCount; ii++)
                    {
                        buf = new byte[bufSizeMax];
                        buf = br.ReadBytes(buf.Length);

                        if (PcieDriver.DmaToDevice(buf) == false)
                        {
                            e.Result  = false;
                            lastError = PcieDriver.GetLastDeviceError();
                            return;
                        }
                    }
                }

                if (lenExtra > 0)
                {
                    buf = new byte[lenExtra];
                    br.ReadBytes((int)lenExtra).CopyTo(buf, 0);

                    if (PcieDriver.DmaToDevice(buf) == false)
                    {
                        e.Result  = false;
                        lastError = PcieDriver.GetLastDeviceError();
                        return;
                    }
                }
            }
            catch
            {
                e.Result      = false;
                lastError     = "配置硬件失败!";
                lalState.Text = "配置硬件失败!";
            }
            finally
            {
                if (br != null)
                {
                    br.Close();
                }
                if (fs != null)
                {
                    fs.Close();
                }
            }
        }
Beispiel #12
0
        private void bgwDmaTransfer_DoWork(object sender, DoWorkEventArgs e)
        {
            string       dmaFilePath = e.Argument as string;
            FileStream   fs          = null;
            BinaryReader br          = null;

            byte[] buf;
            long   bufSizeMax = PcieDriver.MAX_BUF_SIZE;
            uint   bufCount, lenExtra, alignByte = 0x400;
            double lastSec = 0, lastCompleted = 0;

            e.Result = true;

            try
            {
                fs = new FileStream(dmaFilePath, FileMode.Open, FileAccess.Read);
                br = new BinaryReader(fs);

                bufCount = (uint)(fs.Length / bufSizeMax);
                lenExtra = (uint)(fs.Length % bufSizeMax);
                if ((lenExtra & (alignByte - 1)) != 0)
                {
                    lenExtra = (lenExtra & ~(alignByte - 1)) + alignByte;
                }

                if (bufCount > 0)
                {
                    for (uint ii = 0; ii < bufCount; ii++)
                    {
                        swDmaTime.Start();   // hu 开始计时

                        buf = new byte[bufSizeMax];
                        buf = br.ReadBytes(buf.Length);
#if DEBUG_HU
#else
                        if (PcieDriver.DmaToDevice(buf) == false)
                        {
                            swDmaTime.Stop();
                            e.Result = false;

                            MessageBox.Show("发送数据失败!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            return;
                        }
#endif
                        swDmaTime.Stop();

                        dmaSpeedMB = buf.Length / 1024.0 / 1024.0 / (swDmaTime.Elapsed.TotalSeconds - lastSec);
                        dmaSpeedMB = Math.Round(dmaSpeedMB, 2);
                        lastSec    = swDmaTime.Elapsed.TotalSeconds;

                        lastCompleted += buf.Length;
                        dmaCompleted   = (int)Math.Round(lastCompleted / fs.Length * 100);
                    }
                }

                if (lenExtra > 0)
                {
                    swDmaTime.Start();   // hu 开始计时

                    buf = new byte[lenExtra];
                    br.ReadBytes((int)lenExtra).CopyTo(buf, 0);
#if DEBUG_HU
#else
                    if (PcieDriver.DmaToDevice(buf) == false)
                    {
                        swDmaTime.Stop();
                        e.Result = false;

                        MessageBox.Show("发送数据失败!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
#endif
                    swDmaTime.Stop();

                    dmaSpeedMB = buf.Length / 1024.0 / 1024.0 / (swDmaTime.Elapsed.TotalSeconds - lastSec);
                    dmaSpeedMB = Math.Round(dmaSpeedMB, 2);
                    lastSec    = swDmaTime.Elapsed.TotalSeconds;

                    dmaCompleted = 100;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("发送数据失败!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            finally
            {
                if (br != null)
                {
                    br.Close();
                }
                if (fs != null)
                {
                    fs.Close();
                }
            }
        }
Beispiel #13
0
        private void 发送所有选中项ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int maxLen = dgvRegWrite.Rows.Count;

            uint[] addrAndData = new uint[maxLen * 2];
            uint   sendLen     = 0;

            txtStatus.AppendText("发送FPGA控制字:\n");
            txtStatus.AppendText("地址\t数据\n");
            for (int i = 0; i < maxLen; i++)
            {
                bool isCheck = (bool)dgvRegWrite.Rows[i].Cells[0].EditedFormattedValue;

                uint   fpgaAddrData, fpgaWriteData;
                string fpgaAddr = (string)dgvRegWrite.Rows[i].Cells[1].EditedFormattedValue;


                if ("0x" == fpgaAddr || "" == fpgaAddr)
                {
                    continue;
                }

                if (true == isCheck)
                {
                    string fpgaIsCheck = (string)dgvRegWrite.Rows[i].Cells[2].EditedFormattedValue;

                    if ("" == fpgaIsCheck || "0x" == fpgaIsCheck)
                    {
                        continue;
                    }

                    //fpgaAddr = fpgaAddr.Remove(0, 2);
                    fpgaAddrData = Convert.ToUInt32(fpgaAddr, 16);

                    bool isHexIsCheck = fpgaIsCheck.StartsWith("0x");
                    if (isHexIsCheck)
                    {
                        fpgaWriteData = Convert.ToUInt32(fpgaIsCheck, 16);
                    }
                    else
                    {
                        fpgaWriteData = Convert.ToUInt32(fpgaIsCheck);
                    }

                    addrAndData[i * 2]     = fpgaAddrData;
                    addrAndData[1 + i * 2] = fpgaWriteData;

                    txtStatus.AppendText(fpgaAddr + "\t" + fpgaIsCheck + "\n");
                    sendLen += 1;
                }
                else
                {
                    string fpgaNoCheck = (string)dgvRegWrite.Rows[i].Cells[3].EditedFormattedValue;

                    if ("" == fpgaNoCheck || "0x" == fpgaNoCheck)
                    {
                        continue;
                    }

                    fpgaAddrData = Convert.ToUInt32(fpgaAddr, 16);

                    bool isHexIsCheck = fpgaNoCheck.StartsWith("0x");
                    if (isHexIsCheck)
                    {
                        fpgaWriteData = Convert.ToUInt32(fpgaNoCheck, 16);
                    }
                    else
                    {
                        fpgaWriteData = Convert.ToUInt32(fpgaNoCheck);
                    }

                    addrAndData[i * 2]     = fpgaAddrData;
                    addrAndData[1 + i * 2] = fpgaWriteData;

                    txtStatus.AppendText(fpgaAddr + "\t" + fpgaNoCheck + "\n");
                    sendLen += 1;
                }
            }
#if DEBUG_ZHU
            txtStatus.AppendText("发送成功!\n");
#else
            if (!PcieDriver.SetFPGARegister(addrAndData, sendLen))
            {
                txtStatus.AppendText("发送成功!\n");
            }
            else
            {
                txtStatus.AppendText("发送失败!\n");
                txtStatus.AppendText(PcieDriver.GetLastDeviceError());
                txtStatus.AppendText("\n");
            }
#endif
        }