Disable timer interrupt

Hello

I impelmented code like this:

os_timer_t timer;
void setup() {
  
....
  os_timer_disarm(&timer);
  os_timer_setfn(&timer, (os_timer_func_t *)periodic_timer, NULL);
  os_timer_arm(&timer, TIMER_PERIOD*1000, 1); 
...
}

void loop() {

....

//here I need instruction that disables the timer interrupt or stops the time counter
some_function();
//here I need intruction that enables the timer interrupt or start the time counter

...

}



void periodic_timer()
{
...
}

I need instrction that disables timer interrupts. I know os_timer_arm or os_timer_disarm but these functions resets the timer counter and its start from the beginning. I need function that only stops counter or disables the interrupt. Thank You!

Without knowing anything about os_timer_t, you can't expect us to help you.

Ahh sorry, this is on ESP8266 module. Here is and here

Without knowing anything about os_timer_t, you can't expect us to help you.

os_timer_t is the following:

#define os_timer_t ETSTimer

typedef struct _ETSTIMER_ {
    struct _ETSTIMER_    *timer_next;
    uint32_t              timer_expire;
    uint32_t              timer_period;
    ETSTimerFunc         *timer_func;
    void                 *timer_arg;
} ETSTimer;

woodwax: ... I need instrction that disables timer interrupts. I know os_timer_arm or os_timer_disarm but these functions resets the timer counter and its start from the beginning. I need function that only stops counter or disables the interrupt. Thank You!

Before disarm, read the timer and use that value as an offset added to the next arm.

Like this?

os_timer_t timer;
uint32_t temp_expire;

temp_expire=timer.expire;
os_timer_disarm(&timer)

some functions......

os_timer_arm(&timer);
timer.expire=temp_expire;

os_timer_disarm(&timer); resets and disable the timer too. if you call it in periodic_timer(), your code will run once only.

#include <ESP8266WiFi.h>
unsigned int clock_tick = 0;
os_timer_t timer;
void setup() {
 Serial.begin(115200);

  os_timer_disarm(&timer);
  os_timer_setfn(&timer, (os_timer_func_t *)periodic_timer, NULL);
  os_timer_arm(&timer, 200, 1); 

}

void loop() {

}

void periodic_timer()
{
clock_tick +=1;
Serial.println(i);
if(clock_tick == 100)
os_timer_disarm(&timer);
}