9 extern uint8_t *mem_top
;
10 extern uint8_t *mem_bottom
;
11 extern uint8_t *mem_task
;
12 extern uint8_t *mem_sds
;
14 struct sds
*sds_head(void)
16 return mem_sds
== mem_top
? NULL
17 : (struct sds
*)(mem_top
-sizeof(struct sds
));
20 struct sds
*sds_next(struct sds
*s
)
22 uint8_t *next
= (uint8_t *)s
- sizeof(struct sds
);
23 return next
< mem_sds
? NULL
: (struct sds
*)next
;
26 struct sds
*sds_get(uint8_t id
)
28 struct sds
*s
= sds_head();
38 void sds_register(void)
40 debug("free memory: %lu", mem_free());
42 if(mem_sds
-sizeof(struct sds
) < mem_task
){
43 die("Out of memory... Not enough to allocate sds struct");
46 struct sds
*s
= (struct sds
*)(mem_sds
-sizeof(struct sds
));
52 s
->type
= read_byte();
59 mem_sds
-= sizeof(struct sds
);
62 void sds_delete(uint8_t c
)
64 struct sds
*s
= sds_get(c
);
67 //We found the sds, now we move verything from the end of the sds up to
68 //the pointer to the right
69 uint8_t *end
= (uint8_t *)s
;
70 uint8_t *start
= end
+ sizeof(struct sds
) - 1;
71 for(int i
= 0; i
<end
-mem_sds
; i
++){
72 *(start
- i
) = *(end
- i
-1);
74 mem_sds
+= start
-end
+1;
78 bool sds_update(uint8_t id
)
81 struct sds
*s
= sds_get(id
);
84 debug("Received sds update %d: %d", s
->id
, s
->value
);
93 void sds_publish(int id
)
95 struct sds
*s
= sds_get(id
);
97 debug("Publish %d=%d", s
->id
, s
->value
);
110 case 'c': //Character
113 write_byte(s
->value
);
120 debug("SDS identifier unknown: %d", id
);
125 int sds_fetch(int id
)
127 struct sds
*s
= sds_get(id
);
131 debug("SDS identifier unknown: %d", id
);
136 void sds_store(int id
, int val
)
138 struct sds
*s
= sds_get(id
);
142 debug("SDS identifier unknown: %d", id
);