<commit_before>/*******************************************************************
 Frequency-Controlled Voltage Source
 
 Author: gamesun <<EMAIL>>
 URL: https://github.com/gamesun/Frequency-Controlled-Voltage-Source
*******************************************************************/

#include "common.h"


static bool bIsTimerLocking = false;
static ulong ulTimerOvfCnt = 0;
void (*TimerIsUp)( void );

void SetTimerByMillisecond( ulong ulPreiodByMillisecond, void (*callback)(void) )
{
    if ( bIsTimerLocking == false ){
        bIsTimerLocking = true;
        TimerIsUp = callback;
        ulTimerOvfCnt = ulPreiodByMillisecond - 1;
        TCNT1 = 0;
        TCCR1B |= _BV(CS10);         // CLKio(No prescaling)
    }
}


bool IsTimerLocking( void )
{
    return bIsTimerLocking;
}

/*---------------------------------------------------- T/C2 Overflow Event --*/
ISR( TIMER2_OVF_vect )
{
    if ( 0 < ulTimerOvfCnt ){
        ulTimerOvfCnt--;
    } else {
        bIsTimerLocking = false;
        TCCR1B &= ~( _BV(CS12) | _BV(CS11) | _BV(CS10) );
        TimerIsUp();
    }
}


void TimerClear( void )
{
    TCCR1B &= ~( _BV(CS12) | _BV(CS11) | _BV(CS10) );
    bIsTimerLocking = false;
}


void TimerInit( void )
{<commit_msg>fix a bug by modifying interrupe vector TC2 -> TC1<commit_after>/*******************************************************************
 Frequency-Controlled Voltage Source
 
 Author: gamesun <<EMAIL>>
 URL: https://github.com/gamesun/Frequency-Controlled-Voltage-Source
*******************************************************************/

#include "common.h"


static bool bIsTimerLocking = false;
static ulong ulTimerOvfCnt = 0;
void (*TimerIsUp)( void );

void SetTimerByMillisecond( ulong ulPreiodByMillisecond, void (*callback)(void) )
{
    if ( bIsTimerLocking == false ){
        bIsTimerLocking = true;
        TimerIsUp = callback;
        ulTimerOvfCnt = ulPreiodByMillisecond - 1;
        TCNT1 = 0;
        TCCR1B |= _BV(CS10);         // CLKio(No prescaling)
    }
}


bool IsTimerLocking( void )
{
    return bIsTimerLocking;
}

/*---------------------------------------------------- T/C1 Overflow Event --*/
ISR( TIMER1_OVF_vect )
{
    if ( 0 < ulTimerOvfCnt ){
        ulTimerOvfCnt--;
    } else {
        bIsTimerLocking = false;
        TCCR1B &= ~( _BV(CS12) | _BV(CS11) | _BV(CS10) );
        TimerIsUp();
    }
}


void TimerClear( void )
{
    TCCR1B &= ~( _BV(CS12) | _BV(CS11) | _BV(CS10) );
    bIsTimerLocking = false;
}


void TimerInit( void )
{
{'fraction_non_alphanumeric': 0.25806451612903225, 'fraction_numerical': 0.019912385503783353, 'mean_word_length': 2.7661169415292353, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 8, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3566284', 'n_tokens_mistral': 903, 'n_tokens_neox': 815, 'n_words': 164}