Embedded Real Time Software Development Week 1 Introduction

Embedded Real Time Software Development Week 1 Introduction ENTC-489 Embedded Real Time Software Development Week 1 - Introduction (Rev 2) 1

Today’s Agenda • • House Keeping Real Time Kernel Concepts Introduction to our development platform Preparation for first homework assignment ENTC-489 Embedded Real Time Software Development Week 1 - Introduction (Rev 2) 2

House Keeping • Instructor • Goals for this class • Expectations / Grading ENTC-489 Embedded Real Time Software Development Week 1 - Introduction (Rev 2) 3

Instructor • Mike Willey – BSEE Texas A&M ’ 78 – Second Aggie in family, first was Eugene Couch, BSME ‘ 1897 – 36 years designing embedded systems – Co-owner, CTO Paragon Innovations, Inc. – 30 years programming in C and using embedded kernels ENTC-489 Embedded Real Time Software Development Week 1 - Introduction (Rev 2) 4

Goals for this class • Develop skills that will enable you to get and keep a job designing embedded systems firmware – Demonstrate knowledge of the vocabulary of Embedded Kernels – Demonstrate an understanding of memory sharing, dynamic allocation/de-allocation, and stack usage in an embedded design – Demonstrate an ability to use binary semaphores, counting semaphores, and message queues – Demonstrate an ability to design a multi-tasking embedded application using diagrams and text – Demonstrate a knowledge of defensive programming techniques – Design and implement a practical embedded application with at least 5 tasks ENTC-489 Embedded Real Time Software Development Week 1 - Introduction (Rev 2) 5

Expectation / Support / Grading My expectation is that the software you write for this class will be the same quality that a professional engineering company would require of any technical contributor. Midterm Exam (Open Book) 25% Final Exam (Open Book) 25% Quizzes / Homework 25% 5 Task Application Project 25% Total 100% A 90 -100, B 80 -89, C 70 -79, D 60 -69, F < 60 ENTC-489 Embedded Real Time Software Development Week 1 - Introduction (Rev 2) 6

Expectations / Support / Grading (cont) • Software Application Grading – 55% Performs required functions – 5% No compiler warnings – 15% Proper use of highlighted techniques – 15% Design documentation / comments – 10% Conforms with Class Coding Standards – Bonus opportunities (must get full points for “Performs required functions”, max +10%) • 5% Use processor I/O registers directly rather than Tiva Ware calls • 5% Use of Doxygen to document program ENTC-489 Embedded Real Time Software Development Week 1 - Introduction (Rev 2) 7

Bonus Opportunities • Use Processor I/O registers rather than Tiva. Ware calls – Can use Tiva. Ware as a go-by, but DO NOT Xerox! – Keep in separate source/include files – May use Tiva. Ware “inc/*. h” but not “driverlib/*. h” • Use Doxygen – Every function created by you MUST have a Doxygen entry for description, parameters and return values – All #defines and globals must have a description – The descriptions must be “useful” to aid in understanding and use. ENTC-489 Embedded Real Time Software Development Week 1 - Introduction (Rev 2) 8

Expectations / Support / Grading (cont) • Class Support Site – http: //txwilley. com/entc-489 -ERTSD Contains my blog, instructions for setting up tools, handy resources, class coding standards, etc. • Software homework – CCS File->Export->General->Archive File • File name for Jane Smith, Assignment “Blinky” s 15_jsmith_blinky. zip • Supply on a flash drive to be returned following week or Upload to http: //txwilley. com/entc-489 -ERTSD – Requires registration on the web site Registration may take 24 -48 hours for approval ENTC-489 Embedded Real Time Software Development Week 1 - Introduction (Rev 2) 9

Real Time Kernel Concepts • Superloops • Foreground/Background Systems • Real-Time Kernels ENTC-489 Embedded Real Time Software Development Week 1 - Introduction (Rev 2) 10

Superloops Task 1 Task 2 Task 3 Task 4 ENTC-489 Embedded Real Time Software Development Week 1 - Introduction (Rev 2) 11

Superloops void main (void) { initialization_code(); while (1) { read_adc(); read_serial_command(); write_serial_results(); for (i=0; i < bigvalue; i++) { /* delay to synchronize read_adc() */ } } } ENTC-489 Embedded Real Time Software Development Week 1 - Introduction (Rev 2) 12

Superloops Pros • • Easy for very simple stuff No upfront cost Minimal training No extra memory for OS Cons • Difficult to catch external events • Complexity grows quickly • Timing is impossible to predict ENTC-489 Embedded Real Time Software Development Week 1 - Introduction (Rev 2) 13

Foreground/Background Systems ISR #1 Task 1 ISR #2 Task 2 #3 Task 4 ENTC-489 Embedded Real Time Software Development Week 1 - Introduction (Rev 2) 14

Foreground/Background Systems Background Foreground void main (void) { perform_initialization(); while (1) { read_adc(); read_serial_command(); write_serial_result(); wait_timer_flag(); clear_timer_flag(); } } void serial_isr(void) { clear_irq(); store_received_char(); } void timer_isr (void) { clear_irq(); set_timer_flag(); } ENTC-489 Embedded Real Time Software Development Week 1 - Introduction (Rev 2) 15

Foreground/Background Systems Pros • No upfront cost • Minimal training required • Single stack area for – Function nesting – Local variables – ISR nesting • No extra memory for OS • Minimal interrupt latency Cons • Difficult to ensure timing is met • All background code has same priority • If one function takes longer than expected, the whole system will suffer • Complexity increases as the number of background tasks increases ENTC-489 Embedded Real Time Software Development Week 1 - Introduction (Rev 2) 16

Operating System vs. Kernel Application File System GUI TCP/IP Kernel USB Bluetooth RS-232 Hardware An Operating System is a collection of software that provides services useful to Application code. A Kernel provides task scheduling and communication for the other Operating System components and the Application. ENTC-489 Embedded Real Time Software Development Week 1 - Introduction (Rev 2) 17

Real-Time • If a task must be completed within a given time, it is said to be a real-time task – In other words, the task has a deadline • There are two categories of real-time tasks – Hard Real-time tasks Missing the deadline results in a severe problem. For these tasks a late response is equivalent to an incorrect response – Soft Real-time tasks • Missing a deadline does not cause dire consequences ENTC-489 Embedded Real Time Software Development Week 1 - Introduction (Rev 2) 18

Determinism • Fast software is not necessarily real-time software • Determinism is a desirable quality in real-time software • Software is deterministic if it has a bounded response time to events ENTC-489 Embedded Real Time Software Development Week 1 - Introduction (Rev 2) 19

Real-Time Kernel • A real-time kernel is a framework for developing multi-task applications • The services provided by a real-time kernel can help an application meet its timing requirements • The primary service provided by any real-time kernel is task scheduling ENTC-489 Embedded Real Time Software Development Week 1 - Introduction (Rev 2) 20

Real-Time Kernel Pros • Simplifies complex systems • Creating time-deterministic software is more straight forward • Adding functionality has minimum impact on existing code • Very easy for multiple contributors to work in same code base Cons • Up front cost or port of open source code • Requires design prior to coding • Consumes extra memory ENTC-489 Embedded Real Time Software Development Week 1 - Introduction (Rev 2) 21

What is a task? • A task is a simple program that thinks it has the CPU all to itself. • A task will have a priority, based on its importance Variables Arrays Structures CPU Registers Task (Priority) I/O Devices Stack (RAM) (Optional) ENTC-489 Embedded Real Time Software Development Week 1 - Introduction (Rev 2) 22

Tasks in a Kernel-Based System High Priority Task Importance Task Each Task Event Task Low Priority Task Infinite Loop Task ENTC-489 Embedded Real Time Software Development Week 1 - Introduction (Rev 2) 23

Kernel Based System Tasks ISRs void read_ADC_task( void ){ while (1) { wait for conversion time; start A/D conversion; wait for signal from ISR; store_ADC_value(); } } void timer_irq (void) { clear interrupt; signal conversion time; } void read_serial_task (void) { while (1) { wait for character; if (not end of line) { put character in buffer; } else { process command; clear buffer; } } } void adc_irq (void) { clear interrupt; signal conversion complete; } void serial_irq (void) { clear interrupts; signal character ready; } ENTC-489 Embedded Real Time Software Development Week 1 - Introduction (Rev 2) 24

Real Time Kernel Types • A cooperative kernel (non-preemptive) relies on each task to relinquish the use of the CPU on a regular basis • A preemptive kernel evaluates the highest priority task when returning from interrupt routines and resumes the highest priority task, rather than the one which was interrupted ENTC-489 Embedded Real Time Software Development Week 1 - Introduction (Rev 2) 25

Cooperative Kernels Via a kernel call, the ISR makes the high priority task ready Interrupt occurs ISR ISR completes High-priority task Low-priority task The low-priority task completes and the kernel switches to the high-priority task Time ENTC-489 Embedded Real Time Software Development Week 1 - Introduction (Rev 2) 26

Preemptive Kernels Via a kernel call, the ISR makes the high priority task ready Interrupt occurs ISR ISR completes and the kernel switches to the high-priority task High-priority task The kernel switches to the low-priority task Low-priority task Time ENTC-489 Embedded Real Time Software Development Week 1 - Introduction (Rev 2) 27

Task States ENTC-489 Embedded Real Time Software Development Week 1 - Introduction (Rev 2) 28

BREAK ENTC-489 Embedded Real Time Software Development Week 1 - Introduction (Rev 2) 29

Intro to Tiva Development Tiva T 4 C 123 G Launch Pad is REQUIRED Sensor Hub Booster Pack is REQUIRED Code Composer Studio 6 is REQUIRED Install the tools on your PC txwilley/ENTC-489 -ERTSD and go to the “Getting Started” tab • Installation is time consuming, start early • First homework assignment will take some time, order you boards ASAP • • ENTC-489 Embedded Real Time Software Development Week 1 - Introduction (Rev 2) 30

TMC 123 G Launch Pad • Debug USB on top • Power switch right is “on” for debug • RGB Led • 2 Push Buttons • TM 4 C 123 GH 6 PM CPU • UART 0 to Debug USB Port ENTC-489 Embedded Real Time Software Development Week 1 - Introduction (Rev 2) 31

Sensor Hub Booster Pack • MPU 9150 9 Axis Motion Sensor • TMP 006 Thermopile Sensor • SHT 21 Humidity Sensor • BMP 180 Pressure Sensor • ISL 29023 Light Sensor • User LED ENTC-489 Embedded Real Time Software Development Week 1 - Introduction (Rev 2) 32

TM 4 C 123 GH 6 PM CPU ENTC-489 Embedded Real Time Software Development Week 1 - Introduction (Rev 2) 33

System Control • Power on, runs on internal 16 MHz osc, PLL off, /16: 1 MHz instruction cycle • We will run at 50 MHz using the external 16 MHz crystal ENTC-489 Embedded Real Time Software Development Week 1 - Introduction (Rev 2) 34

Changing the Clock • Registers: RSS 2 ENTC-489 Embedded Real Time Software Development Week 1 - Introduction (Rev 2) 35

Changing the Clock • #include “inc/hw_types. h” – HWREG(), HWREGH(), HWREGBITW(), HWREGBITH(), HWREGBITB() • Using Tiva. Ware – #include “driverlib/sysctl. h” – Sys. Ctl. Clock. Set(); ENTC-489 Embedded Real Time Software Development Week 1 - Introduction (Rev 2) 36

Timing on the TM 4 C 123 G • In this class we DO NOT USE TIMING LOOPS (except when adjusting the system clock, making timing loops the only reasonable method of introducing a delay) • ARM Devices provide a special periodic timer, SYSTICK specifically to provide a regular timer tick. – Point interrupt vector to FAULT_SYSTICK (this can be done in the *_startup_css. c file) – – Set the number of clock ticks between interrupts in the NVIC_ST_RELOAD register Enable the interrupts Enable the systick device Using Tiva. Ware • • • Sys. Tick. Int. Register(); /* optional */ Sys. Tick. Period. Set(); Int. Master. Enable(); Sys. Tick. Int. Enable(); Sys. Tick. Enable(); – DANGER, WILL ROBINSON!!! • use Int. Master. Disable() instead of ROM_Int. Disable(FAULT_SYSTICK) to disable interrupts while manipulating variables altered by your SYSTICK interrupt function. The later has the side effect of reloading the SYSTICK counter with the initial value. ENTC-489 Embedded Real Time Software Development Week 1 - Introduction (Rev 2) 37

GPIO Pins on the TM 4 C 123 G • Steps to use a GPIO – Enable the clock to the GPIO port module (RCGC 2) – Set the pad type (GPIO_O_DR 2 R, GPIO_O_DR 4 R, GIPO_O_DR 8 R, GPIO_O_SLR, GPIO_O_ODR, GPIO_O_PUR, GPIO_O_PDR, GPIO_O_DEN, GPIO_O_DIR, GPIO_O_AFSEL) • Using Tiva. Ware – Sys. Ctl. Peripheral. Enable(); – GPIOPin. Type. GPIOOutput(); GPIOPin. Type. GPIOInput(); ENTC-489 Embedded Real Time Software Development Week 1 - Introduction (Rev 2) 38

Homework • Start with Blank. Project (No Operating System) from txwilley. com/entc-489 -ERTSD • Create a program that will – Blink the RGB LED in Blue (no red or green light) – Blink must be at 1 Hz, that is 1 time per second the LED must turn on and off – Use a 50% duty cycle – Processor must run at 50 MHz or faster – The functionality test for your grade will be • Compiling on instructor’s workstation • Running on instructor’s reference platform • Required Techniques – Must use a timer interrupt to achieve time delays (no timing loops) ENTC-489 Embedded Real Time Software Development Week 1 - Introduction (Rev 2) 39

Closed Book Quiz Next Week • • Real-Time Software and Kernel Vocabulary Coding Standards Compliance Task State Diagram Superloop/Superloop with Interrupt/Kernel comparison ENTC-489 Embedded Real Time Software Development Week 1 - Introduction (Rev 2) 40
- Slides: 40