Tải bản đầy đủ (.pdf) (71 trang)

Getting Started with Micriμm’s μC_OS-III Kernel

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (621.56 KB, 71 trang )

Renesas Electronics America Inc.
© 2012 Renesas Electronics America Inc. All rights reserved.
Getting Started with Micriμm’s
μC/OS-III Kernel
© 2012 Renesas Electronics America Inc. All rights reserved.2
Renesas Technology & Solution Portfolio
Company Logo
HERE
© 2012 Renesas Electronics America Inc. All rights reserved.3
Agenda
 Introduction
 Lab 1
 Foreground/Background Systems
 Kernel-Based Applications
 Initiating Multitasking
 Lab 2
 Scheduling and Context Switches
 Lab 3
 Additional Kernel Services
 Lab 4

Conclusion
3
© 2012 Renesas Electronics America Inc. All rights reserved.4
Introduction
4
© 2012 Renesas Electronics America Inc. All rights reserved.5
Class Objectives
 Understand what services a real-time kernel provides
 Learn how to make use of kernel services
 Learn how kernels are implemented


 Gain experience with an actual kernel
5
© 2012 Renesas Electronics America Inc. All rights reserved.6
Labs
 Based on µC/OS-III
 Real-time kernel from Micriµm
 Concepts underlying the labs are not µC/OS-III-specific
 Step-by-step instructions are provided for each lab
6
© 2012 Renesas Electronics America Inc. All rights reserved.7
A µC/OS-III-Based Application
7
Application Code
Micriµm’s Modules
(Portable Code)
Micriµm’s Modules
(Hardware-Specific Code)
Hardware
© 2012 Renesas Electronics America Inc. All rights reserved.8
µC/LIBµC/CPUµC/OS-III
A µC/OS-III-Based Application (Cont.)
8
Application Code
µC/CPUµC/OS-III BSP
Hardware
© 2012 Renesas Electronics America Inc. All rights reserved.9
Directory Structure
9
Workspace files
© 2012 Renesas Electronics America Inc. All rights reserved.10

e
2
Studio
 IDE supporting Renesas MCUs
 Based on Eclipse
 A variety of debugging features
10
© 2012 Renesas Electronics America Inc. All rights reserved.11
Lab 1
11
© 2012 Renesas Electronics America Inc. All rights reserved.12
Lab 1 Summary
 The kernel is built alongside application code
 A kernel-based application looks much like any other C
program
 Application code interacts with the kernel through API
functions
12
© 2012 Renesas Electronics America Inc. All rights reserved.13
Foreground/Background
Systems
13
© 2012 Renesas Electronics America Inc. All rights reserved.14
A Foreground/Background Example
int main (void)
{
Perform initializations;
while (1) {
ADC_Read();
SPI_Read();

USB_Packet();
LCD_Update();
Audio_Decode();
File_Write();
}
}
void USB_ISR (void)
{
Clear interrupt;
Read packet;
}
14
Background Foreground
© 2012 Renesas Electronics America Inc. All rights reserved.15
Foreground/Background Benefits
 No upfront cost
 Minimal training required
 Developers don’t need to learn a kernel’s API
 No need to set aside memory resources to accommodate a
kernel
 There is a small amount of overhead associated with a kernel
15
© 2012 Renesas Electronics America Inc. All rights reserved.16
Foreground/Background Drawbacks
 Difficult to ensure that each operation will meet its deadline
 All code in the background essentially has the same importance,
or priority
16
while (1) {
ADC_Read();

SPI_Read();
USB_Packet();
Service other devices;
}
void ADC_Read (void) {
Initialize ADC;
while (conv_rdy == 0) {
;
}
Process converted value;
}
Potential to delay entire
application
© 2012 Renesas Electronics America Inc. All rights reserved.17
Foreground/Background Drawbacks
(Cont.)
 High-priority code must be placed in the foreground (in an
ISR)
 Lengthy ISRs can negatively impact system responsiveness
17
while (1) {
ADC_Read();
SPI_Read();
USB_Packet();
LCD_Update();
Audio_Decode();
File_Write();
}
void USB_ISR (void) {
Clear interrupt;

Read packet;
}
If a USB packet is received
immediately after this function
returns, the response time will be
lengthy.
© 2012 Renesas Electronics America Inc. All rights reserved.18
Foreground/Background Drawbacks
(Cont.)
 Problems with multiple developers
 Developers’ efforts must be closely coordinated
 Difficult expansion, even with one developer
 Changes to one portion of the application may negatively
impact the remainder of the code
18
© 2012 Renesas Electronics America Inc. All rights reserved.19
Kernel-Based Applications
19
© 2012 Renesas Electronics America Inc. All rights reserved.20
A Kernel-Based Example
void AppTaskADC (void *p_arg)
{
while (1) {
ADC_Read();
Sleep for 1 ms;
}
}
void AppTaskUSB (void *p_arg)
{
while (1) {

Wait for signal from ISR;
USB_Packet();
}
}
void AppISRUSB (void)
{
Clear interrupt;
Signal USB Task;
}
20
Tasks ISRs
© 2012 Renesas Electronics America Inc. All rights reserved.21
Kernel Basics
 Application is divided into tasks
 Kernel shares CPU amongst tasks

Developer may assign importance, or priority, to each task
21
© 2012 Renesas Electronics America Inc. All rights reserved.22
Template Task
22
static void AppTaskExample (void *p_arg)
{
Perform initializations;
while (1) {
Work toward task’s goals;
}
}
© 2012 Renesas Electronics America Inc. All rights reserved.23
Initiating Multitasking

23
© 2012 Renesas Electronics America Inc. All rights reserved.24
Initializing and Starting the Kernel
 Application code must initialize the kernel
 µC/OS-III is typically initialized in main()
 Initialization accomplished through kernel API functions
24
© 2012 Renesas Electronics America Inc. All rights reserved.25
OSInit()
 Must be invoked before any kernel services are used
 Initializes data structures
 Creates internal tasks
 Number of tasks depends on configuration
25

×