source: trunk/core/main.c @ 1124

Revision 1124, 4.2 KB checked in by reyalP, 2 years ago (diff)

exmem improvements, experimental support for loading CHDK binary in exmem - from philmoz in http://chdk.setepontos.com/index.php?topic=650.msg63808#msg63808

  • Property svn:eol-style set to native
Line 
1#include "platform.h"
2#include "core.h"
3#include "conf.h"
4#include "keyboard.h"
5#include "stdlib.h"
6#include "gui.h"
7#include "histogram.h"
8#include "raw.h"
9#ifdef OPT_EDGEOVERLAY
10    #include "edgeoverlay.h"
11#endif
12static int raw_need_postprocess;
13static volatile int spytask_can_start;
14
15void core_hook_task_create(void *tcb) {
16}
17
18void core_hook_task_delete(void *tcb) {
19    char *name = (char*)(*(long*)((char*)tcb+0x34));
20    if (strcmp(name,"tInitFileM")==0) core_spytask_can_start();
21}
22
23long core_get_noise_reduction_value() {
24    return conf.raw_nr;
25}
26
27void dump_memory() {
28    int fd;
29    static int cnt=1;
30    static char fn[32];
31
32    started();
33    mkdir("A/DCIM");
34    mkdir("A/DCIM/100CANON");
35    sprintf(fn, "A/DCIM/100CANON/CRW_%04d.JPG", cnt++);
36    fd = open(fn, O_WRONLY|O_CREAT, 0777);
37    if (fd) {
38#ifdef CAMERA_ixus65_sd630    // Zero is not readable on ixus65!
39        write(fd, (int*)0xFFFF0000, 4);
40        write(fd, (int*)4, 0x1900-4);
41#else
42        write(fd, (void*)0, 0x1900);
43#endif
44        // TODO actual memory size is larger than 32 MB on many cameras!
45        write(fd, (void*)0x1900, 32*1024*1024-0x1900);
46        close(fd);
47    }
48    vid_bitmap_refresh();
49    finished();
50}
51
52int core_get_free_memory() {
53#if defined(OPT_EXMEM_MALLOC) && !defined(OPT_EXMEM_TESTING)
54        // If using the exmem / suba memory allocation system then don't need
55        // to try allocating memory to find out how much is available
56        // Call function to scan free list for the largest free block available.
57        extern int exmem_largest_block();
58        return exmem_largest_block();
59#else
60        int size, l_size, d;
61    char* ptr;
62
63    size = 16;
64    while (1) {
65        ptr= malloc(size);
66        if (ptr) {
67            free(ptr);
68            size <<= 1;
69        } else
70            break;
71    }
72
73    l_size = size;
74    size >>= 1;
75    d=1024;
76    while (d) {
77        ptr = malloc(size);
78        if (ptr) {
79            free(ptr);
80            d = l_size-size;
81            if (d<0) d=-d;
82            l_size = size;
83            size += d>>1;
84        } else {
85            d = size-l_size;
86            if (d<0) d=-d;
87            l_size = size;
88            size -= d>>1;
89        }
90       
91    }
92    return size-1;
93#endif
94}
95
96static volatile long raw_data_available;
97
98// called from another process
99void core_rawdata_available() {
100    raw_data_available = 1;
101}
102
103void core_spytask_can_start() {
104    spytask_can_start = 1;
105}
106
107void core_spytask() {
108    int cnt = 1;
109    int i=0;
110
111    raw_need_postprocess = 0;
112
113    spytask_can_start=0;
114
115#ifdef OPT_EXMEM_MALLOC
116        exmem_malloc_init();
117#endif
118
119#ifdef CAM_CHDK_PTP
120    init_chdk_ptp_task();
121#endif
122
123    while((i++<400) && !spytask_can_start) msleep(10);
124
125    started();
126    msleep(50);
127    finished();
128    drv_self_unhide();
129
130    conf_restore();
131    gui_init();
132
133#if CAM_CONSOLE_LOG_ENABLED
134    cam_console_init();
135#endif
136
137    mkdir("A/CHDK");
138    mkdir("A/CHDK/FONTS");
139    mkdir("A/CHDK/SYMBOLS");
140    mkdir("A/CHDK/SCRIPTS");
141    mkdir("A/CHDK/LANG");
142    mkdir("A/CHDK/BOOKS");
143    mkdir("A/CHDK/GRIDS");
144#ifdef OPT_CURVES
145    mkdir("A/CHDK/CURVES");
146#endif
147    mkdir("A/CHDK/DATA");
148    mkdir("A/CHDK/LOGS");
149#ifdef OPT_EDGEOVERLAY
150    mkdir("A/CHDK/EDGE");
151#endif
152    auto_started = 0;
153
154#ifdef OPT_SCRIPTING
155    if (conf.script_startup==1) script_autostart();    // remote autostart
156    if (conf.script_startup==2) {
157        conf.script_startup=0;
158        conf_save();
159        script_autostart();
160    }
161#endif
162
163    while (1) {
164        if (raw_data_available) {
165            raw_need_postprocess = raw_savefile();
166            hook_raw_save_complete();
167            raw_data_available = 0;
168            continue;
169        }
170
171        if (state_shooting_progress != SHOOTING_PROGRESS_PROCESSING) {
172            if (((cnt++) & 3) == 0)
173                gui_redraw();
174
175            histogram_process();
176#ifdef OPT_EDGEOVERLAY
177            if(conf.edge_overlay_thresh && conf.edge_overlay_enable) edge_overlay();
178#endif
179        }
180
181        if ((state_shooting_progress == SHOOTING_PROGRESS_PROCESSING) && (!shooting_in_progress())) {
182            state_shooting_progress = SHOOTING_PROGRESS_DONE;
183            if (raw_need_postprocess) raw_postprocess();
184        }
185
186        msleep(20);
187    }
188}
189
190long ftell(FILE *file) {
191    if(!file) return -1;
192    return file->pos;
193}
Note: See TracBrowser for help on using the repository browser.