os/linux-2.6-tag--devboard-R2_10-4/arch/cris/arch-v32/drivers/elphel/circbuf.c File Reference

#include <linux/module.h>
#include <linux/mm.h>
#include <linux/sched.h>
#include <linux/slab.h>
#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/string.h>
#include <linux/init.h>
#include <linux/autoconf.h>
#include <linux/time.h>
#include <asm/system.h>
#include <asm/arch/memmap.h>
#include <asm/io.h>
#include <asm/arch/dma.h>
#include <asm/arch/hwregs/dma_defs.h>
#include <asm/arch/hwregs/dma.h>
#include <asm/arch/hwregs/reg_map.h>
#include <asm/arch/hwregs/bif_dma_defs.h>
#include <asm/irq.h>
#include <asm/atomic.h>
#include <asm/delay.h>
#include <asm/uaccess.h>
#include <asm/elphel/c313a.h>
#include "fpgactrl.h"
#include "x3x3.h"
#include "cc3x3.h"
#include "cxdma.h"
#include "circbuf.h"
#include "exif.h"

Include dependency graph for circbuf.c:

Go to the source code of this file.

Data Structures

struct  circbuf_pd

Defines

#define MD12(x)
#define D(x)
#define D1(x)
#define MD1(x)
#define MD2(x)
#define MD5(x)
#define MD6(x)
#define MD7(x)
#define D0(x)
#define MD8(x)
#define MD9(x)
#define MD10(x)
#define MD11(x)
#define JPEG_HEADER_SIZE   0x26f
#define CIRCBUF_MAJOR   135
#define CIRCBUF_DRIVER_NAME   "Elphel (R) Model 353 video buffer device driver"

Functions

static unsigned long ccam_dma_buf[CCAM_DMA_SIZE+(PAGE_SIZE >>2)] __attribute__ ((aligned(PAGE_SIZE)))
void init_ccam_dma_buf_ptr (void)
 still used in autoexposure or something - why is in needed there?
int circbuf_all_open (struct inode *inode, struct file *filp)
int circbuf_all_release (struct inode *inode, struct file *filp)
loff_t circbuf_all_lseek (struct file *file, loff_t offset, int orig)
ssize_t circbuf_all_read (struct file *file, char *buf, size_t count, loff_t *off)
ssize_t circbuf_all_write (struct file *file, const char *buf, size_t count, loff_t *off)
int circbuf_all_mmap (struct file *file, struct vm_area_struct *vma)
unsigned int circbuf_all_poll (struct file *file, poll_table *wait)
int circbuf_all_ioctl (struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg)
 just to notify it is not implemented
int circbuf_open (struct inode *inode, struct file *filp)
int circbufValidPointer (int rp, struct frame_params_t **fpp)
loff_t circbuf_lseek (struct file *file, loff_t offset, int orig)
ssize_t circbuf_write (struct file *file, const char *buf, size_t count, loff_t *off)
ssize_t circbuf_read (struct file *file, char *buf, size_t count, loff_t *off)
int circbuf_mmap (struct file *file, struct vm_area_struct *vma)
unsigned int circbuf_poll (struct file *file, poll_table *wait)
int jpeghead_open (struct inode *inode, struct file *filp)
loff_t jpeghead_lseek (struct file *file, loff_t offset, int orig)
ssize_t jpeghead_read (struct file *file, char *buf, size_t count, loff_t *off)
ssize_t jpeghead_write (struct file *file, const char *buf, size_t count, loff_t *off)
static int __init circbuf_all_init (void)
 module_init (circbuf_all_init)
 MODULE_LICENSE ("GPLv3.0")
 MODULE_AUTHOR ("Andrey Filippov <andrey@elphel.com>.")
 MODULE_DESCRIPTION (CIRCBUF_DRIVER_NAME)

Variables

unsigned long * ccam_dma_buf_ptr = NULL
 Without "static" system hangs after "Uncompressing Linux...
unsigned long * ccam_dma = NULL
frame_params_t frame_params
wait_queue_head_t circbuf_wait_queue
static struct file_operations circbuf_fops


Define Documentation

#define CIRCBUF_DRIVER_NAME   "Elphel (R) Model 353 video buffer device driver"

Definition at line 179 of file circbuf.c.

Referenced by circbuf_all_init().

#define CIRCBUF_MAJOR   135

========================================================================================================= ! circbuf top level device drivers. Minors are the same as before ! CMOSCAM_MINOR_CIRCBUF, CMOSCAM_MINOR_JPEAGHEAD - just a new major ! ! ! ! ! ! !========================================================================================================

Definition at line 178 of file circbuf.c.

Referenced by circbuf_all_init().

#define D ( x   ) 

Definition at line 116 of file circbuf.c.

#define D0 ( x   ) 

Definition at line 131 of file circbuf.c.

#define D1 ( x   ) 

Definition at line 117 of file circbuf.c.

#define JPEG_HEADER_SIZE   0x26f

Definition at line 143 of file circbuf.c.

#define MD1 ( x   ) 

Definition at line 119 of file circbuf.c.

#define MD10 ( x   ) 

Definition at line 138 of file circbuf.c.

#define MD11 ( x   ) 

Definition at line 140 of file circbuf.c.

#define MD12 ( x   ) 

*************************************************************************** ! FILE NAME : circbuf.c ! DESCRIPTION: drivers to manipulate large circular buffer thet holds compressed ! images/video. Buffer frame data is filled in by the FPGA, frame pointers and ! essential frames metadata filled during servicing of the interruptsl ! This code is based on the code from cxdma.c ! ! Copyright (C) 2002-2007 Elphel, Inc ! -----------------------------------------------------------------------------** ! ! This program is free software: you can redistribute it and/or modify ! it under the terms of the GNU General Public License as published by ! the Free Software Foundation, either version 3 of the License, or ! (at your option) any later version. ! ! This program is distributed in the hope that it will be useful, ! but WITHOUT ANY WARRANTY; without even the implied warranty of ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! GNU General Public License for more details. ! ! You should have received a copy of the GNU General Public License ! along with this program. If not, see <http://www.gnu.org/licenses/>. ! -----------------------------------------------------------------------------** !

Log
circbuf.c,v
! Revision 1.10 2008/04/11 23:16:51 elphel ! removed unneeded local_irq_disable() after local_irq_save_flags() ! ! Revision 1.8 2007/12/03 08:28:46 elphel ! Multiple changes, mostly cleanup ! ! Revision 1.7 2007/11/16 08:56:19 elphel ! Added support for 2 additional commands to check circbuf usage ! ! Revision 1.6 2007/11/05 06:08:25 elphel ! fixed "first/second" bug introduced while fixing the previous one ! ! Revision 1.5 2007/11/05 01:40:51 elphel ! fixed wrong count of frames available, "second" frame ! ! Revision 1.4 2007/11/04 05:46:06 elphel ! removed debug, rearranged code to avoid a warning ! ! Revision 1.3 2007/11/01 18:59:37 elphel ! debugging mmap/caching problems ! ! Revision 1.2 2007/10/27 00:55:32 elphel ! untested revision - need to go ! ! Revision 1.1.1.1 2007/10/02 23:54:58 elphel ! This is a fresh tree based on elphel353-2.10 ! ! Revision 1.6 2007/10/02 23:54:58 elphel ! CIRCLSEEK_LAST will now return just write pointer, not an error if there are no frames yet available. Moving to previous will still generate error. ! ! Revision 1.5 2007/10/02 22:29:38 elphel ! made that only 0,SEEK_END can move beyond circbuf, fro SEEK_CUR and SEET_SET it will roll over to 0 ! ! Revision 1.4 2007/10/02 19:35:15 elphel ! minor circbuf interface changes, bug fixes ! ! Revision 1.3 2007/09/30 07:07:08 elphel ! minor bug fix, disabled debug output ! ! Revision 1.2 2007/09/30 03:19:56 elphel ! Cleanup, fixed broken acquisition of individual JPEG images into circbuf (in mode 7) ! ! Revision 1.1 2007/09/29 18:33:29 elphel ! Split cxdma.c - /dev/circbuf is now in a separate circbuf.c file. New device driver does not support ioctl, so some curernt applications are updated to use other drivers to control the camera !

Definition at line 115 of file circbuf.c.

#define MD2 ( x   ) 

Definition at line 121 of file circbuf.c.

#define MD5 ( x   ) 

Definition at line 124 of file circbuf.c.

Referenced by x313_JPEG_cmd().

#define MD6 ( x   ) 

Definition at line 126 of file circbuf.c.

#define MD7 ( x   ) 

Definition at line 128 of file circbuf.c.

#define MD8 ( x   ) 

Definition at line 134 of file circbuf.c.

#define MD9 ( x   ) 

Definition at line 136 of file circbuf.c.


Function Documentation

static unsigned long ccam_dma_buf [CCAM_DMA_SIZE + (PAGE_SIZE>>2)] __attribute__ ( (aligned(PAGE_SIZE))   )  [static]

static int __init circbuf_all_init ( void   )  [static]

Definition at line 735 of file circbuf.c.

References CIRCBUF_DRIVER_NAME, CIRCBUF_MAJOR, init_waitqueue_head, KERN_ERR, and printk.

int circbuf_all_ioctl ( struct inode *  inode,
struct file *  filp,
unsigned int  cmd,
unsigned long  arg 
)

just to notify it is not implemented

Definition at line 295 of file circbuf.c.

References circbuf_pd::minor, and printk.

loff_t circbuf_all_lseek ( struct file *  file,
loff_t  offset,
int  orig 
)

Definition at line 241 of file circbuf.c.

References circbuf_lseek(), CMOSCAM_MINOR_CIRCBUF, CMOSCAM_MINOR_JPEAGHEAD, jpeghead_lseek(), MD10, circbuf_pd::minor, and printk.

int circbuf_all_mmap ( struct file *  file,
struct vm_area_struct *  vma 
)

Definition at line 274 of file circbuf.c.

References circbuf_mmap(), CMOSCAM_MINOR_CIRCBUF, MD10, circbuf_pd::minor, and printk.

int circbuf_all_open ( struct inode *  inode,
struct file *  filp 
)

Definition at line 202 of file circbuf.c.

References circbuf_open(), CMOSCAM_MINOR_CIRCBUF, CMOSCAM_MINOR_JPEAGHEAD, GFP_KERNEL, jpeghead_open(), kfree, kmalloc, MD10, circbuf_pd::minor, and printk.

unsigned int circbuf_all_poll ( struct file *  file,
poll_table *  wait 
)

Definition at line 284 of file circbuf.c.

References circbuf_poll(), CMOSCAM_MINOR_CIRCBUF, MD10, circbuf_pd::minor, and printk.

ssize_t circbuf_all_read ( struct file *  file,
char *  buf,
size_t  count,
loff_t *  off 
)

Definition at line 252 of file circbuf.c.

References circbuf_read(), CMOSCAM_MINOR_CIRCBUF, CMOSCAM_MINOR_JPEAGHEAD, jpeghead_read(), MD10, circbuf_pd::minor, and printk.

int circbuf_all_release ( struct inode *  inode,
struct file *  filp 
)

Definition at line 223 of file circbuf.c.

References CMOSCAM_MINOR_CIRCBUF, CMOSCAM_MINOR_JPEAGHEAD, kfree, MD10, and printk.

ssize_t circbuf_all_write ( struct file *  file,
const char *  buf,
size_t  count,
loff_t *  off 
)

Definition at line 262 of file circbuf.c.

References circbuf_write(), CMOSCAM_MINOR_CIRCBUF, CMOSCAM_MINOR_JPEAGHEAD, jpeghead_write(), MD10, circbuf_pd::minor, and printk.

loff_t circbuf_lseek ( struct file *  file,
loff_t  offset,
int  orig 
)

Definition at line 386 of file circbuf.c.

References camSeqGetJPEG_rp(), camSeqGetJPEG_wp(), camSeqSetJPEG_rp(), ccam_dma_buf, CCAM_DMA_SIZE, circbufValidPointer(), CIRCLSEEK_FIRST, CIRCLSEEK_FREE, CIRCLSEEK_LAST, CIRCLSEEK_NEXT, CIRCLSEEK_PREV, CIRCLSEEK_READY, CIRCLSEEK_SCND, CIRCLSEEK_SETP, CIRCLSEEK_TORP, CIRCLSEEK_TOWP, CIRCLSEEK_USED, CIRCLSEEK_VALID, CIRCLSEEK_WAIT, MD11, MD12, printk, rp, frame_params_t::timestamp_sec, X313_BUFFADD, X313_BUFFSUB, X313_LENGTH_MASK, and X313_PADDED_FRAME.

Referenced by circbuf_all_lseek(), and circbuf_open().

int circbuf_mmap ( struct file *  file,
struct vm_area_struct *  vma 
)

Definition at line 573 of file circbuf.c.

References ccam_dma_buf, MD7, and printk.

Referenced by circbuf_all_mmap().

int circbuf_open ( struct inode *  inode,
struct file *  filp 
)

Definition at line 305 of file circbuf.c.

References CCAM_DMA_SIZE, circbuf_lseek(), CIRCLSEEK_LAST, MD10, and printk.

Referenced by circbuf_all_open().

unsigned int circbuf_poll ( struct file *  file,
poll_table *  wait 
)

=========================================================================== ! If the current read pointer is invalid, circbuf_poll returns POLLHUP ! as no data will be ever available until file poinetr is reset. ! if it is valid, wait is setup and the blocking condition occurs ! ifthe current file pointer is equal to the FPGA write pointer !===========================================================================

result of testing read poinetr

not a valid read pointer, probable buffer overrun

there was frame already available

pointer valid, no frame yet

Frame might become available during call to poll_wait so nobody will wake us up. Let's see if there is stillno frame

we are lucky - got it

Definition at line 602 of file circbuf.c.

References camSeqGetJPEG_wp(), circbufValidPointer(), MD10, and printk.

Referenced by circbuf_all_poll().

ssize_t circbuf_read ( struct file *  file,
char *  buf,
size_t  count,
loff_t *  off 
)

Definition at line 556 of file circbuf.c.

References ccam_dma_buf, CCAM_DMA_SIZE, D, and printk.

Referenced by circbuf_all_read().

ssize_t circbuf_write ( struct file *  file,
const char *  buf,
size_t  count,
loff_t *  off 
)

Definition at line 536 of file circbuf.c.

References ccam_dma_buf, CCAM_DMA_SIZE, D, and printk.

Referenced by circbuf_all_write().

int circbufValidPointer ( int  rp,
struct frame_params_t **  fpp 
)

returns 0 if rp is a valid read ponter returns 1 if there is a frame at this address returns 0 if the pointer is for the frame yet to be acquired returns -1 if there is no frame at this index returns -2 if the rp is not 32-bytes aligned sets *fpp to the frame header, including signature and length

rp is not 32-bytes aligned

32 bytes before the frame pointer, may roll-over to the end of ccam_dma_buf

signature is overwritten

should not get here - should be caught by (p==wp)

Definition at line 360 of file circbuf.c.

References camSeqGetJPEG_wp(), ccam_dma_buf, dumpFrameParams(), MD10, MD11, printk, wp, X313_BUFFSUB, and X313_LENGTH_MASK.

Referenced by circbuf_lseek(), and circbuf_poll().

void init_ccam_dma_buf_ptr ( void   ) 

still used in autoexposure or something - why is in needed there?

Definition at line 159 of file circbuf.c.

References ccam_dma_buf.

Referenced by cmoscam_init().

loff_t jpeghead_lseek ( struct file *  file,
loff_t  offset,
int  orig 
)

================================================================= ! Overloading lseek with additional functionality (to avoid ioctls) ! with orig==SEEK_END lseek will treat (offset>0) as a byte pointer ! in (char *)ccam_dma_buf of a frame pointer and use quality, ! width and height to regenerate header. ! frame pointers are 32-bytes aligned, so adding 1 to offest ! will make sure it is always >0 (as offset=0, orig=SEEK_END ! will just move pointer to the end and return file length. ! ! When called with orig==SEEK_END, offset>0 lseek will position ! file at the very beginning and return 0 if OK, -EINVAL if ! frame header is not found for the specified offset !================================================================

New functionality

32 bytes before the frame pointer, may roll-over to the end of ccam_dma_buf

signature is overwritten

acquisition of this frame is not done yet - length word high byte is non-zero

it is 0

Definition at line 650 of file circbuf.c.

References ccam_dma_buf, frame_params_t::height, JPEG_HEADER_SIZE, frame_params_t::quality, rp, setJPEGHeader(), frame_params_t::signffff, frame_params_t::timestamp_sec, frame_params_t::width, X313_BUFFSUB, and X313_LENGTH_MASK.

Referenced by circbuf_all_lseek().

int jpeghead_open ( struct inode *  inode,
struct file *  filp 
)

make it blocking to use shared resource - jpeg header that may need re-calculation for different requests? or use individual header arrays?

Definition at line 629 of file circbuf.c.

References JPEG_HEADER_SIZE.

Referenced by circbuf_all_open().

ssize_t jpeghead_read ( struct file *  file,
char *  buf,
size_t  count,
loff_t *  off 
)

Definition at line 697 of file circbuf.c.

References D, jpeg_header_sbuffer_ptr, JPEG_HEADER_SIZE, and printk.

Referenced by circbuf_all_read().

ssize_t jpeghead_write ( struct file *  file,
const char *  buf,
size_t  count,
loff_t *  off 
)

Definition at line 717 of file circbuf.c.

References D, jpeg_header_sbuffer_ptr, JPEG_HEADER_SIZE, and printk.

Referenced by circbuf_all_write().

MODULE_AUTHOR ( "Andrey Filippov <andrey@elphel.com>."   ) 

MODULE_DESCRIPTION ( CIRCBUF_DRIVER_NAME   ) 

module_init ( circbuf_all_init   ) 

MODULE_LICENSE ( "GPLv3.0"   ) 


Variable Documentation

unsigned long* ccam_dma = NULL

Definition at line 158 of file circbuf.c.

Referenced by get_image_time().

unsigned long* ccam_dma_buf_ptr = NULL

Without "static" system hangs after "Uncompressing Linux...

Definition at line 157 of file circbuf.c.

Referenced by add_frame_params(), ext_fill_jpeg_mmap_desc_(), flush_par_cache(), x313_dma_forget_jpeg(), x313_dma_init(), x313_dma_reset_chain(), x313_DMA_size(), x313_dma_start(), X313_dma_update(), x313_JPEG_dump(), and x313_setDMABuffer().

struct file_operations circbuf_fops [static]

Initial value:

Definition at line 180 of file circbuf.c.

wait_queue_head_t circbuf_wait_queue

====================================================================================== ! Wait queue for the processes waiting for a new frame to appear in the circular buffer !======================================================================================

Definition at line 167 of file circbuf.c.

Referenced by add_frame_params().

struct frame_params_t frame_params

Definition at line 716 of file cc353.c.


Generated on Thu Aug 7 16:20:09 2008 for elphel by  doxygen 1.5.1