Commit f497cdab authored by Mikhail Karpenko's avatar Mikhail Karpenko
Browse files

Merge sensor_common

parent 03dc3b07
Loading
Loading
Loading
Loading
+749 −0

File added.

Preview size limit exceeded, changes collapsed.

+44 −0
Original line number Diff line number Diff line
/*
 exif353.h
 */
#ifndef _EXIF_H
#define _EXIF_H
#if 0
struct exif_time_t {
  char          tomorrow_date[10]; //!"YYYY:MM:DD"
  unsigned long tomorrow_sec;      //!seconds from epoch tomorrow at 00:00
  char          today_date[10];    //!"YYYY:MM:DD"
  unsigned long today_sec;         //!seconds from epoch today at 00:00
} exif_time;

struct exif_datetime_t {
  char          datetime[20];      //!"YYYY:MM:DD HH:MM:SS\0"
  char          subsec[7];         //!ASCII microseconds (0-padded), ."\0"
} now_datetime;
#endif

void exif_invalidate(void);
int exif_rebuild_chn(int sensor_port, int frames);// reallocate meta buffer to store per-frame meta data (later output as Exif)
int exif_rebuild(int frames);                     // rebuild for all sensor ports

int exif_enable_chn(int sensor_port, int en);     // enable/disable Exif processing (both W/R)
int exif_enable(int en);                          // For all sensor ports
int dir_find_tag (unsigned long tag); //!find location of the tag field in meta page using long tag (Exif tag and tag group)

inline void write_meta_raw_irq(int sensor_port, char * data, int offset, int len); //write data to meta, called from IRQ
inline int write_meta_irq(int sensor_port, char * data, int * indx,  unsigned long ltag, int len); //write data to meta, called from IRQ(len==0 => use field length)
inline void putlong_meta_raw_irq(int sensor_port, unsigned long data, int offset); //write data to meta (4 bytes, big endian), called from IRQ
inline int putlong_meta_irq(int sensor_port, unsigned long data, int * indx,  unsigned long ltag); //write data to meta (4 bytes, big endian), from IRQ
//void write_meta_raw_irq(char * data, int offset, int len); //write data to meta, called from IRQ
//int write_meta_irq(char * data, int * indx,  unsigned long ltag, int len); //write data to meta, called from IRQ(len==0 => use field length). Returns index of the written data, -1 if not written

void write_meta_raw(int sensor_port, char * data, int offset, int len); //write data to meta, called from outside IRQ (atomic)
int write_meta(int sensor_port, char * data, int * indx,  unsigned long ltag, int len); //write data to meta, from outside IRQ (atomic) (len==0 => use field length). Returns index of the written data, -1 if not written
void putlong_meta_raw(int sensor_port, unsigned long data, int offset); //write data to meta (4 bytes, big endian), called from outside IRQ (atomic)
int putlong_meta(int sensor_port, unsigned long data, int * indx,  unsigned long ltag); //write data to meta (4 bytes, big endian), from outside IRQ (atomic). Returns index of the written data, -1 if not written

char * encode_time(unsigned long sec, unsigned long usec);
int store_meta(int sensor_port); //called from IRQ service - put current metadata to meta_buffer, return page index


#endif
+15 −12
Original line number Diff line number Diff line
@@ -71,7 +71,7 @@
#include "sensor_common.h"
//#include "pgm_functions.h"
#include "circbuf.h"
//#include "exif353.h"
#include "exif393.h"
//#include "histograms.h"
//#include "gamma_tables.h"
#include "quantization_tables.h"
@@ -193,8 +193,8 @@ void camseq_set_jpeg_rp(unsigned int chn, int ptr)
*/

static const struct of_device_id elphel393_sensor_of_match[];
static struct sensorproc_t s_sensorproc; // sensor parameters and functions to call
struct sensorproc_t * sensorproc = NULL;
static struct sensorproc_t as_sensorproc[SENSOR_PORTS]; // sensor parameters and functions to call
struct sensorproc_t * asensorproc = NULL;
//EXPORT_SYMBOL_GPL(sensorproc);
//wait_queue_head_t image_acq_wait_queue;  /// queue for the sensor frame interrupts

@@ -207,10 +207,10 @@ void tasklet_fpga_function(unsigned long arg);
 * @param[in]   copy   pointer to a copy structure
 * @return      pointer to a \b copy structure
 */
struct sensorproc_t * copy_sensorproc (struct sensorproc_t * copy)
struct sensorproc_t * copy_sensorproc (int sensor_port, struct sensorproc_t * copy)
{
	/** copy sensor functions */
	memcpy(copy, sensorproc, sizeof(struct sensorproc_t));
	memcpy(copy, asensorproc[sensor_port], sizeof(struct sensorproc_t));
	return copy;
}

@@ -228,7 +228,7 @@ struct sensorproc_t * copy_sensorproc (struct sensorproc_t * copy)
///#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_acq_sensor(void);
int init_acq_sensor(void); // Never used?

//DECLARE_TASKLET(tasklet_fpga, tasklet_fpga_function, 0); /// 0 - no arguments for now
DECLARE_TASKLET(tasklet_fpga_0, tasklet_fpga_function, 0); /// 0 - no arguments for now
@@ -355,6 +355,8 @@ inline void updateIRQFocus(struct jpeg_ptr_t *jptr)
    //set_globalParam     (G_GFOCUS_VALUE, X313_HIGHFREQ);
    //set_imageParamsThis (P_FOCUS_VALUE, X313_HIGHFREQ);
	u32 high_freq = x393_cmprs_hifreq(jptr->chn_num);
    set_globalParam     (jptr->chn_num, G_GFOCUS_VALUE, high_freq);
    set_imageParamsThis (jptr->chn_num, P_FOCUS_VALUE, high_freq);
}

inline static void set_default_interframe(struct interframe_params_t *params)
@@ -404,7 +406,7 @@ inline struct interframe_params_t* updateIRQ_interframe(struct jpeg_ptr_t *jptr)
	set_default_interframe(interframe);
	/* end of debug code */

//	set_globalParam(G_FRAME_SIZE, jpeg_len);
	set_globalParam(jptr->chn_num, G_FRAME_SIZE, jpeg_len);

	// invalidate CPU L1 and L2 caches (in this order)
	phys_addr = circbuf_priv_ptr[jptr->chn_num].phys_addr + DW2BYTE(frame_params_offset);
@@ -419,9 +421,10 @@ inline struct interframe_params_t* updateIRQ_interframe(struct jpeg_ptr_t *jptr)
 * @brief Fill exif data with the current frame data, save pointer to Exif page in the interframe area
 * @param interframe pointer to interframe parameters structure
 */
inline void updateIRQ_Exif(struct interframe_params_t* interframe) {
   int  index_time = JPEG_wp-11; if (index_time<0) index_time+=get_globalParam (G_CIRCBUFSIZE)>>2;
#ifdef TES_DISABLE_CODE
inline void updateIRQ_Exif(int sensor_port, struct interframe_params_t* interframe) {
   int  index_time = aJPEG_wp-11[sensor_port]; if (index_time<0) index_time+=get_globalParam (sensor_port, G_CIRCBUFSIZE)>>2;
//   struct exif_datetime_t
//#ifdef TES_DISABLE_CODE
/// calculates datetime([20] and subsec[7], returns  pointer to char[27]
   char * exif_meta_time_string=encode_time(ccam_dma_buf_ptr[index_time], ccam_dma_buf_ptr[index_time+1]);
/// may be split in datetime/subsec - now it will not notice missing subseq field in template
@@ -481,7 +484,7 @@ inline void updateIRQ_Exif(struct interframe_params_t* interframe) {
   }
   interframe->meta_index=store_meta();

#endif /* TES_DISABLE_CODE */
//#endif /* TES_DISABLE_CODE */
}


@@ -810,7 +813,7 @@ int image_acq_init(struct platform_device *pdev)
	if (!match)
		return -EINVAL;*/

	sensorproc= &s_sensorproc;
	asensorproc= &as_sensorproc[0];
	//MDD1(printk("sensorproc=0x%x\n",(int) sensorproc));
	dev_dbg(dev, "sensorproc address: 0x%x\n", (int)sensorproc);

+30 −14
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@
 #define EDBG(x)
#endif


#define ROUND_UP(N, S) ((((N) + (S) - 1) / (S)) * (S))

// _IOC_TYPE, bits 8 to 15 in ioctl cmd

@@ -234,8 +234,11 @@
#define SENSORWIDTH_IBIS51300  1280
#define SENSORHEIGHT_IBIS51300 1024
/// Parameters related to multi-sensor (10359A) setup
#define MAX_SENSORS 3 // maximal number of sensor attached (modify some hard-wired constants below if this to be changed)
//! Parameters below are accessed through mmap, because of cache coherency problem it make sense to keep them compact (maybe group by 8 - cache line of 32 bytes)
//#define MAX_SENSORS 3 // maximal number of sensor attached (modify some hard-wired constants below if this to be changed)
/* Modified for 393 - using up to 4 sub-sensors (even as 10359 only supports 3 */
#define MAX_SENSORS  4        // maximal number of sensor attached (modify some hard-wired constants below if this to be changed)
#define SENSOR_PORTS 4        // Number of sensor ports (each has individual framepars_all_t
//! Parameters below are accessed through mmap, because of cache coherence problem it make sense to keep them compact (maybe group by 8 - cache line of 32 bytes)
#define P_SENSOR_RUN     4 // 0 - stop, 1 - single, 2 - run
  #define SENSOR_RUN_STOP   0
  #define SENSOR_RUN_SINGLE 1
@@ -592,6 +595,13 @@
#define P_MULTI_REGS          (P_M10359_REGS + P_M10359_NUMREGS) /// 32-words aligned

#define P_MAX_PAR         (P_MULTI_REGS + (MAX_SENSORS * P_MULTI_NUMREGS )) /// maximal # of used parameter+1
/* 393: Making P_MAX_PAR multiple of PAGE_SIZE/2, so framepars_all_t will be multiple of PAGE_SIZE*/
#ifndef PAGE_SIZE
	#define PAGE_SIZE 4096 // not using <asm/page.h> as this file may be used outside of kernel
#endif
#define P_MAX_PAR_ROUNDUP ROUND_UP (P_MAX_PAR , (PAGE_SIZE/8)) // half page in DWORDs


#ifdef SAFE_CHECK
  #define MULTIREG(x,n) ((((n)>=0) && ((n)<MAX_SENSORS) && ((x) >0) && ((x) < P_MAX_PAR) && (multiSensIndex[x] > 0))? (multiSensIndex[x]+(n)) : 0)
#else
@@ -602,8 +612,9 @@

//#define P_MAX_PAR        511 /// maximal # of used parameter
//#define P_MAX_GPAR      1023 // maximal # of global parameter
#define P_MAX_GPAR      2047 /// maximal # of global parameter - TODO: change name to NUM_GPAR and make it 2048

//#define P_MAX_GPAR      2047 /// maximal # of global parameter - TODO: change name to NUM_GPAR and make it 2048
#define NUM_GPAR        2048           /// maximal # of global parameter - TODO: change name to NUM_GPAR and make it 2048
#define P_MAX_GPAR      (NUM_GPAR - 1) /// maximal # of global parameter - TODO: change name to NUM_GPAR and make it 2048

#define PARS_SAVE_FROM   128 /// PARS_SAVE_NUM parameters starting from PARS_SAVE_FROM from "this" frame will be saved in circular buffer, PASTPARS_SAVE_ENTRIES entries
#define PARS_SAVE_COPY    16 /// number of parameters copied from future (framepars) to the past (pastpars)
@@ -617,7 +628,7 @@
#define GLOBALS_PRESERVE   0x20     /// number of parameters that are not erased during initGlobalPars

/// First 32 parameter values are not erased with initGlobalPars
#define GLOBALPARS(x) globalPars[(x)-FRAMEPAR_GLOBALS] // should work in drivers and applications
#define GLOBALPARS(p, x) (aglobalPars[p][(x)-FRAMEPAR_GLOBALS]) // should work in drivers and applications

#define G_DEBUG         (FRAMEPAR_GLOBALS + 2) /// Each bit turns on/off some debug outputs
#define G_TEST_CTL_BITS (FRAMEPAR_GLOBALS + 3) /// turn some features on/off in the drivers for debugging purposes
@@ -817,10 +828,14 @@
/// when the 3-bit counter is combined with the software variable to get the full 32-bit frame number
/// Each parameter page includes 927 parameter registers, as well as 97 bitmasks to speed up updates between frames
/// So if no parameters are changed - nothing to be copied from page to page
#define PARS_FRAMES                                  8      // number of frames handled in buffer
#define PARS_FRAMES_MASK     (PARS_FRAMES-1)               // currently 7
#define PASTPARS_SAVE_ENTRIES       (PARS_FRAMES << 8)     // 2048
#define PASTPARS_SAVE_ENTRIES_MASK ((PARS_FRAMES << 8)-1)  // 0x7ff
/* Modified for 393 : 16 hardware frames, aligning framepars_all_t to PAGE_SIZE*/
#define PARS_FRAMES                                  16 //    8      // number of frames handled in buffer
#define PARS_FRAMES_MASK     (PARS_FRAMES-1)               // currently 15t // 7
// Keeping the same size of past frames storage as in 353:
//#define PASTPARS_SAVE_ENTRIES       (PARS_FRAMES << 8)     // 2048
//#define PASTPARS_SAVE_ENTRIES_MASK ((PARS_FRAMES << 8)-1)  // 0x7ff
#define PASTPARS_SAVE_ENTRIES       (PARS_FRAMES << 7)     // 2048
#define PASTPARS_SAVE_ENTRIES_MASK ((PARS_FRAMES << 7)-1)  // 0x7ff
struct framepars_t {
        unsigned long pars[927];      // parameter values (indexed by P_* constants)
        unsigned long functions;      // each bit specifies function to be executed (triggered by some parameters change)
@@ -893,13 +908,14 @@ struct framepars_past_t {
    unsigned long past_pars[PARS_SAVE_NUM];
};

// size should be PAGE_SIZE aligned
struct framepars_all_t {
    struct framepars_t      framePars[PARS_FRAMES];
    struct framepars_t      func2call;        /// func2call.pars[] - each parameter has a 32-bit mask of what pgm_function to call - other fields not used
     unsigned long          globalPars[P_MAX_GPAR]; /// parameters that are not frame-related, their changes do not initiate any actions so they can be mmaped for both R/W
     unsigned long          globalPars[NUM_GPAR];                  /// parameters that are not frame-related, their changes do not initiate any actions so they can be mmaped for both R/W
    struct framepars_past_t pastPars [PASTPARS_SAVE_ENTRIES];
     unsigned long          multiSensIndex[P_MAX_PAR];     /// indexes of individual sensor register shadows (first of 3) - now for all parameters, not just sensor ones
     unsigned long          multiSensRvrsIndex[P_MAX_PAR]; /// reverse index (to parent) for the multiSensIndex in lower 16 bits, high 16 bits - sensor number
     unsigned long          multiSensIndex[P_MAX_PAR_ROUNDUP];     /// indexes of individual sensor register shadows (first of 3) - now for all parameters, not just sensor ones
     unsigned long          multiSensRvrsIndex[P_MAX_PAR_ROUNDUP]; /// reverse index (to parent) for the multiSensIndex in lower 16 bits, high 16 bits - sensor number
};

struct frameparspair_t {
@@ -1773,7 +1789,7 @@ struct gamma_stuct_t {
#define HISTOGRAM_TABLE_OFFSET 52 /// Histogram tables data starts 44 bytes from the histogram page structure (for PHP raw histogram)
///TODO: Update when histogram_stuct_t is changed
struct histogram_stuct_t {
   unsigned long frame;                /// frame number correspoding to the current histogram
   unsigned long frame;                /// frame number corresponding to the current histogram
/// Color gains for the frame of the histogram
   union {
       unsigned long gains[4];
+17 −2
Original line number Diff line number Diff line
@@ -45,6 +45,11 @@
#define HUFFMAN_MINOR_CHN_2       0x42
#define HUFFMAN_MINOR_CHN_3       0x43

#define CMOSCAM_MINOR_FRAMEPARS_CHN_0  0x50
#define CMOSCAM_MINOR_FRAMEPARS_CHN_1  0x51
#define CMOSCAM_MINOR_FRAMEPARS_CHN_2  0x52
#define CMOSCAM_MINOR_FRAMEPARS_CHN_3  0x53

#define CMOSCAM_MINOR_RWTABLES    9
#define CMOSCAM_MINOR_CIRCBUF    11
#define CMOSCAM_MINOR_HISTOGRAM  12
@@ -79,11 +84,21 @@
#define FPGA_SJTAG_MINOR_OFFSET     8 // Minors range start for the sensor port JTAG
#define FPGA_SJTAG_BOUNDARY_OFFSET 12 // Minors range start for the sensor port boundary

#define X3X3_EXIF_EXIF    0 // read encoded Exif data (SEEK_END,
#define X3X3_EXIF_META    1 // write metadata, concurently opened files. All writes atomic
//#define X3X3_EXIF_EXIF    0 // read encoded Exif data (SEEK_END,
//#define X3X3_EXIF_META    1 // write metadata, concurently opened files. All writes atomic
// control/setup devices
#define X3X3_EXIF_TEMPLATE 2 // write Exif template
#define X3X3_EXIF_METADIR  3 // write metadata to Exif header translation (dir_table[MAX_EXIF_FIELDS])
// those 2 files will disable exif_enable and exif_valid, truncate file size to file pointer on release.
#define X3X3_EXIF_TIME     4 // write today/tomorrow date (YYYY:MM:DD) and number of seconds at today/tomorrow
                             // midnight (00:00:00) in seconds from epoch (long, startting from LSB)

#define X3X3_EXIF_EXIF_CHN_0   0x10 // read encoded Exif data (SEEK_END,
#define X3X3_EXIF_EXIF_CHN_1   0x11 // read encoded Exif data (SEEK_END,
#define X3X3_EXIF_EXIF_CHN_2   0x12 // read encoded Exif data (SEEK_END,
#define X3X3_EXIF_EXIF_CHN_3   0x13 // read encoded Exif data (SEEK_END,
#define X3X3_EXIF_META_CHN_0   0x20 // write metadata, concurently opened files. All writes atomic
#define X3X3_EXIF_META_CHN_1   0x21 // write metadata, concurently opened files. All writes atomic
#define X3X3_EXIF_META_CHN_2   0x22 // write metadata, concurently opened files. All writes atomic
#define X3X3_EXIF_META_CHN_3   0x23 // write metadata, concurently opened files. All writes atomic