Exemplo n.º 1
0
void *process_events(void *ptr)
{
    struct payload *payload = (struct payload *) ptr;
    Display *dpy1, *dpy2;
    XEvent ev;
    uint64_t start, end;
    int i, x11fd1, x11fd2;
    fd_set fds;

    if (!(dpy1 = XOpenDisplay(payload->dpy1))) {
        printf("Could not open dpy %s\n", payload->dpy1);
        return NULL;
    }
    if (setup_events(dpy1) < 0) {
        printf("Could not setup events");
        return NULL;
    }
    x11fd1 = ConnectionNumber(dpy1);

    if (!(dpy2 = XOpenDisplay(payload->dpy2))) {
        printf("Could not open dpy %s\n", payload->dpy2);
        return NULL;
    }
    if (setup_events(dpy2) < 0) {
        printf("Could not setup events");
        return NULL;
    }
    x11fd2 = ConnectionNumber(dpy2);

    i = 0;
    start = 0;

    while (i < REPEATS) {
        FD_ZERO(&fds);

        FD_SET(x11fd1, &fds);
        FD_SET(x11fd2, &fds);

        select(MAX(x11fd1, x11fd2) + 1, &fds, NULL, NULL, NULL);

        if (start == 0)
            start = cpn_bench_nsecs();

        if (FD_ISSET(x11fd1, &fds)) {
            XNextEvent(dpy1, &ev);
            XNextEvent(dpy2, &ev);
        } else if (FD_ISSET(x11fd2, &fds)) {
            XNextEvent(dpy2, &ev);
            XNextEvent(dpy1, &ev);
        } else {
            continue;
        }

        i++;
    }
    end = cpn_bench_nsecs();
    printf("delay (in ns): %"PRIu64"\n", end - start);

    return NULL;
}
Exemplo n.º 2
0
extern "C" void setup()
{
  // first check if user wants to dialog
  // if not then ..
  // read config
  setup_outputs();
  setup_events();
  setup_inputs(); 
}
Exemplo n.º 3
0
extern "C" void setup()
{
  led::initialise();
  i2c::initialise();
  setup_events();
  setup_usarts();
  sh1106_oled::initialise();
 
}
Exemplo n.º 4
0
void run(global_config_struct *global_config) {
	global_resources_struct global_resources;
	
	setup_server_socket(global_config, &global_resources);
	global_resources.bases.transfer_buffer_size = global_config->transfer_buffer_size;
	setup_events(&global_resources);
	listen_server_socket(&global_resources);
	dispatch(&global_resources);
	close_all(&global_resources);
}
Exemplo n.º 5
0
bool XPlatformWindow::open( const char* display_name,
                            int x, int y, int w, int h,
                            int min_w, int max_w, int min_h, int max_h, // -1 for don't care
                            const char* window_name,  const char* icon_name,
                            const char* font_name,    int   /*font_size unimp X*/ ) {

  // (adapted from Spy open routine, needs font info for sizing)
  // XOpenDisplay fails silently if a signal is received during the call.
  // All signals except user interrupts are therefore blocked. 
  SignalBlocker sb(SignalBlocker::allow_user_int);
  
  if (!open_xdisplay(display_name)) { close();  return false; }
  
  bool debugMe = false;              // set to true when debugging X
  XSynchronize(_display, debugMe);  
  XSetErrorHandler(XErrorHandlers::handle_X_error);

  _screen_num     = DefaultScreen(_display);
  _display_width  = DisplayWidth (_display, _screen_num);
  _display_height = DisplayHeight(_display, _screen_num);
  
  _window_x = x;  _window_y = y;  _width = w;  _height = h;

  // create the window; will be resized and repositioned when reparented
  Window root = RootWindow(_display, _screen_num);
  
  _xwindow = XCreateSimpleWindow(  _display, root,
                                   _window_x, _window_y,
                                   width(), height(), 0,
                                   BlackPixel(_display, _screen_num),
                                   WhitePixel(_display, _screen_num));
  
  if (!set_font_info(font_name))                       {  close();  return false; }
  if (!change_size_hints(min_w, max_w, min_h, max_h))  {  close();  return false; }
  
  if (!set_name(     window_name))  {  close(); return false; }
  if (!set_icon_name(  icon_name))  {  close(); return false; }
  
  setup_events();  
  XMapWindow(_display, _xwindow);
  
 if (!setup_gcs())      {  close(); return false; }
 
  return true;
}
Exemplo n.º 6
0
int
main(int argc, char **argv) {
	time_t now = 0L;

	plan_tests(10);

	time(&now);

	currently_running_service_checks = 0;
	max_parallel_service_checks = 1;
	setup_events(now);
	event_execution_loop();

	ok(svc1->next_check == now, "svc1 has not had its next check time changed");
	printf("# Nudge amount: %d\n", svc2->next_check - now);
	ok(svc2->next_check > now + 5 && svc2->next_check < now + 5 + 10, "svc2 has been nudged");


	sigshutdown = FALSE;
	currently_running_service_checks = 0;
	max_parallel_service_checks = 2;
	setup_events(now);
	event_execution_loop();
	ok(svc1->next_check == now, "svc1 has not had its next check time changed");
	printf("# Nudge amount: %d\n", svc2->next_check - now);
	ok(svc2->next_check == now, "svc2 also has not changed, because can execute");


	/* This test should have both services moved forward due to not executing any service checks */
	/* Will make svc2 move forward by a retry_interval amount */
	execute_service_checks = 0;
	sigshutdown = FALSE;
	currently_running_service_checks = 0;
	max_parallel_service_checks = 1;
	setup_events(now);
	svc2->current_state = STATE_CRITICAL;
	event_execution_loop();
	ok(svc1->next_check == now + 300, "svc1 rescheduled ahead - normal interval");
	ok(svc2->next_check == now + 60,  "svc2 rescheduled ahead - retry interval");

	/* Checking that a host check immediately following a service check
	 * correctly checks the host
	 */
	timed_event *temp_event = NULL;
	while ((temp_event = event_list_low) != NULL) {
		remove_event(temp_event, &event_list_low, &event_list_low_tail);
	}

	sigshutdown = FALSE;
	currently_running_service_checks = 0;
	max_parallel_service_checks = 2;
	execute_service_checks = 0;
	execute_host_checks = 1;
	setup_events_with_host(now);
	event_execution_loop();

	ok(host1->last_check - now <= 2,  "host1 was checked (within 2 seconds tolerance)") || diag("Last check: %d, Now: %d", host1->last_check, now);
	ok(svc3->last_check == 0, "svc3 was skipped");
	ok(host1->next_check == now,  "host1 rescheduled ahead - normal interval");
	ok(svc3->next_check == now + 300, "svc3 rescheduled ahead - normal interval");

	return exit_status();
}
Exemplo n.º 7
0
/** Set up the measurement and comparison timer events.
 *   - Configure the reference timer to generate an event upon comparison
 *     match with channel 0.
 *   - Configure the measurement timer to trigger a capture when an event is
 *     received.
 */
static void setup_tc_events(void)
{
	/* Enable incoming events on on measurement timer */
	struct tc_events events_calib = { .on_event_perform_action = true };
	tc_enable_events(&tc_calib, &events_calib);

	/* Generate events from the reference timer on channel 0 compare match */
	struct tc_events events_comp = { .generate_event_on_compare_channel[0] = true };
	tc_enable_events(&tc_comp, &events_comp);

	tc_enable(&tc_calib);
	tc_enable(&tc_comp);
}

/** Set up the event system, linking the measurement and comparison timers so
 *  that events generated from the reference timer are linked to the measurement
 *  timer.
 */
static void setup_events(struct events_resource *event)
{
	struct events_config config;

	events_get_config_defaults(&config);

	/* The event channel detects rising edges of the reference timer output
	 * event */
	config.edge_detect    = EVENTS_EDGE_DETECT_RISING;
	config.path           = EVENTS_PATH_SYNCHRONOUS;
	config.generator      = CONF_EVENT_GENERATOR_ID;

	events_allocate(event, &config);
	events_attach_user(event, CONF_EVENT_USED_ID);

}

/** Set up the USART for transmit-only communication at a fixed baud rate. */
static void setup_usart_channel(void)
{
	struct usart_config cdc_uart_config;
	usart_get_config_defaults(&cdc_uart_config);

	/* Configure the USART settings and initialize the standard I/O library */
	cdc_uart_config.mux_setting = EDBG_CDC_SERCOM_MUX_SETTING;
	cdc_uart_config.pinmux_pad0 = EDBG_CDC_SERCOM_PINMUX_PAD0;
	cdc_uart_config.pinmux_pad1 = EDBG_CDC_SERCOM_PINMUX_PAD1;
	cdc_uart_config.pinmux_pad2 = EDBG_CDC_SERCOM_PINMUX_PAD2;
	cdc_uart_config.pinmux_pad3 = EDBG_CDC_SERCOM_PINMUX_PAD3;
	cdc_uart_config.baudrate    = 115200;
	stdio_serial_init(&usart_edbg, EDBG_CDC_MODULE, &cdc_uart_config);

	usart_enable(&usart_edbg);
}

/** Set up the clock output pin so that the current system clock frequency can
 *  be monitored via an external frequency counter or oscilloscope. */
static void setup_clock_out_pin(void)
{
	struct system_pinmux_config pin_mux;
	system_pinmux_get_config_defaults(&pin_mux);

	/* MUX out the system clock to a I/O pin of the device */
	pin_mux.mux_position = CONF_CLOCK_PIN_MUX;
	system_pinmux_pin_set_config(CONF_CLOCK_PIN_OUT, &pin_mux);
}

/** Retrieves the current system clock frequency, computed from the reference
 *  clock.
 *
 * \return Current system clock frequency in Hz.
 */
static uint32_t get_osc_frequency(void)
{
	/* Clear any existing match status on the measurement timer */
	tc_clear_status(&tc_comp, TC_STATUS_CHANNEL_0_MATCH);

	/* Restart both measurement and reference timers */
	tc_start_counter(&tc_calib);
	tc_start_counter(&tc_comp);

	/* Wait for the measurement timer to signal a compare match */
	while (!(tc_get_status(&tc_comp) & TC_STATUS_CHANNEL_0_MATCH)) {
		/* Wait for channel 0 match */
	}

	/* Compute the real clock frequency from the measurement timer count and
	 * reference count */
	uint64_t tmp = tc_get_capture_value(&tc_calib, TC_COMPARE_CAPTURE_CHANNEL_0);
	return ((tmp * REFERENCE_CLOCK_HZ) >> CALIBRATION_RESOLUTION);
}

int main(void)
{
	struct events_resource event;

	/* System initialization */
	system_init();
	delay_init();

	/* Module initialization */
	setup_tc_channels();
	setup_tc_events();
	setup_events(&event);
	setup_clock_out_pin();

	/* Init the variables with default calibration settings */
	uint8_t frange_cal = SYSCTRL->OSC8M.bit.FRANGE;
	uint8_t temp_cal = SYSCTRL->OSC8M.bit.CALIB >> TEMP_CAL_OFFSET;
	uint8_t comm_cal = SYSCTRL->OSC8M.bit.CALIB & COMM_CAL_MAX;
	/* Set the calibration test range */
	uint8_t frange_cal_min = max((frange_cal - CONF_FRANGE_CAL), FRANGE_CAL_MIN);
	uint8_t frange_cal_max = min((frange_cal + CONF_FRANGE_CAL), FRANGE_CAL_MAX);
	uint8_t temp_cal_min = max((temp_cal - CONF_TEMP_CAL), TEMP_CAL_MIN);
	uint8_t temp_cal_max = min((temp_cal + CONF_TEMP_CAL), TEMP_CAL_MAX);

	/* Variables to track the previous and best calibration settings */
	uint16_t comm_best   = 0;
	uint8_t  frange_best = 0;
	uint32_t freq_best   = 0;
	uint32_t freq_before = get_osc_frequency();

	/* Run calibration loop */
	for (frange_cal = frange_cal_min; frange_cal <= frange_cal_max; frange_cal++) {
		for (temp_cal = temp_cal_min; temp_cal <= temp_cal_max; temp_cal++) {
			for (comm_cal = COMM_CAL_MIN; comm_cal <= COMM_CAL_MAX; comm_cal++) {
				/* Set the test calibration values */
				system_clock_source_write_calibration(
						SYSTEM_CLOCK_SOURCE_OSC8M, (temp_cal << 7) | comm_cal, frange_cal);

				/* Wait for stabilization */
				delay_cycles(1000);

				/* Compute the deltas of the current and best system clock
				 * frequencies, save current settings if they are closer to the
				 * ideal frequency than the previous best values
				 */
				uint32_t freq_current = get_osc_frequency();
				if (abs(freq_current - TARGET_FREQUENCY) < abs(freq_best - TARGET_FREQUENCY)) {
					freq_best   = freq_current;
					comm_best   = comm_cal;
					frange_best = frange_cal;

					port_pin_set_output_level(LED_0_PIN, LED_0_ACTIVE);
				} else {
					port_pin_set_output_level(LED_0_PIN, !LED_0_ACTIVE);
				}
			}
		}
	}

	/* Set the found best calibration values */
	system_clock_source_write_calibration(
			SYSTEM_CLOCK_SOURCE_OSC8M, (temp_cal << 7) | comm_best, frange_best);

	/* Setup USART module to output results */
	setup_usart_channel();

	/* Write previous and current frequency and new calibration settings to the
	 * USART
	 */
	printf("Freq Before: %lu\r\n", freq_before);
	printf("Freq Best: %lu\r\n", freq_best);

	printf("Freq Range: %u\r\n", frange_best);
	printf("Calib Value: 0x%x\r\n", (temp_cal << 7) | comm_best);

	/* Rapidly flash the board LED to signal the calibration completion */
	while (1) {
		port_pin_toggle_output_level(LED_0_PIN);
		delay_ms(200);
	}
}