Is the timer an interrupt process? Is the function called by the timer executed as an interrupt process?

Hello!

I'm trying to handle an interrupt using a timer.

Is it okay to write something like the following?

/**
 * @brief Handler for timer events.
 */
void timer_twi_event_handler(nrf_timer_event_t event_type, void* p_context)
{

    switch (event_type)
    {
        case NRF_TIMER_EVENT_COMPARE1:
					
        
            flags = true;
            time++;
            //data_handler();
					
            break;

        default:
            //Do nothing.
            break;
    }
}


//timer init
nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
err_code = nrf_drv_timer_init(&TIMER, &timer_cfg, timer_twi_event_handler);
APP_ERROR_CHECK(err_code);

time_ticks = nrf_drv_timer_us_to_ticks(&TIMER, time_us);

nrf_drv_timer_extended_compare(
     &TIMER, NRF_TIMER_CC_CHANNEL1, time_ticks, NRF_TIMER_SHORT_COMPARE1_CLEAR_MASK, true);

nrf_drv_timer_enable(&TIMER);

Also, if this is called every 1ms as interrupt processing, will it be interrupt processing if you call the function you want to execute in "timer_twi_event_handler"?

void receive_data(){//receive mpu9250 20byte data -> mpu_buf[]
    ret_code_t ret = nrf_drv_spi_xfer(&spi,&xfer_spi,flags);//Function for starting the SPI data transfer with additional option flags
    if(ret == NRF_SUCCESS)
    {
        uint32_t start_tsk_addr = nrf_drv_spi_start_task_get(&spi);
    }
}


int j = 0;
uint8_t buf[10000] = {0};
uint8_t buf2[10000] = {0};


void put_in_array(uint8_t array[10000]){
    for(int a = 0; a <20;a++)
    {
        array[j*21+a] = mpu_buf[a];
    }
    array[j*21+20] = time;
    
}

/*void data_handler()
{
    receive_data();
    put_in_array(buf);

}*/


bool flag_buf = true;
bool flag_buf2= false;



/**
 * @brief Handler for timer events.
 */
void timer_twi_event_handler(nrf_timer_event_t event_type, void* p_context)
{

    switch (event_type)
    {
        case NRF_TIMER_EVENT_COMPARE1:
					
        
            flags = true;
            time++;
            receive_data();
            if(flag_buf == true){
              put_in_array(buf);
            }else if(flag_buf2 == true){
              put_in_array(buf2);
            }
            j++;
            //data_handler();
					
            break;

        default:
            //Do nothing.
            break;
    }
}

Thank you!

Related