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 / 1775
1774  |  1776
Subject: 
Re: librcx & interrupt handler
Newsgroups: 
lugnet.robotics.rcx
Date: 
Fri, 30 Aug 2002 07:23:36 GMT
Viewed: 
2669 times
  
Hi

Cédric Meuter <cedric.meuter@ulb.ac.be> wrote:
Now my question is how do I call the ROM
handler. I checked the adress in the doc you linked me to (it's 0x36ab), but
i don't exacly know how to call it... it's probably something in assembly,
like "jmp 0x36ab"... can you help me there?

You can do this in C.

   ((void(*)(void))0x36ab)();

i thought of that... but it seemed too easy...


(void(*)(void)) is a cast to make 0x36ab a pointer to a void function with
no parameters.  You then take that and use it as a function.

You still have to be careful about register usage and use the necessary
wrapper code to make sure the C code does not stomp on unsaved registers.
I didn't see this code in the example you posted.

here's what I wrote, and so far it seems to work proprly (tell me if I'm wrong):

#include <timer.h>
#include <null.h>
#include <irq.h>

static char _timer_data[64];

#define save_reg()       asm("push r0"); \
                         asm("push r1"); \
                         asm("push r2"); \
                         asm("push r3"); \
                         asm("push r4"); \
                         asm("push r5")

#define restore_reg();   asm("pop  r5"); \
                         asm("pop  r4"); \
                         asm("pop  r3"); \
                         asm("pop  r2"); \
                         asm("pop  r1"); \
                         asm("pop  r0")

void (*__ir_handler)(void);

extern char __rcall0 (short a);

extern char __rcall2 (short a, short p0, short p1);

void timer_handler(void) {
  save_reg();
  // do my stuff
  if (__ir_handler != NULL)
    __ir_handler();
  // then call the ROM handler
  ((void(*)(void))0x36ab)();
  restore_reg();
}

inline void init_timer(void) {
  __rcall2 (0x3b9a, (short)&_timer_data[6], (short)&_timer_data[0]);
  VECTOR_OCIA = timer_handler;
}

inline void shutdown_timer(void) {
  __rcall0 (0x3ed4);
}

Thanx for the help

Cédric



Message is in Reply To:
  Re: librcx & interrupt handler
 
(...) You can do this in C. ((void(*)(void))0x36ab)(); (void(*)(void)) is a cast to make 0x36ab a pointer to a void function with no parameters. You then take that and use it as a function. You still have to be careful about register usage and use (...) (22 years ago, 29-Aug-02, to lugnet.robotics.rcx)

7 Messages in This Thread:

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

Custom Search

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