avr.c

00001 #include <avr/io.h>
00002 
00003 #include "contiki-conf.h"
00004 
00005 void
00006 cpu_init(void)
00007 {
00008   asm volatile ("clr r1");      /* No longer needed. */
00009 }
00010 
00011 extern int __bss_end;
00012 
00013 #define STACK_EXTRA 32
00014 static char *cur_break = (char *)(&__bss_end + 1);
00015 
00016 /*
00017  * Allocate memory from the heap. Check that we don't collide with the
00018  * stack right now (some other routine might later). A watchdog might
00019  * be used to check if cur_break and the stack pointer meet during
00020  * runtime.
00021  */
00022 void *
00023 sbrk(int incr)
00024 {
00025   char *stack_pointer;
00026 
00027   stack_pointer = (char *)SP;
00028   stack_pointer -= STACK_EXTRA;
00029   if(incr > (stack_pointer - cur_break))
00030     return (void *)-1;          /* ENOMEM */
00031 
00032   void *old_break = cur_break;
00033   cur_break += incr;
00034   /*
00035    * If the stack was never here then [old_break .. cur_break] should
00036    * be filled with zeros.
00037   */
00038   return old_break;
00039 }

Generated on Mon Apr 11 14:23:35 2011 for Contiki 2.5 by  doxygen 1.6.1