コード例 #1
0
ファイル: lua.c プロジェクト: tecywiz121/plugins
//
// Loader Interface
//
int create(void)
{
    if (!states)
    {
        states = kh_init(m32);
    }

    lua_State* l = luaL_newstate();
    openlualibs(l);
    regluafuncs(l);

    struct instance *inst = instance_init(l);

    // Find an unused key
    int ret = 0;
    int id = -1;
    khint_t key;
    do
    {
        id = _nextid++;
        key = kh_put(m32, states, id, &ret);
    } while (0 == ret);

    if (ret > 0)
    {
        kh_value(states, key) = inst;
        return id;
    }
    else
    {
        return 0;
    }
}
コード例 #2
0
ファイル: service.c プロジェクト: asac/procd
static void
service_instance_add(struct service *s, struct blob_attr *attr)
{
	struct service_instance *in;

	if (blobmsg_type(attr) != BLOBMSG_TYPE_TABLE)
		return;

	in = calloc(1, sizeof(*in));
	if (!in)
		return;

	instance_init(in, s, attr);
	vlist_add(&s->instances, &in->node, (void *) in->name);
}
コード例 #3
0
static void
nv50_draw_arrays_instanced(struct pipe_context *pipe,
			   unsigned mode, unsigned start, unsigned count,
			   unsigned startInstance, unsigned instanceCount)
{
	struct nv50_context *nv50 = nv50_context(pipe);
	struct nouveau_channel *chan = nv50->screen->tesla->channel;
	struct nouveau_grobj *tesla = nv50->screen->tesla;
	struct instance a[16];
	unsigned prim = nv50_prim(mode);

	instance_init(nv50, a, startInstance);
	if (!nv50_state_validate(nv50, 10 + 16*3))
		return;

	if (nv50->vbo_fifo) {
		nv50_push_elements_instanced(pipe, NULL, 0, 0, mode, start,
					     count, startInstance,
					     instanceCount);
		return;
	}

	BEGIN_RING(chan, tesla, NV50TCL_CB_ADDR, 2);
	OUT_RING  (chan, NV50_CB_AUX | (24 << 8));
	OUT_RING  (chan, startInstance);
	while (instanceCount--) {
		if (AVAIL_RING(chan) < (7 + 16*3)) {
			FIRE_RING(chan);
			if (!nv50_state_validate(nv50, 7 + 16*3)) {
				assert(0);
				return;
			}
		}
		instance_step(nv50, a);

		BEGIN_RING(chan, tesla, NV50TCL_VERTEX_BEGIN, 1);
		OUT_RING  (chan, prim);
		BEGIN_RING(chan, tesla, NV50TCL_VERTEX_BUFFER_FIRST, 2);
		OUT_RING  (chan, start);
		OUT_RING  (chan, count);
		BEGIN_RING(chan, tesla, NV50TCL_VERTEX_END, 1);
		OUT_RING  (chan, 0);

		prim |= (1 << 28);
	}
}
コード例 #4
0
ファイル: _instance.c プロジェクト: herd/herdtools
static void init_global(global_t *g,int id) {
  if (id == 0) {
#ifdef TIMELIMIT
    /* Starting time */
    g->start = timeofday() ;
#endif
    /* Global barrier */
    barrier_init(&g->gb,AVAIL) ;
    /* Align  to cache line */
    uintptr_t x = (uintptr_t)(g->mem) ;
    x += LINE-1 ; x /=  LINE ; x *= LINE ;
    intmax_t *m = (intmax_t *)x ;
    /* Instance contexts */
    for (int k = 0 ; k < NEXE ; k++) {
      instance_init(&g->ctx[k],k,m) ;
      m += NVARS*LINESZ ;
    }
    mbar() ;
    g->go = 1 ;
  } else {
    while (g->go == 0) ;
    mbar() ;
  }
}
コード例 #5
0
int main(int argc, char *argv[])
{
    fcs_dbm_variant_type_t local_variant = FCS_DBM_VARIANT_2FC_FREECELL;
    const long delta_limit = 100000;
    const int max_num_elements_in_cache = 8000000;
    const char *filename = argv[1];
    FILE *const fh = fopen(filename, "r");
    if (fh == NULL)
    {
        fc_solve_err("Could not open file '%s' for input.\n", filename);
    }
    const fcs_user_state_str_t user_state = read_state(fh);
    fcs_state_keyval_pair_t init_state_pair;
    fc_solve_initial_user_state_to_c(
        user_state.s, &init_state_pair, FREECELLS_NUM, STACKS_NUM, 1, NULL);

    fcs_dbm_solver_instance_t instance;

    instance_init(
        &instance, local_variant, &init_state_pair, max_num_elements_in_cache);

#define LOG_FILENAME "fc-solve-pseudo-dfs.log.txt"

    {
        FILE *const last_line_fh = popen(("tail -1 " LOG_FILENAME), "r");

        if (last_line_fh)
        {
            long count_num_processed;
            if (fscanf(last_line_fh, "At %ld iterations Coords=[",
                    &count_num_processed) == 1)
            {
                instance__load_coords_from_fh(&instance, last_line_fh);
                /*
                 * instance__inspect_new_state increments count_num_processed
                 * so let's set it after loading the coordinates.
                 * */
                instance.count_num_processed = count_num_processed;
            }
        }
        pclose(last_line_fh);
    }

    instance.max_count_num_processed =
        instance.count_num_processed + delta_limit;

    while (instance.max_count_num_processed % delta_limit != 0)
    {
        instance.max_count_num_processed +=
            delta_limit - (instance.max_count_num_processed % delta_limit);
    }

    while (instance.should_terminate == DONT_TERMINATE)
    {
        instance_run(&instance);

        FILE *const log_fh = fopen(LOG_FILENAME, "at");
        instance__print_coords_to_log(&instance, log_fh);
        fclose(log_fh);

        instance.max_count_num_processed =
            instance.count_num_processed + delta_limit;
    }

    if (instance.should_terminate == SOLUTION_FOUND_TERMINATE)
    {
        printf("%s\n", "Solution was found.");
    }
    else
    {
        printf("%s\n", "I could not solve it.");
    }

    instance_free(&instance);

    return 0;
}
コード例 #6
0
ファイル: decawave.c プロジェクト: erudisill/decawave-alpha
uint32 inittestapplication(void) {
	uint32 devID;
	instanceConfig_t instConfig;
	int i, result;

	SPI_ConfigFastRate(SPI_BaudRatePrescaler_16);  //max SPI before PLLs configured is ~4M

	i = 10;

	//this is called here to wake up the device (i.e. if it was in sleep mode before the restart)
	devID = instancereaddeviceid();
	printf("devID %08X\r\n", devID);
	//if the read of devide ID fails, the DW1000 could be asleep
	if (DWT_DEVICE_ID != devID) {
//		port_SPIx_clear_chip_select();  //CS low
//		Sleep(1);   //200 us to wake up then waits 5ms for DW1000 XTAL to stabilise
//		port_SPIx_set_chip_select();  //CS high
//		Sleep(7);

		printf("asleep...wakeup!\r\n");
		pio_set_pin_high(DW_WAKEUP_PIO_IDX);
		Sleep(1);
		pio_set_pin_low(DW_WAKEUP_PIO_IDX);
		Sleep(7);

		devID = instancereaddeviceid();
		printf("devID %08X\r\n", devID);
		// SPI not working or Unsupported Device ID
		if (DWT_DEVICE_ID != devID) {
			return (-1);
		}
		//clear the sleep bit - so that after the hard reset below the DW does not go into sleep
		dwt_softreset();
	}

	//reset the DW1000 by driving the RSTn line low
	reset_DW1000();

	result = instance_init();
	if (0 > result)
		return (-2); // Some failure has occurred

	SPI_ConfigFastRate(SPI_BaudRatePrescaler_4); //increase SPI to max
	devID = instancereaddeviceid();
	printf("devID %08X\r\n", devID);

	if (DWT_DEVICE_ID != devID)   // Means it is NOT MP device
			{
		// SPI not working or Unsupported Device ID
		return (-3);
	}

	if (is_tag) {
		instance_mode = TAG;
		led_on(LED_PC7);
	} else {
		instance_mode = ANCHOR;
#if (DR_DISCOVERY == 1)
		led_on(LED_PC6);
#else
		if(instance_anchaddr & 0x1)
		led_on(LED_PC6);

		if(instance_anchaddr & 0x2)
		led_on(LED_PC7);
#endif
	}

	instancesetrole(instance_mode);     // Set this instance role

	if (use_fast2wr) //if fast ranging then initialise instance for fast ranging application
	{
		instance_init_f(instance_mode); //initialise Fast 2WR specific data
		//when using fast ranging the channel config is either mode 2 or mode 6
		//default is mode 2
		dr_mode = decarangingmode();

		if ((dr_mode & 0x1) == 0)
			dr_mode = 1;
	} else {
		instance_init_s(instance_mode);
		dr_mode = decarangingmode();
	}

	instConfig.channelNumber = chConfig[dr_mode].channel;
	instConfig.preambleCode = chConfig[dr_mode].preambleCode;
	instConfig.pulseRepFreq = chConfig[dr_mode].prf;
	instConfig.pacSize = chConfig[dr_mode].pacSize;
	instConfig.nsSFD = chConfig[dr_mode].nsSFD;
	instConfig.sfdTO = chConfig[dr_mode].sfdTO;
	instConfig.dataRate = chConfig[dr_mode].datarate;
	instConfig.preambleLen = chConfig[dr_mode].preambleLength;

	instance_config(&instConfig);                  // Set operating channel etc

#if (DR_DISCOVERY == 0)
	addressconfigure();                            // set up initial payload configuration
#endif
	instancesettagsleepdelay(POLL_SLEEP_DELAY, BLINK_SLEEP_DELAY); //set the Tag sleep time

	//if TA_SW1_2 is on use fast ranging (fast 2wr)
	if (use_fast2wr) {
		//Fast 2WR specific config
		//configure the delays/timeouts
		instance_config_f();
	} else //use default ranging modes
	{
		// NOTE: this is the delay between receiving the blink and sending the ranging init message
		// The anchor ranging init response delay has to match the delay the tag expects
		// the tag will then use the ranging response delay as specified in the ranging init message
		// use this to set the long blink response delay (e.g. when ranging with a PC anchor that wants to use the long response times != 150ms)
		if (use_long_blink_delay) {
			instancesetblinkreplydelay(FIXED_LONG_BLINK_RESPONSE_DELAY);
		} else //this is for ARM to ARM tag/anchor (using normal response times 150ms)
		{
			instancesetblinkreplydelay(FIXED_REPLY_DELAY);
		}

		//set the default response delays
		instancesetreplydelay(FIXED_REPLY_DELAY, 0);
	}

//    return devID;
	return 0;
}
コード例 #7
0
ファイル: main.c プロジェクト: janicijevic82/pokusaj
uint32 inittestapplication(uint8 s1switch)
{
    uint32 devID ;
    instanceConfig_t instConfig;
    int result;

    SPI_ConfigFastRate(SPI_BaudRatePrescaler_32);  //max SPI before PLLs configured is ~4M

    //this is called here to wake up the device (i.e. if it was in sleep mode before the restart)
    devID = instancereaddeviceid() ;
    if(DWT_DEVICE_ID != devID) //if the read of device ID fails, the DW1000 could be asleep
    {
        port_SPIx_clear_chip_select();  //CS low
        Sleep(1);   //200 us to wake up then waits 5ms for DW1000 XTAL to stabilise
        port_SPIx_set_chip_select();  //CS high
        Sleep(7);
        devID = instancereaddeviceid() ;
        // SPI not working or Unsupported Device ID
        if(DWT_DEVICE_ID != devID)
            return(-1) ;
        //clear the sleep bit - so that after the hard reset below the DW does not go into sleep
        dwt_softreset();
    }

    //reset the DW1000 by driving the RSTn line low
    reset_DW1000();

    result = instance_init() ;
    if (0 > result) return(-1) ; // Some failure has occurred

    SPI_ConfigFastRate(SPI_BaudRatePrescaler_4); //increase SPI to max
    devID = instancereaddeviceid() ;

    if (DWT_DEVICE_ID != devID)   // Means it is NOT MP device
    {
        // SPI not working or Unsupported Device ID
        return(-1) ;
    }


    if(s1switch & SWS1_ANC_MODE)
    {
        instance_mode = ANCHOR;

        led_on(LED_PC6);

    }
    else
    {
        instance_mode = TAG;
        led_on(LED_PC7);
    }

    instancesetrole(instance_mode) ;     // Set this instance role

    instance_init_s(instance_mode);
    dr_mode = decarangingmode(s1switch);

    instConfig.channelNumber = chConfig[dr_mode].channel ;
    instConfig.preambleCode = chConfig[dr_mode].preambleCode ;
    instConfig.pulseRepFreq = chConfig[dr_mode].prf ;
    instConfig.pacSize = chConfig[dr_mode].pacSize ;
    instConfig.nsSFD = chConfig[dr_mode].nsSFD ;
    instConfig.sfdTO = chConfig[dr_mode].sfdTO ;
    instConfig.dataRate = chConfig[dr_mode].datarate ;
    instConfig.preambleLen = chConfig[dr_mode].preambleLength ;


    instance_config(&instConfig) ;                  // Set operating channel etc

    instancesettagsleepdelay(POLL_SLEEP_DELAY, BLINK_SLEEP_DELAY); //set the Tag sleep time

    instance_init_timings();

    return devID;
}
コード例 #8
0
ファイル: master.c プロジェクト: getmoon/vmsync
int main(int argc , char ** argv)
{
	int				ret;
	int				i;
	struct config_instance_t *	inst;
	char				dir_name[128];
	
	if( 	argc != 7 ||
		str_unequal(argv[1] , "-p") ||
		file_unexist(argv[2]) ||
		str_unequal(argv[3] , "-t") ||
		isnotnumber(argv[4])  ||
		str_unequal(argv[5] , "-c") 
	){
		usage();
		exit(0);
	}

	resource_init();

	sprintf(sync_work_dir , "%s" , argv[2]);
	sync_period = atoi(argv[4]);
	sprintf(config_file , "%s" , argv[6]);

	memset(dir_name, 0, 128);
	sprintf(dir_name, "%s/lock/", sync_work_dir);
	if (access(dir_name, F_OK)){
	        ret = mkdir(dir_name, 0777);
	        if (ret < 0){
	                print_error("Create directory %s error" , dir_name);
	                return ret;
	        }
	}
	
	memset(dir_name, 0, 128);
	sprintf(dir_name, "%s/send/", sync_work_dir);
	if (access(dir_name, F_OK)){
	        ret = mkdir(dir_name, 0777);
	        if (ret < 0){
	                print_error("Create directory %s error" , dir_name);
	                return ret;
	        }
	}


	ret = config_init(config_file);
	if(ret < 0){
		print_error("config file init fail\n");
		exit(0);
	}

	for(i = 0 ; i < INSTANCE_MAX_CNT ; i++){
		inst = instance_base + i;	
		if(inst->use == 0)
			continue;
		
		instance_init(inst);	
	}

	while(1){
		sleep(3600);
	}

	return(0);
}