mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-12-29 01:50:53 +00:00
This is the first version of pthread-based RTOS emulator. With this, we will be able to test high-level modules entirely on the host machine. BUG=chrome-os-partner:19325 TEST='make runtests' and see tests passing. BRANCH=None Change-Id: I1f5fcd76aa84bdb46c7d35c5e60ae5d92fd3a319 Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/49954 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
64 lines
1.3 KiB
C
64 lines
1.3 KiB
C
/* Copyright (c) 2012 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.
|
|
*
|
|
* Tasks for timer test.
|
|
*/
|
|
|
|
#include "common.h"
|
|
#include "console.h"
|
|
#include "task.h"
|
|
#include "timer.h"
|
|
#include "util.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)
|
|
|
|
#define TEST_TIME (3 * SECOND)
|
|
|
|
int TaskTimer(void *seed)
|
|
{
|
|
uint32_t num = (uint32_t)seed;
|
|
task_id_t id = task_get_current();
|
|
timestamp_t start;
|
|
|
|
while (1) {
|
|
task_wait_event(-1);
|
|
|
|
ccprintf("\n[Timer task %d]\n", id);
|
|
start = get_time();
|
|
|
|
while (get_time().val - start.val < TEST_TIME) {
|
|
/* Wait for a "random" period */
|
|
task_wait_event(PERIOD_US(num));
|
|
ccprintf("%01d\n", id);
|
|
/* next pseudo random delay */
|
|
num = prng(num);
|
|
}
|
|
}
|
|
|
|
return EC_SUCCESS;
|
|
}
|
|
|
|
void run_test(void)
|
|
{
|
|
task_wake(TASK_ID_TMRD);
|
|
task_wake(TASK_ID_TMRC);
|
|
task_wake(TASK_ID_TMRB);
|
|
task_wake(TASK_ID_TMRA);
|
|
}
|
|
|
|
static int command_run_test(int argc, char **argv)
|
|
{
|
|
run_test();
|
|
return EC_SUCCESS;
|
|
}
|
|
DECLARE_CONSOLE_COMMAND(runtest, command_run_test,
|
|
NULL, NULL, NULL);
|