os/linux-2.6-tag--devboard-R2_10-4/include/asm-cris/elphel/c313a.h

Go to the documentation of this file.
00001 /*
00002  * 05.03.2002 changing for revA
00003  * 03.19.2002 Started support for different sensors
00004  */
00005 
00006 #ifndef _ASM_CMOSCAM_H
00007 #define _ASM_CMOSCAM_H
00008 
00009 #define ELPHEL_DEBUG 0 //global debug on/off in multiple files
00010 
00011 #define ETRAXFS_MMAP_CACHE_BUG y
00012 
00013 
00014 /* _IOC_TYPE, bits 8 to 15 in ioctl cmd */
00015 
00016 #define CMOSCAM_IOCTYPE 124
00017 
00018 /* MINORS */
00019 
00020 #define CMOSCAM_MINOR_FRAME     1
00021 #define CMOSCAM_MINOR_FPN       2
00022 //#define CMOSCAM_MINOR_IORW    1
00023 //#define CMOSCAM_MINOR_I2C     2
00024 //#define CMOSCAM_MINOR_RAW     3
00025 #define CMOSCAM_MINOR_I2C       3
00026 #define CMOSCAM_MINOR_DMA       4
00027 #define CMOSCAM_MINOR_MCP       5
00028 #define CMOSCAM_MINOR_LOCK      6
00029 #define CMOSCAM_MINOR_UNLOCK    7
00030 #define CMOSCAM_MINOR_SENSORJTAGFPGA 8
00031 #define CMOSCAM_MINOR_RWTABLES 9
00032 #define CMOSCAM_MINOR_SENSORFPGACOMM 10
00033 #define CMOSCAM_MINOR_CIRCBUF   11
00034 #define CMOSCAM_MINOR_HISTOGRAM 12
00035 #define CMOSCAM_MINOR_JPEAGHEAD 13
00036 #define CMOSCAM_MINOR_GAMMA     14
00037 #define CMOSCAM_MINOR_SENSPARS  15
00038 
00039 /* new i2c devices */
00040 #define X3X3_I2C 134
00041 // minors (add more later - maybe different minors for different speed - set speed when opening)
00042 #define X3X3_I2C_CTRL       0  // control/reset i2c
00043 #define X3X3_I2C_8_AINC     1  // 8bit  registers, autoincement while read/write
00044 #define X3X3_I2C_16_AINC    2  // 16bit registers, autoincement while read/write
00045 #define X3X3_I2C1_8_AINC    3  // 8bit  registers, autoincement while read/write (bus 1)
00046 #define X3X3_I2C1_16_AINC   4  // 16bit registers, autoincement while read/write (bus 1)
00047 #define X3X3_I2C_RAW        5  // 8bit  registers, no address byte (just slave, then read/write byte(s)
00048 #define X3X3_I2C1_RAW       6  // 8bit  registers, no address byte (just slave, then read/write byte(s)
00049 #define X3X3_I2C_ENABLE     7  // enable(/protect) different I2C devices for different types of I2C accesses
00050 #define X3X3_I2C_ENABLE_RD   0 // bit 0 - enable i2c read
00051 #define X3X3_I2C_ENABLE_WR   1 // bit 1 - enable i2c write
00052 #define X3X3_I2C_ENABLE_RAW  2 // bit 2 - enable i2c raw (no address byte)
00053 #define X3X3_I2C_ENABLE_8    3 // bit 3 - enable i2c 8-bit registers access
00054 #define X3X3_I2C_ENABLE_16   4 // bit 4 - enable i2c 16-bit registers access
00055 #define X3X3_I2C_MAXMINOR  7  //
00056 #define X3X3_I2C_CHANNELS  2  // number of i2c channels
00057 //xi2craw            c 134   5
00058 //xi2craw_aux        c 134   6
00059 //xi2cenable         c 134   7
00060 
00061 
00062 
00063 /* camera sequencer states */
00064 
00065 //New sequencer states
00066 
00067 #define CAMSEQ_OFF       0 // off, not programmed (Video mode off on Zoran sensors)
00068 #define CAMSEQ_READY     1 // sensor programmed may acquire at will (programSensor sets number of frames to skip (if any)
00069 #define CAMSEQ_SKIP      2 // skipping specified number of frames, interrupt service routine counts and will start acquisition
00070 #define CAMSEQ_WAIT_F    3 // set by "start exposure" or interrupt service routine. WAIT_F/WAIT_T/acquire/done differs by hardware register
00071 #define CAMSEQ_WAIT_T    4 // set by "start exposure" or interrupt service routine. Wait/acquire/done differs by hardware register
00072 #define CAMSEQ_ACQUIRE   5 // acquisition in progress (camSeqState is still CAMSEQ_WAIT)
00073 #define CAMSEQ_DONE      6 // acquisition over  (camSeqState is still CAMSEQ_WAIT)
00074 #define CAMSEQ_JPEG      7 // waiting for JPEG done interrupt, acquiring/compressing some frames
00075 
00076 #define CAMSEQ_RUN       8 // compressor is constantly running (but if camSeqCount>0 - just skipping "bad" frames)
00077 #define CAMSEQ_STOP      9 // compressor is constantly running but will stop after next "compressor ready"
00078 #define CAMSEQ_SINGLE   10 // compressor is constantly running to fill one full buffer
00079 /*
00080 Status CAMSEQ_OFF may be changed to CAMSEQ_READY only by programSensor, it will also stop sensor (if needed)
00081   and set camSeqCount (if needed) to skip certain number of frames before actual acquisition
00082   camSeqStart (called mostly through ioctl) will return error if state was not "CAMSEQ_READY" or "CAMSEQ_DONE".
00083   If called from correct states will either start ISR-based waiting for specified number of frames  or just acquisition.
00084   In the first case ISR will start acquisition itself
00085   State "CAMSEQ_WAIT_F" is set at the same time as starting acquisition (by either camSeqStart() or ISR),
00086   States CAMSEQ_WAIT_F,CAMSEQ_ACQUIRE, CAMSEQ_DONE are returned after testing the hardware register in FPGA if camSeqState==CAMSEQ_WAIT_F
00087   camSeqStop will terminate any acquisition in progress and set state to CAMSEQ_READY (if it was not CAMSEQ_OFF)
00088 */
00089 // For KAI11000 sensor board
00090 #define sensorcom_W_size        1024
00091 #define sensorcom_R_size        256
00092 
00093 /* MCP definitions */
00094 
00095 #define MCP_W_size      1024
00096 #define MCP_R_size      256
00097 
00098 #define MCPOtherBits    0xffa7a7ff
00099 #define MCPOffReset     0x00101800
00100 #define MCPReset        0x00001800
00101 #define MCPNoReset      0x00105800
00102 #define MCPToggleA      0x00080000
00103 #define MCPToggleB      0x00001000
00104 #define MCPctlseq       0x00
00105 #define MCPsofttg       0x02
00106 #define MCPeackn        0x03
00107 #define MCPctlgate      0x04
00108 #define MCPwstdly       0x06
00109 #define MCPwrsmsk       0x07
00110 #define MCPwrsup        0x08
00111 #define MCPwrmons       0x09
00112 #define MCPwnom         0x0a
00113 #define MCPwdenom       0x0b
00114 #define MCPwoutw        0x0c
00115 #define MCPwinvctl      0x0d
00116 #define MCPctlsync      0x0e
00117 #define MCPwrdlys       0x10
00118 #define MCPwinv         0x40
00119 #define MCPwshared      0x80
00120 #define MCPwrsynctb     0x100
00121 #define MCPwrseq        0x200
00122 
00123 
00124 /* supported ioctl _IOC_NR's */
00125 #ifndef I2C_WRITEARG
00126  #define I2C_WRITEARG(bus, slave, reg, value) (((bus) << 24) | ((slave) << 16) | ((reg) << 8) | (value))
00127  #define I2C_READARG(bus, slave, reg) (((bus) << 24) | ((slave) << 16) | ((reg) << 8))
00128 
00129  #define I2C_ARGBUS(arg) (((arg) >> 24)  & 0x1)
00130  #define I2C_ARGSLAVE(arg) (((arg) >> 16)  & 0xff)
00131  #define I2C_ARGREG(arg) (((arg) >> 8) & 0xff)
00132  #define I2C_ARGVALUE(arg) ((arg) & 0xff)
00133 
00134  #define I2C_DELAYS   0x0   /* read/write bit deleys for I2C */
00135 // return new delays, if data==0 - don't change, just read
00136 // lower (0) byte - SCL high,
00137 // byte 1 - SCL low
00138 // byte 2 - slave -> master (from slave driving SDA line to master driving SDA)
00139 // byte 3 - master -> slave (from master driving SDA line to slave driving SDA)
00140 
00141  #define I2C_WRITEREG 0x1   /* write to an i2c register */
00142  #define I2C_READREG  0x2   /* read from an i2c register */
00143 #endif
00144 
00145 /* new for Micron sensors  - 16bit data, always bus 0 */
00146 #ifndef I2C_16_WRITEARG
00147  #define I2C_16_WRITEREG 0x3   /* write 2 bytes to an i2c register */
00148  #define I2C_16_READREG  0x4   /* read 2 bytes from an i2c register */
00149   
00150  #define I2C_16_WRITEARG(slave, reg, value) (((slave) << 24) | ((reg) << 16) | (value))
00151  #define I2C_16_READARG(slave, reg) (((slave) << 24) | ((reg) << 16))
00152 
00153  #define I2C_16_ARGSLAVE(arg)   (((arg) >> 24) & 0xff)
00154  #define I2C_16_ARGREG(arg)     (((arg) >> 16) & 0xff)
00155  #define I2C_16_ARGVALUE(arg)   ( (arg)      & 0xffff)
00156  #define I2C_16_ARGVALUE_H(arg) (((arg) >>  8) & 0xff)
00157  #define I2C_16_ARGVALUE_L(arg) ( (arg)        & 0xff)
00158 #endif
00159 
00160 
00161 
00162 // otherParamsRO[16]
00163 
00164 #define _CCCMD(x,y)  (_IO(CMOSCAM_IOCTYPE, (x << 6) | (y & 0x3f)))
00165 
00166 
00167 
00168 #define CCAM_CTRL(x)  ((_IOC_NR(x) >> 6) & 0x03)
00169 #define CCAM_ADDR(x)  (_IOC_NR(x) & 0x3f)
00170 
00171 //#define CCAM_RWSENSOR   1 /* direct read/write first 32 sensor registers */  // will not use at all
00172 #define CCAM_RPARS      2 /* read  parameters      0..0x3f */
00173 #define CCAM_WPARS      3 /* write parameters      0..0x3f */
00174 
00175 /* New parameters and update logic
00176  * Separate read and write set of 64 registers
00177  * User may specify:
00178  *   0 - do not update
00179  *   1 - update at once
00180  *   2 - update when appropriate
00181  * and read update status:
00182  *   0 - will not be updated
00183  *   1 - in sync
00184  *   2 - waiting to be updated
00185  *   3 - update in progress (TODO: - support async)
00186  *      When updating (validating) parameters and copying them to the read "registers" the I2C registers will be written
00187  *  only if they are different from the shadows
00188  */
00189 
00190 /* abstract sensor register names */
00191 #define P_NUMBER         1024   //number of registers (was 64)
00192 #define P_UPDATE         0          /* R/W, see above */
00193 #define P_SENSOR         1     /* read only
00194                            4  - ZR32112MLC - now there is no way to see color/mono
00195                            5  - ZR32112PLC
00196                            8  - ZR32212MLC
00197                            9  - ZR32112PLC
00198                            32 - KAC1310-mono
00199                            33 - KAC1310-RGB
00200                            34 - KAC1310-CMY
00201                            36 - KAC5000
00202                            48 - MI1300
00203                            49 - MT9M001 (1280x1024,same as MI1300)
00204                            50 - MT9M001 (1600x1200)
00205                            51 - MT9T001 (2048*1536)
00206                            52 - MT9P001 (2592*1944)
00207                            64 - IBIS5-1300*/
00208 
00209 // leave it here - may be used in user applications
00210 #define SENSOR_MASK      0xfc
00211 #define SENSOR_ZR32112   0x04
00212 #define SENSOR_ZR32212   0x08
00213 #define SENSOR_KAC1310   0x20
00214 #define SENSOR_KAC5000   0x24
00215 #define SENSOR_MI1300    0x30
00216 #define SENSOR_MT9X001   0x30 // MT9M001 - 31, MT9D001 - 32, MT9T001 - 33, MT9P001 - 34
00217 #define SENSOR_MT9Y001   0x34 // MT9P001 - 34
00218 #define SENSOR_IBIS51300 0x40
00219 #define SENSOR_KAI11000  0x80
00220 #define SENSOR_NONE      0xfc
00221 
00222 // sensor sizes:
00223 //#define SENSORWIDTH_ZR32112  1288
00224 //#define SENSORHEIGHT_ZR32112 1032
00225 #define SENSORWIDTH_ZR32112  1280
00226 #define SENSORHEIGHT_ZR32112 1024
00227 //#define SENSORWIDTH_ZR32212  1288
00228 #define SENSORWIDTH_ZR32212  1280
00229 #define SENSORHEIGHT_ZR32212 968
00230 #define SENSORWIDTH_KAC1310  1280
00231 #define SENSORHEIGHT_KAC1310 1024
00232 //#define SENSORWIDTH_KAC1310  1296
00233 //#define SENSORHEIGHT_KAC1310 1046
00234 #define SENSORWIDTH_MI1300  1280
00235 #define SENSORHEIGHT_MI1300 1024
00236 
00237 #define SENSORWIDTH_MT9M001  1280
00238 #define SENSORHEIGHT_MT9M001 1024
00239 #define SENSORWIDTH_MT9D001  1600
00240 #define SENSORHEIGHT_MT9D001 1200
00241 #define SENSORWIDTH_MT9T001  2048
00242 #define SENSORHEIGHT_MT9T001 1536
00243 #define SENSORWIDTH_MT9P001  2592
00244 #define SENSORHEIGHT_MT9P001 1944
00245 
00246 #define SENSORWIDTH_KAC5000  2592
00247 #define SENSORHEIGHT_KAC5000 1944
00248 
00249 
00250 #define SENSORWIDTH_IBIS51300  1280
00251 #define SENSORHEIGHT_IBIS51300 1024
00252 
00254 #define P_PARS_CHANGED   2 /* RD P_RO_VALID  0  window parameters valid                  */
00255 #define P_DMA_VALID      3 /* RD P_RO_VALID  0  window parameters valid                  */
00256 #define P_ACTUAL_WIDTH   4 /* RD P_RO_WIDTH  1  pixels/row                               */
00257 #define P_ACTUAL_HEIGHT  5 /* RD P_RO_HEIGHT 2  pixels/column                            */
00258 #define P_LPR            6 /* RD P_RO_LPR    3  32-bit words per row (aligned each row)  */
00259 #define P_IMAGE_SIZE     7 /* RD P_RO_SIZE   4  total image size (dma data) in bytes     */
00260 #define P_BAYER          8 /* filter number at (0,0) 0-R, 1-G(R), 2-G(B), 3 - B. Write enabled at first, move to WindowSize later */
00261 #define P_TRIGGERED         9 /* when trigger occured - 4 LSBs - pixel in DMA word, higher bits - number of DMA word */
00262 #define P_PERIOD        10 // Frame period (read only)
00263 #define P_FRAME         11 // Frame number (reset with JPEG pointers) -(read only)
00264 #define P_JPEG_WP       12 // Last reported JPEG write pointer in the circular buffer. (may have cashe coherency problem,
00266 #define P_CLK_FPGA      13 // FPGA clock in MHz
00267 #define P_CLK_SENSOR    14 // Sensor clock in MHz
00268 #define P_FPGA_XTRA     15 // Extra cycles needed to compressor (probably constant...)
00269 
00270 //#define P_TRIG          16 /* R/W P_RW_TRIG   0        0 - internal, 1 - external               */
00271 #define P_TRIG          16 /* External trigger mode                                           */
00272                            /* bit 0  - "old" external mode (0- internal, 1 - external )       */
00273                            /* bit 1 - enable(1) or disable(0) external trigger to stop clip   */
00274                            /* bit 2 - async (snapshot, ext trigger) mode, 0 - continuous   */
00275                            /* ... to be continued */
00276 #define P_EXPOS         17 /* P_RW_EXPOS  1      exposure time                            */
00277 #define P_BGFRAME       18 // Background measurement mode - will use 16-bit mode and no FPN correction 
00278 
00279 
00280 
00281 // image page numbers depend on image size/pixel depth, so changing any of them will invalidate all pages
00282 #define P_PAGE_ACQ      19  // Number of image page buffer to acquire to (0.1?)
00283 #define P_PAGE_READ     20  // Number of image page buffer to read from to (0.1?)
00284 
00285 #define P_OVERLAP       21 // number of EXRA lines to be acquired
00286 #define P_VIDEO         22 /* still (stopped) - 0, video - 1. KAC1310 - video only */
00287 
00288 #define P_AUXCM         23 /* signal on AUXCLK pin: 0 - 0, 1 - 1, 1x - 20MHz */
00289 
00290 #define P_VIRT_WIDTH    24 /* Virtual window width - KAC-1310 sensor */
00291 #define P_VIRT_HEIGHT   25 /* Virtual window height - KAC-1310 sensor */
00292 #define P_WOI_LEFT      26 /* WOI left corner (before applying decimation) */
00293 #define P_WOI_TOP       27 /* WOI top corner */
00294 #define P_WOI_WIDTH     28 /* WOI width */
00295 #define P_WOI_HEIGHT    29 /* WOI height */
00296 
00297 #define P_FLIP          30 // bit 0 - horizontal, bit 1 - vertical
00298 //#define P_FLIPH         30
00299 //#define P_FLIPV         31
00300 
00301 #define P_FPSLM           31 // FPS limit mode - bit 0 - limit fps (not higher than), bit 1 - maintain fps (not lower than)
00302 
00303 #define P_DCM_HOR       32 /* Horizontal decimation (1/2/4/8) */
00304 #define P_DCM_VERT      33 /* Vertical   decimation (1/2/4/8) copied from horizontal for Zoran chips */
00305 #define P_BIN_HOR       34 /* binning 1/2 - KAC1310 only - now for mt9t001 */
00306 #define P_BIN_VERT      35 /* not used yet binning 1/2 - KAC1310 only  - now for mt9t001*/
00307 
00308 #define P_COLOR         36 /* mono - 0, color mode - 1, +0 - normal, 256 - sensor test, 512 - FPGA test */
00309 #define P_FRAMESYNC_DLY     37 /* maybe - temporary - delay of frame sync (vacts) by number of scan lines - for photofinish mode*/
00310 #define P_MCLK          38 /* 2..129  0 - disable?*/
00311 #define P_PF_HEIGHT     39 /*height of each strip in photofinish mode - normally 2 lines */
00312                            /*also now includes timestamping mode +0x10000 - for normal frames, 0x20000 - for photo-finish */
00313 
00314 #define P_BITS          40 /* pixel depth - bits 10/8/4 */
00315 
00316 #define P_SHIFTL        41 /* "digital gain" - shift left by 0/1/2 bits  (3 ->-1)*/
00317 #define P_FPNS          42 // FPN correction mode (subtract) 0..3
00318                            // 0-none, 1 - fine(25%), 2 - 50%, 3 - coarse(100%)
00319 #define P_FPNM          43 // FPN correction mode (multiply) 0..3
00320                            // 0-none, 1 - fine(+/-12.5%), 2 - medium (+/-25%), +3 - coarse(+/-50%)
00321 #define P_VEXPOS        44 /* video exposure (if 0 - use P_RW_EXPOS in ms) */
00322 #define P_VIRTTRIG      45 // Sum of pixels in a line greater than this value - trigger acquisition
00323 
00324 #define P_GAINR         46 /* R channel gain (mono gain)  8.8 0x100 - 1.0 */
00325 #define P_GAING         47 /* G channel gain ("red line" in ZR32212) */
00326 #define P_GAINB         48 /* B channel gain (mono gain) */
00327 #define P_GAINGB        49 /* G channel gain ("blue line" in ZR32212) - copied from P_RW_GAING in ZR2112 */
00328 #define P_FATZERO       50 // subtract while adding data from to consequitive frames (async trigger)
00329 // will be removed
00330 #define P_SPEC_KAC_GGA  51 // KAC-1310 Global gain A , 6 bits, (14)
00331 #define P_SPEC_KAC_GGB  52 // KAC-1310 Global gain B , 6 bits, (14)
00332 #define P_SPEC_KAC_GGM  53 // KAC-1310 Global gain mode, 3 bits, 0
00333 // new gains
00334 #define P_GAIN          51 // 8.8 (0x100 - gain==1.0)  - not used now
00335 #define P_RSCALE        52 // 8.8 (0x100 - rscale==1.0). This parameter applies to digital processing ("gamma" tables, not analog settings)
00336 #define P_BSCALE        53 // 8.8 (0x100 - rscale==1.0). This parameter applies to digital processing ("gamma" tables, not analog settings)
00337 
00338 
00339 
00340 #define P_QUALITY       54 // JPEG IMAGE QUALITY
00341 #define P_FP100S        55 // Frames per 100 sec (fps * 100)
00342 #define P_SENSOR_WIDTH  56
00343 #define P_SENSOR_HEIGHT 57
00344 #define P_COLOR_SATURATION_BLUE 58 // 100*realtive saturation blue
00345 #define P_COLOR_SATURATION_RED  59 // 100*realtive saturation red
00346 #define P_GAMMA         60 // 100*gamma  (for now - just a hint table could be more complex. Use higher bytes for colors in 333)
00347 #define P_PIXEL_LOW     61 //  (just a hint for gamma table) "fat zero" (on 8-bit scale)
00348 #define P_PIXEL_HIGH    62 //  (just a hint for gamma table) highest pixel value (before table) on a 256-scale
00349 
00350 
00351 #define P_DONTCARE      63 // write anything - just to force update
00352 #define P_PGMSENSRSLT   64 // result of last programSensor() call
00353 #define P_CAMSEQSTATE   65 // sequncer state (to replace camSeqState eventually)?
00354 #define P_CAMSEQCOUNT   66 // sequncer counter (to replace camSeqCount eventually)?
00355 #define P_CIRCBUFSIZE   67 // Size of the circular buffer (in bytes)
00357 #define P_FREECIRCBUF   68 //* Free space in circbuf (uses global read pointer, in bytes)
00358 #define P_CIRCBUFWP     69 //* circbuf write pointer (in bytes - similar P_JPEG_WP is in long words)
00359 #define P_CIRCBUFRP     70 //* circbuf global read pointer (in bytes )
00360 #define P_SECONDS       71 // seconds (R/W to FPGA timer)
00361 #define P_MICROSECONDS  72 // microseconds (R/W to FPGA timer)
00362 #define P_TILES         73 // Number of 16x16 (20x20) tiles in a compressed frame
00363 #define P_SENSOR_PHASE  74 // packed, low 16 bit - signed fine phase, bits [18:17] - 90-degrees shift
00364 #define P_GSCALE        75 // 8.8 (0x100 - gscale==1.0). Additional parameter to compensate for difference in Green/Green1 gains
00365 
00367 #define P_AUTOEXP_ON    76 // unsigned long on;
00369 #define P_AUTOEXP_RWIDTH 77 // unsigned long width (%);
00370 #define P_AUTOEXP_RHEIGHT 78 //unsigned long height (%);
00371 #define P_AUTOEXP_RLEFT  79 // unsigned long left (%);
00372 #define P_AUTOEXP_RTOP   80 // unsigned long top (%);
00373 #define P_AUTOEXP_EXP_MAX 81 //unsigned long exp_max;           /* 100 usec == 1 etc... */
00374 #define P_AUTOEXP_OVEREXP_MAX 82 // unsigned long overexp_max;  /* percentages for overexposured pixels - 1% == 100, 5% == 500, 0.02% == 2 etc... */
00375 #define P_AUTOEXP_S_PERCENT 83 // unsigned long s_percent;(controlling that % of pixels that should have value greater than S_INDEX - below)
00376 #define P_AUTOEXP_S_INDEX 84 // unsigned long s_index; Specified number of pixels (S_PERCENT) should have value above S_INDEX
00377 #define P_AUTOEXP_EXP   85 // unsigned long exp; Current exposure time
00378 #define P_AUTOEXP_SKIP_PMIN 86 // unsigned long skip_pmin;      /* percent of delta for skip changes: 1% == 100 */ - no exposure corrections if the desired change is less than that
00379 #define P_AUTOEXP_SKIP_PMAX 87 // unsigned long skip_pmax;      /* percent of changes for wait one frame before apply changes: 1% == 100 */ - do not apply chnanges if they are to big - wait for the next frame
00380 #define P_AUTOEXP_SKIP_T 88 //  unsigned long skip_t;           /* time for skip changes: 100 usec == 1 */ Not quite sure what it is
00381 #define P_AEXPWND_WIDTH  89 // autoexposure window width  (pixels)
00382 #define P_AEXPWND_HEIGHT 90 // autoexposure window height (pixels)
00383 #define P_AEXPWND_TOP    91 // autoexposure window top    (pixels)
00384 #define P_AEXPWND_LEFT   92 // autoexposure window left   (pixels)
00385 #define P_FOCUS_SHOW     93 // show focus information instead of/combined with the image:
00386                             // 0 - regular image, 1 - block focus instead of Y DC (AC=0), 2 - image Y DC combined all frame, 3 combined in WOI
00387 #define P_FOCUS_SHOW1    94 // Additional parameter that modifies visualization mode. Currently just a single bit (how much to add)
00388 #define P_FOCUS_VALUE    95 // (readonly) - sum of all blocks focus values inside focus WOI
00389 #define P_FOCUS_LEFT     96 // focus WOI left margin, inclusive (3 LSB will be zeroed as it should be multiple of 8x8 block width) 
00390 #define P_FOCUS_WIDTH    97 // focus WOI width (3 LSB will be zeroed as it should be multiple of 8x8 block width) 
00391 #define P_FOCUS_TOP      98 // focus WOI top margin, inclusive (3 LSB will be zeroed as it should be multiple of 8x8 block height) 
00392 #define P_FOCUS_HEIGHT   99 // focus WOI height (3 LSB will be zeroed as it should be multiple of 8x8 block height) 
00393 #define P_FOCUS_TOTWIDTH 100 // (readonly) - total width of the image frame in pixels
00394 #define P_FOCUS_FILTER   101 // select 8x8 filter used for the focus calculation (same order as quantization coefficients), 0..14
00395 
00397 
00398 #define P_TRIG_CONDITION 102 // trigger condition, 0 - internal, else dibits ((use<<1) | level) for each GPIO[11:0] pin
00399 #define P_TRIG_DELAY     103 // trigger delay, 32 bits in pixel clocks
00400 #define P_TRIG_OUT       104 // trigger output to GPIO, dibits ((use << 1) | level_when_active). Bit 24 - test mode, when GPIO[11:10] are controlled by other internal signals
00401 #define P_TRIG_PERIOD    105 // output sync period (32 bits, in pixel clocks). 0- stop. 1..256 - single, >=256 repetitive with specified period.
00402 
00403 #define P_TASKLET_CTL    106 // disable individual tasklets
00404 #define P_COMPRESSOR_CMD 107 // read only - compressor command, last written to FPGA
00405 // bit fields
00406   #define COMPRESSOR_CMD_RUN    0x080
00407   #define COMPRESSOR_CMD_SINGLE 0x800  
00408 #define P_SKIP_FRAMES    108 // number of frames to skip after restarting sensor+compressor
00409 #define P_I2C_QPERIOD    109 // number of system clock periods in 1/4 of i2c SCL period to the sensor/sensor board
00410 #define P_I2C_BYTES      110 // number of bytes in hardware i2c write (after slave addr) -0/1/2
00411 #define P_IRQ_SMART      111 // "smart" IRQ modes: +1 - wait for VACT in early compressor_done, +2 - wait for dma fifo ready
00412 #define P_EARLY_TIMESTAMP 112 // "1" - use start of TRIG pulse as a timetamp moment (0 - use start of first visible line readout) - prevent jitter in async mode
00413 #define P_OVERSIZE       113 // ignore sensor dimensions, use absolute WOI_LEFT, WOI_TOP
00414 
00415 #define P_MAX_PAR        127 // maximal # of used parameter
00416 #define P_HIST_NOT_CHANGE 0xffff // will be available as ELPHEL_HIST_NOT_CHANGE constant in PHP
00417 
00418 
00420 #define P_AUTOEXP P_AUTOEXP_ON
00421 #define P_AEXPWND P_AEXPWND_WIDTH
00422 
00423 
00424 struct autoexp_t {
00425         unsigned long on;
00426         /*
00427          * in percents: 1 == 1, 100 == 100
00428          */
00429         unsigned long width;
00430         unsigned long height;
00431         unsigned long left;
00432         unsigned long top;
00433         /*
00434          * start exposure time really not needed...
00435          */
00436         unsigned long exp_max;          /* 100 usec == 1 etc... */
00437         unsigned long overexp_max;      /* percentages for overexposured pixels - 1% == 100, 5% == 500, 0.02% == 2 etc... */
00438         /*
00439          * changed chema - balance exposition for set percent of pixels in needed index
00440          */
00441         unsigned long s_percent;
00442         unsigned long s_index;
00443         /*
00444          * return current state
00445          */
00446         unsigned long exp;
00447         /*
00448          * "sleep" settings
00449          */
00450         unsigned long skip_pmin;        /* percent of delta for skip changes: 1% == 100 */
00451         unsigned long skip_pmax;        /* percent of changes for wait one frame before apply changes: 1% == 100 */
00452         unsigned long skip_t;           /* time for skip changes: 100 usec == 1 */
00453 };
00454 struct aexp_window_t {
00455         unsigned long width;
00456         unsigned long height;
00457         unsigned long top;
00458         unsigned long left;
00459 };
00460 
00461 
00462 struct p_names_t {
00463   int   value;
00464   char* name;
00465 };
00466 
00467 #define P_NAME_ENTRY(y) { P_##y, #y }
00468 #define DEFINE_P_NAMES(x) struct p_names_t x[]= { \
00469           P_NAME_ENTRY(NUMBER), \
00470           P_NAME_ENTRY(UPDATE), \
00471           P_NAME_ENTRY(SENSOR), \
00472           P_NAME_ENTRY(PARS_CHANGED), \
00473           P_NAME_ENTRY(DMA_VALID), \
00474           P_NAME_ENTRY(ACTUAL_WIDTH), \
00475           P_NAME_ENTRY(ACTUAL_HEIGHT), \
00476           P_NAME_ENTRY(LPR), \
00477           P_NAME_ENTRY(IMAGE_SIZE), \
00478           P_NAME_ENTRY(BAYER), \
00479           P_NAME_ENTRY(TRIGGERED), \
00480           P_NAME_ENTRY(PERIOD), \
00481           P_NAME_ENTRY(FRAME), \
00482           P_NAME_ENTRY(JPEG_WP), \
00483           P_NAME_ENTRY(CLK_FPGA), \
00484           P_NAME_ENTRY(CLK_SENSOR), \
00485           P_NAME_ENTRY(FPGA_XTRA), \
00486           P_NAME_ENTRY(TRIG), \
00487           P_NAME_ENTRY(EXPOS), \
00488           P_NAME_ENTRY(BGFRAME), \
00489           P_NAME_ENTRY(PAGE_ACQ), \
00490           P_NAME_ENTRY(PAGE_READ), \
00491           P_NAME_ENTRY(OVERLAP), \
00492           P_NAME_ENTRY(VIDEO), \
00493           P_NAME_ENTRY(AUXCM), \
00494           P_NAME_ENTRY(VIRT_WIDTH), \
00495           P_NAME_ENTRY(VIRT_HEIGHT), \
00496           P_NAME_ENTRY(WOI_LEFT), \
00497           P_NAME_ENTRY(WOI_TOP), \
00498           P_NAME_ENTRY(WOI_WIDTH), \
00499           P_NAME_ENTRY(WOI_HEIGHT), \
00500           P_NAME_ENTRY(FLIP), \
00501           P_NAME_ENTRY(FPSLM), \
00502           P_NAME_ENTRY(DCM_HOR), \
00503           P_NAME_ENTRY(DCM_VERT), \
00504           P_NAME_ENTRY(BIN_HOR), \
00505           P_NAME_ENTRY(BIN_VERT), \
00506           P_NAME_ENTRY(COLOR), \
00507           P_NAME_ENTRY(FRAMESYNC_DLY), \
00508           P_NAME_ENTRY(MCLK), \
00509           P_NAME_ENTRY(PF_HEIGHT), \
00510           P_NAME_ENTRY(BITS), \
00511           P_NAME_ENTRY(SHIFTL), \
00512           P_NAME_ENTRY(FPNS), \
00513           P_NAME_ENTRY(FPNM), \
00514           P_NAME_ENTRY(VEXPOS), \
00515           P_NAME_ENTRY(VIRTTRIG), \
00516           P_NAME_ENTRY(GAINR), \
00517           P_NAME_ENTRY(GAING), \
00518           P_NAME_ENTRY(GAINB), \
00519           P_NAME_ENTRY(GAINGB), \
00520           P_NAME_ENTRY(FATZERO), \
00521           P_NAME_ENTRY(SPEC_KAC_GGA), \
00522           P_NAME_ENTRY(SPEC_KAC_GGB), \
00523           P_NAME_ENTRY(SPEC_KAC_GGM), \
00524           P_NAME_ENTRY(GAIN), \
00525           P_NAME_ENTRY(RSCALE), \
00526           P_NAME_ENTRY(BSCALE), \
00527           P_NAME_ENTRY(GSCALE), \
00528           P_NAME_ENTRY(QUALITY), \
00529           P_NAME_ENTRY(FP100S), \
00530           P_NAME_ENTRY(SENSOR_WIDTH), \
00531           P_NAME_ENTRY(SENSOR_HEIGHT), \
00532           P_NAME_ENTRY(COLOR_SATURATION_BLUE), \
00533           P_NAME_ENTRY(COLOR_SATURATION_RED), \
00534           P_NAME_ENTRY(GAMMA), \
00535           P_NAME_ENTRY(PIXEL_LOW), \
00536           P_NAME_ENTRY(PIXEL_HIGH), \
00537           P_NAME_ENTRY(DONTCARE), \
00538           P_NAME_ENTRY(PGMSENSRSLT), \
00539           P_NAME_ENTRY(CAMSEQSTATE), \
00540           P_NAME_ENTRY(CAMSEQCOUNT), \
00541           P_NAME_ENTRY(CIRCBUFSIZE), \
00542           P_NAME_ENTRY(FREECIRCBUF), \
00543           P_NAME_ENTRY(CIRCBUFWP), \
00544           P_NAME_ENTRY(CIRCBUFRP), \
00545           P_NAME_ENTRY(TILES), \
00546           P_NAME_ENTRY(SENSOR_PHASE), \
00547           P_NAME_ENTRY(SECONDS), \
00548           P_NAME_ENTRY(MICROSECONDS), \
00549           P_NAME_ENTRY(TILES), \
00550           P_NAME_ENTRY(SENSOR_PHASE), \
00551           P_NAME_ENTRY(AUTOEXP_ON), \
00552           P_NAME_ENTRY(AUTOEXP_RWIDTH), \
00553           P_NAME_ENTRY(AUTOEXP_RHEIGHT), \
00554           P_NAME_ENTRY(AUTOEXP_RLEFT), \
00555           P_NAME_ENTRY(AUTOEXP_RTOP), \
00556           P_NAME_ENTRY(AUTOEXP_EXP_MAX), \
00557           P_NAME_ENTRY(AUTOEXP_OVEREXP_MAX), \
00558           P_NAME_ENTRY(AUTOEXP_S_PERCENT), \
00559           P_NAME_ENTRY(AUTOEXP_S_INDEX), \
00560           P_NAME_ENTRY(AUTOEXP_EXP), \
00561           P_NAME_ENTRY(AUTOEXP_SKIP_PMIN), \
00562           P_NAME_ENTRY(AUTOEXP_SKIP_PMAX), \
00563           P_NAME_ENTRY(AUTOEXP_SKIP_T), \
00564           P_NAME_ENTRY(AEXPWND_WIDTH), \
00565           P_NAME_ENTRY(AEXPWND_HEIGHT), \
00566           P_NAME_ENTRY(AEXPWND_TOP), \
00567           P_NAME_ENTRY(AEXPWND_LEFT), \
00568           P_NAME_ENTRY(HIST_NOT_CHANGE), \
00569           P_NAME_ENTRY(FOCUS_SHOW), \
00570           P_NAME_ENTRY(FOCUS_SHOW1), \
00571           P_NAME_ENTRY(FOCUS_VALUE), \
00572           P_NAME_ENTRY(FOCUS_LEFT), \
00573           P_NAME_ENTRY(FOCUS_WIDTH), \
00574           P_NAME_ENTRY(FOCUS_TOP), \
00575           P_NAME_ENTRY(FOCUS_HEIGHT), \
00576           P_NAME_ENTRY(FOCUS_TOTWIDTH), \
00577           P_NAME_ENTRY(FOCUS_FILTER), \
00578           P_NAME_ENTRY(TRIG_CONDITION), \
00579           P_NAME_ENTRY(TRIG_DELAY), \
00580           P_NAME_ENTRY(TRIG_OUT), \
00581           P_NAME_ENTRY(TRIG_PERIOD), \
00582           P_NAME_ENTRY(TASKLET_CTL), \
00583           P_NAME_ENTRY(COMPRESSOR_CMD), \
00584           P_NAME_ENTRY(SKIP_FRAMES), \
00585           P_NAME_ENTRY(I2C_QPERIOD), \
00586           P_NAME_ENTRY(I2C_BYTES), \
00587           P_NAME_ENTRY(IRQ_SMART), \
00588           P_NAME_ENTRY(EARLY_TIMESTAMP), \
00589           P_NAME_ENTRY(OVERSIZE) \
00590 };
00591 
00592 /* i2c errors */
00593 #ifndef ERR_I2C_SCL_ST0
00594  #define        ERR_I2C_SCL_ST0          1
00595  #define        ERR_I2C_SDA_ST0          2
00596  #define        ERR_I2C_SCL_ST1          4
00597  #define        ERR_I2C_SDA_ST1          8
00598  #define        ERR_I2C_SCL_NOPULLUP 16
00599  #define        ERR_I2C_SDA_NOPULLUP 32
00600 
00601 /* i2c_diagnose called by i2c_start (?) could not find any problems. Try again start */
00602  #define    ERR_I2C_NOTDETECTED  64
00603  #define        ERR_I2C_SHORT            128
00604  #define        ERR_I2C_BSY                  256
00605  #define        ERR_I2C_NACK             512
00606 #endif
00607 
00608 
00609 /* supported ioctl _IOC_NR's */
00610 #define IO_CCAM_SET_EXT_EXPOSURE  0x06
00611 #define IO_CCAM_MONITOR_SEQ       0x07
00612 
00613 // HW configuration requests
00614 #define IO_EXT_BOARD_PRESENT       0xF0
00615 
00616 //#define IO_CCAM_STOP_DMA      0x08
00617 //#define IO_CCAM_START_DMA     0x09 // just starts DMA - descriptor list should be set eatlier
00618 //#define IO_CCAM_START_RAW     0x0a // Programs DMA descriptor list according to current frame size, FPGA registers and starts DMA
00619 
00620 
00621 #define IO_CCAM_JPEG            0x08 // JPEG-compressor related commands
00622 #define      JPEG_CMD_RESET     0x00 // Resets pointers - both acquisition and readout
00623 //#define      JPEG_CMD_ARM     0x01 // Prepare compressor to read next frame acquired
00624 #define      JPEG_CMD_GET              0x02 // Read current page (will return empty (and length==0) if not ready
00625 #define      JPEG_CMD_FORGET        0x03 // increment read frame pointer
00626 #define      JPEG_CMD_CATCHUP       0x04 // set read pointer to the last acquired (or acquiring if none is acquired yet)
00627 #define      JPEG_CMD_ACQUIRE       0x05 // acquire and compress one frame
00628 #define      JPEG_CMD_SAVE_RP       0x06 // save read pointer
00629 #define      JPEG_CMD_RESTORE_RP  0x07 // restore read pointer
00630 #define      JPEG_CMD_N_DONE      0x08 // return 1 if no more frames to be acquired (frame number)
00631 #define      JPEG_CMD_L_DONE      0x09 // return 1 if no more frames to be acquired (total length)
00632 #define      JPEG_CMD_START       0x0a // start constant compression mode
00633 #define      JPEG_CMD_STOP        0x0b // stop constant compression mode (may want to wait for CAMSEQ_DONE)
00634 #define      JPEG_CMD_FRAMES      0x0c // returns number of frames in buffer, (re)uilds frames chain
00635 #define      JPEG_CMD_JUST_STOP   0x0d // just stop - don't start cycle if was allready off!
00636 #define      JPEG_CMD_DUMP        0x0f // printk all static data/tables
00637 #define      JPEG_CMD_RESET0      0x10 // same as JPEG_CMD_RESET, but non-zero, to be used from lseek (SEEK_END)
00638 #define      PROGRAM_SENSOR_0     0x11 // programSensor(0) - to be used from lseek (SEEK_END)
00639 #define      PROGRAM_SENSOR_1     0x12 // programSensor(1) - to be used from lseek (SEEK_END)
00640 #define      LSEEK_CAMSEQSTATE    0x13 // return camSeqState - to be used from lseek (SEEK_END)
00641 #define      LSEEK_RESET_SENSOR   0x14 // reset sensor and FPGA - next time will reprogram it
00642 #define      LSEEK_INIT_SENSOR    0x15 // initialise SDRAM and sensor if it is not programmed yet (or reset)
00643 #define      LSEEK_GET_FPGA_TIME  0x16 // get FPGA timer to P_SECONDS, P_MICROSECONDS
00644 #define      LSEEK_SET_FPGA_TIME  0x17 // set FPGA timer to P_SECONDS, P_MICROSECONDS
00645 #define      LSEEK_FLUSH_CACHE    0x18 // workaround for Axis mmap cache coherency problems - flush all cache (8KB)
00646 #define      LSEEK_AUTOEXP_SET    0x19 // set autoexposure parameters
00647 #define      LSEEK_AUTOEXP_GET    0x1a // copy window and exposure parameters to autoexp_state
00648 #define      LSEEK_TRIGGER_PGM    0x1b // program trigger parameters
00649 #define      LSEEK_I2C_PGM        0x1c // program hardware i2c speed/bytes
00650 #define      LSEEK_IRQ_SMART_PGM  0x1d // program "smart" irq modes (+1 - wait VACT, +2 - wait dma fifo)
00651 #define      LSEEK_EARLY_TIMESTAMP_PGM 0x1e // 1 - early timestamp in async mode, 0 (or sync) - uses start of first visible line readout
00652 #define      JPEG_CTRL_MONOCHROME    0x400
00653 #define      JPEG_CTRL_MONOCHROME_BLOCKED    0x1000
00654 #define      JPEG_CTRL_NOMOSAIC    0x1000
00655 
00656 #define IO_CCAM_JPEG_QUALITY    0x09 // Set P_QUALITY
00657 
00658 #define IO_CCAM_JPEG_GET_N      0x0a    // get specified number of frames (will add to already asked for if any)
00659 #define IO_CCAM_JPEG_GET_L      0x0b    // get specified length (will stop after frame if got more)
00660 
00661 #define IO_CCAM_JPEG_CTRL       0x0c // Write JPEG control word (0x10000 - use header, LSW - other settings)
00662 #define IO_CCAM_DMA             0x0d
00663   #define CCAM_DMA_CMD_STOP       0x00
00664   #define CCAM_DMA_CMD_START  0x01 // just starts DMA - descriptor list should be set eatlier
00665 
00666 #define IO_CCAM_CR_MODIFY 0x0e  //(bit number)<<2 | op; op= 0 - nop, 1 - set, 2 - reset, 3 - toggle)
00667 #define IO_CCAM_CR_SHADOW 0x0f
00668 
00669 #define IO_CCAM_PINS_WRITE      0x20
00670 #define IO_CCAM_PINS_READ       0x21
00671 
00672 
00673 /* Memory mappable memory... can be mmap'd by application.
00674 *       Contains the following layout:
00675 *       offset                          content
00676 *       -------------------             ---------------------
00677 *       CCAM_MMAP_OFFSET_MMAP_HEADER    struct ccamMmapHeader + fill
00678 *       CCAM_MMAP_OFFSET_JPEG_HEADER    jpeg header to use + fill
00679 *       CCAM_MMAP_OFFSET_DMABUF         dma buffer, contiguous
00680 */
00681 
00682 /* JPEG DMA buffer. Buffer must be a multiple of
00683 *       64Kbyte because one dma descriptor conveniently handles that many...
00684 *       (can not handle more than that also).
00685 *  The #define CCAM_CHUNK_PER_DMABUF can be increased to allow acquiring
00686 *  larger images, if system memory can be freed up elsewhere.
00687 *  A value of 128 means 128*64Kbytes per buffer, or 8Mbyte for buffer,
00688 *  of 16Mbyte total system memory.
00689 *  Jpeg images rarely get as big as 4MB, but they can get bigger.
00690 */
00691 #define CCAM_BYTES_PER_CHUNK  (1<<16)  /* dma buffer bytes per descriptor */
00692 #define CCAM_DESCR_PER_CHUNK  1
00693 /* If CCAM_CHUNK_PER_DMABUF is 100 then buffer is about 6.5 million bytes
00694 *       which is probably bigger than any single image we'll generate,
00695 *       and is also bigger than raw data (which is 5.5MB).
00696 *       However, images bigger than 6.5/2 == 3.25 million bytes will
00697 *       not be able to be double-buffered and thus will slow things down.
00698 */
00699 // increasing 3 times - about 20MB
00700 //#define CCAM_CHUNK_PER_DMABUF 102  /* no. of 64Kbyte chunks per buffer */
00701 #define CCAM_CHUNK_PER_DMABUF 302  /* no. of 64Kbyte chunks per buffer */
00702 #define CCAM_WORDS_PER_DMABUF (CCAM_CHUNK_PER_DMABUF<<14) /*32bit words...*/
00703 #define CCAM_BYTES_PER_DMABUF (CCAM_CHUNK_PER_DMABUF<<16)
00704 /*  For past compatibility, CCMA_DMA_SIZE...
00705 */
00706 #define CCAM_DMA_SIZE CCAM_WORDS_PER_DMABUF
00707 /*
00708 *       CCAM_MMAP_OFFSET... -- offsets in bytes in memory mapped region.
00709 *       CCAM_MMAP_SIZE -- no. of bytes to mmap.
00710 */       
00711 #define CCAM_MMAP_OFFSET_MMAP_HEADER 0
00712 #define CCAM_MMAP_OFFSET_JPEG_HEADER (PAGE_SIZE)
00713 #define CCAM_MMAP_OFFSET_DMABUF (4*PAGE_SIZE)
00714 #define CCAM_MMAP_SIZE (PAGE_SIZE*sizeof(long)+CCAM_BYTES_PER_DMABUF)
00715 
00716 #define CCAM_MMAP_META 12 // extra bytes included at the end of each frame (last aligned to 32 bytes)
00717 #define CCAM_MMAP_META_LENGTH 4 // displacement to length frame length data from the end of the 32-byte aligned frame slot
00718 #define CCAM_MMAP_META_USEC 8 // (negative) displacement to USEC data - 20 bits (frame timestamp)
00719 #define CCAM_MMAP_META_SEC 12 // (negative) displacement to SEC data - 32 bits (frame timestamp)
00720 
00722 #define CX313_FPGA_TABLES_SIZE 0xC00 //=3000 bytes, 32-bit wide, LSB first, some tables use less
00723 #define CX313_FPGA_TABLES_GAMMA 0x400 // 0x400 words gamma-correction (or arbitrary table)
00724 #define CX313_FPGA_TABLES_FOCUS 0x800 // 15*64 16-bit words (now high 16 bits are unused)
00725 #define CX313_FPGA_TABLES_FOCUSPARS 0xbc0 //block of focus-related parameters: left[11:0],right[11:0],top[11:0],bottom[11:0],full_width[11:0],filter_sel[3:0]
00726 
00727 
00728 
00729 
00730 
00731 // ccamMmapHeader -- Data structure at beginning of mmap'able memory:
00732 // this allows quick access by an application to this data.
00733 // NOTE: this must not exceed PAGESIZE bytes since the jpeg header lives there.
00734 struct ccamMmapHeader
00735 {
00736     /* Application must not change use_header except through setting
00737     *  of parameters.
00738     */
00739     int use_header;     /* should jpeg header/tailer be added? */
00740     /* Application must not change headerSize; doing so would only
00741     *   confuse
00742     */
00743     int headerSize;     /* no. of bytes in jpeg header */
00744     /* Application may set exposureIdx and jpegIdx to any desired value
00745     *   when no acquisition is going on (e.g. before JPEG_CMD_ACQUIRE).
00746     */
00747     int exposureIdx;    /* incremented on every frame sync (exposure) irupt*/
00748     int jpegIdx;        /* incremented on every jpeg done interrupt */
00749     /* Data buffering info.
00750     *   This is readonly by application, which should use:
00751     *   JPEG_CMD_RESET to zero readOffset and writeOffset and buf[readOffset].
00752     *   JPEG_CMD_ACQUIRE to acquire image (when done, sets buf[writeOffset]
00753     *   and then advances writeOffset and zeroes buf[writeOffset]).
00754     *   JPEG_CMD_FORGET to advance readOffset.
00755     *
00756     *   readOffset and writeOffset are byte offsets from beginning of
00757     *   the dma buffer where one can find the respective ccamFileDataHeader.
00758     */
00759     int readOffset;     /* where we (maybe) can read next image from (bytes) */
00760     int writeOffset;    /* where next image will be placed at (bytes) */
00761     /* nfr is the number of frames left to acquire in a sequnce of frames 
00762     */
00763     int nfr;
00764     /* lfr is the length (in bytes) of frames left to acquire.
00765     *   This is a crude measurement that basically says how much of the
00766     *   dma buffer we're willing to consume.
00767     */
00768     int lfr;
00769     /* While dma of jpeg data is enabled/ongoing, jpegBusy is set nonzero.
00770     */
00771     int jpegBusy;
00772 };
00773 
00774 // ccamFileDataHeader -- Data structure preceding each image in dma buffer.
00775 // (Note that the actual image may wrap around, but the 
00776 // this struct is always placed so as to avoid wraparound and be aligned).
00777 // Note that this does not include jpeg header or tailer, and any way
00778 // the actual data is in parts (the offset to is given in part[i].offset,
00779 // a byte count relative to start of dma buffer).
00780 struct ccamFileDataHeader
00781 {
00782     /* Image is not acquired / valid yet until Valid set to 1 or -1  .
00783     *   A value of -1 indicates buffer overflow error.
00784     */
00785     int valid;
00786     /* Value for "valid: (note, OVERFLOW can be recovered from) */
00787     #define CCAM_IMAGE_VALIDFLAG_NOTDONE 0  /* MUST be zero */
00788     #define CCAM_IMAGE_VALIDFLAG_DONEOK  1 
00789     #define CCAM_IMAGE_VALIDFLAG_OVERFLOW -1  /* buffer was too small */
00790     #define CCAM_IMAGE_VALIDFLAG_FATAL  -2  /* misc. unexpected error */
00791     /* nBytes -- Total size of image stored in dma buffer.
00792     *   This does not include e.g. jpeg header (or this header).
00793     */
00794     int nBytes;
00795     /* nBytesMax -- maximum available during acquisition.
00796     *   However, the last CCAM_IMAGE_OVERFLOW_BYTES bytes, if used,
00797     *   should be taken to indicate that an overlow occurred.
00798     *   The value for CCAM_IMAGE_OVERFLOW_BYTES should be large enough
00799     *   to accomodate various corrections without adding a bunch of extra logic.
00800     */
00801     #define CCAM_IMAGE_OVERFLOW_BYTES 512
00802     int nBytesMax;
00803     /* Offset (bytes) in dma buffer of next image header (IFF Valid is 1) */
00804     int nextOffset;
00805     /* Offset and size (bytes) in dma buffer of parts of data 
00806     *   However, only some part(s) may be used, skip those with zero count.
00807     *   Before acq is done, part[i].nBytes is maximum size of the part;
00808     *   after acq (when valid is set to 1) it is set to actual amount.
00809     *   Two parts is enough for a simple ring buffer approach.
00810     */
00811     #define CCAM_IMAGE_NPARTS_MAX 2
00812     struct
00813     {
00814         int offset;     /* w/in dma buffer, bytes */
00815         int nBytes;     /* size of this part */
00816     } part[CCAM_IMAGE_NPARTS_MAX];
00817 };
00818 
00819 // make this structure common for sensors, add fields as needed
00820 struct sensor_t {
00821 // sensor constants
00822    unsigned long  imageWidth;     //nominal image width for final images
00823    unsigned long  imageHeight;    //nominal image height for final images
00824    unsigned long  clearWidth;     //maximal clear (useful) image width
00825    unsigned long  clearHeight;    //maximal clear (useful) image height;
00826    unsigned long  clearTop;       //top margin to the first clear pixel
00827    unsigned long  clearLeft;      //left margin to the first clear pixel
00828    unsigned long  arrayWidth;     //total image array width (including black and boundary)
00829    unsigned long  arrayHeight;    //total image array height (including black and boundary)
00830    unsigned long  minWidth;       // minimal WOI width
00831    unsigned long  minHeight;      // minimal WOI height
00832    unsigned long  minHorBlank;    // minimal horizontal blanking, in pixels in no-decimation, no-binning mode.
00833    unsigned long  minLineDur;     // minimal total line duration, in pixels in no-decimation, no-binning mode.
00834    unsigned long  maxHorBlank;    // maximal horizontal blanking/Virtual frame width (depends on sensor type)
00835    unsigned long  minVertBlank;   // minimal vertical blanking
00836    unsigned long  maxVertBlank;   // maximal vertical blanking/Virtual frame height (depends on sensor type)
00837    unsigned long  maxShutter;     // Maximal shutter duration (in lines)
00838    unsigned long  flips;          // bit mask bit 0 - flipX, 1 - flipY
00839    unsigned long  dcmHor;         // bit mask bit 0 - 1:1, bit 31 - by 32
00840    unsigned long  dcmVert;        // bit mask bit 0 - 1:1, bit 31 - by 32
00841    unsigned long  binHor;         // bit mask bit 0 - 1:1, bit 31 - by 32
00842    unsigned long  binVert;        // bit mask bit 0 - 1:1, bit 31 - by 32
00843    unsigned long  maxGain256;     // maximal analog gain times 0x100
00844    unsigned long  maxClockFreq;   // Maximal clock frequency
00845    unsigned long  nomClockFreq;   //nominal clock frequency
00846    unsigned long  sensorType;     // sensor type (for Elphel cameras)
00847    unsigned long  i2c_addr;       // i2c address
00848    unsigned long  i2c_period;     // SCL period in ns, (standard i2c - 2500)
00849    unsigned long  i2c_bytes;      // number of bytes/ register
00850    unsigned long  margins;        // actually - property of FPGA code, not the sensor
00851    unsigned long  hact_delay;     // hact delay (in ps) from data
00852 // dynamic variables
00853    unsigned long  pixelWidth;     // number of the pixels output in a line (including margins, decimation)
00854    unsigned long  pixelHeight;    // number of the lines output in a frame (including margins, decimation)
00855    unsigned short sensorPhase90;  // (0..3) 90-degree shift (fpcf -w 8 80)
00856    signed   short sensorPhase;    // positive "fpcf -w 8 20", negative - "fpcf -w 8 10"
00857 };
00858 /*!***************************************************************************************************
00859 *! This is essential data related to the last frame aquired to be stored in the circular buffer before
00860 *! each frame received from the FPGA - place where FPGA data is padded by 32 bytes of 0.
00861 *! 6 bytes are already used by next frame pointer signature, so only 26 bytes are left
00862 *! Structure also includes 8 bytes of timestamp (after 2 bytes skipped) - they will be obtained from the circbuf data
00863 *! that goes after the encoded frame, so total is 36 bytes (26+2+8)
00864 !****************************************************************************************************/
00865 // move fram x353.h 
00866 #define DEFAULT_COLOR_SATURATION_BLUE 0x90 // 100*realtive saturation blue
00867 #define DEFAULT_COLOR_SATURATION_RED  0xb6 // 100*realtive saturation red
00868 
00869 #define EXPOSURE_UNIT 100 // to move to finer exposure settings - current unit in microseconds. TODO: Propagate it to drivers...
00871 
00872 // most parameters are moved out, but width, height, quolity are needed for JPEG header, so currently the following are used:
00880 struct frame_params_t {
00881 /*00-03*/ unsigned long  exposure;       //  currently - exposure time measured in 100usec. Really need to change it to smaller increments?
00882 /*04-05*/ unsigned short width;          
00883 /*06-07*/ unsigned short height;         
00884 /*08-11*/ unsigned long  colorsat;       //  matches FPGA format , for 1.0 it is DEFAULT_COLOR_SATURATION_RED<<16 + DEFAULT_COLOR_SATURATION_BLUE
00885 /*12   */ unsigned char  color;          //  0 - mono, 1 - color, 2 - jp4 + (0x40 - flipX) + (0x80 - flipY) 
00886 /*13   */ unsigned char  quality;        
00887 /*14   */ unsigned char  gamma;          //  (%), 255 - non-gamma curve, 0 - raw (16-bit data) - not yet implemented
00888 /*15   */ unsigned char  black;          //  black level shift (255 - full scale)
00889 /*16-17*/ unsigned short rscale;         //  8.8 - red  relative to green - "gamma" table, not sensor gain
00890 /*18-19*/ unsigned short bscale;         //  8.8 - blue relative to green - "gamma" table, not sensor gain
00891 
00892 /*20   */ unsigned char  gain_r;         //  color gain Red   (sensor specific), is set
00893 /*21   */ unsigned char  gain_g;         //  color gain Green (sensor specific)
00894 /*22   */ unsigned char  gain_b;         //  color gain Blue  (sensor specific)
00895 /*23   */ unsigned char  gain_gb;        //  color gain Green in Blue line (sensor specific)
00896 /*24   */
00897 /*25   */
00898 /*24-25*/ unsigned short meta_index;     
00899 
00900 /*26-27*/ unsigned short signffff;       
00901 
00902     union {
00903 /*28-31*/ unsigned long  timestamp_sec ; 
00904 /*28-31*/ unsigned long  frame_length ;  
00905           };
00906 /*32-35*/ unsigned long  timestamp_usec; 
00907 };
00908 
00909 // parameters for lseek circbuf
00910 #define CIRCLSEEK_TORP  1
00911 #define CIRCLSEEK_TOWP  2
00912 #define CIRCLSEEK_PREV  3
00913 #define CIRCLSEEK_NEXT  4
00914 #define CIRCLSEEK_LAST  5
00915 #define CIRCLSEEK_FIRST 6
00916 #define CIRCLSEEK_SCND  7
00917 #define CIRCLSEEK_SETP  8
00918 #define CIRCLSEEK_VALID 9
00919 #define CIRCLSEEK_READY 10
00920 #define CIRCLSEEK_WAIT  11
00921 #define CIRCLSEEK_FREE  12
00922 #define CIRCLSEEK_USED  13
00923 
00924 struct i2c_timing_t {
00925         unsigned char scl_high; //0x02, //! SCL high:
00926         unsigned char scl_low;  //0x02, //! SCL low:
00927         unsigned char slave2master; //0x01, //! slave -> master
00928         unsigned char master2slave; //0x01, //! master -> slave
00929         unsigned char filter_sda;   //0x07, //! filter SDA read data by testing multiple times - currently just zero/non zero
00930         unsigned char filter_scl;  //0x07};//! filter SCL read data by testing multiple times - currently just zero/non zero 
00931 };
00932 
00933 
00934 #endif /* _ASM_CMOSCAM_H */

Generated on Thu Aug 7 16:19:00 2008 for elphel by  doxygen 1.5.1