?? chap5.asm
字號(hào):
; Chapter 5 6811 assembly language programs; Jonathan W. Valvano; This software accompanies the book,; Real Time Embedded Systems published by Brooks Cole;; Program 5.1. Assembly code that statically allocates three threads.TCB1 fdb TCB2 fdb IS1 fcb 1 rmb 49 IS1 rmb 1 fcb $40 fdb 0,0,0 fdb ProgATCB2 fdb TCB3 fdb IS2 fcb 2 rmb 49 IS2 rmb 1 fcb $40 fdb 0,0,0 fdb ProgATCB3 fdb TCB1 link fdb IS3 SP fcb 4 Id rmb 49 IS3 rmb 1 fcb $40 CCR fdb 0,0,0 DXY fdb ProgB PC; Program 5.2. Assembly code that implements the preemptive thread switcher.Next equ 0 pointer to next TCBSP equ 2 Stack pointer for this threadId equ 4 Used to visualize which thread is current runningRunPt rmb 2 pointer to thread that is currently runningMain ldaa #$FF staa DDRC PortC displays which program is executing ldx #TCB1 First thread to run jmp Start* Suspend thread which is currently runningOC5Han ldx RunPt sts SP,x save Stack Pointer in TCB* launch next thread ldx Next,xStart stx RunPt ldaa Id,x staa PORTB visualizes running thread lds SP,x set SP for this new thread ldd TOC5 addd #20000 interrupts every 10 ms std TOC5 ldaa #$08 ($20 on the 6812) staa TFLG1 acknowledge OC5 rti; Program 5.3. Assembly code for the two main programs and shared subroutine.ProgA pshx tsx ldd #5 std 0,xLoopA ldaa #2 staa PORTC ldd 0,x jsr sub std 0,x bra LoopAProgB pshx tsx ldd #5 std 0,xLoopB ldaa #4 staa PORTC ldd 0,x jsr sub std 0,x bra LoopBSub pshx tsx std 0,x ldaa #1 staa PORTC ldd 0,x addd #1 pulx rts; Program 5.8. 6811/6812 assembly code for a spinlock counting semaphore.S fcb 1 semaphore counter initialized to 1wait sei make read-modify-write atomic ldaa S current value of semaphore bhi OK available if >0 cli bra wait **interrupts can occur here**OK deca staa S S=S-1 cli rtssignal inc S S=S+1, this is atomic rts ; Program 5.12. Assembly code to initialize a blocking semaphore.S rmb 1 semaphore counterBlockPt rmb 2 Pointer to threads blocked on SInit tpa psha Save old value of I sei Make atomic ldaa #1 staa S Init semaphore value ldx #Null stx BlockPt empty list pula tap Restore old value of I rts; Program 5.13. Assembly code helper function to block a thread, used to implement a blocking semaphore.* To block a thread on semaphore S, execute SWISWIhan ldx RunPt running process "to be blocked" sts SP,x save Stack Pointer in its TCB* Unlink "to be blocked" thread from RunPt list ldy Next,x find previous thread sty RunPt next one to runlook cpx Next,y search to find previous beq found ldy Next,y bra lookfound ldd RunPt one after blocked std Next,y link previous to next to run* Put "to be blocked" thread on block list ldy BlockPt sty Next,x link "to be blocked" stx BlockPt* Launch next thread ldx RunPt lds SP,x set SP for this new thread ldd TCNT Next thread gets a full 10ms time slice addd #20000 interrupt after 10 ms std TOC5 ldaa #$08 ($20 on the 6812) staa TFLG1 clear OC5F rti
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -