dol: initial dol commit
[jump.git] / dol / examples / exampleproducerconsumer / src / producer.c
1 #include <stdio.h>
2 #include <string.h>
3
4 #include "producer.h"
5
6 // initialization function
7 void producer_init(DOLProcess *p) {
8     p->local->index = 0;
9     p->local->len = 20;
10     sprintf(p->local->str, "abcdefghijklmnopqrstuvwxyz");
11
12 }
13
14 int producer_fire(DOLProcess *p) {
15
16     if (p->local->index < p->local->len) {
17         if (DOL_wtest((void*)PORT_OUTA, 1, p)) {
18             DOL_write((void*)PORT_OUTA, &(p->local->str[p->local->index]),
19                     1, p);
20             printf("p write to port A %c\n",
21                     p->local->str[p->local->index]);
22         }
23         else {
24             DOL_write((void*)PORT_OUTB, &(p->local->str[p->local->index]),
25                     1, p);
26             printf("p write to port B %c\n",
27                     p->local->str[p->local->index]);
28         }
29         p->local->index++;
30         return 0;
31     }
32     else {
33         DOL_detach(p);
34         return -1;
35     }
36 }
37