Idea.

Set up a timer interrupt to check the pin every second. After 300 seconds if the pin is still high then..