cancel
Showing results for 
Search instead for 
Did you mean: 

disabling/enabling interrupts, but with condition

omatza
Associate II
Posted on November 22, 2005 at 06:44

disabling/enabling interrupts, but with condition

7 REPLIES 7
omatza
Associate II
Posted on November 21, 2005 at 06:33

Hello

I saw somewhere, but I don't remember where :( , a sample of code that does something like this:

ints_enabled = interrput_status

..... //code

if ints_enabled

enable interrupts.

It was a very short (assembly, I think, source)

Can anybody help me restore it ?

thanks

Oren

fggnrc
Associate II
Posted on November 21, 2005 at 08:18

otmaza,

to test if the interrupts are enabled (condition code register flag I=0) there are two assembly instructions: JRM and JRNM.

The former jumps to the destination label when interrupts are enabled,

where the latter jumps when interrupts are disabled.

However, I don't know how to translate these assembler instructions in your C compiler...

Bye

EtaPhi

omatza
Associate II
Posted on November 21, 2005 at 08:44

Nice :)

I didn't notice those instractions.

Do you have example of assembly code ?

(I will see how to merge it to my C code)

Thanks

Oren

fggnrc
Associate II
Posted on November 21, 2005 at 09:47

Hello Oren.

I use only assembler when programming ST micros, so take my reply with a grain of salt...

The JRM and JRNM istructions alter the execution flow, so they can not mixed with C statements.

However my little contribution is an asm routine which returns the I state.

Its prototype is:

bool AreInterruptsEnabled( void );

Its asm body is:

Code:

AreInterruptsEnabled

LD X,S

CLR A

JRM WriteResult

CPL A

WriteResult

LD ($102,X),A

RET

I think that it is all you need...

EtaPhi

BTW: My routine is untested. It makes these assumptions:

- the caller pushes one byte on the stack for the result

- the caller pops the result form the stack

- the stack is located in page 1

If the C compiler uses different calling assumptions IT CRASHES VERY BADLY.

omatza
Associate II
Posted on November 21, 2005 at 13:12

Hello EtaPhi

Thanks a lot for the help!

I wonder if you can tell me what is the S register in your code.

Is it the SP register ?

Why is the indexed is $102 ?

What is page 1 ? (I only know that there is page 0 for short access, and the rest (for long access))

do you mean - not page 0 ?

Also when you wrote

the caller pushes one byte on the stack for the result

you mean that is one C routine parameter ?

And ''the caller pops the result form the stack'' do you mean that the results always return in the stack, and not in register A ?

Thanks a lot

Oren

Anyway, it gave me direction....

fggnrc
Associate II
Posted on November 22, 2005 at 04:24

Hello Oren.

Here are the code explanations.

Quote:

I wonder if you can tell me what is the S register in your code.

Is it the SP register ?

Yes, S is the lower byte of the stack pointer.

Quote:

Why is the indexed is $102 ?

The stack area is generally mapped at the upper zone of page 1, i.e. downwards from $01FF.

When the LD X,S executes, the top stack contains the caller address (two bytes). LD A,($100,X) reads the top stack value, which is the first unused location. If one wants to read the first byte before the return address, he/she must add 3 to S, because S+1 contains the lower byte of return address, S+2 contains the higher byte and S+3 contains the byte that was pushed by the caller.

BTW, I made an error: LD ($103,X),A - not LD ($102,X),A - sets the result...

Quote:

What is page 1 ?

You know what page 0 is. By extending this idea each block of 256 bytes is generally called page. According to this definition, the page number is equal to the HIGH byte of the block address.

Quote:

Also when you wrote

the caller pushes one byte on the stack for the result

you mean that is one C routine parameter ?

And ''the caller pops the result form the stack'' do you mean that the results always return in the stack, and not in register A ?

The calling convention is compiler specific. My code uses one convention which may not be what your compiler expects.

If the result is returned in A, then the code becomes simpler:

Code:

AreInterruptsEnabled

CLR A

JRM ReturnInterruptsState

CPL A

ReturnInterruptsState

RET

Regards,

EtaPhi

omatza
Associate II
Posted on November 22, 2005 at 06:44

EtaPhi

Thanks a lot.

You were very kind, and helped a lot.

Yours

Oren

(I use Cosmic compiler, so I will search now for theconvention of the compiler in the Cosmic documents :) )