Beispiel #1
3
int w99685_v4l1_ioctl(w685cf_t *priv, unsigned int cmd, void * buf)
{
	
	int err = 0;
	CmdParameters_t *paramsp = NULL;
	CmdReturns_t *retsp = NULL;
	Firmware_t ifirmware;
	UINT8 *datap;
	int i;
#ifdef 	W865THREAD
	int whichselect;
	ImageContainer_t *containerp = priv->images;
#endif

	if (down_interruptible2(&priv->lock)) {
		printk("Device has been locked\n");
		err = -EINTR;
		goto out;
	} 
	
	
	
	//printk("Cmd: %x, getclass: %x, IOCTLSETFW_CAMERA = %x\n", cmd, IOCTLGETCLASS,IOCTLSETFW_CAMERA);
	if(cmd == IOCTLGETCLASS)
	{
		if(!buf) {
			printk("Illegal buffer address\n");
			err = -EINVAL;
			goto outup;
		}	
		
		if(copy_to_user(buf, DEVICECLALSS, (strlen(DEVICECLALSS)+1)))
		{
			printk("Cannot put data to user\n");
			err = -EFAULT;
		}
		err = (strlen(DEVICECLALSS)+1);
		printk("Get Class name: %s\n", DEVICECLALSS);
		goto outup;
	}
	else if(cmd == IOCTLGETSTATUS)
	{
		if(!buf) {
			printk("Illegal buffer address\n");
			err = -EINVAL;
			goto outup;
		}	
		
		if(copy_to_user(buf, (char *)&(FREG7), sizeof(FREG7)))
		{
			printk("Cannot put data to user\n");
			err = -EFAULT;
		}
		goto outup;
	}
	else if(cmd == IOCTLSETFW_CAMERA)
	{
		diag_printf("IOCTLSETFW_CAMERA = %x\n",IOCTLSETFW_CAMERA);
		if(copy_from_user(&ifirmware, (void *)buf, sizeof(Firmware_t))) {
			printk("Cannot copy data from user\n");
			err = -EFAULT;
 			goto outup;
		}
		printk("Firmware size: %d, %x\n", ifirmware.Length, ifirmware.Data);
		
		datap = (UINT8 *)malloc(ifirmware.Length*sizeof(UINT8));
		diag_printf("datap %p\n",datap);
		if(!datap)
		{
			printk("No enough memory\n");
			err = -ENOMEM;
 			goto outup;
		}
		if(copy_from_user(datap, (void *)ifirmware.Data, ifirmware.Length*sizeof(UINT8))) {
			printk("Cannot copy data from user\n");
			free(datap);
			err = -EFAULT;
 			goto outup;
		}
		InitCFI(0);
		DownLoadFirmware2Camera(datap, ifirmware.Length);
		free(datap);
		for(i=0;i<100;i++)
			wait_ms(20);
		
		printk("DownLoad Firmware ok\n");
		InitCFI(0);
		wait_ms(40);
		//CardDection();
		//W99685CMD_Suspand();
		//wait_ms(40);	
#if 1//ndef __OUTPUT2TV__
		W99685CMD_SetOpMode(OP_SINGLE, PPC_YUV422, 0);

		W99685CMD_SetLCMNums(LCD1_ON_685,LCD_BUS_16);
		//KDEBUG("Have set LCMNUMS");
		W99685CMD_SelectLCM(LCM_1ST);
		//KDEBUG("Have selected LCM\n");
		W99685CMD_SetLCMRes(128, 161);
		//KDEBUG("Have set LCM resolution\n");

		LCM_FillChar(lcm_buf, LEN_LCMBF);
		//wait_ms(100000);
		//memset(lcm_buf, 0xff, LEN_LCMBF);
		//LCM_FillChar(lcm_buf, LEN_LCMBF);
		//KDEBUG("Have Filled LCM with char\n");

		W99685CMD_SetLCMWndPos(0, 32);

		W99685CMD_SetLCMWndSize(128, 96);
#endif
		goto outup;
	}
	else if(cmd == IOCTLSETFW_USBBRIDGE)
	{
		DownLoadFirmware2Camera(W685BRIDGEFW, sizeof(W685BRIDGEFW));
		printk("Have DownLoad Bridge Firmware to W99685\n");
		goto outup;
	}
	else if(cmd == IOCTLDRAWINBYPASS) 
	{
#if 1
		if(copy_from_user(&ifirmware, (void *)buf, sizeof(Firmware_t))) {
			diag_printf("Cannot copy data from user\n");
			err = -EFAULT;
 			goto outup;
		}
		printk("Image size: %d\n", ifirmware.Length);
		
		datap = (UINT8 *)malloc(ifirmware.Length*sizeof(UINT8));
		if(!datap)
		{
			printk("No enough memory\n");
			err = -ENOMEM;
 			goto outup;
		}
		if(copy_from_user(datap, (void *)ifirmware.Data, ifirmware.Length*sizeof(UINT8))) {
			printk("Cannot copy data from user\n");
			free(datap);
			err = -EFAULT;
 			goto outup;
		}
		InitCFI(1);
		wait_ms(20);
		DrawInByPassMode(datap, ifirmware.Length);
		InitCFI(0);
		wait_ms(20);
		free(datap);
#else
		InitCFI(1);
		wait_ms(20);
		ByPass_Test();
		InitCFI(0);
		wait_ms(20);
#endif	
		goto outup;
	}
	
	
	
	
	if (copy_from_user(&priv->m_req, (void *)buf, sizeof(CmdReq_t))) {
		diag_printf("Cannot copy data from user\n");
		err = -EFAULT;
 		goto outup;
 	}

	
	
	if(priv->m_req.cmd_params)
	{
		if (copy_from_user(&priv->m_cmdparams, (void *)priv->m_req.cmd_params, sizeof(CmdParameters_t))) {
			diag_printf("Cannot copy data from user\n");
			err = -EFAULT;
 			goto outup;
 		}
 		paramsp = &priv->m_cmdparams;
	}
	
// allow no parameters
//	else {
//		printk("Command has not parameters\n");
//		err = -EINVAL;
//		goto outup;
//	}
	
	//printk("priv->m_req.cmd_rets: %x, %d\n", priv->m_req.cmd_rets, __LINE__);	
	if(priv->m_req.cmd_rets)
	{
		retsp = &priv->m_cmdrets;
		memset(retsp, 0, sizeof(CmdReturns_t));
	}
//	printk("priv->m_req.cmd_rets: %x, %d\n", priv->m_req.cmd_rets, __LINE__);
//	CommandDump(&priv->m_req, &priv->m_cmdparams);
	
#ifdef 	W865THREAD
	if(priv->m_req.subcmd == CMD_GETJPGBITS)
	{
		err = GetImageLenFromContainer(containerp);	
		TDEBUG("Get Image len: %d, which: %d", err, containerp->reading);
		if(err >= 0) {
			RETVAL4(retsp) = ABYTE(err);
			RETVAL3(retsp) = BBYTE(err);
			RETVAL2(retsp) = CBYTE(err);
			RETVAL1(retsp) = DBYTE(err);
		}
		
		if(priv->m_req.cmd_rets)
		{
			if(copy_to_user(priv->m_req.cmd_rets, retsp, sizeof(CmdReturns_t)))
			{
				err = -EFAULT;
				goto outup;
			}
		}
		up(&priv->lock);
		
		return err;
	}
#endif
	
//	printk("subcmd: 0x%x, priv->m_req.cmd_rets: %x, %d\n", priv->m_req.subcmd, priv->m_req.cmd_rets, __LINE__);
	err = SendCommand2W685(cmd, priv->m_req.subcmd, paramsp, retsp, priv->m_req.flag, NULL);
	
	if(err < 0)
	{
		printf("W99685: send command erro\n");
		goto outup;
	}

	if(priv->m_req.cmd_rets)
	{
//		printk("Copy to user retvals: %x, val: %x, %x, %x, %x\n", priv->m_req.cmd_rets,\
//				RETVAL4(retsp), RETVAL3(retsp), RETVAL2(retsp), RETVAL1(retsp));
		if(copy_to_user(priv->m_req.cmd_rets, retsp, sizeof(CmdReturns_t)))
		{
			diag_printf("Cannot copy data to user\n");
			err = -EFAULT;
			goto outup;
		}
	}
outup:
	
	
	up(&priv->lock);
	
	
//	printk("return value: %d\n", err);
out:
	return err;
}
Beispiel #2
0
/*
 * The ->queue() hook is responsible for initiating io on the io_u
 * being passed in. If the io engine is a synchronous one, io may complete
 * before ->queue() returns. Required.
 *
 * The io engine must transfer in the direction noted by io_u->ddir
 * to the buffer pointed to by io_u->xfer_buf for as many bytes as
 * io_u->xfer_buflen. Residual data count may be set in io_u->resid
 * for a short read/write.
 */
static int fio_unvme_queue(struct thread_data *td, struct io_u *io_u)
{
    /*
     * Double sanity check to catch errant write on a readonly setup
     */
    fio_ro_check(td, io_u);

    int ret = 1;
    unvme_page_t* page = io_u->engine_data;
    page->slba = io_u->offset / unvme.ns->blocksize;
    page->nlb = io_u->xfer_buflen / unvme.ns->blocksize;

    switch (io_u->ddir) {
    case DDIR_READ:
        TDEBUG("READ page=%d lba=%#lx", page->id, page->slba);
        ret = unvme_aread(unvme.ns, page);
        break;

    case DDIR_WRITE:
        TDEBUG("WRITE page=%d lba=%#lx", page->id, page->slba);
        ret = unvme_awrite(unvme.ns, page);
        break;

    default:
        break;
    }

    /*
     * Could return FIO_Q_QUEUED for a queued request,
     * FIO_Q_COMPLETED for a completed request, and FIO_Q_BUSY
     * if we could queue no more at this point (you'd have to
     * define ->commit() to handle that.
     */
    return ret ? FIO_Q_COMPLETED : FIO_Q_QUEUED;
}
QImage NemoThumbnailProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
{
    setupCache();

    // needed for stupid things like gallery model, which pass us a url
    if (id.startsWith("file://")) {
//        qWarning() << Q_FUNC_INFO << "Removing file:// prefix, before: " << id;
        QString &nid = const_cast<QString &>(id);
        nid = nid.remove(0, 7);
    }

    TDEBUG() << Q_FUNC_INFO << "Requested image: " << id << " with size " << requestedSize;

    // sourceSize should indicate what size thumbnail you want. i.e. if you want a 120x120px thumbnail,
    // set sourceSize: Qt.size(120, 120).
    if (!requestedSize.isValid())
        qFatal("You must request a sourceSize whenever you use nemoThumbnail");

    if (size)
        *size = requestedSize;

    QByteArray hashData = cacheKey(id, requestedSize);
    QImage img = attemptCachedServe(id, hashData);
    if (!img.isNull()) {
        TDEBUG() << Q_FUNC_INFO << "Read " << id << " from cache";
        return img;
    }

    return generateThumbnail(id, hashData, requestedSize);
}
Beispiel #4
0
void ConnectionManager::connectionClose()
{
	TDEBUG("connectionClose");

	notifier->setEnabled(false);
	::close(connectionFd);
	connectionFd = -1;
	if (treeManager) {
		treeManager->touch();
		disconnect(treeManager.get(), 0, this, 0);
		TDEBUG("disconnected");
		treeManager.reset();
	}
	deleteLater();
}
bool AsyncThriftForwarder::reloadConfig()
{
	TDEBUG("Load configuration...");

	if (!config_dir.exists(LOG4CXX_CONFIG_FILE)) {
		TWARN("Cannot find '%s'", LOG4CXX_CONFIG_FILE);
		return false;
	}

	if (!config_dir.exists(ASYNCTHRIFT_CONFIG_FILE)) {
		TWARN("Cannot find '%s'", ASYNCTHRIFT_CONFIG_FILE);
		return false;
	}

	TLogger::configure(qPrintable(config_dir.absoluteFilePath(LOG4CXX_CONFIG_FILE)));

	QSettings settings(config_dir.absoluteFilePath(ASYNCTHRIFT_CONFIG_FILE), QSettings::IniFormat);

	QString socket(settings.value("ForwarderSocket", QString(PKGSTATEDIR "/logger")).toString());

	// TODO: Check reconfiguration. We could reconfigure delay and flush_interval
	settings.beginGroup("LogForwarder");
	int nentries = settings.beginReadArray("Forwarders");
	for (int i = 0; i < nentries; i++) {
		settings.setArrayIndex(i);
		forwarders.append(new ForwarderManager(settings.value("Name").toString(), settings.value("ZQuorum").toString(), settings.value("Delay").toUInt(), settings.value("FlushInterval").toUInt(), socket));
	}
	settings.endArray();

	return true;
}
Beispiel #6
0
/*
 * The ->io_u_init() function is called once for each queue depth entry
 * (numjobs x iodepth) prior to .init and after .get_file_size.
 * It is needed if io_u buffer needs to be remapped.
 */
static int fio_unvme_io_u_init(struct thread_data *td, struct io_u *io_u)
{
    int np = 0;
    if (td->o.bs[DDIR_READ] > np) np = td->o.bs[DDIR_READ];
    if (td->o.bs[DDIR_WRITE] > np) np = td->o.bs[DDIR_WRITE];
    if (td->o.max_bs[DDIR_READ] > np) np = td->o.max_bs[DDIR_READ];
    if (td->o.max_bs[DDIR_WRITE] > np) np = td->o.max_bs[DDIR_WRITE];

    np = ((np + unvme.ns->pagesize - 1) & ~(unvme.ns->pagesize - 1));
    np /= unvme.ns->pagesize;
    if (np > unvme.ns->maxppio) {
        error(0, 0, "%s np %d > %d", __func__, np, unvme.ns->maxppio);
        return 1;
    }

    unvme_page_t* page = unvme_alloc(unvme.ns, td->thread_number - 1, np);
    if (!page) {
        error(0, 0, "%s unvme_alloc", __func__);
        return 1;
    }
    page->data = io_u;
    io_u->engine_data = page;
    TDEBUG("page=%d", page->id);

    return 0;
}
Beispiel #7
0
/*
 * The ->getevents() hook is used to reap completion events from an async
 * io engine. It returns the number of completed events since the last call,
 * which may then be retrieved by calling the ->event() hook with the event
 * numbers. Required.
 */
static int fio_unvme_getevents(struct thread_data *td, unsigned int min,
                               unsigned int max, const struct timespec *t)
{
    unvme_data_t* udata = td->io_ops->data;
    int events = 0;
    struct timespec t0, t1;
    uint64_t timeout = 0;

    if (t) {
        timeout = t->tv_sec * 1000000000L + t->tv_nsec;
        clock_gettime(CLOCK_MONOTONIC_RAW, &t0);
    }

    for (;;) {
        unvme_page_t* page = unvme_apoll(unvme.ns, td->thread_number - 1, 0);

        if (page) {
            udata->iocq[udata->tail] = page->data;
            TDEBUG("PUT %d page=%d lba=%#lx", udata->tail, page->id, page->slba);
            if (++udata->tail > td->o.iodepth) udata->tail = 0;
            if (++events >= min) break;
        } else if (t) {
            clock_gettime(CLOCK_MONOTONIC_RAW, &t1);
            uint64_t elapse = ((t1.tv_sec - t0.tv_sec) * 1000000000L)
                              + t1.tv_nsec - t0.tv_nsec;
            if (elapse > timeout) break;
        }
    }

    return events;
}
Beispiel #8
0
/*
 * The ->io_u_free() function is called once for each queue depth entry
 * (numjobs x iodepth) prior to .init and after .get_file_size.
 * It is needed if io_u buffer needs to be remapped.
 */
static void fio_unvme_io_u_free(struct thread_data *td, struct io_u *io_u)
{
    unvme_page_t* page = io_u->engine_data;
    if (page) {
        TDEBUG("page=%d", page->id);
        assert(page->data == io_u);
        unvme_free(unvme.ns, page);
        io_u->engine_data = NULL;
    }
}
QImage NemoThumbnailProvider::generateThumbnail(const QString &id, const QByteArray &hashData, const QSize &requestedSize, bool crop)
{
    QImage img;
    QSize originalSize;
    QByteArray format;

    // image was not in cache thus we read it
    QImageReader ir(id);
    if (!ir.canRead())
        return img;

    originalSize = ir.size();
    format = ir.format();

    if (originalSize != requestedSize && originalSize.isValid()) {
        if (crop) {
            // scales arbitrary sized source image to requested size scaling either up or down
            // keeping aspect ratio of the original image intact by maximizing either width or height
            // and cropping the rest of the image away
            QSize scaledSize(originalSize);

            // now scale it filling the original rectangle by keeping aspect ratio, but expand if needed.
            scaledSize.scale(requestedSize, Qt::KeepAspectRatioByExpanding);

            // set the adjusted clipping rectangle in the center of the scaled image
            QPoint center((scaledSize.width() - 1) / 2, (scaledSize.height() - 1) / 2);
            QRect cr(0,0,requestedSize.width(), requestedSize.height());
            cr.moveCenter(center);
            ir.setScaledClipRect(cr);

            // set requested target size of a thumbnail
            ir.setScaledSize(scaledSize);
        } else {
            // Maintains correct aspect ratio without cropping, as such the final image may
            // be smaller than requested in one dimension.
            QSize scaledSize(originalSize);
            scaledSize.scale(requestedSize, Qt::KeepAspectRatio);
            ir.setScaledSize(scaledSize);
        }
    }
    img = ir.read();

    NemoImageMetadata meta(id, format);
    if (meta.orientation() != NemoImageMetadata::TopLeft)
        img = rotate(img, meta.orientation());

    // write the scaled image to cache
    if (meta.orientation() != NemoImageMetadata::TopLeft ||
        (originalSize != requestedSize && originalSize.isValid())) {
        writeCacheFile(hashData, img);
    }

    TDEBUG() << Q_FUNC_INFO << "Wrote " << id << " to cache";
    return img;
}
Beispiel #10
0
unsigned long tar_read_tarblock(FILE *tarfile, struct tarinfotype *tarinfoptr)
{
  unsigned long result;

  TDEBUG(printf("Entering tar_read_tarblock.\n"));

  /* reading the first info block */
  result = fread(tarinfoptr, 512, 1, tarfile);
  if (result < 0) { perror("Can't read tar info"); exit(1); }                 

  if (feof(tarfile) || 
      ((tarinfoptr->name)[0] == '\0' && (tarinfoptr->name)[1] == '\0'))
  { TDEBUG(printf("End of tar file reached.\n")); 
    return FALSE;
  }

  TDEBUG({
    tarblock_print(tarinfoptr);
    printf("Comparing checksums:\n");
  });
Beispiel #11
0
void ConnectionManager::onNewTreeAvailable()
{
	TTRACE("onNewTreeAvailable");
	if (treeManager) {
		auto tree = treeManager->getConfigurationTree();
		if (tree) {
			TTRACE("got path %s", tree->path.toLatin1().data());
			sendPush(tree->path, tree->fd);
		}
	} else {
		TDEBUG("Connection already closed when new tree is available");
	}
}
Beispiel #12
0
/*
 * The ->event() hook is called to match an event number with an io_u.
 * After the core has called ->getevents() and it has returned eg 3,
 * the ->event() hook must return the 3 events that have completed for
 * subsequent calls to ->event() with [0-2]. Required.
 */
static struct io_u* fio_unvme_event(struct thread_data *td, int event)
{
    unvme_data_t* udata = td->io_ops->data;
    struct io_u* io_u = NULL;

    if (udata->head != udata->tail) {
        io_u = udata->iocq[udata->head];
        TDEBUG("GET %d page=%d lba=%#lx", udata->head,
               ((unvme_page_t*)io_u->engine_data)->id,
               ((unvme_page_t*)io_u->engine_data)->slba);
        if (++udata->head > td->o.iodepth) udata->head = 0;
    }
    return io_u;
}
Beispiel #13
0
/*
 * The ->get_file_size() is called once for every job (i.e. numjobs)
 * before all other functions.  This is called after ->setup() but
 * is simpler to initialize here since we only care about the device name
 * (given as file_name) and just have to specify the device size.
 */
static int fio_unvme_get_file_size(struct thread_data *td, struct fio_file *f)
{
    TDEBUG("file=%s", f->file_name);
    if (!fio_file_size_known(f)) {
        if (do_unvme_init(f->file_name, td)) {
            error(0, 0, "%s do_unvme_init", __func__);
            return 1;
        }
        f->filetype = FIO_TYPE_CHAR;
        f->real_file_size = unvme.ns->blockcount * unvme.ns->blocksize;
        fio_file_set_size_known(f);
    }
    return 0;
}
Beispiel #14
0
/*
 * This is paired with the ->init() function and is called when a thread is
 * done doing io. Should tear down anything setup by the ->init() function.
 * Not required.
 */
static void fio_unvme_cleanup(struct thread_data *td)
{
    unvme_data_t* udata = td->io_ops->data;
    if (udata) {
        if (udata->iocq) free(udata->iocq);
        free(udata);
    }

    pthread_mutex_lock(&unvme.mutex);
    TDEBUG("active=%d", unvme.active);
    if (--unvme.active == 0 && unvme.ns) {
        DEBUG("%s unvme_close", __func__);
        unvme_close(unvme.ns);
        unvme.ns = NULL;
    }
    pthread_mutex_unlock(&unvme.mutex);
}
Beispiel #15
0
void ItemModel::Read(char * File)
{
	int Token;
	// ----
	if( !g_ScriptEncode.ReadScript(File) )
	{
		//MessageBox(NULL, "file not found", "[ItemModel]", ERROR);
		return;
	}
	// ----
	while(true)
	{
		Token = g_ScriptEncode.GetToken();
		// ----
		if( Token == END )
		{
			break;
		}
		// ----
		ItemModelData lpData;
		// ----
		lpData.ItemType	= g_ScriptEncode.GetNumber();
		// ----
		g_ScriptEncode.GetToken();
		lpData.ItemIndex = g_ScriptEncode.GetNumber();
		// ----
		g_ScriptEncode.GetToken();
		strcpy(lpData.Model, g_ScriptEncode.GetString());
		// ----
		g_ScriptEncode.GetToken();
		lpData.R = g_ScriptEncode.GetNumber();
		// ----
		g_ScriptEncode.GetToken();
		lpData.G = g_ScriptEncode.GetNumber();
		// ----
		g_ScriptEncode.GetToken();
		lpData.B = g_ScriptEncode.GetNumber();
		// ----
		TDEBUG("[%d] %d %d - %s", m_Data.size(), lpData.ItemType, lpData.ItemIndex, lpData.Model);

		m_Data.push_back(lpData);
	}
}
Beispiel #16
0
static int w99685_thread(void *arg)
{
	int ret = 0;
	UINT32 imglen = 0;;
	UINT16 blocks = 0;
	UINT8 choice = 0;
	w685cf_t *priv = arg;
	ImageContainer_t *imgcontainerp = priv->images;
	/*
	 * This thread doesn't need any user-level access,
	 * so get rid of all our resources..
	 */
	daemonize();
	reparent_to_init();
//	exit_files(current);
//	current->files = init_task.files;
//	atomic_inc(&current->files->count);
//	daemonize();
//	reparent_to_init();

	/* avoid getting signals */
//	spin_lock_irq(&current->sigmask_lock);
//	flush_signals(current);
//	sigfillset(&current->blocked);
//	recalc_sigpending(current);
//	spin_unlock_irq(&current->sigmask_lock);

	/* set our name for identification purposes */
	sprintf(current->comm, "W99685CFI_thread");

//Get Image Data, :P	
	for(;;) {
		if(priv->user) { // Someone open the camera, get the data.
			W99685CMD_GetImageLen(&imglen);
			TDEBUG("imagelen: %d", imglen);
			if(imglen > 0&& imglen <= W685BUF_SIZE)
			{
				blocks = (imglen-1+DATABLOCKSIZE)/DATABLOCKSIZE;
				if(blocks < W685BUF_SIZE/DATABLOCKSIZE) {
					choice = imgcontainerp->which;
					TDEBUG("Write choice: %d, and choicelen: %d", choice, IMAGELEN(imgcontainerp, choice));
					down( &((IMAGEHOLD(imgcontainerp, choice)).ilock) );
					if(IMAGELEN(imgcontainerp, choice) > 0) //Have had data, don't overwrite it.
						goto do_next;
					W99685_GetData(IMAGEDATA(imgcontainerp, choice) ,blocks);
					(IMAGEHOLD(imgcontainerp, choice)).len = imglen;
do_next:
					imgcontainerp->which = (++(imgcontainerp->which))%IMGCONTAINERSIZE;
					up( &((IMAGEHOLD(imgcontainerp, choice)).ilock) );
				}
			TDEBUG("Sleep...");
			wait_ms(20);
			}
			else if(imglen < 0)  //can't recover, it crazy :(
			{
				W685_ERR("Get image length error: %d\n", imglen);
				break;
			}
			else {
				wait_ms(500);
				continue;
			}
		}
		else
			sleep_on_timeout(&priv->waitq, 10);
	}
out:
	return ret;
}
Beispiel #17
0
/**
 * Setup trigger handling
 * @return void
 */
void tikle_trigger_handling(void)
{
	unsigned int i = 0, base;
	struct task_struct *stop;

	/*
	 * setting up triggers
 	 */
	TDEBUG("TRIGGERS:\n");

	for (i = 0; i < tikle_num_timers; i++) {
		init_timer(&tikle_timers[i].trigger);

		tikle_timers[i].trigger.function = tikle_flag_handling;

		/*
		 * send the next trigger ID, if actual trigger it is
		 * not the latest, else send your own trigger ID
		 */
		if (tikle_timers[i].trigger_id < tikle_timers[tikle_num_timers-1].trigger_id) {
			tikle_timers[i].trigger.data = tikle_timers[i+1].trigger_id;
		} else {
			tikle_timers[i].trigger.data = tikle_timers[i].trigger_id;
		}
		
		TDEBUG("Registering timer %d; trigger_id=%d ; trigger_data=%ld\n",
			i, tikle_timers[i].trigger_id, tikle_timers[i].trigger.data);

		/*
		 * calculate expire time to trigger
		 * based on the experiment start time
		 */		
		base = jiffies;
		tikle_timers[i].trigger.expires = base +
			msecs_to_jiffies(faultload[tikle_timers[i].trigger_id].op_value[0].num * 1000);

		if (tikle_timers[i].trigger_id == 0) { /* if timer corresponds to the first timer */

			/*
			 * register hook
			 */
			tikle_pre_hook.hook = &tikle_pre_hook_function;
			tikle_pre_hook.hooknum = NF_IP_PRE_ROUTING;
			tikle_pre_hook.pf = PF_INET;
			tikle_pre_hook.priority = NF_IP_PRI_FIRST;

			nf_register_hook(&tikle_pre_hook);

			tikle_post_hook.hook = &tikle_post_hook_function;
			tikle_post_hook.hooknum = NF_IP_POST_ROUTING;
			tikle_post_hook.pf = PF_INET;
			tikle_post_hook.priority = NF_IP_PRI_FIRST;

			nf_register_hook(&tikle_post_hook);

			//nf_register_queue_handler(PF_INET, &qh);

			/*
			 * if timer corresponds
			 * to the last timer
			 */
		} else if (tikle_timers[i].trigger_id == tikle_timers[tikle_num_timers-1].trigger_id) {			
			/*
			 * unregister hook timer
			 * this is done by a thread
			 * to avoid console freezing
			 */
			/* not handled here */
			stop = kthread_run((void *)tikle_stop_trigger, (unsigned int *)base, "thread stop trigger");
		}
		add_timer(&tikle_timers[i].trigger);
	}
	TDEBUG("--------------------------------\n");
}
Beispiel #18
0
long w99685_v4l1_read(w685cf_t *priv, char * buf, cyg_uint32 *count)
{
	int k, j;
	long rc = 0;
	long size = 0;
	long blocks = (*count-1+DATABLOCKSIZE)/DATABLOCKSIZE;
	//w685cf_t *priv = (w685cf_t *)vdev->priv;
	
#ifndef W865THREAD	
	char *buffer = priv->rawbuf;
	//KDEBUG("Read data\n");
	if(blocks > W685BUF_SIZE/DATABLOCKSIZE) {
		printf("Too long data: %dbytes\n", *count);
		rc = -EINVAL;
		goto out;
	}
	if (down_interruptible2(&(priv->lock))) {
		rc = -EINTR;
		goto out;
	}

	if (!buf ) {
		printf("W99865:vdev || !buf \n");
		rc = -EFAULT;
		goto out_up;
	}
	
	rc = W99685_GetData(buffer, blocks);
	if(!rc)
		rc = ENOERR;//clyu
	//if(rc > 0) //yc
	{
		if (copy_to_user(buf, buffer, *count)<0) {
			printf("copy_to_user\n");
			rc = -EFAULT;
			goto out_up;
		}
	}
	#if 0
	int i;
	for(i = 0; i < 20; i++)
		diag_printf("%x ", *(buffer+i));
	diag_printf("\n");
	
	for(i = 0; i < 20; i++)
		diag_printf("%x ", *(buf+i));
	diag_printf("\n");
	#endif
#endif

#ifdef	W865THREAD
	ImageContainer_t *container = priv->images;
	UINT8 choice = container->reading;	//Get Write Position
	TDEBUG("Begin reading...");
	
	if(blocks > W685BUF_SIZE/DATABLOCKSIZE) {
		printk("Too long data: %dbytes\n", *count);
		rc = -EINVAL;
		goto out;
	}
	if (down_interruptible2(&priv->lock)) {
		rc = -EINTR;
		goto out;
	}

	down( &(IMAGEHOLD(container, choice).ilock) );
	TDEBUG("read choice: %d, imglen: %d", choice, IMAGELEN(container, choice));
	if(IMAGELEN(container, choice) == 0) {
		// == 0, shouldn't happen, if so, just out.
		rc = 0;
		goto flag_up;
	}
	else if(IMAGELEN(container, choice) != *count)
	{	// != count, :(, wrong data ,remove it
		IMAGELEN(container, choice) = 0;
		rc = 0;
		goto flag_up;
	}
	if (copy_to_user(buf, IMAGEDATA(container, choice), *count)) {
		printk("copy_to_user\n");
		rc = -EFAULT;
		goto flag_up;
	}
	IMAGELEN(container, choice) = 0;	// clean the container's data
	container->reading = (++(container->reading))%IMGCONTAINERSIZE; // Goto Next Reading Position
	
	rc = ENOERR;//clyu
	//rc = *count;//clyu
flag_up:
	up( &(IMAGEHOLD(container, choice).ilock) );
#endif

out_up:
	up(&priv->lock);
out:	
	//TDEBUG("End reading...");	
	//diag_printf("read rc: %d \n",rc);
	return rc;
}