Multiple Software Timers
<p>I've been using the following method for implementing a software timer in code:</p>

<pre><code>typedef enum TIMER_CONFIG
{
    ENABLE_TIMER,
    DISABLE_TIMER,
} TIMER_CONFIG;

struct timer_module{
    uint32_t count;
    uint32_t start_count;
    unsigned int enable;
};

struct timer_module timer_1;
struct timer_module timer_2;

void tc_ms_tick(struct tc_module *const module_inst)
{
    ms_count++;     
}

volatile uint32_t get_ms_count(void){
    return(ms_count);
}

void checkTimers(void){

    if (timerIsDone(&amp;timer_1)){
        timerConfig(&amp;timer_1, DISABLE_TIMER,0);
        // Do something
    }

    if (timerIsDone(&amp;timer_2)){
        timerConfig(&amp;timer_2, DISABLE_TIMER,0);
        // Do something
    }
}

void timerConfig(struct timer_module *timer, TIMER_CONFIG timer_config, uint32_t timer_time){

    switch (timer_config)
    {
        case ENABLE_TIMER:
            timer-&gt;enable = 1;
            timer-&gt;start_count = get_ms_count();
            timer-&gt;count = timer_time;
            break;
        case DISABLE_TIMER:
            timer-&gt;enable = 0;
            break;
        default:
            //Do Nothing
            break;
    }
}

bool timerIsDone(struct timer_module *timer)
{
    bool timer_status = false;

    if (timer-&gt;enable){
        if(((get_ms_count() - timer-&gt;start_count) &gt;= timer-&gt;count)){
            timer_status = true;
        }
    }

    return timer_status;
}

// Main loop    
int main(void)
{       
    // Set the timer for 5 seconds
    timerConfig(&amp;timer_1, ENABLE_TIMER, 5000);

    while (1) {
        checkTimers();      // Check background timers
    }

    return 0;
}
</code></pre>

<p>This implementation works well for the majority of cases, however it doesn't scale well. I've heard of using linked lists for something like this but I'm fairly new to C and I couldn't find an example that I understood. Any help is appreciated!</p>

<p>Kyle</p>