wxThread::ExitCode GammaBlockUSB::Entry()
{
	//wxMutexLocker locker(m_processDataMutex);

	if(deviceFind() && deviceInit())
	{
		while(!GetThread()->TestDestroy())
		{
			GammaDataUSB* pDataOut(new GammaDataUSB);

			int bytesRead = 0x200;
#if defined(_MSC_VER) && defined(GAMMA_USB_CYAPI)
			LONG length = bytesRead;
			m_usbDevice->BulkInEndPt->XferData(pDataOut->data, length);
			bytesRead = length;
#else
			//usb_claim_interface(m_usbDevice, 0);

			bytesRead = usb_bulk_read(m_usbDevice, EP6IN, 
				(char*)pDataOut->data, bytesRead, GAMMA_READ_TIMEOUT);

			//usb_release_interface(m_usbDevice, 0);
#endif
			wxASSERT(GAMMA_READ_SIZE == bytesRead);
			
			pushData(wxSharedPtr<GammaData>(pDataOut));
		}
	}

	return 0;
}
Beispiel #2
0
/*----------------------------------------------------------------------------*/
int main(void)
{
  struct DeviceDriver device;

  struct Interface * const i2c = init(I2c, &i2cConfig);
  assert(i2c);

  deviceInit(&device, i2c, LED_PIN, DEVICE_ADDRESS);

  struct Timer * const timer = init(GpTimer, &timerConfig);
  assert(timer);
  timerSetOverflow(timer, 1000);

  bool event = false;
  timerSetCallback(timer, onTimerOverflow, &event);
  timerEnable(timer);

  while (1)
  {
    while (!event)
      barrier();
    event = false;

    deviceWrite(&device);

    while (!event)
      barrier();
    event = false;

    deviceRead(&device);
  }

  return 0;
}
Beispiel #3
0
char* pcap_lookupdev(char* errbuf)
{
    int    port  = 0;
    struct rte_eth_dev_info info;

    if (globalInit(errbuf) != DPDKPCAP_OK)
    {
        return NULL;
    }

    int portsNumber = rte_eth_dev_count();
    if (portsNumber < 1)
    {
        snprintf (errbuf, PCAP_ERRBUF_SIZE, "No devices found");
        return NULL;
    }

    if (deviceInit(port, errbuf) == DPDKPCAP_FAILURE)
    {
        return NULL;
    }

    rte_eth_dev_info_get(port, &info);

    snprintf(ifName, DPDKPCAP_IF_NAMESIZE, "enp%us%u",
             info.pci_dev->addr.bus,
             info.pci_dev->addr.devid);

    deviceNames[port] = ifName;

    return ifName;
}
void setup() {

    // Helper function found in functions.cpp

    deviceInit();
    pinMode(button1, INPUT_PULLUP);
    pinMode(button2, INPUT_PULLUP);

    // Reset OLED (function from functions.cpp)

    oledReset();
    OrbitOledUpdate();
}
Beispiel #5
0
int main(int argc, char* argv)
{   
 
    fb_init();
    
    printf("after fb_init\n");
    deviceOpen();
    printf("after deviceOpen\n");
    if(!deviceInit())
    {
        return 0;
    }
    printf("after deviceInit\n");
    captureStart();
    printf("after captureStart\n");
    while(1)
    {
	mainLoop();
        printf("in mainLoop\n");
    }

    printf("*****quit\n");
}
Beispiel #6
0
int main(void)
{
    PWM_init();
    
	CF_init(&alpha, &beta);
	
	PID_init(&pid_x, &pid_y);
	
	Flags_init();
    
	Timer1_init();
	
	Twi_init();
	
	Usart_init();

    deviceInit_adc();

    deviceInit_rc();
	
    if(!deviceInit() || !Flags_getBit(flags_deviceAdcInitialised) || !Flags_getBit(flags_deviceRcInitialised))
	{
		_exit();
	}
	
	// todo: workaround for slave initialization
	deviceInitialize(deviceID_slave, _true);

    // todo: workaround for gps initialization
    deviceInitialize(deviceID_gps, _true);
	
	//enable interrupts
	_enableInterrupts();

    while(1);
}	
Beispiel #7
0
int main(int argc, char **argv)
{

    for (;;) {
        int index, c = 0;

        c = getopt_long(argc, argv, short_options, long_options, &index);

        if (-1 == c)
            break;

        switch (c) {
        case 0: /* getopt_long() flag */
            break;

        case 'd':
            deviceName = optarg;
            break;

        case 'h':
            // print help
            usage(stdout, argc, argv);
            exit(EXIT_SUCCESS);

        case 'o':
            // set jpeg filename
            jpegFilename = optarg;
            break;

        case 'q':
            // set jpeg quality
            jpegQuality = atoi(optarg);
            break;

        case 'm':
#ifdef IO_MMAP
            io = IO_METHOD_MMAP;
#else
            fprintf(stderr, "You didn't compile for mmap support.\n");
            exit(EXIT_FAILURE);
#endif
            break;

        case 'r':
#ifdef IO_READ
            io = IO_METHOD_READ;
#else
            fprintf(stderr, "You didn't compile for read support.\n");
            exit(EXIT_FAILURE);
#endif
            break;

        case 'u':
#ifdef IO_USERPTR
            io = IO_METHOD_USERPTR;
#else
            fprintf(stderr, "You didn't compile for userptr support.\n");
            exit(EXIT_FAILURE);
#endif
            break;

        case 'W':
            // set width
            width = atoi(optarg);
            break;

        case 'H':
            // set height
            height = atoi(optarg);
            break;

        case 'I':
            // set fps
            fps = atoi(optarg);
            break;

        case 'c':
            // set flag for continuous capture, interuptible by sigint
            continuous = 1;
            InstallSIGINTHandler();
            break;


        case 'v':
            printf("Version: %s\n", VERSION);
            exit(EXIT_SUCCESS);
            break;

        default:
            usage(stderr, argc, argv);
            exit(EXIT_FAILURE);
        }
    }

    // check for need parameters
    if (!jpegFilename) {
        fprintf(stderr, "You have to specify JPEG output filename!\n\n");
        usage(stdout, argc, argv);
        exit(EXIT_FAILURE);
    }

    if(continuous == 1) {
        int max_name_len = snprintf(NULL,0,continuousFilenameFmt,jpegFilename,UINT32_MAX,INT64_MAX);
        jpegFilenamePart = jpegFilename;
        jpegFilename = calloc(max_name_len+1,sizeof(char));
        strcpy(jpegFilename,jpegFilenamePart);
    }


    // open and initialize device
    deviceOpen();
    deviceInit();

    // start capturing
    captureStart();

    // process frames
    mainLoop();

    // stop capturing
    captureStop();

    // close device
    deviceUninit();
    deviceClose();

    if(jpegFilenamePart != 0) {
        free(jpegFilename);
    }

    exit(EXIT_SUCCESS);

    return 0;
}
/*
 *  ======== encode_decode ========
 */
static Void encode_decode(VIDENC_Handle enc, VIDDEC_Handle dec, FILE *in,
    FILE *out)
{
    Int                         n;
    Int32                       status;

    VIDDEC_InArgs               decInArgs;
    VIDDEC_OutArgs              decOutArgs;
    VIDDEC_DynamicParams        decDynParams;
    VIDDEC_Status               decStatus;

    VIDENC_InArgs               encInArgs;
    VIDENC_OutArgs              encOutArgs;
    VIDENC_DynamicParams        encDynParams;
    VIDENC_Status               encStatus;

    XDM_BufDesc                 inBufDesc;
    XDAS_Int8                  *src[XDM_MAX_IO_BUFFERS];
    XDAS_Int32                  inBufSizes[XDM_MAX_IO_BUFFERS];

    XDM_BufDesc                 encodedBufDesc;
    XDAS_Int8                  *encoded[XDM_MAX_IO_BUFFERS];
    XDAS_Int32                  encBufSizes[XDM_MAX_IO_BUFFERS];

    XDM_BufDesc                 outBufDesc;
    XDAS_Int8                  *dst[XDM_MAX_IO_BUFFERS];
    XDAS_Int32                  outBufSizes[XDM_MAX_IO_BUFFERS];

    /* clear and initialize the buffer descriptors */
    memset(src,     0, sizeof(src[0])     * XDM_MAX_IO_BUFFERS);
    memset(encoded, 0, sizeof(encoded[0]) * XDM_MAX_IO_BUFFERS);
    memset(dst,     0, sizeof(dst[0])     * XDM_MAX_IO_BUFFERS);

    src[0]     = inBuf;
    encoded[0] = encodedBuf;
    dst[0]     = outBuf;

    inBufDesc.numBufs = encodedBufDesc.numBufs = outBufDesc.numBufs = 1;
   


    inBufDesc.bufSizes      = inBufSizes;
    encodedBufDesc.bufSizes = encBufSizes;
    outBufDesc.bufSizes     = outBufSizes;

    //Note , this declaration is tell the memtab how much need to  allocate the buf sizes  
    inBufSizes[0] = IFRAMESIZE;
    encBufSizes[0] = EFRAMESIZE;
    outBufSizes[0] = OFRAMESIZE;

    inBufDesc.bufs      = src;
    encodedBufDesc.bufs = encoded;
    outBufDesc.bufs     = dst;

    /* initialize all "sized" fields */
    encInArgs.size    = sizeof(encInArgs);
    decInArgs.size    = sizeof(decInArgs);
    encOutArgs.size   = sizeof(encOutArgs);
    decOutArgs.size   = sizeof(decOutArgs);
    encDynParams.size = sizeof(encDynParams);
    decDynParams.size = sizeof(decDynParams);
    encStatus.size    = sizeof(encStatus);
    decStatus.size    = sizeof(decStatus);

    /*
     * Query the encoder and decoder.
     * This app expects the encoder to provide 1 buf in and get 1 buf out,
     * and the buf sizes of the in and out buffer must be able to handle
     * NSAMPLES bytes of data.
     */
    status = VIDENC_control(enc, XDM_GETSTATUS, &encDynParams, &encStatus);
    if (status != VIDENC_EOK) {
        /* failure, report error and exit */
        GT_1trace(curMask, GT_7CLASS, "encode control status = 0x%x\n", status);
        return;
    }

    /* Validate this encoder codec will meet our buffer requirements */
    if ((inBufDesc.numBufs < encStatus.bufInfo.minNumInBufs) ||
        (IFRAMESIZE < encStatus.bufInfo.minInBufSize[0]) ||
        (encodedBufDesc.numBufs < encStatus.bufInfo.minNumOutBufs) ||
        (EFRAMESIZE < encStatus.bufInfo.minOutBufSize[0])) {

        /* failure, report error and exit */
        GT_0trace(curMask, GT_7CLASS,
            "Error:  encoder codec feature conflict\n");
        return;
    }


//#if 0
    status = VIDDEC_control(dec, XDM_GETSTATUS, &decDynParams, &decStatus);
    if (status != VIDDEC_EOK) {
        /* failure, report error and exit */
        GT_1trace(curMask, GT_7CLASS, "decode control status = 0x%x\n", status);
        return;
    }
//#endif


    /* Validate this decoder codec will meet our buffer requirements */
    if ((encodedBufDesc.numBufs < decStatus.bufInfo.minNumInBufs) ||
        (EFRAMESIZE < decStatus.bufInfo.minInBufSize[0]) ||
        (outBufDesc.numBufs < decStatus.bufInfo.minNumOutBufs) ||
        (OFRAMESIZE < decStatus.bufInfo.minOutBufSize[0])) {

        /* failure, report error and exit */
        GT_0trace(curMask, GT_7CLASS,
            "App-> ERROR: decoder does not meet buffer requirements.\n");
        return;
    }



    /*
     * Read complete frames from in, encode, decode, and write to out.
     */


    /* opencv create init image */
#ifdef USE_OPENCV_DISPLAY
    cvNamedWindow("sobel",CV_WINDOW_AUTOSIZE);
    cvResizeWindow("sobel",320,240);//怕畫面太大讓人看不完,所以顯示視窗設小一點
#endif
    CvSize size=cvSize(320,240);
    frame=cvCreateImage(size,IPL_DEPTH_8U,3);
    frame_gray=cvCreateImage(size,IPL_DEPTH_8U,1);
    frame_Smooth=cvCreateImage(size,IPL_DEPTH_8U,1);
    frame_sobel=cvCreateImage(size,IPL_DEPTH_16S,1);
    frame_sobel_8U=cvCreateImage(size,IPL_DEPTH_8U,1);

    /* v4l2 init */
     int count=0;

     deviceOpen();
     deviceInit();
     /*start capturing*/
     captureStart();


    /*===============v4l2 grab frame by Camera======================*/
    while(1){
        mainLoop(); /*this is the v4l2grab frame*/
        memcpy(inBuf,buffers[0].start,IFRAMESIZE);

#ifdef CACHE_ENABLED
#ifdef xdc_target__isaCompatible_64P
        /*
         *  fread() on this processor is implemented using CCS's stdio, which
         *  is known to write into the cache, not physical memory.  To meet
         *  xDAIS DMA Rule 7, we must writeback the cache into physical
         *  memory.  Also, per DMA Rule 7, we must invalidate the buffer's
         *  cache before providing it to any xDAIS algorithm.
         */
        Memory_cacheWbInv(inBuf, IFRAMESIZE);
#else
#error Unvalidated config - add appropriate fread-related cache maintenance
#endif
        /* Per DMA Rule 7, our output buffer cache lines must be cleaned */
        Memory_cacheInv(encodedBuf, EFRAMESIZE);
#endif

        GT_1trace(curMask, GT_1CLASS, "App-> Processing frame %d...\n", count);

        /* encode the frame */
        status = VIDENC_process(enc, &inBufDesc, &encodedBufDesc, &encInArgs,
            &encOutArgs);

        GT_2trace(curMask, GT_2CLASS,
            "App-> Encoder frame %d process returned - 0x%x)\n",
            count, status);

#ifdef CACHE_ENABLED
        /* Writeback this outBuf from the previous call.  Also, as encodedBuf
         * is an inBuf to the next process call, we must invalidate it also, to
         * clean buffer lines.
         */
        Memory_cacheWbInv(encodedBuf, EFRAMESIZE);

        /* Per DMA Rule 7, our output buffer cache lines must be cleaned */
        Memory_cacheInv(outBuf, OFRAMESIZE);
#endif

        if (status != VIDENC_EOK) {
            GT_3trace(curMask, GT_7CLASS,
                "App-> Encoder frame %d processing FAILED, status = 0x%x, "
                "extendedError = 0x%x\n", count, status, encOutArgs.extendedError);
            break;
        }


/***************************decode part (Unuse)***********************************/
/************************** decode the frame**************************************/
        status = VIDDEC_process(dec, &encodedBufDesc, &outBufDesc, &decInArgs,
           &decOutArgs);

        GT_2trace(curMask, GT_2CLASS,
            "App-> Decoder frame %d process returned - 0x%x)\n",
            n, status);

        if (status != VIDDEC_EOK) {
            GT_3trace(curMask, GT_7CLASS,
                "App-> Decoder frame %d processing FAILED, status = 0x%x, "
                "extendedError = 0x%x\n", n, status, decOutArgs.extendedError);
            break;
        }


#ifdef CACHE_ENABLED
        /* Writeback the outBuf. */
        Memory_cacheWb(outBuf, OFRAMESIZE);
#endif

        /* write to file */
        //fwrite(encodedBuf, EFRAMESIZE, 1, out);

        frame->imageData =  encoded[0];
        frame_gray->imageData = dst[0];
        //cvCvtColor(frame,frame_gray,CV_BGR2GRAY);

#ifdef USE_OPENCV_DISPLAY
        cvShowImage("sobel",frame_gray);
        int key=cvWaitKey(33);
#endif 
        //cvSaveImage("22.bmp",frame_gray,0);
        printf("the %d frame are completed \n",count);
        count++;

    }/*end while*/

#ifdef USE_OPENCV_DISPLAY
    cvDestroyWindow("sobel"); 
#endif 
    cvReleaseImage(&frame);
    cvReleaseImage(&frame_gray);
    cvReleaseImage(&frame_Smooth);
    cvReleaseImage(&frame_sobel);
    cvReleaseImage(&frame_sobel_8U);

    GT_1trace(curMask, GT_1CLASS, "%d frames encoded/decoded\n", n);
}
Beispiel #9
0
int main(int argc, char **argv)
{

	for (;;) {
		int index, c = 0;

		c = getopt_long(argc, argv, short_options, long_options, &index);

		if (-1 == c)
			break;

		switch (c) {
			case 0: /* getopt_long() flag */
				break;

			case 'd':
				deviceName = optarg;
				break;

			case 'h':
				// print help
				usage(stdout, argc, argv);
				exit(EXIT_SUCCESS);

			case 'o':
				// set jpeg filename
				jpegFilename = optarg;
				break;

			case 'q':
				// set jpeg quality
				jpegQuality = atoi(optarg);
				break;

			case 'm':
#ifdef IO_MMAP
				io = IO_METHOD_MMAP;
#else
				fprintf(stderr, "You didn't compile for mmap support.\n");
				exit(EXIT_FAILURE);
#endif
				break;

			case 'r':
#ifdef IO_READ
				io = IO_METHOD_READ;
#else
				fprintf(stderr, "You didn't compile for read support.\n");
				exit(EXIT_FAILURE);
#endif
				break;

			case 'u':
#ifdef IO_USERPTR
				io = IO_METHOD_USERPTR;
#else
				fprintf(stderr, "You didn't compile for userptr support.\n");
				exit(EXIT_FAILURE);
#endif
				break;

			case 'W':
				// set width
				width = atoi(optarg);
				break;

			case 'H':
				// set height
				height = atoi(optarg);
				break;
				
			case 'I':
				// set fps
				fps = atoi(optarg);
				break;

			case 'v':
				printf("Version: %s\n", VERSION);
				exit(EXIT_SUCCESS);
				break;

			default:
				usage(stderr, argc, argv);
				exit(EXIT_FAILURE);
		}
	}

	// check for need parameters
	if (!jpegFilename) {
		fprintf(stderr, "You have to specify JPEG output filename!\n\n");
		usage(stdout, argc, argv);
		exit(EXIT_FAILURE);
	}

	// open and initialize device
	deviceOpen();
	deviceInit();

	// start capturing
	captureStart();

	// process frames
	mainLoop();

	// stop capturing
	captureStop();

	// close device
	deviceUninit();
	deviceClose();

	exit(EXIT_SUCCESS);

	return 0;
}
Beispiel #10
0
int pcap_findalldevs(pcap_if_t **alldevsp, char *errbuf)
{
    int       port     = 0;
    pcap_if_t *pPcapIf = NULL;
    pcap_if_t *pPcapPrevious = NULL;
    struct rte_eth_dev_info info;

    if (globalInit(errbuf) != DPDKPCAP_OK)
    {        
        return DPDKPCAP_FAILURE;
    }

    int portsNumber = rte_eth_dev_count();
    if (portsNumber < 1)
    {
        snprintf (errbuf, PCAP_ERRBUF_SIZE, "No devices found");
        return DPDKPCAP_FAILURE;
    }

    debug ("Discovered %d devices\n", portsNumber);

    for (port = 0; port < portsNumber; port++)
    {
        if (deviceInit(port, errbuf) == DPDKPCAP_FAILURE)
        {
            return DPDKPCAP_FAILURE;
        }

        pPcapIf = malloc(sizeof(pcap_if_t));
        memset(pPcapIf, 0, sizeof(pcap_if_t));

        if (pPcapPrevious)
            pPcapPrevious->next = pPcapIf;
        else
            *alldevsp = pPcapIf;

        pPcapPrevious = pPcapIf;

        rte_eth_dev_info_get(port, &info);

        pPcapIf->name = malloc(DPDKPCAP_IF_NAMESIZE);
        memset(pPcapIf->name, 0, DPDKPCAP_IF_NAMESIZE);

        snprintf(pPcapIf->name, DPDKPCAP_IF_NAMESIZE, "port%ubus%udev%u",
                 port,
                 info.pci_dev->addr.bus,
                 info.pci_dev->addr.devid);

        deviceNames[port] = pPcapIf->name;

        pPcapIf->description = malloc(DPDKPCAP_IF_NAMESIZE);
        memset(pPcapIf->description, 0, DPDKPCAP_IF_NAMESIZE);

        snprintf(pPcapIf->description, DPDKPCAP_IF_NAMESIZE, "DPDK interface");

        printf("Allocating memory for %s\n", pPcapIf->name);
    }

    pPcapPrevious->next = NULL;

    return DPDKPCAP_OK;
}