1 /* ports implementation */
8 int size_shm(void *hwbuf)
10 hwbuf_t *b = (hwbuf_t*)hwbuf;
14 int level_shm(void *hwbuf)
16 hwbuf_t *b = (hwbuf_t*)hwbuf;
18 int level = (b->wp - b->rp) % b->size;
19 if(level < 0) level += b->size;
24 int read_shm (void *hwbuf, void *buf, int len)
26 hwbuf_t *b = (hwbuf_t*)hwbuf;
28 /* block if necessary */
29 while(level_shm(hwbuf) < len);
32 if(b->rp + len > b->size) {
33 /* wrap-around -> split access */
34 uint32_t amount = b->size - b->rp;
35 memcpy(buf, &b->buf[b->rp], amount);
36 memcpy(buf + amount, &b->buf[0], len - amount);
38 memcpy(buf, &b->buf[b->rp], len);
41 /* update read pointer */
42 b->rp = (b->rp + len) % b->size;
47 int write_shm(void *hwbuf, void *buf, int len)
49 hwbuf_t *b = (hwbuf_t*)hwbuf;
51 /* block if necessary */
52 while(b->size - level_shm(hwbuf) < len);
55 if(b->wp + len > b->size) {
56 /* wrap-around -> split access */
57 uint32_t amount = b->size - b->wp;
58 memcpy(&b->buf[b->wp], buf, amount);
59 memcpy(&b->buf[0], buf + amount, len - amount);
61 memcpy(&b->buf[b->wp], buf, len);
64 /* update write pointer */
65 b->wp = (b->wp + len) % b->size;