Skip to content

Instantly share code, notes, and snippets.

@InariAimu
Last active August 17, 2022 05:12
Show Gist options
  • Save InariAimu/0077286423148c1fab56d27f38b1b42c to your computer and use it in GitHub Desktop.
Save InariAimu/0077286423148c1fab56d27f38b1b42c to your computer and use it in GitHub Desktop.
Make cpu usage graph to display an I2C signal graph.
// make cpu usage graph to display an I2C signal graph.
// delay is for AMD Ryzen 9 3900X
// tested on AMD Ryzen 9 3900X
// up is SCL, down is SDA
using System.Diagnostics;
Process Proc = Process.GetCurrentProcess();
long AffinityMask = (long)Proc.ProcessorAffinity;
AffinityMask &= (1|1<<6);
Proc.ProcessorAffinity = (IntPtr)AffinityMask;
byte data = 0xD4;
new Thread(new ThreadStart(scl)).Start();
new Thread(new ThreadStart(sda)).Start();
List<int> list = new List<int>();
Proc.Threads[1].ProcessorAffinity = (IntPtr)(1L);
Proc.Threads[2].ProcessorAffinity = (IntPtr)(1L<<6);
Thread.Sleep(30 * 1000);
void high()
{
for (long i = 0; i < 15000000000; i++) ;
}
void low()
{
Thread.Sleep(3500);
}
void scl()
{
high();
high();
high();
low();
for (int i = 0; i < 8; i++)
{
high();
low();
}
}
void sda()
{
high();
high();
low();
low();
for (int i = 0; i < 8; i++)
{
int d = ((data << i) & 0x80);
Console.WriteLine(d);
if (d == 0)
low();
else
high();
low();
}
}
@InariAimu
Copy link
Author

cpu_i2c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment