my bad i did not look at your code, no time. please search for my postings a few months ago for details on how i did it.
if the processor is in a sleep mode that disables the clock the TPI, dependant on the clock, will be down and so this int will not wake the processor. but i dont have details on how the tpi is failing. i am basically using the tpi pin as an extra external interrupt in the code below. look it over if you will and if you need more details do the search but here is some details:
//in the begining of main.c
PTDD = 0x40; // pull port D pins low, except ptd6/tpm0input
PTDPE = 0xFF; // enable pullup's on all of portD
PTDDD = 0xBF; // All of Port D Data Direction set to OUTPUT 0xFF, except b6=input
DisableInterrupts;
//Timer Int Init mod timer interrupts, remove overflow, add outcput compare (1) and //input(0)
TPM1SC = 0x08; //setup common ch1&0 control reg, clr TPM1CNTx
//clock=bus, scale=1, pwm=off, overflow irq=off
TPM1C0SC=0x48; //set ch0 as input capture w/ irq
//irq=on, PTD6/TPM1CH0=in capture mode, +e&level.
TPM1C1SC=0x90; //set ch1 as output compare, irq=off,
//output compare=on, softwre compare=on.
TPM1C0SC = TPM1C0SC;//clr any pending input capture irq
TPM1C0SC &= 0x7F;
EnableInterrupts;
//int service routine
interrupt 5 void TPM1OutputCompare_ISR (void){
TPM1C1SC = TPM1C1SC; //2part irq reset.
TPM1C1SC &= 0x7F;
if(!timercounter) timertimeout++; //report irq status to main emulation .
timercounter--;
} //interrupt 5 void Timer...
//in my linker file *.prn
//*******************************>>> define unused interrupt vectors ****************************
//081906jmp, mod timer interrupts, remove overflow, add outcput compare (1) and input(0)
VECTOR 0 _Startup //reset vector: this is the default entry point for a C/C++ application
VECTOR 1 _Startup
//VECTOR 2 _Startup //used defined
VECTOR 3 _Startup
//VECTOR 4 _Startup //used defined
//VECTOR 5 _Startup //used defined
VECTOR 6 _Startup
VECTOR 7 _Startup
VECTOR 8 _Startup
VECTOR 9 _Startup
//VECTOR 10 _Startup //used defined
VECTOR 11 _Startup
//VECTOR 12 _Startup //used defined
VECTOR 13 _Startup
//VECTOR 14 _Startup //used defined
VECTOR 15 _Startup
//******************
i hope this gives you some thoughts onto your situation, good luck.