コード例 #1
0
ファイル: oven_controller.c プロジェクト: AndreyMostovov/asf
/**
 * \brief Turn off power to simulated oven plate, disable tests
 *
 * This function modified the simulation input to zero (zero watts, no
 * power input), then turns off the periodic tests and disables monitoring of
 * them.
 *
 * \param *wattage Pointer to the value representing desired power level
 * \param *power Pointer to the value representing whether the desired power
 * level should be applied to the induction element.
 */
static void ovenctl_turn_off_plate(uint8_t *wattage, bool *power)
{
	*wattage = 0;
	*power = false;

	/* Turn off and stop monitoring temperature test */
	tc_write_clock_source(&OVEN_PERIODIC_TEMPTEST_TC, TC_CLKSEL_OFF_gc);
	tc_reset(&OVEN_PERIODIC_TEMPTEST_TC);
	classb_intmon_set_state(TEMP_SANITY_TEST, M_DISABLE);

	/* Turn off and stop monitoring periodic Class B tests. */
	tc_write_clock_source(&OVEN_PERIODIC_CLASSB_TC, TC_CLKSEL_OFF_gc);
	tc_reset(&OVEN_PERIODIC_CLASSB_TC);
	classb_intmon_set_state(PER_CLASSB_TESTS, M_DISABLE);
}
コード例 #2
0
/**
 * public method to get the summary information for the camara.
 *
 * takes a string buffer to put the information in and returns the length writen.
 */
int tc_get_summary(char * content, const int size_of) {

	CameraText text;
	int content_length = 0;
	int ret;

	initCamaraAndContext();

	if( initFailed ) {
		content_length = snprintf(content, size_of, "No camera detected");
	}
	else {
		ret = gp_camera_get_summary (camera, &text, context);
		if (ret < GP_OK) {
			// here we will try and reset the camara so next time some one tries to use it hopefully it will re init.
			tc_reset();
			content_length = snprintf(content, size_of, "Camera failed retrieving summary.");
		}
		else {
			content_length = snprintf(content, size_of, "Summary info from camara:\n %s",text.text);
		}
	}

	return content_length;
}
コード例 #3
0
/**
 * \internal
 * \brief Test the callback API
 *
 * This test tests the callback API for the TC. The TC uses one-shot mode.
 *
 * \param test Current test case.
 */
static void run_callback_test(const struct test_case *test)
{
	test_assert_true(test,
			tc_init_success == true,
			"TC initialization failed, skipping test");

	test_assert_true(test,
			basic_functionality_test_passed == true,
			"Basic functionality test failed, skipping test");

	/* Setup TC0 */
	tc_reset(&tc_test0_module);
	tc_get_config_defaults(&tc_test0_config);
	tc_test0_config.wave_generation                       = TC_WAVE_GENERATION_MATCH_PWM;
	tc_test0_config.counter_16_bit.compare_capture_channel\
		[TC_COMPARE_CAPTURE_CHANNEL_0]                    = 0x03FF;
	tc_test0_config.counter_16_bit.compare_capture_channel\
		[TC_COMPARE_CAPTURE_CHANNEL_1]                    = 0x03FA;


	tc_init(&tc_test0_module, CONF_TEST_TC0, &tc_test0_config);

	/* Setup callbacks */
	tc_register_callback(&tc_test0_module, tc_callback_function, TC_CALLBACK_CC_CHANNEL1);
	tc_enable_callback(&tc_test0_module, TC_CALLBACK_CC_CHANNEL1);

	tc_enable(&tc_test0_module);

	while ((tc_get_status(&tc_test0_module) & TC_STATUS_COUNT_OVERFLOW) == 0) {
		/* Wait for overflow of TC1*/
	}

	tc_disable(&tc_test0_module);
	tc_clear_status(&tc_test0_module, TC_STATUS_COUNT_OVERFLOW);

	test_assert_true(test,
			callback_function_entered == 1,
			"The callback has failed callback_function_entered = %d",
			(int)callback_function_entered);

	/* Test disable callback function */
	tc_disable_callback(&tc_test0_module, TC_CALLBACK_CC_CHANNEL1);
	tc_set_count_value(&tc_test0_module, 0x00000000);

	tc_enable(&tc_test0_module);

	while ((tc_get_status(&tc_test0_module) & TC_STATUS_COUNT_OVERFLOW) == 0) {
		/* Wait for overflow of TC1*/
	}

	/* Test tc_disable() */
	tc_disable(&tc_test0_module);

	test_assert_true(test,
			callback_function_entered == 1,
			"Disabling the callback has failed");
}
コード例 #4
0
// function to make sure the camara is initalised
void initCamaraAndContext() {

	if(resetNextTime) {
		tc_reset();
		resetNextTime = false;
	}

	if( context == NULL && camera == NULL ) {
		context = create_context ();
		gp_camera_new (&camera);

		if( gp_camera_init (camera, context) < GP_OK ) {
			initFailed = true;
			tc_reset();
		}
		else {
			internal_set_setting("capture", "1");
			initFailed = false;
		}
	}
}
コード例 #5
0
/**
 * \internal
 * \brief Test basic functionality.
 *
 * This test tests the basic functionality for the TC. It tests the following functions:
 *  - tc_get_count_value()
 *  - tc_stop_counter()
 *  - tc_set_count_value()
 *  - tc_start_counter()
 *
 * \param test Current test case.
 */
static void run_basic_functionality_test(const struct test_case *test)
{
	test_assert_true(test,
			tc_init_success == true,
			"TC initialization failed, skipping test");

	/* Setup TC0 */
	tc_reset(&tc_test0_module);
	tc_get_config_defaults(&tc_test0_config);

	tc_init(&tc_test0_module, CONF_TEST_TC0, &tc_test0_config);
	tc_enable(&tc_test0_module);

	/* Test tc_get_count_value() */
	uint32_t test_val0 = tc_get_count_value(&tc_test0_module);

	test_assert_true(test,
			test_val0 > 0,
			"The tc_get_count_value() returned 0 expected larger value");

	/* Test tc_stop_counter() */
	tc_stop_counter(&tc_test0_module);

	uint32_t test_val1 = tc_get_count_value(&tc_test0_module);
	uint32_t test_val2 = tc_get_count_value(&tc_test0_module);

	test_assert_true(test,
			test_val1 == test_val2,
			"The counter failed to stop");

	/* Test tc_set_count_value() */
	tc_set_count_value(&tc_test0_module, 0x00FF);

	test_assert_true(test,
			tc_get_count_value(&tc_test0_module) == 0x00FF,
			"tc_set_count_value() have failed");

	/* Test tc_start_counter() */
	tc_start_counter(&tc_test0_module);

	test_assert_true(test,
			tc_get_count_value(&tc_test0_module) > 0x00FF,
			"tc_get_count_value() have failed");

	basic_functionality_test_passed = true;
}
コード例 #6
0
/**
 * \internal
 * \brief Test capture and compare
 *
 * This test uses TC module 0 as a PWM generator (compare function).
 * TC module 1 will be set to capture the signal from TC module 0 to test the capture
 * functionality.
 *
 * \param test Current test case.
 */
static void run_16bit_capture_and_compare_test(const struct test_case *test)
{
	test_assert_true(test,
			tc_init_success == true,
			"TC initialization failed, skipping test");

	test_assert_true(test,
			callback_function_entered == 1,
			"The callback test has failed, skipping test");

	/* Configure 16-bit TC module for PWM generation */
	tc_reset(&tc_test0_module);
	tc_get_config_defaults(&tc_test0_config);
	tc_test0_config.wave_generation  = TC_WAVE_GENERATION_MATCH_PWM;
	tc_test0_config.counter_16_bit.compare_capture_channel[TC_COMPARE_CAPTURE_CHANNEL_0]  = 0x03FF;
	tc_test0_config.counter_16_bit.compare_capture_channel[TC_COMPARE_CAPTURE_CHANNEL_1]  = 0x01FF;

	/* Calculate the theoretical PWM frequency & duty */
	uint32_t frequency_output, duty_output;
	frequency_output = system_clock_source_get_hz(SYSTEM_CLOCK_SOURCE_OSC8M)/ (0x03FF+1);

	/* This value is depend on the WaveGeneration Mode */
	duty_output = (uint32_t)(tc_test0_config.counter_16_bit.compare_capture_channel[TC_COMPARE_CAPTURE_CHANNEL_1]) * 100 \
					/ tc_test0_config.counter_16_bit.compare_capture_channel[TC_COMPARE_CAPTURE_CHANNEL_0];

	tc_test0_config.pwm_channel[TC_COMPARE_CAPTURE_CHANNEL_1].enabled = true;
	tc_test0_config.pwm_channel[TC_COMPARE_CAPTURE_CHANNEL_1].pin_out = CONF_TEST_PIN_OUT;
	tc_test0_config.pwm_channel[TC_COMPARE_CAPTURE_CHANNEL_1].pin_mux = CONF_TEST_PIN_MUX;
	tc_init(&tc_test0_module, CONF_TEST_TC0, &tc_test0_config);

	tc_register_callback(&tc_test0_module, tc_callback_function, TC_CALLBACK_CC_CHANNEL0);
	tc_enable_callback(&tc_test0_module, TC_CALLBACK_CC_CHANNEL0);

	/* Configure 16-bit TC module for capture */
	tc_reset(&tc_test1_module);
	tc_get_config_defaults(&tc_test1_config);
	tc_test1_config.clock_prescaler              = TC_CLOCK_PRESCALER_DIV1;
	tc_test1_config.enable_capture_on_channel[CONF_CAPTURE_CHAN_0] = true;
	tc_test1_config.enable_capture_on_channel[CONF_CAPTURE_CHAN_1] = true;

	tc_init(&tc_test1_module, CONF_TEST_TC1, &tc_test1_config);

	struct tc_events tc_events = { .on_event_perform_action = true,
								.event_action = TC_EVENT_ACTION_PPW,};

	tc_enable_events(&tc_test1_module, &tc_events);

	/* Configure external interrupt controller */
	struct extint_chan_conf extint_chan_config;
	extint_chan_config.gpio_pin            = CONF_EIC_PIN;
	extint_chan_config.gpio_pin_mux        = CONF_EIC_MUX;
	extint_chan_config.gpio_pin_pull       = EXTINT_PULL_UP;
	extint_chan_config.wake_if_sleeping    = false;
	extint_chan_config.filter_input_signal = false;
	extint_chan_config.detection_criteria  = EXTINT_DETECT_HIGH;
	extint_chan_set_config(0, &extint_chan_config);

	/* Configure external interrupt module to be event generator */
	struct extint_events extint_event_conf;
	extint_event_conf.generate_event_on_detect[0] = true;
	extint_enable_events(&extint_event_conf);

	/* Configure event system */
	struct events_resource event_res;

	/* Configure channel */
	struct events_config config;
	events_get_config_defaults(&config);
	config.generator      = CONF_EVENT_GENERATOR_ID;
	config.edge_detect    = EVENTS_EDGE_DETECT_NONE;
	config.path           = EVENTS_PATH_ASYNCHRONOUS;
	events_allocate(&event_res, &config);

	/* Configure user */
	events_attach_user(&event_res, CONF_EVENT_USED_ID);

	/* Enable TC modules */
	tc_enable(&tc_test1_module);
	tc_enable(&tc_test0_module);

	uint16_t period_after_capture = 0;
	uint16_t pulse_width_after_capture = 0;
	uint32_t capture_frequency = 0;
	uint32_t capture_duty = 0;


	while (callback_function_entered < 4) {
		period_after_capture = tc_get_capture_value(&tc_test1_module,
				TC_COMPARE_CAPTURE_CHANNEL_0);
		pulse_width_after_capture = tc_get_capture_value(&tc_test1_module,
				TC_COMPARE_CAPTURE_CHANNEL_1);
	}

	if(period_after_capture != 0) {
		capture_frequency = system_clock_source_get_hz(SYSTEM_CLOCK_SOURCE_OSC8M)/ period_after_capture;
		capture_duty = (uint32_t)(pulse_width_after_capture) * 100 / period_after_capture;
	}

	test_assert_true(test,
			(capture_frequency <= (frequency_output * (100 + CONF_TEST_TOLERANCE) / 100)) && \
			(capture_frequency >= (frequency_output * (100 - CONF_TEST_TOLERANCE) / 100)) && \
			(capture_duty <= (duty_output * (100 + CONF_TEST_TOLERANCE) / 100)) && \
			(capture_duty >= (duty_output * (100 - CONF_TEST_TOLERANCE) / 100)) \
			,"The result of Capture is wrong, captured frequency: %ldHz, captured duty: %ld%%",
			capture_frequency,
			capture_duty
			);
}

/**
 * \brief Initialize the USART for unit test
 *
 * Initializes the SERCOM USART used for sending the unit test status to the
 * computer via the EDBG CDC gateway.
 */
static void cdc_uart_init(void)
{
	struct usart_config usart_conf;

	/* Configure USART for unit test output */
	usart_get_config_defaults(&usart_conf);
	usart_conf.mux_setting = CONF_STDIO_MUX_SETTING;
	usart_conf.pinmux_pad0 = CONF_STDIO_PINMUX_PAD0;
	usart_conf.pinmux_pad1 = CONF_STDIO_PINMUX_PAD1;
	usart_conf.pinmux_pad2 = CONF_STDIO_PINMUX_PAD2;
	usart_conf.pinmux_pad3 = CONF_STDIO_PINMUX_PAD3;
	usart_conf.baudrate    = CONF_STDIO_BAUDRATE;

	stdio_serial_init(&cdc_uart_module, CONF_STDIO_USART, &usart_conf);
	usart_enable(&cdc_uart_module);
}

/**
 * \brief Run TC unit tests
 *
 * Initializes the system and serial output, then sets up the TC unit test
 * suite and runs it.
 */
int main(void)
{
	system_init();
	cdc_uart_init();

	/* Define Test Cases */
	DEFINE_TEST_CASE(init_test, NULL,
			run_init_test, NULL,
			"Initialize tc_xmodules");

	DEFINE_TEST_CASE(basic_functionality_test, NULL,
			run_basic_functionality_test, NULL,
			"test start stop and getters and setters");

	DEFINE_TEST_CASE(callback_test, NULL,
			run_callback_test, NULL,
			"test callback API");

	DEFINE_TEST_CASE(reset_32bit_master_test, NULL,
			run_reset_32bit_master_test, NULL,
			"Setup, reset and reinitialize TC modules of a 32-bit TC");


	DEFINE_TEST_CASE(capture_and_compare_test, NULL,
			run_16bit_capture_and_compare_test, NULL,
			"Test capture and compare");

	/* Put test case addresses in an array */
	DEFINE_TEST_ARRAY(tc_tests) = {
		&init_test,
		&basic_functionality_test,
		&callback_test,
		&reset_32bit_master_test,
		&capture_and_compare_test,
	};

	/* Define the test suite */
	DEFINE_TEST_SUITE(tc_suite, tc_tests,
			"SAM TC driver test suite");

	/* Run all tests in the suite*/
	test_suite_run(&tc_suite);

	tc_reset(&tc_test0_module);
	tc_reset(&tc_test1_module);

	while (true) {
		/* Intentionally left empty */
	}
}
コード例 #7
0
/**
 * \internal
 * \brief Test initializing and resetting 32-bit TC and reinitialize
 *
 * This test tests the software reset of a 32-bit TC by the use of the
 * tc_reset(). It also test re-enabling the two TC modules used in the 32-bit
 * TC into two separate 16-bit TC's.
 *
 * \param test Current test case.
 */
static void run_reset_32bit_master_test(const struct test_case *test)
{
	test_assert_true(test,
			tc_init_success == true,
			"TC initialization failed, skipping test");

	/* Configure 32-bit TC module and run test*/
	tc_reset(&tc_test0_module);
	tc_get_config_defaults(&tc_test0_config);
	tc_test0_config.counter_size = TC_COUNTER_SIZE_32BIT;

	tc_init(&tc_test0_module, CONF_TEST_TC0, &tc_test0_config);
	tc_enable(&tc_test0_module);

	while (tc_is_syncing(&tc_test0_module)) {
		/* Synchronize enable */
	}

	test_assert_true(test,
			tc_test0_module.hw->COUNT32.CTRLA.reg & TC_CTRLA_ENABLE,
			"Failed first enable of 32-bit TC");

	/* Reset and test if both TC modules are disabled after reset */
	tc_reset(&tc_test0_module);

	while (tc_is_syncing(&tc_test0_module)) {
		/* Synchronize reset */
	}

	test_assert_false(test,
			tc_test0_module.hw->COUNT32.CTRLA.reg & TC_CTRLA_ENABLE,
			"Failed reset of 32-bit master TC TEST0");
	test_assert_false(test,
			tc_test1_module.hw->COUNT32.CTRLA.reg & TC_CTRLA_ENABLE,
			"Failed reset of 32-bit slave TC TEST1");

	/* Change to 16-bit counter on TC0  */
	tc_test0_config.counter_size = TC_COUNTER_SIZE_16BIT;

	tc_init(&tc_test0_module, CONF_TEST_TC0, &tc_test0_config);
	tc_enable(&tc_test0_module);

	while (tc_is_syncing(&tc_test0_module)) {
		/* Synchronize enable */
	}


	tc_init(&tc_test1_module, CONF_TEST_TC1, &tc_test1_config);
	tc_enable(&tc_test1_module);

	while (tc_is_syncing(&tc_test1_module)) {
		/* Synchronize enable */
	}

	test_assert_true(test,
			tc_test0_module.hw->COUNT16.CTRLA.reg & TC_CTRLA_ENABLE,
			"Failed re-enable of TC TEST0");
	test_assert_true(test,
			tc_test1_module.hw->COUNT16.CTRLA.reg & TC_CTRLA_ENABLE,
			"Failed re-enable of TC TEST1");
}
コード例 #8
0
void platform_delete_bus_timer(void *timer_handle)
{
	tc_stop_counter(&bus_tc_instance);
	tc_reset(&bus_tc_instance);
	hw_timers[0].timer_usage = 0;
}
コード例 #9
0
ファイル: dist.c プロジェクト: carriercomm/netem
static int dist_load(int argc, char *argv[])
{
	FILE *fp;
	double mu, sigma, rho;

	if (argc == 1) {
		if (!(fp = fopen(argv[0], "r")))
			error(-1, errno, "Failed to open file: %s", argv[0]);
	}
	else
		fp = stdin;

	short *inverse = dist_make(fp, &mu, &sigma, &rho);
	if (!inverse)
		error(-1, 0, "Failed to generate distribution");
	
	int ret;

	struct nl_sock *sock;
	
	struct rtnl_link *link;
	struct rtnl_tc *qdisc_prio = NULL;
	struct rtnl_tc *qdisc_netem = NULL;
	struct rtnl_tc *cls_fw = NULL;

	/* Create connection to netlink */
	sock = nl_socket_alloc();
	nl_connect(sock, NETLINK_ROUTE);
	
	/* Get interface */
	link = tc_get_link(sock, cfg.dev);
	if (!link)
		error(-1, 0, "Interface does not exist: %s", cfg.dev);
	
	/* Reset TC subsystem */
	ret = tc_reset(sock, link);
	if (ret && ret != -NLE_OBJ_NOTFOUND)
		error(-1, 0, "Failed to reset TC: %s", nl_geterror(ret));
	
	/* Setup TC subsystem */
	if ((ret = tc_prio(sock, link, &qdisc_prio)))
		error(-1, 0, "Failed to setup TC: prio qdisc: %s", nl_geterror(ret));

	if ((ret = tc_classifier(sock, link, &cls_fw, cfg.mark, cfg.mask)))
		error(-1, 0, "Failed to setup TC: fw filter: %s", nl_geterror(ret));
	
	if ((ret = tc_netem(sock, link, &qdisc_netem)))
		error(-1, 0, "Failed to setup TC: netem qdisc: %s", nl_geterror(ret));
	
	/* We will use the default normal distribution for now */
	if (rtnl_netem_set_delay_distribution_data((struct rtnl_qdisc *) qdisc_netem, inverse, TABLESIZE))
		error(-1, 0, "Failed to set netem delay distrubtion: %s", nl_geterror(ret));
	
	rtnl_netem_set_delay((struct rtnl_qdisc *) qdisc_netem, mu);
	rtnl_netem_set_jitter((struct rtnl_qdisc *) qdisc_netem, sigma);	

	nl_close(sock);
	nl_socket_free(sock);

	return 0;
}