Пример #1
0
/*!
 * @brief Initialize everything so the application is fully operable after a call to this function.
 *
 * @return SUCCESS or an appropriate error code.
 */
static OSC_ERR init(const int argc, const char * * argv)
{
	OSC_ERR err = SUCCESS;
	
	/* Set log levels. */
	OscLogSetConsoleLogLevel(EMERG);
	OscLogSetFileLogLevel(EMERG);
	
	/* Create the framework */
	err = OscCreate(&hFramework);
	if (err != SUCCESS)
	{
		fprintf(stderr, "%s: error: Unable to create framework.\n", __func__);
		return err;
	}
	
	/* Load the framework module dependencies. */
	err = OscLoadDependencies(hFramework, deps, length (deps));
	if (err != SUCCESS)
	{
		fprintf(stderr, "%s: error: Unable to load dependencies! (%d)\n", __func__, err);
		goto dep_err;
	}
	
	/* Seed the random generator */
	srand(OscSupCycGet());
		
	return SUCCESS;
		
dep_err:
	OscDestroy(&hFramework);
	
	return err;
}
Пример #2
0
/*********************************************************************//*!
 * @brief Initialize framework and system parameters
 *
 * @param s Pointer to the system state 
 *//*********************************************************************/
void initSystem(struct SYSTEM *s)
{
	OscCreate(&s->hFramework);
	
	/******* Load the framework module dependencies. **********/
	OscLoadDependencies(s->hFramework, deps, sizeof(deps)/sizeof(struct OSC_DEPENDENCY));

	OscLogSetConsoleLogLevel(WARN);
	OscLogSetFileLogLevel(WARN);
	
	#if defined(OSC_HOST)
		/* Setup file name reader (for host compiled version); read constant image */
		OscFrdCreate(s->hFramework);
		OscFrdCreateConstantReader(&s->hFileNameReader, "EAN13Example.bmp");
		OscCamSetFileNameReader(s->hFileNameReader);
	#endif
	
	/* Configure camera */
	OscCamPresetRegs();
	/* Set AGC and AEC */
	OscCamSetRegisterValue(REG_AEC_AGC_ENABLE, 0x3);
        /* Turn on continuous capture for this application. */
        OscCamSetRegisterValue(CAM_REG_CHIP_CONTROL, 0x388);
        /* Set the undocumented reserved almighty Micron register to the
           "optimal" value. */
        OscCamSetRegisterValue(CAM_REG_RESERVED_0x20, 0x3d5);

	OscCamSetAreaOfInterest(0, 0, OSC_CAM_MAX_IMAGE_WIDTH, OSC_CAM_MAX_IMAGE_HEIGHT);
	OscCamSetupPerspective(OSC_CAM_PERSPECTIVE_180DEG_ROTATE);

	OscCamSetFrameBuffer(0, OSC_CAM_MAX_IMAGE_WIDTH * OSC_CAM_MAX_IMAGE_HEIGHT, s->frameBuffer1, TRUE); 
	OscCamSetFrameBuffer(1, OSC_CAM_MAX_IMAGE_WIDTH * OSC_CAM_MAX_IMAGE_HEIGHT, s->frameBuffer2, TRUE); 

	s->doubleBufferIDs[0] = 0;
	s->doubleBufferIDs[1] = 1;
	OscCamCreateMultiBuffer(2, s->doubleBufferIDs); 

	OscCamSetupCapture(OSC_CAM_MULTI_BUFFER); 

} /* initSystem */
Пример #3
0
Файл: dma.c Проект: scs/tutorial
/*********************************************************************//*!
 * @brief Program entry.
 * 
 * @param argc Command line argument count.
 * @param argv Command line argument string.
 * @return 0 on success
 *//*********************************************************************/
int main(const int argc, const char * argv[])
{
	/* Handle to framework instance. */
	void *hFramework;
	
	/* Handle to the DMA chain. */
	void *hChain;
	
	/* Dma source and destination pointer. */
	void *src, *dest;
	
	/* Source data field. */
	uint32 source[WIDTH][HEIGHT];
	
	/* Destination data field. */
	uint32 drain[WIDTH][HEIGHT];
	uint32 i,j;
	
	/* Create framework */
	OscCreate(&hFramework);
	
	/* Allocate dma chain */
	OscDmaAllocChain(&hChain);
	
	/* Load dma module */
	OscDmaCreate(hFramework);
	
	/* Compute something and fill source data segment with data */
	/* -------------------------------------------------------- */
	
	/* Add a 2D dma move to the chain (max. 4 moves per chain) */
	src = (void*)&source;
	dest = (void*)&drain;
	
	OscDmaAdd2DMove(hChain, dest, DMA_WDSIZE_32, WIDTH, sizeof(uint32), HEIGHT, sizeof(uint32), src, DMA_WDSIZE_32, WIDTH, sizeof(uint32), HEIGHT, sizeof(uint32));
	OscDmaAddSyncPoint(hChain);
	
	/* Start dma transfer */
	OscDmaStart(hChain);
	
	/* DMA transfer in progress... compute something else. */
	/* --------------------------------------------------- */
	
	/* Sync with dma transfer */
	OscDmaSync(hChain);
	
	/* Compare source and drain.. print if difference detected */
	for (i=0; i<HEIGHT; i++){
		for ( j=0; j<WIDTH; j++){
			if (source[j][i] != drain[j][i]){
				printf("x=%lu y=%lu data=%lu final%lu\n",j,i,source[j][i],drain[j][i]);
			}
		}
	}
	printf("Dma transfer done!!!\n");
	
	/* Unload dma module */
	OscDmaDestroy(hFramework);
	
	/* Destroy framework */
	OscDestroy(hFramework);
	
	return 0;
}
Пример #4
0
/*********************************************************************//*!
 * @brief Initialize everything so the application is fully operable
 * after a call to this function.
 *
 * @return SUCCESS or an appropriate error code.
 *//*********************************************************************/
static OSC_ERR init(const int argc, const char * argv[])
{
	OSC_ERR err = SUCCESS;
	uint8 multiBufferIds[2] = {0, 1};

	memset(&data, 0, sizeof(struct TEMPLATE));

	/******* Create the framework **********/
	err = OscCreate(&data.hFramework);
	if (err < 0)
	{
		fprintf(stderr, "%s: Unable to create framework.\n", __func__);
		return err;
	}

	/******* Load the framework module dependencies. **********/
	err = OscLoadDependencies(data.hFramework, deps, sizeof(deps)/sizeof(struct OSC_DEPENDENCY));

	if (err != SUCCESS)
	{
		fprintf(stderr, "%s: ERROR: Unable to load dependencies! (%d)\n", __func__, err);
		goto dep_err;
	}

	/********* Seed the random generator *************/
	srand(OscSupCycGet());

#if defined(OSC_HOST) || defined(OSC_SIM)
	err = OscFrdCreateConstantReader(&data.hFileNameReader, TEST_IMAGE_FN);
	if (err != SUCCESS)
	{
		OscLog(ERROR, "%s: Unable to create constant file name reader for %s! (%d)\n", __func__, TEST_IMAGE_FN, err);
		goto frd_err;
	}
	err = OscCamSetFileNameReader(data.hFileNameReader);
	if (err != SUCCESS)
	{
		OscLog(ERROR, "%s: Unable to set file name reader for camera! (%d)\n", __func__, err);
		goto frd_err;
	}
#endif /* OSC_HOST or OSC_SIM */

	/* Set the camera registers to sane default values. */
	err = OscCamPresetRegs();
	if (err != SUCCESS)
	{
		OscLog(ERROR, "%s: Unable to preset camera registers! (%d)\n", __func__, err);
		goto fb_err;
	}

	/* Set up two frame buffers with enough space for the maximum
	 * camera resolution in cached memory. */
	err = OscCamSetFrameBuffer(0, OSC_CAM_MAX_IMAGE_WIDTH*OSC_CAM_MAX_IMAGE_HEIGHT, data.u8FrameBuffers[0], TRUE);
	if (err != SUCCESS)
	{
		OscLog(ERROR, "%s: Unable to set up first frame buffer!\n", __func__);
		goto fb_err;
	}
	err = OscCamSetFrameBuffer(1, OSC_CAM_MAX_IMAGE_WIDTH*OSC_CAM_MAX_IMAGE_HEIGHT, data.u8FrameBuffers[1], TRUE);
	if (err != SUCCESS)
	{
		OscLog(ERROR, "%s: Unable to set up second frame buffer!\n", __func__);
		goto fb_err;
	}

	/* Create a double-buffer from the frame buffers initilalized above.*/
	err = OscCamCreateMultiBuffer(2, multiBufferIds);
	if (err != SUCCESS)
	{
		OscLog(ERROR, "%s: Unable to set up multi buffer!\n", __func__);
		goto mb_err;
	}

	/* Register an IPC channel to the CGI for the user interface. */
	err = OscIpcRegisterChannel(&data.ipc.ipcChan, USER_INTERFACE_SOCKET_PATH, F_IPC_SERVER | F_IPC_NONBLOCKING);
	if (err != SUCCESS)
	{
		OscLog(ERROR, "%s: Unable to initialize IPC channel to web interface! (%d)\n", __func__, err);
		goto ipc_err;
	}

	err |= OscCamPerspectiveStr2Enum("DEFAULT", &data.perspective);
	if ( err != SUCCESS)
	{
		OscLog(ERROR, "%s: Invalid camera perspective.\n", __func__);
		goto per_err;
	}
	OscCamSetupPerspective( data.perspective);

	return SUCCESS;

per_err:
ipc_err:
mb_err:
fb_err:
#if defined(OSC_HOST) || defined(OSC_SIM)
frd_err:
#endif
	OscUnloadDependencies(data.hFramework, deps, sizeof(deps)/sizeof(struct OSC_DEPENDENCY));
dep_err:
	OscDestroy(&data.hFramework);

	return err;
}
Пример #5
0
/*********************************************************************//*!
 * @brief Initialize everything so the application is fully operable
 * after a call to this function.
 * 
 * @return SUCCESS or an appropriate error code.
 *//*********************************************************************/
static OSC_ERR init(const int argc, const char * argv[])
{
    OSC_ERR err = SUCCESS;
    uint8 multiBufferIds[2] = {0, 1};
    char strVersion[15]; 
    struct CFG_KEY configKey;
    struct CFG_VAL_STR strCfg;
#ifdef HAS_CPLD
    uint16 exposureDelay;
#endif /* HAS_CPLD */	
    memset(&data, 0, sizeof(struct DATA));
	
    /* Print software version */
    GetVersionString( strVersion); 
	fprintf(stderr, "Software rich-view version: %s\n", strVersion); 	
	
    /******* Create the framework **********/
    err = OscCreate(&data.hFramework);
    if (err < 0)
    {
    	fprintf(stderr, "%s: Unable to create framework.\n", __func__);
    	return err;
    }
	
    /******* Load the framework module dependencies. **********/
    err = OscLoadDependencies(data.hFramework, deps, sizeof(deps)/sizeof(struct OSC_DEPENDENCY));
    
    if (err != SUCCESS)
    {
    	fprintf(stderr, "%s: ERROR: Unable to load dependencies! (%d)\n", __func__, err);
    	goto dep_err;
    }

    /* Set logging levels */
    OscLogSetConsoleLogLevel(INFO);
    OscLogSetFileLogLevel(DEBUG);

    /* Print framework version */
    OscGetVersionString( strVersion);    
    OscLog(INFO, "Oscar framework version: %s\n", strVersion);

	/* Disable watchdog (probably activated from previous application) */
	OscSupWdtInit();
	OscSupWdtClose();
	
	/* Set LED to green, util the idle state is entered */
	OscGpioSetTestLed( TRUE);       
	OscGpioSetTestLedColor(FALSE, TRUE); /* R, G*/ 	

    /* Register configuration file */
    err = OscCfgRegisterFile(&data.hConfig, CONFIG_FILE_NAME, CONFIG_FILE_SIZE);
    if (err != SUCCESS)
    {
    	OscLog(ERROR, "Cannot access config file.\n");
    	goto cfg_err;
    } 
    

    /* Get perspective setting from config file- */
    configKey.strSection = NULL;
    configKey.strTag = "PER";
   
    strcpy( strCfg.str, "");    
    err = OscCfgGetStr( data.hConfig, 
            &configKey, 
            &strCfg);    

    err |= OscCamPerspectiveStr2Enum( strCfg.str, &data.perspective);  
    if( err != SUCCESS)
    {
        OscLog(WARN, 
                 "%s: No (valid) camera-scene perspective configured (%s). "
                 "Use default (%s).\n",
                 __func__, strCfg.str, OSC_CAM_PERSPECTIVE_DEFAULT);
		data.perspective = OSC_CAM_PERSPECTIVE_DEFAULT;
    }             


    /* Get exposure time setting from configuration. */            
    configKey.strSection = NULL;
    configKey.strTag = "EXP";
    err = OscCfgGetUInt32( data.hConfig,
            &configKey, 
            &data.exposureTime);    
    
    if( err != SUCCESS)
    {
        OscLog(WARN, 
                "%s: No (valid) Exposure Time defined in configuration (%d). "
                "Use default (%d).\n",
                __func__, data.exposureTime, DEFAULT_EXPOSURE_TIME);
        data.exposureTime = DEFAULT_EXPOSURE_TIME;
    }  

#ifdef HAS_CPLD		
    /* Get exposure delay setting from configuration. */            
    configKey.strSection = NULL;
    configKey.strTag = "DEL";
    err = OscCfgGetUInt16Range( data.hConfig,
            &configKey, 
            &exposureDelay, 
            0, 
            FINECLK2CLK_RATIO-1);    
    data.exposureDelay = exposureDelay & 0x00ff;
    if( err != SUCCESS)
    {
        OscLog(WARN, 
                "%s: No (valid) Exposure Delay defined in configuration (%d). "
                "Use default (%d).\n",
                __func__, data.exposureDelay, DEFAULT_EXPOSURE_DELAY);
        data.exposureDelay = DEFAULT_EXPOSURE_DELAY;
    }  
#endif /* HAS_CPLD */	
	
	
#ifdef HAS_CPLD	
	/* Get firmware version */
	err = OscCpldRget(OSC_LGX_FWREV, &data.firmwareRevision);	
	if(err != SUCCESS)
	{
	        OscLog(ERROR, "Cannot read firmware version. (%d)\n", err);
		goto cpld_err;
	}	

	/* Apply exposure delay to CPLD and disable. */
	err = OscCpldRset(OSC_LGX_CLKDELAY, 
		(const uint8)(data.exposureDelay & !OSC_LGX_CLKDELAY_ENABLE));		
	if(err != SUCCESS)
	{
		OscLog(ERROR, "Cannot disable clock-delay in CPLD.\n");
		goto cpld_err;
	}
	/* Set CPLD to synchronous mode. */
	err = OscCpldFset(OSC_LGX_VARCTRL, OSC_LGX_VARCTRL_SYNCOUT, OSC_LGX_VARCTRL_SYNCOUT);	
	if(err != SUCCESS)
	{
		OscLog(ERROR, "Cannot set CPLD to synchronous mode.\n");
		goto cpld_err;
	}
#endif /* HAS_CPLD */	
	
	

	/* Set the camera registers to sane default values. */
	err = OscCamPresetRegs();
	if (err != SUCCESS)
	{
		OscLog(ERROR, "%s: Unable to preset camera registers! (%d)\n", __func__, err);
		goto cam_err;
	}
	
	/* Set up two frame buffers with enough space for the maximum
	 * camera resolution in cached memory. */
	err = OscCamSetFrameBuffer(0, IMAGE_AERA, data.u8FrameBuffers[0], TRUE);
	if (err != SUCCESS)
	{
		OscLog(ERROR, "%s: Unable to set up first frame buffer!\n", __func__);
		goto cam_err;
	}
	err = OscCamSetFrameBuffer(1, IMAGE_AERA, data.u8FrameBuffers[1], TRUE);
	if (err != SUCCESS)
	{
		OscLog(ERROR, "%s: Unable to set up second frame buffer!\n", __func__);
		goto cam_err;
	}
	
	/* Create a double-buffer from the frame buffers initilalized above.*/
	err = OscCamCreateMultiBuffer(2, multiBufferIds);
	if (err != SUCCESS)
	{
		OscLog(ERROR, "%s: Unable to set up multi buffer!\n", __func__);
		goto mb_err;
	}
	
	OscCamSetupPerspective( data.perspective);

	/* Make the register file known to the communication protocol. */
	data.comm.pRegFile = regfile;
	data.comm.nRegs = (sizeof(regfile)/sizeof(struct CBP_PARAM));

	/* Init communication sockets. */
	err = Comm_Init(&data.comm);
	if (err != SUCCESS)
	{
		OscLog(ERROR, "Communication initialization failed.\n");
		goto comm_err;		
	}	
	
	return SUCCESS;
	
comm_err:    
cfg_err:
#ifdef HAS_CPLD	
cpld_err:
#endif /* HAS_CPLD */
mb_err:
cam_err:
    OscUnloadDependencies(data.hFramework,
            deps,
            sizeof(deps)/sizeof(struct OSC_DEPENDENCY));
dep_err:
	OscDestroy(&data.hFramework);
	
	return err;
}
Пример #6
0
Файл: cfg.c Проект: scs/tutorial
/*********************************************************************//*!
 * @brief Program entry.
 * 
 * @param argc Command line argument count.
 * @param argv Command line argument string.
 * @return 0 on success
 *//*********************************************************************/
int main(const int argc, const char * argv[])
{
	void *hFramework;
	struct CFG_KEY key;
	struct CFG_VAL_STR val;
	int16 number1;
	int32 number2;
	
	char strNumber[10];
	
	/* Handle to the config file */
	CFG_FILE_CONTENT_HANDLE hCfg;
	const char fileName[] = "config.txt";
	
	/* Create framework */
	OscCreate(&hFramework);
	
	/* Initialize config module */
	OscCfgCreate(hFramework);
	
	/* Register config file */
	OscCfgRegisterFile(&hCfg, fileName, 1024);
	
	/* Set config file section (global if NULL) */
	key.strSection = NULL;
	
	/* Read value of tag NAME from global section */
	key.strTag = "NAME";
	OscCfgGetStr(hCfg, &key, &val);
	printf("NAME: %s\n",(char*)&val);
	
	/* Read 16 bit integer */
	key.strTag = "16BIT";
	OscCfgGetInt(hCfg, &key, &number1);
	printf("16BIT: %d\n",number1);
	
	/* Read 32 bit integer */
	key.strTag = "32BIT";
	OscCfgGetInt32(hCfg, &key, &number2);
	printf("32Bit: %ld\n",number2);
	
	/* Write new section, tag and value */
	key.strSection = "NEWSECTION";
	key.strTag = "NEWTAG";
	OscCfgSetStr(hCfg, &key, "newvalue");
	
	/* Write new 32 bit integer */
	key.strTag = "NEW32BIT";
	sprintf(strNumber,"%ld",-number2);
	OscCfgSetStr(hCfg, &key, strNumber);
	
	/* Write changes to disk */
	OscCfgFlushContent(hCfg);
	
	/* Destroy support module */
	OscCfgDestroy(hFramework);
	
	/* Destroy framework */
	OscDestroy(hFramework);
	
	return 0;
}
Пример #7
0
Файл: cam.c Проект: scs/tutorial
/*********************************************************************//*!
 * @brief Program entry.
 * 
 * @param argc Command line argument count.
 * @param argv Command line argument string.
 * @return 0 on success
 *//*********************************************************************/
int main(const int argc, const char * argv[])
{
	/* Handle to framework instance. */
	void *hFramework;
	
#if defined(OSC_HOST) || defined(OSC_SIM)
	/* Handle to file name reader, if compiled for host platform. */
	void *hFileNameReader;
#endif
	
	/* Camera parameters */
	uint32 shutterWidth;
	uint16 x, y, width, height;
	uint16 blackOffset;
	uint8 bufferIDs[2];
	
	/* Frame buffers. */
	uint8 frameBuffer0[OSC_CAM_MAX_IMAGE_WIDTH * OSC_CAM_MAX_IMAGE_HEIGHT];
	uint8 frameBuffer1[OSC_CAM_MAX_IMAGE_WIDTH * OSC_CAM_MAX_IMAGE_HEIGHT];
	
	/* Pointer to captured picture */
	void *pic;
	
	struct OSC_PICTURE p;
	
	OSC_ERR err = SUCCESS;
	
	/* Create framework */
	OscCreate(&hFramework);
	
	/* Load camera module */
	OscCamCreate(hFramework);

	/* Load GPIO module */
	OscGpioCreate(hFramework);

	p.width = OSC_CAM_MAX_IMAGE_WIDTH;
	p.height = OSC_CAM_MAX_IMAGE_HEIGHT;
	p.type = OSC_PICTURE_GREYSCALE;
	
	/* Get camera settings */
	OscCamGetShutterWidth(&shutterWidth);
	OscCamGetAreaOfInterest(&x, &y, &width, &height);
	OscCamGetBlackLevelOffset(&blackOffset);
	printf("ShutterWidth=%lu\n",shutterWidth);
	printf("AreaOfInterest: x=%u y=%u width=%u height=%u\n", x, y, width, height);
	printf("BlackLevelOffset=%u\n",blackOffset);
	
	/* Process settings */
	/* ---------------- */
	
	/* Set new camera settings */
	shutterWidth = 50000; /* set shutter to 50ms, 0 => automatic */
	OscCamSetShutterWidth(shutterWidth);
	OscCamSetAreaOfInterest(0,0,OSC_CAM_MAX_IMAGE_WIDTH, OSC_CAM_MAX_IMAGE_HEIGHT);
	OscCamSetBlackLevelOffset(blackOffset);
	OscCamSetupPerspective(OSC_CAM_PERSPECTIVE_VERTICAL_MIRROR);
	
#if defined(OSC_HOST) || defined(OSC_SIM)
	/* Setup file name reader if compiled for host platform */
	OscFrdCreateConstantReader(&hFileNameReader, "imgCapture.bmp");
	OscCamSetFileNameReader(hFileNameReader);
#endif
	
	/* Setup framebuffers - double buffering */
	OscCamSetFrameBuffer(0, OSC_CAM_MAX_IMAGE_WIDTH*OSC_CAM_MAX_IMAGE_HEIGHT, frameBuffer0, TRUE);
	OscCamSetFrameBuffer(1, OSC_CAM_MAX_IMAGE_WIDTH*OSC_CAM_MAX_IMAGE_HEIGHT, frameBuffer1, TRUE);
	bufferIDs[0] = 0;
	bufferIDs[1] = 1;
	OscCamCreateMultiBuffer(2, bufferIDs);
	
	/* Setup capture to first frame buffer */
	err = OscCamSetupCapture(OSC_CAM_MULTI_BUFFER);
	if(err != SUCCESS){
		printf("%s: Unable to setup initial capture (%d)!\n", __func__, err);
		return err;
	}

	/* Trigger image capturing */
	err = OscGpioTriggerImage();
	if(err != SUCCESS){
		printf("%s: Unable to trigger capture (%d)!\n", __func__, err);
		return err;
	}
	
	/* Do something ... */
	/* ---------------- */
	
	/* Read Picture */
	err = OscCamReadPicture(OSC_CAM_MULTI_BUFFER, (void *) &pic, 0, 0);
	if(err != SUCCESS){
		printf("%s: Unable to read picture (%d)!\n", __func__, err);
		return err;
	}
	
	/* Process picture */
	/* --------------- */
	
	/* Capture picture to second frame buffer */
	err = OscCamSetupCapture(OSC_CAM_MULTI_BUFFER);
	if(err != SUCCESS){
		printf("%s: Unable to setup initial capture (%d)!\n", __func__, err);
		return err;
	}
	
	/* Do something ... */
	/* ---------------- */
	
	err = OscCamReadPicture(OSC_CAM_MULTI_BUFFER, (void *) &pic, 0, 0);
	if(err != SUCCESS){
		printf("%s: Unable to read picture (%d)!\n", __func__, err);
		return err;
	}
	
	/* Process picture */
	/* --------------- */
	
	/* Unload camera module */
	OscCamDestroy(hFramework);

	/* Unload GPIO module */
	OscGpioDestroy(hFramework);
	
	/* Destroy framework */
	OscDestroy(hFramework);
	
	return 0;
}