00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <linux/kernel.h>
00024 #include <linux/sched.h>
00025 #include <linux/mm.h>
00026
00027 #include <linux/wait.h>
00028
00029 #include <asm/unistd.h>
00030 #include <asm/semaphore.h>
00031
00032 #include <asm/atomic.h>
00033
00034 #include <linux/module.h>
00035 #include <linux/slab.h>
00036 #include <linux/errno.h>
00037 #include <linux/fs.h>
00038 #include <linux/string.h>
00039 #include <linux/init.h>
00040 #include <linux/mm.h>
00041
00042
00043 #include <linux/vmalloc.h>
00044 #include <linux/rwsem.h>
00045
00046 #include <linux/netdevice.h>
00047 #include <linux/skbuff.h>
00048 #include <linux/time.h>
00049 #include <linux/wait.h>
00050 #include <asm/io.h>
00051 #include <asm/atomic.h>
00052 #include <asm/page.h>
00053
00054
00055 #include "fpgactrl.h"
00056
00057 #include <asm/elphel/c313a.h>
00058 #include <asm/elphel/hist.h>
00059 #include <asm/elphel/autoexp.h>
00060
00061 #include "cc3x3.h"
00062 #include "cxdma.h"
00063 #include "x3x3.h"
00064 #include "hist.h"
00065 #include "fpga_io.h"
00066
00067
00068
00069 #define STREAM_MAJOR 127
00070
00071 #if ELPHEL_DEBUG
00072 #define MD1(x) printk("%s:%d:",__FILE__,__LINE__);x
00073
00074 #else
00075 #define MD1(x)
00076 #endif
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086 DECLARE_MUTEX(stream_lock);
00087 static int stream__open(struct inode *inode, struct file *filp);
00088 static int stream__ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg);
00089 static int stream__release(struct inode *inode, struct file *filp);
00090
00091 static struct file_operations stream__fops = {
00092 owner: THIS_MODULE,
00093 open: stream__open,
00094 ioctl: stream__ioctl,
00095 release: stream__release,
00096 };
00097
00098 struct stream_ctx_t {
00099 int fps_flag;
00100 unsigned long p_fp100s;
00101 unsigned long p_fpslm;
00102 };
00103
00104 int stream__open(struct inode *inode, struct file *filp) {
00105 filp->private_data = NULL;
00106 if(down_trylock(&stream_lock)) {
00107
00108 return -EBUSY;
00109 }
00110
00111
00112 filp->private_data = (struct stream_ctx_t *)kmalloc(sizeof(struct stream_ctx_t), GFP_ATOMIC);
00113 struct stream_ctx_t *ctx = (struct stream_ctx_t *)filp->private_data;
00114 ctx->fps_flag = 0;
00115 return 0;
00116 }
00117
00118 static int stream__ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg) {
00119 unsigned char *qtable[128];
00120 struct stream_ctx_t *ctx = (struct stream_ctx_t *)filp->private_data;
00121 unsigned long get_time_rez[4];
00122 struct timeval sys_1, sys_2;
00123
00124 switch(_IOC_TYPE(cmd)) {
00125 case IOC_STREAM_SET_FPS:
00126 ctx->fps_flag = 1;
00127 ctx->p_fp100s = get_imageParamsR(P_FP100S);
00128 ctx->p_fpslm = get_imageParamsR(P_FPSLM);
00129 printk("P_FPSLM read == 0x%08lX\n", ctx->p_fpslm);
00130 ctx->p_fpslm = get_imageParamsW(P_FPSLM);
00131 printk("P_FPSLM write == 0x%08lX\n", ctx->p_fpslm);
00132 set_imageParamsW(P_FP100S, arg);
00133 set_imageParamsW(P_FPSLM, 0x03);
00134 set_imageParamsR(P_FP100S, arg);
00135 set_imageParamsR(P_FPSLM, 0x03);
00136 program_sensor_exposition_just();
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147 break;
00148 case IOC_STREAM_GET_QTABLES:
00149 jpeg_set_quality(_IOC_NR(cmd), QTABLES_TABLE, (void *)&qtable[0]);
00150 copy_to_user((void *)arg, (void *)&qtable[0], 128);
00151 break;
00152 case IOC_STREAM_GET_TIME:
00153 do_gettimeofday(&sys_1);
00154
00155 port_csp0_addr[X313_WA_RTC_LATCH] = 0xFF;
00156 get_time_rez[2] = port_csp0_addr[X313_RA_RTC_SEC];
00157 get_time_rez[3] = port_csp0_addr[X313_RA_RTC_USEC];
00158 do_gettimeofday(&sys_2);
00159 unsigned long delta;
00160 if(sys_2.tv_sec != sys_1.tv_sec)
00161 sys_2.tv_usec += 1000000;
00162 delta = sys_2.tv_usec - sys_1.tv_usec;
00163 sys_1.tv_usec += delta / 2;
00164 if(sys_1.tv_usec >= 1000000) {
00165 sys_1.tv_usec -= 1000000;
00166 sys_1.tv_sec -= 1;
00167 }
00168 get_time_rez[0] = sys_1.tv_sec;
00169 get_time_rez[1] = sys_1.tv_usec;
00170 copy_to_user((void *)arg, (void *)&get_time_rez[0], 4 * sizeof(unsigned long));
00171 break;
00172 }
00173 return 0;
00174 }
00175
00176 int stream__release(struct inode *inode, struct file *filp) {
00177 if(filp->private_data != NULL) {
00178 struct stream_ctx_t *ctx = (struct stream_ctx_t *)filp->private_data;
00179
00180 if(ctx->fps_flag) {
00181 set_imageParamsR(P_FP100S, ctx->p_fp100s);
00182 set_imageParamsR(P_FPSLM, ctx->p_fpslm);
00183 }
00184 kfree(filp->private_data);
00185 }
00186
00187 up(&stream_lock);
00188 return 0;
00189 }
00190
00191
00192
00193
00194
00195
00196
00197 static int __init stream__init(void) {
00198 int res = register_chrdev(STREAM_MAJOR, "stream", &stream__fops);
00199 return res;
00200 }
00201
00202 static void __exit stream__exit(void) {
00203 unregister_chrdev(STREAM_MAJOR, "stream");
00204 }
00205
00206 module_init(stream__init);
00207 module_exit(stream__exit);