CW 6.3 build 14 Lite optimization question

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

CW 6.3 build 14 Lite optimization question

2,493 Views
jjr
Contributor I
Hi,
I started setting up the ADC on the M52233 and I'm using the ini code
generated by the Freescale init software that allows you to
plug in some params and it generates the C code to ini various
peripherals. While debugging in mixed view mode I noticed the
line

// Wait for converter A power up to complete
while (MCF_ADC_POWER & MCF_ADC_POWER_PSTS0)

would never fall through because the compiler was not re reading the
MCF_ADC_POWER reg. I changed the definition to make it volitale

#define MCF_ADC_POWER *(volatile unsigned short *)(MFC_ADC_ADD + 0x52) // ADC Power Control register

but it still wouldn't work. I had to change the CodeWarrior global
optimization from 4, generate smallest code, to 2 to get it to
work.
I see where various regs in M5223x.h are using the volatile keyword
and it works with full optimization. Why do I have to lower it
to get the ADC loop to work ?


Thanks,
John

--
Alban Edit: format changed to allow text wrapping


Message Edited by Alban on 2007-10-01 08:50 PM
Labels (1)
0 Kudos
Reply
4 Replies

804 Views
odnt
Contributor I
Optimization will move "loop invariants" outside of a control loop. If the optimizer sees that you have already assigned "a = b", it will consider it a waste to just do it again. I suspect this is your problem, especially since reducing optimization changes it.

Try putting "#pragma opt_loop_invariants off" before the loop, and "#pragma opt_loop_invariants on" after.
0 Kudos
Reply

804 Views
jjr
Contributor I
Hi ,
 I modified it as follows, but it still didn't work unless the global optimiazation was lowered to 2.
 
  #pragma opt_loop_invariants off
    // Wait for converter A power up to complete
    while (MCF_ADC_POWER & MCF_ADC_POWER_PSTS0)
        ;
0001274C: 4A80            tst.l    d0
0001274E: 66FC            bne.s    fnInit_adc+0x44 (0x1274c); 0x0001274c
    // Wait for converter B power up to complete
    while (MCF_ADC_POWER & MCF_ADC_POWER_PSTS1)
  #pragma opt_loop_invariants on

  return;
00012750: 028100000800    andi.l   #0x800,d1
00012756: 66000104        bne.w    fnInit_adc+0x14a (0x1285c); 0x0001285c
  
 
 Thanks,
 John
.
0 Kudos
Reply

804 Views
jjr
Contributor I
Placing the  #pragma opt_loop_invariants off/on around the loop prevented it from working
even using global optimization level 2.
 
  John
 
0 Kudos
Reply

804 Views
jjr
Contributor I
The header file that I was making the change to set the reg as volatile and was not the
one that CW was using in the project, so that's why it ignored the keyword. I'm new to CW so I overlooked this. It now works as expected.

 Thanks,
 John

0 Kudos
Reply