예제 #1
0
파일: timer.c 프로젝트: JosiahSnarr/ESES4P
void timer_init(void)
{
	TIMER_SET_PRESCALER(TIMER_PRESCALER_64);

	TIMER_DISABLE_ON_FREEZE();
	TIMER_FANCY_FAST_CLEAR();
	
	TIMER_ENABLE();
	CLR_BITS(TIE, (TIE_C3I_MASK));
}
예제 #2
0
파일: timer.c 프로젝트: wulfskin/mod-rob
int timer_set_prescaler(const uint8_t timer, const timer_prescaler prescaler)
{
	uint8_t scaler = 0;
	// Calculate prescaler bit-combination depending on available prescalers
	switch (timer)
	{
		case 0:
		case 1:
		case 3:
		case 4:
		case 5:
			scaler = TIMER_MASK_PRESCALER_NORMAL(prescaler);
		break;
			
		case 2:
			scaler = TIMER_MASK_PRESCALER_FINE(prescaler);
		break;
		
		default:
			return TIMER_ERROR_INVALID_TIMER;
	}
	// Check if prescaler combination is valid
	if (scaler || prescaler == TPS_DISABLED)
	{
		// Set new prescaler value
		switch (timer)
		{
			case 0:
				TIMER_SET_PRESCALER(TCCR0B, scaler);
			break;
			
			case 1:
				TIMER_SET_PRESCALER(TCCR1B, scaler);
			break;
			
			case 2:
				TIMER_SET_PRESCALER(TCCR2B, scaler);
			break;
			
			case 3:
				TIMER_SET_PRESCALER(TCCR3B, scaler);
			break;
			
			case 4:
				TIMER_SET_PRESCALER(TCCR4B, scaler);
			break;
			
			case 5:
				TIMER_SET_PRESCALER(TCCR5B, scaler);
			break;
		}
		return TIMER_ERROR_SUCCESS;
	}
	else
		return TIMER_ERROR_INVALID_OPERATION;
}