예제 #1
0
파일: ast.c 프로젝트: JohsBL/MobRob
int ast_init_counter(volatile avr32_ast_t *ast,
                     unsigned char osc_type,
                     unsigned char psel,
                     unsigned long ast_counter)
{

//	while (ast_is_clkbusy(ast));
	ast->clock = AVR32_AST_CLOCK_CEN_MASK |
		osc_type << AVR32_AST_CLOCK_CSSEL_OFFSET;

	// Set the new AST configuration
	ast->cr =   AST_MODE_COUNTER << AVR32_AST_CR_CAL_OFFSET |
		psel << AVR32_AST_CR_PSEL_OFFSET ;

	// Wait until the ast CTRL register is up-to-date
//	while (ast_is_busy(ast));

	// Set the calendar
	ast_set_counter_value(ast, ast_counter);

	return 1;
}
예제 #2
0
파일: ast.c 프로젝트: InSoonPark/asf
/**
 * \brief This function will initialize the AST module in counter Mode.
 *
 * \note  If you use the 32 KHz oscillator, it must be enabled before calling
 *        this function.
 *
 * \param ast Base address of the AST (i.e. &AVR32_AST).
 * \param osc_type The oscillator you want to use. If you need a better
 *        accuracy, use the 32 KHz oscillator (i.e. AST_OSC_32KHZ).
 * \param psel The preselector value for the corresponding oscillator (4-bits).
 *        To obtain this value, you can use this formula:
 *        psel = log(Fosc/Fast)/log(2)-1, where Fosc is the frequency of the
 *        oscillator you are using (32 KHz or 115 KHz) and Fast the frequency
 *        desired.
 * \param ast_counter Startup counter value
 *
 * \return Boolean true if the initialization succeeds, false otherwise.
 */
bool ast_init_counter(volatile avr32_ast_t *ast, uint8_t osc_type,
		uint8_t psel, uint32_t ast_counter)
{
	uint32_t time_out = AST_POLL_TIMEOUT;
	while (ast_is_clkbusy(ast)) {
		if (--time_out == 0) {
			return false;
		}
	}
	
	ast->clock = osc_type << AVR32_AST_CLOCK_CSSEL_OFFSET;
	time_out = AST_POLL_TIMEOUT;
	while (ast_is_clkbusy(ast)) {
		if (--time_out == 0) {
			return false;
		}
	}

	ast->clock |= AVR32_AST_CLOCK_CEN_MASK;
	time_out = AST_POLL_TIMEOUT;
	while (ast_is_clkbusy(ast)) {
		if (--time_out == 0) {
			return false;
		}
	}

	/* Set the new AST configuration */
	ast->cr = (AST_MODE_COUNTER << AVR32_AST_CR_CAL_OFFSET) |
			(psel << AVR32_AST_CR_PSEL_OFFSET);

	/* Wait until the ast CTRL register is up-to-date */
	while (ast_is_busy(ast)) {
	}

	/* Set the calendar */
	ast_set_counter_value(ast, ast_counter);

	return true;
}
예제 #3
0
파일: sysclk_auto.c 프로젝트: marekr/asf
//! Callback used to reset the counter of the reference's oscillator.
void freq_detect_iface_ref_cnt_reset(void)
{
	ast_set_counter_value(&AVR32_AST, 0);
}