Using VT as timeout generator
Posted: Wed Jun 13, 2012 2:43 pm
I want to implement timeout system in my project. This means that I want to set timer and continue endless loop. If in this loop I will see that timer was expired, I want to do something (save timeout error, for example).
Pseudo-code:
So, I want to:
1. Timer can be set in any place. If timer was set already, just reset ot and restart count from zero.
2. Do not wait for timer to expire, but continue working
3. Do not call any callbacks while timer was expired. Just return another value when I need this.
Can I do this and how?
Thanks!
Pseudo-code:
Code: Select all
while (1) {
if (!waiting_answer && timerExpired(tm_msg)) {
send_msg();
setTimer(tm_msg, 100);
setTimer(tm_answer, 100);
waiting_answer = 1;
}
if (cmd_received()) {
setTimer(tm_msg, 100);
waiting_answer = 0;
}
if (waiting_answer && timerExpired(tm_anwser)) {
// something happens, ERROR!
loudScreamAndCry();
}
doSomethingWithDataReceived();
}
So, I want to:
1. Timer can be set in any place. If timer was set already, just reset ot and restart count from zero.
2. Do not wait for timer to expire, but continue working
3. Do not call any callbacks while timer was expired. Just return another value when I need this.
Can I do this and how?
Thanks!