#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_t * | updateIRQ_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_t * | sensorproc = NULL |
static struct file_operations | image_acq_fops |
#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/>. ! -----------------------------------------------------------------------------** !
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" |
#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.
void camera_interrupts | ( | int | on | ) |
Camera interrupts on/off (currently both in the FPGA and in the CPU).
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 | ) |
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 | , | |||
0 | ||||
) |
static irqreturn_t elphel_FPGA_interrupt | ( | int | irq, | |
void * | dev_id | |||
) | [static] |
hardware IRQ service most urgent tasks
irq | ||
dev_id |
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?
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.
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.
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
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().
const char elphel_cam_name[] = "elphelcam353" [static] |
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:
{ owner: THIS_MODULE, llseek: image_acq_fops_lseek, write: image_acq_fops_write, open: image_acq_open, mmap: image_acq_mmap, release: image_acq_release }
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] |
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().