Enable interrupts

General discussion on mikroPascal PRO for PIC32.
Post Reply
Author
Message
LGR
Posts: 3204
Joined: 23 Sep 2004 20:07

Enable interrupts

#1 Post by LGR » 22 Dec 2012 04:16

Something that I noticed by happenstance in the asm code:

Code: Select all

;initpsc1.mpas, 403 ::                 setuart;           // Set UART parameters
0x9D005D0C        0x0F4016B0  JAL        initpsc1_setuart+0
0x9D005D10        0x70000000  NOP        
;initpsc1.mpas, 404 ::                 EnableInterrupts();   <<<<<<<<<<<<-----------!!!!!!!!!!!!!!!!
;initpsc1.mpas, 405 ::                 readSD;            // Read the CONTROL.TXT file
0x9D005D14        0x0F4010CC  JAL        initpsc1_readSD+0
0x9D005D18        0x417E6020  EI        R30
It appears that EnableInterrupts(); generates no code!
If you know what you're doing, you're not learning anything.

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: Enable interrupts

#2 Post by janko.kaljevic » 24 Dec 2012 18:36

Hello,

EnableInterrupts() function definitely should generate EI function call in assembly.
Please if you can post here a code example that generated this behavior and I will insoect it.

Best regards.

LGR
Posts: 3204
Joined: 23 Sep 2004 20:07

Re: Enable interrupts

#3 Post by LGR » 24 Dec 2012 18:56

It's part of a fairly large program, but the 'init' procedure is:

Code: Select all

procedure init;
begin
  setbasic;          // Basic initialization
  zero;              // Zero out variables
  diagnostics;       // Startup-diagnostics
  setuart;           // Set UART parameters
  EnableInterrupts();
  readSD;            // Read the CONTROL.TXT file
  //assign;            // Assign variables based upon the CONTROL.TXT file
  loadalg;           // Load pump control algorithm into RAM
end;
This generates this in the .lst file:

Code: Select all

_init:
;initpsc1.mpas, 400 ::                 begin
0x9D0062DC        0x27BDFFFC  ADDIU        SP, SP, -4
0x9D0062E0        0xAFBF0000  SW        RA, 0(SP)
;initpsc1.mpas, 401 ::                 setbasic;          // Basic initialization
0x9D0062E4        0x0F401377  JAL        initpsc1_setbasic+0
0x9D0062E8        0x70000000  NOP        
;initpsc1.mpas, 402 ::                 zero;              // Zero out variables
0x9D0062EC        0x0F40116E  JAL        initpsc1_zero+0
0x9D0062F0        0x70000000  NOP        
;initpsc1.mpas, 403 ::                 diagnostics;       // Startup-diagnostics
0x9D0062F4        0x0F4011DF  JAL        initpsc1_diagnostics+0
0x9D0062F8        0x70000000  NOP        
;initpsc1.mpas, 404 ::                 setuart;           // Set UART parameters
0x9D0062FC        0x0F4013DF  JAL        initpsc1_setuart+0
0x9D006300        0x70000000  NOP        
;initpsc1.mpas, 405 ::                 EnableInterrupts();
;initpsc1.mpas, 406 ::                 readSD;            // Read the CONTROL.TXT file
0x9D006304        0x0F4010E9  JAL        initpsc1_readSD+0
0x9D006308        0x417E6020  EI        R30
;initpsc1.mpas, 408 ::                 loadalg;           // Load pump control algorithm into RAM
0x9D00630C        0x0F401404  JAL        _loadalg+0
0x9D006310        0x70000000  NOP        
;initpsc1.mpas, 409 ::                 end;
As far as I can tell the interrupts work, and I discovered that when I look at the .asm instead of the .lst, I get this:

Code: Select all

_init:
;initpsc1.mpas,400 ::                 begin
ADDIU        SP, SP, -4
SW        RA, 0(SP)
;initpsc1.mpas,401 ::                 setbasic;          // Basic initialization
JAL        initpsc1_setbasic+0
NOP        
;initpsc1.mpas,402 ::                 zero;              // Zero out variables
JAL        initpsc1_zero+0
NOP        
;initpsc1.mpas,403 ::                 diagnostics;       // Startup-diagnostics
JAL        initpsc1_diagnostics+0
NOP        
;initpsc1.mpas,404 ::                 setuart;           // Set UART parameters
JAL        initpsc1_setuart+0
NOP        
;initpsc1.mpas,405 ::                 EnableInterrupts();
EI        R30    <<<<<<<<<<<<<<<<<<<<<<<<<<--------------------------------!!!!!
;initpsc1.mpas,406 ::                 readSD;            // Read the CONTROL.TXT file
JAL        initpsc1_readSD+0
NOP        
;initpsc1.mpas,408 ::                 loadalg;           // Load pump control algorithm into RAM
JAL        _loadalg+0
NOP        
;initpsc1.mpas,409 ::                 end;
L_end_init:
Looking closer, the EI is present in the .lst, it's just in the wrong line. It's a couple of lines down. It looks like the .lst file isn't being correctly formed.
If you know what you're doing, you're not learning anything.

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: Enable interrupts

#4 Post by janko.kaljevic » 25 Dec 2012 11:54

Hello,

The compiler generates the call, and I missed it in your first post. Sorry for that :oops:

The call that enables interrupt is:

Code: Select all

EI        R30
And in this case it is located in delay slot of JAL instruction.
That way it is first instruction after JAL.

Best regards.

LGR
Posts: 3204
Joined: 23 Sep 2004 20:07

Re: Enable interrupts

#5 Post by LGR » 25 Dec 2012 16:29

Look closely at the .lst and the .asm. They're not the same. They were generated from the same pascal, but the EI is in different places. I'm not sure which is correct.

It really doesn't matter practically, the program does work. But then again, the placement of the EI isn't critical, either in this case. I was just pointing out something strange. One of those isn't exactly right, and I suspect that it's the .lst.
If you know what you're doing, you're not learning anything.

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: Enable interrupts

#6 Post by janko.kaljevic » 26 Dec 2012 09:27

Hello,

listing file is the generated code which will be loaded into controller. asm file is first generated file without optimization.
And in this case as you can see EI will be executed and JAL instruction will execute NOP in it's delay slot.
So after optimization you will get JAL with EI in delay slot.

Best regards.

LGR
Posts: 3204
Joined: 23 Sep 2004 20:07

Re: Enable interrupts

#7 Post by LGR » 26 Dec 2012 16:11

It's good to know that. That being the case, is there any reason to ever refer to the .asm file?
If you know what you're doing, you're not learning anything.

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: Enable interrupts

#8 Post by janko.kaljevic » 27 Dec 2012 15:56

Hello,

User should always look at listing file because this will be the code that controller will execute.

Best regards.

Post Reply

Return to “mikroPascal PRO for PIC32 General”