1986 lines
74 KiB
C#
1986 lines
74 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.ComponentModel;
|
||
using System.Data;
|
||
using System.Drawing;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
using System.Windows.Forms;
|
||
using System.IO.Ports;
|
||
using System.Threading;
|
||
using System.IO;
|
||
using Renci.SshNet;
|
||
|
||
// Based on, see below
|
||
// https://www.codeproject.com/Articles/678025/Serial-Comms-in-Csharp-for-Beginners
|
||
|
||
|
||
namespace uartTestGUI
|
||
{
|
||
public partial class Form1 : Form
|
||
{
|
||
|
||
|
||
bool system_on = false;
|
||
|
||
SshClient ssh_client;
|
||
|
||
public Form1()
|
||
{
|
||
InitializeComponent();
|
||
|
||
if (cw_w1.Checked == true)
|
||
{
|
||
end_freq_w1.ReadOnly = true;
|
||
}
|
||
if (cw_w2.Checked == true)
|
||
{
|
||
end_freq_w2.ReadOnly = true;
|
||
}
|
||
if (cw_w3.Checked == true)
|
||
{
|
||
end_freq_w3.ReadOnly = true;
|
||
}
|
||
if (cw_w4.Checked == true)
|
||
{
|
||
end_freq_w4.ReadOnly = true;
|
||
}
|
||
|
||
|
||
|
||
// Thread oThread = new Thread(new ThreadStart(backgroundTask));
|
||
// oThread.IsBackground = true;
|
||
// oThread.Start();
|
||
|
||
|
||
}
|
||
|
||
public void backgroundTask()
|
||
{
|
||
// while (true == status_update_en.Checked)
|
||
while (true)
|
||
{
|
||
|
||
if (true == system_on)
|
||
{
|
||
|
||
}
|
||
|
||
Thread.Sleep(1000);
|
||
}
|
||
|
||
}
|
||
|
||
|
||
private void send_button_w1_Click(object sender, EventArgs e)
|
||
{
|
||
send_button_w1.Text = "Loading...";
|
||
send_button_w1.BackColor = Color.LightGreen;
|
||
|
||
double actual_start_freq;
|
||
double actual_end_freq;
|
||
double actual_duration;
|
||
double actual_idle_samples;
|
||
|
||
string str = String.Empty;
|
||
str += "************************";
|
||
str += "\n";
|
||
richTextBox0.Text = str;
|
||
|
||
double start_freq = (Convert.ToDouble(start_freq_w1.Text)) * 1e6;
|
||
double end_freq = (Convert.ToDouble(end_freq_w1.Text)) * 1e6;
|
||
double duration = (Convert.ToDouble(duration_w1.Text)) * 1e-6;
|
||
double idle_samples = (Convert.ToDouble(idle_samples_w1.Text)) * 1e-6;
|
||
uint phase_inc_dwell = (Convert.ToUInt32(phase_inc_dwell_w1.Text, 10));
|
||
|
||
ComputeSend_PDW(1, chirp_w1.Checked, start_freq, end_freq, duration, idle_samples, phase_inc_dwell, out actual_start_freq, out actual_end_freq, out actual_duration, out actual_idle_samples);
|
||
actual_start_freq_w1.Text = actual_start_freq.ToString("G6");
|
||
actual_end_freq_w1.Text = actual_end_freq.ToString("G6");
|
||
actual_duration_w1.Text = actual_duration.ToString("G6");
|
||
actual_idle_samples_w1.Text = actual_idle_samples.ToString("G6");
|
||
|
||
double scale_factor = (double)scale_factor_w1.Value;
|
||
Set_ScaleFactor(1, scale_factor, iq_swap_w1.Checked);
|
||
|
||
ssh_WriteReg("0x83000028", "00000000");// phase_off_1
|
||
dds_reg28.Text = "00000000";
|
||
|
||
send_button_w1.Text = "Load";
|
||
send_button_w1.BackColor = Color.Gainsboro;
|
||
dds_send_w1.BackColor = Color.Yellow;
|
||
|
||
}
|
||
|
||
private void SendWord_Decimal(string cmd, int word)
|
||
{
|
||
string str = String.Empty;
|
||
|
||
str += cmd;
|
||
str += word.ToString("D");
|
||
str += "\n";
|
||
|
||
richTextBox0.AppendText(str);
|
||
|
||
}
|
||
|
||
private void Set_ScaleFactor(uint chan, double scale_db, bool flag)
|
||
{
|
||
string str = String.Empty;
|
||
|
||
uint scale_factor = (uint)(Math.Pow(2.0, scale_db / 6.0) * 0x8000);
|
||
uint swap_sf;
|
||
|
||
Console.WriteLine("scale_db: {0} ", scale_db);
|
||
str += "scale_db: ";
|
||
str += scale_db.ToString("N1");
|
||
str += "\n";
|
||
richTextBox0.AppendText(str);
|
||
|
||
swap_sf = scale_factor;
|
||
|
||
if (flag == true)
|
||
{
|
||
swap_sf = swap_sf | 0x10000;
|
||
}
|
||
else
|
||
{
|
||
swap_sf = swap_sf & 0xFFFEFFFF;
|
||
}
|
||
|
||
str = String.Empty;
|
||
str += "scale_factor: ";
|
||
str += scale_factor.ToString("X8");
|
||
str += "\n";
|
||
richTextBox0.AppendText(str);
|
||
|
||
if (chan == 1)
|
||
{
|
||
ssh_WriteReg("0x83000010", "0x" + scale_factor.ToString("X8"));
|
||
dds_reg10.Text = scale_factor.ToString("X8");
|
||
|
||
ssh_WriteReg("0x8300002C", "0x" + swap_sf.ToString("X8"));
|
||
dds_reg2C.Text = swap_sf.ToString("X8");
|
||
}
|
||
else if (chan == 2)
|
||
{
|
||
ssh_WriteReg("0x83000030", "0x" + scale_factor.ToString("X8"));
|
||
dds_reg30.Text = scale_factor.ToString("X8");
|
||
|
||
ssh_WriteReg("0x8300004C", "0x" + swap_sf.ToString("X8"));
|
||
dds_reg4C.Text = swap_sf.ToString("X8");
|
||
}
|
||
else if (chan == 3)
|
||
{
|
||
ssh_WriteReg("0x83000050", "0x" + scale_factor.ToString("X8"));
|
||
dds_reg50.Text = scale_factor.ToString("X8");
|
||
|
||
ssh_WriteReg("0x8300006C", "0x" + swap_sf.ToString("X8"));
|
||
dds_reg6C.Text = swap_sf.ToString("X8");
|
||
}
|
||
else if (chan == 4)
|
||
{
|
||
ssh_WriteReg("0x83000070", "0x" + scale_factor.ToString("X8"));
|
||
dds_reg70.Text = scale_factor.ToString("X8");
|
||
|
||
ssh_WriteReg("0x8300008C", "0x" + swap_sf.ToString("X8"));
|
||
dds_reg8C.Text = swap_sf.ToString("X8");
|
||
}
|
||
|
||
}
|
||
|
||
|
||
private void dac_on_Click(object sender, EventArgs e)
|
||
{
|
||
// send_button_w1.Text = "Send";
|
||
|
||
ssh_WriteReg("0x83000004", "0x00000000"); // set bit0 - 0 = RF On
|
||
dds_reg04.Text = ssh_ReadReg("0x83000004");
|
||
|
||
dac_off.BackColor = Color.LightGray;
|
||
dac_on.BackColor = Color.LightGreen;
|
||
system_status.BackColor = Color.LightGreen;
|
||
if (tx_fiber_data_src_adc.Checked == true)
|
||
{
|
||
system_status.Text = "ARMED";
|
||
|
||
}
|
||
else if (tx_fiber_data_src_dds.Checked == true)
|
||
{
|
||
system_status.Text = "ARMED";
|
||
}
|
||
|
||
system_on = true;
|
||
}
|
||
|
||
private void dac_off_Click(object sender, EventArgs e)
|
||
{
|
||
// send_button_w1.Text = "Load";
|
||
|
||
ssh_WriteReg("0x83000004", "0x00000001"); // set bit0 - 1 = RF Off
|
||
dds_reg04.Text = ssh_ReadReg("0x83000004");
|
||
|
||
system_status.Text = "OFF";
|
||
dac_on.BackColor = Color.LightGray;
|
||
dac_off.BackColor = Color.Red;
|
||
system_status.BackColor = Color.LightGray;
|
||
system_on = false;
|
||
}
|
||
|
||
private void chirp_w1_Click(object sender, EventArgs e)
|
||
{
|
||
end_freq_w1.ReadOnly = false;
|
||
}
|
||
|
||
private void cw_w1_Click(object sender, EventArgs e)
|
||
{
|
||
end_freq_w1.ReadOnly = true;
|
||
}
|
||
|
||
private void chirp_w2_Click(object sender, EventArgs e)
|
||
{
|
||
end_freq_w2.ReadOnly = false;
|
||
}
|
||
|
||
private void cw_w2_Click(object sender, EventArgs e)
|
||
{
|
||
end_freq_w2.ReadOnly = true;
|
||
}
|
||
|
||
|
||
private void chirp_w3_Click(object sender, EventArgs e)
|
||
{
|
||
end_freq_w3.ReadOnly = false;
|
||
}
|
||
|
||
private void cw_w3_Click(object sender, EventArgs e)
|
||
{
|
||
end_freq_w3.ReadOnly = true;
|
||
}
|
||
|
||
|
||
|
||
private void save_pdw_file_Click(object sender, EventArgs e)
|
||
{
|
||
SaveFileDialog saveFileDialog = new SaveFileDialog();
|
||
saveFileDialog.Title = "Save PDW File";
|
||
saveFileDialog.Filter = "PDW Files|*.txt";
|
||
saveFileDialog.RestoreDirectory = true;
|
||
|
||
string pdw_data = String.Empty;
|
||
|
||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||
{
|
||
string filename = saveFileDialog.FileName;
|
||
|
||
Console.WriteLine("filename: {0} ", filename);
|
||
|
||
try
|
||
{
|
||
using (StreamWriter writer = new StreamWriter(filename))
|
||
{
|
||
pdw_data = idx_w1.Text;
|
||
pdw_data += ",";
|
||
pdw_data += (chirp_w1.Checked == true) ? "1" : "0";
|
||
pdw_data += ",";
|
||
pdw_data += start_freq_w1.Text;
|
||
pdw_data += ",";
|
||
pdw_data += end_freq_w1.Text;
|
||
pdw_data += ",";
|
||
pdw_data += duration_w1.Text;
|
||
pdw_data += ",";
|
||
pdw_data += idle_samples_w1.Text;
|
||
pdw_data += ",";
|
||
pdw_data += phase_inc_dwell_w1.Text;
|
||
pdw_data += ",";
|
||
pdw_data += scale_factor_w1.Value.ToString("N1");
|
||
pdw_data += ",";
|
||
pdw_data += (iq_swap_w1.Checked == true) ? "1" : "0";
|
||
writer.WriteLine(pdw_data);
|
||
|
||
pdw_data = String.Empty;
|
||
pdw_data = idx_w2.Text;
|
||
pdw_data += ",";
|
||
pdw_data += (chirp_w2.Checked == true) ? "1" : "0";
|
||
pdw_data += ",";
|
||
pdw_data += start_freq_w2.Text;
|
||
pdw_data += ",";
|
||
pdw_data += end_freq_w2.Text;
|
||
pdw_data += ",";
|
||
pdw_data += duration_w2.Text;
|
||
pdw_data += ",";
|
||
pdw_data += idle_samples_w2.Text;
|
||
pdw_data += ",";
|
||
pdw_data += phase_inc_dwell_w2.Text;
|
||
pdw_data += ",";
|
||
pdw_data += scale_factor_w2.Value.ToString("N1");
|
||
pdw_data += ",";
|
||
pdw_data += (iq_swap_w2.Checked == true) ? "1" : "0";
|
||
writer.WriteLine(pdw_data);
|
||
|
||
pdw_data = String.Empty;
|
||
pdw_data = idx_w3.Text;
|
||
pdw_data += ",";
|
||
pdw_data += (chirp_w3.Checked == true) ? "1" : "0";
|
||
pdw_data += ",";
|
||
pdw_data += start_freq_w3.Text;
|
||
pdw_data += ",";
|
||
pdw_data += end_freq_w3.Text;
|
||
pdw_data += ",";
|
||
pdw_data += duration_w3.Text;
|
||
pdw_data += ",";
|
||
pdw_data += idle_samples_w3.Text;
|
||
pdw_data += ",";
|
||
pdw_data += phase_inc_dwell_w3.Text;
|
||
pdw_data += ",";
|
||
pdw_data += scale_factor_w3.Value.ToString("N1");
|
||
pdw_data += ",";
|
||
pdw_data += (iq_swap_w3.Checked == true) ? "1" : "0";
|
||
writer.WriteLine(pdw_data);
|
||
|
||
pdw_data = String.Empty;
|
||
pdw_data = idx_w4.Text;
|
||
pdw_data += ",";
|
||
pdw_data += (chirp_w4.Checked == true) ? "1" : "0";
|
||
pdw_data += ",";
|
||
pdw_data += start_freq_w4.Text;
|
||
pdw_data += ",";
|
||
pdw_data += end_freq_w4.Text;
|
||
pdw_data += ",";
|
||
pdw_data += duration_w4.Text;
|
||
pdw_data += ",";
|
||
pdw_data += idle_samples_w4.Text;
|
||
pdw_data += ",";
|
||
pdw_data += phase_inc_dwell_w4.Text;
|
||
pdw_data += ",";
|
||
pdw_data += scale_factor_w4.Value.ToString("N1");
|
||
pdw_data += ",";
|
||
pdw_data += (iq_swap_w4.Checked == true) ? "1" : "0";
|
||
writer.WriteLine(pdw_data);
|
||
|
||
|
||
|
||
}
|
||
}
|
||
catch (FileNotFoundException ioEx)
|
||
{
|
||
Console.WriteLine(ioEx.Message);
|
||
}
|
||
}
|
||
}
|
||
|
||
private void load_pdw_file_Click(object sender, EventArgs e)
|
||
{
|
||
OpenFileDialog openFileDialog = new OpenFileDialog();
|
||
openFileDialog.Title = "Read PDW File";
|
||
openFileDialog.Filter = "PDW Files|*.txt";
|
||
openFileDialog.RestoreDirectory = true;
|
||
|
||
string pdw_data = String.Empty;
|
||
|
||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||
{
|
||
string filename = openFileDialog.FileName;
|
||
|
||
Console.WriteLine("filename: {0} ", filename);
|
||
|
||
try
|
||
{
|
||
using (StreamReader reader = new StreamReader(filename))
|
||
{
|
||
pdw_data = reader.ReadLine(); // ReadLine(pdw_data); 0
|
||
if (pdw_data == null)
|
||
{
|
||
richTextBox0.AppendText("**End of File\n");
|
||
return;
|
||
}
|
||
richTextBox0.AppendText(pdw_data + "\n");
|
||
string[] data_item = pdw_data.Split(',');
|
||
|
||
for (int i = 0; i < data_item.Length; ++i)
|
||
{
|
||
richTextBox0.AppendText(i.ToString() + ":" + data_item[i] + "\n");
|
||
}
|
||
|
||
idx_w1.Text = data_item[0];
|
||
chirp_w1.Checked = (data_item[1] == "1") ? true : false;
|
||
cw_w1.Checked = (data_item[1] == "0") ? true : false;
|
||
start_freq_w1.Text = data_item[2];
|
||
end_freq_w1.Text = data_item[3];
|
||
duration_w1.Text = data_item[4];
|
||
idle_samples_w1.Text = data_item[5];
|
||
phase_inc_dwell_w1.Text = data_item[6];
|
||
scale_factor_w1.Value = Convert.ToDecimal(data_item[7]);
|
||
iq_swap_w1.Checked = (data_item[8] == "1") ? true : false;
|
||
|
||
pdw_data = reader.ReadLine(); // ReadLine(pdw_data);1
|
||
if (pdw_data == null)
|
||
{
|
||
richTextBox0.AppendText("**End of File\n");
|
||
return;
|
||
}
|
||
richTextBox0.AppendText(pdw_data + "\n");
|
||
data_item = pdw_data.Split(',');
|
||
for (int i = 0; i < data_item.Length; ++i)
|
||
{
|
||
richTextBox0.AppendText(i.ToString() + ":" + data_item[i] + "\n");
|
||
}
|
||
|
||
idx_w2.Text = data_item[0];
|
||
chirp_w2.Checked = (data_item[1] == "1") ? true : false;
|
||
cw_w2.Checked = (data_item[1] == "0") ? true : false;
|
||
start_freq_w2.Text = data_item[2];
|
||
end_freq_w2.Text = data_item[3];
|
||
duration_w2.Text = data_item[4];
|
||
idle_samples_w2.Text = data_item[5];
|
||
phase_inc_dwell_w2.Text = data_item[6];
|
||
scale_factor_w2.Value = Convert.ToDecimal(data_item[7]);
|
||
iq_swap_w2.Checked = (data_item[8] == "1") ? true : false;
|
||
|
||
pdw_data = reader.ReadLine(); // ReadLine(pdw_data);2
|
||
if (pdw_data == null)
|
||
{
|
||
richTextBox0.AppendText("**End of File\n");
|
||
return;
|
||
}
|
||
richTextBox0.AppendText(pdw_data + "\n");
|
||
data_item = pdw_data.Split(',');
|
||
for (int i = 0; i < data_item.Length; ++i)
|
||
{
|
||
richTextBox0.AppendText(i.ToString() + ":" + data_item[i] + "\n");
|
||
}
|
||
|
||
idx_w3.Text = data_item[0];
|
||
chirp_w3.Checked = (data_item[1] == "1") ? true : false;
|
||
cw_w3.Checked = (data_item[1] == "0") ? true : false;
|
||
start_freq_w3.Text = data_item[2];
|
||
end_freq_w3.Text = data_item[3];
|
||
duration_w3.Text = data_item[4];
|
||
idle_samples_w3.Text = data_item[5];
|
||
phase_inc_dwell_w3.Text = data_item[6];
|
||
scale_factor_w3.Value = Convert.ToDecimal(data_item[7]);
|
||
iq_swap_w3.Checked = (data_item[8] == "1") ? true : false;
|
||
|
||
pdw_data = reader.ReadLine(); // ReadLine(pdw_data);3
|
||
if (pdw_data == null)
|
||
{
|
||
richTextBox0.AppendText("**End of File\n");
|
||
return;
|
||
}
|
||
richTextBox0.AppendText(pdw_data + "\n");
|
||
data_item = pdw_data.Split(',');
|
||
for (int i = 0; i < data_item.Length; ++i)
|
||
{
|
||
richTextBox0.AppendText(i.ToString() + ":" + data_item[i] + "\n");
|
||
}
|
||
|
||
idx_w4.Text = data_item[0];
|
||
chirp_w4.Checked = (data_item[1] == "1") ? true : false;
|
||
cw_w4.Checked = (data_item[1] == "0") ? true : false;
|
||
start_freq_w4.Text = data_item[2];
|
||
end_freq_w4.Text = data_item[3];
|
||
duration_w4.Text = data_item[4];
|
||
idle_samples_w4.Text = data_item[5];
|
||
phase_inc_dwell_w4.Text = data_item[6];
|
||
scale_factor_w4.Value = Convert.ToDecimal(data_item[7]);
|
||
iq_swap_w4.Checked = (data_item[8] == "1") ? true : false;
|
||
|
||
pdw_data = reader.ReadLine(); // ReadLine(pdw_data);4
|
||
if (pdw_data == null)
|
||
{
|
||
richTextBox0.AppendText("**End of File\n");
|
||
return;
|
||
}
|
||
richTextBox0.AppendText(pdw_data + "\n");
|
||
data_item = pdw_data.Split(',');
|
||
for (int i = 0; i < data_item.Length; ++i)
|
||
{
|
||
richTextBox0.AppendText(i.ToString() + ":" + data_item[i] + "\n");
|
||
}
|
||
|
||
|
||
}
|
||
}
|
||
catch (FileNotFoundException ioEx)
|
||
{
|
||
Console.WriteLine(ioEx.Message);
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
private void chirp_w4_Click(object sender, EventArgs e)
|
||
{
|
||
end_freq_w4.ReadOnly = false;
|
||
}
|
||
private void cw_w4_Click(object sender, EventArgs e)
|
||
{
|
||
end_freq_w4.ReadOnly = true;
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
private void ComputeSend_PDW(uint chan, bool wave_type, double start_freq, double end_freq, double duration, double idle_samples, uint phase_inc_dwell, out double actual_start_freq, out double actual_end_freq, out double actual_duration, out double actual_idle_samples)
|
||
{
|
||
double sample_rate = 250e6;
|
||
string str = String.Empty;
|
||
double MULT = 4294967296.0;
|
||
int step_size_t;
|
||
|
||
str += "************************";
|
||
str += "\n";
|
||
richTextBox0.AppendText(str); //.Text = str; //
|
||
|
||
str = String.Empty;
|
||
str += "chan: ";
|
||
str += chan.ToString("X1");
|
||
str += "\n";
|
||
richTextBox0.AppendText(str);
|
||
|
||
Console.WriteLine("start_freq: {0} ", start_freq);
|
||
str = String.Empty;
|
||
str += "start_freq: ";
|
||
str += start_freq.ToString("F");
|
||
str += "\n";
|
||
richTextBox0.AppendText(str);
|
||
|
||
Console.WriteLine("end_freq: {0} ", end_freq);
|
||
str = String.Empty;
|
||
str += "end_freq: ";
|
||
str += end_freq.ToString("F");
|
||
str += "\n";
|
||
richTextBox0.AppendText(str);
|
||
|
||
Console.WriteLine("duration: {0} ", duration);
|
||
str = String.Empty;
|
||
str += "duration: ";
|
||
str += duration.ToString("G6");
|
||
str += "\n\n";
|
||
richTextBox0.AppendText(str);
|
||
|
||
Console.WriteLine("idle_samples: {0} ", idle_samples);
|
||
str = String.Empty;
|
||
str += "idle_samples: ";
|
||
str += idle_samples.ToString("G6");
|
||
str += "\n";
|
||
richTextBox0.AppendText(str);
|
||
|
||
double num_samples = duration / (1 / sample_rate); // num_samples = duration / (1/sample_rate)
|
||
Console.WriteLine("num_samples: {0} ", num_samples);
|
||
str = String.Empty;
|
||
str += "num_samples: ";
|
||
str += num_samples.ToString("F");
|
||
str += "\n";
|
||
richTextBox0.AppendText(str);
|
||
uint num_samples_t = (uint)Math.Round(num_samples);/////////////////////////////////////
|
||
str = String.Empty;
|
||
str += "num_samples_t: ";
|
||
str += num_samples_t.ToString("D");
|
||
str += "\n\n";
|
||
richTextBox0.AppendText(str);
|
||
|
||
actual_duration = num_samples / sample_rate;
|
||
str = String.Empty;
|
||
str += "actual_duration: ";
|
||
str += actual_duration.ToString("G6");
|
||
str += "\n\n";
|
||
richTextBox0.AppendText(str);
|
||
|
||
double start_freq_phase_inc = MULT * (start_freq / sample_rate); // PhaseInc = 2^32 * (desired freq / sample rate)
|
||
Console.WriteLine("start_freq_phase_inc: {0} ", start_freq_phase_inc);
|
||
str = String.Empty;
|
||
str += "start_freq_phase_inc: ";
|
||
str += start_freq_phase_inc.ToString("F");
|
||
str += "\n";
|
||
richTextBox0.AppendText(str);
|
||
|
||
double t_double = Math.Round(start_freq_phase_inc, MidpointRounding.AwayFromZero);//////////////////////////////
|
||
str = String.Empty;
|
||
str += "t_double: ";
|
||
str += t_double.ToString("F");
|
||
str += "\n";
|
||
richTextBox0.AppendText(str);
|
||
|
||
int start_freq_phase_inc_t = (int)t_double;
|
||
str = String.Empty;
|
||
str += "start_freq_phase_inc_t: ";
|
||
str += start_freq_phase_inc_t.ToString("D");
|
||
str += "\n";
|
||
richTextBox0.AppendText(str);
|
||
actual_start_freq = start_freq_phase_inc_t * sample_rate / MULT; // desired freq = PhaseInc * sample rate / 2^32
|
||
str = String.Empty;
|
||
str += "actual_start_freq: ";
|
||
str += actual_start_freq.ToString("G6");
|
||
str += "\n\n";
|
||
richTextBox0.AppendText(str);
|
||
|
||
if (wave_type == true)
|
||
{
|
||
double end_freq_phase_inc = MULT * (end_freq / sample_rate); // PhaseInc = 2^32 * (desired freq / sample rate)
|
||
Console.WriteLine("end_freq_phase_inc: {0} ", end_freq_phase_inc);
|
||
str = String.Empty;
|
||
str += "end_freq_phase_inc: ";
|
||
str += end_freq_phase_inc.ToString("F");
|
||
str += "\n";
|
||
richTextBox0.AppendText(str);
|
||
int end_freq_phase_inc_t = (int)Math.Round(end_freq_phase_inc);//////////////////////////////////////
|
||
str = String.Empty;
|
||
str += "end_freq_phase_inc_t: ";
|
||
str += end_freq_phase_inc_t.ToString("D");
|
||
str += "\n";
|
||
richTextBox0.AppendText(str);
|
||
actual_end_freq = end_freq_phase_inc_t * sample_rate / MULT; // desired freq = PhaseInc * sample rate / 2^32
|
||
|
||
double step_size = (double)(end_freq_phase_inc - start_freq_phase_inc) / num_samples; // step_size = start_phase_inc - end_phase_inc / num_samples
|
||
Console.WriteLine("step_size: {0} ", step_size);
|
||
str = String.Empty;
|
||
str += "step_size: ";
|
||
str += step_size.ToString("F");
|
||
str += "\n";
|
||
richTextBox0.AppendText(str);
|
||
step_size_t = (int)Math.Round(step_size);///////////////////////////
|
||
}
|
||
else
|
||
{
|
||
str = String.Empty;
|
||
str += "*****CW******: ";
|
||
str += "\n";
|
||
richTextBox0.AppendText(str);
|
||
step_size_t = 0;
|
||
actual_end_freq = actual_start_freq;
|
||
}
|
||
|
||
double idle_samples_d = idle_samples / (1 / sample_rate);
|
||
uint idle_samples_t = (uint)Math.Round(idle_samples_d);
|
||
actual_idle_samples = idle_samples_t * (1 / sample_rate);
|
||
str = String.Empty;
|
||
str += "actual_idle_samples: ";
|
||
str += actual_idle_samples.ToString("F");
|
||
str += "\n";
|
||
richTextBox0.AppendText(str);
|
||
|
||
str = String.Empty;
|
||
str += "step_size_t: ";
|
||
str += step_size_t.ToString("D");
|
||
str += "\n";
|
||
richTextBox0.AppendText(str);
|
||
|
||
str = String.Empty;
|
||
str += "actual_end_freq: ";
|
||
str += actual_end_freq.ToString("F");
|
||
str += "\n";
|
||
richTextBox0.AppendText(str);
|
||
|
||
str = String.Empty;
|
||
str += "--------------------------";
|
||
str += "\n";
|
||
richTextBox0.AppendText(str);
|
||
|
||
str = String.Empty;
|
||
str += "phase_inc_dwell: ";
|
||
str += phase_inc_dwell.ToString("X8");
|
||
str += "\n";
|
||
richTextBox0.AppendText(str);
|
||
if (chan == 1)
|
||
{
|
||
ssh_WriteReg("0x83000014", "0x" + phase_inc_dwell.ToString("X8"));
|
||
dds_reg14.Text = phase_inc_dwell.ToString("X8");
|
||
}
|
||
else if (chan == 2)
|
||
{
|
||
ssh_WriteReg("0x83000034", "0x" + phase_inc_dwell.ToString("X8"));
|
||
dds_reg34.Text = phase_inc_dwell.ToString("X8");
|
||
}
|
||
else if (chan == 3)
|
||
{
|
||
ssh_WriteReg("0x83000054", "0x" + phase_inc_dwell.ToString("X8"));
|
||
dds_reg54.Text = phase_inc_dwell.ToString("X8");
|
||
}
|
||
else if (chan == 4)
|
||
{
|
||
ssh_WriteReg("0x83000074", "0x" + phase_inc_dwell.ToString("X8"));
|
||
dds_reg74.Text = phase_inc_dwell.ToString("X8");
|
||
}
|
||
|
||
|
||
str = String.Empty;
|
||
str += "step_size_t: ";
|
||
str += step_size_t.ToString("X8");
|
||
str += "\n";
|
||
richTextBox0.AppendText(str);
|
||
if (chan == 1)
|
||
{
|
||
ssh_WriteReg("0x83000018", "0x" + step_size_t.ToString("X8"));
|
||
dds_reg18.Text = step_size_t.ToString("X8");
|
||
}
|
||
else if (chan == 2)
|
||
{
|
||
ssh_WriteReg("0x83000038", "0x" + step_size_t.ToString("X8"));
|
||
dds_reg38.Text = step_size_t.ToString("X8");
|
||
}
|
||
else if (chan == 3)
|
||
{
|
||
ssh_WriteReg("0x83000058", "0x" + step_size_t.ToString("X8"));
|
||
dds_reg58.Text = step_size_t.ToString("X8");
|
||
}
|
||
else if (chan == 4)
|
||
{
|
||
ssh_WriteReg("0x83000078", "0x" + step_size_t.ToString("X8"));
|
||
dds_reg78.Text = step_size_t.ToString("X8");
|
||
}
|
||
|
||
|
||
str = String.Empty;
|
||
str += "idle_samples_t: ";
|
||
str += idle_samples_t.ToString("X8");
|
||
str += "\n";
|
||
richTextBox0.AppendText(str);
|
||
if (chan == 1)
|
||
{
|
||
ssh_WriteReg("0x8300001C", "0x" + idle_samples_t.ToString("X8"));
|
||
dds_reg1C.Text = idle_samples_t.ToString("X8");
|
||
}
|
||
else if (chan == 2)
|
||
{
|
||
ssh_WriteReg("0x8300003C", "0x" + idle_samples_t.ToString("X8"));
|
||
dds_reg3C.Text = idle_samples_t.ToString("X8");
|
||
}
|
||
else if (chan == 3)
|
||
{
|
||
ssh_WriteReg("0x8300005C", "0x" + idle_samples_t.ToString("X8"));
|
||
dds_reg5C.Text = idle_samples_t.ToString("X8");
|
||
}
|
||
else if (chan == 4)
|
||
{
|
||
ssh_WriteReg("0x8300007C", "0x" + idle_samples_t.ToString("X8"));
|
||
dds_reg7C.Text = idle_samples_t.ToString("X8");
|
||
}
|
||
|
||
|
||
str = String.Empty;
|
||
str += "num_samples_t: ";
|
||
str += num_samples_t.ToString("X8");
|
||
str += "\n";
|
||
richTextBox0.AppendText(str);
|
||
if (chan == 1)
|
||
{
|
||
ssh_WriteReg("0x83000020", "0x" + num_samples_t.ToString("X8"));
|
||
dds_reg20.Text = num_samples_t.ToString("X8");
|
||
}
|
||
else if (chan == 2)
|
||
{
|
||
ssh_WriteReg("0x83000040", "0x" + num_samples_t.ToString("X8"));
|
||
dds_reg40.Text = num_samples_t.ToString("X8");
|
||
}
|
||
else if (chan == 3)
|
||
{
|
||
ssh_WriteReg("0x83000060", "0x" + num_samples_t.ToString("X8"));
|
||
dds_reg60.Text = num_samples_t.ToString("X8");
|
||
}
|
||
else if (chan == 4)
|
||
{
|
||
ssh_WriteReg("0x83000080", "0x" + num_samples_t.ToString("X8"));
|
||
dds_reg80.Text = num_samples_t.ToString("X8");
|
||
}
|
||
|
||
str = String.Empty;
|
||
str += "start_freq_phase_inc_t: ";
|
||
str += start_freq_phase_inc_t.ToString("X8");
|
||
str += "\n";
|
||
richTextBox0.AppendText(str);
|
||
if (chan == 1)
|
||
{
|
||
ssh_WriteReg("0x83000024", "0x" + start_freq_phase_inc_t.ToString("X8"));
|
||
dds_reg24.Text = start_freq_phase_inc_t.ToString("X8");
|
||
}
|
||
else if (chan == 2)
|
||
{
|
||
ssh_WriteReg("0x83000044", "0x" + start_freq_phase_inc_t.ToString("X8"));
|
||
dds_reg44.Text = start_freq_phase_inc_t.ToString("X8");
|
||
}
|
||
else if (chan == 3)
|
||
{
|
||
ssh_WriteReg("0x83000064", "0x" + start_freq_phase_inc_t.ToString("X8"));
|
||
dds_reg64.Text = start_freq_phase_inc_t.ToString("X8");
|
||
}
|
||
else if (chan == 4)
|
||
{
|
||
ssh_WriteReg("0x83000084", "0x" + start_freq_phase_inc_t.ToString("X8"));
|
||
dds_reg84.Text = start_freq_phase_inc_t.ToString("X8");
|
||
}
|
||
|
||
|
||
|
||
|
||
}
|
||
|
||
private void duration_mode_Click(object sender, EventArgs e)
|
||
{
|
||
string str = String.Empty;
|
||
|
||
if (duration_mode.Checked == true)
|
||
{
|
||
int duration_ms_cnt_int = (Convert.ToInt32(duration_ms_cnt.Text, 10));
|
||
SendWord_Decimal("G", duration_ms_cnt_int);
|
||
Thread.Sleep(500);
|
||
|
||
str += "M3";
|
||
str += "\n";
|
||
}
|
||
else
|
||
{
|
||
str += "M2";
|
||
str += "\n";
|
||
}
|
||
|
||
|
||
}
|
||
|
||
|
||
string ssh_ReadReg(string addr)
|
||
{
|
||
SshCommand cmd;
|
||
string str = String.Empty;
|
||
string str1 = String.Empty;
|
||
if (true == ssh_client.IsConnected)
|
||
{
|
||
str1 = "devmem " + addr;
|
||
Console.WriteLine("ssh_ReadReg(): Command: " + str1);
|
||
// Console.WriteLine(str1);
|
||
toolStripStatusLabel1.Text = "ssh_ReadReg(): Command: " + str1;
|
||
|
||
cmd = ssh_client.RunCommand(str1);
|
||
str = cmd.Result;
|
||
Console.WriteLine("ssh_ReadReg(): Response:" + str);
|
||
toolStripStatusLabel1.Text = "ssh_ReadReg(): Response:" + str;
|
||
// Console.WriteLine(str);
|
||
return str.Substring(2, 8);
|
||
}
|
||
return "FFFFFFFF";
|
||
}
|
||
|
||
void ssh_WriteReg(string addr, string val)
|
||
{
|
||
SshCommand cmd;
|
||
string str = String.Empty;
|
||
|
||
if (true == ssh_client.IsConnected)
|
||
{
|
||
str = "devmem " + addr + " 32 " + val;
|
||
Console.WriteLine("ssh_WriteReg(): Command:" + str);
|
||
toolStripStatusLabel1.Text = "ssh_ReadReg(): Response:" + str;
|
||
// Console.WriteLine(str); // Get the command output
|
||
|
||
cmd = ssh_client.RunCommand(str);// Execute a command
|
||
|
||
Console.WriteLine("ssh_WriteReg(): Response:" + cmd.Result);
|
||
toolStripStatusLabel1.Text = "ssh_WriteReg(): Response:" + cmd.Result;
|
||
// Console.WriteLine(cmd.Result); // Get the command output
|
||
}
|
||
}
|
||
|
||
|
||
private void ssh_connect_Click(object sender, EventArgs e)
|
||
{
|
||
// if (false == ssh_client.IsConnected)
|
||
// {
|
||
try
|
||
{
|
||
|
||
ssh_connect.Text = "Connecting...";
|
||
ssh_client = new SshClient(ipAddress.Text, "root", "analog");
|
||
ssh_client.Connect();
|
||
Console.WriteLine($"Connected to {ssh_client.ConnectionInfo.Host} successfully.");
|
||
|
||
ssh_connect.BackColor = Color.LightGreen;
|
||
// SshCommand cmd = ssh_client.RunCommand("devmem 0x80000000"); // Execute a command
|
||
// Console.WriteLine("Command Output:");
|
||
// Console.WriteLine(cmd.Result); // Get the command output
|
||
// reg_0x00.Text = cmd.Result;
|
||
// read_all_regs.PerformClick();
|
||
// cmac_read_all_regs.PerformClick();
|
||
|
||
read_all_regs.PerformClick();
|
||
// reg00.Text = ssh_ReadReg("0x80000000");
|
||
cmac_0_reg_0x10024.Text = ssh_ReadReg("0x84010024");
|
||
ssh_connect.Text = "Connected";
|
||
|
||
// ssh_client.Disconnect();
|
||
// Thread oThread = new Thread(new ThreadStart(backgroundTask));
|
||
// oThread.IsBackground = true;
|
||
// oThread.Start();
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
Console.WriteLine($"An error occurred: {ex.Message}");
|
||
ssh_connect.Text = "Connect";
|
||
ssh_connect.BackColor = Color.Red;
|
||
}
|
||
// }
|
||
// else
|
||
// {
|
||
//
|
||
// }
|
||
}
|
||
|
||
private void reg_read_Click(object sender, EventArgs e)
|
||
{
|
||
reg_data.Text = ssh_ReadReg("0x" + reg_addr.Text);
|
||
}
|
||
|
||
private void reg_write_Click(object sender, EventArgs e)
|
||
{
|
||
ssh_WriteReg("0x" + reg_addr.Text, "0x" + reg_data.Text);
|
||
}
|
||
|
||
private void dac_data_src_quadsend_rcv_Click(object sender, EventArgs e)
|
||
{
|
||
reg28.Text = ssh_ReadReg("0x80000028");
|
||
uint cntrl_reg28 = (Convert.ToUInt32(reg28.Text, 16));
|
||
cntrl_reg28 &= 0xFFFF_F8FF; // bit10:8 = "000" <= quadsendrecv
|
||
|
||
ssh_WriteReg("0x80000028", "0x" + cntrl_reg28.ToString("X8"));
|
||
reg28.Text = ssh_ReadReg("0x80000028");
|
||
}
|
||
|
||
private void dac_data_src_dds_pulse_gen_Click(object sender, EventArgs e)
|
||
{
|
||
reg28.Text = ssh_ReadReg("0x80000028");
|
||
uint cntrl_reg28 = (Convert.ToUInt32(reg28.Text, 16));
|
||
cntrl_reg28 &= 0xFFFF_F8FF; // bit10:8
|
||
cntrl_reg28 |= 0x300; // bit10:8 = "011" <= DDS
|
||
|
||
ssh_WriteReg("0x80000028", "0x" + cntrl_reg28.ToString("X8"));
|
||
reg28.Text = ssh_ReadReg("0x80000028");
|
||
}
|
||
|
||
private void dac_data_src_adc_chan0_loopback_Click(object sender, EventArgs e)
|
||
{
|
||
reg28.Text = ssh_ReadReg("0x80000028");
|
||
uint cntrl_reg28 = (Convert.ToUInt32(reg28.Text, 16));
|
||
cntrl_reg28 &= 0xFFFF_F8FF; // // bit10:8
|
||
cntrl_reg28 |= 0x200; // bit10:8 = "010" <= ADC loopack
|
||
|
||
ssh_WriteReg("0x80000028", "0x" + cntrl_reg28.ToString("X8"));
|
||
reg28.Text = ssh_ReadReg("0x80000028");
|
||
}
|
||
|
||
private void dac_data_src_fiber_Click(object sender, EventArgs e)
|
||
{
|
||
reg28.Text = ssh_ReadReg("0x80000028");
|
||
uint cntrl_reg28 = (Convert.ToUInt32(reg28.Text, 16));
|
||
cntrl_reg28 &= 0xFFFF_F8FF; // bit10:8
|
||
cntrl_reg28 |= 0x100; // bit10:8 = "001" <= fiber
|
||
|
||
ssh_WriteReg("0x80000028", "0x" + cntrl_reg28.ToString("X8"));
|
||
reg28.Text = ssh_ReadReg("0x80000028");
|
||
}
|
||
|
||
private void dac_data_src_cmac_Click(object sender, EventArgs e)
|
||
{
|
||
reg28.Text = ssh_ReadReg("0x80000028");
|
||
uint cntrl_reg28 = (Convert.ToUInt32(reg28.Text, 16));
|
||
cntrl_reg28 &= 0xFFFF_F8FF; // bit10:8
|
||
cntrl_reg28 |= 0x400; // bit10:8 = "100" <= fiber
|
||
|
||
ssh_WriteReg("0x80000028", "0x" + cntrl_reg28.ToString("X8"));
|
||
reg28.Text = ssh_ReadReg("0x80000028");
|
||
}
|
||
|
||
private void RegDump()
|
||
{
|
||
if (true == ssh_client.IsConnected)
|
||
{
|
||
reg00.Text = "";
|
||
reg04.Text = "";
|
||
reg14.Text = "";
|
||
reg20.Text = "";
|
||
reg28.Text = "";
|
||
reg44.Text = "";
|
||
reg2C.Text = "";
|
||
reg4C.Text = "";
|
||
reg34.Text = "";
|
||
reg3C.Text = "";
|
||
reg40.Text = "";
|
||
regE8.Text = "";
|
||
regDC.Text = "";
|
||
regD4.Text = "";
|
||
regE4.Text = "";
|
||
regF4.Text = "";
|
||
regE0.Text = "";
|
||
regF0.Text = "";
|
||
|
||
reg00.Text = ssh_ReadReg("0x80000000");
|
||
//
|
||
reg04.Text = ssh_ReadReg("0x80000004");
|
||
uint val = (Convert.ToUInt32(reg04.Text, 16));
|
||
//
|
||
if (0x1 == (val & 0x01))
|
||
{
|
||
qsfp1_intfc_rdy.BackColor = Color.LightGreen;
|
||
}
|
||
else
|
||
{
|
||
qsfp1_intfc_rdy.BackColor = Color.Red;
|
||
}
|
||
if (0x2 == (val & 0x02))
|
||
{
|
||
qsfp1_present.BackColor = Color.Red;
|
||
}
|
||
else
|
||
{
|
||
qsfp1_present.BackColor = Color.LightGreen;
|
||
}
|
||
if (0x4 == (val & 0x04))
|
||
{
|
||
qsfp1_intl.BackColor = Color.Red;
|
||
}
|
||
else
|
||
{
|
||
qsfp1_intl.BackColor = Color.LightGreen;
|
||
}
|
||
|
||
|
||
//
|
||
if (0x10 == (val & 0x010))
|
||
{
|
||
qsfp2_intfc_rdy.BackColor = Color.LightGreen;
|
||
}
|
||
else
|
||
{
|
||
qsfp2_intfc_rdy.BackColor = Color.Red;
|
||
}
|
||
if (0x20 == (val & 0x020))
|
||
{
|
||
qsfp2_present.BackColor = Color.Red;
|
||
}
|
||
else
|
||
{
|
||
qsfp2_present.BackColor = Color.LightGreen;
|
||
}
|
||
|
||
if (0x40 == (val & 0x040))
|
||
{
|
||
qsfp2_intl.BackColor = Color.Red;
|
||
}
|
||
else
|
||
{
|
||
qsfp2_intl.BackColor = Color.LightGreen;
|
||
}
|
||
|
||
|
||
//
|
||
if (0x100 == (val & 0x0100))
|
||
{
|
||
qsfp3_intfc_rdy.BackColor = Color.LightGreen;
|
||
}
|
||
else
|
||
{
|
||
qsfp3_intfc_rdy.BackColor = Color.Red;
|
||
}
|
||
if (0x200 == (val & 0x0200))
|
||
{
|
||
qsfp3_present.BackColor = Color.Red;
|
||
}
|
||
else
|
||
{
|
||
qsfp3_present.BackColor = Color.LightGreen;
|
||
}
|
||
if (0x400 == (val & 0x0400))
|
||
{
|
||
qsfp3_intl.BackColor = Color.Red;
|
||
}
|
||
else
|
||
{
|
||
qsfp3_intl.BackColor = Color.LightGreen;
|
||
}
|
||
|
||
|
||
//
|
||
if (0x1000 == (val & 0x01000))
|
||
{
|
||
qsfp4_intfc_rdy.BackColor = Color.LightGreen;
|
||
}
|
||
else
|
||
{
|
||
qsfp4_intfc_rdy.BackColor = Color.Red;
|
||
}
|
||
if (0x2000 == (val & 0x02000))
|
||
{
|
||
qsfp4_present.BackColor = Color.Red;
|
||
}
|
||
else
|
||
{
|
||
qsfp4_present.BackColor = Color.LightGreen;
|
||
}
|
||
if (0x4000 == (val & 0x04000))
|
||
{
|
||
qsfp4_intl.BackColor = Color.Red;
|
||
}
|
||
else
|
||
{
|
||
qsfp4_intl.BackColor = Color.LightGreen;
|
||
}
|
||
|
||
|
||
|
||
reg14.Text = ssh_ReadReg("0x80000014");
|
||
|
||
reg20.Text = ssh_ReadReg("0x80000020");
|
||
val = (Convert.ToUInt32(reg20.Text, 16));
|
||
if (0xCAFE == val)
|
||
{
|
||
// CMAC already init'ed
|
||
cmac_init.Text = "CMACs Initialized";
|
||
cmac_init.BackColor = Color.LightGreen;
|
||
cmac_read_all_regs.PerformClick();
|
||
}
|
||
else
|
||
{
|
||
cmac_init.Text = "CMAC_Init";
|
||
cmac_init.BackColor = Color.Gainsboro;
|
||
}
|
||
|
||
reg28.Text = ssh_ReadReg("0x80000028");
|
||
val = (Convert.ToUInt32(reg28.Text, 16));
|
||
if (0 == (val & 0x700)) // bit9:8 dac_src_data_sel
|
||
{
|
||
dac_data_src_quadsend_rcv.Checked = true;
|
||
}
|
||
else if (0x100 == (val & 0x700))
|
||
{
|
||
dac_data_src_fiber.Checked = true;
|
||
}
|
||
else if (0x200 == (val & 0x700))
|
||
{
|
||
dac_data_src_adc_chan0_loopback.Checked = true;
|
||
}
|
||
else if (0x300 == (val & 0x700))
|
||
{
|
||
dac_data_src_dds_pulse_gen.Checked = true;
|
||
}
|
||
else if (0x400 == (val & 0x700))
|
||
{
|
||
dac_data_src_cmac.Checked = true;
|
||
}
|
||
|
||
if (0 == (val & 0x8000_0000)) // bit31 qsfp4_playback_path_data_enable_n
|
||
{
|
||
tx_fiber_data_on.Checked = true;
|
||
}
|
||
else if (0x8000_0000 == (val & 0x8000_0000))
|
||
{
|
||
tx_fiber_data_off.Checked = true;
|
||
}
|
||
|
||
if (0 == (val & 0x0000_8000)) // bit15 qsfp1_capture_en_n
|
||
{
|
||
rx_fiber_data_on.Checked = true;
|
||
}
|
||
else if (0x0000_8000 == (val & 0x0000_8000))
|
||
{
|
||
rx_fiber_data_off.Checked = true;
|
||
}
|
||
|
||
if (0 == (val & 0x0000_0001)) // bit0 fiber_tx_src_data_sel
|
||
{
|
||
tx_fiber_data_src_adc.Checked = true;
|
||
}
|
||
else if (0x0000_0001 == (val & 0x0000_0001))
|
||
{
|
||
tx_fiber_data_src_dds.Checked = true;
|
||
}
|
||
|
||
if (0 == (val & 0x0000_1000)) // bit12 chan1to4_mode_sel
|
||
{
|
||
adc_loopback_mode_chan_all.Checked = true;
|
||
}
|
||
else if (0x0000_1000 == (val & 0x0000_1000))
|
||
{
|
||
adc_loopback_mode_chan_0.Checked = true;
|
||
}
|
||
|
||
if (0 == (val & 0x3000_0000)) // bit29:28 = "00" <= cmac disabled
|
||
{
|
||
cmac_disable.Checked = true;
|
||
}
|
||
else if (0x1000_0000 == (val & 0x3000_0000))// bit29:28 = "01" <= Tx enable
|
||
{
|
||
cmac_tx_en.Checked = true;
|
||
}
|
||
else if (0x2000_0000 == (val & 0x3000_0000))// bit29:28 = "10" <= Rx enable
|
||
{
|
||
cmac_rx_en.Checked = true;
|
||
}
|
||
else if (0x3000_0000 == (val & 0x3000_0000))// bit29:28 = "11" <= Rx and Tx enable
|
||
{
|
||
cmac_rxtx_en.Checked = true;
|
||
}
|
||
|
||
|
||
|
||
|
||
//clk125
|
||
String str = ssh_ReadReg("0x80000044");
|
||
val = (Convert.ToUInt32(str, 16));
|
||
reg44.Text = val.ToString("D");
|
||
|
||
// qsfp1
|
||
str = ssh_ReadReg("0x8000002C");
|
||
val = (Convert.ToUInt32(str, 16));
|
||
reg2C.Text = val.ToString("D");
|
||
|
||
//clk250
|
||
str = ssh_ReadReg("0x8000004C");
|
||
val = (Convert.ToUInt32(str, 16));
|
||
reg4C.Text = val.ToString("D");
|
||
|
||
//qsfp4
|
||
str = ssh_ReadReg("0x80000034");
|
||
val = (Convert.ToUInt32(str, 16));
|
||
reg34.Text = val.ToString("D");
|
||
|
||
//jesd_rx
|
||
str = ssh_ReadReg("0x8000003C");
|
||
val = (Convert.ToUInt32(str, 16));
|
||
reg3C.Text = val.ToString("D");
|
||
|
||
//jesd_tx
|
||
str = ssh_ReadReg("0x80000040");
|
||
val = (Convert.ToUInt32(str, 16));
|
||
reg40.Text = val.ToString("D");
|
||
|
||
|
||
regE8.Text = ssh_ReadReg("0x800000E8");
|
||
regDC.Text = ssh_ReadReg("0x800000DC");
|
||
regD4.Text = ssh_ReadReg("0x800000D4");
|
||
regE4.Text = ssh_ReadReg("0x800000E4");
|
||
regF4.Text = ssh_ReadReg("0x800000F4");
|
||
regE0.Text = ssh_ReadReg("0x800000E0");
|
||
regF0.Text = ssh_ReadReg("0x800000F0");
|
||
|
||
// dds_reg_dump();
|
||
|
||
|
||
}
|
||
}
|
||
|
||
private void dds_reg_dump()
|
||
{
|
||
dds_reg00.Text = ssh_ReadReg("0x83000000");
|
||
dds_reg04.Text = ssh_ReadReg("0x83000004");
|
||
dds_reg08.Text = ssh_ReadReg("0x83000008");
|
||
dds_reg0C.Text = ssh_ReadReg("0x8300000C");
|
||
|
||
dds_reg04.Text = ssh_ReadReg("0x83000004");
|
||
uint val = (Convert.ToUInt32(dds_reg04.Text, 16));
|
||
|
||
if (1 == (val & 0x1))
|
||
{
|
||
dac_off.PerformClick();
|
||
}
|
||
else
|
||
{
|
||
dac_on.PerformClick();
|
||
}
|
||
|
||
dds_reg90.Text = ssh_ReadReg("0x83000090");
|
||
dds_reg94.Text = ssh_ReadReg("0x83000094");
|
||
dds_reg98.Text = ssh_ReadReg("0x83000098");
|
||
dds_reg9C.Text = ssh_ReadReg("0x8300009C");
|
||
}
|
||
|
||
private void read_all_regs_Click(object sender, EventArgs e)
|
||
{
|
||
read_all_regs.Text = "Refreshing...";
|
||
read_all_regs.BackColor = Color.LightGreen;
|
||
RegDump();
|
||
read_all_regs.Text = "Refresh";
|
||
read_all_regs.BackColor = Color.Gainsboro;
|
||
}
|
||
|
||
private void dds_cnt_reset_Click(object sender, EventArgs e)
|
||
{
|
||
dds_reg0C.Text = ssh_ReadReg("0x8300000C");
|
||
uint cntrl_reg = (Convert.ToUInt32(dds_reg0C.Text, 16));
|
||
cntrl_reg |= 0x0000_0001; // bit0: 1 <= reset
|
||
ssh_WriteReg("0x8300000C", "0x" + cntrl_reg.ToString("X8"));
|
||
|
||
dds_reg0C.Text = ssh_ReadReg("0x8300000C");
|
||
cntrl_reg = (Convert.ToUInt32(dds_reg0C.Text, 16));
|
||
cntrl_reg &= 0xFFFF_FFFE; // bit0: 0 <= normal
|
||
|
||
ssh_WriteReg("0x8300000C", "0x" + cntrl_reg.ToString("X8"));
|
||
dds_reg0C.Text = ssh_ReadReg("0x8300000C");
|
||
}
|
||
|
||
|
||
|
||
|
||
private void button3_Click(object sender, EventArgs e)
|
||
{
|
||
regE8.Text = ssh_ReadReg("0x800000E8");
|
||
regDC.Text = ssh_ReadReg("0x800000DC");
|
||
regD4.Text = ssh_ReadReg("0x800000D4");
|
||
regE4.Text = ssh_ReadReg("0x800000E4");
|
||
regF4.Text = ssh_ReadReg("0x800000F4");
|
||
regE0.Text = ssh_ReadReg("0x800000E0");
|
||
regF0.Text = ssh_ReadReg("0x800000F0");
|
||
|
||
dds_reg90.Text = ssh_ReadReg("0x83000090");
|
||
dds_reg94.Text = ssh_ReadReg("0x83000094");
|
||
|
||
}
|
||
|
||
private void read_dds_regs_Click(object sender, EventArgs e)
|
||
{
|
||
dds_reg10.Text = ssh_ReadReg("0x83000010");
|
||
dds_reg14.Text = ssh_ReadReg("0x83000014");
|
||
dds_reg18.Text = ssh_ReadReg("0x83000018");
|
||
dds_reg1C.Text = ssh_ReadReg("0x8300001C");
|
||
dds_reg20.Text = ssh_ReadReg("0x83000020");
|
||
dds_reg24.Text = ssh_ReadReg("0x83000024");
|
||
dds_reg28.Text = ssh_ReadReg("0x83000028");
|
||
dds_reg2C.Text = ssh_ReadReg("0x8300002C");
|
||
|
||
dds_reg30.Text = ssh_ReadReg("0x83000030");
|
||
dds_reg34.Text = ssh_ReadReg("0x83000034");
|
||
dds_reg38.Text = ssh_ReadReg("0x83000038");
|
||
dds_reg3C.Text = ssh_ReadReg("0x8300003C");
|
||
dds_reg40.Text = ssh_ReadReg("0x83000040");
|
||
dds_reg44.Text = ssh_ReadReg("0x83000044");
|
||
dds_reg48.Text = ssh_ReadReg("0x83000048");
|
||
dds_reg4C.Text = ssh_ReadReg("0x8300004C");
|
||
|
||
dds_reg50.Text = ssh_ReadReg("0x83000050");
|
||
dds_reg54.Text = ssh_ReadReg("0x83000054");
|
||
dds_reg58.Text = ssh_ReadReg("0x83000058");
|
||
dds_reg5C.Text = ssh_ReadReg("0x8300005C");
|
||
dds_reg60.Text = ssh_ReadReg("0x83000060");
|
||
dds_reg64.Text = ssh_ReadReg("0x83000064");
|
||
dds_reg68.Text = ssh_ReadReg("0x83000068");
|
||
dds_reg6C.Text = ssh_ReadReg("0x8300006C");
|
||
|
||
dds_reg70.Text = ssh_ReadReg("0x83000070");
|
||
dds_reg74.Text = ssh_ReadReg("0x83000074");
|
||
dds_reg78.Text = ssh_ReadReg("0x83000078");
|
||
dds_reg7C.Text = ssh_ReadReg("0x8300007C");
|
||
dds_reg80.Text = ssh_ReadReg("0x83000080");
|
||
dds_reg84.Text = ssh_ReadReg("0x83000084");
|
||
dds_reg88.Text = ssh_ReadReg("0x83000088");
|
||
dds_reg8C.Text = ssh_ReadReg("0x8300008C");
|
||
|
||
}
|
||
|
||
private void dds_send_w1_Click(object sender, EventArgs e)
|
||
{
|
||
dds_send_w1.Text = "Sending...";
|
||
dds_send_w1.BackColor = Color.LightGreen;
|
||
|
||
|
||
ssh_WriteReg("0x83000000", "0x00000001"); //bit 0 self clearing bit
|
||
dds_send_w1.Text = "Send";
|
||
dds_send_w1.BackColor = Color.Gainsboro;
|
||
}
|
||
|
||
private void dds_reset_Click(object sender, EventArgs e)
|
||
{
|
||
ssh_WriteReg("0x8300000C", "0"); //bit 31
|
||
Thread.Sleep(500);
|
||
ssh_WriteReg("0x8300000C", "0x80000000"); //bit 31
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
private void send_button_w2_Click(object sender, EventArgs e)
|
||
{
|
||
send_button_w2.Text = "Loading...";
|
||
send_button_w2.BackColor = Color.LightGreen;
|
||
|
||
string str = String.Empty;
|
||
double actual_start_freq;
|
||
double actual_end_freq;
|
||
double actual_duration;
|
||
double actual_idle_samples;
|
||
|
||
str += "************************";
|
||
str += "\n";
|
||
richTextBox0.AppendText(str);
|
||
|
||
double start_freq = (double)(Convert.ToDouble(start_freq_w2.Text)) * 1e6;
|
||
double end_freq = (double)(Convert.ToDouble(end_freq_w2.Text)) * 1e6;
|
||
double duration = (double)(Convert.ToDouble(duration_w2.Text)) * 1e-6;
|
||
double idle_samples = (Convert.ToDouble(idle_samples_w2.Text)) * 1e-6;
|
||
uint phase_inc_dwell = (Convert.ToUInt32(phase_inc_dwell_w2.Text, 10));
|
||
|
||
ComputeSend_PDW(2, chirp_w2.Checked, start_freq, end_freq, duration, idle_samples, phase_inc_dwell, out actual_start_freq, out actual_end_freq, out actual_duration, out actual_idle_samples);
|
||
actual_start_freq_w2.Text = actual_start_freq.ToString("F");
|
||
actual_end_freq_w2.Text = actual_end_freq.ToString("F");
|
||
actual_duration_w2.Text = actual_duration.ToString("G6");
|
||
actual_idle_samples_w2.Text = actual_idle_samples.ToString("G6");
|
||
|
||
double scale_factor = (double)scale_factor_w2.Value;
|
||
Set_ScaleFactor(2, scale_factor, iq_swap_w2.Checked);
|
||
|
||
ssh_WriteReg("0x83000048", "00000000");// phase_off_2
|
||
dds_reg48.Text = "00000000";
|
||
|
||
send_button_w2.Text = "Load";
|
||
send_button_w2.BackColor = Color.Gainsboro;
|
||
dds_send_w2.BackColor = Color.Yellow;
|
||
}
|
||
|
||
private void send_button_w3_Click(object sender, EventArgs e)
|
||
{
|
||
send_button_w3.Text = "Loading...";
|
||
send_button_w3.BackColor = Color.LightGreen;
|
||
|
||
string str = String.Empty;
|
||
double actual_start_freq;
|
||
double actual_end_freq;
|
||
double actual_duration;
|
||
double actual_idle_samples;
|
||
|
||
str += "************************";
|
||
str += "\n";
|
||
richTextBox0.AppendText(str);
|
||
|
||
double start_freq = (double)(Convert.ToDouble(start_freq_w3.Text)) * 1e6;
|
||
double end_freq = (double)(Convert.ToDouble(end_freq_w3.Text)) * 1e6;
|
||
double duration = (double)(Convert.ToDouble(duration_w3.Text)) * 1e-6;
|
||
double idle_samples = (Convert.ToDouble(idle_samples_w3.Text)) * 1e-6;
|
||
uint phase_inc_dwell = (Convert.ToUInt32(phase_inc_dwell_w3.Text, 10));
|
||
|
||
ComputeSend_PDW(3, chirp_w3.Checked, start_freq, end_freq, duration, idle_samples, phase_inc_dwell, out actual_start_freq, out actual_end_freq, out actual_duration, out actual_idle_samples);
|
||
actual_start_freq_w3.Text = actual_start_freq.ToString("F");
|
||
actual_end_freq_w3.Text = actual_end_freq.ToString("F");
|
||
actual_duration_w3.Text = actual_duration.ToString("G6");
|
||
actual_idle_samples_w3.Text = actual_idle_samples.ToString("G6");
|
||
|
||
double scale_factor = (double)scale_factor_w3.Value;
|
||
Set_ScaleFactor(3, scale_factor, iq_swap_w3.Checked);
|
||
|
||
ssh_WriteReg("0x83000068", "00000000");// phase_off_3
|
||
dds_reg68.Text = "00000000";
|
||
|
||
send_button_w3.Text = "Load";
|
||
send_button_w3.BackColor = Color.Gainsboro;
|
||
dds_send_w3.BackColor = Color.Yellow;
|
||
}
|
||
|
||
private void send_button_w4_Click(object sender, EventArgs e)
|
||
{
|
||
send_button_w4.Text = "Loading...";
|
||
send_button_w4.BackColor = Color.LightGreen;
|
||
|
||
string str = String.Empty;
|
||
double actual_start_freq;
|
||
double actual_end_freq;
|
||
double actual_duration;
|
||
double actual_idle_samples;
|
||
|
||
str += "************************";
|
||
str += "\n";
|
||
richTextBox0.AppendText(str);
|
||
|
||
double start_freq = (double)(Convert.ToDouble(start_freq_w4.Text)) * 1e6;
|
||
double end_freq = (double)(Convert.ToDouble(end_freq_w4.Text)) * 1e6;
|
||
double duration = (double)(Convert.ToDouble(duration_w4.Text)) * 1e-6;
|
||
double idle_samples = (Convert.ToDouble(idle_samples_w4.Text)) * 1e-6;
|
||
uint phase_inc_dwell = (Convert.ToUInt32(phase_inc_dwell_w4.Text, 10));
|
||
|
||
ComputeSend_PDW(4, chirp_w4.Checked, start_freq, end_freq, duration, idle_samples, phase_inc_dwell, out actual_start_freq, out actual_end_freq, out actual_duration, out actual_idle_samples);
|
||
actual_start_freq_w4.Text = actual_start_freq.ToString("F");
|
||
actual_end_freq_w4.Text = actual_end_freq.ToString("F");
|
||
actual_duration_w4.Text = actual_duration.ToString("G6");
|
||
actual_idle_samples_w4.Text = actual_idle_samples.ToString("G6");
|
||
|
||
double scale_factor = (double)scale_factor_w4.Value;
|
||
Set_ScaleFactor(4, scale_factor, iq_swap_w4.Checked);
|
||
|
||
ssh_WriteReg("0x83000088", "00000000");// phase_off_4
|
||
dds_reg88.Text = "00000000";
|
||
|
||
send_button_w4.Text = "Load";
|
||
send_button_w4.BackColor = Color.Gainsboro;
|
||
dds_send_w4.BackColor = Color.Yellow;
|
||
}
|
||
|
||
private void dds_send_w2_Click(object sender, EventArgs e)
|
||
{
|
||
dds_send_w2.Text = "Sending...";
|
||
dds_send_w2.BackColor = Color.LightGreen;
|
||
|
||
|
||
ssh_WriteReg("0x83000000", "0x00000010"); //bit 4 self clearing bit
|
||
dds_send_w2.Text = "Send";
|
||
dds_send_w2.BackColor = Color.Gainsboro;
|
||
}
|
||
|
||
private void dds_send_w3_Click(object sender, EventArgs e)
|
||
{
|
||
dds_send_w3.Text = "Sending...";
|
||
dds_send_w3.BackColor = Color.LightGreen;
|
||
|
||
|
||
ssh_WriteReg("0x83000000", "0x00000100"); //bit 8 self clearing bit
|
||
dds_send_w3.Text = "Send";
|
||
dds_send_w3.BackColor = Color.Gainsboro;
|
||
}
|
||
|
||
private void dds_send_w4_Click(object sender, EventArgs e)
|
||
{
|
||
dds_send_w4.Text = "Sending...";
|
||
dds_send_w4.BackColor = Color.LightGreen;
|
||
|
||
|
||
ssh_WriteReg("0x83000000", "0x00001000"); //bit 12 self clearing bit
|
||
dds_send_w4.Text = "Send";
|
||
dds_send_w4.BackColor = Color.Gainsboro;
|
||
}
|
||
|
||
private void tx_fiber_adcs_src_Click(object sender, EventArgs e)
|
||
{
|
||
reg28.Text = ssh_ReadReg("0x80000028");
|
||
uint cntrl_reg28 = (Convert.ToUInt32(reg28.Text, 16));
|
||
cntrl_reg28 &= 0xFFFF_FFFE; // bit0 0=ADCs, 1=DDS
|
||
|
||
ssh_WriteReg("0x80000028", "0x" + cntrl_reg28.ToString("X8"));
|
||
reg28.Text = ssh_ReadReg("0x80000028");
|
||
}
|
||
|
||
private void tx_fiber_dds_src_Click(object sender, EventArgs e)
|
||
{
|
||
|
||
}
|
||
|
||
private void tx_fiber_data_on_Click(object sender, EventArgs e)
|
||
{
|
||
reg28.Text = ssh_ReadReg("0x80000028");
|
||
uint cntrl_reg28 = (Convert.ToUInt32(reg28.Text, 16));
|
||
cntrl_reg28 &= 0x7FFF_FFFF; // bit31 0=On, 1=Off
|
||
|
||
ssh_WriteReg("0x80000028", "0x" + cntrl_reg28.ToString("X8"));
|
||
reg28.Text = ssh_ReadReg("0x80000028");
|
||
}
|
||
|
||
private void tx_fiber_data_off_Click(object sender, EventArgs e)
|
||
{
|
||
reg28.Text = ssh_ReadReg("0x80000028");
|
||
uint cntrl_reg28 = (Convert.ToUInt32(reg28.Text, 16));
|
||
cntrl_reg28 |= 0x8000_0000; // bit31 0=On, 1=Off
|
||
|
||
ssh_WriteReg("0x80000028", "0x" + cntrl_reg28.ToString("X8"));
|
||
reg28.Text = ssh_ReadReg("0x80000028");
|
||
}
|
||
|
||
private void rx_fiber_data_on_Click(object sender, EventArgs e)
|
||
{
|
||
reg28.Text = ssh_ReadReg("0x80000028");
|
||
uint cntrl_reg28 = (Convert.ToUInt32(reg28.Text, 16));
|
||
cntrl_reg28 &= 0xFFFF_7FEF; // bit15 0=On bit4 0=normal
|
||
|
||
ssh_WriteReg("0x80000028", "0x" + cntrl_reg28.ToString("X8"));
|
||
reg28.Text = ssh_ReadReg("0x80000028");
|
||
}
|
||
|
||
private void rx_fiber_data_off_Click(object sender, EventArgs e)
|
||
{
|
||
reg28.Text = ssh_ReadReg("0x80000028");
|
||
uint cntrl_reg28 = (Convert.ToUInt32(reg28.Text, 16));
|
||
cntrl_reg28 |= 0x0000_8010; // bit15 1=Off bit4 1=reset FIFOs
|
||
|
||
ssh_WriteReg("0x80000028", "0x" + cntrl_reg28.ToString("X8"));
|
||
reg28.Text = ssh_ReadReg("0x80000028");
|
||
}
|
||
|
||
private void qsfp4_reg_refresh_Click(object sender, EventArgs e)
|
||
{
|
||
reg28_1.Text = "";
|
||
regE8_1.Text = "";
|
||
regD0_1.Text = "";
|
||
regEC_1.Text = "";
|
||
regDC_1.Text = "";
|
||
regD4_1.Text = "";
|
||
regCC_1.Text = "";
|
||
|
||
reg28_1.Text = ssh_ReadReg("0x80000028");
|
||
regE8_1.Text = ssh_ReadReg("0x800000E8");
|
||
regD0_1.Text = ssh_ReadReg("0x800000D0");
|
||
regEC_1.Text = ssh_ReadReg("0x800000EC");
|
||
regDC_1.Text = ssh_ReadReg("0x800000DC");
|
||
regD4_1.Text = ssh_ReadReg("0x800000D4");
|
||
regCC_1.Text = ssh_ReadReg("0x800000CC");
|
||
|
||
}
|
||
|
||
private void qsfp1_reg_refresh_Click(object sender, EventArgs e)
|
||
{
|
||
regE4_1.Text = "";
|
||
regF4_1.Text = "";
|
||
regD8_1.Text = "";
|
||
regE0_1.Text = "";
|
||
regF8_1.Text = "";
|
||
regF0_1.Text = "";
|
||
regFC_1.Text = "";
|
||
regC8_1.Text = "";
|
||
regC4_1.Text = "";
|
||
|
||
regE4_1.Text = ssh_ReadReg("0x800000E4");
|
||
regF4_1.Text = ssh_ReadReg("0x800000F4");
|
||
regD8_1.Text = ssh_ReadReg("0x800000D8");
|
||
regE0_1.Text = ssh_ReadReg("0x800000E0");
|
||
regF8_1.Text = ssh_ReadReg("0x800000F8");
|
||
regF0_1.Text = ssh_ReadReg("0x800000F0");
|
||
regFC_1.Text = ssh_ReadReg("0x800000FC");
|
||
regC8_1.Text = ssh_ReadReg("0x800000C8");
|
||
regC4_1.Text = ssh_ReadReg("0x800000C4");
|
||
}
|
||
|
||
private void adc_loopback_mode_chan_0_Click(object sender, EventArgs e)
|
||
{
|
||
reg28.Text = ssh_ReadReg("0x80000028");
|
||
uint cntrl_reg28 = (Convert.ToUInt32(reg28.Text, 16));
|
||
cntrl_reg28 |= 0x0000_1000; // bit12 1=chan 0
|
||
|
||
ssh_WriteReg("0x80000028", "0x" + cntrl_reg28.ToString("X8"));
|
||
reg28.Text = ssh_ReadReg("0x80000028");
|
||
}
|
||
|
||
private void adc_loopback_mode_chan_all_Click(object sender, EventArgs e)
|
||
{
|
||
reg28.Text = ssh_ReadReg("0x80000028");
|
||
uint cntrl_reg28 = (Convert.ToUInt32(reg28.Text, 16));
|
||
cntrl_reg28 &= 0xFFFF_EFFF; // bit12 0=All channels
|
||
|
||
ssh_WriteReg("0x80000028", "0x" + cntrl_reg28.ToString("X8"));
|
||
reg28.Text = ssh_ReadReg("0x80000028");
|
||
}
|
||
|
||
private void reg28_TextChanged(object sender, EventArgs e)
|
||
{
|
||
reg28.BackColor = Color.Red;
|
||
Thread.Sleep(500);
|
||
reg28.BackColor = Color.White;
|
||
}
|
||
|
||
private void cmac_init_Click(object sender, EventArgs e)
|
||
{
|
||
cmac_init.Text = "CMAC_1 Initializing...";
|
||
// GT_RESET - CMAC_1 - self clearing
|
||
ssh_WriteReg("0x84010000", "0x1");
|
||
cmac_0_reg_0x10000.Text = ssh_ReadReg("0x84010000");
|
||
// RESET - reset all logic
|
||
ssh_WriteReg("0x84010004", "0xFFFFFFFF");
|
||
cmac_0_reg_0x10004.Text = ssh_ReadReg("0x84010004");
|
||
|
||
// await Task.Run(() =>
|
||
// {
|
||
// Sleep 5
|
||
Thread.Sleep(5000);
|
||
// });
|
||
|
||
// release RESET - CMAC_1
|
||
ssh_WriteReg("0x84010004", "0x0");
|
||
cmac_0_reg_0x10004.Text = ssh_ReadReg("0x84010004");
|
||
|
||
// CONFIGURATION_TX_FLOW_CONTROL_REFRESH_REG5
|
||
// bits 15:0 - ctl_tx_pause_refresh_timer8
|
||
ssh_WriteReg("0x84010044", "0x0000FFFF");
|
||
cmac_0_reg_0x10044.Text = ssh_ReadReg("0x84010044");
|
||
|
||
// CONFIGURATION_TX_FLOW_CONTROL_QUANTA_REG5
|
||
// bit 15:0 - ctl_tx_pause_quanta8
|
||
ssh_WriteReg("0x84010058", "0x0000FFFF");
|
||
cmac_0_reg_0x10058.Text = ssh_ReadReg("0x84010058");
|
||
|
||
// CONFIGURATION_TX_FLOW_CONTROL_CONTROL_REG1
|
||
// bits 8:0 - ctl_tx_pause_enable
|
||
ssh_WriteReg("0x84010030", "0x00000100");
|
||
cmac_0_reg_0x10030.Text = ssh_ReadReg("0x84010030");
|
||
|
||
// CONFIGURATION_RX_FLOW_CONTROL_CONTROL_REG1
|
||
// bit12 - ctl_rx_enable_gpp, bit10 - ctl_rx_enable_gcp bit8 - ctl_rx_pause_enable
|
||
ssh_WriteReg("0x84010084", "0x00001500");
|
||
cmac_0_reg_0x10084.Text = ssh_ReadReg("0x84010084");
|
||
|
||
// CONFIGURATION_RX_FLOW_CONTROL_CONTROL_REG2
|
||
// bits 31:0 - ctl_rx_check....
|
||
ssh_WriteReg("0x84010088", "0x00007C1F");
|
||
cmac_0_reg_0x10088.Text = ssh_ReadReg("0x84010088");
|
||
|
||
//#:: LOOPBACK MODE
|
||
//#:: 1=LB, 0=No LB
|
||
ssh_WriteReg("0x84010090", "0x0");
|
||
cmac_0_reg_0x10090.Text = ssh_ReadReg("0x84010090");
|
||
|
||
//#:: TX ENABLE
|
||
//#:: offset 0xC
|
||
//#:: Set bit(0) to 1 to enable, do not modify other bits
|
||
ssh_WriteReg("0x8401000C", "0x1");
|
||
cmac_0_reg_0x1000C.Text = ssh_ReadReg("0x8401000C");
|
||
|
||
//#:: RX ENABLE
|
||
//#:: offset 0x14
|
||
//#:: Set bit(0) to 1 to enable, do not modify other bits
|
||
ssh_WriteReg("0x84010014", "0x1");
|
||
cmac_0_reg_0x10014.Text = ssh_ReadReg("0x84010014");
|
||
|
||
//#:: Set Destination MAC address
|
||
//#:: Broadcast (not multicast, but accepted everywhere): FF:FF:FF:FF:FF:FF
|
||
//#:: IPv4 multicast (All-hosts group): 01:00:5E:00:00:01
|
||
//#:: IPv6 multicast (All-nodes group): 33:33:00:00:00:01
|
||
ssh_WriteReg("0x84000000", "0x5E000001");
|
||
cmac_0_reg_0x00.Text = ssh_ReadReg("0x84000000");
|
||
|
||
ssh_WriteReg("0x84000004", "0x00000100");
|
||
cmac_0_reg_0x04.Text = ssh_ReadReg("0x84000004");
|
||
|
||
//#:: Set Source MAC address 02:00:00:00:00:01
|
||
ssh_WriteReg("0x84000008", "0x00000001");
|
||
cmac_0_reg_0x08.Text = ssh_ReadReg("0x84000008");
|
||
ssh_WriteReg("0x8400000C", "0x00000200");
|
||
cmac_0_reg_0x0C.Text = ssh_ReadReg("0x8400000C");
|
||
|
||
//#:: Set EtherType
|
||
//#:: 0x88B5 – IEEE “local/experimental” Ethertype (commonly used for custom payloads)
|
||
//#:: 0x0800 – IPv4 (often whitelisted by other stacks, even if the payload isn’t fully IP)
|
||
ssh_WriteReg("0x84000010", "0x000088B5");
|
||
cmac_0_reg_0x10.Text = ssh_ReadReg("0x84000010");
|
||
|
||
|
||
// PROG_FULL_MANUAL_MODE - 0x14
|
||
ssh_WriteReg("0x84000014", "0x00000000"); //0 =OFF
|
||
cmac_0_reg_0x14.Text = ssh_ReadReg("0x84000014");
|
||
|
||
// PROG_FULL_ON_THRESH - 0x18
|
||
ssh_WriteReg("0x84000018", "0x00000300"); //256
|
||
cmac_0_reg_0x18.Text = ssh_ReadReg("0x84000018");
|
||
//PROG_FULL_OFF_THRESH - 0x1C
|
||
ssh_WriteReg("0x8400001C", "0x00000100"); //768
|
||
cmac_0_reg_0x1C.Text = ssh_ReadReg("0x8400001C");
|
||
|
||
|
||
cmac_init.Text = "CMACs Initialized";
|
||
cmac_init.BackColor = Color.LightGreen;
|
||
cmac_read_all_regs.PerformClick();
|
||
ssh_WriteReg("0x80000020", "0xCAFE"); // init flag
|
||
}
|
||
|
||
private void cmac_rx_en_Click(object sender, EventArgs e)
|
||
{
|
||
reg28.Text = ssh_ReadReg("0x80000028");
|
||
uint cntrl_reg28 = (Convert.ToUInt32(reg28.Text, 16));
|
||
cntrl_reg28 &= 0xCFFF_FFFF; // bit29:28 = "00" <= cmac disabled
|
||
|
||
cntrl_reg28 |= 0x2000_0000; // bit29:28 = "10" <= Rx Only enable
|
||
|
||
ssh_WriteReg("0x80000028", "0x" + cntrl_reg28.ToString("X8"));
|
||
reg28.Text = ssh_ReadReg("0x80000028");
|
||
}
|
||
|
||
private void cmac_tx_en_Click(object sender, EventArgs e)
|
||
{
|
||
reg28.Text = ssh_ReadReg("0x80000028");
|
||
uint cntrl_reg28 = (Convert.ToUInt32(reg28.Text, 16));
|
||
cntrl_reg28 &= 0xCFFF_FFFF; // bit29:28 = "00" <= cmac disabled
|
||
|
||
cntrl_reg28 |= 0x1000_0000; // bit29:28 = "01" <= Tx enable
|
||
|
||
ssh_WriteReg("0x80000028", "0x" + cntrl_reg28.ToString("X8"));
|
||
reg28.Text = ssh_ReadReg("0x80000028");
|
||
}
|
||
|
||
private void cmac_rxtx_en_Click(object sender, EventArgs e)
|
||
{
|
||
reg28.Text = ssh_ReadReg("0x80000028");
|
||
uint cntrl_reg28 = (Convert.ToUInt32(reg28.Text, 16));
|
||
cntrl_reg28 &= 0xCFFF_FFFF; // bit29:28 = "00" <= cmac disabled
|
||
|
||
cntrl_reg28 |= 0x3000_0000; // bit29:28 = "11" <= Rx and Tx enable
|
||
|
||
ssh_WriteReg("0x80000028", "0x" + cntrl_reg28.ToString("X8"));
|
||
reg28.Text = ssh_ReadReg("0x80000028");
|
||
}
|
||
|
||
private void cmac_disable_Click(object sender, EventArgs e)
|
||
{
|
||
reg28.Text = ssh_ReadReg("0x80000028");
|
||
uint cntrl_reg28 = (Convert.ToUInt32(reg28.Text, 16));
|
||
cntrl_reg28 &= 0xCFFF_FFFF; // bit29:28 = "00" <= cmac disabled
|
||
|
||
ssh_WriteReg("0x80000028", "0x" + cntrl_reg28.ToString("X8"));
|
||
reg28.Text = ssh_ReadReg("0x80000028");
|
||
}
|
||
|
||
|
||
private void cmac_read_all_regs_Click(object sender, EventArgs e)
|
||
{
|
||
cmac_0_RegDump();
|
||
}
|
||
|
||
private void cmac_0_RegDump()
|
||
{
|
||
if (true == ssh_client.IsConnected)
|
||
{
|
||
|
||
cmac_0_reg_0x10000.Text = "";
|
||
cmac_0_reg_0x10004.Text = "";
|
||
cmac_0_reg_0x1000C.Text = "";
|
||
cmac_0_reg_0x10014.Text = "";
|
||
cmac_0_reg_0x10024.Text = "";
|
||
cmac_0_reg_0x10090.Text = "";
|
||
cmac_0_reg_0x10030.Text = "";
|
||
cmac_0_reg_0x10058.Text = "";
|
||
cmac_0_reg_0x10044.Text = "";
|
||
cmac_0_reg_0x10084.Text = "";
|
||
cmac_0_reg_0x10088.Text = "";
|
||
|
||
cmac_0_reg_0x00.Text = "";
|
||
cmac_0_reg_0x04.Text = "";
|
||
cmac_0_reg_0x08.Text = "";
|
||
cmac_0_reg_0x0C.Text = "";
|
||
cmac_0_reg_0x10.Text = "";
|
||
cmac_0_reg_0x14.Text = "";
|
||
cmac_0_reg_0x18.Text = "";
|
||
cmac_0_reg_0x1C.Text = "";
|
||
|
||
cmac_0_reg_0x10000.Text = ssh_ReadReg("0x84010000");
|
||
cmac_0_reg_0x10004.Text = ssh_ReadReg("0x84010004");
|
||
cmac_0_reg_0x1000C.Text = ssh_ReadReg("0x8401000C");
|
||
cmac_0_reg_0x10014.Text = ssh_ReadReg("0x84010014");
|
||
cmac_0_reg_0x10024.Text = ssh_ReadReg("0x84010024");
|
||
cmac_0_reg_0x10090.Text = ssh_ReadReg("0x84010090");
|
||
cmac_0_reg_0x10030.Text = ssh_ReadReg("0x84010030");
|
||
cmac_0_reg_0x10058.Text = ssh_ReadReg("0x84010058");
|
||
cmac_0_reg_0x10044.Text = ssh_ReadReg("0x84010044");
|
||
cmac_0_reg_0x10084.Text = ssh_ReadReg("0x84010084");
|
||
cmac_0_reg_0x10088.Text = ssh_ReadReg("0x84010088");
|
||
|
||
cmac_0_reg_0x00.Text = ssh_ReadReg("0x84000000");
|
||
cmac_0_reg_0x04.Text = ssh_ReadReg("0x84000004");
|
||
cmac_0_reg_0x08.Text = ssh_ReadReg("0x84000008");
|
||
cmac_0_reg_0x0C.Text = ssh_ReadReg("0x8400000C");
|
||
cmac_0_reg_0x10.Text = ssh_ReadReg("0x84000010");
|
||
cmac_0_reg_0x14.Text = ssh_ReadReg("0x84000014");
|
||
cmac_0_reg_0x18.Text = ssh_ReadReg("0x84000018");
|
||
cmac_0_reg_0x1C.Text = ssh_ReadReg("0x8400001C");
|
||
|
||
}
|
||
}
|
||
|
||
private void cmac_read_cnt_reg_Click(object sender, EventArgs e)
|
||
{
|
||
reg_0xBC.Text = "";
|
||
reg_0xC0.Text = "";
|
||
|
||
reg_0xBC.Text = ssh_ReadReg("0x800000BC");
|
||
reg_0xC0.Text = ssh_ReadReg("0x800000C0");
|
||
}
|
||
|
||
private void count_reset_Click(object sender, EventArgs e)
|
||
{
|
||
reg20.Text = ssh_ReadReg("0x80000020");
|
||
uint cntrl_reg20 = (Convert.ToUInt32(reg20.Text, 16));
|
||
cntrl_reg20 |= 0x8000_0000; // bit31: 1 <= reset
|
||
ssh_WriteReg("0x80000020", "0x" + cntrl_reg20.ToString("X8"));
|
||
|
||
reg20.Text = ssh_ReadReg("0x80000020");
|
||
cntrl_reg20 = (Convert.ToUInt32(reg20.Text, 16));
|
||
cntrl_reg20 &= 0x7FFF_FFFF; // bit31: 0 <= normal
|
||
ssh_WriteReg("0x80000020", "0x" + cntrl_reg20.ToString("X8"));
|
||
reg20.Text = ssh_ReadReg("0x80000020");
|
||
}
|
||
|
||
private void dds_reg_read_Click(object sender, EventArgs e)
|
||
{
|
||
dds_reg_dump();
|
||
}
|
||
|
||
private void tx_cmac_data_src_dds_Click(object sender, EventArgs e)
|
||
{
|
||
reg28.Text = ssh_ReadReg("0x80000028");
|
||
uint cntrl_reg28 = (Convert.ToUInt32(reg28.Text, 16));
|
||
cntrl_reg28 |= 0x0100_0000; // bit24 0 = fiber, 1 = cmac --> 1st set destination of DDS data
|
||
cntrl_reg28 |= 0x0008_0000; // bit19 = 0 = ADC, 1 = DDS cmac data source
|
||
|
||
ssh_WriteReg("0x80000028", "0x" + cntrl_reg28.ToString("X8"));
|
||
reg28.Text = ssh_ReadReg("0x80000028");
|
||
}
|
||
|
||
private void tx_cmac_data_src_adc_Click(object sender, EventArgs e)
|
||
{
|
||
reg28.Text = ssh_ReadReg("0x80000028");
|
||
uint cntrl_reg28 = (Convert.ToUInt32(reg28.Text, 16));
|
||
cntrl_reg28 |= 0xFFF7_FFFF; // bit19 = 0 = ADC, 1 = DDS cmac data source
|
||
|
||
ssh_WriteReg("0x80000028", "0x" + cntrl_reg28.ToString("X8"));
|
||
reg28.Text = ssh_ReadReg("0x80000028");
|
||
}
|
||
|
||
private void tx_fiber_data_src_adc_Click(object sender, EventArgs e)
|
||
{
|
||
reg28.Text = ssh_ReadReg("0x80000028");
|
||
uint cntrl_reg28 = (Convert.ToUInt32(reg28.Text, 16));
|
||
cntrl_reg28 |= 0xFFFF_FFFE; // bit0 = 0 = ADC, 1 = DDS tx_fiber data source
|
||
|
||
ssh_WriteReg("0x80000028", "0x" + cntrl_reg28.ToString("X8"));
|
||
reg28.Text = ssh_ReadReg("0x80000028");
|
||
}
|
||
|
||
private void tx_fiber_data_src_dds_Click(object sender, EventArgs e)
|
||
{
|
||
reg28.Text = ssh_ReadReg("0x80000028");
|
||
uint cntrl_reg28 = (Convert.ToUInt32(reg28.Text, 16));
|
||
cntrl_reg28 &= 0xFEFF_FFFF; // bit24 0 = fiber, 1 = cmac --> 1st set destination of DDS data
|
||
cntrl_reg28 |= 0x0000_0001; // bit0 = 0 = ADC, 1 = DDS tx_fiber data source
|
||
|
||
ssh_WriteReg("0x80000028", "0x" + cntrl_reg28.ToString("X8"));
|
||
reg28.Text = ssh_ReadReg("0x80000028");
|
||
}
|
||
|
||
private void cmac_rx_tx_debug_regs_Click(object sender, EventArgs e)
|
||
{
|
||
uint overflow_0 = (Convert.ToUInt32(cmac_0_reg_0x58.Text, 16));
|
||
|
||
if (true == ssh_client.IsConnected)
|
||
{
|
||
cmac_0_reg_0x40.Text = "";
|
||
cmac_0_reg_0x44.Text = "";
|
||
cmac_0_reg_0x48.Text = "";
|
||
cmac_0_reg_0x4C.Text = "";
|
||
cmac_0_reg_0x50.Text = "";
|
||
cmac_0_reg_0x54.Text = "";
|
||
cmac_0_reg_0x58.Text = "";
|
||
|
||
cmac_0_reg_0x40.Text = ssh_ReadReg("0x84000040");
|
||
cmac_0_reg_0x44.Text = ssh_ReadReg("0x84000044");
|
||
cmac_0_reg_0x48.Text = ssh_ReadReg("0x84000048");
|
||
cmac_0_reg_0x4C.Text = ssh_ReadReg("0x8400004C");
|
||
cmac_0_reg_0x50.Text = ssh_ReadReg("0x84000050");
|
||
cmac_0_reg_0x54.Text = ssh_ReadReg("0x84000054");
|
||
cmac_0_reg_0x58.Text = ssh_ReadReg("0x84000058");
|
||
}
|
||
|
||
uint overflow_0_cur = (Convert.ToUInt32(cmac_0_reg_0x58.Text, 16));
|
||
uint overflow_0_err = overflow_0_cur - overflow_0;
|
||
textBox1.Text = overflow_0_err.ToString("X8");
|
||
|
||
}
|
||
}
|
||
}
|