Interrupt Scheduling
by John Pote

Example 1: 

SchedListElem   .struct
reqCnt  .byte   ;request count bits 1-7, RUNNING flag bit 0
indxNxt .byte   ;offset to next list member
funcPt  .word   ;address of interrupt handler
    .endstruct


Example 2: 
scheduler:  set pointer to point to first member in list
    while RUNNING flag not set {
        do {    set RUNNING flag
            if request count > 0 {
                call function
                decrement request count
            }
            clear RUNNING flag
        } while request count > 0
        point to next member in list
    }
    return from interrupt


Listing One    
RUNNING     .equ    1       ;RUNNING flag bit mask
REQCOUNT    .equ    2       ;request count inc/dec value
REQCNTBITS  .equ    0feh    ;i.e. not the running bit

;rListPtr, rRunning, rReqCntBits are 
;      macro names for general-purpose registers.
scheduler:
    mov.w   &schedListFirst, rListPtr   ;point to list head
    ; the next 2 are useful constants to have in registers
    mov.w   #RUNNING, rRunning
    mov.w   #REQCNTBITS, rReqCntBits
    ;is current function already running?
    bit.b   @rListPtr, rRunning
    jnz    schedEnd

doElem: bis.b   rRunning, SchedListElem.reqCnt(rListPtr)    
                                                ;mark this func running
    bit.b   @rListPtr, rReqCntBits              ;req cnt > 0?
    jz      zCount
    ;call the func
    call    SchedListElem.funcPt(rListPtr)
    sub.b   #REQCOUNT, SchedListElem.reqCnt(rListPtr)  ;dec req count
zCount:
    bic.b   rRunning, SchedListElem.reqCnt(rListPtr)   ;clr this func running
    bit.b   @rListPtr, rReqCntBits                     ;req cnt > 0?
    jnz     doElem
    ;req count is 0, do next func
    mov.b   SchedListElem.indxNxt(rListPtr), rTemp
    add     rTemp, rListPtr                     ;->next element in list

    ;repeat first instrs here for speed
    ;is new function already running?
    bit.b   @rListPtr, rRunning
    jz      doElem
schedEnd:
    popSchedRegs    ;macro to restore scheduler registers
    reti            ;terminate scheduler and interrupt





1

