Commit 6f2d80e7 authored by Oleg Dzhimiev's avatar Oleg Dzhimiev

functions for membridge

parent cac8b2ff
......@@ -68,6 +68,167 @@ static struct elphel_video_buf_t buffer_settings = { ///< some default settings,
};
static int selected_channel = 0;
static int membridge_direction = 0; // 0 - from pl to ps, 1 - from ps to pl
/** Setup memory bridge system memory */
int setup_membridge_system_memory(
int lo_addr64, ///< start address of the system memory range in QWORDs (4 LSBs==0)
int size64, ///< size of the system memory range in QWORDs (4 LSBs==0), rolls over
int start64, ///< start of transfer offset to system memory range in QWORDs (4 LSBs==0)
int len64, ///< Full length of transfer in QWORDs
int width64) ///< Frame width in QWORDs (last xfer in each line may be partial)
{
// no need to wait for anything
x393_membridge_lo_addr64(lo_addr64);
x393_membridge_size64(size64);
x393_membridge_start64(start64);
x393_membridge_len64(len64);
x393_membridge_width64(width64);
return 0;
}
/** Setup memory bridge for a specified sensor channel */
int setup_membridge_memory(
int num_sensor, ///< sensor port number (0..3)
int window_width, ///< 13-bit - in 8*16=128 bit bursts
int window_height, ///< 16-bit window height (in scan lines)
int window_left, ///< 13-bit window left margin in 8-bursts (16 bytes)
int window_top, ///< 16-bit window top margin (in scan lines
int start_x, ///< START X ...
int start_y, ///< START Y ...
x393cmd_t x393cmd, ///< how to apply commands - directly or through channel sequencer
int frame16) ///< Frame number the command should be applied to (if not immediate mode)
///< @return 0 -OK
{
int frame_sa = buffer_settings.frame_start[num_sensor] >> (4 + 3) ;
int frame_full_width = buffer_settings.frame_full_width[num_sensor] >> 4;
int frame_sa_inc = frame_full_width * (buffer_settings.frame_height[num_sensor] >>3);
int last_frame_num = buffer_settings.frames_in_buffer[num_sensor] - 1;
x393_mcntrl_window_frame_sa_t window_frame_sa = {.d32=0};
x393_mcntrl_window_frame_sa_inc_t window_frame_sa_inc = {.d32=0};
x393_mcntrl_window_last_frame_num_t window_last_frame_num = {.d32=0};
x393_mcntrl_window_full_width_t window_full_width = {.d32=0};
x393_mcntrl_window_width_height_t window_width_height = {.d32=0};
x393_mcntrl_window_left_top_t window_left_top = {.d32=0};
x393_mcntrl_window_startx_starty_t window_startx_starty = {.d32=0};
window_frame_sa.frame_sa = frame_sa;
window_frame_sa_inc.frame_sa_inc = frame_sa_inc;
window_last_frame_num.last_frame_num = last_frame_num;
window_full_width.full_width = frame_full_width;
window_width_height.width = window_width;
window_width_height.height = window_height;
window_left_top.left = window_left;
window_left_top.top = window_top;
window_startx_starty.start_x = start_x;
window_startx_starty.start_y = start_y;
dev_dbg(g_dev_ptr,"{%d} setup_compressor_memory frame16=%d, command=%d\n",num_sensor,frame16, (int) x393cmd);
dev_dbg(g_dev_ptr,"sa=0x%08x sa_inc=0x%08x lfn=0x%08x fw=0x%08x wh=0x%08x lt=0x%08x sxy=0x%08x\n",
window_frame_sa.d32,window_frame_sa_inc.d32, window_last_frame_num.d32, window_full_width.d32,
window_width_height.d32,window_left_top.d32, window_startx_starty.d32);
MDP(DBGB_VM,num_sensor,"frame16=%d, command=%d\n", frame16, (int) x393cmd)
MDP(DBGB_VM,num_sensor,"sa=0x%08x sa_inc=0x%08x lfn=0x%08x fw=0x%08x wh=0x%08x lt=0x%08x sxy=0x%08x\n",
window_frame_sa.d32,window_frame_sa_inc.d32, window_last_frame_num, window_full_width.d32,
window_width_height.d32,window_left_top.d32, window_startx_starty.d32)
switch (x393cmd){
case ASAP:
frame16 = 0;
// no break
case RELATIVE:
/*
seqr_x393_membridge_scanline_startaddr (frame16, window_frame_sa, num_sensor); // Set frame start address
seqr_x393_membridge_scanline_frame_size (frame16, window_frame_sa_inc, num_sensor); // Set frame size (address increment)
seqr_x393_membridge_scanline_frame_last (frame16, window_last_frame_num, num_sensor); // Set last frame number (number of frames in buffer minus 1)
seqr_x393_membridge_scanline_frame_full_width(frame16, window_full_width, num_sensor); // Set frame full(padded) width
seqr_x393_membridge_scanline_window_wh (frame16, window_width_height, num_sensor); // Set frame window size
seqr_x393_membridge_scanline_window_x0y0 (frame16, window_left_top, num_sensor); // Set frame position
seqr_x393_membridge_scanline_startxy (frame16, window_startx_starty, num_sensor); // Set start x & y ...
*/
break;
case ABSOLUTE:
/*
seqa_x393_membridge_scanline_startaddr (frame16, window_frame_sa, num_sensor); // Set frame start address
seqa_x393_membridge_scanline_frame_size (frame16, window_frame_sa_inc, num_sensor); // Set frame size (address increment)
seqa_x393_membridge_scanline_frame_last (frame16, window_last_frame_num, num_sensor); // Set last frame number (number of frames in buffer minus 1)
seqa_x393_membridge_scanline_frame_full_width(frame16, window_full_width, num_sensor); // Set frame full(padded) width
seqa_x393_membridge_scanline_window_wh (frame16, window_width_height, num_sensor); // Set frame window size
seqa_x393_membridge_scanline_window_x0y0 (frame16, window_left_top, num_sensor); // Set frame position
seqa_x393_membridge_scanline_startxy (frame16, window_startx_starty, num_sensor); // Set start x & y ...
*/
break;
case DIRECT:
x393_membridge_scanline_startaddr (window_frame_sa, num_sensor); // Set frame start address
x393_membridge_scanline_frame_size (window_frame_sa_inc, num_sensor); // Set frame size (address increment)
x393_membridge_scanline_frame_last (window_last_frame_num, num_sensor); // Set last frame number (number of frames in buffer minus 1)
x393_membridge_scanline_frame_full_width (window_full_width, num_sensor); // Set frame full(padded) width
x393_membridge_scanline_window_wh (window_width_height, num_sensor); // Set frame window size
x393_membridge_scanline_window_x0y0 (window_left_top, num_sensor); // Set frame position
x393_membridge_scanline_startxy (window_startx_starty, num_sensor); // Set start x & y ...
break;
}
return 0;
}
/** Control membridge memory */
int control_membridge_memory (int num_sensor, ///< sensor port number (0..3)
int cmd, ///< command: 0 stop, 1 - single, 2 - repetitive, 3 - reset
int reset_frame, ///< reset addresses to the start of frame, reset buffer (1 of 4) pointer.
///< Should only be used if the channel controller was stopped before
x393cmd_t x393cmd, ///< how to apply commands - directly or through channel sequencer
int frame16) ///< Frame number the command should be applied to (if not immediate mode)
///< @return 0 -OK
{
x393_mcntrl_mode_scan_t membridge_mode = {.enable = 1, // [ 0] (1) enable requests from this channel ( 0 will let current to finish, but not raise want/need)
.chn_nreset = 1, // [ 1] (1) 0: immediately reset all the internal circuitry
.write_mem = 1, // [ 2] (0) 0 - read from memory, 1 - write to memory
.extra_pages = 0, // [ 4: 3] (0) 2-bit number of extra pages that need to stay (not to be overwritten) in the buffer
.keep_open = 0, // [ 5] (0) (NA in linescan) for 8 or less rows - do not close page between accesses (not used in scanline mode)
.byte32 = 0, // [ 6] (1) (NA in linescan) 32-byte columns (0 - 16-byte), not used in scanline mode
.reset_frame = 0, // [ 8] (0) reset frame number
.single = 0, // [ 9] (0) run single frame
.repetitive = 1, // [ 10] (1) run repetitive frames
.disable_need = 0, // [ 11] (0) disable 'need' generation, only 'want' (compressor channels)
.skip_too_late = 1, // [ 12] (0) Skip over missed blocks to preserve frame structure (increment pointers)
.abort_late = 1};// [ 14] (0) abort frame if not finished by the new frame sync (wait pending memory transfers)
x393_membridge_cmd_t membridge_cmd = {.enable = 0, // [ 0] (0) enable membridge
.start_reset = 0};// [ 2: 1] (0) 1 - start (from current address), 3 - start from reset address
membridge_mode.write_mem = membridge_direction;
//membridge_cmd.enable = 1;
//membridge_cmd.start_reset = 3;
switch (x393cmd){
case ASAP:
frame16 = 0;
// no break
case RELATIVE:
//seqr_x393_sens_mcntrl_scanline_mode (frame16, mcntrl_mode, num_sensor); // Set mode register (write last after other channel registers are set)
break;
case ABSOLUTE:
//seqa_x393_sens_mcntrl_scanline_mode (frame16, mcntrl_mode, num_sensor); // Set mode register (write last after other channel registers are set)
break;
case DIRECT:
// 1. wait until absolute frame number?
// 2. wait until copying is done? or not?
x393_membridge_ctrl(membridge_cmd,num_sensor); // Set mode register (write last after other channel registers are set)
//get_x393_membridge_status_cntrl();?!
x393_membridge_scanline_mode (mcntrl_mode, num_sensor); // Set mode register (write last after other channel registers are set)
break;
}
return 0;
}
/** Setup memory controller for a sensor channel */
int setup_sensor_memory (int num_sensor, ///< sensor port number (0..3)
......@@ -517,6 +678,8 @@ static int videomem_open(struct inode *inode, struct file *filp)
{
struct raw_priv_t *privData;
int test_channel=0;
pr_debug("VIDEOMEM_OPEN \n");
// Problem: pass channel number to the driver,
......@@ -540,47 +703,64 @@ static int videomem_open(struct inode *inode, struct file *filp)
privData->buf_size = pElphel_buf->raw_chn0_size*PAGE_SIZE;
privData->buf_size32 = (privData->buf_size)>>2;
// setup membridge
// setup membridge system memory - everything is in QW
setup_membridge_system_memory(
(privData->phys_addr)>>4,
(privData->buf_size)>>4,
0, // start offset?
2592>>4,
1936>>4
);
test_channel = 2;
//// get this frame number
//#define thisFrameNumber(p) GLOBALPARS(p,G_THIS_FRAME) // Current frame number (may lag from the hardware)
//#define thisCompressorFrameNumber(p) GLOBALPARS(p,G_COMPRESSOR_FRAME) // Current compressed frame number (lags from thisFrameNumber)
//// wait for certain frame number
// wait_event_interruptible(aframepars_wait_queue[sensor_port], getThisFrameNumber(sensor_port) >= target_frame);
//// get frame sizes
//unsigned long get_imageParamsPast(int sensor_port, int n, int frame);
/*
// FROM:
// from dts: frame_start_chn2 = <0x10000000>; // Channel 2 frame start (in bytes)
x393_membridge_scanline_startaddr(0x10000000);
//x393_membridge_scanline_startaddr(buffer_settings.frame_start[test_channel]);
// what units? Bytes?
x393_membridge_scanline_frame_size(privData->buf_size);
////x393_membridge_scanline_frame_size(privData->buf_size);
// number of frames in buffer - 1
x393_membridge_scanline_frame_last(1);
//x393_membridge_scanline_frame_last(buffer_settings.frames_in_buffer[test_channel]);
// Set frame full(padded) width - get from some parameter
x393_membridge_scanline_frame_full_width(2592);
////x393_membridge_scanline_frame_full_width(2592);
// set frame window size?!
// (window_height << 16)
x393_membridge_scanline_window_wh(1940<<16);
////x393_membridge_scanline_window_wh(1940<<16);
// Set startXY register
// (window_top << 16)
x393_membridge_scanline_window_x0y0(0<<16);
////x393_membridge_scanline_window_x0y0(0<<16);
x393_membridge_scanline_startxy(0);
////x393_membridge_scanline_startxy(0);
// TO:
// start address of the system memory range in QWORDs (4 LSBs==0)
x393_membridge_lo_addr64((privData->phys_addr)>>4);
///x393_membridge_lo_addr64((privData->phys_addr)>>4);
// size of the system memory range in QWORDs (4 LSBs==0), rolls over
x393_membridge_size64((privData->buf_size)>>4);
///x393_membridge_size64((privData->buf_size)>>4);
// start of transfer offset to system memory range in QWORDs (4 LSBs==0)
x393_membridge_start64(0);
///x393_membridge_start64(0);
// Full length of transfer in QWORDs
x393_membridge_len64((8192*PAGE_SIZE)>>4);
///x393_membridge_len64((8192*PAGE_SIZE)>>4);
// Frame width in QWORDs (last xfer in each line may be partial)
x393_membridge_width64(2592>>4);
///x393_membridge_width64(2592>>4);
// start?
x393_membridge_ctrl();
////x393_membridge_ctrl();
// wait until transfer is done
get_x393_membridge_status_cntrl();
*/
////get_x393_membridge_status_cntrl();
return 0;
}
......
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