00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <avr/io.h>
00023 #include <aversive.h>
00024
00025
00026 #include <diagnostic.h>
00027
00028
00036
00037 void fill_mem_with_mark(void) __attribute__ ((naked)) \
00038 __attribute__ ((section (".init1")));
00039
00040
00043 void fill_mem_with_mark(void)
00044 {
00045 register int i asm("r16");
00046 register int end asm("r18");
00047
00048
00049
00050 #ifdef DIAG_FILL_ENTIRE_RAM // fill entire RAM
00051 asm( "ldi r16,lo8(__data_start)" );
00052 asm( "ldi r17,hi8(__data_start)" );
00053 #else // fill only stack and heap spaces
00054 asm( "ldi r16,lo8(__heap_start)" );
00055 asm( "ldi r17,hi8(__heap_start)" );
00056 #endif
00057
00058
00059 asm( "ldi r18,lo8(__stack)" );
00060 asm( "ldi r19,hi8(__stack)" );
00061
00062
00063 for(; i< end ; i++)
00064 * ( (volatile unsigned char* )(i) ) = MARK;
00065
00066 }
00067
00068
00069 uint16_t min_stack_space_available(void)
00070 {
00071 register int i asm("r16");
00072 register int end asm("r18");
00073 uint16_t count , max;
00074
00075
00076 asm( "ldi r16,lo8(__heap_start)" );
00077 asm( "ldi r17,hi8(__heap_start)" );
00078
00079 asm( "ldi r18,lo8(__stack)" );
00080 asm( "ldi r19,hi8(__stack)" );
00081
00082
00083
00084 count = 0;
00085 max = 0;
00086 for(; i<end; i++) {
00087
00088 if (MARK == * ( (volatile unsigned char* )(i) )) {
00089
00090 count ++;
00091 if (count > max)
00092 max = count;
00093 }
00094 else
00095 count = 0;
00096 }
00097
00098 return max;
00099 }