linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Jason McMullan <jason.mcmullan@timesys.com>
To: linuxppc-embedded <linuxppc-embedded@ozlabs.org>
Subject: Re: [PATCH 2.6.11.6] CPM2 Timers API
Date: Fri, 01 Apr 2005 08:50:15 -0500	[thread overview]
Message-ID: <1112363416.9748.5.camel@ad.doubleclick.net> (raw)
In-Reply-To: <1112301225.3337.19.camel@ad.doubleclick.net>


[-- Attachment #1.1: Type: text/plain, Size: 123 bytes --]


And here's the test-case kernel module....


-- 
Jason McMullan <jason.mcmullan@timesys.com>
TimeSys Corporation


[-- Attachment #1.2: cpm_timer_test.c --]
[-- Type: text/x-csrc, Size: 3852 bytes --]

/*
 * CPM Timers test
 *
 * Copyright 2004, Timesys Corp.
 * Jason McMullan <jason.mcmullan@timesys.com>
 */

#include <linux/init.h>
#include <linux/module.h>
#include <linux/delay.h>
#include <linux/wait.h>

#include <asm/cpm_timer.h>

static int failed = 0;
static volatile int once, every;

static wait_queue_head_t queue;

#define FAILED(x, args...) do { failed++; printk(KERN_INFO "cpm_timer_test: " x , ## args ); if (tm != NULL) { cpm_timer_stop(tm); cpm_timer_free(tm); } return -EINVAL; } while (0)

static void cpm_timer_test_callback(cpm_timer_t tm, void *data)
{
	if (data == &once) {
		unsigned long val = cpm_timer_get_ticks(tm);
		printk(KERN_INFO "cpm_timer_test: Called once at tick %ld.\n",
		       val);
		once++;
		wmb();
	}

	if (data == &every) {
		unsigned long val = cpm_timer_get_ticks(tm);
		printk(KERN_INFO
		       "cpm_timer_test: Called every(%d), tick %ld.\n", every,
		       val);
		every++;
		if (every > 5)
			cpm_timer_call_none(tm);
		wmb();
	}

	wake_up_interruptible(&queue);
}

static int test_timer(int timer_id)
{
	cpm_timer_t tm = NULL;
	int err;
	unsigned long res, val;

	printk(KERN_INFO "cpm_timer_test: Test timer ID 0x%.2x\n", timer_id);
	err = cpm_timer_alloc(timer_id, &tm);
	if (err < 0)
		FAILED("Can't allocate timer 0x%.2x\n", timer_id);

	res = cpm_timer_get_resolution(tm);
	printk(KERN_INFO "cpm_timer_test: nanoseconds/tick = %ld\n", res);

	val = cpm_timer_get_ticks(tm);
	printk(KERN_INFO "cpm_timer_test: current value = %ld\n", val);

	cpm_timer_stop(tm);
	cpm_timer_reset(tm);
	val = cpm_timer_get_ticks(tm);
	printk(KERN_INFO "cpm_timer_test: value after stop/reset= %ld\n", val);
	if (val != 0)
		FAILED("Timer 0x%.2x didn't stop!\n", timer_id);

	cpm_timer_start(tm);
	udelay(5);
	val = cpm_timer_get_ticks(tm);
	udelay(5);
	res = cpm_timer_get_ticks(tm);
	printk(KERN_INFO "cpm_timer_test: value after  5 us= %ld\n", val);
	printk(KERN_INFO "cpm_timer_test: value after 10 us= %ld\n", res);
	if (val == 0 || res == 0)
		FAILED("Timer 0x%.2x didn't increment!\n", timer_id);

	init_waitqueue_head(&queue);

	once = 0;
	err =
	    cpm_timer_call_once(tm, 50000, cpm_timer_test_callback,
				(void *)&once);
	if (err < 0)
		FAILED("Can't call cpm_timer_call_once for 0x%.2x\n", timer_id);

	printk(KERN_INFO "cpm_timer_test: Waiting for one-shot...\n");
	cpm_timer_start(tm);
	err = wait_event_interruptible(queue, once != 0);
	if (err < 0)
		FAILED("Interrupted sleep for 0x%.2x\n", timer_id);

	every = 0;
	err =
	    cpm_timer_call_every(tm, 50000, cpm_timer_test_callback,
				 (void *)&every);
	if (err < 0)
		FAILED("Can't call cpm_timer_call_every for 0x%.2x\n",
		       timer_id);

	printk(KERN_INFO "cpm_timer_test: Waiting for multi-shot x5...\n");
	cpm_timer_start(tm);
	err = wait_event_interruptible(queue, every > 5);
	if (err < 0)
		FAILED("Interrupted sleep for 0x%.2x\n", timer_id);
	cpm_timer_call_none(tm);
	printk(KERN_INFO "cpm_timer_test: Counted up to %d.\n", every);

	cpm_timer_stop(tm);
	cpm_timer_free(tm);

	return 0;
}

static int cpm_timer_test_init(void)
{
	int err;

	printk(KERN_INFO "CPM2 Timer Test Module.\n");

#define TEST(x) do { err=test_timer(x); if (err != 0) goto bad; } while (0)

	TEST(CPM2_TIMER16_1);
	TEST(CPM2_TIMER16_2);
	TEST(CPM2_TIMER16_3);
	TEST(CPM2_TIMER16_4);

	TEST(CPM2_TIMER32_1);
	TEST(CPM2_TIMER32_2);

      bad:
	if (failed) {
		printk(KERN_INFO "cpm_timer_test: FAILED %d tests\n", failed);
	} else {
		printk(KERN_INFO "cpm_timer_test: PASSED\n");
	}

	return 0;
}

static void cpm_timer_test_exit(void)
{
	printk(KERN_INFO "CPM2 Timer Test Module unloaded.\n");
	return;
}

MODULE_LICENSE("GPL");
module_init(cpm_timer_test_init);
module_exit(cpm_timer_test_exit);

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

      reply	other threads:[~2005-04-01 13:50 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-31 19:54 [PATCH 2.6.11.6] CPM2 Timers API Jason McMullan
2005-03-31 20:33 ` Jason McMullan
2005-04-01 13:50   ` Jason McMullan [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1112363416.9748.5.camel@ad.doubleclick.net \
    --to=jason.mcmullan@timesys.com \
    --cc=linuxppc-embedded@ozlabs.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).