diff mbox

example: timer: don't set timeout less than resolution

Message ID 1446245574-31181-1-git-send-email-ivan.khoronzhuk@linaro.org
State New
Headers show

Commit Message

Ivan Khoronzhuk Oct. 30, 2015, 10:52 p.m. UTC
The period cannot be less than timer resolution. Also the timer
accuracy is +- 1 tick, that means if period is [1;2) of tick the
timer can expire right after setting, but it doesn't break the
algorithm, so I didn't limit period to be more than 2*resolution.

Signed-off-by: Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org>
---
 example/timer/odp_timer_test.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
diff mbox

Patch

diff --git a/example/timer/odp_timer_test.c b/example/timer/odp_timer_test.c
index 94619e4..e081daf 100644
--- a/example/timer/odp_timer_test.c
+++ b/example/timer/odp_timer_test.c
@@ -252,7 +252,7 @@  static void print_usage(void)
  * @param argv  Argument vector
  * @param args  Test arguments
  */
-static void parse_args(int argc, char *argv[], test_args_t *args)
+static int parse_args(int argc, char *argv[], test_args_t *args)
 {
 	int opt;
 	int long_index;
@@ -311,6 +311,12 @@  static void parse_args(int argc, char *argv[], test_args_t *args)
 			break;
 		}
 	}
+
+	if (args->period_us > args->resolution_us)
+		return 0;
+
+	EXAMPLE_ERR("Error: period must be more then timer resolution\n");
+	return -1;
 }
 
 
@@ -371,7 +377,10 @@  int main(int argc, char *argv[])
 	}
 	memset(gbls, 0, sizeof(test_globals_t));
 
-	parse_args(argc, argv, &gbls->args);
+	if (parse_args(argc, argv, &gbls->args)) {
+		EXAMPLE_ERR("Error: Argumets are incorrect.\n");
+		return -1;
+	}
 
 	memset(thread_tbl, 0, sizeof(thread_tbl));