OpenDMAForm.cs
上传用户:huajielb
上传日期:2022-07-29
资源大小:626k
文件大小:12k
源码类别:

驱动编程

开发平台:

Visual C++

  1. using System;
  2. using System.Drawing;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Windows.Forms;
  6. using DWORD = System.UInt32;
  7. using WORD = System.UInt16;
  8. using BOOL = System.Boolean;
  9. using Jungo.wdapi_dotnet;
  10. using Jungo.plx_lib;
  11. namespace Jungo.PLX_Sample
  12. {
  13.     public class OpenDMAForm : System.Windows.Forms.Form
  14.     {
  15.         private Exception m_excp;
  16.         private uint m_u32LocalAddr;
  17.         private RW m_direction;
  18.         private ALLOCATION_TYPE m_wAllocType;
  19.         private DWORD m_dwBytes;
  20.         private BOOL m_bAutoInc;
  21.         private System.Windows.Forms.ComboBox cmboAllocType;
  22.         private System.Windows.Forms.TextBox txtLocalAddr;
  23.         private System.Windows.Forms.TextBox txtBuffSize;
  24.         private System.Windows.Forms.Label lblDmaOpen;
  25.         private System.Windows.Forms.ComboBox cmboAction;
  26.         private System.Windows.Forms.Label lblAllocType;
  27.         private System.Windows.Forms.Label label3;
  28.         private System.Windows.Forms.Label label4;
  29.         private System.Windows.Forms.Label label5;
  30.         private System.Windows.Forms.Button btSubmit;
  31.         private System.Windows.Forms.Button btCancel;
  32.         private System.Windows.Forms.GroupBox groupBox1;
  33.         private System.Windows.Forms.Label label1;
  34.         private System.Windows.Forms.Label label2;
  35.         private System.Windows.Forms.CheckBox chkBoxInc;
  36.         private System.ComponentModel.Container components = null;
  37.         public OpenDMAForm(PLX_DMA_CHANNEL channel)
  38.         {
  39.             InitializeComponent();
  40.             lblDmaOpen.Text = (channel == 0)? 
  41.                 "Open DMA - Channel 0":
  42.                 "Open DMA - Channel 1";
  43.             cmboAllocType.Items.AddRange(new object[]{"Scatter Gather", 
  44.                 "Contigious"});
  45.             cmboAction.Items.AddRange(new object[]{"Read", "Write"});
  46.             cmboAllocType.SelectedIndex = 0;
  47.             cmboAction.SelectedIndex = 1;
  48.             chkBoxInc.Checked = true;
  49.         }
  50.         protected override void Dispose( bool disposing )
  51.         {
  52.             if( disposing )
  53.             {
  54.                 if(components != null)
  55.                 {
  56.                     components.Dispose();
  57.                 }
  58.             }
  59.             base.Dispose( disposing );
  60.         }
  61. #region Windows Form Designer generated code
  62.         private void InitializeComponent()
  63.         {
  64.             this.cmboAllocType = new System.Windows.Forms.ComboBox();
  65.             this.txtLocalAddr = new System.Windows.Forms.TextBox();
  66.             this.txtBuffSize = new System.Windows.Forms.TextBox();
  67.             this.lblDmaOpen = new System.Windows.Forms.Label();
  68.             this.cmboAction = new System.Windows.Forms.ComboBox();
  69.             this.lblAllocType = new System.Windows.Forms.Label();
  70.             this.label3 = new System.Windows.Forms.Label();
  71.             this.label4 = new System.Windows.Forms.Label();
  72.             this.label5 = new System.Windows.Forms.Label();
  73.             this.btSubmit = new System.Windows.Forms.Button();
  74.             this.btCancel = new System.Windows.Forms.Button();
  75.             this.groupBox1 = new System.Windows.Forms.GroupBox();
  76.             this.label1 = new System.Windows.Forms.Label();
  77.             this.label2 = new System.Windows.Forms.Label();
  78.             this.chkBoxInc = new System.Windows.Forms.CheckBox();
  79.             this.SuspendLayout();
  80.             // 
  81.             // cmboAllocType
  82.             // 
  83.             this.cmboAllocType.Location = new System.Drawing.Point(29, 52);
  84.             this.cmboAllocType.Name = "cmboAllocType";
  85.             this.cmboAllocType.Size = new System.Drawing.Size(145, 20);
  86.             this.cmboAllocType.TabIndex = 0;
  87.             this.cmboAllocType.Text = "-------  -------";
  88.             // 
  89.             // txtLocalAddr
  90.             // 
  91.             this.txtLocalAddr.Location = new System.Drawing.Point(48, 155);
  92.             this.txtLocalAddr.Name = "txtLocalAddr";
  93.             this.txtLocalAddr.Size = new System.Drawing.Size(120, 21);
  94.             this.txtLocalAddr.TabIndex = 3;
  95.             // 
  96.             // txtBuffSize
  97.             // 
  98.             this.txtBuffSize.Location = new System.Drawing.Point(48, 207);
  99.             this.txtBuffSize.Name = "txtBuffSize";
  100.             this.txtBuffSize.Size = new System.Drawing.Size(120, 21);
  101.             this.txtBuffSize.TabIndex = 4;
  102.             // 
  103.             // lblDmaOpen
  104.             // 
  105.             this.lblDmaOpen.Location = new System.Drawing.Point(67, 9);
  106.             this.lblDmaOpen.Name = "lblDmaOpen";
  107.             this.lblDmaOpen.Size = new System.Drawing.Size(154, 24);
  108.             this.lblDmaOpen.TabIndex = 5;
  109.             this.lblDmaOpen.Text = "Open DMA - Channel 0";
  110.             // 
  111.             // cmboAction
  112.             // 
  113.             this.cmboAction.ItemHeight = 12;
  114.             this.cmboAction.Location = new System.Drawing.Point(29, 103);
  115.             this.cmboAction.Name = "cmboAction";
  116.             this.cmboAction.Size = new System.Drawing.Size(145, 20);
  117.             this.cmboAction.TabIndex = 2;
  118.             this.cmboAction.Text = "------ ------";
  119.             // 
  120.             // lblAllocType
  121.             // 
  122.             this.lblAllocType.Location = new System.Drawing.Point(29, 34);
  123.             this.lblAllocType.Name = "lblAllocType";
  124.             this.lblAllocType.Size = new System.Drawing.Size(153, 18);
  125.             this.lblAllocType.TabIndex = 6;
  126.             this.lblAllocType.Text = "Allocation type";
  127.             // 
  128.             // label3
  129.             // 
  130.             this.label3.Location = new System.Drawing.Point(29, 86);
  131.             this.label3.Name = "label3";
  132.             this.label3.Size = new System.Drawing.Size(134, 17);
  133.             this.label3.TabIndex = 8;
  134.             this.label3.Text = "Read/Write";
  135.             // 
  136.             // label4
  137.             // 
  138.             this.label4.Location = new System.Drawing.Point(29, 138);
  139.             this.label4.Name = "label4";
  140.             this.label4.Size = new System.Drawing.Size(163, 17);
  141.             this.label4.TabIndex = 9;
  142.             this.label4.Text = "DMA local Address (hex)";
  143.             // 
  144.             // label5
  145.             // 
  146.             this.label5.Location = new System.Drawing.Point(29, 190);
  147.             this.label5.Name = "label5";
  148.             this.label5.Size = new System.Drawing.Size(173, 17);
  149.             this.label5.TabIndex = 10;
  150.             this.label5.Text = "DMA buffer size (hex)";
  151.             // 
  152.             // btSubmit
  153.             // 
  154.             this.btSubmit.Location = new System.Drawing.Point(221, 60);
  155.             this.btSubmit.Name = "btSubmit";
  156.             this.btSubmit.Size = new System.Drawing.Size(90, 25);
  157.             this.btSubmit.TabIndex = 11;
  158.             this.btSubmit.Text = "Submit";
  159.             this.btSubmit.Click += new System.EventHandler(this.btSubmit_Click);
  160.             // 
  161.             // btCancel
  162.             // 
  163.             this.btCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
  164.             this.btCancel.Location = new System.Drawing.Point(221, 103);
  165.             this.btCancel.Name = "btCancel";
  166.             this.btCancel.Size = new System.Drawing.Size(90, 25);
  167.             this.btCancel.TabIndex = 12;
  168.             this.btCancel.Text = "Cancel";
  169.             // 
  170.             // groupBox1
  171.             // 
  172.             this.groupBox1.Location = new System.Drawing.Point(202, 43);
  173.             this.groupBox1.Name = "groupBox1";
  174.             this.groupBox1.Size = new System.Drawing.Size(134, 95);
  175.             this.groupBox1.TabIndex = 13;
  176.             this.groupBox1.TabStop = false;
  177.             // 
  178.             // label1
  179.             // 
  180.             this.label1.Location = new System.Drawing.Point(29, 155);
  181.             this.label1.Name = "label1";
  182.             this.label1.Size = new System.Drawing.Size(19, 25);
  183.             this.label1.TabIndex = 14;
  184.             this.label1.Text = "0x";
  185.             // 
  186.             // label2
  187.             // 
  188.             this.label2.Location = new System.Drawing.Point(29, 207);
  189.             this.label2.Name = "label2";
  190.             this.label2.Size = new System.Drawing.Size(19, 25);
  191.             this.label2.TabIndex = 15;
  192.             this.label2.Text = "0x";
  193.             // 
  194.             // chkBoxInc
  195.             // 
  196.             this.chkBoxInc.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  197.             this.chkBoxInc.Location = new System.Drawing.Point(211, 172);
  198.             this.chkBoxInc.Name = "chkBoxInc";
  199.             this.chkBoxInc.Size = new System.Drawing.Size(125, 26);
  200.             this.chkBoxInc.TabIndex = 16;
  201.             this.chkBoxInc.Text = "AutoIncrement Address";
  202.             // 
  203.             // OpenDMAForm
  204.             // 
  205.             this.AcceptButton = this.btSubmit;
  206.             this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  207.             this.CancelButton = this.btCancel;
  208.             this.ClientSize = new System.Drawing.Size(358, 267);
  209.             this.Controls.Add(this.chkBoxInc);
  210.             this.Controls.Add(this.label2);
  211.             this.Controls.Add(this.label1);
  212.             this.Controls.Add(this.btCancel);
  213.             this.Controls.Add(this.btSubmit);
  214.             this.Controls.Add(this.label5);
  215.             this.Controls.Add(this.label4);
  216.             this.Controls.Add(this.label3);
  217.             this.Controls.Add(this.lblAllocType);
  218.             this.Controls.Add(this.lblDmaOpen);
  219.             this.Controls.Add(this.txtBuffSize);
  220.             this.Controls.Add(this.txtLocalAddr);
  221.             this.Controls.Add(this.cmboAction);
  222.             this.Controls.Add(this.cmboAllocType);
  223.             this.Controls.Add(this.groupBox1);
  224.             this.Name = "OpenDMAForm";
  225.             this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
  226.             this.Text = "OpenDMA_Form";
  227.             this.Load += new System.EventHandler(this.OpenDMAForm_Load);
  228.             this.ResumeLayout(false);
  229.             this.PerformLayout();
  230.         }
  231. #endregion
  232.         public bool GetInput(ref uint u32LocalAddr, ref RW direction, 
  233.             ref ALLOCATION_TYPE wAllocType, ref DWORD dwBytes, ref BOOL 
  234.             bAutoInc)                        
  235.         {
  236.             DialogResult result = DialogResult.Retry;
  237.             while((result = ShowDialog()) == DialogResult.Retry);
  238.             if (result != DialogResult.OK)
  239.                 return false;
  240.             u32LocalAddr = m_u32LocalAddr;
  241.             direction = m_direction;
  242.             wAllocType = m_wAllocType;
  243.             dwBytes = m_dwBytes;
  244.             bAutoInc = m_bAutoInc;
  245.             return true; 
  246.         }
  247.         private void btSubmit_Click(object sender, System.EventArgs e)
  248.         {
  249.             DialogResult = DialogResult.OK;
  250.             try
  251.             {
  252.                 TranslateInput();
  253.             }
  254.             catch 
  255.             {
  256.                 MessageBox.Show(m_excp.Message ,"Input Entry Error",
  257.                     MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  258.                 DialogResult = DialogResult.Retry;
  259.             }            
  260.         }
  261.         private void TranslateInput()
  262.         {
  263.             m_excp = new Exception("Select Allocation Type");
  264.             if((uint)cmboAllocType.SelectedIndex == 0xffffffff)
  265.                 throw m_excp;
  266.             m_wAllocType = (cmboAllocType.SelectedIndex == 0)?
  267.                 ALLOCATION_TYPE.SG: ALLOCATION_TYPE.CONTIG;
  268.             m_excp = new Exception("Select DMA direction");
  269.             if((uint)cmboAction.SelectedIndex == 0xffffffff)
  270.                 throw m_excp;
  271.             m_direction = (cmboAction.SelectedIndex == 0)?
  272.                 RW.READ : RW.WRITE;
  273.             m_excp = new Exception("Enter local DMA address. " + 
  274.                 "Entered value should be a hex number");
  275.             m_u32LocalAddr = (DWORD)Convert.ToInt32(txtLocalAddr.Text,16);
  276.             m_excp = new Exception("Enter the DMA buffer's size in bytes. " +
  277.                 "Entered value should be a hex number");
  278.             m_dwBytes = (DWORD)Convert.ToInt32(txtBuffSize.Text,16);
  279.             
  280.             m_bAutoInc = chkBoxInc.Checked;
  281.         }
  282.         private void OpenDMAForm_Load(object sender, EventArgs e)
  283.         {
  284.             
  285.         }                
  286.     }
  287. }