Commit 09f15f8e authored by Andrey Filippov's avatar Andrey Filippov

digging through/documenting legacy code

parent 9fef6848
///@file legacy_defines.h
#define X313_MAXWIDTH 65536 // 4096 // multiple of 128
#define X313_MAXHEIGHT 65536 // 16384 // multiple of 16 - unsafe - not enough room for black level subtraction
#define X313_MAXHEIGHT_SAFE 65536 // 4096 // multiple of 16 OK for black level subtraction TODO: disable black level if unsafe
#define X313_MAP_FRAME ((X313_MAP_FPN) + (X313_MAXWIDTH) * (X313_MAXHEIGHT_SAFE))
#define X313_MARGINS 4
#define X313_TILEHOR 16
#define X313_TILEVERT 16
#define X313_TIMESTAMPLEN 28 // pixels used for timestamp (in linescan mode added after the line)
#define X3X3_RSTSENSDCM // FPGA DCM can fail after clock change, needs to be reset
#define X3X3_SENSDCM_CLK2X_RESET // reset pclk2x DCM also
#define I2C359_CLK_NUMBER 4
......@@ -11,3 +19,62 @@
#define CCAM_ARST_OFF
#define CCAM_RESET_MCONTR_ON // Set mode that resets memory controller pointers after each frame sync. TODO: Later - make it work without?
#define CCAM_ENDFRAMES_EN // Enable ending frame being compressed if no more data will be available (frame ended before specified number of blocks compressed)
#define CCAM_DCLK_ON
#define CCAM_CNVEN_OFF
#define CCAM_MRST_ON
#define CCAM_EXTERNALTS_EN // Maybe use default as enabled - yes, it will not be active if not available
#define CCAM_CNVEN_ON
#define CCAM_POSRST
#define X3X3_SENSDCM_HACT_ZERO
#define X3X3_SENSDCM_HACT_LATE90
#define X3X3_SENSDCM_HACT_EARLY90
#define X3X3_SENSDCM_INC
#define X3X3_SENSDCM_DEC
#define X3X3_SENSDCM_INC90
#define X3X3_SENSDCM_DEC90
#define COMPCMD_DEMOS(x) ((1<<13) | (((x) & 0x0f) << 9))
// 6 blocks output per macroblock:
#define DEMOS_MONO6 0 // original monochrome YCbCr 4:2:0 with zeroed color components
#define DEMOS_COLOR18 1 // original color YCbCr 4:2:0, 3x3 demosaic (18x18 tiles)
#define DEMOS_JP46 2 // original jp4, (4:2:0, zero color), decoded by regular JPEG decoder
#define DEMOS_JP46DC 3 // dc-improved: same as DEMOS_JP46, but DC difference separate for each component
#define DEMOS_COLOR20 4 // color YCbCr 4:2:0, 5x5 demosaic (20x20 tiles) - not yet implemented
// 4 blocks output per macroblock:
#define DEMOS_JP4 5 // similar to DEMOS_JP46 , but zero color components are not output
#define DEMOS_JP4DC 6 // similar to DEMOS_JP46DC , but zero color components are not output
#define DEMOS_JP4DIFF 7 // differential red := (R-G1), blue:=(B-G1), green=G1, green2 (G2-G1). G1 is defined by Bayer shift, any pixel can be used
#define DEMOS_JP4HDR 8 // similar to DEMOS_JP4DIFF, but second green (opposite from the reference one) is encoded without subtracting:
// red := (R-G1), blue:=(B-G1), green=G1, green2 (high gain)=G2) (G1 and G2 - diagonally opposite)
#define DEMOS_JP4DIFF2 9 // similar to DEMOS_JP4DIFF, but all differences are divided by 2 to fit into 8 bit range:
// red := (R-G1)/2, blue:=(B-G1)/2, green=G1, green2 (G2-G1)/2
#define DEMOS_JP4HDR2 10 // red := (R-G1)/2, blue:=(B-G1)/2, green=G1, green2 (high gain)=G2),
#define DEMOS_MONO4 14 // monochrome, but the block scan order is still the same as in YCbCr 4:2:0 (macroblocks in scan order, block in 2x2 macroblock in scan order)
// [8:7] == 0,1 - NOP, 2 - disable, 3 - enable subtracting of average value (DC component), bypassing DCT
#define COMPCMD_DCSUB(x) ((1<<8) | (((x) & 1) << 7))
// [6] == 1 - enable quantization bank select, 0 - disregard bits [5:3]
// [5:3] = quantization page number (0..7)
#define COMPCMD_QTAB(x) ((1<<6) | (((x) & 7) << 3))
#define CONFIG_ETRAX_ELPHEL_MT9X001 1
void x313_dma_stop(){}
void x313_dma_init(){}
void reset_compressor(){}
// X3X3_SEQ_SEND1(frame16, X313_WA_DCR0, X353_DCR0(SENSTRIGEN,async));
......@@ -115,7 +115,6 @@
#include "pgm_functions.h"
//#include "x3x3.h" // hardware definitions
#include "legacy_defines.h" // temporarily
#include "sensor_i2c.h"
/**
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -4,50 +4,68 @@
#include "sensor_i2c.h"
#define LEGACY_READ_PAGE 0xff
int init_pgm_proc(void); /// initialize array of functions that program different acquisition parameters (some are sensor dependent)
int add_sensor_proc(int index, int (*sens_func)(struct sensor_t * , struct framepars_t * , struct framepars_t *, int ));
//int pgm_detectsensor (struct sensor_t * sensor, struct framepars_t * thispars, struct framepars_t * prevpars, int frame8);
// Slave address is now 7-bit,old was 8-bit
// TODO: add registering single sensor as in multi10359. Registering twice is OK
#define X3X3_I2C_SEND2(p,a,s,r,d) write_xi2c_reg16_abs_asap(p,s,a,r,d)
/*
// Write sensor 16 bit (or 8 bit as programmed in the table) data in immediate mode
void write_xi2c_reg16_abs_asap (int chn, // sensor port
int page, // index in the table (8 bits)
int frame, // absolute frame number modulo PARS_FRAMES
int addr, // low byte of the register address (high is in the table), 8 bits
u32 data); //16 or 8-bit data (LSB aligned)
*/
int init_pgm_proc(void);
int add_sensor_proc(int index, int (*sens_func)(int sensor_port, struct sensor_t * , struct framepars_t * , struct framepars_t *, int ));
/** Perform I2C write (8 bits address, a6 bits data in "legacy" mode,
* pages matching slave address should be registered.
*
* TODO: Add registering single sensors as in multi10359. Registering twice is OK.
* Slave address is now 7-bit,old was 8-bit, change (10359 already done)
* @param port - sensor port
* @param frame Frame number to apply, <0 - ASAP
* @param sa7 I2C slave address, 7 bit
* @param reg sensor register address (8-bit)
* @param data value to set (16 bits) */
#define X3X3_I2C_SEND2(port,frame,sa7,reg,data) write_xi2c_reg16_abs_asap(port,sa7,frame,reg,data)
/** Tells if parameter is modifies
* @param x parameter index to test
* @return nonzero if modified */
#define FRAMEPAR_MODIFIED(x) (thispars->mod[(x) >> 5] & (1<<((x) & 0x1f)))
/** Adds new parameter/value pair to the modification queue
* @param p parameter index
* @param v parameter value(32 bits) */
#define SETFRAMEPARS_SET(p,v) { pars_to_update[nupdate ].num= (p) ; pars_to_update[nupdate++].val=(v);}
/** Puts current parameter value into the modification queue
* @param p parameter index (all high bits/attributes will be removed, only 12 LSBs preserved)*/
#define SETFRAMEPARS_UPDATE(p) { pars_to_update[nupdate ].num= (p) ; pars_to_update[nupdate++].val=thispars->pars[(p) & 0xffff];}
/** Puts new (or current) parameter value into the modification queue
* Uses specified value only if the current one is zero (not initialized already), otherwise updates with current
* @param p parameter index (all high bits/attributes will be removed, only 12 LSBs preserved)
* @param v parameter value(32 bits) */
#define SETFRAMEPARS_UPDATE_SET(p,v) { pars_to_update[nupdate ].num= (p) ; pars_to_update[nupdate++].val=thispars->pars[(p) & 0xffff]?thispars->pars[(p) & 0xffff]:(v);}
///Like SETFRAMEPARS_SET(p,v), but do nothing if not chnaged
#define SETFRAMEPARS_COND(p,v) { if (unlikely((v)!=thispars->pars[p])) { pars_to_update[nupdate ].num= (p) ; pars_to_update[nupdate++].val=(v);} }
/*
if (unlikely((thispars->pars[P_FLIPH] & sensor->flips & 1)!=thispars->pars[P_FLIPH])) { /// remove unsupoported flips
SETFRAMEPARS_SET(P_FLIPH, (thispars->pars[P_FLIPH] & sensor->flips & 1));
}
*/
///set parameter for the sensor register and hardware itself
/// f - fpga address, s - i2c slave address, r - sensor register, v - value to set
#define SET_SENSOR_PAR(p, f,s,r,v) { pars_to_update[nupdate ].num= P_SENSOR_REGS+(r) ;\
pars_to_update[nupdate++].val=(v);\
X3X3_I2C_SEND2((p),(f), (s), (r), (v)); \
}
/// same, but broadcast set for parameters with individual values. Updates individual ones (can use 4 elements in pars_to_update array, increase size where needed!)
/// relies that individual parameters are processed later, so it verifyis that broadcast does not modify individual if they are also modified and scheduled to be applied
/** Adds new parameter/value pair to the modification queue only if it is different from tghe current
* @param p parameter index (all high bits/attributes will be removed, only 12 LSBs preserved)
* @param v parameter value(32 bits) */
#define SETFRAMEPARS_COND(p,v) { if (unlikely((v)!=thispars->pars[(p) & 0xffff])) { pars_to_update[nupdate ].num= (p) ; pars_to_update[nupdate++].val=(v);} }
//#define SETFRAMEPARS_COND(p,v) { if (unlikely((v)!=thispars->pars[p])) { pars_to_update[nupdate ].num= (p) ; pars_to_update[nupdate++].val=(v);} }
/**Set parameter for the sensor register and send to hardware i2c sequencer
* @param port Sensor port number
* @param frame Frame number to apply, <0 - ASAP
* @param sa7 I2C slave address, 7 bit
* @param reg sensor register address (8-bit)
* @param data value to set (16 bits) */
#define SET_SENSOR_PAR(port,frame,sa7,reg,data) { pars_to_update[nupdate ].num= P_SENSOR_REGS+(reg) ;\
pars_to_update[nupdate++].val=(data);\
X3X3_I2C_SEND2((port),(frame), (sa7), (reg), (data)); \
}
/**Set parameter for the same register in multiple multiplexed sensors and send to hardware i2c sequencer
* Similar to SET_SENSOR_PAR, but broadcast set for parameters with individual values.
* Updates both "parent" parameter (used without multiplexer) and the individual ones
* (can use 4 elements in pars_to_update array, increase size where needed!).
* Relies on the fact that individual parameters are processed later, so it verifies that broadcast
* does not modify individual if they are also modified and scheduled to be applied.
* @param p Sensor port number
* @param f Frame number to apply, <0 - ASAP
* @param s I2C slave address, 7 bit
* @param r sensor register address (8-bit)
* @param v value to set (16 bits)
* @see SET_SENSOR_PAR */
#define SET_SENSOR_MBPAR(p,f,s,r,v) { pars_to_update[nupdate ].num= P_SENSOR_REGS+(r) ;\
pars_to_update[nupdate++].val=(v);\
X3X3_I2C_SEND2((p), (f), (s), (r), (v)); \
......@@ -72,7 +90,17 @@ void write_xi2c_reg16_abs_asap (int chn, // sensor port
} \
} \
}
/// same, but do not update the "parent" parameter, only the individual ones
/**Set parameter for the same register in multiple multiplexed sensors and send to hardware i2c sequencer
* Similar to SET_SENSOR_MBPAR, but it does not update "parent" parameter, only individual ones.
* (can use 4 elements in pars_to_update array, increase size where needed!).
* Relies on the fact that individual parameters are processed later, so it verifies that broadcast
* does not modify individual if they are also modified and scheduled to be applied.
* @param p Sensor port number
* @param f Frame number to apply, <0 - ASAP
* @param s I2C slave address, 7 bit
* @param r sensor register address (8-bit)
* @param v value to set (16 bits)
* @see SET_SENSOR_MBPAR */
#define SET_SENSOR_MBOPAR(p,f,s,r,v) { X3X3_I2C_SEND2((p), (f), (s), (r), (v)); \
int _MINDEX= MULTIREG(p,P_SENSOR_REGS+(r),0); \
EDBG(if (GLOBALPARS(G_DEBUG) & (1 <<4)) printk("%s:%d:%s _MINDEX=0x%x, v=0x%x, FRAMEPAR_MODIFIED(_MINDEX)=0x%x\n",__FILE__,__LINE__,__FUNCTION__, _MINDEX, (int) (v), (int) FRAMEPAR_MODIFIED(_MINDEX) ));\
......@@ -98,7 +126,15 @@ void write_xi2c_reg16_abs_asap (int chn, // sensor port
/// set individual sensor parameter, do nothing if no individual exists
/**Set individual (multiplexed) sensor parameter (and send to hardware i2c sequencer)
* Do nothing if there is no individual parameter reserved
* @param p Sensor port number
* @param f Frame number to apply, <0 - ASAP
* @param s I2C slave address, 7 bit
* @param i sensor index (1..3)
* @param r sensor register address (8-bit)
* @param v value to set (16 bits)
*/
#define SET_SENSOR_MIPAR(p,f,s,i,r,v) { int _MINDEX= MULTIREG(p,P_SENSOR_REGS+(r),(i)); \
if (_MINDEX) { \
pars_to_update[nupdate ].num= _MINDEX ;\
......@@ -106,7 +142,16 @@ void write_xi2c_reg16_abs_asap (int chn, // sensor port
X3X3_I2C_SEND2((p), (f), ( s )+( I2C359_INC * ( i )), ( r ), ( v )); \
} \
}
/// Same but only if different from the shadow
/**Set individual (multiplexed) sensor parameter if the new value is different from the shadow
* (and send to hardware i2c sequencer).
* Do nothing if there is no individual parameter reserved
* @param p Sensor port number
* @param f Frame number to apply, <0 - ASAP
* @param s I2C slave address, 7 bit
* @param i sensor index (1..3)
* @param r sensor register address (8-bit)
* @param v value to set (16 bits)
*/
#define SET_SENSOR_MIPAR_COND (p,f,s,i,r,v) \
{ int _MINDEX= MULTIREG(p,P_SENSOR_REGS+(r),(i)); \
if ((_MINDEX) && ((v) != thispars->pars[_MINDEX])) { \
......@@ -119,9 +164,14 @@ void write_xi2c_reg16_abs_asap (int chn, // sensor port
}
/// set individual sensor parameter, fall back to common parameter if no individual exists
/**Set individual (multiplexed) sensor parameter (and send to hardware i2c sequencer)
* Fall back to common parameter if no individual exists
* @param p Sensor port number
* @param f Frame number to apply, <0 - ASAP
* @param s I2C slave address, 7 bit
* @param i sensor index (1..3)
* @param r sensor register address (8-bit)
* @param v value to set (16 bits) */
#define SET_SENSOR_MIBPAR(p,f,s,i,r,v) { int _MINDEX= MULTIREG(p,P_SENSOR_REGS+(r),(i)); \
if (_MINDEX) { \
pars_to_update[nupdate ].num= _MINDEX ;\
......@@ -135,6 +185,16 @@ void write_xi2c_reg16_abs_asap (int chn, // sensor port
}
/// same, but only if different from the shadow
/**Set individual (multiplexed) sensor parameter (and send to hardware i2c sequencer)
* only if the new value is different from the current one.
* Fall back to common parameter if no individual exists
* @param p Sensor port number
* @param f Frame number to apply, <0 - ASAP
* @param s I2C slave address, 7 bit
* @param i sensor index (1..3)
* @param r sensor register address (8-bit)
* @param v value to set (16 bits)
* @see SET_SENSOR_MIBPAR */
#define SET_SENSOR_MIBPAR_COND(p,f,s,i,r,v) \
{ int _MINDEX= MULTIREG(p,P_SENSOR_REGS+(r),(i)); \
if (_MINDEX) { \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment