Commit 04de3c63 authored by Mikhail Karpenko's avatar Mikhail Karpenko

receive corrupted image

parent c96d81bb
......@@ -342,9 +342,9 @@ int circbuf_open(struct inode *inode, struct file *filp) { // set filesize
//! returns -2 if the rp is not 32-bytes aligned
//!sets *fpp to the frame header, including signature and length
void dump_interframe_params(struct interframe_params_t *params)
void dump_interframe_params(struct interframe_params_t *params, int offset)
{
dev_dbg(g_dev_ptr, "Dump of interframe parameters:\n");
dev_dbg(g_dev_ptr, "Dump of interframe parameters at offset 0x%x:\n", offset);
print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, params, sizeof(struct interframe_params_t));
}
......@@ -376,41 +376,23 @@ int circbufValidPointer(int rp, struct interframe_params_t ** fpp, unsigned int
struct interframe_params_t *fp;
if (rp & 0x1f) { //!rp is not 32-bytes aligned
//MD10(printk("circbufValidPointer: misaligned pointer\n"));
dev_dbg(g_dev_ptr, "misaligned pointer rp = 0x%x for channel %d\n", rp, chn);
return -2;
}
fp = (struct interframe_params_t *) &circbuf_priv[chn].buf_ptr[BYTE2DW(X393_BUFFSUB(rp, OFFSET_X40))];
fp = (struct interframe_params_t *) &circbuf_priv[chn].buf_ptr[BYTE2DW(X393_BUFFSUB(rp, sizeof(struct interframe_params_t)))];
*fpp = fp;
dump_interframe_params(fp);
dump_interframe_params(fp, X393_BUFFSUB(rp, sizeof(struct interframe_params_t)));
if (BYTE2DW(rp) == wp)
// frame not yet acquired (?)
// read pointer and write pointer coincide, frame not yet acquired
return 0;
dev_dbg(g_dev_ptr, "checking end of frame marker len32 = 0x%x at offset = 0x%x\n", fp->len32 & FRAME_LENGTH_MASK, rp);
/*if ((len32 & MARKER_FF) != MARKER_FF) {
wp -= CHUNK_SIZE;
len32 = get_image_length(DW2BYTE(wp), chn, &last_image_chunk);
if ((len32 & MARKER_FF) != MARKER_FF) {
dev_dbg(g_dev_ptr, "failed to get marker 0xFF at CORRECTED offset\n");
return -1;
}
}*/
if ((fp->len32 & MARKER_FF) != MARKER_FF) {
len32 = get_image_length(rp - CHUNK_SIZE, chn, &last_image_chunk);
if ((len32 & MARKER_FF) != MARKER_FF) {
dev_dbg(g_dev_ptr, "failed to get marker 0xFF at CORRECTED offset 0x%x\n", rp - CHUNK_SIZE);
return -1;
}
if (fp->signffff != MARKER_FFFF) {
dev_dbg(g_dev_ptr, "interframe signature is overwritten\n");
return -1;
}
// check timestamp
//sec = circbuf_priv[chn].buf_ptr[BYTE2DW(last_image_chunk + (CHUNK_SIZE - CCAM_MMAP_META_SEC))];
//usec = circbuf_priv[chn].buf_ptr[BYTE2DW(last_image_chunk +(CHUNK_SIZE - CCAM_MMAP_META_USEC))];
dev_dbg(g_dev_ptr, "reading time stamp: sec = 0x%x, usec = 0x%x\n", fp->timestamp_sec, fp->timestamp_usec);
return 1;
}
......@@ -419,7 +401,6 @@ loff_t circbuf_lseek(struct file * file, loff_t offset, int orig) {
int inserted_bytes;
int last_image_chunk;
int img_start, next_img, padded_frame;
const int ADJUSTMENT = 4; // this constant comes from python code x393_cmprs_afi.py
unsigned int minor = MINOR(file->f_inode->i_rdev);
unsigned int chn = minor_to_chn(minor);
// orig 0: position from begning
......@@ -477,7 +458,7 @@ loff_t circbuf_lseek(struct file * file, loff_t offset, int orig) {
break;
case LSEEK_CIRC_LAST:
next_img = camseq_get_jpeg_wp(chn) << 2;
fvld = circbufValidPointer(next_img, &fp, chn);
//fvld = circbufValidPointer(next_img, &fp, chn);
dev_dbg(g_dev_ptr, "LSEEK_CIRC_LAST: next_img = 0x%x, fvld = %d\n", next_img, fvld);
dev_dbg(g_dev_ptr, "mem dump of last 0x40 bytes in buffer number %d\n", chn);
......@@ -489,10 +470,12 @@ loff_t circbuf_lseek(struct file * file, loff_t offset, int orig) {
dev_dbg(g_dev_ptr, "failed to get marker 0xFF at 0x%x, len32: 0x%x\n", next_img, len32);
return -EOVERFLOW;
}
len32 &= 0xffffff;
inserted_bytes = ((CHUNK_SIZE - (((len32 % CHUNK_SIZE) + CCAM_MMAP_META) % CHUNK_SIZE) - ADJUSTMENT) % CHUNK_SIZE ) + ADJUSTMENT;
img_start = X393_BUFFSUB(last_image_chunk + CHUNK_SIZE - inserted_bytes - CCAM_MMAP_META, len32);
len32 &= FRAME_LENGTH_MASK;
//inserted_bytes = ((CHUNK_SIZE - (((len32 % CHUNK_SIZE) + CCAM_MMAP_META) % CHUNK_SIZE) - ADJUSTMENT) % CHUNK_SIZE ) + ADJUSTMENT;
img_start = X393_BUFFSUB(last_image_chunk + CHUNK_SIZE - INSERTED_BYTES(len32) - CCAM_MMAP_META, len32);
dev_dbg(g_dev_ptr, "calculated start address = 0x%x, length = 0x%x\n", img_start, len32);
if (circbufValidPointer(img_start, &fp, chn) < 0)
return -EOVERFLOW;
file->f_pos = img_start;
dev_dbg(g_dev_ptr, "LSEEK_CIRC_LAST: moving file->f_pos to 0x%llx\n", file->f_pos);
break;
......@@ -522,13 +505,11 @@ loff_t circbuf_lseek(struct file * file, loff_t offset, int orig) {
file->f_pos = img_start;
break;
case LSEEK_CIRC_NEXT:
dev_dbg(g_dev_ptr, "LSEEK_CIRC_NEXT: file->f_pos = 0x%x, fvld = %d, fp->len32 = 0x%x\n", file->f_pos >> 2, fvld, fp->len32);
dev_dbg(g_dev_ptr, "LSEEK_CIRC_NEXT: file->f_pos = 0x%x, fvld = %d, fp->len32 = 0x%x\n", file->f_pos, fvld, fp->frame_length);
if (fvld <= 0)
return -EOVERFLOW; //! no frames after current
// calculate the full length of current frame and advance file pointer by this value
len32 = fp->len32 & FRAME_LENGTH_MASK;
inserted_bytes = ((CHUNK_SIZE - (((len32 % CHUNK_SIZE) + CCAM_MMAP_META) % CHUNK_SIZE) - ADJUSTMENT) % CHUNK_SIZE ) + ADJUSTMENT;
padded_frame = len32 + inserted_bytes + CHUNK_SIZE + CCAM_MMAP_META;
padded_frame = fp->frame_length + INSERTED_BYTES(fp->frame_length) + CHUNK_SIZE + CCAM_MMAP_META;
file->f_pos = X393_BUFFADD(file->f_pos, padded_frame); // do it even if the next frame does not yet exist
dev_dbg(g_dev_ptr, "LSEEK_CIRC_NEXT: moving file->f_pos to 0x%x\n", file->f_pos);
break;
......
......@@ -368,7 +368,7 @@ loff_t jpeghead_lseek(struct file * file, loff_t offset, int orig,
fp = (struct interframe_params_t *) &ccam_dma_buf_ptr[X313_BUFFSUB(rp, 8)]; //! 32 bytes before the frame pointer, may roll-over to the end of ccam_dma_buf_ptr
*/
//if ((fp->signffff != 0xffff) || //! signature is overwritten
if ((fp->signff != 0xff) || //! signature is overwritten
if ((fp->signffff != MARKER_FFFF) || //! signature is overwritten
((fp->timestamp_sec) & X313_LENGTH_MASK)) return -EINVAL; //! acquisition of this frame is not done yet - length word high byte is non-zero
......
......@@ -283,14 +283,13 @@ inline void updateIRQFocus(struct jpeg_ptr_t *jptr)
u32 high_freq = x393_cmprs_hifreq(jptr->chn_num);
}
static void set_default_interframe(struct interframe_params_t *params)
inline static void set_default_interframe(struct interframe_params_t *params)
{
params->height = 1936;
params->width = 2592;
params->byrshift = 0;
params->byrshift = 3;
params->color = 0;
params->quality2 = 127;
dev_dbg(NULL, "%s: DEBUG, setting default interframe parameters\n", __func__);
params->quality2 = 100;
}
/**
......@@ -315,17 +314,19 @@ inline struct interframe_params_t* updateIRQ_interframe(struct jpeg_ptr_t *jptr)
//#endif
struct interframe_params_t *interframe;
int circbuf_size = BYTE2DW(get_globalParam(G_CIRCBUFSIZE));
int len_offset = X393_BUFFSUB(jptr->jpeg_wp, 8);
int len32 = circbuf_priv_ptr[jptr->chn_num].buf_ptr[len_offset] & FRAME_LENGTH_MASK;
int frame_params_offset = X393_BUFFSUB(jptr->jpeg_wp, OFFSET_X40);
int len_offset = X393_BUFFSUB(jptr->jpeg_wp, INTERFRAME_PARAMS_SZ + 1);
int jpeg_len = circbuf_priv_ptr[jptr->chn_num].buf_ptr[len_offset] & FRAME_LENGTH_MASK;
int jpeg_start = X393_BUFFSUB(DW2BYTE(jptr->jpeg_wp) - CHUNK_SIZE - INSERTED_BYTES(jpeg_len) - CCAM_MMAP_META, jpeg_len);
// frame_params_offset points to interframe_params_t area before current frame (this parameters belong to the frame below in memory, not the previous)
int frame_params_offset = BYTE2DW(X393_BUFFSUB(jpeg_start, CHUNK_SIZE));
interframe = (struct interframe_params_t *) &circbuf_priv_ptr[jptr->chn_num].buf_ptr[frame_params_offset];
//interframe->frame_length = len32;
interframe->frame_length = jpeg_len;
interframe->signffff = 0xffff;
set_default_interframe(interframe);
set_globalParam(G_FRAME_SIZE, len32);
set_globalParam(G_FRAME_SIZE, jpeg_len);
return interframe;
}
......
......@@ -18,6 +18,8 @@
#define MARKER_FF 0xff000000
#define MARKER_FFFF 0xffff
#define FRAME_LENGTH_MASK 0xffffff
#define IRQ_NOP 0
......@@ -28,6 +30,10 @@
#define BYTE2DW(x) ((x) >> 2)
#define DW2BYTE(x) ((x) << 2)
// 4 bytes offset, this one comes from python code x393_cmprs_afi.py
#define ADJUSTMENT 4
#define INSERTED_BYTES(x) (((CHUNK_SIZE - ((((x) % CHUNK_SIZE) + CCAM_MMAP_META) % CHUNK_SIZE) - ADJUSTMENT) % CHUNK_SIZE ) + ADJUSTMENT)
/* These macro were removed from sensor_common.h*/
#define X313_LENGTH_MASK 0xff000000
#define X393_BUFFSUB(x, y) (((x) >= (y)) ? ((x)-(y)) : ((x) + (CCAM_DMA_SIZE -(y))))
......
......@@ -1645,23 +1645,18 @@ struct sensorproc_t {
* Last three double words contain time stamp and (length+0xff) marker in new camera
*/
struct interframe_params_t {
unsigned long quality2;
unsigned long color;
unsigned long byrshift;
unsigned long width;
unsigned long height;
unsigned long pad0;
unsigned long pad1;
unsigned short quality2;
unsigned char color;
unsigned char byrshift;
unsigned short width;
unsigned short height;
unsigned short meta_index;
unsigned short signffff;
unsigned long timestamp_sec; //! number of seconds since 1970 till the start of the frame exposure
unsigned long timestamp_usec; //! number of microseconds to add
union {
unsigned long len32; //! should be 0xffxxyyzz - it will be a signature that JPEG data was not overwritten,
//! xxyyzz here is the length in 32 double words;
struct {
unsigned char pad0; // pad double word with 3 bytes and use only most significant byte as 0xff marker
unsigned char pad1;
unsigned char pad2;
unsigned char signff;
};
};
unsigned long frame_length; // frame length in bytes
};
struct i2c_timing_t {
......
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