accessing an isr static variable

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
BeHi_4668916
Level 1
Level 1
First like received

I have an application that is getting stuck when I try to access a static variable from within my isr.  The interrupt is working and at a periodic interval (1 millisecond) the isr is incrementing a static variable inside that file.  If I reference that variable directly in the sysTickDelay function there is no problem, BUT if I access it using a getSysTick function then my application gets stuck.  I've used this same technique before on other micros and it has worked, not sure what I am doing, or have configured differently here that it is not working on my PSoC4 application.

Thanks.

/* Variables

-------------------------*/

static uint32_t oneMsecTick = 0;

/**

  * @brief  This function is called from the SysTick ISR every millisecond.

  *         It increments a variable to be used as a consistent time base.

  *

  * @param  None

  * @retval None

  */

void sysTickIncrement( void )

{

  oneMsecTick++;

}

/**

  * @brief  Provides access to SysTick variable value in milliseconds.

  *

  * @param  None

  * @retval Tick value

  */

uint32_t getSysTick( void )

{

  return ( oneMsecTick );

}

/**

  * @brief  Provides a blocking delay in millisecond.

  *

  *  * @param  delay_mSecs : specifies the delay time length, in milliseconds.

  * @retval None

  */

void sysTickDelay( uint32_t delay_mSecs )

{

  uint32_t timeDelay = getSysTick() + delay_mSecs;

  while( getSysTick() < timeDelay )

  {

//    feedTheWatchDog();  /* Refresh the watchdog timer */

    uint32_t count = 0;

    count++;

  }

}

0 Likes
1 Solution
Alakananda_BG
Moderator
Moderator
Moderator
50 likes received 250 sign-ins 250 replies posted

Hi,

You can refer to the below KBA

https://community.cypress.com/docs/DOC-15425

Regards,

Alakananda

Alakananda

View solution in original post

0 Likes
2 Replies
odissey1
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted

Correct to

static volatile uint32_t oneMsecTick = 0;

The volatile keyword instructs the compiler that the variable is subject to sudden changes and should not be optimized.

/odissey1

Alakananda_BG
Moderator
Moderator
Moderator
50 likes received 250 sign-ins 250 replies posted

Hi,

You can refer to the below KBA

https://community.cypress.com/docs/DOC-15425

Regards,

Alakananda

Alakananda
0 Likes