Hi all Iam using STR912FW44 based board and I want a delay function that should give the delay in milisecond I made a function
void delay_ms (unsigned long nCount){ /* Wait function */ nCount=nCount+16000000L; while (nCount--); }
when I call
delay_ms(10000);
it gives arround 10 second delay but when I call
delay_ms(20000); it should give arround 20 second delay but it does not happen
but when I call
delay_ms(10000); delay_ms(10000);
it gives arround 15 sec delay
please tell me exact way to build a delay function
regards rupesh
// this system call will only stop user timers - never the first MAX_TASKS timers dedicated // to waiting periods of tasks void timer_stop_all(void) { int32u l_index = USER_TIMER_SLOTS - 1, l_scheduler_state ; timer_t *lp_timer = s_timers + MAX_TASKS - 1 + USER_TIMER_SLOTS - 1 ; scheduler_disable(&l_scheduler_state) ; system_timer_disable() ; do { lp_timer->state = e_timer_not_ticking ; --lp_timer ; } while (l_index-- != 0) ; system_timer_enable() ; scheduler_restore(l_scheduler_state) ; } // stop a specific user timer. stopped a timer whose index is smaller than MAX_TASKS is not // allowed as these timers are dedicated to waiting tasks int32s timer_stop(int32s a_index) { int32s l_result = 0 ; if ( ( (a_index >= 0) && (a_index < MAX_TASKS) ) || (a_index < 0) ) { l_result = ERR_INVALID_PARAMETER ; } else { int32u l_scheduler_state ; scheduler_disable(&l_scheduler_state) ; system_timer_disable() ; (s_timers + a_index)->state = e_timer_not_ticking ; system_timer_enable() ; scheduler_restore(l_scheduler_state) ; } return l_result ; } int32u timer_ticks_remaining(int32s a_index) { int32u l_result = 0 ; // user is allowed to investigate remaining time for every timer - also timers that // are integrated into tasks (for wait purposes...) if (a_index < 0) { software_error("%d %s %d", ERR_INVALID_PARAMETER, __FILE__, __LINE__) ; } else { int32u l_scheduler_state ; scheduler_disable(&l_scheduler_state) ; system_timer_disable() ; l_result = (s_timers + a_index)->deadline_countdown ; system_timer_enable() ; scheduler_restore(l_scheduler_state) ; } return l_result ; } // invoked from TIM1 ISR void TIM1_callback(void) { timer_t *lp_timer ; int32u l_index = s_max_timers - 1 ; ++g_tick_count ; // update all timers do { lp_timer = s_timers + l_index ; // an interrupt can occur before the next call to timer_poll that will reset 'deadline_countdown' // prevent an underflow if ( (lp_timer->state == e_timer_ticking) && (lp_timer->deadline_countdown > 0) ) { --lp_timer->deadline_countdown ; } if ( (lp_timer->state == e_timer_ticking) && (lp_timer->deadline_countdown == 0) ) { // the next call to timer_poll will reveal how late the call way with regards to // the expiration of the timer switch (lp_timer->mode) { case e_timer_poll_mode: { lp_timer->state = e_timer_expired ; lp_timer->late_counter = 1 ; if ( ( (*(g_tcb + l_index))->status == e_task_waiting) || ( (*(g_tcb + l_index))->status == e_task_waiting_for_message) ) { scheduler_declare_task_ready(l_index, (*(g_tcb + l_index))->priority) ; } } break ; case e_timer_exact_period_mode: { lp_timer->deadline_countdown = lp_timer->period ; // invoke callback if (lp_timer->callback) { lp_timer->callback(lp_timer->callback_parameter) ; } } break ; case e_timer_exact_oneshot_mode: { lp_timer->state = e_timer_expired ; // invoke callback if (lp_timer->callback) { lp_timer->callback(lp_timer->callback_parameter) ; } } break ; default: software_error("%d %s %d\n", ERR_INVALID_TIMER_MODE, __FILE__, __LINE__ ) ; } } else if (lp_timer->state == e_timer_expired) //&& (lp_timer->deadline_countdown == 0) ) { ++lp_timer->late_counter ; // this will specify to the caller by how much time he was late } } while (l_index-- != 0) ; } #endif // TIMER_MODULE