Detecting IRQ pin state in C

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Detecting IRQ pin state in C

1,625 Views
bigmac
Specialist III

Hello all,

 

I am using the MC9S08GT32A in conjunction with CW 6.3.  This device has a dedicated IRQ pin that is not shared with any GPIO.

 

Within a C program, I need to detect the current state of the IRQ pin, without generating an interrupt.  Using assembly code, I have the BIH and BIL instructions available, which might potentially be used within inline assembly code, But at this moment I am not sure how this would be accomplished.  

 

I wonder if there might be a simpler method, or perhaps an existing library function or macro within CW.

Any suggestions would be welcome.

 

Regards,

Mac

Labels (1)
Tags (1)
0 Kudos
4 Replies

711 Views
bigmac
Specialist III

Hello,

 

Perhaps my previous post was a little premature.  I was able to evolve the following function to return the current IRQ state.

 

byte get_IRQ( void){   __asm {      clra      bil B0      incaB0:   rts   }   return 0;}

 

 

The final return 0; does not generate any code because it is never reached.  It is there only to avoid a compiler warning about there being no return value (the return value is actually the accumulator value).  This method seems quite efficient in that it avoids the need for defining a local variable on the stack.

 

I would still like to hear of other ideas, and any comments.

 

Regards,

Mac

 

0 Kudos

711 Views
kef
Specialist I

There's dedicated intrinsic function for this:

 

/* returns the state of the external interrupt pin */
char __isflag_int(void);

 

You need to #include <intrinsics_hc08.h>, which can be found here

<CW 6.x root>\lib\hc08c\include\intrinsics_hc08.h

0 Kudos

711 Views
bigmac
Specialist III

Hello Kef,

 

Thanks for the input.  I did vaguely recall that I had previously seen functions that returned the state of some of the CCR flags, but did not realize that the IRQ pin was amongst them.

 

For simple functions like these, I usually like to check out the code that they generate, to determine bytes and cycles.  In this case, the source code would have been a macro rather than a function (as there is no JSR and RTS generated).  The method used is somewhat unorthodox, to say the least.  The following would be the equivalent assembly code.

 

    bih  B1    clra    dcb  0x65B1: lda  #01

 

How does it work when the branch is not taken?  The 0x65 value is an opcode for cphx #, so the instruction becomes

cphx #0xA601.  This does nothing except potentially change some CCR flags.

 

How is it possible to implement a branch within a macro?  Can the equivalent of bih *+4; be done with inline code?

 

Regards,

Mac

0 Kudos

711 Views
kef
Specialist I

CPHX opcode works here as a skip 2 bytes of code. Disassemble shows   SKIP2 L8.

 

Clearly you assigned return value to variable. Using it as

if ( __isrflag__int() )

{

}

won't generate those extra lda skip2 etc. Just BIH/BIL over {} block.

 

It is not a macro, it is compiler predefined inline function.

 

0 Kudos