private void ReadDSP_Click(object sender, EventArgs e) { string addrOffsStr; uint addrOffs, data = 0, barx; addrOffsStr = OffsetDSP.Text; addrOffsStr = addrOffsStr.Remove(0, 2); if ("" == addrOffsStr) { MessageBox.Show("偏移地址栏不能为空!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } addrOffs = Convert.ToUInt32(addrOffsStr, 16); if (true == WriteSelectDDR.Checked) { barx = 5; } else { barx = 0; } PCIStatusShow.Text = string.Format("设备{0}:\r\n开始读取...", PCIDriverFun.deviceSelect); #if DEBUG_HU #else PciDriverFun.ReadFromDSP4CS((int)PCIDriverFun.deviceSelect, (int)barx, addrOffs, ref data); #endif ReadDSPData.Text = data.ToString(); PCIStatusShow.Text += string.Format("\r\n偏移地址:0x{0}:{1}\r\n读取成功!", PCIDriverFun.deviceSelect, data); }
private void IniFile2FPGA_Click(object sender, EventArgs e) { PciDriverFun.WriteToDev4CS pPhyAddr = new PciDriverFun.WriteToDev4CS((int)PCIDriverFun.deviceSelect, 5, 8, 0), // hu 物理地址 dataLen = new PciDriverFun.WriteToDev4CS((int)PCIDriverFun.deviceSelect, 5, 0xc, 0), // hu 物理空间中数据的长度 endFlag = new PciDriverFun.WriteToDev4CS((int)PCIDriverFun.deviceSelect, 5, 0x10, 1); // hu 传输结束标志位 if (!File.Exists(FPGAWriteFilePath.Text)) { MessageBox.Show("文件不存在!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } FileInfo iniFPGAFileInfo = new FileInfo(FPGAWriteFilePath.Text); if (iniFPGAFileInfo.Length >= 11 * 1024 * 1024) { MessageBox.Show("加载文件不能大于11MB!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } #if DEBUG_HU PCIDriverFun.PostMessage(this.Handle, (int)PciDriverFun.wm_CallbackMessage_0, 2, (int)PCIDriverFun.deviceSelect); #else PciDriverFun.DmaFileToDSP4CS((int)PCIDriverFun.deviceSelect, 0, FPGAWriteFilePath.Text, pPhyAddr, dataLen, endFlag); #endif WriteTimeShow.Text = ""; PCIStatusShow.Text = "设备" + PCIDriverFun.deviceSelect.ToString() + ":\r\n开始动态加载..."; stopwatch.Start(); // hu 开始计时 }
private void ListWrite2FPGA_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (0 == e.ColumnIndex) { uint fpgaAddrData, fpgaWriteData; bool isCheck = (bool)ListWrite2FPGA.Rows[e.RowIndex].Cells[0].EditedFormattedValue; string fpgaAddr = (string)ListWrite2FPGA.Rows[e.RowIndex].Cells[1].EditedFormattedValue; string fpgaIsCheck = (string)ListWrite2FPGA.Rows[e.RowIndex].Cells[2].EditedFormattedValue; string fpgaNoCheck = (string)ListWrite2FPGA.Rows[e.RowIndex].Cells[3].EditedFormattedValue; fpgaAddr = fpgaAddr.Remove(0, 2); if ("" == fpgaAddr) { MessageBox.Show("地址栏不能为空!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } fpgaAddrData = Convert.ToUInt32(fpgaAddr, 16); if (true == isCheck) { if ("" == fpgaIsCheck) { MessageBox.Show("数据栏不能为空!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } fpgaWriteData = Convert.ToUInt32(fpgaIsCheck); } else { if ("" == fpgaNoCheck) { MessageBox.Show("数据栏不能为空!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } fpgaWriteData = Convert.ToUInt32(fpgaNoCheck); } PCIStatusShow.Text = "写入...\r\n0x" + fpgaAddr + ":" + fpgaWriteData.ToString(); #if DEBUG_HU #else PciDriverFun.WriteToDSP4CS((int)PCIDriverFun.deviceSelect, 3, fpgaAddrData * 4, fpgaWriteData); #endif PCIStatusShow.Text += "\r\n成功!"; } }
private void WriteDSP_Click(object sender, EventArgs e) { string addrOffsStr, dataStr; uint addrOffs, data, barx; addrOffsStr = OffsetDSP.Text; addrOffsStr = addrOffsStr.Remove(0, 2); if ("" == addrOffsStr) { MessageBox.Show("偏移地址栏不能为空!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } addrOffs = Convert.ToUInt32(addrOffsStr, 16); dataStr = WriteDSPData.Text; if ("" == dataStr) { MessageBox.Show("写入数据栏不能为空!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } data = Convert.ToUInt32(dataStr); if (true == WriteSelectDDR.Checked) { barx = 5; } else { barx = 0; } PCIStatusShow.Text = string.Format("设备{0}:\r\n开始写入...\r\n偏移地址:0x{1}:{2}", PCIDriverFun.deviceSelect, addrOffsStr, dataStr); #if DEBUG_HU #else PciDriverFun.WriteToDSP4CS((int)PCIDriverFun.deviceSelect, (int)barx, addrOffs, data); #endif PCIStatusShow.Text += "\r\n写入成功!"; }
protected override void DefWndProc(ref System.Windows.Forms.Message m) { if (m.Msg == PciDriverFun.wm_CallbackMessage_0) { #region 中断消息响应 switch ((int)m.WParam) { case 0: { // hu ///////////添加0号中断处理程序/////////////// break; // hu ///////////////////////////////////////////// } case 1: { // hu ///////////添加1号中断处理程序/////////////// break; // hu ///////////////////////////////////////////// } case 2: { // hu ///////////添加2号中断处理程序/////////////// uint GPIO2FPGA_flag = 0; stopwatch.Stop(); WriteTimeShow.Text = Convert.ToString(stopwatch.ElapsedMilliseconds / 1000.0); stopwatch.Reset(); #if DEBUG_HU GPIO2FPGA_flag = 99; #else PciDriverFun.ReadFromDSP4CS((int)m.LParam, 5, 0x14, ref GPIO2FPGA_flag); #endif PCIStatusShow.Text = PCIStatusShow.Text + "\r\n设备" + m.LParam + ":"; switch (GPIO2FPGA_flag) { case 0: PCIStatusShow.Text += "\r\n动态加载成功!"; break; case 1: PCIStatusShow.Text += "\r\nFPGA初始化失败!"; break; case 2: PCIStatusShow.Text += "\r\n未收到FPGA的INTB信号,动态加载失败!"; break; case 3: PCIStatusShow.Text += "\r\n未收到FPGA的DONE信号,动态加载失败!"; break; default: PCIStatusShow.Text += "\r\n未收到约定返回值,动态加载失败!"; break; } break; // hu ///////////////////////////////////////////// } case 3: { // hu ///////////添加3号中断处理程序/////////////// stopwatch.Stop(); WriteTimeShow.Text = Convert.ToString(stopwatch.ElapsedMilliseconds / 1000.0); stopwatch.Reset(); #if DEBUG_HU #else PciDriverFun.WriteToDSP4CS((int)m.LParam, 3, 0xa0a00 * 4, 0xf0f0); // hu 通知fpga传输完毕 0xa0a00为fpga读取数据地址 #endif PCIStatusShow.Text = PCIStatusShow.Text + "\r\n设备" + m.LParam + ":\r\nEDMA传输成功!"; break; // hu ///////////////////////////////////////////// } default: { MessageBox.Show(string.Format("中断号{0}不存在!", m.WParam), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); break; } } #endregion } else { base.DefWndProc(ref m); // hu 一定要调用基类函数,以便系统处理其它消息。 } }
private void PCIDriverTest_Load(object sender, EventArgs e) { #region 驱动初始化 for (int ii = 0; ii < PCIDriverFun.dspDriver.Length; ii++) { PCIDriverFun.dspDriver[ii] = new PciDriverFun.DSPDriver4CS(); } #if DEBUG_HU PCIDriverFun.pciStatus = 99; #else PCIDriverFun.pciStatus = PciDriverFun.InitAllDSPDriver4CS(PCIDriverFun.dspDriver); #endif if (0 == PCIDriverFun.pciStatus) { PCIStatusShow.Text = "初始化驱动程序成功!\r\n"; } else { PCIStatusShow.Text = PciDriverFun.GetLastDriverError4CS(); } if (0 == PCIDriverFun.pciStatus) { for (uint ii = 0; ii < PciDriverFun.devNum_Max; ii++) { PCIStatusShow.Text = PCIStatusShow.Text + "PCI设备" + ii.ToString() + ":\r\n"; if (0 == PCIDriverFun.dspDriver[ii].status) { PCIDriverFun.deviceNum = ii + 1; } PCIStatusShow.Text += PciDriverFun.DriverStatus2Str4CS(PCIDriverFun.dspDriver[ii].status); PCIStatusShow.Text += "\r\n"; for (uint jj = 0; jj < PCIDriverFun.dspDriver[ii].memNum; jj++) { PCIStatusShow.Text += PciDriverFun.DriverMemStatus2Str4CS(PCIDriverFun.dspDriver[ii].memStatus[jj], PCIDriverFun.dspDriver[ii].memSize[jj]); PCIStatusShow.Text += "\r\n"; } } // hu 初始化组合框 if (0 == PCIDriverFun.deviceNum) { PCISelect.Items.Add("无设备"); } else { PCISelect.Text = "设备0"; for (uint ii = 0; ii < PCIDriverFun.deviceNum; ii++) { PCISelect.Items.Add("设备" + ii.ToString()); } } PCISelect.SelectedIndex = 0; PCIDriverFun.deviceSelect = 0; // hu 注册消息函数 // hu IntPtr p = PCIDriverFun.FindWindowEx(IntPtr.Zero, IntPtr.Zero, null, "驱动测试"); PciDriverFun.RegistHWNDToDev4CS(this.Handle); PciDriverFun.SetDSPAutoRun4CS(true); } #endregion }