apps/autoexposure/globalsinit.c

Go to the documentation of this file.
00001 /*!***************************************************************************
00002 *! FILE NAME  : globalsinit.c
00003 *! DESCRIPTION: Opens files, mmap-s data structures, initializes variables
00004 *!              For the autoexposure daemon
00005 *! Copyright (C) 2008 Elphel, Inc.
00006 *! -----------------------------------------------------------------------------**
00007 *!  This program is free software: you can redistribute it and/or modify
00008 *!  it under the terms of the GNU General Public License as published by
00009 *!  the Free Software Foundation, either version 3 of the License, or
00010 *!  (at your option) any later version.
00011 *!
00012 *!  This program is distributed in the hope that it will be useful,
00013 *!  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 *!  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 *!  GNU General Public License for more details.
00016 *!
00017 *!  You should have received a copy of the GNU General Public License
00018 *!  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00019 *! -----------------------------------------------------------------------------**
00020 *!
00021 *!  $Log: globalsinit.c,v $
00022 *!  Revision 1.1.1.1  2008/11/27 20:04:01  elphel
00023 *!
00024 *!
00025 *!  Revision 1.2  2008/11/18 19:30:16  elphel
00026 *!  Added initialization of the "next" frame - otherwise it wait _very_ long if the camera frame number is reset
00027 *!
00028 *!  Revision 1.1  2008/11/15 23:08:24  elphel
00029 *!  8.0.alpha17 - split autoexposure source file
00030 *!
00031 *!
00032 */ 
00033 
00034 #include "autoexposure.h"
00035 
00036 
00037 
00038 
00039   int fd_fparmsall, fd_histogram_cache, fd_gamma_cache;
00040   struct framepars_all_t    *frameParsAll;
00041   struct framepars_t        *framePars;
00042   unsigned long             *globalPars;
00043   struct framepars_past_t   *pastPars;
00044   struct histogram_stuct_t  * histogram_cache; 
00045 
00046   struct gamma_stuct_t  * gamma_cache; 
00047   int hist_index; 
00048   int gamma_index; 
00049   int aex_recover_cntr;
00050   unsigned long this_frame;
00051 
00052   int      autoexposure_debug;
00053 
00054 
00060 int initFilesMmap(void) {
00061   const char framepars_driver_name[]="/dev/frameparsall";
00062   const char histogram_driver_name[]="/dev/histogram_cache";
00063   const char gamma_driver_name[]=    "/dev/gamma_cache";
00065   fd_fparmsall= open(framepars_driver_name, O_RDWR);
00066   if (fd_fparmsall <0) {
00067      ELP_FERR(fprintf(stderr, "Open failed: (%s)\r\n", framepars_driver_name));
00068      return -1;
00069   }
00070   frameParsAll = (struct framepars_all_t *) mmap(0, sizeof (struct framepars_all_t) * HISTOGRAM_CACHE_NUMBER , PROT_READ | PROT_WRITE, MAP_SHARED, fd_fparmsall, 0);
00071   if((int) frameParsAll == -1) {
00072      ELP_FERR(fprintf(stderr, "problems with mmap: %s\n", framepars_driver_name));
00073      close (fd_fparmsall);
00074      return -1;
00075   }
00076   framePars =   frameParsAll->framePars;
00077   pastPars =    frameParsAll->pastPars;
00078   globalPars=   frameParsAll->globalPars;
00079 
00081   fd_histogram_cache= open(histogram_driver_name, O_RDONLY);
00082   if (fd_histogram_cache <0) {
00083      ELP_FERR(fprintf(stderr, "Open failed: (%s)\r\n", histogram_driver_name));
00084      close (fd_fparmsall);
00085      return -1;
00086   }
00087   histogram_cache = (struct histogram_stuct_t *) mmap(0, sizeof (struct histogram_stuct_t) * HISTOGRAM_CACHE_NUMBER , PROT_READ, MAP_SHARED, fd_histogram_cache, 0);
00088   if((int) histogram_cache == -1) {
00089      ELP_FERR(fprintf(stderr, "problems with mmap: %s\n", histogram_driver_name));
00090      close (fd_fparmsall);
00091      close (fd_histogram_cache);
00092      return -1;
00093   }
00094 
00096   fd_gamma_cache= open(gamma_driver_name, O_RDWR);
00097   if (fd_gamma_cache <0) {
00098      ELP_FERR(fprintf(stderr, "Open failed: (%s)\r\n", gamma_driver_name));
00099      close (fd_fparmsall);
00100      close (fd_histogram_cache);
00101      return -1;
00102   }
00103   gamma_cache = (struct gamma_stuct_t *) mmap(0, sizeof (struct gamma_stuct_t) * GAMMA_CACHE_NUMBER , PROT_READ, MAP_SHARED, fd_gamma_cache, 0);
00104   if((int) gamma_cache == -1) {
00105      ELP_FERR(fprintf(stderr, "problems with mmap: %s\n", gamma_driver_name));
00106      close (fd_fparmsall);
00107      close (fd_histogram_cache);
00108      close (fd_gamma_cache);
00109      return -1;
00110   }
00111   return 0; 
00112 }
00118 int initParams(int daemon_bit) {
00119     aex_recover_cntr=0;
00120     lseek(fd_histogram_cache, LSEEK_DAEMON_HIST_Y+daemon_bit, SEEK_END);   
00121     GLOBALPARS(G_AE_INTEGERR)=0; 
00122     GLOBALPARS(G_WB_INTEGERR)=0; 
00123     this_frame=GLOBALPARS(G_THIS_FRAME);  
00124     if (GLOBALPARS(G_HIST_DIM_01)==0) {
00125       GLOBALPARS(G_HIST_DIM_01)=DEFAULT_BLACK_CALIB | (DEFAULT_BLACK_CALIB <<16);
00126       GLOBALPARS(G_HIST_DIM_23)=DEFAULT_BLACK_CALIB | (DEFAULT_BLACK_CALIB <<16);
00127       return 1 ; 
00128     }
00129 //#define P_AUTOEXP_EXP_MAX 81 //unsigned long exp_max;         /* 100 usec == 1 etc... */
00130     initAexpCorr();
00131     initWhiteBalanceCorr();
00132     return 0;
00133 }
00134 
00135 

Generated on Fri Nov 28 00:06:21 2008 for elphel by  doxygen 1.5.1