- Freescale Semiconductor

advertisement

Rapid Prototyping Solutions

Module 2: Introduction to Real-Time

Operating Systems

Freescale, the Freescale logo, AltiVec, C-5, CodeTest, CodeWarrior, ColdFire, C-Ware, mobileGT, PowerQUICC, StarCore, and Symphony are trademarks of Freescale Semiconductor, Inc.,

Reg. U.S. Pat. & Tm. Off. BeeKit, BeeStack, CoreNet, the Energy Efficient Solutions Logo, Flexis, MXC, Platform in a Package, Processor Expert, QorIQ, QUICC Engine, SmartMOS, TurboLink and VortiQa are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respect ive owners. © Freescale Semiconductor, Inc. 2010.

TM

Module Objectives

► This session describes basic RTOS concepts using the MQX RTOS

► It will cover tasks, scheduling, semaphores and more with hands-on examples

► You’ll learn how to use a RTOS and the advantages that using one provides

Freescale, the Freescale logo, AltiVec, C-5, CodeTest, CodeWarrior, ColdFire, C-Ware, mobileGT, PowerQUICC, StarCore, and Symphony are trademarks of Freescale Semiconductor, Inc.,

Reg. U.S. Pat. & Tm. Off. BeeKit, BeeStack, CoreNet, the Energy Efficient Solutions Logo, Flexis, MXC, Platform in a Package, Processor Expert, QorIQ, QUICC Engine, SmartMOS, TurboLink and VortiQa are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respect ive owners. © Freescale Semiconductor, Inc. 2010. 2

TM

► What is an RTOS

► MQX Basics: Tasks

• Hands-on

► MQX Basics: Scheduling

• Hands-on

► MQX Basics: Task Synchronization

• Semaphores

Hands-on

► Additional Resources

► Review

Freescale, the Freescale logo, AltiVec, C-5, CodeTest, CodeWarrior, ColdFire, C-Ware, mobileGT, PowerQUICC, StarCore, and Symphony are trademarks of Freescale Semiconductor, Inc.,

Reg. U.S. Pat. & Tm. Off. BeeKit, BeeStack, CoreNet, the Energy Efficient Solutions Logo, Flexis, MXC, Platform in a Package, Processor Expert, QorIQ, QUICC Engine, SmartMOS, TurboLink and VortiQa are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respect ive owners. © Freescale Semiconductor, Inc. 2010. 3

Module Agenda

TM

► What is an RTOS?

► MQX Basics: Tasks

• Hands-on

► MQX Basics: Scheduling

• Hands-on

► MQX Basics: Task Synchronization

• Semaphores

Hands-on

► Additional Resources

► Review

Module Agenda

Freescale, the Freescale logo, AltiVec, C-5, CodeTest, CodeWarrior, ColdFire, C-Ware, mobileGT, PowerQUICC, StarCore, and Symphony are trademarks of Freescale Semiconductor, Inc.,

Reg. U.S. Pat. & Tm. Off. BeeKit, BeeStack, CoreNet, the Energy Efficient Solutions Logo, Flexis, MXC, Platform in a Package, Processor Expert, QorIQ, QUICC Engine, SmartMOS, TurboLink and VortiQa are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respect ive owners. © Freescale Semiconductor, Inc. 2010. 4

TM

► The term “ operating system ” can be used to describe the collection of software that manages a system’s hardware resources

► This software might include a file system module, a GUI and other components

► Often times, a “ kernel ” is understood to be a subset of such a collection

► Characteristics

Resource management

Interface between application and hardware

Library of functions for the application

Operating Systems

User

Application

Operating System

HARDWARE

Freescale, the Freescale logo, AltiVec, C-5, CodeTest, CodeWarrior, ColdFire, C-Ware, mobileGT, PowerQUICC, StarCore, and Symphony are trademarks of Freescale Semiconductor, Inc.,

Reg. U.S. Pat. & Tm. Off. BeeKit, BeeStack, CoreNet, the Energy Efficient Solutions Logo, Flexis, MXC, Platform in a Package, Processor Expert, QorIQ, QUICC Engine, SmartMOS, TurboLink and VortiQa are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respect ive owners. © Freescale Semiconductor, Inc. 2010. 5

TM

Embedded Operating Systems

► Fusion of the application and the OS to one unit

► Characteristics

Resource management

 Primary internal resources

Less overhead

Code of the OS and the application mostly reside in

ROM

User

Operating System + Application

HARDWARE

Freescale, the Freescale logo, AltiVec, C-5, CodeTest, CodeWarrior, ColdFire, C-Ware, mobileGT, PowerQUICC, StarCore, and Symphony are trademarks of Freescale Semiconductor, Inc.,

Reg. U.S. Pat. & Tm. Off. BeeKit, BeeStack, CoreNet, the Energy Efficient Solutions Logo, Flexis, MXC, Platform in a Package, Processor Expert, QorIQ, QUICC Engine, SmartMOS, TurboLink and VortiQa are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respect ive owners. © Freescale Semiconductor, Inc. 2010. 6

TM

Real Time Operating Systems

► A real-time operating system (RTOS) manages the time of a microprocessor or microcontroller

► Features of an RTOS:

 Allows multi-tasking

 Scheduling of the tasks with priorities

 Synchronization of the resource access

 Inter-task communication

 Time predictable

 Interrupt handling

Freescale, the Freescale logo, AltiVec, C-5, CodeTest, CodeWarrior, ColdFire, C-Ware, mobileGT, PowerQUICC, StarCore, and Symphony are trademarks of Freescale Semiconductor, Inc.,

Reg. U.S. Pat. & Tm. Off. BeeKit, BeeStack, CoreNet, the Energy Efficient Solutions Logo, Flexis, MXC, Platform in a Package, Processor Expert, QorIQ, QUICC Engine, SmartMOS, TurboLink and VortiQa are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respect ive owners. © Freescale Semiconductor, Inc. 2010. 7

TM

Why use an RTOS?

► Plan to use drivers that are available with an RTOS

► Would like to spend your time developing application code and not creating or maintaining a scheduling system

► Multi-thread support with synchronization

► Portability of application code to other CPUs

Resource handling

Add new features without affecting higher priority functions

Support for upper layer protocols such as:

TCP/IP, USB, Flash Systems, Web Servers,

 CAN protocols, Embedded GUI, SSL, SNMP

Freescale, the Freescale logo, AltiVec, C-5, CodeTest, CodeWarrior, ColdFire, C-Ware, mobileGT, PowerQUICC, StarCore, and Symphony are trademarks of Freescale Semiconductor, Inc.,

Reg. U.S. Pat. & Tm. Off. BeeKit, BeeStack, CoreNet, the Energy Efficient Solutions Logo, Flexis, MXC, Platform in a Package, Processor Expert, QorIQ, QUICC Engine, SmartMOS, TurboLink and VortiQa are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respect ive owners. © Freescale Semiconductor, Inc. 2010.

TM

► We will be using Freescale MQX to demonstrate these RTOS concepts

► Freescale MQX Software can be downloaded:

 http://www.freescale.com/mqx

► Default Freescale MQX folder:

 C:\Program Files\Freescale\Freescale MQX 3.5

Freescale MQX

Freescale, the Freescale logo, AltiVec, C-5, CodeTest, CodeWarrior, ColdFire, C-Ware, mobileGT, PowerQUICC, StarCore, and Symphony are trademarks of Freescale Semiconductor, Inc.,

Reg. U.S. Pat. & Tm. Off. BeeKit, BeeStack, CoreNet, the Energy Efficient Solutions Logo, Flexis, MXC, Platform in a Package, Processor Expert, QorIQ, QUICC Engine, SmartMOS, TurboLink and VortiQa are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respect ive owners. © Freescale Semiconductor, Inc. 2010. 9

TM

MQX Directory Structure

► Described in the MQX Release Notes

► Folders are:

 config demo doc lib mqx tools

And then the RTCS, USB, and MFS stacks

Freescale, the Freescale logo, AltiVec, C-5, CodeTest, CodeWarrior, ColdFire, C-Ware, mobileGT, PowerQUICC, StarCore, and Symphony are trademarks of Freescale Semiconductor, Inc.,

Reg. U.S. Pat. & Tm. Off. BeeKit, BeeStack, CoreNet, the Energy Efficient Solutions Logo, Flexis, MXC, Platform in a Package, Processor Expert, QorIQ, QUICC Engine, SmartMOS, TurboLink and VortiQa are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respect ive owners. © Freescale Semiconductor, Inc. 2010. 10

TM

► The “mqx” directory is heart of

MQX

► Folders are:

 build examples

 source bsp io psp

MQX API source

MQX Directory Structure (Cont.)

Freescale, the Freescale logo, AltiVec, C-5, CodeTest, CodeWarrior, ColdFire, C-Ware, mobileGT, PowerQUICC, StarCore, and Symphony are trademarks of Freescale Semiconductor, Inc.,

Reg. U.S. Pat. & Tm. Off. BeeKit, BeeStack, CoreNet, the Energy Efficient Solutions Logo, Flexis, MXC, Platform in a Package, Processor Expert, QorIQ, QUICC Engine, SmartMOS, TurboLink and VortiQa are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respect ive owners. © Freescale Semiconductor, Inc. 2010. 11

TM

Changing Configuration Options

► User configuration options are set in

<mqx_install>/config/<board>/user_config.h

► Change the default serial port to UART1:

#define BSP_DEFAULT_IO_CHANNEL "ttyb:"

#define BSP_DEFAULT_IO_CHANNEL_DEFINED

#define BSPCFG_ENABLE_TTYB 1

► Always need to re-build all the libraries with this new configuration

Freescale, the Freescale logo, AltiVec, C-5, CodeTest, CodeWarrior, ColdFire, C-Ware, mobileGT, PowerQUICC, StarCore, and Symphony are trademarks of Freescale Semiconductor, Inc.,

Reg. U.S. Pat. & Tm. Off. BeeKit, BeeStack, CoreNet, the Energy Efficient Solutions Logo, Flexis, MXC, Platform in a Package, Processor Expert, QorIQ, QUICC Engine, SmartMOS, TurboLink and VortiQa are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respect ive owners. © Freescale Semiconductor, Inc. 2010. 12

TM

► What is an RTOS?

► MQX Basics: Tasks

• Hands-on

► MQX Basics: Scheduling

• Hands-on

► MQX Basics: Task Synchronization

• Semaphores

Hands-on

► Additional Resources

► Review

Module Agenda

Freescale, the Freescale logo, AltiVec, C-5, CodeTest, CodeWarrior, ColdFire, C-Ware, mobileGT, PowerQUICC, StarCore, and Symphony are trademarks of Freescale Semiconductor, Inc.,

Reg. U.S. Pat. & Tm. Off. BeeKit, BeeStack, CoreNet, the Energy Efficient Solutions Logo, Flexis, MXC, Platform in a Package, Processor Expert, QorIQ, QUICC Engine, SmartMOS, TurboLink and VortiQa are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respect ive owners. © Freescale Semiconductor, Inc. 2010. 13

TM

MQX RTOS Tasks

► A system consists of multiple tasks

► Tasks take turns running

► Only one task is active (has the processor) at any given time

► MQX manages how the tasks share the processor (context switching)

► Task Context

• Data structure stored for each task, including registers and a list of owned resources

Freescale, the Freescale logo, AltiVec, C-5, CodeTest, CodeWarrior, ColdFire, C-Ware, mobileGT, PowerQUICC, StarCore, and Symphony are trademarks of Freescale Semiconductor, Inc.,

Reg. U.S. Pat. & Tm. Off. BeeKit, BeeStack, CoreNet, the Energy Efficient Solutions Logo, Flexis, MXC, Platform in a Package, Processor Expert, QorIQ, QUICC Engine, SmartMOS, TurboLink and VortiQa are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respect ive owners. © Freescale Semiconductor, Inc. 2010. 14

TM

Typical Task Coding Structure

Freescale, the Freescale logo, AltiVec, C-5, CodeTest, CodeWarrior, ColdFire, C-Ware, mobileGT, PowerQUICC, StarCore, and Symphony are trademarks of Freescale Semiconductor, Inc.,

Reg. U.S. Pat. & Tm. Off. BeeKit, BeeStack, CoreNet, the Energy Efficient Solutions Logo, Flexis, MXC, Platform in a Package, Processor Expert, QorIQ, QUICC Engine, SmartMOS, TurboLink and VortiQa are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respect ive owners. © Freescale Semiconductor, Inc. 2010. 15

TM

► What is an RTOS?

► MQX Basics: Tasks

• Hands-on

► MQX Basics: Scheduling

• Hands-on

► MQX Basics: Task Synchronization

• Semaphores

Hands-on

► Additional Resources

► Review

Module Agenda

Freescale, the Freescale logo, AltiVec, C-5, CodeTest, CodeWarrior, ColdFire, C-Ware, mobileGT, PowerQUICC, StarCore, and Symphony are trademarks of Freescale Semiconductor, Inc.,

Reg. U.S. Pat. & Tm. Off. BeeKit, BeeStack, CoreNet, the Energy Efficient Solutions Logo, Flexis, MXC, Platform in a Package, Processor Expert, QorIQ, QUICC Engine, SmartMOS, TurboLink and VortiQa are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respect ive owners. © Freescale Semiconductor, Inc. 2010. 16

TM

Write Your First RTOS Application

Exercise:

Run your first application

Freescale, the Freescale logo, AltiVec, C-5, CodeTest, CodeWarrior, ColdFire, C-Ware, mobileGT, PowerQUICC, StarCore, and Symphony are trademarks of Freescale Semiconductor, Inc.,

Reg. U.S. Pat. & Tm. Off. BeeKit, BeeStack, CoreNet, the Energy Efficient Solutions Logo, Flexis, MXC, Platform in a Package, Processor Expert, QorIQ, QUICC Engine, SmartMOS, TurboLink and VortiQa are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respect ive owners. © Freescale Semiconductor, Inc. 2010. 17

TM

Hands On: Run your first application

► The application has only one task – the Init Task

 Prints out welcome

 Loops, incrementing x

► Follow the directions in Lab 1 to compile and run the lab using CodeWarrior 10

► Pause the execution to see the init task running

Freescale, the Freescale logo, AltiVec, C-5, CodeTest, CodeWarrior, ColdFire, C-Ware, mobileGT, PowerQUICC, StarCore, and Symphony are trademarks of Freescale Semiconductor, Inc.,

Reg. U.S. Pat. & Tm. Off. BeeKit, BeeStack, CoreNet, the Energy Efficient Solutions Logo, Flexis, MXC, Platform in a Package, Processor Expert, QorIQ, QUICC Engine, SmartMOS, TurboLink and VortiQa are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respect ive owners. © Freescale Semiconductor, Inc. 2010. 18

TM

► A task is in one of these logical states:

 blocked

 the task is blocked and therefore not ready it’s waiting for a condition to be true active

 the task is ready and is running because it’s the highestpriority ready task ready

 the task is ready, but it’s not running because it isn’t the highest-priority ready task terminated

 the task has finished all its work, or was explicitly destroyed

Task States

Freescale, the Freescale logo, AltiVec, C-5, CodeTest, CodeWarrior, ColdFire, C-Ware, mobileGT, PowerQUICC, StarCore, and Symphony are trademarks of Freescale Semiconductor, Inc.,

Reg. U.S. Pat. & Tm. Off. BeeKit, BeeStack, CoreNet, the Energy Efficient Solutions Logo, Flexis, MXC, Platform in a Package, Processor Expert, QorIQ, QUICC Engine, SmartMOS, TurboLink and VortiQa are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respect ive owners. © Freescale Semiconductor, Inc. 2010. 19

TM

Task States

Task Finishes

Explicit

Termination

Terminated

Active

Higher-priority Task becomes Ready

Time Slice Expires

Interrupt comes in

Context Switch

Blocking

Call

Blocked

Task

Starts

Ready

Object

Available

Timeout Expires

Freescale, the Freescale logo, AltiVec, C-5, CodeTest, CodeWarrior, ColdFire, C-Ware, mobileGT, PowerQUICC, StarCore, and Symphony are trademarks of Freescale Semiconductor, Inc.,

Reg. U.S. Pat. & Tm. Off. BeeKit, BeeStack, CoreNet, the Energy Efficient Solutions Logo, Flexis, MXC, Platform in a Package, Processor Expert, QorIQ, QUICC Engine, SmartMOS, TurboLink and VortiQa are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respect ive owners. © Freescale Semiconductor, Inc. 2010. 20

TM

► What is an RTOS?

► MQX Basics: Tasks

• Hands-on

► MQX Basics: Scheduling

• Hands-on

► MQX Basics: Task Synchronization

• Semaphores

Hands-on

► Additional Resources

► Review

Module Agenda

Freescale, the Freescale logo, AltiVec, C-5, CodeTest, CodeWarrior, ColdFire, C-Ware, mobileGT, PowerQUICC, StarCore, and Symphony are trademarks of Freescale Semiconductor, Inc.,

Reg. U.S. Pat. & Tm. Off. BeeKit, BeeStack, CoreNet, the Energy Efficient Solutions Logo, Flexis, MXC, Platform in a Package, Processor Expert, QorIQ, QUICC Engine, SmartMOS, TurboLink and VortiQa are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respect ive owners. © Freescale Semiconductor, Inc. 2010. 21

TM

► Each task is assigned a priority

• Higher number means lower priority

• 0 is highest priority

► Used by scheduler to determine which task to run next

► User tasks should run at priority 8 or higher.

Priorities

Freescale, the Freescale logo, AltiVec, C-5, CodeTest, CodeWarrior, ColdFire, C-Ware, mobileGT, PowerQUICC, StarCore, and Symphony are trademarks of Freescale Semiconductor, Inc.,

Reg. U.S. Pat. & Tm. Off. BeeKit, BeeStack, CoreNet, the Energy Efficient Solutions Logo, Flexis, MXC, Platform in a Package, Processor Expert, QorIQ, QUICC Engine, SmartMOS, TurboLink and VortiQa are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respect ive owners. © Freescale Semiconductor, Inc. 2010. 22

TM

T

► Common Scheduling Configurations:

FIFO (also called priority-based preemptive)

The active task is the highest-priority task that has been ready the longest

Round Robin

The active task is the highest-priority task that has been ready the longest without consuming its time slice

Scheduler

Freescale, the Freescale logo, AltiVec, C-5, CodeTest, CodeWarrior, ColdFire, C-Ware, mobileGT, PowerQUICC, StarCore, and Symphony are trademarks of Freescale Semiconductor, Inc.,

Reg. U.S. Pat. & Tm. Off. BeeKit, BeeStack, CoreNet, the Energy Efficient Solutions Logo, Flexis, MXC, Platform in a Package, Processor Expert, QorIQ, QUICC Engine, SmartMOS, TurboLink and VortiQa are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respect ive owners. © Freescale Semiconductor, Inc. 2010. 23

TM

T high

FIFO list of ready tasks priority

Priority Based FIFO Scheduling low

CPU

Scheduler active

Freescale, the Freescale logo, AltiVec, C-5, CodeTest, CodeWarrior, ColdFire, C-Ware, mobileGT, PowerQUICC, StarCore, and Symphony are trademarks of Freescale Semiconductor, Inc.,

Reg. U.S. Pat. & Tm. Off. BeeKit, BeeStack, CoreNet, the Energy Efficient Solutions Logo, Flexis, MXC, Platform in a Package, Processor Expert, QorIQ, QUICC Engine, SmartMOS, TurboLink and VortiQa are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respect ive owners. © Freescale Semiconductor, Inc. 2010. processor time

TM

T high

FIFO list of ready tasks priority

Priority Based FIFO Scheduling low

CPU

Scheduler active

Freescale, the Freescale logo, AltiVec, C-5, CodeTest, CodeWarrior, ColdFire, C-Ware, mobileGT, PowerQUICC, StarCore, and Symphony are trademarks of Freescale Semiconductor, Inc.,

Reg. U.S. Pat. & Tm. Off. BeeKit, BeeStack, CoreNet, the Energy Efficient Solutions Logo, Flexis, MXC, Platform in a Package, Processor Expert, QorIQ, QUICC Engine, SmartMOS, TurboLink and VortiQa are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respect ive owners. © Freescale Semiconductor, Inc. 2010. processor time

TM

T high

FIFO list of ready tasks priority

Priority Based FIFO Scheduling low

CPU

Scheduler active

Freescale, the Freescale logo, AltiVec, C-5, CodeTest, CodeWarrior, ColdFire, C-Ware, mobileGT, PowerQUICC, StarCore, and Symphony are trademarks of Freescale Semiconductor, Inc.,

Reg. U.S. Pat. & Tm. Off. BeeKit, BeeStack, CoreNet, the Energy Efficient Solutions Logo, Flexis, MXC, Platform in a Package, Processor Expert, QorIQ, QUICC Engine, SmartMOS, TurboLink and VortiQa are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respect ive owners. © Freescale Semiconductor, Inc. 2010. processor time

TM

T

Same

Priority

Time Slice = 50ms

Task 1

75ms

Task 2

50ms

Task 3

60ms

Round-Robin Scheduling time

T0

Task1

50ms

Task2

100ms

Task3 Task1 Task3

150ms 200ms time

Freescale, the Freescale logo, AltiVec, C-5, CodeTest, CodeWarrior, ColdFire, C-Ware, mobileGT, PowerQUICC, StarCore, and Symphony are trademarks of Freescale Semiconductor, Inc.,

Reg. U.S. Pat. & Tm. Off. BeeKit, BeeStack, CoreNet, the Energy Efficient Solutions Logo, Flexis, MXC, Platform in a Package, Processor Expert, QorIQ, QUICC Engine, SmartMOS, TurboLink and VortiQa are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respect ive owners. © Freescale Semiconductor, Inc. 2010.

TM

T

► Tasks can be automatically created when MQX Starts; also, any task can create another task by calling _task_create() or

_task_create_blocked()

► The function _task_create() puts the child task in the ready state and the scheduler puts the higher priority task to run

► If _task_create_blocked is used the task is not ready until

_task_ready() is called

_task_abort

_task_destroy

Terminated

_task_create

Active

Ready

MQX Tasks

_task_block

Blocked

_task_ready

Freescale, the Freescale logo, AltiVec, C-5, CodeTest, CodeWarrior, ColdFire, C-Ware, mobileGT, PowerQUICC, StarCore, and Symphony are trademarks of Freescale Semiconductor, Inc.,

Reg. U.S. Pat. & Tm. Off. BeeKit, BeeStack, CoreNet, the Energy Efficient Solutions Logo, Flexis, MXC, Platform in a Package, Processor Expert, QorIQ, QUICC Engine, SmartMOS, TurboLink and VortiQa are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respect ive owners. © Freescale Semiconductor, Inc. 2010. 28

TM

Creating a Task

► When creating a task you have to:

 Make the task prototype and index definition

#define INIT_TASK 5 extern void init_task(uint_32);

 Add the task in the Task Template List

TASK_TEMPLATE_STRUCT MQX_template_list[] =

{

{ TASK_INDEX, TASK, STACK, TASK_PRIORITY,

TASK_NAME, TASK_ATTRIBUTES, CREATION_PARAMETER,

TIME_SLICE}

}

Using the init_task example:

TASK_TEMPLATE_STRUCT MQX_template_list[] =

{

{INIT_TASK, init_task, 1500, 9, "init",

MQX_AUTO_START_TASK, 0, 0},

}

Freescale, the Freescale logo, AltiVec, C-5, CodeTest, CodeWarrior, ColdFire, C-Ware, mobileGT, PowerQUICC, StarCore, and Symphony are trademarks of Freescale Semiconductor, Inc.,

Reg. U.S. Pat. & Tm. Off. BeeKit, BeeStack, CoreNet, the Energy Efficient Solutions Logo, Flexis, MXC, Platform in a Package, Processor Expert, QorIQ, QUICC Engine, SmartMOS, TurboLink and VortiQa are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respect ive owners. © Freescale Semiconductor, Inc. 2010. 29

TM

► When creating a task you have to:

 Make the task definition

}

{ void init_task(void)

/* Put the Task Code here */

 During execution time, create the task using task_create()

(if it is not an autostart task)

Creating a Task

Freescale, the Freescale logo, AltiVec, C-5, CodeTest, CodeWarrior, ColdFire, C-Ware, mobileGT, PowerQUICC, StarCore, and Symphony are trademarks of Freescale Semiconductor, Inc.,

Reg. U.S. Pat. & Tm. Off. BeeKit, BeeStack, CoreNet, the Energy Efficient Solutions Logo, Flexis, MXC, Platform in a Package, Processor Expert, QorIQ, QUICC Engine, SmartMOS, TurboLink and VortiQa are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respect ive owners. © Freescale Semiconductor, Inc. 2010. 30

TM

MQX_Template_List

{ WORLD_ID, world_task, 0x3000, 9,

"world_task",

MQX_AUTO_START_TASK, 0L, 0},

{ HELLO_ID, hello_task, 0x1000, 8,

“hello_task",

MQX_TIME_SLICE_TASK, 0L, 100},

{ LED_ID, led_task, 0x2000, 10,

“LED Task",

MQX_AUTO_START_TASK |

MQX_TIME_SLICE_TASK, 0L, 50},

Freescale, the Freescale logo, AltiVec, C-5, CodeTest, CodeWarrior, ColdFire, C-Ware, mobileGT, PowerQUICC, StarCore, and Symphony are trademarks of Freescale Semiconductor, Inc.,

Reg. U.S. Pat. & Tm. Off. BeeKit, BeeStack, CoreNet, the Energy Efficient Solutions Logo, Flexis, MXC, Platform in a Package, Processor Expert, QorIQ, QUICC Engine, SmartMOS, TurboLink and VortiQa are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respect ive owners. © Freescale Semiconductor, Inc. 2010. 31

TM

T

MQX - Task Management Example

{INIT_TASK, init_task, 1500, 11,

"init",

MQX_AUTO_START_TASK,

0, 0},

{TASK_A, Task_A,

1500, 10, “Task A",

0, 0, 0},

{TASK_B, Task_B,

1500, 9, “Task B",

0, 0, 0}, void init_task(void)

{

_task_create(0,TASK_A,0);

...

_task_ready(Task_B);

...

} void Task_A(void)

{

...

_task_create_blocked(0,TASK_B,0);

}

...

_task_abort(TASK_A); void Task_B(void)

{

}

...

_task_abort(TASK_B); init_task is created when

MQX starts

CPU Time

Freescale, the Freescale logo, AltiVec, C-5, CodeTest, CodeWarrior, ColdFire, C-Ware, mobileGT, PowerQUICC, StarCore, and Symphony are trademarks of Freescale Semiconductor, Inc.,

Reg. U.S. Pat. & Tm. Off. BeeKit, BeeStack, CoreNet, the Energy Efficient Solutions Logo, Flexis, MXC, Platform in a Package, Processor Expert, QorIQ, QUICC Engine, SmartMOS, TurboLink and VortiQa are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respect ive owners. © Freescale Semiconductor, Inc. 2010.

TM

► What is an RTOS?

► MQX Basics: Tasks

• Hands-on

► MQX Basics: Scheduling

• Hands-on

► MQX Basics: Task Synchronization

• Semaphores

Hands-on

► Additional Resources

► Review

Module Agenda

Freescale, the Freescale logo, AltiVec, C-5, CodeTest, CodeWarrior, ColdFire, C-Ware, mobileGT, PowerQUICC, StarCore, and Symphony are trademarks of Freescale Semiconductor, Inc.,

Reg. U.S. Pat. & Tm. Off. BeeKit, BeeStack, CoreNet, the Energy Efficient Solutions Logo, Flexis, MXC, Platform in a Package, Processor Expert, QorIQ, QUICC Engine, SmartMOS, TurboLink and VortiQa are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respect ive owners. © Freescale Semiconductor, Inc. 2010. 33

TM

Write Your First RTOS Application

Exercise:

Scheduling Lab

Freescale, the Freescale logo, AltiVec, C-5, CodeTest, CodeWarrior, ColdFire, C-Ware, mobileGT, PowerQUICC, StarCore, and Symphony are trademarks of Freescale Semiconductor, Inc.,

Reg. U.S. Pat. & Tm. Off. BeeKit, BeeStack, CoreNet, the Energy Efficient Solutions Logo, Flexis, MXC, Platform in a Package, Processor Expert, QorIQ, QUICC Engine, SmartMOS, TurboLink and VortiQa are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respect ive owners. © Freescale Semiconductor, Inc. 2010. 34

TM

Hands On: Scheduling

► Add the print task to our application

Init Task:

 AUTOSTART, priority 9

Prints out welcome

Loops, incrementing x

Print Task:

 AUTOSTART, priority 10

 Loops, printing the value of x

► Add a _time_delay() to block the init task after incrementing x

► Follow the directions in Lab 2 to compile, download and run the code

Freescale, the Freescale logo, AltiVec, C-5, CodeTest, CodeWarrior, ColdFire, C-Ware, mobileGT, PowerQUICC, StarCore, and Symphony are trademarks of Freescale Semiconductor, Inc.,

Reg. U.S. Pat. & Tm. Off. BeeKit, BeeStack, CoreNet, the Energy Efficient Solutions Logo, Flexis, MXC, Platform in a Package, Processor Expert, QorIQ, QUICC Engine, SmartMOS, TurboLink and VortiQa are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respect ive owners. © Freescale Semiconductor, Inc. 2010.

TM

Task Aware Debugging

► Task Aware Debugging is available to analyze tasks running on MQX

► Look at the ready queues and task state

Freescale, the Freescale logo, AltiVec, C-5, CodeTest, CodeWarrior, ColdFire, C-Ware, mobileGT, PowerQUICC, StarCore, and Symphony are trademarks of Freescale Semiconductor, Inc.,

Reg. U.S. Pat. & Tm. Off. BeeKit, BeeStack, CoreNet, the Energy Efficient Solutions Logo, Flexis, MXC, Platform in a Package, Processor Expert, QorIQ, QUICC Engine, SmartMOS, TurboLink and VortiQa are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respect ive owners. © Freescale Semiconductor, Inc. 2010. 36

TM

► What is an RTOS?

► MQX Basics: Tasks

• Hands-on

► MQX Basics: Scheduling

• Hands-on

► MQX Basics: Task Synchronization

• Semaphores

Hands-on

► Additional Resources

► Review

Module Agenda

Freescale, the Freescale logo, AltiVec, C-5, CodeTest, CodeWarrior, ColdFire, C-Ware, mobileGT, PowerQUICC, StarCore, and Symphony are trademarks of Freescale Semiconductor, Inc.,

Reg. U.S. Pat. & Tm. Off. BeeKit, BeeStack, CoreNet, the Energy Efficient Solutions Logo, Flexis, MXC, Platform in a Package, Processor Expert, QorIQ, QUICC Engine, SmartMOS, TurboLink and VortiQa are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respect ive owners. © Freescale Semiconductor, Inc. 2010. 37

TM

Why Synchronization?

► Synchronization may be used to solve:

 Mutual Exclusion

Control Flow

Data Flow

Synchronization Mechanisms include:

Semaphores

Events

Mutexs

Message Queues

► The correct synchronization mechanism depends on the synchronization issue being addressed

EF

M

Freescale, the Freescale logo, AltiVec, C-5, CodeTest, CodeWarrior, ColdFire, C-Ware, mobileGT, PowerQUICC, StarCore, and Symphony are trademarks of Freescale Semiconductor, Inc.,

Reg. U.S. Pat. & Tm. Off. BeeKit, BeeStack, CoreNet, the Energy Efficient Solutions Logo, Flexis, MXC, Platform in a Package, Processor Expert, QorIQ, QUICC Engine, SmartMOS, TurboLink and VortiQa are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respect ive owners. © Freescale Semiconductor, Inc. 2010.

TM

Control Flow with Synchronization

► One task affects another’s execution, so that tasks execute in an application-controlled order

Active Task

Post Wait

Blocked

Task

Freescale, the Freescale logo, AltiVec, C-5, CodeTest, CodeWarrior, ColdFire, C-Ware, mobileGT, PowerQUICC, StarCore, and Symphony are trademarks of Freescale Semiconductor, Inc.,

Reg. U.S. Pat. & Tm. Off. BeeKit, BeeStack, CoreNet, the Energy Efficient Solutions Logo, Flexis, MXC, Platform in a Package, Processor Expert, QorIQ, QUICC Engine, SmartMOS, TurboLink and VortiQa are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respect ive owners. © Freescale Semiconductor, Inc. 2010.

TM

Mutual Exclusion

► Allowing only one task at a time to access a shared resource

► Resource may be devices, files, memory, drivers, code…

► Mutual exclusion locks the resource

Protected Resource

M

TASK 1

Lock do work

Unlock

TASK 2

Lock do work

Unlock

TASK 3

Lock do work

Unlock

TASK 4

Lock do work

Unlock

Freescale, the Freescale logo, AltiVec, C-5, CodeTest, CodeWarrior, ColdFire, C-Ware, mobileGT, PowerQUICC, StarCore, and Symphony are trademarks of Freescale Semiconductor, Inc.,

Reg. U.S. Pat. & Tm. Off. BeeKit, BeeStack, CoreNet, the Energy Efficient Solutions Logo, Flexis, MXC, Platform in a Package, Processor Expert, QorIQ, QUICC Engine, SmartMOS, TurboLink and VortiQa are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respect ive owners. © Freescale Semiconductor, Inc. 2010.

TM

Competence Condition

► What happens if two tasks access the same resource at the same time?

 We call this “competence condition”. When two or more tasks read or write on share a resource at a certain moment

► Why the “competence condition” can be a problem?

Memory corruption

Wrong results

Unstable application

Device conflicts

Freescale, the Freescale logo, AltiVec, C-5, CodeTest, CodeWarrior, ColdFire, C-Ware, mobileGT, PowerQUICC, StarCore, and Symphony are trademarks of Freescale Semiconductor, Inc.,

Reg. U.S. Pat. & Tm. Off. BeeKit, BeeStack, CoreNet, the Energy Efficient Solutions Logo, Flexis, MXC, Platform in a Package, Processor Expert, QorIQ, QUICC Engine, SmartMOS, TurboLink and VortiQa are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respect ive owners. © Freescale Semiconductor, Inc. 2010. 41

TM

► What is an RTOS?

► MQX Basics: Tasks

• Hands-on

► MQX Basics: Scheduling

• Hands-on

► MQX Basics: Task Synchronization

• Semaphores

Hands-on

► Additional Resources

► Review

Module Agenda

Freescale, the Freescale logo, AltiVec, C-5, CodeTest, CodeWarrior, ColdFire, C-Ware, mobileGT, PowerQUICC, StarCore, and Symphony are trademarks of Freescale Semiconductor, Inc.,

Reg. U.S. Pat. & Tm. Off. BeeKit, BeeStack, CoreNet, the Energy Efficient Solutions Logo, Flexis, MXC, Platform in a Package, Processor Expert, QorIQ, QUICC Engine, SmartMOS, TurboLink and VortiQa are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respect ive owners. © Freescale Semiconductor, Inc. 2010. 42

TM

Semaphores

► A semaphore is a protocol mechanism offered by most multitasking kernels. Semaphores are used to:

Control access to a shared resource

(mutual exclusion)

Signal the occurrence of an event

Allow two tasks to synchronize their activities

► A semaphore is a token that your code acquires in order to continue execution

► If the semaphore is already in use, the requesting task is suspended until the semaphore is released by its current owner

Freescale, the Freescale logo, AltiVec, C-5, CodeTest, CodeWarrior, ColdFire, C-Ware, mobileGT, PowerQUICC, StarCore, and Symphony are trademarks of Freescale Semiconductor, Inc.,

Reg. U.S. Pat. & Tm. Off. BeeKit, BeeStack, CoreNet, the Energy Efficient Solutions Logo, Flexis, MXC, Platform in a Package, Processor Expert, QorIQ, QUICC Engine, SmartMOS, TurboLink and VortiQa are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respect ive owners. © Freescale Semiconductor, Inc. 2010. 43

TM

How Semaphores Work

► A semaphore has:

 counter — maximum number of concurrent accesses

 queue — for tasks that wait for access

► If a task waits for a semaphore

 if counter > 0 counter is decremented by 1 task gets the semaphore and can do work else task is put in the queue

► If a task releases (post) a semaphore

 if at least one task is in the semaphore queue appropriate task is readied, according to the queuing policy else counter is incremented by 1

Freescale, the Freescale logo, AltiVec, C-5, CodeTest, CodeWarrior, ColdFire, C-Ware, mobileGT, PowerQUICC, StarCore, and Symphony are trademarks of Freescale Semiconductor, Inc.,

Reg. U.S. Pat. & Tm. Off. BeeKit, BeeStack, CoreNet, the Energy Efficient Solutions Logo, Flexis, MXC, Platform in a Package, Processor Expert, QorIQ, QUICC Engine, SmartMOS, TurboLink and VortiQa are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respect ive owners. © Freescale Semiconductor, Inc. 2010.

TM

Using Lightweight Semaphores

To declare a lightweight semaphore:

LWSEM_STRUCT sem;

To create a lightweight semaphore:

_mqx_uint _lwsem_create (lwsem_ptr,initial_count)

To wait for a lightweight semaphore

_mqx_uint _lwsem_wait (lwsem_ptr)

► To post a lightweight semaphore:

_mqx_uint _lwsem_post (lwsem_ptr)

Freescale, the Freescale logo, AltiVec, C-5, CodeTest, CodeWarrior, ColdFire, C-Ware, mobileGT, PowerQUICC, StarCore, and Symphony are trademarks of Freescale Semiconductor, Inc.,

Reg. U.S. Pat. & Tm. Off. BeeKit, BeeStack, CoreNet, the Energy Efficient Solutions Logo, Flexis, MXC, Platform in a Package, Processor Expert, QorIQ, QUICC Engine, SmartMOS, TurboLink and VortiQa are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respect ive owners. © Freescale Semiconductor, Inc. 2010. 45

TM

► What is an RTOS?

► MQX Basics: Tasks

• Hands-on

► MQX Basics: Scheduling

• Hands-on

► MQX Basics: Task Synchronization

• Semaphores

Hands-on

► Additional Resources

► Review

Module Agenda

Freescale, the Freescale logo, AltiVec, C-5, CodeTest, CodeWarrior, ColdFire, C-Ware, mobileGT, PowerQUICC, StarCore, and Symphony are trademarks of Freescale Semiconductor, Inc.,

Reg. U.S. Pat. & Tm. Off. BeeKit, BeeStack, CoreNet, the Energy Efficient Solutions Logo, Flexis, MXC, Platform in a Package, Processor Expert, QorIQ, QUICC Engine, SmartMOS, TurboLink and VortiQa are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respect ive owners. © Freescale Semiconductor, Inc. 2010. 46

TM

Write Your First RTOS Application

Exercise:

Semaphore Lab

Freescale, the Freescale logo, AltiVec, C-5, CodeTest, CodeWarrior, ColdFire, C-Ware, mobileGT, PowerQUICC, StarCore, and Symphony are trademarks of Freescale Semiconductor, Inc.,

Reg. U.S. Pat. & Tm. Off. BeeKit, BeeStack, CoreNet, the Energy Efficient Solutions Logo, Flexis, MXC, Platform in a Package, Processor Expert, QorIQ, QUICC Engine, SmartMOS, TurboLink and VortiQa are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respect ive owners. © Freescale Semiconductor, Inc. 2010. 47

TM

Mutual Exclusion Hands-on

► The application uses the two tasks from the previous labs, but adds semaphore control for accessing the variable

► Follow the directions in Lab 3 to compile, download, and run the code

 Declare a global lightweight semaphore

 Create a lightweight semaphore, count = 1

 In both tasks:

Before accessing x, wait on the lightweight semaphore

After accessing x, post the lightweight semaphore

► Look at TAD to analyze the semaphores

Freescale, the Freescale logo, AltiVec, C-5, CodeTest, CodeWarrior, ColdFire, C-Ware, mobileGT, PowerQUICC, StarCore, and Symphony are trademarks of Freescale Semiconductor, Inc.,

Reg. U.S. Pat. & Tm. Off. BeeKit, BeeStack, CoreNet, the Energy Efficient Solutions Logo, Flexis, MXC, Platform in a Package, Processor Expert, QorIQ, QUICC Engine, SmartMOS, TurboLink and VortiQa are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respect ive owners. © Freescale Semiconductor, Inc. 2010.

TM

► MQX RTOS Basics

► Write Your MQX Application

► MQX Tasks

• Task scheduling

Hands-on

► Task Synchronization

• Semaphores

Hands-on

► Additional Resources

► Review

Freescale, the Freescale logo, AltiVec, C-5, CodeTest, CodeWarrior, ColdFire, C-Ware, mobileGT, PowerQUICC, StarCore, and Symphony are trademarks of Freescale Semiconductor, Inc.,

Reg. U.S. Pat. & Tm. Off. BeeKit, BeeStack, CoreNet, the Energy Efficient Solutions Logo, Flexis, MXC, Platform in a Package, Processor Expert, QorIQ, QUICC Engine, SmartMOS, TurboLink and VortiQa are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respect ive owners. © Freescale Semiconductor, Inc. 2010. 49

Module Agenda

TM

Freescale MQX™ Documentation

► MQXUG User Guide

► MQXRM Reference Manual

► MQXUSBHOSTAPIRM USB Host API Reference Manual

► MQXUSBDEVAPI USB Device API Reference

► MQXUSBHOSTUG USB Host User Guide

► MQXRTCSUG RTCS User Guide

► MQXMFSUG File System User Guide

► MQXIOUG I/O Drivers User Guide

► MQXFS Software Solutions Fact Sheets

Freescale, the Freescale logo, AltiVec, C-5, CodeTest, CodeWarrior, ColdFire, C-Ware, mobileGT, PowerQUICC, StarCore, and Symphony are trademarks of Freescale Semiconductor, Inc.,

Reg. U.S. Pat. & Tm. Off. BeeKit, BeeStack, CoreNet, the Energy Efficient Solutions Logo, Flexis, MXC, Platform in a Package, Processor Expert, QorIQ, QUICC Engine, SmartMOS, TurboLink and VortiQa are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respect ive owners. © Freescale Semiconductor, Inc. 2010. 50

TM

Further Reading and Training

TWR-MCF51CN-KIT Lab Document

MCF5225x – Lab Document

MQX Release Notes

MQX User’s Guide

Writing First MQX Application (AN3905)

Using MQX: RTCS, USB, and MFS (AN3907)

How to Develop I/O Drivers for MQX (AN3902)

Freescale, the Freescale logo, AltiVec, C-5, CodeTest, CodeWarrior, ColdFire, C-Ware, mobileGT, PowerQUICC, StarCore, and Symphony are trademarks of Freescale Semiconductor, Inc.,

Reg. U.S. Pat. & Tm. Off. BeeKit, BeeStack, CoreNet, the Energy Efficient Solutions Logo, Flexis, MXC, Platform in a Package, Processor Expert, QorIQ, QUICC Engine, SmartMOS, TurboLink and VortiQa are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respect ive owners. © Freescale Semiconductor, Inc. 2010. 51

TM

Further Reading and Training (Cont.)

Videos: www.freescale.com/mqx

MCF5225x & Freescale MQX introduction

Getting started with MCF5225x and Freescale MQX Lab Demos

And more

vFTF technical session videos www.freescale.com/vftf

 Introducing a modular system, Serial-toEthernet V1 ColdFire® MCU and Complimentary MQX™ RTOS

Writing First MQX Application

Implementing Ethernet Connectivity with the complimentary Freescale

MQX™ RTOS

Freescale, the Freescale logo, AltiVec, C-5, CodeTest, CodeWarrior, ColdFire, C-Ware, mobileGT, PowerQUICC, StarCore, and Symphony are trademarks of Freescale Semiconductor, Inc.,

Reg. U.S. Pat. & Tm. Off. BeeKit, BeeStack, CoreNet, the Energy Efficient Solutions Logo, Flexis, MXC, Platform in a Package, Processor Expert, QorIQ, QUICC Engine, SmartMOS, TurboLink and VortiQa are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respect ive owners. © Freescale Semiconductor, Inc. 2010. 52

TM

By now, you should be able to:

► Understand what an RTOS is and how they can be used

► Create tasks, schedule them and add synchronization using MQX

► Create your own MQX applications

In Summary

Freescale, the Freescale logo, AltiVec, C-5, CodeTest, CodeWarrior, ColdFire, C-Ware, mobileGT, PowerQUICC, StarCore, and Symphony are trademarks of Freescale Semiconductor, Inc.,

Reg. U.S. Pat. & Tm. Off. BeeKit, BeeStack, CoreNet, the Energy Efficient Solutions Logo, Flexis, MXC, Platform in a Package, Processor Expert, QorIQ, QUICC Engine, SmartMOS, TurboLink and VortiQa are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respect ive owners. © Freescale Semiconductor, Inc. 2010. 53

TM

TM

Download