develop an rtos- based application in less than 30 … · synergy ssp integration fully integrated...

26
© 2016 Renesas Electronics Corporation. All rights reserved. Renesas Synergy Engineering Conference LAKE GARDA 7-8 April 2016 DEVELOP AN RTOS- BASED APPLICATION IN LESS THAN 30 MINUTES

Upload: others

Post on 27-May-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: DEVELOP AN RTOS- BASED APPLICATION IN LESS THAN 30 … · SYNERGY SSP INTEGRATION Fully integrated into e2 studio RTOS and middleware configuration, task table views in debugger and

© 2016 Renesas Electronics Corporation. All rights reserved.

Renesas Synergy Engineering ConferenceLAKE GARDA7-8 April 2016

DEVELOP AN RTOS-BASED APPLICATION IN LESS THAN 30 MINUTES

Page 2: DEVELOP AN RTOS- BASED APPLICATION IN LESS THAN 30 … · SYNERGY SSP INTEGRATION Fully integrated into e2 studio RTOS and middleware configuration, task table views in debugger and

© 2016 Renesas Electronics Corporation. All rights reserved. Page 2

AGENDA

Products without an Operating System

Why use an Operating System?

Benefits of using an Operating System

What is a Thread/Process/Task?

Pre-emptive Kernel

e2 studio, ThreadX & X-Ware

Summary & conclusions

Page 3: DEVELOP AN RTOS- BASED APPLICATION IN LESS THAN 30 … · SYNERGY SSP INTEGRATION Fully integrated into e2 studio RTOS and middleware configuration, task table views in debugger and

© 2016 Renesas Electronics Corporation. All rights reserved. Page 3

PRODUCTS WITHOUT AN OPERATING

SYSTEM

Page 4: DEVELOP AN RTOS- BASED APPLICATION IN LESS THAN 30 … · SYNERGY SSP INTEGRATION Fully integrated into e2 studio RTOS and middleware configuration, task table views in debugger and

© 2016 Renesas Electronics Corporation. All rights reserved.

PRODUCTS WITHOUT AN OPERATING SYSTEM

Page 4

thread #1

ISR #1

thread #2

ISR #2

ISR #1

thread #3Background

Foreground #1

Foreground #2

Time

Infinite loop

Page 5: DEVELOP AN RTOS- BASED APPLICATION IN LESS THAN 30 … · SYNERGY SSP INTEGRATION Fully integrated into e2 studio RTOS and middleware configuration, task table views in debugger and

© 2016 Renesas Electronics Corporation. All rights reserved.

TYPICAL IMPLEMENTATION WITHOUT AN RTOS

Page 5

/* Background */ void main (void) {Initialization;FOREVER {Read analog inputs;Read discrete inputs;Perform monitoring functions;Perform control functions;Update analog outputs;Update discrete outputs;Scan keyboard;Handle user interface;Update display;Handle communication requests;Other...

}}

/* Foreground */ISR (void) {

Handle asynchronous event;}

Page 6: DEVELOP AN RTOS- BASED APPLICATION IN LESS THAN 30 … · SYNERGY SSP INTEGRATION Fully integrated into e2 studio RTOS and middleware configuration, task table views in debugger and

© 2016 Renesas Electronics Corporation. All rights reserved. Page 6

DISADVANTAGES OF NO OPERATING SYSTEM

Background response time is the background execution time

Non-deterministic

Affected by if, for, while ...

May not be responsive enough

Changes as you change your code

thread #3 thread #4

Poll to see if ISR occurred

Affected by if, for, while

thread #1 thread #2

ISR #1

Page 7: DEVELOP AN RTOS- BASED APPLICATION IN LESS THAN 30 … · SYNERGY SSP INTEGRATION Fully integrated into e2 studio RTOS and middleware configuration, task table views in debugger and

© 2016 Renesas Electronics Corporation. All rights reserved. Page 7

DISADVANTAGES OF NO OPERATING SYSTEM (CONT.)

All ‘threads’ have the same priority!

Code executes in sequence

If an important event occurs it’s handled at the same priority as everything else!

You may need to execute the same code often to avoid missing an event.

thread #3 thread #4

Infinite loop

thread #1 thread #2

Page 8: DEVELOP AN RTOS- BASED APPLICATION IN LESS THAN 30 … · SYNERGY SSP INTEGRATION Fully integrated into e2 studio RTOS and middleware configuration, task table views in debugger and

© 2016 Renesas Electronics Corporation. All rights reserved.

WHY USE AN OPERATING SYSTEM?

Page 8

Page 9: DEVELOP AN RTOS- BASED APPLICATION IN LESS THAN 30 … · SYNERGY SSP INTEGRATION Fully integrated into e2 studio RTOS and middleware configuration, task table views in debugger and

© 2016 Renesas Electronics Corporation. All rights reserved. Page 9

WHY USE AN OPERATING SYSTEM?

An Operating System is software which manages the time of a microprocessor or microcontroller.

Ensures that the most important code runs first!

Allows Multithreading:

Do more than one thing at the same time.

Application is broken down into multiple threads each handling one aspect of your application

It’s like having multiple CPUs!

Provides valuable services to your application:

Time delays

Resource sharing

Inter-thread communication and synchronization

Page 10: DEVELOP AN RTOS- BASED APPLICATION IN LESS THAN 30 … · SYNERGY SSP INTEGRATION Fully integrated into e2 studio RTOS and middleware configuration, task table views in debugger and

© 2016 Renesas Electronics Corporation. All rights reserved. Page 10

WHY USE AN OPERATING SYSTEM? (CONT.)

Operating System vendors are usually able to provide a wealth of other modules required in the latest

applications. Tested and guaranteed saving many man hours of development time and cost.

TCP/IP

File systems

GUI

Audio/video drivers

USB etc.

Page 11: DEVELOP AN RTOS- BASED APPLICATION IN LESS THAN 30 … · SYNERGY SSP INTEGRATION Fully integrated into e2 studio RTOS and middleware configuration, task table views in debugger and

© 2016 Renesas Electronics Corporation. All rights reserved. Page 11

BENEFITS OF USING AN OPERATING SYSTEM

Allows the system to be more responsive to real-time events

Allows the work (application threads) to be prioritized

Simplifies system expansion

Adding low-priority threads generally does not change the responsiveness of higher priority threads!

Reduce development time

Allows the application to be distributed between programmers

Can simplify debugging

Documentation easier to maintain

Allows the application to take advantage of useful services from the Operating System

Services that you would want to provide to your application code

Page 12: DEVELOP AN RTOS- BASED APPLICATION IN LESS THAN 30 … · SYNERGY SSP INTEGRATION Fully integrated into e2 studio RTOS and middleware configuration, task table views in debugger and

© 2016 Renesas Electronics Corporation. All rights reserved. Page 12

DISADVANTAGES OF USING AN RTOS

Increased RAM footprint

Each thread requires separate stack

RTOS internal structures e.g. TCB (thread control block)

ThreadX RAM usage from 0.5 - 2K bytes

ROM footprint

RTOS functions

ThreadX FLASH usage from 2K bytes

Cost

Unless of course, you use Synergy,

when it is all included

Page 13: DEVELOP AN RTOS- BASED APPLICATION IN LESS THAN 30 … · SYNERGY SSP INTEGRATION Fully integrated into e2 studio RTOS and middleware configuration, task table views in debugger and

© 2016 Renesas Electronics Corporation. All rights reserved.

WHAT IS A THREAD/PROCESS/TASK?

Page 13

Page 14: DEVELOP AN RTOS- BASED APPLICATION IN LESS THAN 30 … · SYNERGY SSP INTEGRATION Fully integrated into e2 studio RTOS and middleware configuration, task table views in debugger and

© 2016 Renesas Electronics Corporation. All rights reserved. Page 14

WHAT IS A THREAD/PROCESS/TASK?

Process/Task

Independent executable program with its own

memory space

Multitasking: running several tasks/processes

“concurrently”

A Process can have multiple threads

Thread

Semi-independent program segment; multiple

threads can share the same memory space

Multithreading: running several threads

“concurrently”

Some RTOS’ use “task” to mean “thread”

Each thread has:

Its own stack space

A priority based on its importance

Thread design can be based on modular functional blocks

of the application, e.g.:

Video thread

Audio thread

Network stack

Motor control thread

Page 15: DEVELOP AN RTOS- BASED APPLICATION IN LESS THAN 30 … · SYNERGY SSP INTEGRATION Fully integrated into e2 studio RTOS and middleware configuration, task table views in debugger and

© 2016 Renesas Electronics Corporation. All rights reserved.

TYPICAL THREAD IMPLEMENTATION

Page 15

#include "tx_api.h"

ULONG my_thread_counter = 0;TX_THREAD my_thread;

main( ){

/* Enter the ThreadX kernel. */tx_kernel_enter( );

}

void tx_application_define(void *first_unused_memory){

/* Create my_thread! */tx_thread_create(

&my_thread, "My Thread",my_thread_entry, 0x1234, first_unused_memory, 1024,3, 3, TX_NO_TIME_SLICE, TX_AUTO_START);

}

Definition

void my_thread_entry(ULONG thread_input){

/* Enter into a forever loop. */while(1){

/* Increment thread counter. */my_thread_counter++;

/* Sleep for 1 tick. */tx_thread_sleep(1);

}}

Thread

Page 16: DEVELOP AN RTOS- BASED APPLICATION IN LESS THAN 30 … · SYNERGY SSP INTEGRATION Fully integrated into e2 studio RTOS and middleware configuration, task table views in debugger and

© 2016 Renesas Electronics Corporation. All rights reserved.

SPLITTING APPLICATIONS INTO THREADS

Page 16

thread 3

thread 4

Infinite loop

thread 1

thread 2

High Priority thread

Low Priority thread

Event Event

Each thread

Importance

thread

Page 17: DEVELOP AN RTOS- BASED APPLICATION IN LESS THAN 30 … · SYNERGY SSP INTEGRATION Fully integrated into e2 studio RTOS and middleware configuration, task table views in debugger and

© 2016 Renesas Electronics Corporation. All rights reserved.

PRE-EMPTIVE KERNEL

Page 17

Page 18: DEVELOP AN RTOS- BASED APPLICATION IN LESS THAN 30 … · SYNERGY SSP INTEGRATION Fully integrated into e2 studio RTOS and middleware configuration, task table views in debugger and

© 2016 Renesas Electronics Corporation. All rights reserved.

PRE-EMPTIVE KERNEL

Page 18

ISR

Low Priority thread (LPT)

High Priority thread (HPT)

ISR

ISR makes High Priority thread Readye.g. posts a semaphore

Interrupt OccursVector to ISR

ISRCompletes

(Switch to HP thread)

HP thread Completes(Switch back to LP

thread)

Page 19: DEVELOP AN RTOS- BASED APPLICATION IN LESS THAN 30 … · SYNERGY SSP INTEGRATION Fully integrated into e2 studio RTOS and middleware configuration, task table views in debugger and

© 2016 Renesas Electronics Corporation. All rights reserved. Page 19

TYPICAL RTOS FEATURES

An RTOS typically provides the following features

System initialisation

Thread control

Scheduling/Context switch

Inter-thread control/communications

Mutexes

Semaphores

Message queues

Event flags

Memory management

Timers

Interrupt control

tx (ID)

nx

gx

fx

ux

queue (Noun)

timer

mutex

semaphore

event flag group

block pool

byte pool

.

.

.

send (Verb)

receive

create

remove

delete

terminate

close

.

.

.

tx_queue_send

Typical RTOS API

Page 20: DEVELOP AN RTOS- BASED APPLICATION IN LESS THAN 30 … · SYNERGY SSP INTEGRATION Fully integrated into e2 studio RTOS and middleware configuration, task table views in debugger and

© 2016 Renesas Electronics Corporation. All rights reserved.

E2 STUDIO, SSP, THREADX & X-WARE

Page 20

Page 21: DEVELOP AN RTOS- BASED APPLICATION IN LESS THAN 30 … · SYNERGY SSP INTEGRATION Fully integrated into e2 studio RTOS and middleware configuration, task table views in debugger and

© 2016 Renesas Electronics Corporation. All rights reserved.

SYNERGY, THREADX & X-WARE

Page 21

ThreadX RTOS

Small memory footprint

Fast real-time response and

performance

NetX/NetX Duo

Dual IPv4/IPv6 TCP/IP stack

USBX

USB Host/Device/OTG

FileX

MS-DOS FAT file system for

embedded systems

GUIX Graphics toolkit for

embedded GUI development

TraceX RTOS and application event viewer

Analyze real-time system behavior

Page 22: DEVELOP AN RTOS- BASED APPLICATION IN LESS THAN 30 … · SYNERGY SSP INTEGRATION Fully integrated into e2 studio RTOS and middleware configuration, task table views in debugger and

© 2016 Renesas Electronics Corporation. All rights reserved. Page 22

SYNERGY SSP INTEGRATION

Fully integrated into e2 studio

RTOS and middleware configuration, task table views in debugger and extensive context switching / object

tracing with TraceX

Synergy Hardware Stack Monitor initialisation for each context switch

Removes the need to manually code ThreadX and X-Ware components by hand

Priority, stack size, Preemption-Threshold etc.

Possible to re-configure during project

Reduced learning curve for new engineers

In depth knowledge of the RTOS not

necessary to start development

A few clicks and the RTOS is up and running

Focus on application rather than middleware

configuration

Page 23: DEVELOP AN RTOS- BASED APPLICATION IN LESS THAN 30 … · SYNERGY SSP INTEGRATION Fully integrated into e2 studio RTOS and middleware configuration, task table views in debugger and

© 2016 Renesas Electronics Corporation. All rights reserved. Page 23

TRACEX

Analysis tool to examine system “events”

RTOS logs “events” in trace buffer in target memory

Events include RTOS services like “queue_send”, “queue_receive”

Also internal RTOS operations like “internal_suspend”

Upload Trace Buffer to host as a file

Using e2 studio function

TraceX reads file and converts to graphical representation

Shows all threads

Shows all logged events

Shows time-ticks

Shows context switches

Page 24: DEVELOP AN RTOS- BASED APPLICATION IN LESS THAN 30 … · SYNERGY SSP INTEGRATION Fully integrated into e2 studio RTOS and middleware configuration, task table views in debugger and

© 2016 Renesas Electronics Corporation. All rights reserved.

SUMMARY & CONCLUSIONS

Page 24

Page 25: DEVELOP AN RTOS- BASED APPLICATION IN LESS THAN 30 … · SYNERGY SSP INTEGRATION Fully integrated into e2 studio RTOS and middleware configuration, task table views in debugger and

© 2016 Renesas Electronics Corporation. All rights reserved. Page 25

SUMMARY & CONCLUSIONS

X-Ware Platform for Synergy

Full RTOS and Middleware functionality

Fully integrated with e2studio and Synergy

Fully supported by Renesas

ThreadX RTOS

Small, Fast, with Advanced Technology

Easy to use

e2 studio integration eases application building and debugging

TraceX System Event Trace

Powerful tool to show system behavior

e2 studio

Extensive ThreadX & X-Ware integration

Page 26: DEVELOP AN RTOS- BASED APPLICATION IN LESS THAN 30 … · SYNERGY SSP INTEGRATION Fully integrated into e2 studio RTOS and middleware configuration, task table views in debugger and

© 2016 Renesas Electronics Corporation. All rights reserved. Page 26

Thank you for your attention

Please complete the feedback form in your smartphone app