Why it is showing "loop is not reachable"?

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

Why it is showing "loop is not reachable"?

2,105 Views
pankajprasad100
Contributor III

Hi,

I am working on S32k144 with IAR compiler, in which i am getting the error as loop is not reachable.

 

Any solution for this issue.

 

Thanks &Regards

Pankaj Prasad

 

pankajprasad100_0-1626439331814.png

 

0 Kudos
6 Replies

2,086 Views
jiri_kral
NXP Employee
NXP Employee

Hi, 

 

can you please share part of code where the for(;;) loop is located? 

 

Jiri

0 Kudos

2,076 Views
pankajprasad100
Contributor III

hi,

Please check with this code

/* Including necessary module. Cpu.h contains other modules needed for compiling.*/
#include "Cpu.h"

volatile int exit_code = 0;

/* User includes (#include below this line is not maintained by Processor Expert) */

/*!
\brief The main function for the project.
\details The startup initialization sequence is the following:
* - startup asm routine
* - main()
*/

 

char flag_1=0,flag_2=0,temp=20,result_1,result_2;

 


void ftmTimerISR_1(void)
{
/* Static variable for storing the timer overflow count */
static uint8_t s_overflowCount = 0U;

if(s_overflowCount>8)
{
PINS_DRV_TogglePins(PTD, 1 << 6);
flag_1=1;
result_1=1;
s_overflowCount=0;
temp=50;
}
else{
s_overflowCount++;
result_1=0;
//flag_1=0;

}
FTM_DRV_ClearStatusFlags(INST_FLEXTIMER_MC1, (uint32_t)FTM_TIME_OVER_FLOW_FLAG);
}

void ftmTimerISR_2(void)
{
/* Static variable for storing the timer overflow count */
static uint8_t s_overflowCount = 0U;
if(s_overflowCount>5)
{
PINS_DRV_TogglePins(PTC, 1 << 15);
flag_2=1;
result_2=1;
s_overflowCount=0;
}
else{
s_overflowCount++;
result_2=0;

}

FTM_DRV_ClearStatusFlags(INST_FLEXTIMER_MC2, (uint32_t)FTM_TIME_OVER_FLOW_FLAG);
}

 

 

 

int main(void)
{
/* Write your local variable definition here */

/*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
#ifdef PEX_RTOS_INIT
PEX_RTOS_INIT(); /* Initialization of the selected RTOS. Macro is defined by the RTOS component. */
#endif
/*** End of Processor Expert internal initialization. ***/

/* Write your code here */
/* For example: for(;;) { } */


ftm_state_t ftmStateStruct_1,ftmStateStruct_2;

CLOCK_SYS_Init(g_clockManConfigsArr, CLOCK_MANAGER_CONFIG_CNT,
g_clockManCallbacksArr, CLOCK_MANAGER_CALLBACK_CNT);
CLOCK_SYS_UpdateConfiguration(0U, CLOCK_MANAGER_POLICY_AGREEMENT);

/* Initialize pins
* - See PinSettings component for more info
*/
PINS_DRV_Init(NUM_OF_CONFIGURED_PINS, g_pin_mux_InitConfigArr);

/* Initialize GPIO
* - set direction (out)
* - set initial value
*/
PINS_DRV_SetPinsDirection(PTC, (1 << 15));
PINS_DRV_SetPinsDirection(PTD, (1 << 6));
PINS_DRV_SetPinsDirection(PTE, (1 << 16));


FTM_DRV_Init(INST_FLEXTIMER_MC1, &flexTimer_mc1_InitConfig, &ftmStateStruct_1);
INT_SYS_InstallHandler(FTM0_Ovf_Reload_IRQn, &ftmTimerISR_1, (isr_t*) 0U);
INT_SYS_EnableIRQ(FTM0_Ovf_Reload_IRQn);
FTM_DRV_InitCounter(INST_FLEXTIMER_MC1, &flexTimer_mc1_TimerConfig);
// FTM_DRV_CounterStart(INST_FLEXTIMER_MC1);


FTM_DRV_Init(INST_FLEXTIMER_MC2, &flexTimer_mc2_InitConfig, &ftmStateStruct_2);
INT_SYS_InstallHandler(FTM1_Ovf_Reload_IRQn, &ftmTimerISR_2, (isr_t*) 0U);
INT_SYS_EnableIRQ(FTM1_Ovf_Reload_IRQn);
FTM_DRV_InitCounter(INST_FLEXTIMER_MC2, &flexTimer_mc2_TimerConfig);
// FTM_DRV_CounterStart(INST_FLEXTIMER_MC2);



while(1)
{
flag_1=0;
FTM_DRV_CounterStart(INST_FLEXTIMER_MC1);
while(flag_1!=1);
FTM_DRV_CounterStop(INST_FLEXTIMER_MC1);
temp=~temp;
}

/*** Don't write any code pasthis line, or it will be deleted during code generation. ***/
/*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/
#ifdef PEX_RTOS_START
PEX_RTOS_START(); /* Startup of the selected RTOS. Macro is defined by the RTOS component. */
#endif
/*** End of RTOS startup code. ***/
/*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
for(;;) {
if(exit_code != 0) {
break;
}
}
return exit_code;
/*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/


Thanks & Regards

PANKAJ PRASAD

0 Kudos

2,069 Views
jiri_kral
NXP Employee
NXP Employee

Hi, 

the IAR compiler is  complaining because there no way how the for(;;) loop can be reached. The program will be forever stuck in while(1) loop what means that there is also no way how to reach the return. 

 

I think you can remove the for(;;) loop. 

 

Jiri

0 Kudos

2,068 Views
pankajprasad100
Contributor III

Hi,

After removing for(;;),while compiling the code the for loop is added.

Same problem loop is not reachable. 

0 Kudos

2,065 Views
jiri_kral
NXP Employee
NXP Employee

Hi, 

 

I see, I forgot that the part of code is autogenerated. Well, in this case - you need to add some break; condition in your while(1) loop. You can copy/paste the part from for(;;) loop: 

if(exit_code != 0) 
break;

 

and add it into your while(1) loop like this: 

while(1)
{
flag_1=0;
FTM_DRV_CounterStart(INST_FLEXTIMER_MC1);
while(flag_1!=1);
FTM_DRV_CounterStop(INST_FLEXTIMER_MC1);
temp=~temp;

if(exit_code != 0) break;
}

 

Hope it helps. 

 

Jiri

 

 

 

0 Kudos

2,063 Views
pankajprasad100
Contributor III

Hi,

Thankyou jiri , now its working...   

 

0 Kudos