12 - 1 texas instruments incorporated module 12 : real time os: dsp/bios 32-bit-digital signal...

22
12 - 12 - 1 Texas Instruments Incorporated Module 12 : Real Time OS: DSP/BIOS Module 12 : Real Time OS: DSP/BIOS 32-Bit-Digital Signal Controller TMS320F2812

Upload: janice-richardson

Post on 14-Dec-2015

218 views

Category:

Documents


1 download

TRANSCRIPT

12 - 12 - 11

Texas Instruments Incorporated

Module 12 : Real Time OS: DSP/BIOSModule 12 : Real Time OS: DSP/BIOS

32-Bit-Digital Signal ControllerTMS320F2812

12 - 12 - 22

Real Time Operating Systems (RTOS)Real Time Operating Systems (RTOS)

Particular class of operating systems for Particular class of operating systems for digital processor systemsdigital processor systems

Capable of serving multiple user tasks at one Capable of serving multiple user tasks at one time ( “multi-task OS”)time ( “multi-task OS”)

For all tasks in a running system it is For all tasks in a running system it is guaranteed, that random external events in guaranteed, that random external events in the environment of each individual task will the environment of each individual task will be serviced in a given time ( “Worst Case be serviced in a given time ( “Worst Case Response Time”).Response Time”).

All tasks must be served simultaneously All tasks must be served simultaneously (“multi-task OS”) AND timely (“RTOS”)(“multi-task OS”) AND timely (“RTOS”)

RTOS are very popular in embedded controlRTOS are very popular in embedded control

What is a RTOS?What is a RTOS?

12 - 12 - 33

Real Time Operating Systems (RTOS)Real Time Operating Systems (RTOS)

A running or executable program object, that:A running or executable program object, that: is controlled by a portion of machine codeis controlled by a portion of machine code ‘‘owns’ a given set of operating resources to owns’ a given set of operating resources to

start/resume its course of actions start/resume its course of actions is characterized by a set of state variables is characterized by a set of state variables

( registers, program counter, local stack variables, ( registers, program counter, local stack variables, semaphores, mailboxes)semaphores, mailboxes)

Tasks are programmed and debugged Tasks are programmed and debugged independently from each other independently from each other

Accesses to peripherals or data transfers Accesses to peripherals or data transfers between tasks are performed by RTOS -between tasks are performed by RTOS -system functions calls.system functions calls.

What is a Task?What is a Task?

12 - 12 - 44

Real Time Operating Systems (RTOS)Real Time Operating Systems (RTOS)

Each task can reside in one of the following Each task can reside in one of the following states:states:

What is a Task- State - Model?What is a Task- State - Model?

existent

not existent

ready

completedblocked

running

1

2 3

4

5

6

7

8

For explanation of arrows 1-8 see next slide

12 - 12 - 55

Real Time Operating Systems (RTOS)Real Time Operating Systems (RTOS)

1.1. A task is created by an initialization functionA task is created by an initialization function2.2. A task is selected by the scheduler to use the A task is selected by the scheduler to use the

CPUCPU3.3. The scheduler performs a task change The scheduler performs a task change

according to the scheduling rules of the according to the scheduling rules of the RTOSRTOS

4.4. The running task is waiting for an external The running task is waiting for an external event , a message from another task or for a event , a message from another task or for a signalsignal

5.5. The event that was blocking a task has The event that was blocking a task has occurredoccurred

6.6. The task has completed its programThe task has completed its program7.7. The task is re-activated by another task or The task is re-activated by another task or

by an eventby an event8.8. The task will never be used again ( as long as The task will never be used again ( as long as

the embedded system is not switched off)the embedded system is not switched off)All other task state transitions are illegal. All other task state transitions are illegal.

When does the task – state change?When does the task – state change?

12 - 12 - 66

Real Time Operating Systems (RTOS)Real Time Operating Systems (RTOS)

An important part of the RTOS that schedules the An important part of the RTOS that schedules the sequence of task execution phases and the change of sequence of task execution phases and the change of task statestask states

Two basic operating modes for schedulers:Two basic operating modes for schedulers: time slice mode - computing time is assigned to tasks in a time slice mode - computing time is assigned to tasks in a

predefined amount of processor timepredefined amount of processor time priority mode – computing time is assigned to tasks priority mode – computing time is assigned to tasks

according to the priority of each task in the system. If a according to the priority of each task in the system. If a task with higher priority gets into status ‘ready’ the task with higher priority gets into status ‘ready’ the running task will be pre-empted. running task will be pre-empted.

combined versions between pre-emptive and time slice combined versions between pre-emptive and time slice schedulers are also possibleschedulers are also possible

What is a Task - Scheduler?What is a Task - Scheduler?

12 - 12 - 77

Texas Instruments DSP/BIOSTexas Instruments DSP/BIOS

BIOS = “Build In Operating System”BIOS = “Build In Operating System” Texas Instruments firm ware RTOS kernel Texas Instruments firm ware RTOS kernel

for the TMS320 family of DSP’sfor the TMS320 family of DSP’s A full-featured, scalable real-time kernelA full-featured, scalable real-time kernel

System configuration toolsSystem configuration tools Preemptive multi-threading schedulerPreemptive multi-threading scheduler Real-time analysis toolsReal-time analysis tools

What is DSP/BIOS?What is DSP/BIOS?

12 - 12 - 88

Texas Instruments DSP/BIOSTexas Instruments DSP/BIOS

Helps manage complex C28x system resourcesHelps manage complex C28x system resources Allows to develop and test tasks in a multiple Allows to develop and test tasks in a multiple

task control environment independentlytask control environment independently Reduces software project development timeReduces software project development time Eases software maintenance & documentationEases software maintenance & documentation Integrated with Code Composer Studio IDEIntegrated with Code Composer Studio IDE

Requires no runtime license feesRequires no runtime license fees Fully supported by TI and is a key component of Fully supported by TI and is a key component of

TI’s eXpressDSP™ real-time software technologyTI’s eXpressDSP™ real-time software technology

Uses minimal MIPS and memory (2-8K)Uses minimal MIPS and memory (2-8K)

Why use DSP/BIOS?Why use DSP/BIOS?

12 - 12 - 99

DSP/BIOS Configuration Tool DSP/BIOS Configuration Tool (file .cdb)(file .cdb)

System Setup ToolsSystem Setup Tools

Handles memory configuration (builds .cmd file), run-time support libraries, interrupt vectors, system setup and reset, etc.

Real-Time Analysis ToolsReal-Time Analysis Tools

Allows application to run uninterrupted while displaying debug data

Real-Time SchedulerReal-Time Scheduler

Preemptive tread manager kernel Real-Time I/OReal-Time I/O

Allows two way communication between threads or between target and PC host

12 - 12 - 1010

TI DSP

Design Problem: Add a new FunctionDesign Problem: Add a new Function

Existing Function

New Function Issues:

Do we have enough remaining computing power to add another function?

Are there possible resource conflicts between the new function and the existing system?

Will the new system meet all time restrictions in a real-time embedded control system?

What are some possible solutions?

Function 1

Function 2

12 - 12 - 1111

Solution 1: extend the main-loopSolution 1: extend the main-loop

Function 2

Function 1

Main(){while(1){

}}

Potential Problems:

What if Algorithms run at different rates:- motor current loop at 20 kHz- respond to keypad input at 2 Hz

What if one algorithm consumes enough MIPS to force the other algorithm to miss its real-time deadlines / delays its response?

Call each function from an endless loop within main

12 - 12 - 1212

Solution 2: use interruptsSolution 2: use interrupts

TI DSP

main{while(1);

}

Function1_ISR{

}

Function2_ISR{

}

Only one ISR can run at a time: Function 1 will be delayed, eventually missing its deadline…

Period Compute CPU Usage

Function 1: 0.05 ms 1 s 2%

Function 2: 500 ms 3 s ~ 0%

2%

Function 2

Function 1

An interrupt driven system places each function in its own ISR

running

idle

Time 1 2 3 54 6 70

Function 1

Function 2

12 - 12 - 1313

Solution 3: nested hardware interrupts (HWI)Solution 3: nested hardware interrupts (HWI)

Use DSP/BIOS HWI dispatcher for context save/restore, and allow preemption

Reasonable approach if you have limited number of interrupts/functions

one HWI function for each interrupt

running

idle

Time 1 2 3 54 6 70

Nested interrupts allow hardwareinterrupts to preempt each other

main{return;

}

Function1_ISR{

}

Function2_ISR{

}Function 2

Function 1

12 - 12 - 1414

interrupt void MyHwi(void){}

DSP/BIOS - HWI Dispatcher for ISRsDSP/BIOS - HWI Dispatcher for ISRs For non-BIOS code, we use the interrupt keyword to declare an ISR

tells the compiler to perform context save/restore

For DSP/BIOS code, the dispatcher will perform the save/restore Remove the interrupt keyword from the MyHwi()

Check the “Use Dispatcher” box when you configure the interrupt vector in the DSP/BIOS config tools

12 - 12 - 1515

DSP/BIOS - Software Interrupts (SWI)DSP/BIOS - Software Interrupts (SWI)

main{ …// return to O/S;}

DSP/BIOS

Make each algorithm an independent software interrupt

SWI scheduling is handled by DSP/BIOS HWI function triggered by hardware SWI function triggered by software

e.g. a call to SWI_post() Why use a SWI?

No limitation on number of SWIs, and priorities for SWIs are user-defined

SWI can be scheduled by hardware or software event(s)

Relocate task processing from HWI to SWI

Function 2

Function 1

12 - 12 - 1616

period

LED LED LED

DSP/BIOS - Periodic FunctionsDSP/BIOS - Periodic Functions

Periodic functions run at a specific rate in your system:- e.g. LED blink requires 0.5 Hz

Use the CLK Manager to specify the DSP/BIOS CLK rate in microseconds per “tick”

Use the PRD Manager to specify the period (for the function) in ticks

Allows multiple periodic functions with different rates

DSP/BIOSCLK

tick

12 - 12 - 1717

Creating a Periodic FunctionCreating a Periodic Function

period

func1 func1 func1

DSP/BIOSCLK

tick

12 - 12 - 1818

Enabling BIOS – Return from main()Enabling BIOS – Return from main()

main{ …// return to BIOS}

DSP BIOS

Function 2

Function 1

Must delete the endless while() loop main() returns to BIOS IDLE thread,

allowing BIOS to schedule events, transfer info to host, etc.

An endless while() loop in main() will not allow BIOS to activate

12 - 12 - 1919

Built-in Real-Time Analysis ToolsBuilt-in Real-Time Analysis Tools Gather data on target (3-10 CPU cycles) Send data during BIOS IDL (100s of cycles) Format data on host (1000s of cycles) Data gathering does NOT stop target CPU

Execution Graph

Shows amount of CPU- power being consumed

CPU Load Graph

Software logic analyzer Debug event timing

and priority

12 - 12 - 2020

DSP/BIOS - API ModulesDSP/BIOS - API Modules

Instrumentation/Real-Time Analysis Instrumentation/Real-Time Analysis

LOGLOG Message log managerMessage log managerSTSSTS Statistics accumulator manager Statistics accumulator manager TRCTRC Trace manager Trace manager RTDXRTDX Real-Time Data eXchange manager Real-Time Data eXchange manager

Thread Types Thread Types

HWIHWI Hardware interrupt manager Hardware interrupt manager SWISWI Software interrupt manager Software interrupt manager TSKTSK Multi-tasking manager Multi-tasking manager IDLIDL Idle function & process loop manager Idle function & process loop manager

Clock and Periodic Functions Clock and Periodic Functions

CLKCLK System clock manager System clock manager PRDPRD Periodic function manager Periodic function manager

TSK Communication/SynchronizationTSK Communication/Synchronization

SEMSEM Semaphores manager Semaphores manager MBXMBX Mailboxes manager Mailboxes manager LCKLCK Resource lock manager Resource lock manager

Device-Independent Input/Output Device-Independent Input/Output

PIPPIP Data pipe manager Data pipe manager HSTHST Host input/output manager Host input/output manager SIOSIO Stream I/O manager Stream I/O manager DEVDEV Device driver interface Device driver interface

Memory and Low-Level PrimitivesMemory and Low-Level Primitives

MEMMEM Memory manager Memory manager SYSSYS System services manager System services manager QUEQUE Queue manager Queue manager ATMATM Atomic functions Atomic functions GBLGBL Global setting manager Global setting manager

12 - 12 - 2121

Lab 12: Modify Lab 2 to use BIOSLab 12: Modify Lab 2 to use BIOS

Use your solution for Lab2 to begin with Modify the project to use DSP/BIOS functionality Let DSP/BIOS create the necessary Linker

Command Files Replace the software delay loop from Lab2 by a

periodic function (“PRD”) of DSP/BIOS Create a new function “led_runner()” that will

activate the next state of the LED-line Call this function every 500ms with a PRD-function

out of DSP/BIOS

For a detailed procedure see textbook!