class object inside interrupt handler

Hi.

if a class object is created in a funtion, and an interrupt handler is to access that objects variables. how can i set up the handler to use that object if it doesnt exist yet.

You want your ISR to affect a nonexistent object (yet) ?

Maybe write some pseudo code.

Create a global pointer or class static pointer to point to the object. Have the ISR check for a null pointer before using the object through the pointer.

Make sure the object you create is not local to the function. Local objects get deleted when the function returns. I think your object has to be global, static, or allocated with 'new'. I'm fairly sure that global and static objects have to be instantiated at load time so your function would not be 'creating' it.

You can't.

Also, probably a classic XY problem:

What is it?

The XY problem is asking about your attempted solution rather than your actual problem.

That is, you are trying to solve problem X, and you think solution Y would work, but instead of asking about X when you run into trouble, you ask about Y.

The Problem

This can lead to frustration by people who are trying to help you solve the problem because by the time you ask about it, the solution that you need help with might not have any obvious connections to the problem that you are trying to solve.

How to Avoid

To avoid falling into this trap, always include information about a broader picture along with any attempted solution. If someone asks for more information, or especially a more specific question, do provide details. If there are other solutions which you believe will be suggested and which you've already ruled out, then don't try to avoid going over them again – instead state why you've ruled them out, as this gives more information about your requirements and helps others provide better answers.

im only mucking around but want to know if its possible

create DataRec object

void data_recorder_run()
{
 InputRecorder DataRec;
 
 while(program_state == OptID::Opt1)
 {
 DataRec.flow_control();
 }
}

interrupt

void PIOC_Handler(void)
{
 InputRecorder DataRec;

 DataRec.PIO_ISR_reg_state[DataRec.log_idx] = INPUT_PIN_PORT->PIO_ISR;
 
 DataRec.PIO_PDSR_reg_state[DataRec.log_idx] = INPUT_PIN_PORT->PIO_PDSR;
 DataRec.time_stamp[DataRec.log_idx] = TC0->TC_CHANNEL[0].TC_CV;
 
 DataRec.samples_in++;
 
 if(++DataRec.log_idx >= log_limit)
 {
 DataRec.prog_state = Prog_State::PROCESS_LOG ;
 DataRec.stop_sampling_hardware();
 }

 
}
void loop()
{
 SI.check_for_int_input(program_state, Prog, ProgOpts);
 
 switch(program_state)
 {
 case OptID::Opt1 :
 data_recorder_run();
 //DataRec.flow_control();
 break;
 case OptID::Opt2 :
 
 break;
 case OptID::Opt3 :
 
 break;
 }

}

basically what im trying to do is make a simple data recorder which depending on which state it is in it stores info in different arrays. ie state 1 has a struct array[7500] of 2 uint32_t which is fine. both states will use arrays with uint32_t types so i can use the same array for both program states. but program state 2 will need struct array of 3 uint32_t, so im trying to figure out if there is a reliable way of creating these arrays and destroying them based on the state of the program.

state 1 needs - struct array[7500] of 2 uint32_t
state 2 needs - struct array[5000] of 3 uint32_t

cheers

The way your code is written your data_recorder_run() function and PIOC_Handler() function each create a local InputRecorder each time they run and that InputRecorder disappears as soon as the enclosing function exits. Those instances of InputRecorder don't share any data other than Class Static variables and functions (members declared 'static' in the class declaration are shared by all instances).

thanks john, im familiar with static members ill try this approach. i dont want to create an instance inside the handler. it would be best to take the struct array out of the class. if i declare a struct array inside a function, it is created on the stack isnt it. if i use new and delete to create struct array[7500] of 2 uint32_t, exit that function, then use new and delete in another function to create struct array[5000] of three uint32_t, will that cause me problems with fragmentation

What the hell are you doing that you need thousands of uint32s at a time?

Assuming you know what you're doing, you do need to use dynamic allocation (new and delete), and use a pair of global variables to store the pointer to the allocated array and the number of currently allocated objects.