-
Notifications
You must be signed in to change notification settings - Fork 1
/
cachehog.c
52 lines (45 loc) · 950 Bytes
/
cachehog.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "cachehog_lib.h"
#include <stdio.h>
// Transmit mode main loop
void do_transmit() {
while(1) {
int c = getchar();
if(c == EOF) {
break;
}
transmit_word(c);
}
}
// Receive mode main loop
void do_receive() {
while(1) {
int word = read_word();
if(word != 0) {
putchar(word);
fflush(stdout);
}
}
}
// Record mode main loop
void do_record(int nbits) {
int i;
for(i = 0; i < nbits; i++) {
int value = measure(1);
printf("%d\n", value);
}
}
int main(int argc, char **argv) {
init_cachehog();
if(argc >= 2 && !strcmp(argv[1], "transmit")) {
do_transmit();
} else if(argc >= 2 && !strcmp(argv[1], "receive")) {
do_receive();
} else if(argc >= 3 && !strcmp(argv[1], "record")) {
int nbits = atoi(argv[2]);
do_record(nbits);
} else {
fprintf(stderr, "Usage: %s ( transmit | receive | record <nbits> )\n", argv[0]);
return 1;
}
return 0;
}