Commit 11711b85 authored by Mikhail Karpenko's avatar Mikhail Karpenko

Add FPGA timer query using lseek

parent b1a63b79
...@@ -21,16 +21,16 @@ ...@@ -21,16 +21,16 @@
<builder id="org.eclipse.cdt.build.core.settings.default.builder.580164057" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="org.eclipse.cdt.build.core.settings.default.builder"/> <builder id="org.eclipse.cdt.build.core.settings.default.builder.580164057" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="org.eclipse.cdt.build.core.settings.default.builder"/>
<tool id="org.eclipse.cdt.build.core.settings.holder.libs.2129855326" name="holder for library settings" superClass="org.eclipse.cdt.build.core.settings.holder.libs"/> <tool id="org.eclipse.cdt.build.core.settings.holder.libs.2129855326" name="holder for library settings" superClass="org.eclipse.cdt.build.core.settings.holder.libs"/>
<tool id="org.eclipse.cdt.build.core.settings.holder.745731625" name="Assembly" superClass="org.eclipse.cdt.build.core.settings.holder"> <tool id="org.eclipse.cdt.build.core.settings.holder.745731625" name="Assembly" superClass="org.eclipse.cdt.build.core.settings.holder">
<option id="org.eclipse.cdt.build.core.settings.holder.incpaths.1859993711" name="Include Paths" superClass="org.eclipse.cdt.build.core.settings.holder.incpaths" valueType="includePath"/> <option id="org.eclipse.cdt.build.core.settings.holder.incpaths.1859993711" name="Include Paths" superClass="org.eclipse.cdt.build.core.settings.holder.incpaths"/>
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.58661368" languageId="org.eclipse.cdt.core.assembly" languageName="Assembly" sourceContentType="org.eclipse.cdt.core.asmSource" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/> <inputType id="org.eclipse.cdt.build.core.settings.holder.inType.58661368" languageId="org.eclipse.cdt.core.assembly" languageName="Assembly" sourceContentType="org.eclipse.cdt.core.asmSource" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
</tool> </tool>
<tool id="org.eclipse.cdt.build.core.settings.holder.1227611439" name="GNU C++" superClass="org.eclipse.cdt.build.core.settings.holder"> <tool id="org.eclipse.cdt.build.core.settings.holder.1227611439" name="GNU C++" superClass="org.eclipse.cdt.build.core.settings.holder">
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.1739426241" languageId="org.eclipse.cdt.core.g++" languageName="GNU C++" sourceContentType="org.eclipse.cdt.core.cxxSource,org.eclipse.cdt.core.cxxHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/> <inputType id="org.eclipse.cdt.build.core.settings.holder.inType.1739426241" languageId="org.eclipse.cdt.core.g++" languageName="GNU C++" sourceContentType="org.eclipse.cdt.core.cxxSource,org.eclipse.cdt.core.cxxHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
</tool> </tool>
<tool id="org.eclipse.cdt.build.core.settings.holder.176385540" name="GNU C" superClass="org.eclipse.cdt.build.core.settings.holder"> <tool id="org.eclipse.cdt.build.core.settings.holder.176385540" name="GNU C" superClass="org.eclipse.cdt.build.core.settings.holder">
<option id="org.eclipse.cdt.build.core.settings.holder.incpaths.1931881995" superClass="org.eclipse.cdt.build.core.settings.holder.incpaths" valueType="includePath"> <option id="org.eclipse.cdt.build.core.settings.holder.incpaths.1931881995" name="Include Paths" superClass="org.eclipse.cdt.build.core.settings.holder.incpaths" valueType="includePath">
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/linux-elphel/linux/source/include/elphel}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/linux-elphel/sysroots/elphel393/usr/include}&quot;"/> <listOptionValue builtIn="false" value="&quot;${workspace_loc:/linux-elphel/sysroots/elphel393/usr/include}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/linux-elphel/linux/source/include/elphel}&quot;"/>
</option> </option>
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.1408747788" languageId="org.eclipse.cdt.core.gcc" languageName="GNU C" sourceContentType="org.eclipse.cdt.core.cSource,org.eclipse.cdt.core.cHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/> <inputType id="org.eclipse.cdt.build.core.settings.holder.inType.1408747788" languageId="org.eclipse.cdt.core.gcc" languageName="GNU C" sourceContentType="org.eclipse.cdt.core.cSource,org.eclipse.cdt.core.cHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
</tool> </tool>
......
...@@ -2,9 +2,30 @@ ...@@ -2,9 +2,30 @@
PORT=2323 PORT=2323
echo file circbuf.c +pfl > /sys/kernel/debug/dynamic_debug/control if [ $1 == "nodebug" ]; then
echo file sensor_common.c +pfl > /sys/kernel/debug/dynamic_debug/control echo file circbuf.c -pfl > /sys/kernel/debug/dynamic_debug/control
echo file jpeghead.c +pfl > /sys/kernel/debug/dynamic_debug/control echo file sensor_common.c -pfl > /sys/kernel/debug/dynamic_debug/control
echo file jpeghead.c -pfl > /sys/kernel/debug/dynamic_debug/control
exit 0
elif [ $1 == "dump_state" ]; then
echo "func circbuf_valid_ptr +p" > /sys/kernel/debug/dynamic_debug/control
echo "func get_image_length +p" > /sys/kernel/debug/dynamic_debug/control
echo "func dump_interframe_params +p" > /sys/kernel/debug/dynamic_debug/control
echo "func dump_state +p" > /sys/kernel/debug/dynamic_debug/control
exit 0
elif [ $1 == "full_debug" ]; then
echo file circbuf.c +pfl > /sys/kernel/debug/dynamic_debug/control
echo file sensor_common.c +pfl > /sys/kernel/debug/dynamic_debug/control
echo file jpeghead.c +pfl > /sys/kernel/debug/dynamic_debug/control
exit 0
else
# default, turn off all
echo file circbuf.c -pfl > /sys/kernel/debug/dynamic_debug/control
echo file sensor_common.c -pfl > /sys/kernel/debug/dynamic_debug/control
echo file jpeghead.c -pfl > /sys/kernel/debug/dynamic_debug/control
fi
if [ ! -e /dev/circbuf0 ]; then if [ ! -e /dev/circbuf0 ]; then
mknod /dev/circbuf0 c 135 32 mknod /dev/circbuf0 c 135 32
......
...@@ -200,6 +200,7 @@ ...@@ -200,6 +200,7 @@
struct file_set { struct file_set {
unsigned short port_num; unsigned short port_num;
unsigned char sensor_num;
const char *cirbuf_fn; const char *cirbuf_fn;
int circbuf_fd; int circbuf_fd;
const char *jphead_fn; const char *jphead_fn;
...@@ -598,55 +599,55 @@ int metaXML(int fd_circ, int mode) /// mode: 0 - new (send headers), 1 - con ...@@ -598,55 +599,55 @@ int metaXML(int fd_circ, int mode) /// mode: 0 - new (send headers), 1 - con
frameParamPointer = jpeg_start - 32; frameParamPointer = jpeg_start - 32;
if (frameParamPointer < 0) frameParamPointer += buff_size; if (frameParamPointer < 0) frameParamPointer += buff_size;
memcpy(&frame_params, (unsigned long* )&ccam_dma_buf[frameParamPointer >> 2], 32); /// ccam_dma_buf - global memcpy(&frame_params, (unsigned long* )&ccam_dma_buf[frameParamPointer >> 2], 32); /// ccam_dma_buf - global
// jpeg_len=frame_params.frame_length; jpeg_len=frame_params.frame_length;
///// Copy timestamp (goes after the image data) /// Copy timestamp (goes after the image data)
// timestamp_start=jpeg_start+((jpeg_len+CCAM_MMAP_META+3) & (~0x1f)) + 32 - CCAM_MMAP_META_SEC; //! magic shift - should index first byte of the time stamp timestamp_start=jpeg_start+((jpeg_len+CCAM_MMAP_META+3) & (~0x1f)) + 32 - CCAM_MMAP_META_SEC; //! magic shift - should index first byte of the time stamp
// if (timestamp_start >= buff_size) timestamp_start-=buff_size; if (timestamp_start >= buff_size) timestamp_start-=buff_size;
// memcpy (&(frame_params.timestamp_sec), (unsigned long * ) &ccam_dma_buf[timestamp_start>>2],8); memcpy (&(frame_params.timestamp_sec), (unsigned long * ) &ccam_dma_buf[timestamp_start>>2],8);
/////TODO: Parse Exif data if available and add here ///TODO: Parse Exif data if available and add here
// printf ("<frame>\n" \ printf ("<frame>\n" \
// "<start> 0x%x </start>\n" \ "<start> 0x%x </start>\n" \
// "<hash32_r> 0x%x </hash32_r>\n" \ "<hash32_r> 0x%x </hash32_r>\n" \
// "<hash32_g> 0x%x </hash32_g>\n" \ "<hash32_g> 0x%x </hash32_g>\n" \
// "<hash32_gb>0x%x </hash32_gb>\n" \ "<hash32_gb>0x%x </hash32_gb>\n" \
// "<hash32_b> 0x%x </hash32_b>\n" \ "<hash32_b> 0x%x </hash32_b>\n" \
// "<quality2> 0x%x </quality2>\n" \ "<quality2> 0x%x </quality2>\n" \
// "<color> 0x%x </color>\n" \ "<color> 0x%x </color>\n" \
// "<byrshift> 0x%x </byrshift>\n" \ "<byrshift> 0x%x </byrshift>\n" \
// "<width> 0x%x </width>\n" \ "<width> 0x%x </width>\n" \
// "<height> 0x%x </height>\n" \ "<height> 0x%x </height>\n" \
// "<meta_index> 0x%x </meta_index>\n" \ "<meta_index> 0x%x </meta_index>\n" \
// "<timestamp> %ld.%06ld</timestamp>\n" \ "<timestamp> %ld.%06ld</timestamp>\n" \
// "<signffff> 0x%x </signffff>\n" "<signffff> 0x%x </signffff>\n"
// , (int) jpeg_start , (int) jpeg_start
// , (int) frame_params.hash32_r , (int) frame_params.hash32_r
// , (int) frame_params.hash32_g , (int) frame_params.hash32_g
// , (int) frame_params.hash32_gb , (int) frame_params.hash32_gb
// , (int) frame_params.hash32_b , (int) frame_params.hash32_b
// , (int) frame_params.quality2 , (int) frame_params.quality2
// , (int) frame_params.color /// color mode //18 , (int) frame_params.color /// color mode //18
// , (int) frame_params.byrshift /// bayer shift in compressor //19 , (int) frame_params.byrshift /// bayer shift in compressor //19
// , (int) frame_params.width /// frame width, pixels 20-21 - NOTE: should be 20-21 , (int) frame_params.width /// frame width, pixels 20-21 - NOTE: should be 20-21
// , (int) frame_params.height /// frame height, pixels 22-23 , (int) frame_params.height /// frame height, pixels 22-23
// , (int) frame_params.meta_index //! index of the linked meta page , (int) frame_params.meta_index //! index of the linked meta page
// , frame_params.timestamp_sec , frame_params.timestamp_sec
// , frame_params.timestamp_usec , frame_params.timestamp_usec
// , (int) frame_params.signffff , (int) frame_params.signffff
// ); );
/////28-31 unsigned long timestamp_sec ; //! number of seconds since 1970 till the start of the frame exposure ///28-31 unsigned long timestamp_sec ; //! number of seconds since 1970 till the start of the frame exposure
/////28-31 unsigned long frame_length ; //! JPEG frame length in circular buffer, bytes ///28-31 unsigned long frame_length ; //! JPEG frame length in circular buffer, bytes
///// }; /// };
/////32-35 unsigned long timestamp_usec; //! number of microseconds to add ///32-35 unsigned long timestamp_usec; //! number of microseconds to add
//
// if (frame_params.signffff !=0xffff) { if (frame_params.signffff !=0xffff) {
// printf("<error>\"wrong signature (should be 0xffff)\"</error>\n"); printf("<error>\"wrong signature (should be 0xffff)\"</error>\n");
// } else { } else {
/////Put Exif data here ///Put Exif data here
// printf ("<Exif>\n"); printf ("<Exif>\n");
// printExifXML(frame_params.meta_index); printExifXML(frame_params.meta_index);
// printf ("</Exif>\n"); printf ("</Exif>\n");
// } }
// printf ("</frame>\n"); printf ("</frame>\n");
return 0; return 0;
} }
...@@ -874,6 +875,7 @@ int sendImage(struct file_set *fset, int bufferImageData, int use_Exif, int sav ...@@ -874,6 +875,7 @@ int sendImage(struct file_set *fset, int bufferImageData, int use_Exif, int sav
color_mode = frame_params.color; color_mode = frame_params.color;
if (frame_params.signffff != 0xffff) { if (frame_params.signffff != 0xffff) {
fprintf(stderr, "wrong signature signff = 0x%x \n", (int)frame_params.signffff); fprintf(stderr, "wrong signature signff = 0x%x \n", (int)frame_params.signffff);
lseek(fset->circbuf_fd, LSEEK_CIRC_STOP_COMPRESSOR, SEEK_END);
close(fd_head); close(fd_head);
return -4; return -4;
} }
...@@ -976,6 +978,28 @@ int sendImage(struct file_set *fset, int bufferImageData, int use_Exif, int sav ...@@ -976,6 +978,28 @@ int sendImage(struct file_set *fset, int bufferImageData, int use_Exif, int sav
else printf("Content-Disposition: inline; filename=\"elphelimg_%ld.%s\"\r\n", frame_params.timestamp_sec, extension); /// opens in browser, asks to save on right-click else printf("Content-Disposition: inline; filename=\"elphelimg_%ld.%s\"\r\n", frame_params.timestamp_sec, extension); /// opens in browser, asks to save on right-click
if (bufferImageData) { /*! Buffer the whole file before sending over the network to make sure it will not be corrupted if the circular buffer will be overrun) */ if (bufferImageData) { /*! Buffer the whole file before sending over the network to make sure it will not be corrupted if the circular buffer will be overrun) */
// tell driver to flush CPU caches
const char *fname = "/sys/devices/soc0/elphel393-mem@0/flush_cpu_cache";
char cmd[128] = {0};
int jpeg_end;
int cmd_len;
// int fd_sys = open(fname, O_RDWR);
unsigned long start_time, end_time;
// if (fd_sys < 0) {
// fprintf(stderr, "unable to open sysfs entry: %s\n", fname);
// } else {
//// jpeg_end = jpeg_start + jpeg_len;
// jpeg_end = jpeg_start + (sizeof(struct interframe_params_t) - 4) * 512;
// if (jpeg_end > buff_size)
// jpeg_end -= buff_size;
// cmd_len = snprintf(cmd, 127, "%u:%d:%d", fset->sensor_num, jpeg_start, jpeg_end);
// if (write(fd_sys, cmd, cmd_len) == -1)
// fprintf(stderr, "failed to write to sysfs\n");
// close(fd_sys);
// }
start_time = lseek(fset->circbuf_fd, LSEEK_CIRC_UTIME, SEEK_END);
l = head_size + exifDataSize; l = head_size + exifDataSize;
/*! JPEG image data may be split in two segments (rolled over buffer end) - process both variants */ /*! JPEG image data may be split in two segments (rolled over buffer end) - process both variants */
if ((jpeg_start + jpeg_len) > buff_size) { // two segments if ((jpeg_start + jpeg_len) > buff_size) { // two segments
...@@ -985,6 +1009,9 @@ int sendImage(struct file_set *fset, int bufferImageData, int use_Exif, int sav ...@@ -985,6 +1009,9 @@ int sendImage(struct file_set *fset, int bufferImageData, int use_Exif, int sav
} else { /*! single segment */ } else { /*! single segment */
memcpy(&jpeg_copy[l], (unsigned long* )&ccam_dma_buf[jpeg_start >> 2], jpeg_len); memcpy(&jpeg_copy[l], (unsigned long* )&ccam_dma_buf[jpeg_start >> 2], jpeg_len);
} }
end_time = lseek(fset->circbuf_fd, LSEEK_CIRC_UTIME, SEEK_END);
fprintf(stderr, "memcpy time = %lu\n", end_time - start_time);
memcpy(&jpeg_copy[jpeg_len + head_size + exifDataSize], trailer, 2); memcpy(&jpeg_copy[jpeg_len + head_size + exifDataSize], trailer, 2);
printf("Content-Length: %d\r\n", jpeg_full_size); printf("Content-Length: %d\r\n", jpeg_full_size);
printf("\r\n"); printf("\r\n");
...@@ -1315,6 +1342,7 @@ void init_file_set(struct file_set *fset, int fset_sz) ...@@ -1315,6 +1342,7 @@ void init_file_set(struct file_set *fset, int fset_sz)
fset[i].jphead_fn = jhead_fnames[i]; fset[i].jphead_fn = jhead_fnames[i];
fset[i].jphead_fd = -1; fset[i].jphead_fd = -1;
fset[i].port_num = 0; fset[i].port_num = 0;
fset[i].sensor_num = i;
} }
} }
......
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