INtime SDK Help
ResetRtInterruptHandler
INtime SDK v6 > About INtime > INtime Kernel > Interrupts > ResetRtInterruptHandler

Cancels the assignment of the current interrupt handler to the specified level and disables the level.

BOOLEAN ResetRtInterruptHandler(
    WORD wLevel
);

Parameters

wLevel
Encoded interrupt level

Remarks

If an interrupt thread has also been assigned to the level, the interrupt thread is deleted.

The level reserved for the system clock (IRQ0_LEVEL) is considered invalid for this call.

Note: This call is the only way to delete an interrupt thread. DeleteRtThread when invoked on an interrupt thread will fail with a status of E_CONTEXT. To cleanly delete an interrupt thread, call ResetRtInterruptHandler from inside the thread. Normally, when a thread runs to completion, it executes the user code associated with RslMain() and RSL_THREAD_DETACH. Calling ResetRtInterruptHandler from outside the interrupt thread will delete the thread but may not clean up all the resources associated with RSLs used by the process. This is a concern if you will be calling SetRtInterruptHandler again within the current process. See example below to show how an interrupt thread might be deleted with a view to recreating it within the same process.

Note: Before INtime version 6.3 there was an error in this call which meant that the RSL handlers did not get called in all cases. An acceptable workaround is to call DeleteRtThread just prior to calling ResetRtInterruptHandler. The DeleteRtThread call will fail with a status of E_CONTEXT, but will always call the RSL handlers, then the subsequent call to ResetRtInterruptHandlers will correctly delete the thread. If the workaround is left in after INtime 6.3 it will correctly fail the DeleteRtThread calls and call the RSL handlers from the ResetRtInterruptHandler call.

Example

The following code show how an interrupt thread might be deleted without leaking resources. The first snippet shows a simplified interrupt thread:

int kill_thread = 0;
void int_thread(void *param)
{
    :
    :
    while (1) {
        if (!WaitForRtInterrupt(level, WAIT_FOREVER)) {
            printf("WaitForRtInterrupt failed: %04x\n", GetLastRtError());
            break;
        }
        if (kill_thread) {
            kill_thread = 0;
            printf("Killing interrupt thread\n");
            break;
        }
        // TODO: handle interrupt here
        :
    }
    // WORKAROUND for bug described above.
    DeleteRtThread(NULL_RTHANDLE);

    // now delete the interrupt thread
    if (!ResetRtInterruptHandler(level)) {
        printf("Failed to ResetRtInterruptHandler: %04x\n", GetLastRtError());
    }
    :
}

The next snippet shows how to signal the interrupt thread from another thread to cause it to delete itself cleanly.

    kill_thread = 1;
    SignalRtInterruptThread(level);

Return Values

TRUE
Success
FALSE
To determine the status, call GetLastRtError

Status

E_OK 0x0000
No exceptional conditions occurred.
E_CONTEXT 0x0005
The specified level has no interrupt handler assigned.
E_PARAM 0x8004
wLevel contains an invalid value.

Requirements

Versions Defined in Include Link to
INtime 3.0 intime/rt/includertbase.h rt.h rt.lib
See Also