Commit 8e57db81 authored by Andrey Filippov's avatar Andrey Filippov

Separating time in pixels with camsync time (at 100MHz)

parent 01a8902c
...@@ -1226,7 +1226,7 @@ int mt9x001_pgm_limitfps (int sensor_port, ///< sensor port numb ...@@ -1226,7 +1226,7 @@ int mt9x001_pgm_limitfps (int sensor_port, ///< sensor port numb
int row_time_in_pixels=0; int row_time_in_pixels=0;
int hor_blank_min; int hor_blank_min;
int hor_blank=0; int hor_blank=0;
int p1,p2, pix_period, sclk,fp1000s; int p1,p2, pix_period, sclk,fp1000s, trig_period;
int styp = sensor->sensorType & 7; int styp = sensor->sensorType & 7;
int height; int height;
int virt_height; int virt_height;
...@@ -1390,7 +1390,10 @@ int mt9x001_pgm_limitfps (int sensor_port, ///< sensor port numb ...@@ -1390,7 +1390,10 @@ int mt9x001_pgm_limitfps (int sensor_port, ///< sensor port numb
SETFRAMEPARS_SET(P_PERIOD, pix_period); SETFRAMEPARS_SET(P_PERIOD, pix_period);
} }
// Update period from external trigger (assuming internal/self trigger, we do not know real external trigger period) // Update period from external trigger (assuming internal/self trigger, we do not know real external trigger period)
if ((thispars->pars[P_TRIG]!=0) && (thispars->pars[P_TRIG_PERIOD] > pix_period)) pix_period=thispars->pars[P_TRIG_PERIOD]; if (thispars->pars[P_TRIG]!=0){
trig_period = camsync_to_sensor(thispars->pars[P_TRIG_PERIOD], thispars->pars[P_CLK_SENSOR]);
if (trig_period > pix_period) pix_period=trig_period;
}
// schedule updating P_FP1000S if it changed // schedule updating P_FP1000S if it changed
sclk=thispars->pars[P_CLK_SENSOR] ; ///pixel clock, in Hz sclk=thispars->pars[P_CLK_SENSOR] ; ///pixel clock, in Hz
#if USELONGLONG #if USELONGLONG
......
...@@ -1230,7 +1230,25 @@ int pgm_window_common (int sensor_port, ///< sensor port number ( ...@@ -1230,7 +1230,25 @@ int pgm_window_common (int sensor_port, ///< sensor port number (
return 0; return 0;
} }
/** Convert time interval in camsync periods (10ns) to sensor pixel periods */
unsigned long camsync_to_sensor(unsigned long camsync_time, ///< time interval in camsync periods (@100MHz)
unsigned long sensor_clk) ///< sensor pixel clock in Hz
///< @return time interval in pixel clock periods
{
uint64_t ull_period = (((long long) sensor_clk) * ((long long) camsync_time));
do_div(ull_period, CAMSYNC_FREQ);
return (unsigned long) ull_period;
}
/** Convert time interval sesnor pixel periods to camsync periods (10ns)*/
unsigned long sensor_to_camsync(unsigned long pixel_time, ///< time interval in pixel clock periods
unsigned long sensor_clk) ///< sensor pixel clock in Hz
///< @return time interval in camsync periods (@100MHz)
{
uint64_t ull_period = (((long long) pixel_time) * ((long long) CAMSYNC_FREQ));
do_div(ull_period, sensor_clk);
return (unsigned long) ull_period;
}
/** Check if compressor can keep up, limit sensor FPS if needed. /** Check if compressor can keep up, limit sensor FPS if needed.
* Apply both user FPS limits (both low and high), prepare data for the sensor function and sequencer. * Apply both user FPS limits (both low and high), prepare data for the sensor function and sequencer.
...@@ -1255,6 +1273,8 @@ int pgm_limitfps (int sensor_port, ///< sensor port number (0..3 ...@@ -1255,6 +1273,8 @@ int pgm_limitfps (int sensor_port, ///< sensor port number (0..3
int period=0; int period=0;
int pfh; int pfh;
int n_stripes; int n_stripes;
int min_period_camsync, period_camsync;
//#define CAMSYNC_FREQ 100000000 ///< 100MHz - frequency used for external trigger periods and delays
u32 clk_sensor = thispars->pars[P_CLK_SENSOR]; u32 clk_sensor = thispars->pars[P_CLK_SENSOR];
u32 clk_fpga = thispars->pars[P_CLK_FPGA]; u32 clk_fpga = thispars->pars[P_CLK_FPGA];
#if USELONGLONG #if USELONGLONG
...@@ -1278,7 +1298,7 @@ int pgm_limitfps (int sensor_port, ///< sensor port number (0..3 ...@@ -1278,7 +1298,7 @@ int pgm_limitfps (int sensor_port, ///< sensor port number (0..3
default: default:
cycles*=4; cycles*=4;
} }
// cycles *=64 *2; //cycles per frame (64 pixels/block, 2 clock cycles/pixel) // cycles *=64 *2; //cycles per frame (64 pixels/block, 2 clock cycles/pixel)
cycles *=64; //cycles per frame (64 pixels/block, 1 clock cycles/pixel in NC393) cycles *=64; //cycles per frame (64 pixels/block, 1 clock cycles/pixel in NC393)
dev_dbg(g_dev_ptr,"{%d} cycles=%d(0x%x)\n",sensor_port,cycles,cycles); dev_dbg(g_dev_ptr,"{%d} cycles=%d(0x%x)\n",sensor_port,cycles,cycles);
MDP(DBGB_PADD, sensor_port,"cycles=%d(0x%x)\n",cycles,cycles) MDP(DBGB_PADD, sensor_port,"cycles=%d(0x%x)\n",cycles,cycles)
...@@ -1298,7 +1318,7 @@ int pgm_limitfps (int sensor_port, ///< sensor port number (0..3 ...@@ -1298,7 +1318,7 @@ int pgm_limitfps (int sensor_port, ///< sensor port number (0..3
__div64_32(&ull_min_period, clk_fpga); __div64_32(&ull_min_period, clk_fpga);
#else #else
do_div(ull_min_period, clk_fpga); do_div(ull_min_period, clk_fpga);
// ull_min_period/=thispars->pars[P_CLK_FPGA]; // ull_min_period/=thispars->pars[P_CLK_FPGA];
#endif #endif
min_period= ull_min_period; min_period= ull_min_period;
dev_dbg(g_dev_ptr,"{%d} min_period =%d(0x%x)\n", sensor_port, min_period, min_period); dev_dbg(g_dev_ptr,"{%d} min_period =%d(0x%x)\n", sensor_port, min_period, min_period);
...@@ -1329,7 +1349,7 @@ int pgm_limitfps (int sensor_port, ///< sensor port number (0..3 ...@@ -1329,7 +1349,7 @@ int pgm_limitfps (int sensor_port, ///< sensor port number (0..3
__div64_32(&ull_period, thispars->pars[P_FP1000SLIM]); __div64_32(&ull_period, thispars->pars[P_FP1000SLIM]);
#else #else
do_div(ull_period, thispars->pars[P_FP1000SLIM]); do_div(ull_period, thispars->pars[P_FP1000SLIM]);
// ull_period /= thispars->pars[P_FP1000SLIM]; // ull_period /= thispars->pars[P_FP1000SLIM];
#endif #endif
period= ull_period; period= ull_period;
dev_dbg(g_dev_ptr,"{%d} period =%d(0x%x)\n", sensor_port, period, period); dev_dbg(g_dev_ptr,"{%d} period =%d(0x%x)\n", sensor_port, period, period);
...@@ -1362,10 +1382,15 @@ int pgm_limitfps (int sensor_port, ///< sensor port number (0..3 ...@@ -1362,10 +1382,15 @@ int pgm_limitfps (int sensor_port, ///< sensor port number (0..3
// if (async && (thispars->pars[P_TRIG_PERIOD] !=1)) { // <256 - single trig, here only ==1 is for single // if (async && (thispars->pars[P_TRIG_PERIOD] !=1)) { // <256 - single trig, here only ==1 is for single
// Update period to comply even if it is not in async mode // Update period to comply even if it is not in async mode
if (thispars->pars[P_TRIG_PERIOD] !=1) { // <256 - single trig, here only ==1 is for single if (thispars->pars[P_TRIG_PERIOD] !=1) { // <256 - single trig, here only ==1 is for single
if (thispars->pars[P_TRIG_PERIOD] < min_period) SETFRAMEPARS_SET(P_TRIG_PERIOD, min_period); // set it (and propagate to the later frames) min_period_camsync = sensor_to_camsync(min_period, thispars->pars[P_CLK_SENSOR]);
if (async && (thispars->pars[P_FPSFLAGS] & 2) && (thispars->pars[P_TRIG_PERIOD] > period)) { if (thispars->pars[P_TRIG_PERIOD] < min_period_camsync) SETFRAMEPARS_SET(P_TRIG_PERIOD, min_period_camsync); // set it (and propagate to the later frames)
SETFRAMEPARS_SET(P_TRIG_PERIOD, period); // set it (and propagate to the later frames) // if (async && (thispars->pars[P_FPSFLAGS] & 2) && (thispars->pars[P_TRIG_PERIOD] > period)) {
MDP(DBGB_PADD, sensor_port,"SETFRAMEPARS_SET(P_TRIG_PERIOD, 0x%x)\n", period) if (async && (thispars->pars[P_FPSFLAGS] & 2)) {
period_camsync = sensor_to_camsync(period, thispars->pars[P_CLK_SENSOR]);
if (thispars->pars[P_TRIG_PERIOD] > period_camsync) {
SETFRAMEPARS_SET(P_TRIG_PERIOD, period_camsync); // set it (and propagate to the later frames)
MDP(DBGB_PADD, sensor_port,"SETFRAMEPARS_SET(P_TRIG_PERIOD, 0x%x)\n", period_camsync)
}
} }
} }
if (nupdate) setFramePars(sensor_port, thispars, nupdate, pars_to_update); // save changes, schedule functions if (nupdate) setFramePars(sensor_port, thispars, nupdate, pars_to_update); // save changes, schedule functions
......
...@@ -28,6 +28,8 @@ ...@@ -28,6 +28,8 @@
void pgm_functions_set_device(struct device *dev); void pgm_functions_set_device(struct device *dev);
int init_pgm_proc(int sensor_port); int init_pgm_proc(int sensor_port);
int add_sensor_proc(int port, int index, int (*sens_func)(int sensor_port, struct sensor_t * , struct framepars_t * , struct framepars_t *, int )); int add_sensor_proc(int port, int index, int (*sens_func)(int sensor_port, struct sensor_t * , struct framepars_t * , struct framepars_t *, int ));
unsigned long camsync_to_sensor(unsigned long camsync_time, unsigned long sensor_clk);
unsigned long sensor_to_camsync(unsigned long pixel_time, unsigned long sensor_clk);
/// Commands through sequencer: switch between ASAP (frame <0) and absolute /// Commands through sequencer: switch between ASAP (frame <0) and absolute
/// @param port - sensor port (0..3) /// @param port - sensor port (0..3)
......
...@@ -208,6 +208,18 @@ ...@@ -208,6 +208,18 @@
*/ */
// parameter indexes will be updated to group-related ones into the same groups of 32 // parameter indexes will be updated to group-related ones into the same groups of 32
// NOTE: P_* and G_* should not end with numbers - numbers will be used in PHP constants to add to the constant value (ELPHEL_AAA3 will be treated as ELPHEL_AAA+3) // NOTE: P_* and G_* should not end with numbers - numbers will be used in PHP constants to add to the constant value (ELPHEL_AAA3 will be treated as ELPHEL_AAA+3)
//TODO: Update CONST_NAME_ENTRY_* to new P_vars
/// 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 */
#define CAMSYNC_FREQ 100000000 ///< 100MHz - frequency used for external trigger periods and delays
#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
/* Notes for NC353:
* 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_NUMBER 1024 //number of registers (was 64) - NOTE: obsolete? #define P_NUMBER 1024 //number of registers (was 64) - NOTE: obsolete?
#define P_SENSOR 1 /**< if set to 0 - will (re)detect sensor, if set to None - won't bother <ul> #define P_SENSOR 1 /**< if set to 0 - will (re)detect sensor, if set to None - won't bother <ul>
<li> 4 - ZR32112MLC - now there is no way to see color/mono <li> 4 - ZR32112MLC - now there is no way to see color/mono
...@@ -267,15 +279,6 @@ ...@@ -267,15 +279,6 @@
#define SENSORWIDTH_IBIS51300 1280 ///< FillFactory IBIS51300 width #define SENSORWIDTH_IBIS51300 1280 ///< FillFactory IBIS51300 width
#define SENSORHEIGHT_IBIS51300 1024 ///< FillFactory IBIS51300 height #define SENSORHEIGHT_IBIS51300 1024 ///< FillFactory IBIS51300 height
//TODO: Update CONST_NAME_ENTRY_* to new P_vars
/// 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 */
#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
/* Notes for NC353:
* 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 ///< Sensor acquisition mode 0 - stop, 1 - single, 2 - run #define P_SENSOR_RUN 4 ///< Sensor acquisition mode 0 - stop, 1 - single, 2 - run
#define SENSOR_RUN_STOP 0 ///< Sensor acquisition mode: STOP #define SENSOR_RUN_STOP 0 ///< Sensor acquisition mode: STOP
#define SENSOR_RUN_SINGLE 1 ///< Sensor acquisition mode: SINGLE FRAME #define SENSOR_RUN_SINGLE 1 ///< Sensor acquisition mode: SINGLE FRAME
...@@ -296,8 +299,8 @@ ...@@ -296,8 +299,8 @@
#define P_JPEG_WP 11 ///< Last reported JPEG write pointer in the circular buffer. ** OBSOLETE #define P_JPEG_WP 11 ///< Last reported JPEG write pointer in the circular buffer. ** OBSOLETE
// In new code use G_CIRCBUFWP instead! // In new code use G_CIRCBUFWP instead!
#define P_CLK_FPGA 12 ///< FPGA clock in MHz #define P_CLK_FPGA 12 ///< FPGA clock in Hz
#define P_CLK_SENSOR 13 ///< Sensor clock in MHz #define P_CLK_SENSOR 13 ///< Sensor clock in Hz
#define P_FPGA_XTRA 14 ///< Extra cycles needed to compressor (probably constant...) #define P_FPGA_XTRA 14 ///< Extra cycles needed to compressor (probably constant...)
#define P_TRIG 15 /**< External trigger mode<ul> #define P_TRIG 15 /**< External trigger mode<ul>
<li> bit 0 - "old" external mode (0 - internal, 1 - external ) <li> bit 0 - "old" external mode (0 - internal, 1 - external )
......
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