root/platform/ixus40_sd300/main.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. core_hook_task_create
  2. core_hook_task_delete
  3. spytask
  4. task_start_hook
  5. remount_filesystem
  6. task_fs
  7. capt_seq_hook
  8. movie_record_hook
  9. my_ncmp
  10. createHook
  11. deleteHook
  12. startup
  13. get_vbatt_min
  14. get_vbatt_max
  15. get_effective_focal_length
  16. get_focal_length
  17. get_zoom_x
  18. rec_mode_active
  19. hook_tyWriteOrig
  20. cam_console_init

   1 #define VBATT_DEFAULT_MIN (3500)
   2 #define VBATT_DEFAULT_MAX (4100)
   3 
   4 #include "lolevel.h"
   5 #include "platform.h"
   6 #include "core.h"
   7 #include "keyboard.h"
   8 
   9 /* Ours stuff */
  10 extern long link_bss_start;
  11 extern long link_bss_end;
  12 extern void boot();
  13 extern void mykbd_task(long ua, long ub, long uc, long ud, long ue, long uf);
  14 extern void kbd_process_task(long ua, long ub, long uc, long ud, long ue, long uf);
  15 
  16 static void core_hook_task_create(__attribute__ ((unused))void *tcb)
  17 {
  18 }
  19 
  20 static void core_hook_task_delete(void *tcb)
  21 {
  22     char *name = (char*)(*(long*)((char*)tcb+0x34));
  23     if (strcmp(name,"tInitFileM")==0) core_spytask_can_start();
  24 }
  25 
  26 static int stop_hooking;
  27 
  28 static void (*taskprev)(
  29     long p0,    long p1,    long p2,    long p3,    long p4,
  30     long p5,    long p6,    long p7,    long p8,    long p9);
  31 
  32 static void (*taskfsprev)(
  33     long p0,    long p1,    long p2,    long p3,    long p4,
  34     long p5,    long p6,    long p7,    long p8,    long p9);
  35 
  36 
  37 
  38 void spytask(long ua, long ub, long uc, long ud, long ue, long uf)
  39         {
  40     (void)ua; (void)ub; (void)uc; (void)ud; (void)ue; (void)uf;
  41     core_spytask(); // This is the main CHDK loop
  42         }
  43 
  44 
  45 static void task_start_hook(
  46     long p0,    long p1,    long p2,    long p3,    long p4,
  47     long p5,    long p6,    long p7,    long p8,    long p9)
  48         {
  49     _CreateTask("SpyTask", 0x19, 0x2000, spytask, 0); // First creates the SpyTask, i.e. the main CHDK loop
  50     
  51     //create our second keypress task
  52                 _CreateTask("SpyTask2", 0x18, 0x2000, kbd_process_task, 0); 
  53     
  54     taskprev(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9 ); // then, whatever was the call intended to be...
  55         }
  56 
  57 
  58 static void remount_filesystem()
  59 {
  60     _Unmount_FileSystem();
  61     _Mount_FileSystem();
  62 }
  63 
  64 
  65 static void task_fs(
  66     long p0,    long p1,    long p2,    long p3,    long p4,
  67     long p5,    long p6,    long p7,    long p8,    long p9)
  68         {
  69     remount_filesystem();
  70     taskfsprev(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9 );
  71         }
  72 
  73 
  74 static void capt_seq_hook(
  75     long p0,    long p1,    long p2,    long p3,    long p4,
  76     long p5,    long p6,    long p7,    long p8,    long p9)
  77         {
  78     (void)p0; (void)p1; (void)p2; (void)p3; (void)p4; (void)p5; (void)p6; (void)p7; (void)p8; (void)p9;
  79     capt_seq_task();
  80         }
  81 
  82 static void movie_record_hook(
  83     long p0,    long p1,    long p2,    long p3,    long p4,
  84     long p5,    long p6,    long p7,    long p8,    long p9)
  85         {
  86     (void)p0; (void)p1; (void)p2; (void)p3; (void)p4; (void)p5; (void)p6; (void)p7; (void)p8; (void)p9;
  87     movie_record_task();
  88         }
  89 
  90 
  91 
  92 static int my_ncmp(const char *s1, const char *s2, long len)
  93         {
  94     int i;
  95     for (i=0;i<len;i++)
  96                 {
  97                 if (s1[i] != s2[i])
  98                         return 1;
  99                 }
 100     return 0;
 101         }
 102 
 103 void createHook (void *pNewTcb)
 104 {
 105     char *name = (char*)(*(long*)((char*)pNewTcb+0x34));
 106     long *entry = (long*)((char*)pNewTcb+0x74);
 107     
 108     //volatile long *p; p=(void*) 0xc02200E0; *p=0x46; //debug led
 109     
 110     // always hook first task creation
 111     // to create SpyTask
 112     if (!stop_hooking){
 113         taskprev = (void*)(*entry);
 114         *entry = (long)task_start_hook;
 115         stop_hooking = 1;
 116     }else{
 117         // hook/replace another tasks
 118         // Replace the call to "SwitchCheckTask" with our own procedure
 119         if (my_ncmp(name, "tSwitchChe", 10) == 0){
 120             *entry = (long)mykbd_task;
 121         }
 122         
 123         // Replace the call to "InitFileModules" with our own procedure
 124         if (my_ncmp(name, "tInitFileM", 10) == 0){
 125             taskfsprev = (void*)(*entry);
 126             *entry = (long)task_fs;
 127         }
 128         
 129         // Replace the call to "CaptSeqTask" with our own procedure
 130         if (my_ncmp(name, "tCaptSeqTa", 10) == 0){
 131             *entry = (long)capt_seq_hook;
 132         }
 133 
 134         if (my_ncmp(name, "tMovieRecT", 10) == 0){
 135             *entry = (long)movie_record_hook;
 136         }
 137 
 138 core_hook_task_create(pNewTcb);
 139 }
 140         }
 141 
 142 void deleteHook (void *pTcb)
 143         {
 144     core_hook_task_delete(pTcb);
 145         }
 146 
 147 void startup()
 148         {
 149     long *bss = &link_bss_start;
 150 
 151     //volatile long *p; p=(void*) 0xc02200E0; *p=0x46; //debug led
 152 
 153     // sanity check
 154     if ((long)&link_bss_end > (MEMISOSTART + MEMISOSIZE)) {
 155                         started();
 156                         shutdown();
 157     }
 158 
 159     // initialize .bss segment
 160     while (bss<&link_bss_end)
 161                 *bss++ = 0;
 162 
 163     // fill memory with this magic value so we could see what
 164     // parts of memory were or not used
 165     
 166     // update:
 167     // this seems to be required for unknown reason
 168     // or else sryproc startup will fail from
 169     // time to time...
 170 #if 0
 171     long *ptr;
 172     for (ptr=(void*)MEMBASEADDR;((long)ptr)<MEMISOSTART;ptr+=4)
 173                 {
 174                 ptr[0]=0x55555555;
 175                 ptr[1]=0x55555555;
 176                 ptr[2]=0x55555555;
 177                 ptr[3]=0x55555555;
 178                 }
 179 #endif
 180 
 181     boot();
 182         }
 183 
 184 long get_vbatt_min()
 185         {
 186     return 3500;
 187         }
 188 
 189 long get_vbatt_max()
 190         {
 191     return 4100;
 192         }
 193 
 194 // Focus length table in firmware @0xffd792e8
 195 #define NUM_FL      7   // 0 - 6, entries in firmware
 196 #define NUM_DATA    3   // 3 words each entry, first is FL
 197 extern int focus_len_table[NUM_FL*NUM_DATA];
 198 
 199 // Conversion factor lens FL --> 35mm equiv
 200 // lens      35mm     CF
 201 // ----      ----     --
 202 // 5.8       35       ( 35/ 5.8) * 580 = 3500  (min FL)
 203 // 17.4      105      (105/17.4) * 580 = 3500  (max FL)
 204 #define CF_EFL      3500
 205 #define CF_EFL_DIV  580
 206 
 207 const int zoom_points = NUM_FL;
 208 
 209 int get_effective_focal_length(int zp) {
 210     return (CF_EFL*get_focal_length(zp))/CF_EFL_DIV;
 211 }
 212 
 213 int get_focal_length(int zp) {
 214     if (zp < 0) zp = 0;
 215     else if (zp >= NUM_FL) zp = NUM_FL-1;
 216     return focus_len_table[zp*NUM_DATA];
 217 }
 218 
 219 int get_zoom_x(int zp) {
 220     return get_focal_length(zp)*10/focus_len_table[0];
 221 }
 222 
 223 int rec_mode_active(void) {
 224     //return ((physw_status[0]&0x03)==0x01) ? 0 : 1;
 225     return (playrec_mode==1); //(0 in play, 1 in record, 2 in record review)
 226 }
 227 
 228 #if 0
 229   //CAM_CONSOLE_LOG_ENABLED
 230 #define DEV_HDR_WRITE_OFFSET (0x14C/4)
 231 
 232 typedef int DEV_HDR;
 233 
 234 int (*_tyWriteOrig)(DEV_HDR *hdr, char *buf, int len);
 235 
 236 
 237 int hook_tyWriteOrig(DEV_HDR *hdr, char *buf, int len)
 238 {
 239         // Slow, but stable writes
 240         FILE *fd = fopen("A/stdout.txt", "a");
 241         if (fd) {
 242             fwrite(buf, 1, len, fd);
 243             fclose(fd);
 244         }
 245 
 246     return _tyWriteOrig(hdr, buf, len);
 247 
 248 }
 249 
 250 void cam_console_init()
 251 {
 252     DEV_HDR *DRV_struct;
 253 
 254     DRV_struct = _iosDevFind("/tyCo/0", 0);
 255 
 256     _tyWriteOrig = (void*)DRV_struct[DEV_HDR_WRITE_OFFSET];
 257 
 258         FILE *fd = fopen("A/chdklog.txt", "a");
 259         if (fd) {
 260             // can't be used with "Fut" API
 261             //fprintf(fd, "DRV_struct: %x, _tyWriteOrig: %x\n", DRV_struct, _tyWriteOrig);
 262             char buf[256];
 263             int buflen = sprintf(buf, "DRV_struct: %x, _tyWriteOrig: %x\n", DRV_struct, _tyWriteOrig);
 264             fwrite(buf, 1, buflen, fd);
 265         }
 266 
 267         FILE *fdout = fopen("A/stdout.txt", "r");
 268         if (fdout)
 269         {
 270         DRV_struct[DEV_HDR_WRITE_OFFSET] = (int)hook_tyWriteOrig;
 271         fclose(fdout);
 272             // fprintf(fd, "tyWrite replaced, camera log enabled\n");
 273             fwrite("tyWrite replaced, camera log enabled\n", 1, sizeof("tyWrite replaced, camera log enabled\n"), fd);
 274     }
 275 
 276         if (fd)
 277         {
 278             fclose(fd);
 279         }
 280 
 281 }
 282 xx
 283 #endif

/* [<][>][^][v][top][bottom][index][help] */