annotate ABP/sender.c @ 9:18d2a590bc10 draft

add fibonacci
author Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
date Sun, 03 Jun 2012 22:06:40 +0900
parents 5dc0fa7caa57
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9
18d2a590bc10 add fibonacci
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 8
diff changeset
1 #include <stdio.h>
18d2a590bc10 add fibonacci
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 8
diff changeset
2
8
5dc0fa7caa57 add ABP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 extern int comm_bit_s; /* communication bit for sender */
5dc0fa7caa57 add ABP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 extern int comm_bit_r; /* communication bit for receiver */
5dc0fa7caa57 add ABP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 extern char *comm_msg; /* communication message */
5dc0fa7caa57 add ABP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6
5dc0fa7caa57 add ABP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7
5dc0fa7caa57 add ABP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 struct packet {
5dc0fa7caa57 add ABP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 int bit; /* alternating bit */
5dc0fa7caa57 add ABP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 char **msg; /* messages */
5dc0fa7caa57 add ABP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 code (*next)(); /* next code segment */
5dc0fa7caa57 add ABP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 };
5dc0fa7caa57 add ABP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13
9
18d2a590bc10 add fibonacci
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 8
diff changeset
14 extern code schedule(struct packet pkt, int i);
18d2a590bc10 add fibonacci
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 8
diff changeset
15
18d2a590bc10 add fibonacci
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 8
diff changeset
16 code s_sendState(struct packet, int);
18d2a590bc10 add fibonacci
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 8
diff changeset
17 code s_receiveState(struct packet, int);
18d2a590bc10 add fibonacci
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 8
diff changeset
18
8
5dc0fa7caa57 add ABP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 code s_receiveState(struct packet pkt, int i)
5dc0fa7caa57 add ABP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 {
5dc0fa7caa57 add ABP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 /* correct bit */
5dc0fa7caa57 add ABP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 if (pkt.bit == comm_bit_r) {
5dc0fa7caa57 add ABP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 printf("sender: success\n");
5dc0fa7caa57 add ABP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 pkt.bit = !pkt.bit;
5dc0fa7caa57 add ABP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 i++; // for message increment
5dc0fa7caa57 add ABP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 pkt.next = s_sendState;
5dc0fa7caa57 add ABP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 goto schedule(pkt, i);
5dc0fa7caa57 add ABP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 /* wrong bit */
5dc0fa7caa57 add ABP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 } else {
5dc0fa7caa57 add ABP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 printf("sender: failure\n");
5dc0fa7caa57 add ABP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 pkt.next = s_sendState;
5dc0fa7caa57 add ABP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 goto schedule(pkt, i);
5dc0fa7caa57 add ABP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 }
5dc0fa7caa57 add ABP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 }
5dc0fa7caa57 add ABP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
35
5dc0fa7caa57 add ABP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 code s_sendState(struct packet pkt, int i)
5dc0fa7caa57 add ABP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 {
5dc0fa7caa57 add ABP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 comm_bit_s = pkt.bit;
5dc0fa7caa57 add ABP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 comm_msg = pkt.msg[i];
5dc0fa7caa57 add ABP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 pkt.next = s_receiveState;
5dc0fa7caa57 add ABP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 goto schedule(pkt, i);
5dc0fa7caa57 add ABP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 }