Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
10/11/12 22:08
Read: times


 
#188630 - bug
Responding to: ???'s previous message
For anyone critiquing or using the code for their own application




//call this on a 1mSec or more tick that is not on an interrupt.
void TIMERS_sort_out_timers(void){
	unsigned char i;
	unsigned int elapsed_msecs;

	elapsed_msecs = timer_count;
	timer_count = 0;


	for (i = 0; i < NUMBER_OF_TIMERS; i++){				//step through each of our timers
		if (timer_array[i].current_value != 0){			//see if we have already expired.
			timer_array[i].current_value -= elapsed_msecs;			//if not then decrement the timer toward 0 or past 0 
			if (timer_array[i].current_value <= 0){		//now see if we have timed out
				timer_array[i].current_value = 0;		//make sure that we won't fire again if we are a single shot timer, we may have gone past 0 
				if (timer_array[i].timer_type == timer_periodic){	//if we run on a periodic timer 
					timer_array[i].current_value = timer_array[i].reset_value;	//reload the timer 
				}
				timer_array[i].timeout_func(timer_array[i].func_args);			//if we have timed out then perform the function in our callback.
			}
		}
	}
}




 


I have made sure to explicitly set the current_value to 0, so that the fire won't repeatedly fire if the time tick causes the current_value to go negative.





List of 13 messages in thread
TopicAuthorDate
Timers - Function Pointers            01/01/70 00:00      
   Too much for a '51?            01/01/70 00:00      
      I Agree            01/01/70 00:00      
   Function Pointers...            01/01/70 00:00      
   you are violating KISS            01/01/70 00:00      
   Various Timer Functions            01/01/70 00:00      
      Thanks Michael            01/01/70 00:00      
         regardless, you are violating KISS            01/01/70 00:00      
            even on ARM            01/01/70 00:00      
            The timer simply increments            01/01/70 00:00      
               bug            01/01/70 00:00      
                  more bugs            01/01/70 00:00      
                     thanks            01/01/70 00:00      

Back to Subject List