DEVELOP AN RTOS- BASED APPLICATION IN LESS THAN 30 MINUTES Renesas Synergy Engineering Conference LAKE GARDA 7-8 April 2016 2016 Renesas Electronics Corporation. All rights reserved.
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 2016 Renesas Electronics Corporation. All rights reserved. Page 2
PRODUCTS WITHOUT AN OPERATING SYSTEM 2016 Renesas Electronics Corporation. All rights reserved. Page 3
PRODUCTS WITHOUT AN OPERATING SYSTEM Foreground #2 ISR #2 Foreground #1 ISR #1 ISR #1 Background thread #1 thread #2 thread #3 Infinite loop Time 2016 Renesas Electronics Corporation. All rights reserved. Page 4
TYPICAL IMPLEMENTATION WITHOUT AN RTOS /* 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; } 2016 Renesas Electronics Corporation. All rights reserved. Page 5
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 Affected by if, for, while Poll to see if ISR occurred ISR #1 thread #1 thread #2 thread #3 thread #4 2016 Renesas Electronics Corporation. All rights reserved. Page 6
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 #1 thread #2 thread #3 thread #4 Infinite loop 2016 Renesas Electronics Corporation. All rights reserved. Page 7
WHY USE AN OPERATING SYSTEM? 2016 Renesas Electronics Corporation. All rights reserved. Page 8
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 2016 Renesas Electronics Corporation. All rights reserved. Page 9
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. 2016 Renesas Electronics Corporation. All rights reserved. Page 10
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 2016 Renesas Electronics Corporation. All rights reserved. Page 11
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 2016 Renesas Electronics Corporation. All rights reserved. Page 12
WHAT IS A THREAD/PROCESS/TASK? 2016 Renesas Electronics Corporation. All rights reserved. Page 13
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 2016 Renesas Electronics Corporation. All rights reserved. Page 14
TYPICAL THREAD IMPLEMENTATION #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); } 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 Definition 2016 Renesas Electronics Corporation. All rights reserved. Page 15
SPLITTING APPLICATIONS INTO THREADS High Priority thread thread 1 Each thread thread 2 Importance Event Event thread 3 thread thread 4 Infinite loop Low Priority thread 2016 Renesas Electronics Corporation. All rights reserved. Page 16
PRE-EMPTIVE KERNEL 2016 Renesas Electronics Corporation. All rights reserved. Page 17
PRE-EMPTIVE KERNEL ISR makes High Priority thread Ready e.g. posts a semaphore ISR Interrupt Occurs Vector to ISR ISR ISR Completes (Switch to HP thread) High Priority thread (HPT) Low Priority thread (LPT) HP thread Completes (Switch back to LP thread) 2016 Renesas Electronics Corporation. All rights reserved. Page 18
TYPICAL RTOS FEATURES tx_queue_send 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 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... Timers Interrupt control Typical RTOS API 2016 Renesas Electronics Corporation. All rights reserved. Page 19
E 2 STUDIO, SSP, THREADX & X-WARE 2016 Renesas Electronics Corporation. All rights reserved. Page 20
SYNERGY, THREADX & X-WARE 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 2016 Renesas Electronics Corporation. All rights reserved. Page 21
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 2016 Renesas Electronics Corporation. All rights reserved. Page 22
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 2016 Renesas Electronics Corporation. All rights reserved. Page 23
SUMMARY & CONCLUSIONS 2016 Renesas Electronics Corporation. All rights reserved. Page 24
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 2016 Renesas Electronics Corporation. All rights reserved. Page 25
Thank you for your attention Please complete the feedback form in your smartphone app 2016 Renesas Electronics Corporation. All rights reserved. Page 26