To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcxOpen lugnet.robotics.rcx in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / 2369
2368  |  2370
Subject: 
Re: [long] Interrupt programming, buggy code
Newsgroups: 
lugnet.robotics.rcx
Date: 
Tue, 2 Mar 2004 17:51:14 GMT
Viewed: 
6693 times
  
In lugnet.robotics.rcx, Benjamin Sigonneau wrote:
> Hi all,
> 
> I am currently programming the Lego RCX at low-level (plain C) using the
> GCC cross-compiler for Hitachi H8/300 and Kekoa Proudfoot's LibRCX. In
> fact, I'm designing exercises for students that learn micro-controller
> programming. Therefore, I don't even use the ROM routines (except those
> that deals with the lcd display).

All I can give you is guesses.  There are pleny of gurus here who will know the
answer.

Do you know if the display_debug() routine or any of the things it uses depends
on the interrupts you are taking over?  If default interrupt handler provides
facilities for display_debug(), and your handler does not provide those
facilities, maybe you hang?

> 
> I managed to deal with motors and touch sensors using both the Hitachi
> Hardware Manual and Kekoa Proudfoot's "RCX Internals".
> 
> I know want to program the H8/300 interrupts. I've managed to define an
> OCIA handler, but I'm afraid I've missed something since I can't get it
> to work right. This handler only increments a global and then displays
> its value on the LCD. That should be easy, but... When I run my program,
> the LCD displays 0, then 1, then 2, then 3, then... Then the RCX hangs,
> and I can't get anything from it. I have to remove the batteries and put
> them in again to "reboot" the crashed RCX.

Can we assume that interrupts are disable while in ocia_handler()?  An infinite
number of interrupts would cause this to happen.  Is there some other interrupt
source that you are enabling when you unmask, and it takes a while to fire?
Once it fires, it never stops because the interrupt handler(s) don't clear it?

> 
> I just don't see what I'm doing wrong, so I'm asking if anybody has an
> idea. In case such gurus lie around here, I post my C code below.

I'm very interested in seeing your final code.  I've used Kekoa's framework too
and it is pretty handy.

Kevin

> 
> Thanks.
> 
> 
> /* My buggy code */
> 
> int count;
> 
> #define mask_it()   asm ("orc  #0x80, ccr");
> #define unmask_it() asm ("andc #0x7f, ccr");
> 
> #define OCIA_HANDLER  *( (volatile word  *) 0xfda2)
> 
> void ocia_handler(void) __attribute__ ((interrupt_handler));
> void ocia_handler(void) {
>   FRT_TCSR &= ~bit3; /* clear output compare flag A */
>   count++;
>   debug_value(count);
> }
> 
> int main (void) {
> 
>   count = 0;
> 
>   /* debug_value is just a call to ROM routine at 0x1ff2
>    * that displays an integer */
>   debug_value(count);
> 
>   OCIA_HANDLER = (word)ocia_handler;   /* install OCIA handler */
> 
>   /* Timer clock selection: use div 32 clock */
>   FRT_TCR  |=  bit1;  /* CSK1 <- 1 */
>   FRT_TCR  &= ~bit0;  /* CSK0 <- 0 */
> 
>   FRT_TCSR  =  bit0;  /* Clear FRT on compare-match A */
>   FRT_TOCR &= ~bit4;  /* Compare timer to OCRA */
>   FRT_OCRA  = 50000;  /* Interrupt every 100 ms */
>   FRT_FRC   = 0;      /* Clear free running timer */
>   FRT_TCSR &= ~bit3;  /* Clear output compare flag A */
> 
>   /* Enable OCIA - see p. 117
>    * ie an interrupt is generated when FRT == OCRA
>    */
>   FRT_TIER |= bit3;
> 
>   /* Unmask interrupts */
>   unmask_it();
> 
>   while (!prgm_pressed()) {
>     /* Wait for "pgrm"button to be pressed */
>   }
> 
>   return 0;
> }



Message is in Reply To:
  [long] Interrupt programming, buggy code
 
Hi all, I am currently programming the Lego RCX at low-level (plain C) using the GCC cross-compiler for Hitachi H8/300 and Kekoa Proudfoot's LibRCX. In fact, I'm designing exercises for students that learn micro-controller programming. Therefore, I (...) (23 years ago, 2-Mar-04, to lugnet.robotics.rcx)

7 Messages in This Thread:





Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR