1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
#include <linux/module.h>
#include <linux/kernel.h>
#include <rtl_fifo.h>
#include <linux/rtl.h>
#include <asm/rt_irq.h>
#include <asm/rt_time.h>
#include <rtl_sched.h>
#include <asm/io.h>
#include <linux/cons.h>
#include "common.h"
#define TIMEOUT 100000
#define SKIP 1000
#define PERIOD 500
RT_TASK mytask;
RTIME min_response;
RTIME max_response;
struct sample samp;
int skip;
void fun(int t) {
register int i;
register int orig;
int flags;
RTIME before, after, response;
while (1) {
for (skip = 0; skip < SKIP; skip++) {
r_save_flags(flags);
r_cli();
outb_p(0, LPT_PORT);
orig = inb_p(LPT_PORT + 1);
outb(0xff, LPT_PORT);
before = rt_get_time();
i = 0;
while ((inb(LPT_PORT + 1) == orig) && ++i < TIMEOUT);
/* while ((inb(LPT_PORT + 1) == orig) && rt_get_time() < before + TIMEOUT); */
after = rt_get_time();
if (i >= TIMEOUT) {
rtl_printf("timeout!!!\n");
r_restore_flags(flags);
rt_task_wait();
return;
}
response = after - before;
if (response < min_response) {
min_response = response;
}
if (response > max_response) {
max_response = response;
}
r_restore_flags(flags);
rt_task_wait();
}
samp.min = min_response;
samp.max = max_response;
rtf_put(0, &samp, sizeof(samp));
}
}
int init_module(void)
{
RTIME now = rt_get_time();
min_response = 1000000000;
max_response = 0;
rtf_create(0, 4000);
rt_task_init(&mytask, fun, 1, 3000, 4);
rt_task_make_periodic(&mytask, now + 3000, PERIOD);
return 0;
}
void cleanup_module(void)
{
rt_task_delete(&mytask);
rtf_destroy(0);
}
|