Subject:
|
Re: librcx & interrupt handler
|
Newsgroups:
|
lugnet.robotics.rcx
|
Date:
|
Fri, 30 Aug 2002 07:23:36 GMT
|
Viewed:
|
2669 times
|
| |
![Post a public reply to this message](/news/icon-reply.gif) | |
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:
![](/news/x.gif) | | 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: ![librcx & interrupt handler -Cédric Meuter (26-Aug-02 to lugnet.robotics.rcx)](/news/x.gif) ![](/news/46.gif) ![Re: librcx & interrupt handler -Kekoa Proudfoot (27-Aug-02 to lugnet.robotics.rcx)](/news/x.gif) ![](/news/46.gif) ![Re: librcx & interrupt handler -Cédric Meuter (28-Aug-02 to lugnet.robotics.rcx)](/news/x.gif) ![](/news/46.gif) ![Re: librcx & interrupt handler -Kekoa Proudfoot (28-Aug-02 to lugnet.robotics.rcx)](/news/x.gif) ![](/news/46.gif) ![Re: librcx & interrupt handler -Cédric Meuter (29-Aug-02 to lugnet.robotics.rcx)](/news/x.gif) ![](/news/46.gif) ![Re: librcx & interrupt handler -Kekoa Proudfoot (29-Aug-02 to lugnet.robotics.rcx)](/news/x.gif) ![](/news/46.gif) ![You are here](/news/here.gif)
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|