Exemplo n.º 1
0
	bool dto_complex::parse( const rapidjson::Value& json )
	{
		if( json.IsObject() && json.HasMember( key() ) && json[key()].IsObject() )
		{
			for( auto& child : get_children() )
			{
				child->set_client( client() );
				if( !child->parse( json[key()] ) && !optional() )
				{
					return false;
				}
			}
			
			return true;
		}
		else if( json.IsObject() )
		{
			for( auto& child : get_children() )
			{
				child->set_client( client() );
				if( !child->parse( json ) && !optional()  )
				{
					return false;
				}
			}
			
			return true;
		}

		set_present( false );
		return optional();
	}
Exemplo n.º 2
0
void setup_routes(int argc, char **argv)
{
    errval_t err;
    struct monitor_binding *st = get_monitor_binding();

    /* printf("%s: setup_routes\n", argv[0]); */

    /* Set core id */
    my_core_id = disp_get_core_id();
    strcpy(my_name, argv[0]);

    // Get number of cores
    coreid_t cores = atoi(argv[1]);

    // Get list of present cores
    for(int i = 3; i < argc; i++) {
        set_present(argv[i]);
    }

    if (strcmp(argv[argc - 1], "dummy")) { /* bsp core */
        // Spawn all copies
        bsp_id = my_core_id;

        /* Spawn on all cores */
        char *spawnargv[argc + 2];
        for (int i = 0; i < argc; i++) {
            spawnargv[i] = argv[i];
        }
        spawnargv[argc] = "dummy";
        spawnargv[argc + 1] = NULL;
        for(coreid_t i = 0; i < MAX_CPUS; i++) {
            if(core_present[i] && i != my_core_id) {
                err = spawn_program(i, my_name, spawnargv, NULL,
                                    SPAWN_FLAGS_DEFAULT, NULL);
                assert(err_is_ok(err));
            }
        }
    }

    /* printf("%s: exporting service\n", argv[0]); */
    /* Setup a server */
    request_done = false;
    err = rcce_export(NULL, _listening, _connected, get_default_waitset(),
                      IDC_EXPORT_FLAGS_DEFAULT);
    if (err_is_fail(err)) {
        DEBUG_ERR(err, "rcce_export failed");
        abort();
    }
    while (!request_done) {
        event_dispatch(get_default_waitset());
    }

    if (strcmp(argv[argc - 1], "dummy")) { /* bsp core */
        for (coreid_t i = 0; i < MAX_CPUS; i++) {
            /* Connect to all cores */
            if (core_present[i] && i != my_core_id && barray[i] == NULL) {
                /* printf("%s: connecting to core %d\n", argv[0], i); */
                connect(i);
            }
        }
    } else {
        /* printf("%s: waiting for connection\n", argv[0]); */
        // Wait for an incoming connection request
        while(connect_request == NULL) {
            event_dispatch(get_default_waitset());
        }

        /* Connect to all cores to which we have not connected already */
        for (coreid_t i = 0; i < MAX_CPUS; i++) {
            if (core_present[i] && i != my_core_id && barray[i] == NULL) {
                /* printf("%s: slave connecting to core %d\n", argv[0], i); */
                connect(i);
            }
        }

        /* printf("%s: sending connect reply\n", argv[0]); */
        // Send the reply back
        err = connect_request->tx_vtbl.
            error_reply(connect_request, NOP_CONT, SYS_ERR_OK, connect_state);
        if (err_is_fail(err)) {
            DEBUG_ERR(err, "init_reply failed");
            abort();
        }
    }

    /* printf("%s: done\n", argv[0]); */

    // Determine maximum core ID
    coreid_t maxcore = 0;
    for(coreid_t i = 0; i < MAX_CPUS; i++) {
        if(core_present[i]) {
            maxcore = i;
        }
    }

    barriers_init(maxcore + 1);
}
Exemplo n.º 3
0
/*
 * Motion Sense Task
 * Requirement: motion_sensors[] are defined in board.c file.
 * Two (minimium) Accelerometers:
 *    1 in the A/B(lid, display) and 1 in the C/D(base, keyboard)
 * Gyro Sensor (optional)
 */
void motion_sense_task(void)
{
	int i, ret, wait_us, fifo_flush_needed = 0;
	timestamp_t ts_begin_task, ts_end_task;
	uint32_t event = 0;
	uint16_t ready_status;
	struct motion_sensor_t *sensor;
#ifdef CONFIG_LID_ANGLE
	const uint16_t lid_angle_sensors = ((1 << CONFIG_LID_ANGLE_SENSOR_BASE)|
					    (1 << CONFIG_LID_ANGLE_SENSOR_LID));
#endif
#ifdef CONFIG_ACCEL_FIFO
	timestamp_t ts_last_int;
#endif
#ifdef CONFIG_LPC
	int sample_id = 0;
	uint8_t *lpc_status;
	uint16_t *lpc_data;

	lpc_status = host_get_memmap(EC_MEMMAP_ACC_STATUS);
	lpc_data = (uint16_t *)host_get_memmap(EC_MEMMAP_ACC_DATA);
	set_present(lpc_status);
#endif

#ifdef CONFIG_ACCEL_FIFO
	ts_last_int = get_time();
#endif
	do {
		ts_begin_task = get_time();
		ready_status = 0;
		for (i = 0; i < motion_sensor_count; ++i) {

			sensor = &motion_sensors[i];

			/* if the sensor is active in the current power state */
			if (SENSOR_ACTIVE(sensor)) {
				if (sensor->state != SENSOR_INITIALIZED) {
					continue;
				}

				ts_begin_task = get_time();
				ret = motion_sense_process(sensor, event,
						&ts_begin_task,
						&fifo_flush_needed);
				if (ret != EC_SUCCESS)
					continue;
				ready_status |= (1 << i);
			}
		}

#ifdef CONFIG_GESTURE_DETECTION
		/* Run gesture recognition engine */
		gesture_calc();
#endif
#ifdef CONFIG_LID_ANGLE
		/*
		 * Check to see that the sensors required for lid angle
		 * calculation are ready.
		 */
		ready_status &= lid_angle_sensors;
		if (ready_status == lid_angle_sensors)
			motion_lid_calc();
#endif
#ifdef CONFIG_CMD_ACCEL_INFO
		if (accel_disp) {
			CPRINTF("[%T event 0x%08x ", event);
			for (i = 0; i < motion_sensor_count; ++i) {
				sensor = &motion_sensors[i];
				CPRINTF("%s=%-5d, %-5d, %-5d ", sensor->name,
					sensor->xyz[X],
					sensor->xyz[Y],
					sensor->xyz[Z]);
			}
#ifdef CONFIG_LID_ANGLE
			CPRINTF("a=%-4d", motion_lid_get_angle());
#endif
			CPRINTF("]\n");
		}
#endif
#ifdef CONFIG_LPC
		update_sense_data(lpc_status, lpc_data, &sample_id);
#endif

		ts_end_task = get_time();
#ifdef CONFIG_ACCEL_FIFO
		/*
		 * Ask the host to flush the queue if
		 * - a flush event has been queued.
		 * - the queue is almost full,
		 * - we haven't done it for a while.
		 */
		if (fifo_flush_needed ||
		    event & TASK_EVENT_MOTION_ODR_CHANGE ||
		    queue_space(&motion_sense_fifo) < CONFIG_ACCEL_FIFO_THRES ||
		    (accel_interval > 0 &&
		     (ts_end_task.val - ts_last_int.val) > accel_interval)) {
			if (!fifo_flush_needed)
				motion_sense_insert_timestamp();
			fifo_flush_needed = 0;
			ts_last_int = ts_end_task;
#ifdef CONFIG_MKBP_EVENT
			/*
			 * We don't currently support wake up sensor.
			 * When we do, add per sensor test to know
			 * when sending the event.
			 */
			if (sensor_active == SENSOR_ACTIVE_S0)
				mkbp_send_event(EC_MKBP_EVENT_SENSOR_FIFO);
#endif
		}
#endif
		if (accel_interval > 0) {
			/*
			 * Delay appropriately to keep sampling time
			 * consistent.
			 */
			wait_us = accel_interval -
				(ts_end_task.val - ts_begin_task.val);

			/*
			 * Guarantee some minimum delay to allow other lower
			 * priority tasks to run.
			 */
			if (wait_us < MIN_MOTION_SENSE_WAIT_TIME)
				wait_us = MIN_MOTION_SENSE_WAIT_TIME;
		} else {
			wait_us = -1;
		}

	} while ((event = task_wait_event(wait_us)));
}