Listing 1aHeres
the main routine for ETS. You program the timer using EtsSetTimerperiod() and install
the servo interrupt service routine (ISR) as a timer call back using EtsRegisterCallback() from the
ETS application programming interface. bIn QNX, setting up the ISR
is done much like in ETS. clock_setres() sets the timer period, and qnx_hint_attach() attaches an
ISR to the timer call-back chain. Since QNX is an operating system, which persists after
we get done running our program, we want to make sure that we remove our ISR when done.
a)
#include "global.h"
#include "servo.h"
main() {
int Servo_Isr();
EtsSetTimerPeriod(1);
EtsRegisterCallback((WORD)ETS_CB_TIMER,
&Servo_Isr, 0, ETS_CB_ADD);
GaitThread(); }
b)
#include "global.h"
#include "servo.h"
main(){
pid_t far Servo_Isr();
int id,i;
struct timespec st;
st.tv_sec = 0;
st.tv_nsec = 500000;
clock_setres(CLOCK_REALTIME, &st);
if((id = qnx_hint_attach( 0, &Servo_Isr,
FP_SEG(&SetTime[0]))) == -1 ){
printf("can't attach interrupt\n");
exit(2); }
GaitThread();
qnx_hint_detach(id); }