CHDK_DE Vorschauversion  Trunk Rev. 5279
 Alle Datenstrukturen Dateien Funktionen Variablen Typdefinitionen Aufzählungen Aufzählungswerte Makrodefinitionen
memmgmt.c-Dateireferenz
#include "platform.h"
#include "stdlib.h"
#include "core.h"
#include "conf.h"
#include "gui_draw.h"
+ Include-Abhängigkeitsdiagramm für memmgmt.c:

gehe zum Quellcode dieser Datei

Datenstrukturen

struct  chdk_heap
 

Funktionen

void * suba_init (void *heap, unsigned size, unsigned mincell, char *name)
 
void * suba_alloc (void *heap, unsigned size, unsigned zero)
 
int suba_free (void *heap, void *p)
 
static void chdk_heap_init (chdk_heap *h)
 
static void chdk_heap_create (chdk_heap *h, void *mem, int size, int chdk_in_heap, int heap_testing, char *name)
 
static void * chdk_malloc (chdk_heap *h, unsigned size)
 
static int chdk_free (chdk_heap *h, void *p)
 
static int chdk_meminfo (chdk_heap *h, cam_meminfo *camera_meminfo)
 
void exmem_malloc_init ()
 
int GetExMemInfo (cam_meminfo *camera_meminfo)
 
void aram_malloc_init ()
 
int GetARamInfo (cam_meminfo *camera_meminfo)
 
void canon_malloc_init (void)
 
static void combine_meminfo (cam_meminfo *combined, cam_meminfo *m)
 
void GetCombinedMemInfo (cam_meminfo *camera_meminfo)
 
void * malloc (long size)
 
void free (void *p)
 

Variablen

static chdk_heap exmem_heap
 
static chdk_heap aram_heap
 
int canon_heap_sem
 

Dokumentation der Funktionen

void aram_malloc_init ( )

Definiert in Zeile 207 der Datei memmgmt.c.

208 {
210 #ifdef OPT_ARAM_MALLOC
211 #ifndef OPT_CHDK_IN_ARAM
212 #define OPT_CHDK_IN_ARAM 0
213 #endif
214 #ifndef OPT_ARAM_TESTING
215 #define OPT_ARAM_TESTING 0
216 #endif
217  chdk_heap_create(&aram_heap, (void*)ARAM_HEAP_START, ARAM_HEAP_SIZE, OPT_CHDK_IN_ARAM, OPT_ARAM_TESTING, "aram_suba");
218 #endif
219 }
void canon_malloc_init ( void  )

Definiert in Zeile 232 der Datei memmgmt.c.

232  {
233  canon_heap_sem=CreateBinarySemaphore("canonheap", 1);
234 }
static int chdk_free ( chdk_heap h,
void *  p 
)
static

Definiert in Zeile 79 der Datei memmgmt.c.

80 {
81  if (h && h->heap && (p >= h->start) && (p < h->end))
82  {
83  suba_free(h->heap,p);
84  return 1;
85  }
86  return 0;
87 }
static void chdk_heap_create ( chdk_heap h,
void *  mem,
int  size,
int  chdk_in_heap,
int  heap_testing,
char *  name 
)
static

Definiert in Zeile 32 der Datei memmgmt.c.

33 {
34  if (h)
35  {
36  if (chdk_in_heap)
37  {
38  // If loading CHDK into heap then move heap start past the end of CHDK
39  // and reduce available space by CHDK size (MEMISOSIZE)
40  // round MEMISOSIZE up to next 4 byte boundary if needed (just in case)
41  h->start = mem + ((camera_info.memisosize+3)&0xFFFFFFFC);
42  h->size = size - ((camera_info.memisosize+3)&0xFFFFFFFC);
43  }
44  else
45  {
46  // Set start & size based on requested values
47  h->start = mem;
48  h->size = size;
49  }
50 
51  h->end = h->start + h->size;
52 
53  if (heap_testing)
54  {
55  // For testing exmem allocated memory for corruption from normal camera operations
56  // set the above #define. This will allocate the memory; but won't use it (exmem_heap is set to 0)
57  // Instead all the memory is filled with the guard value below.
58  // In gui_draw_debug_vals_osd (gui.c) the memory is tested for the guard value and if any
59  // corruption has occurred then info about the memory locations that were altered is displayed
60  // Note: do not use heap_testing and chdk_in_heap at the same time
61  unsigned long *p;
62  for (p=(unsigned long*)h->start; p<(unsigned long*)h->end; p++) *p = 0xDEADBEEF;
63  }
64  else
65  {
66  // Normal operation, use the suba allocation system to manage the memory block
67  h->heap = suba_init(h->start,h->size,8,name);
68  }
69  }
70 }
static void chdk_heap_init ( chdk_heap h)
static

Definiert in Zeile 24 der Datei memmgmt.c.

25 {
26  h->heap = 0;
27  h->start = 0;
28  h->end = 0;
29  h->size = 0;
30 }
static void* chdk_malloc ( chdk_heap h,
unsigned  size 
)
static

Definiert in Zeile 72 der Datei memmgmt.c.

73 {
74  if (h && h->heap)
75  return suba_alloc(h->heap,size,0);
76  return 0;
77 }
static int chdk_meminfo ( chdk_heap h,
cam_meminfo camera_meminfo 
)
static

Definiert in Zeile 90 der Datei memmgmt.c.

91 {
92  if (h && h->heap)
93  {
94  extern void suba_getmeminfo(void*, int*, int*, int*, int*, int*, int*);
95 
96  camera_meminfo->start_address = (int)h->start;
97  camera_meminfo->end_address = (int)h->end;
98  camera_meminfo->total_size = h->size;
100  &camera_meminfo->allocated_size, &camera_meminfo->allocated_peak, &camera_meminfo->allocated_count,
101  &camera_meminfo->free_size, &camera_meminfo->free_block_max_size, &camera_meminfo->free_block_count);
102 
103  return 1; // return success
104  }
105  else
106  {
107  memset(camera_meminfo, 0, sizeof(cam_meminfo));
108  return 0;
109  }
110 }
static void combine_meminfo ( cam_meminfo combined,
cam_meminfo m 
)
static

Definiert in Zeile 238 der Datei memmgmt.c.

239 {
240  combined->total_size += m->total_size;
241  if(m->free_block_max_size > combined->free_block_max_size)
242  {
244  }
245  combined->free_size += m->free_size;
246  combined->free_block_count += m->free_block_count;
247  combined->allocated_size += m->allocated_size;
248  combined->allocated_peak += m->allocated_peak;
249  combined->allocated_count += m->allocated_count;
250 }
void exmem_malloc_init ( )

Definiert in Zeile 170 der Datei memmgmt.c.

171 {
173 #ifdef OPT_EXMEM_MALLOC
174 #ifndef OPT_CHDK_IN_EXMEM
175 #define OPT_CHDK_IN_EXMEM 0
176 #endif
177 #ifndef OPT_EXMEM_TESTING
178 #define OPT_EXMEM_TESTING 0
179 #endif
180  // pool zero is EXMEM_RAMDISK on d10
181  extern void *exmem_alloc(int pool_id,int size,int unk,int unk2);
182  void *mem = exmem_alloc(0,EXMEM_HEAP_SIZE,0,0);
183  if (mem)
184  {
185  chdk_heap_create(&exmem_heap, mem, EXMEM_BUFFER_SIZE, OPT_CHDK_IN_EXMEM, OPT_EXMEM_TESTING, "exmem_suba");
186  }
187 #endif
188 }
void free ( void *  p)

Definiert in Zeile 299 der Datei memmgmt.c.

300 {
301  extern void canon_free(void *p);
302 
303  if (!chdk_free(&aram_heap,p))
304  if (!chdk_free(&exmem_heap,p))
305  canon_free(p);
306 }
int GetARamInfo ( cam_meminfo camera_meminfo)

Definiert in Zeile 222 der Datei memmgmt.c.

223 {
224  return chdk_meminfo(&aram_heap, camera_meminfo);
225 }
void GetCombinedMemInfo ( cam_meminfo camera_meminfo)

Definiert in Zeile 255 der Datei memmgmt.c.

256 {
257  // get system meminfo, should always be available
258  GetMemInfo(camera_meminfo);
259 // some fields are set to -1 for vxworks cams
260 #if !defined(CAM_DRYOS)
261  camera_meminfo->allocated_peak = 0;
262  camera_meminfo->total_size = 0;
263 #ifdef CAM_NO_MEMPARTINFO
264  // a more useful base value than 0
265  camera_meminfo->free_size = camera_meminfo->free_block_max_size;
266  camera_meminfo->free_block_count = 0;
267  camera_meminfo->allocated_size = 0;
268  camera_meminfo->allocated_count = 0;
269 #endif
270 #endif
271 
272  // these don't make sense to combine
273  camera_meminfo->start_address = camera_meminfo->end_address = 0;
274 
275  cam_meminfo m;
276  if(GetARamInfo(&m)) {
277  combine_meminfo(camera_meminfo,&m);
278  }
279  if(GetExMemInfo(&m)) {
280  combine_meminfo(camera_meminfo,&m);
281  }
282 }
int GetExMemInfo ( cam_meminfo camera_meminfo)

Definiert in Zeile 191 der Datei memmgmt.c.

192 {
193  return chdk_meminfo(&exmem_heap, camera_meminfo);
194 }
void* malloc ( long  size)

Definiert in Zeile 284 der Datei memmgmt.c.

285 {
286  extern void *canon_malloc(long size);
287 
288  void *p = chdk_malloc(&aram_heap,size);
289 
290  if (p == 0)
291  p = chdk_malloc(&exmem_heap,size);
292 
293  if (p == 0)
294  p = canon_malloc(size);
295 
296  return p;
297 }
void* suba_alloc ( void *  heap,
unsigned  size,
unsigned  zero 
)
int suba_free ( void *  heap,
void *  p 
)
void* suba_init ( void *  heap,
unsigned  size,
unsigned  mincell,
char *  name 
)

Variablen-Dokumentation

chdk_heap aram_heap
static

Definiert in Zeile 198 der Datei memmgmt.c.

int canon_heap_sem

Definiert in Zeile 230 der Datei memmgmt.c.

chdk_heap exmem_heap
static

Definiert in Zeile 161 der Datei memmgmt.c.