// if (unlikely((color>=4) || (color<0))) return NULL; //
index=gammas[0].locked_chn_color[cps];
MDF11(printk(" index=%d(0x%x)\n",index,index));
if(index)returngammas[index].fpga;
elsereturnNULL;
...
...
@@ -376,18 +384,18 @@ unsigned long * get_gamma_fpga(int color) { /// NOTE: Not needed anymore?
*/
intgamma_new_node(void){
inttmp_p;
if((gammas[0].non_scaled_length>GAMMA_THRESH)&&(gammas[gammas[0].oldest_non_scaled].newest_scaled==gammas[0].oldest_non_scaled)){/// no scaled for the oldest hash
/// sacrifice oldest hash
if((gammas[0].non_scaled_length>GAMMA_THRESH)&&(gammas[gammas[0].oldest_non_scaled].newest_scaled==gammas[0].oldest_non_scaled)){// no scaled for the oldest hash
// sacrifice oldest hash
tmp_p=gammas[0].oldest_non_scaled;
remove_from_nonscaled(tmp_p);
}else{/// use oldest scaled
}else{// use oldest scaled
tmp_p=gammas[0].oldest_all;
/// skip locked if any (should be unlikely to get any locked)
// skip locked if any (should be unlikely to get any locked)
* @brief calculate gamma table (and requested derivatives), insert new node if needed.
* @param hash16 16-bit unique (non-scaled) gamma table identifier. Can be 1-byte gamma and 1-byte black level shift TODO: make black level fine-grained?
* - 1 - if set, no interrupts will be enabled between steps, whole operation will be atomic
* - 2 - calculate reverse gamma table
* - 4 - calculate FPGA-format gamma table.
* - 8 - Lock (FPGA) table for specified color
* @param color color index (0..3) to lock table for (if mode bit 4 is set), otherwise color is ignored
* @return index for the specified table or 0 if none exists and prototype was not provided (gamma_proto==NULL)
*/
//#define GAMMA_MODE_LOCK 8 // Lock the table for the specified color (used from irq/tasklet - it is needed because all 4 tables in FPGA have to be overwritten at once)
/// next 1 byte [4] - mode (1 - not_nice, 2 - need reverse, 4 - hardware, 8 - lock)
/// next byte [5] - color only if lock bit in mode is set
/// next 514 bytes [6..519] - 16-bit gamma table
/// can use current file pointer or special indexes (0x****ff01 - set frame number, 0x****ff02 - set latency) that should come before actual parameters
/// file pointer - absolute frame number
/// lseek (SEEK_SET, value) - do nothing, return 0
/// lseek (SEEK_CUR, value) - ignore value, return last write result (and if it is still valid) - used by ftell
/// lseek (SEEK_END, value <= 0) - do nothing?, do not modify file pointer
/// lseek (SEEK_END, value > 0) - execute commands, do not modify file pointer
/// lseek (SEEK_END, 1) - initialize all the gamma data structures
/// lseek (SEEK_END, 2) - check that current hash/scale/index are still current
/// mmap (should be used read only)
// File operations:
// open, release - nop
// read - none
// write should be a single call (with or without actual table), file pointer after write is result node index (0 - failure)
// next 1 byte [4] - mode (1 - not_nice, 2 - need reverse, 4 - hardware, 8 - lock)
// next byte [5] - color only if lock bit in mode is set
// next 514 bytes [6..519] - 16-bit gamma table
// can use current file pointer or special indexes (0x****ff01 - set frame number, 0x****ff02 - set latency) that should come before actual parameters
// file pointer - absolute frame number
// lseek (SEEK_SET, value) - do nothing, return 0
// lseek (SEEK_CUR, value) - ignore value, return last write result (and if it is still valid) - used by ftell
// lseek (SEEK_END, value <= 0) - do nothing?, do not modify file pointer
// lseek (SEEK_END, value > 0) - execute commands, do not modify file pointer
// lseek (SEEK_END, 1) - initialize all the gamma data structures
// lseek (SEEK_END, 2) - check that current hash/scale/index are still current
// mmap (should be used read only)
//#define LSEEK_GAMMA_INIT 1 // SEEK_END LSEEK_GAMMA_INIT to initialize all the gamma data structures
//#define LSEEK_GAMMA_ISCURRENT 2 // SEEK_END to check if the selected node(pointed by file pointer) is current - returns 0 if not, otherwise - node index
* - next 1 byte [5] - color only if lock bit in mode is set
* - next 1 byte [5] - color only if lock bit in mode is set. Note: could not find why it was >>3 - error?, seems never used. In 393 it holds {port[1:0],chn[1:0],color[1:0]}
* - next 514 bytes [6..519] - 16-bit gamma table (if less than 514 bytes NULL will be passed to \b set_gamma_table()
* sets file pointer to gamma cache index (0 - no table exist)
set_gamma_table(0,GAMMA_SCLALE_1,NULL,0,0);/// maybe not needed to put linear to cache - it can be calculated as soon FPGA will be tried to be programmed with
/// hash16==0
set_gamma_table(0,GAMMA_SCLALE_1,NULL,0,0,0,0);// maybe not needed to put linear to cache - it can be calculated as soon FPGA will be tried to be programmed with
@@ -18,14 +18,14 @@ void gamma_encode_fpga(unsigned short * gamma_in, unsigned long * gamma_out);///
voidgamma_calc_scaled(unsignedshortscale,unsignedshort*gamma_in,unsignedshort*gamma_out);/// scale gamma table by (scale>>GAMMA_SCALE_SHIFT), saturate to 0..0xffff
//void gamma_calc_reverse(unsigned short * gamma_in, unsigned short * gamma_out);/// calculate reverse gamma table (16-bit output) that matches 1-byte gamma-converted data to the input data (in the 0..ffff range)
voidgamma_calc_reverse(unsignedshort*gamma_in,unsignedchar*gamma_out);/// calculate reverse gamma table (8-bit output) that matches 1-byte gamma-converted data to the input data (in the 0..ffff range)
/// return index of the specified hash/scale, insert new table (gamma_proto) if needed
/// If no table is specified (null) - return 0 if no prototype is found
/// if (not_nice) - don't re-enable interrupts between atomic actions (may fail)
/// if "hardware" is non-zero, color/frame pair will be used to lock node to it, fpga-encoded table will be calculated (if not done so earlier)
// return index of the specified hash/scale, insert new table (gamma_proto) if needed
// If no table is specified (null) - return 0 if no prototype is found
// if (not_nice) - don't re-enable interrupts between atomic actions (may fail)
// if "hardware" is non-zero, color/frame pair will be used to lock node to it, fpga-encoded table will be calculated (if not done so earlier)
// #define GAMMA_MODE_NOT_NICE 1 // if set, no interrupts will be enabled between steps, whole operation is atomic
// #define GAMMA_MODE_NEED_REVERSE 2 // reverse gamma table is needed
// #define GAMMA_MODE_HARDWARE 4 // the table is needed to program FPGA: fpga-encoded table will be calculated (if not yet), node will be locked for specified
* lseek (SEEK_END, LSEEK_HIST_REQ_EN) - (default)enable histogram request when reading histogram (safer, but may be not desirable in HDR mode) - default after opening
* lseek (SEEK_END, LSEEK_HIST_REQ_DIS) - disable histogram request when reading histogram - will read latest available relying it is available
// #define X313_RA_HIST_DATA 0x45 /// use CSP4 with wait cycles to have a pulse
port_csp0_addr[X313_WA_HIST_ADDR]=addr;/// Write start address, read first word from the memory to the output buffer (will be read out during next read)
X3X3_AFTERWRITE;//! needed before reading from FPGA after writing to it (for the writes that influence reads only)
for(i=0;i<l;i++)data[i]=port_csp4_addr[X313_RA_HIST_DATA];/// will autoincrement FPGA table address)
/// 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)?
// 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)?
/// 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)
/* Modified for 393 - using up to 4 sub-sensors (even as 10359 only supports 3 */
...
...
@@ -427,6 +428,8 @@
// The following 4 parameters should have consecutive indexes
// see FRAMEPAIR_MASK_BYTES to modify just part of the word (i.e. scale, not hash16
//
// Will need to have them per-subchannel (4x)
#define PER_CHANNEL393 0 ///< set to 1 when ready with per-channel for 393, meanwhile will overwrite each other in histograms.c
#define P_GTAB_R 128 ///< combines (P_PIXEL_LOW<<24) | (P_GAMMA <<16) and 16-bit (6.10) scale for gamma tables, individually for each color.
///< 16Msbs are also "hash16" and do not need to be black level/gamma, just uniquely identify the table for applications
#define P_GTAB_G 129 ///< same for the first green (red line)
...
...
@@ -453,6 +456,8 @@
#define COLORMODE_MONO4 14 ///< monochrome, 4 blocks (but still with 2x2 macroblocks)
// the following 8 values should go in the same sequence as fields in the histogram page
// 393: per sub-channel
//// Will need to have them per-subchannel (4x)
#define P_FRAME 136 ///< Frame number (reset with JPEG pointers) -(read only)
#define P_GAINR 137 ///< R channel gain 8.16 (0x10000 - 1.0). Combines both analog gain and digital scaling
#define P_GAING 138 ///< G channel gain ("red line")
...
...
@@ -706,9 +711,10 @@
#define TASKLET_CTL_HISTY_BIT 4 ///< shift of histogram calculation for Y in G_TASKLET_CTL (bits 4,5,6)
#define TASKLET_CTL_HISTC_BIT 8 ///< shift of histogram calculation for C in G_TASKLET_CTL (bits 8,9,10)
#define G_HIST_LAST_INDEX (FRAMEPAR_GLOBALS + 56) ///< last used index in histogram cache
#define G_HIST_Y_FRAME (FRAMEPAR_GLOBALS + 57) ///< last frame for which Y histogram was calcualted
#define G_HIST_C_FRAME (FRAMEPAR_GLOBALS + 58) ///< last frame for which C histograms were calcualted
//#define G_HIST_LAST_INDEX (FRAMEPAR_GLOBALS + 56) // /< last used index in histogram cache
//#define G_HIST_Y_FRAME (FRAMEPAR_GLOBALS + 57) // /< last frame for which Y histogram was calculated
//#define G_HIST_C_FRAME (FRAMEPAR_GLOBALS + 58) // /< last frame for which C histograms were calculated
#define G_SUBCHANNELS (FRAMEPAR_GLOBALS + 56) ///< subchannels used on this sensor port (bitmask)
#define G_SKIP_DIFF_FRAME (FRAMEPAR_GLOBALS + 59) ///< number of frames with different size to tolerate before producing POLLHUP in poll(circbuf)
#define G_FTP_NEXT_TIME (FRAMEPAR_GLOBALS + 60) ///< time of the next FTP upload (seconds from epoch)
...
...
@@ -719,6 +725,12 @@
#define G_TEMPERATURE01 (FRAMEPAR_GLOBALS + 96) ///< temperature on the sensors 0 and 1 (0x1000 - sign, rest 8.4 C) no 10359 - only chn0, with 10359 - only 1,2,3 (no 0)
#define G_TEMPERATURE23 (FRAMEPAR_GLOBALS + 97) ///< temperature on the sensors 2 and 3
// Moving here as there can be multiple histograms per port
#define G_HIST_LAST_INDEX (FRAMEPAR_GLOBALS + 98) ///< last used index in histogram cache (uses 4 locations), set to !=0 to activate, 0 will skip
#define G_HIST_Y_FRAME (FRAMEPAR_GLOBALS + 102) ///< last frame for which Y histogram was calculated (uses 4 locations)
#define G_HIST_C_FRAME (FRAMEPAR_GLOBALS + 106) ///< last frame for which C histograms were calculated (uses 4 locations)
#define G_SENSOR_CALIB (FRAMEPAR_GLOBALS + 1024) ///< 1024 Array of sensor calibration data, sensor dependent.For Micron it is 256*4 actual gains in 8.16 format
///< Only first 96 for each color are used
...
...
@@ -1266,6 +1278,7 @@ struct p_names_t {
G_NAME_ENTRY(HIST_LAST_INDEX), \
G_NAME_ENTRY(HIST_Y_FRAME), \
G_NAME_ENTRY(HIST_C_FRAME), \
G_NAME_ENTRY(SUBCHANNELS), \
G_NAME_ENTRY(SKIP_DIFF_FRAME), \
G_NAME_ENTRY(FTP_NEXT_TIME), \
G_NAME_ENTRY(DAEMON_ERR), \
...
...
@@ -1340,29 +1353,29 @@ struct p_names_t {
//#define IO_CCAM_START_RAW 0x0a // Programs DMA descriptor list according to current frame size, FPGA registers and starts DMA
/// MOST ARE OBSOLETE - WILL REMOVE WHEN UPDATING STREAMERS
#define IO_CCAM_JPEG 0x08 /// JPEG-compressor related commands
#define JPEG_CMD_RESET 0x00 /// Resets pointers - both acquisition and readout
//#define JPEG_CMD_ARM 0x01 /// Prepare compressor to read next frame acquired
#define JPEG_CMD_GET 0x02 /// Read current page (will return empty (and length==0) if not ready
#define JPEG_CMD_STOP 0x0b ///< stop constant compression mode (may want to wait for CAMSEQ_DONE)
#define JPEG_CMD_FRAMES 0x0c ///< returns number of frames in buffer, (re)uilds frames chain
#define JPEG_CMD_JUST_STOP 0x0d ///< just stop - don't start cycle if was allready off!
#define JPEG_CMD_DUMP 0x0f ///< printk all static data/tables
#define JPEG_CMD_RESET0 0x10 ///< same as JPEG_CMD_RESET, but non-zero, to be used from lseek (SEEK_END)
//#define PROGRAM_SENSOR_0 0x11 ///< programSensor(0) - to be used from lseek (SEEK_END)
//#define PROGRAM_SENSOR_1 0x12 ///< programSensor(1) - to be used from lseek (SEEK_END)
/// Compressor state now applies only to particular frame
//#define LSEEK_CAMSEQSTATE 0x13 /// return camSeqState - to be used from lseek (SEEK_END)
//#define LSEEK_CAMSEQSTATE 0x13 ///< return camSeqState - to be used from lseek (SEEK_END)
#define LSEEK_GAMMA_INIT 1 // SEEK_END LSEEK_GAMMA_INIT to initialize all the gamma data structures
#define LSEEK_GAMMA_ISCURRENT 2 // SEEK_END to check if the selected node(pointed by file pointer) is current - returns 0 if not, otherwise - node index
...
...
@@ -1392,47 +1405,48 @@ struct p_names_t {
#define LSEEK_HUFFMAN_FPGACALC 7
#define LSEEK_HUFFMAN_FPGAPGM 8
//#define LSEEK_RESET_SENSOR 0x14 /// reset sensor and FPGA - next time will reprogram it
//#define LSEEK_INIT_SENSOR 0x15 /// initialise SDRAM and sensor if it is not programmed yet (or reset)
//#define LSEEK_RESET_SENSOR 0x14 ///< reset sensor and FPGA - next time will reprogram it
//#define LSEEK_INIT_SENSOR 0x15 ///< initialise SDRAM and sensor if it is not programmed yet (or reset)
#define LSEEK_GET_FPGA_TIME 0x16 /// get FPGA timer to G_SECONDS, G_MICROSECONDS
#define LSEEK_SET_FPGA_TIME 0x17 /// set FPGA timer to G_SECONDS, G_MICROSECONDS
#define LSEEK_GET_FPGA_TIME 0x16 ///< get FPGA timer to G_SECONDS, G_MICROSECONDS
#define LSEEK_SET_FPGA_TIME 0x17 ///< set FPGA timer to G_SECONDS, G_MICROSECONDS
//#define LSEEK_FLUSH_CACHE 0x18 // workaround for Axis mmap cache coherency problems - flush all cache (8KB)
#define LSEEK_AUTOEXP_SET 0x19 /// set autoexposure parameters
#define LSEEK_AUTOEXP_GET 0x1a /// copy window and exposure parameters to autoexp_state
#define LSEEK_TRIGGER_PGM 0x1b /// program trigger parameters
#define LSEEK_I2C_PGM 0x1c /// program hardware i2c speed/bytes
#define LSEEK_SENSORPROC 0x26 /// process modified parameters in frame 0 (to start sensor detection)
#define LSEEK_FRAME_RESET 0x27 /// reset absolute frame number to avoid integer overflow
///Histograms related commands
#define LSEEK_HIST_WAIT_Y 0x28 /// set histogram waiting for the Y (actually G1) histogram (default after open)
#define LSEEK_HIST_WAIT_C 0x29 /// set histogram waiting for the C (actually R, G2, B) histograms to become available - implies G1 too
#define LSEEK_HIST_REQ_EN 0x2a /// enable histogram request when reading histogram (safer, but may be not desirable in HDR mode) - default after opening
#define LSEEK_HIST_REQ_DIS 0x2b /// disable histogram request when reading histogram - will read latest available relying it is available
#define LSEEK_HIST_NEEDED 0x10000 /// set histogram "needed" mask - 0x10000..0x1ffff
//#define LSEEK_HIST_WAIT_AE 0x2a /// wait for autoexposure enabled
#define LSEEK_DAEMON_FRAME 0x80 /// LSEEK_DAEMON_FRAME+B wait for frame interrupt and corresponding bit (B) in P_DAEMON_EN is set
#define LSEEK_DAEMON_CIRCBUF 0xa0 /// LSEEK_DAEMON_FRAME+B wait for frame compressed interrupt and corresponding bit (B) in P_DAEMON_EN is set
#define LSEEK_DAEMON_HIST_Y 0xc0 /// LSEEK_DAEMON_FRAME+B wait for histogram Y ready and corresponding bit (B) in P_DAEMON_EN is set
#define LSEEK_DAEMON_HIST_C 0xe0 /// LSEEK_DAEMON_FRAME+B wait for all histograms ready and corresponding bit (B) in P_DAEMON_EN is set
#define LSEEK_FRAME_WAIT_REL 0x100 /// LSEEK_WAIT_FRAME_REL+N - skip N frames (0<N<256)
#define LSEEK_FRAME_WAIT_ABS 0x200 /// LSEEK_WAIT_FRAME_ABS+N - wait absolute frame N
#define LSEEK_AUTOEXP_SET 0x19 ///< set autoexposure parameters
#define LSEEK_AUTOEXP_GET 0x1a ///< copy window and exposure parameters to autoexp_state
#define LSEEK_TRIGGER_PGM 0x1b ///< program trigger parameters
#define LSEEK_I2C_PGM 0x1c ///< program hardware i2c speed/bytes
#define LSEEK_SENSORPROC 0x26 ///< process modified parameters in frame 0 (to start sensor detection)
#define LSEEK_FRAME_RESET 0x27 ///< reset absolute frame number to avoid integer overflow
//Histograms related commands
#define LSEEK_HIST_WAIT_Y 0x28 ///< set histogram waiting for the Y (actually G1) histogram (default after open)
#define LSEEK_HIST_WAIT_C 0x29 ///< set histogram waiting for the C (actually R, G2, B) histograms to become available - implies G1 too
#define LSEEK_HIST_REQ_EN 0x2a ///< enable histogram request when reading histogram (safer, but may be not desirable in HDR mode) - default after opening
#define LSEEK_HIST_REQ_DIS 0x2b ///< disable histogram request when reading histogram - will read latest available relying it is available
#define LSEEK_HIST_SET_CHN 0x30 ///< ..2F Select channel to wait for (4*port+subchannel)
#define LSEEK_HIST_NEEDED 0x10000 ///< set histogram "needed" mask - 0x10000..0x1ffff
//#define LSEEK_HIST_WAIT_AE 0x2a ///< wait for autoexposure enabled
#define LSEEK_DAEMON_FRAME 0x80 ///< LSEEK_DAEMON_FRAME+B wait for frame interrupt and corresponding bit (B) in P_DAEMON_EN is set
#define LSEEK_DAEMON_CIRCBUF 0xa0 ///< LSEEK_DAEMON_FRAME+B wait for frame compressed interrupt and corresponding bit (B) in P_DAEMON_EN is set
#define LSEEK_DAEMON_HIST_Y 0xc0 ///< LSEEK_DAEMON_FRAME+B wait for histogram Y ready and corresponding bit (B) in P_DAEMON_EN is set
#define LSEEK_DAEMON_HIST_C 0xe0 ///< LSEEK_DAEMON_FRAME+B wait for all histograms ready and corresponding bit (B) in P_DAEMON_EN is set
#define LSEEK_FRAME_WAIT_REL 0x100 ///< LSEEK_WAIT_FRAME_REL+N - skip N frames (0<N<256)
#define LSEEK_FRAME_WAIT_ABS 0x200 ///< LSEEK_WAIT_FRAME_ABS+N - wait absolute frame N
#define LSEEK_FSDRAM_RESET 0x01 // re-program FSDRAM (to be programmed again when accessed)
...
...
@@ -1569,49 +1583,49 @@ struct p_names_t {
// make this structure common for sensors, add fields as needed
structsensor_t{
// sensor constants
unsignedlongimageWidth;/// nominal image width for final images
unsignedlongimageHeight;/// nominal image height for final images
#define DEFAULT_COLOR_SATURATION_BLUE 0x90 // 100*realtive saturation blue
#define DEFAULT_COLOR_SATURATION_RED 0xb6 // 100*realtive saturation red
#define DEFAULT_COLOR_SATURATION_BLUE 0x90 ///< 100*realtive saturation blue
#define DEFAULT_COLOR_SATURATION_RED 0xb6 ///< 100*realtive saturation red
//#define EXPOSURE_UNIT 100 // to move to finer exposure settings - current unit in microseconds. TODO: Propagate it to drivers...
#define EXPOSURE_UNIT 1 // to move to finer exposure settings - current unit in microseconds. TODO: Propagate it to drivers...
#define EXPOSURE_UNIT 1 ///< to move to finer exposure settings - current unit in microseconds. TODO: Propagate it to drivers...
/// width,height, quality are still needed even with new Exif - it is used to rebuild JPEG header
// most parameters are moved out, but width, height, quality are needed for JPEG header, so currently the following are used:
...
...
@@ -1711,9 +1725,9 @@ struct gamma_stuct_t {
};
};
};
intvalid;/// 0 - table invalid, 1 - table valid +2 for table locked (until sent to FPGA)
u64valid;/// 0 - table invalid, 1 - table valid +2 for table locked (until sent to FPGA)
// int locked; /// bit frame+ (color<<3) locked for color/frame
intlocked;/// NOTE: Changed to just color locked for color
u64locked;/// NOTE: Changed to just color locked for color
intthis_non_scaled;// 0 for non-scaled, others - (for scaled) - pointer to the corresponding non-scaled
union{/// used in head (element 0) and non-scaled chain (not used in scaled)
struct{/// element 0 - heads of the chains
...
...
@@ -1760,10 +1774,12 @@ struct gamma_stuct_t {
};
struct{
// int locked_col_frame[4 * PARS_FRAMES]; //index of the table to load to color/frame (should be locked, until unlocked)
intlocked_color[4];/// NOTE: Changed to just color (locked last written to FPGA - maybe needed again, as the FPGA needs all table to be overwritten - two pages)
intlocked_chn_color[4*MAX_SENSORS*SENSOR_PORTS];/// NOTE: Changed to just color (locked last written to FPGA - maybe needed again, as the FPGA needs all table to be overwritten - two pages)
// For NC393 - using 64 entries - individual for each channel/subchannel, color is in 2 lower bits