ESP8266 ILI9341 display support code with printf sources, wire-frame viewer and custom fonts  1.0
ESP8266ILI9341DisplayProject
system.c
Go to the documentation of this file.
1 
24 #include "user_config.h"
25 
26 #ifdef AVR
27 #include <stdlib.h>
28 #endif
29 
30 #include "system.h"
31 
32 #include "mathio.h"
33 
35 #undef calloc
36 #undef free
38 #undef malloc
40 
41 extern void * _heap_start;
42 #define HEAP_START ((uint32_t) & (_heap_start))
43 #define HEAP_END ((uint32_t) (0x3FFFC000UL - 1UL))
44 
45 
50 MEMSPACE
51 void *malloc(size_t size)
52 {
53  void *p = (void *)os_zalloc( size );
54  if(!p)
55  {
56  printf("mcalloc(%d) failed!\n", size);
57  PrintRam();
58  }
59  return(p);
60 }
61 
62 
68 MEMSPACE
69 void *calloc(size_t nmemb, size_t size)
70 {
71  void *p = (void *)os_zalloc( (nmemb * size) );
72  if(!p)
73  {
74  printf("calloc(%d,%d) failed!\n", nmemb, size);
75  PrintRam();
76  }
77  return(p);
78 }
79 
80 
86 MEMSPACE
87 void free(void *p)
88 {
89  if( (uint32_t) p >= HEAP_START \
90  && (uint32_t) p <= HEAP_END)
91  {
92  os_free((int) p);
93  return;
94  }
95  printf("free: FREE ERROR (%08x)\n", p);
96  PrintRam();
97 }
98 
103 MEMSPACE
104 size_t freeRam()
105 {
106  return ((size_t) system_get_free_heap_size());
107 }
108 
109 
112 MEMSPACE
113 void PrintRam()
114 {
115  printf("Heap Free(%d) bytes\n" , system_get_free_heap_size());
116  printf("Heap Start(%08x), Heap End(%08x), Delta(%d)\n" ,
118 }
119 
127 MEMSPACE
128 void *safecalloc(size_t nmemb, size_t size)
129 {
130  void *p = calloc(nmemb, size);
131  if(!p)
132  {
133  printf("safecalloc(%d,%d) failed!\n", nmemb, size);
134  PrintRam();
135  }
136  return(p);
137 }
138 
145 MEMSPACE
146 void *safemalloc(size_t size)
147 {
148  return(safecalloc(size,1));
149 }
150 
154 #ifdef ESP8266
155 #endif
159 MEMSPACE
165 void safefree(void *p)
166 {
167  if( (uint32_t) p >= HEAP_START \
168  && (uint32_t) p <= HEAP_END)
169  {
170  free(p);
171  return;
172  }
173  printf("safefree: FREE ERROR (%08x)\n", p);
174  PrintRam();
175 }
176 
177 
180 MEMSPACE
181 void reset(void)
182 {
183  system_restart();
184 }
185 
186 
189 MEMSPACE
190 void wdt_reset( void )
191 {
192  WRITE_PERI_REG(0x60000914, 0x73);
193 }
MEMSPACE size_t freeRam()
Return Free memory.
Definition: system.c:104
void * _heap_start
calloc may be aliased to safecalloc
Master include file for project Includes all project includes and defines here.
MEMSPACE void reset(void)
reset system
Definition: system.c:181
MEMSPACE void PrintRam()
Display Free memory and regions.
Definition: system.c:113
#define HEAP_END
Definition: system.c:43
unsigned int uint32_t
Definition: send.c:19
MEMSPACE void * calloc(size_t nmemb, size_t size)
calloc buffer POSIX function
Definition: system.c:69
#define HEAP_START
Definition: system.c:42
MEMSPACE void free(void *p)
Free buffer POSIX function We only call os_free() is pointer is not null.
Definition: system.c:87
MEMSPACE void * safemalloc(size_t size)
Safe Malloc - Display Error message if Malloc fails.
Definition: system.c:146
MEMSPACE void * malloc(size_t size)
malloc buffer POSIX function
Definition: system.c:51
Math IO functions, and verious conversion code with floating point support.
#define MEMSPACE
Definition: cpu.h:25
MEMSPACE void wdt_reset(void)
reset watchdog
Definition: system.c:190
MEMSPACE int printf(const char *format,...)
System memory and reset utilities.
MEMSPACE void safefree(void *p)
Safe free - Only free a pointer if it is in malloc memory range. We want to try to catch frees of sta...
Definition: system.c:165
MEMSPACE void * safecalloc(size_t nmemb, size_t size)
Safe Calloc - Display Error message if Calloc fails.
Definition: system.c:128