Hi all,
  First off, I would like to introduce myself. I'm Thomas Folkers, Operations
Manager and Project Manager for the SubMillimeter Telescope Observatory
located in Tucson Arizona. I am in charge of updating the control system
for the Heinrich Hertz 10 Meter Radio Telescope located on the 10,500' peak
of Mt. Graham in southeast Arizona.

  I'm seriously considering using RT-Linux for most of our time critical 
real-time data taking and antenna control tasks.  I am not new to RT-Linux, 
having used it in 1998 for a similar project on the 12 Meter Radio Telescope
located on Kitt Peak, Arizona.  In fact in April, 1999, I had the pleasure of
following Mr. Yodaiken at a conference on Real Time systems held in Soccoro
New Mexico, presenting my results at the 12 Meter.  But, I have been out of 
the loop, so to speak, since then. 

  So, I come to you with my problem not so much as a newbie, but as one who may
be getting a little RT rusty...

  So, here's the drill. I have two systems, one running normal Linux and the
second, and soon to be more, running RT-Linux V3.0. The first system contains
a clock board which decodes IRIG-B and produces extremely accurate time which
is in turn feed into a custom version of xntpd running on said first system.
The IRIG-B signal comes from a Spectracom clock which is slaved to WWVB. So,
the time within the first system is traceable to the NIST. A Stratum-0 in NTP
parlance.

  Now, the second system, the one with the RTL running within, it is running
a plain, out of the box, version of xntpd configured to be a client to the 
xntpd server in the first system. So far so good. In fact, this configuration
works just fine. You can do a 'synchronized' date command and get the same
results. But, how accurate in the second clock? Let's find out.

  Out of the Spectracom clock comes a 1 Pulse/Second TTL signal. The falling
edge of this signal is coincident with the clocks internal time. I take this
1 PPS signal and condition it with a .5 usec one-shot to produce a suitable
interrupt signal for the second system. I plumb this signal into a ISA card
manufactured by Computer Boards, a CIO-CTR05 counter board, which has 
facilities for external interrupts.

  The goal here is to capture the interrupt in RT-Linux, get the time, give
a semaphore and return from the interrupt handler. A RT thread, sleeping on
the semaphore, wakes up, formats a simple string containing a index number
and the microseconds of time, writes it to a fifo and then goes back to sleep.
A Linux task reads from the fifo and prints it to stdout. That in turn is 
redirected to a log file.  Simple enough.  The plan is to plot the resulting
information and look for deviations in the usecs of time. This will in turn
tell me how well I can rely on xntpd to deliver accurate time and if it's
suitable enough for telescope control.

  This entire test works exactly and I had hoped. I have gotten results
that shows the time to be accurate down to the tens of microseconds. That
is, once the xntpd client has settled down, usually after about 90 minutes.
Even then, the errors are under 1 msec once the two xntpd processes are
in sync.

  But, and this is a big one, the test only lasts for a while before the
entire system hangs. I have run this test a dozen times and the longest it
ran was 15,900 seconds. Sometimes a short as 1500. The system is completely
hung, and totally un-responsive. Only pressing the reset button can bring
it back.

  I have tried different interrupts 7 and 3. I tried having the interrupt
handler write to the fifo, then I added the thread to do the writing.
None of these made a difference. I'm at my wits end on this one.

  I read in the FAQ's where Michael Barabanov said do_gettimeofday() was
safe to use in a RTL thread. Is it possible the it's not safe to use in
a interrupt handler. I have included his email below.

> 
> To: Karim Yaghmour <[EMAIL PROTECTED]> 
> Subject: Re: [rtl] do_gettimeofday available in hard real-time for RTAI 
> From: Michael Barabanov <[EMAIL PROTECTED]> 
> Date: Thu, 24 Aug 2000 11:05:52 +0400 
> Cc: [EMAIL PROTECTED] 
> 
> Karim Yaghmour ([EMAIL PROTECTED]) wrote:
> > 
> > .. skipped ...
> > The code I've written to fix do_gettimeofday isn't the most efficient
> > that can be written to do the job, but it works. Feel free to optimize
> > this and use it as you wish. If this can be used by RTLinux folks then
> > so be it.
> 
> Thanks, but
> in RTLinux, gettimeofday has been working correctly for a while already.
> 
> Michael.
> 

  Below you will find my source code. Not a whole lot to it, but something
in here is killing my system. If I don't run my test program the system never
crashs. Any and all help will be appreciated. And I apologize for the length
of this email. But, I felt that I needed to get all the facts out.

Thanks a bunch,
Thomas



*******************************************************************************
*                                                                             *
*     clock_test.c : Measure the time difference between a 1PPS Spectracom    *
*                    clock and the internal system time policed by xntpd.     *
*                    The 1PPS TTL signal has been conditioned to produce a    *
*                    .5usec signal at the interrupt pin.                      *
*                                                                             *
*******************************************************************************

#include <rtl.h>
#include <rtl_fifo.h>
#include <semaphore.h>
#include <pthread.h>

#define CT_IRQ 3
int n = 0;
int fifo;
struct timeval ct_tv;
sem_t irqsem;
pthread_t thread;
int indx = 0;

                                     /* Do not rt_task_wait() in a handler */
unsigned int handler(unsigned int irq_number, struct pt_regs *p) 
{
  do_gettimeofday(&ct_tv);
  sem_post(&irqsem);
  rtl_hard_enable_irq(CT_IRQ);
  return 0;
}

void *thread_code(void *param) 
{
  char buf[80];

  rtl_printf("clock_test: thread started\n");

  while(1) {
    sem_wait(&irqsem);
    sprintf(buf, "%6d %ld", n++, ct_tv.tv_usec);
    rtf_put(fifo, buf, sizeof(buf));
  }
  return(0);
}


int init_module(void)
{
  int debug;

  printk("Starting clock_test module\n");
  rtf_destroy(0);
  fifo = rtf_create(0, 4000);
  sem_init(&irqsem, 1, 0);
  pthread_create(&thread,  NULL, thread_code, (void *)1);
  debug = rtl_request_irq(CT_IRQ, handler);
  printk("Requested %d and got %d\n", CT_IRQ, debug);
  return 0;
}

void cleanup_module(void)
{
  printk("Removing clock_test module\n");
  rtl_free_irq(CT_IRQ);
  rtf_destroy(0);
  pthread_cancel(thread);
  pthread_join(thread, NULL);
  sem_destroy(&irqsem);
}

-- 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    _/_/_/_/   _/_/    _/_/  _/_/_/_/_/  _/_/_/_/  Thomas W. Folkers
   _/         _/ _/ _/  _/      _/      _/    _/  Telescope Operations Mgr.
  _/_/_/_/   _/   _/   _/      _/      _/    _/  Sub-Millimeter Telescope
        _/  _/        _/      _/      _/    _/  Kitt Peak 12M Radio Telescope
       _/  _/        _/      _/      _/    _/  933 N. Cherry Ave. Rm. 486
_/_/_/_/  _/        _/      _/      _/_/_/_/  Tucson, Arizona 85721
-------------------------------------------  email: [EMAIL PROTECTED]
------------------------------------------  Voice: (520) 626-7837
-- http://maisel.as.arizona.edu:8080/ ---  Fax:  621-5554  Pager: 446-0760
-- http://kp12m.as.arizona.edu/      ---  Mobil: 909-1113  Home:  742-9279
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- [rtl] ---
To unsubscribe:
echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
echo "unsubscribe rtl <Your_email>" | mail [EMAIL PROTECTED]
--
For more information on Real-Time Linux see:
http://www.rtlinux.org/rtlinux/

Reply via email to