AnsweredAssumed Answered

extern variable doubt

Question asked by vinod Karuvat on Oct 2, 2014
Latest reply on Jul 18, 2016 by SCOTT MILLER

Hello Friends,

 

I am writing some code for a KL04 chip. I want to define and use a global variable which can eventually be placed in a header file.

The value of that variable will  be changed/modified in a few different functions. But, I am getting no result. The definition and usage are shown below

 

extern volatile uint8_t commState;

 

// - function 1 -- //

static void runMode(uint8_t commState){ 

          uint8_t nextState;  

          volatile uint8_t commState;          

          nextState = commState;  

          dutyCycle = 10; 

           while(1){

//            tempCountValSaved = tempCount;

                 stateChange(nextState,dutyCycle);

                     commTimerFunc(tempCount);

                     while(commutationFlag == 0){

  }                       

                     commutationFlag = 0;

                     nextState--;

             if(nextState >=6) nextState = 5;

//            zeroCrossTempFlag = 0;           

           }         

        }

 

// -- function 2 -- //

 

static uint8_t blindStartUp(uint8_t commState){   
                            
                

      uint8_t slotCounts = 0;

      uint8_t nextState = 0;

      uint8_t dutyCycle;

      uint8_t rpmStartup = 0;

      uint8_t rough = 0;

      uint8_t initIteration = 0;

      uint8_t runTime = 0;

      uint8_t flagger = 0; 

      volatile uint8_t commState;                 

     

     

      nextState = commState;

      tempCount = 12000; 

      zeroCrossFlagDet = 0;  

  while(zeroCrossFlagDet != 1){   
      while(tempCount >= 1500){
     
    stateChange(nextState,dutyCycle);
          commTimerFunc(tempCount);
    while(commutationFlag == 0);
    commutationFlag = 0;
    nextState--;
       if(nextState >=6) nextState = 5;                   
   }               
   // --------------------------------------- //
      if(zeroCrossFlagDet != 1){
      
       }                   
    commutationFlag = 0;                   
    nextState--;
    if(nextState >=6) nextState = 5;
    zeroCrossTempFlag = 0;
   }
  }
  asm("nop");
                
commState = nextState;
return(zeroCrossFlagDet);
}

    

 

 

Now , in both these functions commState is being modified but there is no change.

The value what I give in the first time stays in commState. So, what exactly is the syntax of an

extern in Kinetis or rather Code Warrior.

 

 

Regards,

Vinod.

Outcomes