Professional Documents
Culture Documents
CONCURRENT SOFTWARE
Wait for
Interrupts
IRET IRET IRET
void Send_Request_For_Data(void)
{
outportb(CMD_PORT, RQST_DATA_CMD) ;
byte_counter = 0 ;
}
STI
Input Data
ISR with Long
Execution Time
Process Data
Output Device
Ready?
Yes
Output Data
Send EOI
Command to
PIC
STI Initialize
Input Data
Data
Enqueued
Removing
?
Yes the Waiting
Loop from
Process Output
Data Device
Ready?
the ISR
Yes
Enqueue FIFO Dequeue
Data Queue Data
IRET
Copyright © 2000, Daniel W. Lewis. All Rights Reserved.
Input Output
Ready Ready
STI STI
Input Data
Interrupt-
Process
Data
Data Enqueued?
Driven
Output
Yes
Enqueue FIFO Dequeue
Data Queue Data
Output Data
IRET IRET
SendData Output
Input Data Subroutine Ready
Yes
Enqueue Data FIFO Dequeue Data
Queue Clear Busy
Flag
Output No! Output Data
Device
Busy?
CALL SendData
CALL SendData
(Kick Start) Set Busy Flag
Send EOI
Send EOI RET Command to
Command to PIC
PIC
Disable future
Set the mask bit for this interrupts from
device in the 8259 PIC this device.
CS:EIP CS:EIP
SS:ESP SS:ESP
EAX EAX
EBX EBX
EFlags EFlags
Executing Suspended
Suspended Executing
Yes
Wait? Yield to other
threads
Data
Processing
IRET
Thread B
Thread A Executing
Suspended
Copyright © 2000, Daniel W. Lewis. All Rights Reserved.
Critical Sections
• Critical section: A code sequence whose proper
execution is based on the assumption that it has
exclusive access to the shared resources that it
is using during the execution of the sequence.
• Protection Options:
– Disabling interrupts
– Spin lock
– mutex
– semaphore
do {
Flag disable() ; L1: MOV AL,1
set? ok = !flag ; XCHG [_flag],AL
flag = TRUE ; OR AL,AL
No enable() ; JNZ L1
} while (!ok) ;
Set Flag
Critical Spin-lock in
Spin-lock in C.
Section assembly.
Semaphore “Post”
C/OS-II:
OSInit() ;
OSStart() ;
C/OS-II:
BYTE8 OSTaskCreate(void (*fn)(void *), void *data,
void *stk, BYTE8 prio) ;
BYTE8 OSTaskDel(BYTE8 prio) ;
C/OS-II:
void OSSchedLock(void) ;
void OSSchedUnlock(void) ;
BYTE8 OSTimeTick(BYTE8 old, BYTE8 new) ;
void OSTimeDly(WORD16) ;]
C/OS-II:
BYTE8 OSTaskChangePrio(BYTE8 old, BYTE8 new) ;
C/OS-II:
OS_ENTER_CRITICAL() ;
OS_EXIT_CRITICAL() ;
void OSIntEnter(void) ;
void OSIntExit(void) ;
C/OS-II:
OS_EVENT *OSSemCreate(WORD16) ;
void OSSemPend(OS_EVENT *, WORD16, BYTE8 *) ;
BYTE8 OSSemPost(OS_EVENT *) ;
Copyright © 2000, Daniel W. Lewis. All Rights Reserved.
Mailbox Services
Multi-C:
n/a
C/OS-II:
OS_EVENT *OSMboxCreate(void *msg) ;
void *OSMboxPend(OS_EVENT *, WORD16, BYTE8 *) ;
BYTE8 OSMboxPost(OS_EVENT *, void *) ;
C/OS-II:
OS_EVENT *OSQCreate(void **start, BYTE8 size) ;
void *OSQPend(OS_EVENT *, WORD16, BYTE8 *) ;
BYTE8 OSQPost(OS_EVENT *, void *) ;
C/OS-II:
DWORD32 OSTimeGet(void) ;
void OSTimeSet(DWORD32) ;