Changeset 1175


Ignore:
Timestamp:
05/07/11 06:11:49 (2 years ago)
Author:
reyalP
Message:

GetMemInfo? to find available memory, equivalent for exmem - from philmoz in http://chdk.setepontos.com/index.php?topic=650.msg66186#msg66186

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/core/main.c

    r1124 r1175  
    5555        // to try allocating memory to find out how much is available 
    5656        // Call function to scan free list for the largest free block available. 
    57         extern int exmem_largest_block(); 
    58         return exmem_largest_block(); 
     57    cam_meminfo camera_meminfo; 
     58    GetExMemInfo(&camera_meminfo); 
     59    return camera_meminfo.free_block_max_size; 
     60#elif defined(CAM_FIRMWARE_MEMINFO) 
     61    // Call firmware function to fill memory info structure and return size of largest free block 
     62    cam_meminfo camera_meminfo; 
     63    GetMemInfo(&camera_meminfo); 
     64    return camera_meminfo.free_block_max_size; 
    5965#else 
    6066        int size, l_size, d; 
  • trunk/core/suba.c

    r1124 r1175  
    8686#define SUBA_MAGIC "\xFF\x15\x15\x15SUBA" 
    8787 
    88 int suba_largest_block(struct allocator *suba) 
    89 { 
    90         size_t sz = 0; 
     88void suba_getmeminfo(struct allocator *suba, int *allocated_size, int *allocated_peak, int *allocated_count, int *free_size, int *largest_block, int *free_block_count) 
     89{ 
     90        size_t largest = 0; 
     91    size_t free = 0; 
     92    size_t count = 0; 
    9193 
    9294        if (suba) 
    9395        { 
    9496                struct cell *c = SADR(suba, suba->tail); 
    95                 if (c->size > sz) sz = c->size; 
     97                if (c->size > largest) largest = c->size; 
     98        free += c->size; 
     99        count++; 
    96100                while (c->next != suba->tail) 
    97101                { 
    98102                        c = SADR(suba, c->next); 
    99                         if (c->size > sz) sz = c->size; 
    100                 } 
    101         } 
    102  
    103         return sz; 
     103                        if (c->size > largest) largest = c->size;    
     104            free += c->size; 
     105            count++; 
     106                } 
     107        } 
     108 
     109    *largest_block = largest; 
     110    *free_size = free; 
     111    *free_block_count = count; 
     112    *allocated_size = suba->size_total;     // TODO check this is a reasonable value for this field 
     113    *allocated_peak = suba->alloc_total;    // TODO check this is a reasonable value for this field 
     114    *allocated_count = 0;                   // TODO implement this 
    104115} 
    105116 
  • trunk/include/camera.h

    r1140 r1175  
    146146#undef    PARAM_CAMERA_NAME                      // parameter number for GetParameterData to get camera name 
    147147 
     148 
     149#undef  CAM_FIRMWARE_MEMINFO                    // Use 'GetMemInfo' function in firmware to get free memory details 
     150                                                // GetMemInfo should be found correctly by the gensig/finsig signature 
     151                                                // finder for all dryos based cameras. 
     152 
    148153//---------------------------------------------------------- 
    149154// Override Default values for Camera if necessary 
  • trunk/include/platform.h

    r1101 r1175  
    560560void ExitTask(); 
    561561 
     562// Data returned from GetMemInfo & GetExMemInfo functions stored in this data structure 
     563typedef struct { 
     564    int start_address; 
     565    int end_address; 
     566    int total_size; 
     567    int allocated_size; 
     568    int allocated_peak; 
     569    int allocated_count; 
     570    int free_size; 
     571    int free_block_max_size; 
     572    int free_block_count; 
     573} cam_meminfo; 
     574 
     575#if defined(CAM_FIRMWARE_MEMINFO) 
     576extern void GetMemInfo(cam_meminfo*); 
     577#endif 
     578 
    562579#ifdef OPT_EXMEM_MALLOC 
    563580void exmem_malloc_init(void); 
     581void GetExMemInfo(cam_meminfo*); 
    564582#endif 
    565583 
  • trunk/platform/d10/platform_camera.h

    r1140 r1175  
    131131    #define  CAM_CHDK_PTP               1 // include CHDK PTP support 
    132132 
     133#define CAM_FIRMWARE_MEMINFO    1       // Use 'GetMemInfo' to get free memory size. 
     134 
    133135//---------------------------------------------------------- 
    134  
    135  
    136 //========================================================== 
    137 // SD-Series (IXUS-Series) 
    138 //========================================================== 
  • trunk/platform/g12/platform_camera.h

    r1148 r1175  
    110110                                                                                                                        // see http://chdk.setepontos.com/index.php?topic=6179.0 
    111111 
     112#define CAM_FIRMWARE_MEMINFO    1       // Use 'GetMemInfo' to get free memory size. 
     113 
    112114//---------------------------------------------------------- 
    113115 
  • trunk/platform/generic/wrappers.c

    r1160 r1175  
    700700                // round MEMISOSIZE up to next 4 byte boundary if needed (just in case) 
    701701                exmem_start = mem + ((MEMISOSIZE+3)&0xFFFFFFFC); 
    702                 exmem_size = EXMEM_HEAP_SIZE - EXMEM_HEAP_SKIP - ((MEMISOSIZE+3)&0xFFFFFFFC); 
     702                exmem_size = EXMEM_BUFFER_SIZE - ((MEMISOSIZE+3)&0xFFFFFFFC); 
    703703#else 
    704704                // Set start & size based on requested values 
    705705                exmem_start = mem; 
    706                 exmem_size = EXMEM_HEAP_SIZE - EXMEM_HEAP_SKIP; 
     706                exmem_size = EXMEM_BUFFER_SIZE; 
    707707#endif 
    708708                exmem_end = exmem_start + exmem_size; 
     
    737737} 
    738738 
    739 int exmem_largest_block() 
    740 { 
    741         extern int suba_largest_block(void*); 
    742         return suba_largest_block(exmem_heap); 
     739// Use suba functions to fill meminfo structure to match firmware GetMemInfo function 
     740 
     741void GetExMemInfo(cam_meminfo *camera_meminfo) 
     742{ 
     743        extern void suba_getmeminfo(void*, int*, int*, int*, int*, int*, int*); 
     744 
     745    camera_meminfo->start_address        = (int)exmem_start; 
     746    camera_meminfo->end_address          = (int)exmem_start + exmem_size; 
     747    camera_meminfo->total_size           = exmem_size; 
     748    suba_getmeminfo(exmem_heap, 
     749                    &camera_meminfo->allocated_size, &camera_meminfo->allocated_peak, &camera_meminfo->allocated_count, 
     750                    &camera_meminfo->free_size, &camera_meminfo->free_block_max_size, &camera_meminfo->free_block_count); 
    743751} 
    744752// regular malloc 
     
    785793#endif 
    786794} 
     795  
     796#if defined(CAM_FIRMWARE_MEMINFO) 
     797 
     798// Use firmware GetMemInfo function to retrieve info about Canon heap memory allocation 
     799 
     800void GetMemInfo(cam_meminfo *camera_meminfo) 
     801{ 
     802    // Prior to dryos R39 GetMemInfo returns 9 values, after R39 it returns 10 (all but 1 are used in each case) 
     803    int fw_info[10]; 
     804    extern void _GetMemInfo(int*); 
     805    _GetMemInfo(fw_info); 
     806 
     807#if defined(CAM_DRYOS_2_3_R39) 
     808    // For newer dryos version copy all 9 used values to CHDK structure 
     809    camera_meminfo->start_address        = fw_info[0]; 
     810    camera_meminfo->end_address          = fw_info[1]; 
     811    camera_meminfo->total_size           = fw_info[2]; 
     812    camera_meminfo->allocated_size       = fw_info[3]; 
     813    camera_meminfo->allocated_peak       = fw_info[4]; 
     814    camera_meminfo->allocated_count      = fw_info[5]; 
     815    camera_meminfo->free_size            = fw_info[6]; 
     816    camera_meminfo->free_block_max_size  = fw_info[7]; 
     817    camera_meminfo->free_block_count     = fw_info[8]; 
     818#else 
     819    // For older dryos version copy 8 used values to CHDK structure and calculate missing value 
     820    camera_meminfo->start_address        = fw_info[0]; 
     821    camera_meminfo->end_address          = fw_info[0] + fw_info[1]; 
     822    camera_meminfo->total_size           = fw_info[1]; 
     823    camera_meminfo->allocated_size       = fw_info[2]; 
     824    camera_meminfo->allocated_peak       = fw_info[3]; 
     825    camera_meminfo->allocated_count      = fw_info[4]; 
     826    camera_meminfo->free_size            = fw_info[5]; 
     827    camera_meminfo->free_block_max_size  = fw_info[6]; 
     828    camera_meminfo->free_block_count     = fw_info[7]; 
     829#endif 
     830} 
     831 
     832#endif 
    787833 
    788834//---------------------------------------------------------------------------- 
  • trunk/platform/sx30/platform_camera.h

    r1140 r1175  
    104104 
    105105    #define CAM_KEY_CLICK_DELAY 150 // SX30 appears to need extra delay for clicks 
     106 
     107#define CAM_FIRMWARE_MEMINFO    1       // Use 'GetMemInfo' to get free memory size. 
     108 
    106109//---------------------------------------------------------- 
Note: See TracChangeset for help on using the changeset viewer.