Introduction to Nucleus PLUS (RTOS)
指導教授 陳文賢 老師 Chun-Chi Jim Liu 劉俊吉 jjliu@cs.nchu.edu.tw
2009/1/23
1
Outline
Nucleus PLUS Kernel
Nucleus PLUS Service Calls Task Control Transferring data between tasks Inter-task Synchronization Memory Management LISR and HISR
Multitask Debugging on TRACE32 A sample C program
2009/1/23
2
What is Nucleus PLUS?
Nucleus PLUS is a real-time, preemptive, multitasking kernel designed for time-critical embedded applications. Accelerated Technology’s product Nucleus PLUS is 95% ANSI C and 5% assembly language. The assembly language portion is divided into three target dependent modules: initialization, thread management, and timer management.
2009/1/23
3
Portability
This is possible since it is written primarily in ANSI C. So, porting Nucleus PLUS to new processor families is straightforward and reliable. To port Nucleus PLUS we need only modify the system initialization, task management, and timer control modules.
2009/1/23
4
Nucleus PLUS Service Calls (1)
Task Control Services
NU_Create_Task() NU_Suspend_Task() NU_Change_Time_Slice() NU_Sleep() NU_Current_Task_Pointer() NU_Task_Information() NU_Delete_Task() NU_Resume_Task() NU_Terminate_Task() NU_Reset_Task() NU_Change_Priority() NU_Change_Preemption() NU_Relinquish() NU_Check_Stack() NU_Established_Tasks() NU_Task_Pointers()
Task Communication Services
NU_Create_Mailbox() NU_Broadcast_To_Mailbox() NU_Mailbox_Pointers() NU_Delete_Queue() NU_Broadcast_To_Queue() NU_Established_Queues() NU_Create_Pipe() NU_Send_To_Front_Of_Pipe() NU_Reset_Pipe() NU_Pipe_Information()
2009/1/23
NU_Delete_Mailbox() NU_Send_To_Mailbox() NU_Receive_From_Mailbox() NU_Established_Mailboxes() NU_Mailbox_Information() NU_Create_Queue() NU_Send_To_Queue() NU_Send_To_Front_Of_Queue() NU_Receive_From_Queue() NU_Reset_Queue() NU_Queue_Pointers() NU_Queue_Information() NU_Delete_Pipe() NU_Send_To_Pipe() NU_Broadcast_To_Pipe() NU_Receive_From_Pipe() NU_Established_Pipes() NU_Pipe_Pointers()
5
Nucleus PLUS Service Calls (2)
Task Synchronization Services
NU_Create_Semaphore() NU_Delete_Semaphore() NU_Release_Semaphore() NU_Established_Semaphores() NU_Semaphore_Information() NU_Create_Event_Group() NU_Set_Events() NU_Retrieve_Events() NU_Established_Event_Groups()NU_Event_Group_Pointers() NU_Event_Group_Information() NU_Register_Signal_Handler() NU_Send_Signals() NU_Receive_Signals() NU_Obtain_Semaphore() NU_Semaphore_Pointers() NU_Delete_Event_Group()
NU_Control_Signals()
Timer Services
NU_Set_Clock() NU_Delete_Timer() NU_Established_Timers() NU_Get_Remaining_Time() NU_Retrieve_Clock() NU_Control_Timer() NU_Timer_Pointers() NU_Create_Timer() NU_Reset_Timer() NU_Timer_Information()
Memory Services
NU_Create_Partition_Pool() NU_Delete_Partition_Pool() NU_Allocate_Partition() NU_Deallocate_Partition() NU_Established_Partition_Pools() NU_Deallocate_Memory() NU_Partition_Pool_Pointers() NU_Partition_Pool_Information() NU_Create_Memory_Pool() NU_Delete_Memory_Pool() NU_Allocate_Memory() NU_Memory_Pool_Pointers() NU_Established_Memory_Pools() NU_Memory_Pool_Information() 2009/1/23 6
Nucleus PLUS Service Calls (3)
Interrupt Services
NU_Control_Interrupts() NU_Register_LISR() NU_Create_HISR() NU_Delete_HISR() NU_Activate_HISR() NU_Setup_Vector() NU_Protect() NU_Unprotect() NU_Established_HISRs() NU_HISR_Pointers() NU_HISR_Information() NU_Current_HISR_Pointer()
I/O Driver Services
NU_Create_Driver()NU_Delete_Driver() NU_Request_Driver() NU_Suspend_Driver() NU_Resume_Driver() NU_Established_Drivers() NU_Driver_Pointers()
Development Services
NU_Release_Information() NU_Enable_History_Saving() NU_Retrieve_History_Entry() NU_License_Information() NU_Disable_History_Saving() NU_Make_History_Entry()
2009/1/23
7
Timeout Parameter
Incorporated into every service call that could conditionally result in a suspension (e.g., placing an item onto a queue that is full) a timeout parameter is always specified. This value can be either suspend forever (until the requested service is available), return immediately (if the service is not available an error is returned), or suspend for some period of time.
2009/1/23
8
Task States
Executing: Task is currently running. Ready: Task is ready, but another task is currently running. Suspended: Task is dormant while waiting for the completion of a service request. When the request is complete, the task is moved to the ready state. Terminated: Task was killed. Once in this state, the task cannot execute again until it is reset. Finished: Task finished it.s processing and returned from initial entry routine. Once in this 2009/1/23 9
Task Control
Preemption
Preemption is the act of suspending a lower priority task when a higher priority task becomes ready. A task is created with preemption either enabled or disabled. Preemption may also be enabled and disabled during task execution.
Relinquish
A mechanism is provided to share the processor with other ready tasks at the same priority level in a roundrobin fashion. Time Slicing
Time slicing
2009/1/23 10
Idle Task
Whenever there are no tasks ready, the idle task will run. Nucleus PLUS idles in the scheduler. The scheduling loop itself is only a few instructions written in assembly language. Since only a minimal number of registers are used, only a minimal number must be saved in order to respond to an interrupt. This means that the idle state is extremely efficient and allows the system to respond to external events in the fastest manner possible.
2009/1/23 11
Transferring data between tasks
Pipes are byte-oriented Queues are 32-bit word oriented The messages can be sent and received in sizes greater than or less than the specified units per item as long as the total message size does not exceed the total size of the pipe or queue. The third mechanism for transferring data is a mailbox, which is a single entry, four 32-bit word item.
2009/1/23
12
Inter-task Synchronization
Counting Semaphores are used to protect system resources. Counting Semaphores provide for a range of devices to be used. Event Groups are 32-bit flags that can be set and retrieved. A task can wait for or set an event with any combination of the 32-bits logically AND’d or OR’d. Signals are a mechanism for a thread to execute outside of its normal processing. These are generally used for exceptional situations.
2009/1/23 13
Memory Management
Memory Pools are similar to the familiar malloc and free service calls provided in the standard ANSI C Library. The Nucleus PLUS Memory Pool manager allows you to allocate multiple pools from which to allocate memory. Fixed Partition Memory Management in Nucleus PLUS is not as flexible as the Memory Pool Manager, but it is deterministic. To use the Fixed Partition Memory Manager, you create a partition by defining the number of fixed block sizes it will contain.
2009/1/23 14
LISR
Low-Level Interrupt Service Routines LISR threads have limited access to Nucleus PLUS services; the most important is the activateHISR service. The following services are available from LISRs:
NU_Activate_HISR NU_Local_Control_Interrupts NU_Current_HISR_Pointer NU_Current_Task_Pointer NU_License_Information NU_Retrieve_Clock
2009/1/23 15
HISR
High-Level Interrupt Service Routines HISR threads are scheduled in a manner similar to task threads, and also may call most of the Nucleus PLUS services. HISR threads are not allowed to make any self-suspension requests. The entry point of an HISR routine is determined during HISR creation.
2009/1/23
16
LISR vs HISR
When an interrupt occurs, a Low-level Interrupt Service Routine (LISR) is executed. If a kernel service is required as a result of the interrupt, the LISR schedules a High-level Interrupt Service Routine (HISR) which will execute as a “super thread” once the LISR exits and the scheduler is resumed. The HISR will execute at a higher priority than any other task in the system. It is prevented from being delayed by the use of the service’s protection mechanism.
2009/1/23 17
The Software Watchdog Timer
The SIU provides the software watchdog timer (SWT) option that prevents system lockup when software gets trapped in loops without a controlled exit. The software watchdog timer requires a special service sequence to be executed periodically; otherwise, the watchdog timer times out and issues a reset. 2009/1/23 18
Multitask Debugging on TRACE32
2009/1/23
19
DEBUG+
Nucleus PLUS provides a kernel debugger called DBUG+, which runs on the target. TRACE32 provides an interface to this debugger. You can control the debugger and view it's outputs inside the TRACE32 surface.
2009/1/23
20
Real time, non-intrusive display of Nucleus PLUS system resources
The system resources tasks, mailboxes, queues, pipes, semaphores, events, timers, partitions and dynamic memory usage can be displayed. By using the emulators dual-port memory, the display of all these regions can be viewed non-intrusively in real time.
2009/1/23
21
2009/1/23
22
Statistic evaluation and graphic display of task states
2009/1/23
23
Nucleus PLUS related pull-down menu
2009/1/23
24
Debugging Interface
2009/1/23
25
A sample C program
Reference: http://www.acceleratedtechnology.com/
2009/1/23
26