From e24fa592d2a215d8ae67917c1d89e68cdf847a03 Mon Sep 17 00:00:00 2001 From: Vincent Palatin Date: Wed, 7 Dec 2011 18:58:43 +0000 Subject: Initial sources import 3/3 source files mainly done by Vincent. Signed-off-by: Vincent Palatin Change-Id: Ic2d1becd400c9b4b4a14d4a243af1bdf77d9c1e2 --- test/timer_dos.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 test/timer_dos.c (limited to 'test/timer_dos.c') diff --git a/test/timer_dos.c b/test/timer_dos.c new file mode 100644 index 0000000000..b0c37a4eaf --- /dev/null +++ b/test/timer_dos.c @@ -0,0 +1,39 @@ +/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + * Copyright 2011 Google Inc. + * + * Tasks for timer test. + */ + +#include "common.h" +#include "uart.h" +#include "task.h" +#include "timer.h" + +/* Linear congruential pseudo random number generator*/ +static uint32_t prng(uint32_t x) +{ + return 22695477 * x + 1; +} + +/* period between 500us and 128ms */ +#define PERIOD_US(num) (((num % 256) + 1) * 500) + +int TaskTimer(void *seed) +{ + uint32_t num = (uint32_t)seed; + task_id_t id = task_get_current(); + + uart_printf("\n[Timer task %d]\n", id); + + while (1) { + /* Wait for a "random" period */ + task_wait_msg(PERIOD_US(num)); + uart_printf("%01d\n", id); + /* next pseudo random delay */ + num = prng(num); + } + + return EC_SUCCESS; +} -- cgit v1.2.1