Contiki 2.5
avr.c
1 #include <avr/io.h>
2 
3 #include "contiki-conf.h"
4 
5 void
6 cpu_init(void)
7 {
8  asm volatile ("clr r1"); /* No longer needed. */
9 }
10 
11 extern int __bss_end;
12 
13 #define STACK_EXTRA 32
14 static char *cur_break = (char *)(&__bss_end + 1);
15 
16 /*
17  * Allocate memory from the heap. Check that we don't collide with the
18  * stack right now (some other routine might later). A watchdog might
19  * be used to check if cur_break and the stack pointer meet during
20  * runtime.
21  */
22 void *
23 sbrk(int incr)
24 {
25  char *stack_pointer;
26 
27  stack_pointer = (char *)SP;
28  stack_pointer -= STACK_EXTRA;
29  if(incr > (stack_pointer - cur_break))
30  return (void *)-1; /* ENOMEM */
31 
32  void *old_break = cur_break;
33  cur_break += incr;
34  /*
35  * If the stack was never here then [old_break .. cur_break] should
36  * be filled with zeros.
37  */
38  return old_break;
39 }