610 likes | 615 Views
Learn about Real-Time Operating Systems (RTOS) and components like uCOS-II, including source code review, total solutions, and application code review. Get insights into developing environments and OS concepts like resource and process management. Understand embedded OS and characteristics of a Good Embedded OS. Discover what Real-Time means and the differences between hard and soft real-time. Dive into RTOS tasks, scheduling, multi-tasking, and inter-thread communication and synchronization mechanisms.
E N D
Agenda RTOS introduction uCOS-II components and architecture uCOS-II Source code review uCOS-II total solutions uC/GUI, uC/FS, uC/USB, uCTCP/IP etc. A complete uCOS-II application code review Developing environment Q & A
Operating System Overview Operating systems are programs Every portion in system must be controlled and coordinated The operating system acts as an intermediary between the software applications and the hardware they run on Designed to control the operation of a computer system Resource management Devices Memory Process management
Embedded OS An “embedded system” is any computer system or computing device that performs a dedicated function or is designed for use with a specific embedded software application. Embedded systems may use a ROM/Flash-based operating system or they may use a Disk-based system, like a PC. But an embedded system is not usable as a commercially viable substitute for general purpose computers or devices.
Good Embedded OS ? • CPU core family support • Configurable • Modular • Scalable • Small footprint • Device drivers • Performance • Processor isolation • Refernce information, etc……
What is Real Time ? “ A real time system is one in which the correctness of the computations not only depends upon the logical correctness of the computation but also upon the time at which the result is produced. If the timing constraints of the system are not met, system failure is said to have occurred.” -Donald Gillies
What is Real Time ? “ Real time in operating systems : The ability of the operating system to provide a required level of service in a bounded response time. ” -POSIX Standard 1003.1
Hard vs. Soft Real Time Hard guaranteed worst-case reponse times absolutely, positively, first time every time Soft
Good RTOS ? Multi- Task Preemptive Priority Synchronization mechanisms High Reaponsiveness
Single-Task Operating System Single Task Complete process in one task A single execution pointer Single menory space /* Main control*/ Main() { system _initail ….. do _something(); …. } /*Process*/ Void do_something() { …….. } System Initial
Multi-Task Operating System /*Process*/ Void task_1( ) { ….. } Task 1 Multi tasks competing Multi execution pointers Multi memory spaces /*Process*/ Void task_2( ) { ….. } System Initial Task 2 /*Process*/ Void task_3( ) { ….. } Task 3
The Scheduler What Scheduler do ? Schedule tasks Move / Remove task into / from CPU Task 1 Task 2 Task 3
The Scheduler , cont. The way is : Time-slicing Dividing CUP computing cycles between multiple tasks. Giving each task a certain amount of process cycles, then halting that task to make the next task active. Priority The service level of process High service-level gain more CPU computing cycle
The Scheduler , cont. The way is : Preemptive To control which processes are allowed access to the CPU and for how long. Once the time slice of current process expires, the current process is halted and the next process is given its computing time.
The Scheduler , cont. Task-1 0 Task-2 0 Task-3 0 Task-4 0 Task List (0) Highest Priority Task-1 31 Task-2 31 Task List (15) Task List (31) Task-1 31 Task-231 Task-3 31 Lowest Priority
Register 5 Register 5 Register 1 Register 1 Register 6 Register 6 Register 2 Register 2 CPU CPU Register 7 Register 7 Register 3 Register 3 Register 8 Register 8 Register 4 Register 4 Register 1 Register 2 Register 3 Register 4 Register 5 Register 6 Register 7 Register 8 Context Switch Stakc n Stack 1 Stack 2
Inter-Thread Communication Transfer Data/Message to one or more Thread Mailbox Message Queues Share-Memory
Inter-Thread Communication, cont. Mail-Box Fix-length message Transfer one message to one or more threads (Tasks) Thread 2 Thread 1 One Message Thread 3
Inter-Thread Communication, cont. Thread 2 Message Queues Fixed or Variable length messages Transfer large number of messages to one or more Threads (Tasks) Thread 1 Thread 3 Message Queues
Inter-Thread Synchronization Thread synchronization control To control ther access of threads to certain application areas critical sections application resources Resource access control Share-memory Devices Inter-Thread Synchronization : Counting Semaphore Event Flags Mutex
Inter-Thread Synchronization, cont. Task 1 Task 2 Critical Sections More than one task are modifying the same area of memory / data section Or access / control the same device memory Varible X,Y,Z
Inter-Thread Synchronization, cont. Counting Semaphores To control access Critical section Device resources Task 1 Semaphore 1 Device 1 Semaphore 2 Device 2 Task 2 Task 2 must wait Until “Device 1” are released.
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 Inter-Thread Synchronization, cont. Task 1 Device 1 Task 1 Event Flags 0 0 0 1 1 1 Task 3 + ( And ) = Fase
Memory Management Fixed-Size Allocation Allocate the fixed-size block from deterministic memory space Dynamic-Size Allocation Allocate varible sized memory block
50 bytes 50 bytes 50 bytes 50 bytes 50 bytes 50 bytes Memory Management, cont. Memory Task 1 Fixed-Size block Allocation Task 2
Memory Management, cont. Memory Task 1 50 bytes Dynamic-Size block Allocation 50 bytes Task 2
uCOS-II Features Real-Time & Multithreading kernel Not a black box Complete source code ANSI C & Processor assembly language Advanced Technology Hing Performance
Thread Management Functions : Thread create / delete Thread resume / Suspend / termination
Thread Management, cont. Thread priorities (0 to 63) No two tasks with the same priority. Thread scheduling Priority No TimeSlice( will be available later)
Message Queue Management Functions Create / Delete a message queue Send / Receive a message Send a message to the front of queue Retrieve information Prioritize queue suspension list Flush message queue Task 2 Task 1 Task 3 Message Queues
Message Queue Management, cont Primary form of inter-thread communication One or more messages can reside in a message queue Message sizes 1, 2, 4, 8, and 16 32-bit words. Message > 16 words Passed by pointer Using 1 word size to carry a pointer via Message Queue Mailbox A message queue holds a single message
Semaphore Management Functions Create / Delete a Semaphore Get / Put a Semaphore Retrieve information about a semaphore Prioritize semaphore suspension list Task 1 Semaphore 1 Device 1 Semaphore 2 Device 2 Task 2
Semaphore Management, cont. 32-bit counting semahpores (0~4, 294, 967, 295) Mutual exclusion Control the access in certain application areas (critical sections or application resources) Event Notification (producer-consumer) Pitfall Deadly Embrace Priority Inversion
Semaphore Management, cont. First Semaphore Second Semaphore Deadlock Deadly Embrace Owned by Thread 1 Owned by Thread 2 Thread 1 Thread 2 Attempt to Get second semaphore Attempt to Get first semaphore
Semaphore Management, cont. Wait for release Semaphore Attempt to get semaphore Owned by Thread 1 Priority Inversion Thread 2 Thread 1 High Priority Low Priority
Mutexes Management As a binary semaphore Functions Create / Delete a mutual exclusion mutex Obtain / Release ownership of a mutex Prioritize mutex suspension list Retrieve information about a mutex
Porting uC/OS-II • Os_CPU_a.s (Porting的重點,Assembly Code) • Os_CPU_c.c (包含和CPU結構相關的任務堆疊初始化函数,以及用户可以利用的一系列子函数,可以處理特殊硬體擴展、MMU、DEBUG等之用) • Os_CPU.h (需要根據CPU的指令字長和硬體更改的header file)
Writing Applications Under µC/OS-II • Tasks running under a multitasking kernel should be written in one of two ways: • A non-returning forever loop. For example: void Task (void *) { DoInitStuff(); while (1) { do this; do that; do the other thing; call OS service (); // e.g. OSTimeDelay, OSSemPend, etc. } }
Writing Applications Under µC/OS-II • A task that deletes itself after running. For example: void Task (void *) { do this; do that; do the other thing; call OS service (); // e.g. OSTimeDelay, OSSemPend, etc. OSTaskDelete(); // Ask the OS to delete the task }
Total solution of uC/OS-II • GUI ---uC/GUI ; PEGX • File system ----uC/FS; FILEX • TCP/IP stack ---- NETX;Interniche;uc/stack
uC/GUI • 100% ANSI-C code • Pctools : • Simulation environment • Bitmap converter • Font converter
µCGUI (Contd..) • Memory Devices: Frame buffer, the image of the windows etc are drawn on this buffer and when the drawing is completed, this is copied to the touch screen. This helps in preventing the flickering of the screen. • Window Manager: It manages the windows that are created in the GUI. It handles all the mouse and keyboard events (touch screen in this case). • Touch Screen: Touch Screen drivers • LCD Drivers • Anti-aliasing: This smoothens the fonts and other graphical entities. It gives a pleasant affect to the eye instead of the rugged look.
µCGUI (contd..) • Widgets and Dialogs: A library to create the widgets (buttons, textboxes, etc) and dialog boxes. Reduces lot of effort to build everything using pixels and lines • Font Converter: It converts a general font format (ttf, utf, etc) to the µCGUI compatible fonts • Bitmap Converter: It converts the 32-bit bitmap images to the compatible bitmap image that is used on µCGUI • µCGUI supports all the processors from 8-bit to 16-bit
uC/FS • µC/FS is a FAT file system which can be used on any media • Basic hardware access functions has to be provided • MS-DOS/MS-Windows compatible FAT12 and FAT16 support • Multiple device driver support allows to access different types of hardware with the file system at the same time • Multiple media support. A device driver allows you to access different medias at the same time • OS support: µC/FS can easily be integrated into any OS
µC/FS Device Drivers • µC/FS has been designed to cooperate with any kind of hardware. To use a specific hardware with µC/FS, a device driver for that hardware is required. • The device driver consists of basic I/O functions for accessing the hardware and a global table, which holds pointers to these functions. Available drivers are: RAM disk SMC (Smart Card) MMC (Multimedia Card) SD (Secure Digital) CF (Compact Flash) Windows (used by the Visual C++ demonstration and simulation code) IDE Hard Disk