jiC/OS - GBV

Preview:

Citation preview

jiC/OS

The Real-Time Kernel

Jean J. Labrosse

R & D Publications Lawrence, Kansas 66046

Table of Contents

Preface

List of Figures

Table of Code Listings

Introduction

Chapter 1

Real-Time Kernel Concepts Critical Section of Code . . 7

Resource 7

Shared Resource 7

Multitasking 7

Task 7

Context Switch or Task Switch 8

Kernel 8

Scheduler 8 Non-Preemptive Kernel 8

Preemptive Kernel . • . 10

Preemptive vs Non-Preemptive 10

Reentrancy 11

Round Robin Scheduling 12

TaskPriority 12 Static Priorities 12

Dynamic Priorities 12 Priority Inversions 14

Semaphores 14 Mutual Exclusion 15 Deadlock (or Deadly Embrace) 19 Synchronization 21 Event Flags . . 23 Intertask Communication 23 Message Mailboxes 26 Message Queues 27 Interrupts 29

Interrupt Latency, Response and Recovery . . 29

ISR Processing Time 30

Non-Maskable Interrupts (NMIs) . . . . 30

ClockTick 34

Performance 35

Chapter 2

Kernel Structure Critical Sections 39 Tasks 40 Task States 40 Task Control Blocks . . . . . . 42 Creating a Task 44 Deleting a Task 48

Task Scheduling 50

LOCK/UNLOCK 56

Changing a Task's Priority 57

Delaying a Task 58

Chapter 3

Interrupt Processing 61 Interrupt Latency, Response and Recovery 64

ClockTick 65

Chapter 4

Communication, Synchronization & Coordination 71 Event Control Blocks 71

SEMAPHORES 74 MAILBOXES 78

QUEUES 81

Chapter 5

Initialization & Configuration 87 Initialization 87

Configuration 88

Chapter 6

Reference Manual and Timing Reference 93 Introduction 93

vii

Memory Usage 95 Program Memory . . . . 95

Data Memory 95

Kernel Services 97 OSInit() 98

OSIntEnter() 99

OSIntExit() 100

OSMboxCreate() 101

OSMboxPend() . . . . . . . . .102

OSMboxPost() . . . 104

OSQCreate() 106

OSQPend() 108

OSQPost() 110

OSSchedLock() . . . . . . . . .112

OSSchedUnlock() . .114

OSSemCreate() . . . . . . . . ' ' . 1 1 6

OSSemPend() . . .118

OSSemPost() . . . . . . . . . .120

OSStart() 122

OSTaskChangePrio() 124

OSTaskCreate() 126

OSTaskDel() 128

OSTimeDly() . . . . .130

OSTimeGet() 132

OSTimeSet() 133

OSTimeTick() 134

MACROs 136 OS_ENTER_CRITICAL() 136

OS_EXIT_CRITICAL() .136

viii

#DEFINEs 137 OS_MAX_TASKS 137

OS_MAX_EVENTS . . . . . . . 1 3 7

OS_MAX_QS 137

OS_IDLE_TASK_STK_SIZE 137

uCOS 137

Execution Time Summary 138

Chapter 7

Examples 145 Example #1 145

Example#2 152

Appendix A

uC/OS Microprocessor Independent Source Code 163

Appendix B

80186/80188 Microprocessor Specific Source Code 185

Appendix C

Software Development Conventions 189 Directory Structure 189

C Programming Style 190 Overview .';•''. 190

Header 191

Revision History 192

ix

Include Files 192

Naming Identifiers 192

Acronyms, Abbreviations & Mnemonics . . .194

Comments 197

#DEFINES •. . 198

DataTypes 198

Local Variables 199

Function Prototypes 199

Function Declarations . . . . . . . . 199

Indentation 201

Statements & Expressions 203

Structures and Unions 204

Reserved Keywords 205

Appendix D

LISTC & HPLISTC 207

Appendix E

TO 223

Appendix F

Real-Time Kernel Manufacturers 233 Buying a Kernel 233

Writing Your Own Kernel 234

Real-time Kernel Survey 234

X

Appendix G Bibliography 251

Appendix H

Companion Disk 255 Licensing . . 255

Hardware/Software Requirements . . . . . . . . . 256 Installation . 256

Directory Structure . 257

Index 259

xi