You are here

Setting variable from method called by ISR | Cypress Semiconductor

Setting variable from method called by ISR

Summary: 2 Replies, Latest post by ran_d0m on 01 Dec 2016 01:38 PM PST
Verified Answers: 0
Last post
Log in to post new comments.
user_459156114's picture
User
24 posts

I'm still learning the in's and out's of C programing so this maybe a very obvious question. I have a Timer that calls an ISR. In my ISR I have this code: 

clockCounter++;
    
    if (clockCounter == 1600) {
        Increment_Quadrant_LED_OFF_Timer();
        Increment_Quadrant_Reset_Timer();
        Increment_Power_Off_Timer();
        clockCounter = 0;
    }

So that every second it calls those three methods to increment some other timer counters. My though process is that this is the cleanest way to handle keeping track of the timers in the appropriate other classes. 

 

Here is what my Increment_Quadrant_LED_OFF_Timer() function looks like: 

void Increment_Quadrant_LED_OFF_Timer()
{    
    if (!quadrant_LED_OFF_timer_ENABLED) { 
        return; 
    }

    quadrant_LED_OFF_timer_counter++;
    if (quadrant_LED_OFF_timer_counter >= (QUADRANT_LED_OFF_TIMER_DURATION / DEBUG_DIVIDER)) {
        Quadrant_LED_OFF_Timer_Did_Expire();
    }
}

Where quadrant_LED_OFF_timer_ENABLED variable and Quadrant_LED_OFF_Timer_Did_Expire() are defined in a class call app_Timers. So this works fine the first time that quadrant_LED_OFF_timer_ENABLED is set to 1 from my main.c.

Here is what my Quadrant_LED_OFF_Timer_Did_Expire() method looks like: 

void Quadrant_LED_OFF_Timer_Did_Expire()
{
    UART_UartPutString("Quadrant_LED_OFF_Timer_Did_Expire \n\r ");
    
    quadrant_LED_OFF_timer_ENABLED = 0;
    quadrant_LED_OFF_timer_counter = 0;
}

So you can see that I set my quadrant_LED_OFF_timer_ENABLED to 0 here.

If I debug and check quadrant_LED_OFF_timer_ENABLED after it has been set it's correct at 0.  However, continuing in debug if I check quadrant_LED_OFF_timer_ENABLED in this function Increment_Quadrant_LED_OFF_Timer() it's set back to 1. 

 

So just to clarify: 

void Increment_Quadrant_LED_OFF_Timer()

void Quadrant_LED_OFF_Timer_Did_Expire()

int quadrant_LED_OFF_timer_ENABLED

int quadrant_LED_OFF_timer_counter

Are all declared and defined in app_Timers.c and Increment_Quadrant_LED_OFF_Timer() is being called from Cook_Timer_ISR.c

 

My questions are: 

  1. What my take away from the debugging and my other programming experience is that the ISR is calling Increment_Quadrant_LED_OFF_Timer() from a different thread? Which is guess it's not technically a different "thread" but some other location in memory? However if this was the case I'm not sure how I'm getting proper UART output. 
  2. Is calling external methods like this to increment other counters the proper way to do this from an ISR? Or should I have a separate ISR for each timer that I need? It seems logical to have one counter that counts every 1 second then just piggy back off that one. Maybe not. 

Thanks for any help! 

user_1377889's picture
User
9581 posts

It is much easier to follow your code when you provide us with the complete project to look at. To do so, use
Creator->File->Create Workspace Bundle (minimal)
and attach the resulting file.

In terms of secure processing the lines

clockCounter++;   
    if (clockCounter == 1600) {

should read

clockCounter++;
    if (clockCounter >= 1600) {

just in case of that cosmic particle changing a bit...  ;-)

 

Bob

user_459156114's picture
User
24 posts

I wish that I could upload the project but due it's for work and strapped under NDAs and other legal mumbo jumbo so would get in trouble if client found out :-( 

Log in to post new comments.