Last active
August 17, 2022 05:12
-
-
Save InariAimu/0077286423148c1fab56d27f38b1b42c to your computer and use it in GitHub Desktop.
Make cpu usage graph to display an I2C signal graph.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); | |
} | |
} | |
Author
InariAimu
commented
May 7, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment