Commit 567fd260 authored by Andrey Filippov's avatar Andrey Filippov
Browse files

merged with framepars, wrong FPS in triggered mode fixed

parents 5edb25c9 8e57db81
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -1226,7 +1226,7 @@ int mt9x001_pgm_limitfps (int sensor_port, ///< sensor port numb
    int row_time_in_pixels=0;
    int hor_blank_min;
    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 height;
    int virt_height;
@@ -1390,7 +1390,10 @@ int mt9x001_pgm_limitfps (int sensor_port, ///< sensor port numb
        SETFRAMEPARS_SET(P_PERIOD, pix_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
    sclk=thispars->pars[P_CLK_SENSOR] ; ///pixel clock, in Hz
#if USELONGLONG
+32 −7
Original line number Diff line number Diff line
@@ -1230,7 +1230,25 @@ int pgm_window_common (int sensor_port, ///< sensor port number (
    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.
 *  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
    int period=0;
    int pfh;
    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_fpga = thispars->pars[P_CLK_FPGA];
#if USELONGLONG
@@ -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
    // 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] < min_period) SETFRAMEPARS_SET(P_TRIG_PERIOD, min_period);  // set it (and propagate to the later frames)
        if (async &&  (thispars->pars[P_FPSFLAGS] & 2) && (thispars->pars[P_TRIG_PERIOD] > period)) {
            SETFRAMEPARS_SET(P_TRIG_PERIOD, period);  // set it (and propagate to the later frames)
            MDP(DBGB_PADD, sensor_port,"SETFRAMEPARS_SET(P_TRIG_PERIOD, 0x%x)\n", period)
        min_period_camsync = sensor_to_camsync(min_period, thispars->pars[P_CLK_SENSOR]);
        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)
        //        if (async &&  (thispars->pars[P_FPSFLAGS] & 2) && (thispars->pars[P_TRIG_PERIOD] > 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
+2 −0
Original line number Diff line number Diff line
@@ -28,6 +28,8 @@
void pgm_functions_set_device(struct device *dev);
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 ));
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
/// @param port - sensor port (0..3)
+14 −11
Original line number Diff line number Diff line
@@ -208,6 +208,18 @@
 */
// 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)
//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_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
@@ -267,15 +279,6 @@
#define SENSORWIDTH_IBIS51300  1280 ///< FillFactory IBIS51300 width
#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 SENSOR_RUN_STOP   0       ///< Sensor acquisition mode: STOP
  #define SENSOR_RUN_SINGLE 1       ///< Sensor acquisition mode: SINGLE FRAME
@@ -296,8 +299,8 @@

#define P_JPEG_WP       11 ///< Last reported JPEG write pointer in the circular buffer. ** OBSOLETE
                            // In new code use G_CIRCBUFWP instead!
#define P_CLK_FPGA      12 ///< FPGA clock in MHz
#define P_CLK_SENSOR    13 ///< Sensor clock in MHz
#define P_CLK_FPGA      12 ///< FPGA clock in Hz
#define P_CLK_SENSOR    13 ///< Sensor clock in Hz
#define P_FPGA_XTRA     14 ///< Extra cycles needed to compressor (probably constant...)
#define P_TRIG          15 /**< External trigger mode<ul>
<li>                     bit 0  - "old" external mode (0 - internal, 1 - external )