1 /* DOL Block Implementation */
7 /* DOL support functions
8 * ===================================================================== */
9 int DOL_read(void *port, void *buf, int len, DOLProcess *p)
11 port_t *pp = get_port(port);
12 if(!pp || !pp->read) return 0;
14 return(pp->read(buf, len));
17 int DOL_write(void *port, void *buf, int len, DOLProcess *p)
19 port_t *pp = get_port(port);
20 if(!pp || !pp->write) return 0;
22 return(pp->write(buf, len));
25 int DOL_rtest(void *port, int len, DOLProcess *p)
27 /* check if channel contains at least 'len' bytes */
28 port_t *pp = get_port(port);
29 if(!pp || !pp->level) return 0;
31 int level = pp->level();
32 return (level >= len) ? 1 : 0;
35 int DOL_wtest(void *port, int len, DOLProcess *p)
37 /* check if channel has space for at least 'len' bytes */
38 port_t *pp = get_port(port);
39 if(!pp || !pp->level) return 0;
41 int level = pp->level();
42 return (level < (pp->size() - len)) ? 1 : 0;
45 void DOL_detach(DOLProcess *p)
51 int DOL_get_index(int dim, DOLProcess *p)
53 if((dim < 0) || (dim > 4)) return(-1);
55 return(p->wptr->instance[dim]);
58 char* DOL_create_port(char* port, char* base, int ndim, int index0, int range0,
59 int index1, int range1, int index2, int range2, int index3, int range3)
61 /* hang on invalid input */
62 if(range0 && (index0 >= range0)) while(1);
63 if(range1 && (index1 >= range1)) while(1);
64 if(range2 && (index2 >= range2)) while(1);
65 if(range3 && (index3 >= range3)) while(1);
69 snprintf(port, PORTNAME_MAXLEN-1,
70 "%s_%i", base, index0);
71 port[PORTNAME_MAXLEN-1] = '\0';
74 snprintf(port, PORTNAME_MAXLEN-1,
75 "%s_%i_%i", base, index0, index1);
76 port[PORTNAME_MAXLEN-1] = '\0';
79 snprintf(port, PORTNAME_MAXLEN-1,
80 "%s_%i_%i_%i", base, index0, index1, index2),
81 port[PORTNAME_MAXLEN-1] = '\0';
84 snprintf(port, PORTNAME_MAXLEN-1,
85 "%s_%i_%i_%i_%i", base, index0, index1, index2, index3);
86 port[PORTNAME_MAXLEN-1] = '\0';