1 /* ports implementation */
7 #define DEBUG0(X) { shm.states[14] = (uint32_t)(X); }
8 #define DEBUG1(X) { shm.states[15] = (uint32_t)(X); }
12 for(volatile long a = 0; a < 25; a++)
13 for(volatile long b = 0; b < 2000000; b++)
17 int size_shm(void *hwbuf)
19 hwbuf_t *b = (hwbuf_t*)hwbuf;
23 int level_shm(void *hwbuf)
25 hwbuf_t *b = (hwbuf_t*)hwbuf;
27 int level = (b->wp - b->rp) % b->size;
28 if(level < 0) level += b->size;
33 int read_shm (void *hwbuf, void *buf, int len)
35 hwbuf_t *b = (hwbuf_t*)hwbuf;
37 /* block if necessary */
38 while(level_shm(hwbuf) < len);
41 if(b->rp + len > b->size) {
42 /* wrap-around -> split access */
43 uint32_t amount = b->size - b->rp;
44 memcpy(buf, &b->buf[b->rp], amount);
45 memcpy(buf + amount, &b->buf[0], len - amount);
47 memcpy(buf, &b->buf[b->rp], len);
50 /* update read pointer */
51 b->rp = (b->rp + len) % b->size;
56 int write_shm(void *hwbuf, void *buf, int len)
58 hwbuf_t *b = (hwbuf_t*)hwbuf;
60 /* block if necessary */
61 while(b->size - level_shm(hwbuf) < len);
64 if(b->wp + len > b->size) {
65 /* wrap-around -> split access */
66 uint32_t amount = b->size - b->wp;
67 memcpy(&b->buf[b->wp], buf, amount);
68 memcpy(&b->buf[0], buf + amount, len - amount);
70 memcpy(&b->buf[b->wp], buf, len);
73 /* update write pointer */
74 b->wp = (b->wp + len) % b->size;
76 DEBUG1(level_shm(hwbuf)); delay();