Example #1
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");
}
Example #2
0
/**
 * \brief Resets the TC module.
 *
 * Resets the TC module, restoring all hardware module registers to their
 * default values and disabling the module. The TC module will not be
 * accessible while the reset is being performed.
 *
 * \note When resetting a 32-bit counter only the master TC module's instance
 *       structure should be passed to the function.
 *
 * \param[in]  module_inst    Pointer to the software module instance struct
 *
 * \return Status of the procedure.
 * \retval STATUS_OK                   The module was reset successfully
 * \retval STATUS_ERR_UNSUPPORTED_DEV  A 32-bit slave TC module was passed to
 *                                     the function. Only use reset on master
 *                                     TC
 */
enum status_code tc_reset(
    const struct tc_module *const module_inst)
{
    /* Sanity check arguments  */
    Assert(module_inst);
    Assert(module_inst->hw);

    /* Get a pointer to the module hardware instance */
    TcCount8 *const tc_module = &(module_inst->hw->COUNT8);

    if (tc_module->STATUS.reg & TC_STATUS_SLAVE) {
        return STATUS_ERR_UNSUPPORTED_DEV;
    }

    /* Disable this module if it is running */
    if (tc_module->CTRLA.reg & TC_CTRLA_ENABLE) {
        tc_disable(module_inst);
        while (tc_is_syncing(module_inst)) {
            /* wait while module is disabling */
        }
    }

    /* Reset this TC module */
    tc_module->CTRLA.reg  |= TC_CTRLA_SWRST;

    return STATUS_OK;
}
void Adafruit_ZeroTimer::enable(boolean en) {
  if (en) {
    tc_enable(&tc_instance);
  } else {
    tc_disable(&tc_instance);
  }
}
Example #4
0
/**
 * \brief DMA transfer complete callback
 *
 * \param status             Status of transfer
 */
static void dma_transfer_is_complete(enum dma_channel_status status)
{
	if (status == DMA_CH_TRANSFER_COMPLETED) {
		/* The transfer is complete, tell the waiting test function */
		dma_has_completed = true;
		/* Disable the timer */
		tc_disable(&TIMER);
	}
}
Example #5
0
File: main.c Project: Tjalling7/asf
/**
 * \brief Delay function which use a Timer Counter and can be aborted
 * SW1 pressed stop delay.
 *
 * \param delay_ms  delay in ms
 */
static void main_introduction_delay(uint16_t delay_ms)
{
    /* Initialization TC to manage a delay between each slide */
    tc_enable(&TCC1);
    tc_write_clock_source(&TCC1, TC_CLKSEL_DIV1024_gc); /* 24MHz / 1024 */
    tc_set_direction(&TCC1, TC_UP);
    while (delay_ms) {
        tc_write_count(&TCC1, 0);
        uint16_t delay_step = delay_ms;
        if (delay_step > 2800) {
            delay_step = 2500;
        }

        while (tc_read_count(&TCC1) <
                ((24000lu * delay_step) / 1024lu)) {
            if (main_introduction_is_exist()) {
                break;
            }
        }
        delay_ms -= delay_step;
    }
    tc_disable(&TCC1);
}
Example #6
0
/*! \brief  to stop the running timer
 */
void tmr_stop(void)
{
	tc_disable(TIMER);
}
Example #7
0
void shutter_cont_stop(void){
    tc_write_clock_source(&SHUTTER_TC, TC_CLKSEL_OFF_gc);
    tc_set_wgm(&SHUTTER_TC, TC_WG_NORMAL);
    tc_disable(&SHUTTER_TC);
    ioport_set_pin_level(SHUTTER_PIN, 0);
}
Example #8
0
void backlight_stop_pwm()
{
	tc_disable_cc_channels(&BACKLIGHT_TIMER,TC_CCBEN);
	backlight_off();
	tc_disable(&BACKLIGHT_TIMER);
}
Example #9
0
/*! \brief  to stop the running timer
 */
void tmr_stop(void)
{
	tc_disable(&module_inst);
}