os/linux-2.6-tag--devboard-R2_10-4/arch/cris/arch-v32/drivers/elphel/sensor_common.c File Reference

#include <linux/module.h>
#include <linux/sched.h>
#include <linux/slab.h>
#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/string.h>
#include <linux/init.h>
#include <linux/autoconf.h>
#include <linux/interrupt.h>
#include <linux/time.h>
#include <linux/vmalloc.h>
#include <asm/system.h>
#include <asm/byteorder.h>
#include <asm/io.h>
#include <asm/arch/hwregs/intr_vect_defs.h>
#include <asm/irq.h>
#include <asm/delay.h>
#include <asm/uaccess.h>
#include <asm/elphel/driver_numbers.h>
#include <asm/elphel/c313a.h>
#include <asm/elphel/fpgaconfa.h>
#include <asm/elphel/exifa.h>
#include "fpgactrl.h"
#include "fpga_sdram.h"
#include "x3x3.h"
#include "cxdma.h"
#include "framepars.h"
#include "sensor_common.h"
#include "pgm_functions.h"
#include "circbuf.h"
#include "exif353.h"
#include "histograms.h"
#include "gamma_tables.h"
#include "quantization_tables.h"

Include dependency graph for sensor_common.c:

Go to the source code of this file.

Data Structures

struct  meta_offsets_t
 Previous value of the FPGA transfer counter (to find out if it did change). More...
struct  image_acq_pd

Defines

#define ELPHEL_DEBUG_THIS   0
 ETRAX interrupt registers.
#define MDF2(x)
#define MD1(x)
#define MDD1(x)
#define MD12(x)
#define MD13(x)
#define X3X3_ELPHEL_DRIVER_NAME   "Elphel (R) Model 353 Camera Driver"
#define X3X3_IMAGEACQ_DRIVER_NAME   "Elphel (R) Model 353 Image Acquisition device driver"

Functions

int camSeqGetJPEG_wp (void)
 Defines/macros moved from the cc353.h.
int camSeqGetJPEG_rp (void)
void camSeqSetJPEG_rp (int p)
void tasklet_fpga_function (unsigned long arg)
 Tasklet - software interrupt lower priority tasks try to implement some balancing - if job is not finished - reduce FPS for it (alternate jobs)?
int init_FPGA (void)
 Not yet used?? Check FPGA version and initialize SDRAM (if not done yet) TODO: when should it be called?
int init_acq_sensor (void)
static int __init image_acq_init (void)
 DECLARE_TASKLET (tasklet_fpga, tasklet_fpga_function, 0)
int updateIRQJPEG_wp (void)
 0 - no arguments for now reads FPGA transfer pointer to update JPEG_wp NOTE: should be called before compressor is reset - that would zero out that hardware register
void updateIRQCircbuf (void)
 Calculate/update CIRCBUF parameters available after compressor interrupt.
void updateIRQFocus (void)
 Calculate/update focus parameters available after compressor interrupt NOTE: currently global (latest), not per-frame.
interframe_params_tupdateIRQ_interframe (void)
 Locate area between frames in the circular buffer.
void updateIRQ_Exif (struct interframe_params_t *interframe)
 Fill exif data with the current frame data, save pointer to Exif page in the interframe area.
static irqreturn_t elphel_FPGA_interrupt (int irq, void *dev_id)
 hardware IRQ service most urgent tasks
void reset_compressor (void)
 can be verified with if (!X313_IS_SDRAM_ON)
void camera_interrupts (int on)
 Camera interrupts on/off (currently both in the FPGA and in the CPU).
int image_acq_open (struct inode *inode, struct file *filp)
int image_acq_release (struct inode *inode, struct file *filp)
loff_t image_acq_fops_lseek (struct file *file, loff_t offset, int orig)
ssize_t image_acq_fops_write (struct file *file, const char *buf, size_t count, loff_t *off)
int image_acq_mmap (struct file *file, struct vm_area_struct *vma)
 module_init (image_acq_init)
 MODULE_LICENSE ("GPLv3.0")
 MODULE_AUTHOR ("Andrey Filippov <andrey@elphel.com>.")
 MODULE_DESCRIPTION (X3X3_IMAGEACQ_DRIVER_NAME)

Variables

static const char elphel_cam_name [] = "elphelcam353"
static volatile int JPEG_wp
static volatile int JPEG_rp
static int fpga_counter_prev = 0
static struct meta_offsets_t meta_offsets
 Previous value of the FPGA transfer counter (to find out if it did change).
static struct sensorproc_t s_sensorproc
sensorproc_tsensorproc = NULL
static struct file_operations image_acq_fops


Define Documentation

#define ELPHEL_DEBUG_THIS   0

ETRAX interrupt registers.

******************************************************************************** ! FILE NAME : sensor_common.c ! DESCRIPTION: Sensor discovery, initialization, programming - common ! for all sensors ! Now most is moved to other files, here will be ! - system initialization ! - compressor write (and global read) pointers ! - populating 32-byte interframe data ! - something for Exif? ! - where are histograms? ->histograms.c ! - interrupt loop ! - tasklets ! - device driver that includes waiting for the next frame regardless of compression ! - anything else? ! ! ! Copyright (C) 2008 Elphel, Inc. ! -----------------------------------------------------------------------------** ! ! This program is free software: you can redistribute it and/or modify ! it under the terms of the GNU General Public License as published by ! the Free Software Foundation, either version 3 of the License, or ! (at your option) any later version. ! ! This program is distributed in the hope that it will be useful, ! but WITHOUT ANY WARRANTY; without even the implied warranty of ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! GNU General Public License for more details. ! ! You should have received a copy of the GNU General Public License ! along with this program. If not, see <http://www.gnu.org/licenses/>. ! -----------------------------------------------------------------------------** !

Log
sensor_common.c,v
! Revision 1.1.1.1 2008/11/27 20:04:00 elphel ! ! ! Revision 1.33 2008/11/20 07:04:47 elphel ! made silent when debug is 0 ! ! Revision 1.32 2008/11/14 07:06:54 elphel ! fixed wrong timing for servicing histogram requests ! ! Revision 1.31 2008/11/13 05:40:45 elphel ! 8.0.alpha16 - modified histogram storage, profiling ! ! Revision 1.30 2008/11/10 19:47:46 elphel ! added TODO abut reducing CPU load by decimating histogram calculations (not each frame) ! ! Revision 1.29 2008/10/29 04:18:28 elphel ! v.8.0.alpha10 made a separate structure for global parameters (not related to particular frames in a frame queue) ! ! Revision 1.28 2008/10/26 05:54:45 elphel ! changed value of frame counters for histograms to compensate for 1 frame latency of histograms ! ! Revision 1.27 2008/10/25 19:55:00 elphel ! made the histograms calculations relate to previous, not this frame. ! ! Revision 1.26 2008/10/23 08:09:02 elphel ! support for histogram wait queues ! ! Revision 1.25 2008/10/19 06:56:05 elphel ! elphel_wait_frame() now works only for compressed frames, new elphel_skip_frames() and elphel_wait_frame_abs() wait sequencer frames (all sensor frames, even those that are not compressed) ! ! Revision 1.24 2008/10/15 22:28:56 elphel ! snapshot 8.0.alpha2 ! ! Revision 1.23 2008/10/13 16:55:53 elphel ! removed (some) obsolete P_* parameters, renamed CIRCLSEEK to LSEEK_CIRC constants (same as other similar) ! ! Revision 1.22 2008/10/12 16:46:22 elphel ! snapshot ! ! Revision 1.21 2008/10/11 18:46:07 elphel ! snapshot ! ! Revision 1.20 2008/10/10 17:06:59 elphel ! just a snapshot ! ! Revision 1.19 2008/10/08 21:26:25 elphel ! snapsot 7.2.0.pre4 - first images (actually - second) ! ! Revision 1.18 2008/10/05 05:13:33 elphel ! snapshot003 ! ! Revision 1.17 2008/10/04 16:10:12 elphel ! snapshot ! ! Revision 1.16 2008/09/28 00:31:57 elphel ! snapshot ! ! Revision 1.15 2008/09/25 00:58:12 elphel ! snapshot ! ! Revision 1.14 2008/09/22 22:55:49 elphel ! snapshot ! ! Revision 1.13 2008/09/20 00:29:50 elphel ! moved driver major/minor numbers to a single file - include/asm-cris/elphel/driver_numbers.h ! ! Revision 1.12 2008/09/19 04:37:26 elphel ! snapshot ! ! Revision 1.11 2008/09/16 00:49:32 elphel ! snapshot ! ! Revision 1.10 2008/09/12 00:24:00 elphel ! removed cc353.c, cc353.h ! ! Revision 1.9 2008/09/07 19:48:09 elphel ! snapshot ! ! Revision 1.8 2008/09/05 23:20:26 elphel ! just a snapshot ! ! Revision 1.7 2008/09/02 21:01:07 elphel ! just next... ! ! Revision 1.6 2008/07/29 01:15:07 elphel ! another snapshot ! ! Revision 1.5 2008/07/27 23:25:07 elphel ! next snapshot ! ! Revision 1.4 2008/07/27 04:27:49 elphel ! next snapshot ! ! Revision 1.3 2008/06/24 00:43:44 elphel ! just a snapshot ! ! Revision 1.2 2008/06/20 03:54:21 elphel ! another snapshot ! ! Revision 1.1 2008/06/16 06:51:21 elphel ! work in progress, intermediate commit ! !

Definition at line 187 of file sensor_common.c.

#define MD1 ( x   ) 

Definition at line 200 of file sensor_common.c.

#define MD12 ( x   ) 

Definition at line 202 of file sensor_common.c.

#define MD13 ( x   ) 

Definition at line 203 of file sensor_common.c.

#define MDD1 ( x   ) 

Definition at line 201 of file sensor_common.c.

#define MDF2 ( x   ) 

Definition at line 199 of file sensor_common.c.

#define X3X3_ELPHEL_DRIVER_NAME   "Elphel (R) Model 353 Camera Driver"

Definition at line 208 of file sensor_common.c.

Referenced by image_acq_init().

#define X3X3_IMAGEACQ_DRIVER_NAME   "Elphel (R) Model 353 Image Acquisition device driver"

End of compressor-related code - TODO: move to a separate file?

Definition at line 251 of file sensor_common.c.


Function Documentation

void camera_interrupts ( int  on  ) 

Camera interrupts on/off (currently both in the FPGA and in the CPU).

Parameters:
on 1 - enable, 0 - disable interrupts

clear smart interrupt circuitry in any case

Definition at line 580 of file sensor_common.c.

References DIS_INTERRUPTS, EN_INTERRUPT, MDF2, port_csp0_addr, printk, and X313_WA_SMART_IRQ.

Referenced by framepars_lseek(), and pgm_detectsensor().

int camSeqGetJPEG_rp ( void   ) 

Definition at line 233 of file sensor_common.c.

References JPEG_rp.

Referenced by circbuf_lseek().

int camSeqGetJPEG_wp ( void   ) 

Defines/macros moved from the cc353.h.

Definition at line 232 of file sensor_common.c.

References JPEG_wp.

Referenced by circbuf_lseek(), circbuf_poll(), circbufValidPointer(), and get_image_time().

void camSeqSetJPEG_rp ( int  p  ) 

Definition at line 234 of file sensor_common.c.

References G_CIRCBUFRP, G_CIRCBUFSIZE, G_CIRCBUFWP, G_FREECIRCBUF, get_globalParam(), JPEG_rp, and set_globalParam().

Referenced by circbuf_lseek().

DECLARE_TASKLET ( tasklet_fpga  ,
tasklet_fpga_function  ,
 
)

static irqreturn_t elphel_FPGA_interrupt ( int  irq,
void *  dev_id 
) [static]

hardware IRQ service most urgent tasks

Parameters:
irq 
dev_id 
Returns:

making dummy read - see c353.h

read hardware write pointer (will only advance if compression was on) find out if compressor was running and update pointers, exif, ...?

also fills P_FRAME ahead

NOTE: currently global (latest), not per-frame

fills jpeg_len, signffff

should we use memcpy as before here?

only when frame is acquired

all interrupts, not just frames acquired

trigger software interrupt

Definition at line 408 of file sensor_common.c.

References circbuf_wait_queue, DIS_INTERRUPTS, EN_INTERRUPT, framepars_wait_queue, PROFILE_NEXT, PROFILE_NOW, updateFramePars(), updateIRQ_Exif(), updateIRQ_interframe(), updateIRQCircbuf(), updateIRQFocus(), updateIRQJPEG_wp(), X313_IRQSTATE, and X3X3_I2C_FRAME.

Referenced by image_acq_init().

loff_t image_acq_fops_lseek ( struct file *  file,
loff_t  offset,
int  orig 
)

Definition at line 654 of file sensor_common.c.

ssize_t image_acq_fops_write ( struct file *  file,
const char *  buf,
size_t  count,
loff_t *  off 
)

Definition at line 657 of file sensor_common.c.

static int __init image_acq_init ( void   )  [static]

Definition at line 613 of file sensor_common.c.

References elphel_cam_name, elphel_FPGA_interrupt(), ELPHEL_MAJOR, init_ccam_dma_buf_ptr(), init_pgm_proc(), KERN_ERR, MDD1, printk, reset_compressor(), reset_qtables(), s_sensorproc, sensorproc, x313_dma_init(), and X3X3_ELPHEL_DRIVER_NAME.

int image_acq_mmap ( struct file *  file,
struct vm_area_struct *  vma 
)

Definition at line 660 of file sensor_common.c.

int image_acq_open ( struct inode *  inode,
struct file *  filp 
)

Definition at line 648 of file sensor_common.c.

int image_acq_release ( struct inode *  inode,
struct file *  filp 
)

Definition at line 651 of file sensor_common.c.

int init_acq_sensor ( void   ) 

initializes structures for the image acquisition parameter initializes hardware i2c controller and the command sequencer (leaves them stopped to ignore any frame syncs) sets some default acquisition parameters Maybe - set up DMA also? TODO: Take care while turning off reset on i2c and cmd_sequencer so there will be no sensor vsync lost (easier to do in FPGA) Done: define CCAM_VSYNC_ON port_csp0_addr[X313_WA_DCR1]=X353_DCR1(BLOCKVSYNC,0) define CCAM_VSYNC_OFF port_csp0_addr[X313_WA_DCR1]=X353_DCR1(BLOCKVSYNC,1)

int init_FPGA ( void   ) 

Not yet used?? Check FPGA version and initialize SDRAM (if not done yet) TODO: when should it be called?

Returns:
<0 error, 0 - just checked, nothing done,1 - needs sensor initialization

fpga is not configured

what this initialization really mean?

Definition at line 273 of file sensor_common.c.

References fpga_initSDRAM(), fpga_state, FPGA_STATE_INITIALIZED, FPGA_STATE_LOADED, MD1, port_csp0_addr, printk, X313__RA__MODEL, X313_CHN0_USED, X313_IS_SDRAM_ON, X313_MAXMODREV, and X313_MINMODREV.

MODULE_AUTHOR ( "Andrey Filippov <andrey@elphel.com>."   ) 

MODULE_DESCRIPTION ( X3X3_IMAGEACQ_DRIVER_NAME   ) 

module_init ( image_acq_init   ) 

MODULE_LICENSE ( "GPLv3.0"   ) 

void reset_compressor ( void   ) 

can be verified with if (!X313_IS_SDRAM_ON)

can be initialized only after FPGA is configured, not at module init (NOTE was static??)

bypasses command sequencer

TODO: There still is a possibility, that there are compressor commands in the hardware que. Should we stop the hardware sequencer here (and restart it later)?

initialize G_CIRCBUFWP, G_FREECIRCBUF

Definition at line 562 of file sensor_common.c.

References COMPCMD_RESET, COMPRESSOR_RUN_STOP, flags, fpga_counter_prev, framepars, JPEG_rp, JPEG_wp, local_irq_restore, local_irq_save, P_COMPRESSOR_RUN, port_csp0_addr, printk, set_imageParamsR_all(), updateIRQCircbuf(), and X313_WA_COMP_CMD.

Referenced by framepars_lseek(), and image_acq_init().

void tasklet_fpga_function ( unsigned long  arg  ) 

Tasklet - software interrupt lower priority tasks try to implement some balancing - if job is not finished - reduce FPS for it (alternate jobs)?

HISTOGRAMS_WAKEUP_ALWAYS if 0 will only wakeup processes waiting for histograms when they become available, maybe never if they are disabled if defined 1 - will wakeup each frame, regardless of the availability of the histograms

Time is out?

already next frame

Histograms are available for the previous frame (that is already in circbuf if compressor was running) Is Y histogram needed?

never calculate

calculate each even (0,2,4,6 frme of 8)

calculate twice per 8 (0, 4)

calculate once per 8 (0)

calculate only when specifically requested

calculate each frame

calculate always (safer)

after updateFramePars gammaHash are from framepars[this-1]

0x2 Green1

histogram corresponds to previous frame

Time is out?

already next frame

wait queue for the G1 histogram (used as Y)

Process parameters

program parameters

Time is out?

already next frame

Are C histograms needed?

never calculate

calculate each even (0,2,4,6 frme of 8)

calculate twice per 8 (0, 4)

calculate once per 8 (0)

calculate only when specifically requested

calculate each frame

calculate always (safer)

after updateFramePars gammaHash are from framepars[this-1]

all 4 colors, including Y (it will be skipped)

histogram corresponds to previous frame

Time is out?

already next frame

wait queue for all the other (R,G2,B) histograms (color)

Definition at line 463 of file sensor_common.c.

References COLOR_Y_NUMBER, framepars, G_HIST_Y_FRAME, G_TASKLET_CTL, get_globalParam(), get_imageParamsPrev(), getThisFrameNumber(), GLOBALPARS, hist_y_wait_queue, HISTRQ_BIT_Y, P_GTAB_R, P_HISTRQ, PARS_FRAMES_MASK, PROFILE_NOW, set_histograms(), TASKLET_CTL_HISTY_BIT, TASKLET_HIST_ALL, TASKLET_HIST_HALF, TASKLET_HIST_NEVER, TASKLET_HIST_ONCE, TASKLET_HIST_QUATER, TASKLET_HIST_RQONLY, thisFrameNumber, and X3X3_I2C_FRAME.

void updateIRQ_Exif ( struct interframe_params_t interframe  )  [inline]

Fill exif data with the current frame data, save pointer to Exif page in the interframe area.

Parameters:
interframe pointer to interframe parameters structure

calculates datetime([20] and subsec[7], returns pointer to char[27]

may be split in datetime/subsec - now it will not notice missing subseq field in template

Definition at line 389 of file sensor_common.c.

References ccam_dma_buf_ptr, encode_time(), Exif_Image_DateTime, Exif_Image_FrameNumber, Exif_Photo_DateTimeOriginal, Exif_Photo_ExposureTime, G_CIRCBUFSIZE, get_globalParam(), get_imageParamsThis, meta_offsets_t::Image_DateTime, meta_offsets_t::Image_FrameNumber, JPEG_wp, interframe_params_t::meta_index, meta_offsets, P_EXPOS, P_FRAME, meta_offsets_t::Photo_DateTimeOriginal, meta_offsets_t::Photo_ExposureTime, putlong_meta_irq(), store_meta(), and write_meta_irq().

Referenced by elphel_FPGA_interrupt().

struct interframe_params_t* updateIRQ_interframe ( void   )  [inline]

Locate area between frames in the circular buffer.

Returns:
pointer to interframe parameters structure

multiple of 32-byte chunks to subtract

size of the storage area to be filled before the frame

should we use memcpy as before here?

Definition at line 366 of file sensor_common.c.

References ccam_dma_buf_ptr, CCAM_MMAP_META, interframe_params_t::frame_length, G_CIRCBUFSIZE, get_globalParam(), JPEG_wp, set_globalParam(), and interframe_params_t::signffff.

Referenced by elphel_FPGA_interrupt().

void updateIRQCircbuf ( void   )  [inline]

Calculate/update CIRCBUF parameters available after compressor interrupt.

Definition at line 345 of file sensor_common.c.

References G_CIRCBUFRP, G_CIRCBUFSIZE, G_CIRCBUFWP, G_FREECIRCBUF, get_globalParam(), JPEG_wp, and set_globalParam().

Referenced by elphel_FPGA_interrupt(), and reset_compressor().

void updateIRQFocus ( void   )  [inline]

Calculate/update focus parameters available after compressor interrupt NOTE: currently global (latest), not per-frame.

Definition at line 355 of file sensor_common.c.

References G_GFOCUS_VALUE, P_FOCUS_VALUE, set_globalParam(), set_imageParamsThis(), and X313_HIGHFREQ.

Referenced by elphel_FPGA_interrupt().

int updateIRQJPEG_wp ( void   )  [inline]

0 - no arguments for now reads FPGA transfer pointer to update JPEG_wp NOTE: should be called before compressor is reset - that would zero out that hardware register

Returns:
0 if compressor was off (no advance), 1 if write pointer did actually advance

number of 32-byte chunks transferred since compressor was reset

using macro defined in x353.h that makes a dummy read (reads after writes can be wrong)

Transferred since last JPEG_wp update (or counter reset)

no advance (compressor was off?)

Hardware counter is 24 bits - rolled over

counts in 32-byte ( 8 of 32bit words) chunks

Definition at line 320 of file sensor_common.c.

References fpga_counter_prev, G_CIRCBUFSIZE, get_globalParam(), JPEG_wp, set_globalParam(), and X313_XFERCNTR.

Referenced by elphel_FPGA_interrupt().


Variable Documentation

const char elphel_cam_name[] = "elphelcam353" [static]

Definition at line 209 of file sensor_common.c.

Referenced by image_acq_init().

int fpga_counter_prev = 0 [static]

Definition at line 213 of file sensor_common.c.

Referenced by reset_compressor(), and updateIRQJPEG_wp().

struct file_operations image_acq_fops [static]

Initial value:

Definition at line 603 of file sensor_common.c.

volatile int JPEG_rp [static]

Definition at line 212 of file sensor_common.c.

Referenced by camSeqGetJPEG_rp(), camSeqSetJPEG_rp(), and reset_compressor().

volatile int JPEG_wp [static]

Definition at line 211 of file sensor_common.c.

Referenced by camSeqGetJPEG_wp(), reset_compressor(), updateIRQ_Exif(), updateIRQ_interframe(), updateIRQCircbuf(), and updateIRQJPEG_wp().

struct meta_offsets_t meta_offsets [static]

Previous value of the FPGA transfer counter (to find out if it did change).

Referenced by updateIRQ_Exif().

struct sensorproc_t s_sensorproc [static]

Definition at line 252 of file sensor_common.c.

Referenced by image_acq_init().

struct sensorproc_t* sensorproc = NULL

Definition at line 253 of file sensor_common.c.

Referenced by add_sensor_proc(), framepars_lseek(), image_acq_init(), init_pgm_proc(), processPars(), processParsASAP(), processParsSeq(), and setFrameParsAtomic().


Generated on Fri Nov 28 00:08:12 2008 for elphel by  doxygen 1.5.1