Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: Provide Callback on entering Interrupt Routine #13

Open
jbaumann opened this issue Jun 20, 2020 · 1 comment
Open

Enhancement: Provide Callback on entering Interrupt Routine #13

jbaumann opened this issue Jun 20, 2020 · 1 comment

Comments

@jbaumann
Copy link

When working with the Watchdog, code has to be executed directly after waking up, otherwise the watchdog resets the Microcontroller.

When USI_Start_Condition_ISR() is called, then the processor might have been woken from any sleep mode, which means that the Watchdog has to be turned off very early during its execution.

I propose a callback for this. I have tested an implementation of this with my current application ATTinyDaemon with different communication partners (RPi3, RPI Zero...) and it works without adverse effects. Here is what my implementation looks like in USI_TWI_Slave.c, line 161ff:

__interrupt void USI_Start_Condition_ISR(void)
#endif
{

	unsigned char tmpPin; // Temporary variable for pin state
	unsigned char tmpRxHead; // Temporary variable to store volatile
	
	if (USI_TWI_On_Slave_Interrupt) {
            USI_TWI_On_Slave_Interrupt();
	}
	
	// call slave receive callback on repeated start
...

together with adding the attribute in TWI_Slave.h, line 41,

void (*USI_TWI_On_Slave_Interrupt)(void);

a method declaration in USIWire.h, line 66

    void onInterrupt( void (*)(void) );

and the following in USIWire.c, line 282ff:

// sets function called on slave interrupt
void USIWire::onInterrupt( void (*function)(void) ) {
  USI_TWI_On_Slave_Interrupt = function;
}
@jbaumann
Copy link
Author

Added a pull request for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant