Lab. 2 Overview Move the tasks you developed in Lab. 1 into the more controllable TTCOS operating system Manual control of RC car.

Slides:



Advertisements
Similar presentations
Lab. 2 Overview. Lab. 2 and Assignment 3 Many Lab. 2 and Assignment 3 tasks involve “downloading” provided code, compiling and linking into a project.
Advertisements

Microprocessor or Microcontroller Not just a case of “you say tomarto and I say tomayto” M. Smith, ECE University of Calgary, Canada.
Blackfin BF533 EZ-KIT Control The O in I/O Activating a FLASH memory “output line” Part 2.
Lab3 -- Lab 4 Design and implementation details on the way to a valid SPI-LCD interface driver.
Embedded System Timers Details of independent timers build into the Blackfin Assignment 2-- Watchdog Timer can be used to prevent the OS system from locking.
Lab 3 Details. Lab 3 Develop a bio-feedback system based on a PWM (pulse width modulated) thermal sensor Use temperature setting to control the delays.
Boot Issues Processor comparison TigerSHARC multi-processor system Blackfin single-core.
6/2/2015 Concept of Test Driven Development applied to Embedded Systems M. Smith University of Calgary, Canada 1 Automated Testing Environment Concepts.
Thermal arm-wrestling Design of a video game using two programmable flags (PF) interrupts Tutorial on handling 2 Hardware interrupts from an external device.
Review of Blackfin Syntax Moves and Adds 1) What we already know and have to remember to apply 2) What we need to learn.
Lab. 2 – More details – Tasks 4 to 6 1. What concepts are you expected to understand after the Lab. 2 is finished? 2. How do you demonstrate that you have.
Microprocessor or Microcontroller Not just a case of “you say tomarto and I say tomayto” M. Smith, ECE University of Calgary, Canada.
A Play Core Timer Interrupts Acted by the Human Microcontroller Ensemble from ENCM415.
Core Timer Code Development How you could have done the Take- Home Quiz using a test driven development (TDD) approach.
A look at interrupts What are interrupts and why are they needed in an embedded system? Equally as important – how are these ideas handled on the Blackfin.
Lab. 2 Overview 1. What concepts are you expected to understand after the Lab. 2 is finished? 2. How do you demonstrate that you have that knowledge?
Timers and Timing Signals Tutorial. 6/18/2015 Timer Control Copyright M. Smith, ECE, University of Calgary, Canada 2 / 31 Temperature Sensor -- Lab 3.
A look at interrupts What are interrupts and why are they needed.
Microprocessor or Microcontroller Not just a case of “you say tomarto and I say tomayto” M. Smith, ECE University of Calgary, Canada.
Getting the O in I/O to work on a typical microcontroller Ideas of how to send output signals to the radio controlled car. The theory behind the LED controller.
Getting the O in I/O to work on a typical microcontroller Activating a FLASH memory “output line” Part 1 Main part of Laboratory 1 Also needed for “voice.
Tutorial Essentially all the Blackfin instruction you need for all of ENCM511. The instructions are easy. Its knowing when to use them that is the difficult.
EEE527 Embedded Systems Lecture 8: Practical Interrupts Ian McCrumRoom 5B18, Tel: voice mail on 6 th ring Web site:
HD44780 LCD programming From the Hardware Side
1 Advanced Computer Programming Concurrency Multithreaded Programs Copyright © Texas Education Agency, 2013.
Peripherals and their Control An overview of industrially available “peripheral devices” that use “pulse-width modulation” for information passing. Review.
A Play Core Timer Interrupts Acted by the Human Microcontroller Ensemble from ENCM511.
Understanding the TigerSHARC ALU pipeline Determining the speed of one stage of IIR filter – Part 2 Understanding the pipeline.
Lab. 4 Demonstrating and understanding multi-processor boot TigerSHARC multi-processor system.
Moving Arrays -- 1 Completion of ideas needed for a general and complete program Final concepts needed for Final Review for Final – Loop efficiency.
Blackfin Array Handling Part 1 Making an array of Zeros void MakeZeroASM(int foo[ ], int N);
Lab. 2 Overview. Echo Switches to LED Lab1 Task 7 12/4/2015 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 2 / 28.
Operating Systems CSE 411 CPU Management Sept Lecture 10 Instructor: Bhuvan Urgaonkar.
12/14/2015 Concept of Test Driven Development applied to Embedded Systems M. Smith University of Calgary, Canada 1 Automated Testing Environment Concepts.
The right and wrong ways for constructing tasks for the Labs and Assignment.
Handling multiple input signals Version #2 – co-operative scheduler Version #3 – pre-emptive scheduler.
Building a simple loop using Blackfin assembly code If you can handle the while-loop correctly in assembly code on any processor, then most of the other.
Lab. 1 – GPIO Pin control Using information ENEL353 and ENCM369 text books combined with Blackfin DATA manual.
A Play Core Timer Interrupts Acted by the Human Microcontroller Ensemble from ENCM415.
Assignment 4 / Lab. 3 Convert C++ ISR to ASM AND GET IT TO WORK Doing Assignment 4 / Lab. 3 the Test Driven Development way.
“Lab. 5” – Updating Lab. 3 to use DMA Test we understand DMA by using some simple memory to memory DMA Make life more interesting, since hardware is involved,
Developing Tasks to use with a co-operative scheduler Ideas for Assignment 2 Lab. 2, 3 and 4 Review for Midterm on Lab. 2 Ideas of defects, errors and.
Lab3 -- Lab 4 Design and implementation details on the way to a valid SPI-LCD interface driver.
Lab. 2 Overview – Earlier Tasks Prelaboratory T1, T3, T4 and T5
Interrupts, Tasks and Timers
Lab. 2 Overview.
A Play Core Timer Interrupts
Thermal arm-wrestling
Handling Arrays Completion of ideas needed for a general and complete program Final concepts needed for Final.
TigerSHARC processor and evaluation board
Lab. 2 – More details – Later tasks
Moving Arrays -- 2 Completion of ideas needed for a general and complete program Final concepts needed for Final DMA.
Thermal arm-wrestling
A Play Lab. 2 Task 8 Core Timer Interrupts
Single Value Processing Multi-Threaded Process
Handling Arrays Completion of ideas needed for a general and complete program Final concepts needed for Final.
HD44780 LCD programming From the Hardware Side
General purpose timers
Thermal arm-wrestling
Concept of TDD Test Driven Development
Explaining issues with DCremoval( )
Lab. 4 – Part 2 Demonstrating and understanding multi-processor boot
Lab. 1 – GPIO Pin control Using information ENEL353 and ENCM369 text books combined with Blackfin DATA manual.
Independent timers build into the processor Basis for Lab. 2
Handling Arrays Completion of ideas needed for a general and complete program Final concepts needed for Final.
Independent timers build into the processor
Lab. 2 Overview Move the tasks you developed in Lab. 1 into the more controllable TTCOS operating system.
Thermal arm-wrestling
Working with the Compute Block
Blackfin Syntax Moves and Adds
Presentation transcript:

Lab. 2 Overview Move the tasks you developed in Lab. 1 into the more controllable TTCOS operating system Manual control of RC car

Lab 1 Task 4A Uncontrolled switch copy 11/4/2015 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 2 / 28

How would you handle a more complex set of embedded tests Echo switches 1 and 2 in LED’s 1 and 2 Flash LED 3 every 2 seconds Flash LED 5 every ½ second Flash LED 6 every ¼ second Do something else for 4 seconds, then something else for 12 and then something else for 5 – Assignment 1 Etc 11/4/2015 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 3 / 28

If we used the “super-loop idea” int main( ) { InitLED( ); while (1) { if CorrectTIme(time1) then TaskFlashLED3( ); I if CorrectTIme(time 2) then TaskFlashLED3( ); value = ReadSwitches( ); WriteLED(value >> 8); } Actual code on next slide 11/4/2015 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 4 / 28 QUESTONS TO ASNWER 1.We need the processor to switch LED every 2 seconds 2.How do you handle the timing? 3.How can you get the processor to go to sleep to save battery power at other times?

Super loop – Lab 1 Task 4B 11/4/2015 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 5 / 28

From Pont’s book Control of an aeroplane 11/4/2015 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 6 / 28

Need a systematic way of programming such a system These ideas and the following slides are based on the book by M. J. Pont – “Patterns for Time- Triggered Embedded Systems” Down load a free copy from The code in the book was for the 8051 processor and I have modified the code to run on Blackfin Processor 11/4/2015 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 7 / 28

Scheduler The idea is to make a list of all the tasks that you need to make the embedded system to work Then you use a “scheduler” to cause the tasks to run Pre-emptive scheduler -- discussed Wednesday Tasks run as random events Co-operative Scheduler -- discussed Wednesday Tasks run at predictable intervals 11/4/2015 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 8 / 28

Lab. 2 Task 2 – Download TTCOS and validate the install Check the web pages for install details TTCOS511.h file all the prototypes for the TTCOS functions TTCOS511.dlb the TTCOS library for the Blackfin Example_TTCOSmain.c Use this as a template for all TTCOS programs in Labs, assignment and quizzes and exams) 11/4/2015 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 9 / 28

Example_TTCOS main.cpp 11/4/2015 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 10 / 28 The only lines of code that ever change FOR OTHER LAB 2 parts replace these lines

The total code for Lab. 2 Task 2 11/4/2015 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 11 / 28 First task – name -- Task_SayGreeting Runs with no delay Runs only once Second task – name -- Task_SayHiOccasionally Runs with no delay Runs every 5 seconds, and then allows processor to sleep

Lab. 2 – Task 3: Reuse Lab. 1 Functions within TTCOS 11/4/2015 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 12 / 28 Step 1 in process Recognize the tasks that are needed 3 RUN_ONCE 2 PERIODIC

Step 1 – Add TTCOS task to initialize system One TTCOS task activates many others 11/4/2015 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 13 / 28

So this is the code we need to replace – Lab 1 Task 4B 11/4/2015 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 14 / 28

Lets add the flashing LED tasks For predictability – each task runs in its own time slot 1 / apart 11/4/2015 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 15 / 28

Uncoupling actions -- Use two task to do copy of switches to LEDs Later will have a task that copies switch values to RC car 11/4/2015 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 16 / 28

Final task is more difficult In Lab 1 Task 4B - Controlled echo (copy) of switches to LED we simply had DO CheckSwitch4PressedAndReleased( ) stop the loop.Lab 1 Task 4B - Controlled echo (copy) of switches to LED 11/4/2015 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 17 / 28

We can't stop the operating system -- so we much use a KILL task based on the old CheckSwitch4 task 11/4/2015 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 18 / 28

New switch 4 task – calls a kill task Possible error messages from ‘task race’ 11/4/2015 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 19 / 28

Halloween – so we bring the killed tasks back to life 11/4/2015 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 20 / 28

Lab 2 Task 4 -- Make PF lines INPUT and OUPUT at same time 11/4/2015 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 21 / 28

ChristineTask -- Step 1 11/4/2015 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 22 / 28

Christine Task – step 2 Control the wheels to turn the car left and right Use AND and OR instructions, otherwise you will destroy the input switch values 11/4/2015 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 23 / 28

ChristineTask( ) – Step 3 Run these task every 1/ 4 second – no more often – the car will not respond any faster 11/4/2015 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 24 / 28

Major milestone (B- on Lab) 11/4/2015 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 25 / 28

Task 5 -- totally automated 11/4/2015 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 26 / 28

What does code look like on pre- emptive scheduler? int main( ) { Setup LED, Switches Set Up interrupts( ) and start them while (1 ) { // Lab. 1 Task 7 Read Switches and Write to LED; } Timer1_ISR( ) { // Only happens when Timer1 alarm rings Flash LED 3( ); } Timer2_ISR( ) { // Only happens when Timer1 alarm rings Flash LED 4( ); } 11/4/2015 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 27 / 28 Problem is “what happens if both alarms ring at same time (with larger ISR code) Interrupt Service Routine “Subroutine activated by hardware” not by “code” -- unpredictable

ENCM Real time course Pre-emptive scheduler Lab. 2 problems Task to Flash LED 3 every 2 seconds Task to Flash LED 4 every one second Both tasks want to use same resource What happens if one task starts to save something and gets interrupted? 11/4/2015 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 28 / 28

We think we can solve this problem using “locks” and “semaphores” #define UNLOCKED 0 #define LOCKED 1 Bit lock = UNLOCKED ;// Global Lock void LED3_Task( ) while (lock == LOCKED) /* Wait for lock to be released */ ; lock = LOCKED; // Indicate using LEDs WriteLEDASM(LED3_ON); lock = UNLOCKED; } void LED4_Task( ) while (lock == LOCKED) /* Wait for lock to be released */ ; lock = LOCKED; // Indicate using LEDs WriteLEDASM(LED4_ON); lock = UNLOCKED; } 11/4/2015 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 29 / 28

Solve this problem using “lock” #define UNLOCKED 0 #define LOCKED 1 Bit lock = UNLOCKED ;// Global Lock void LED3_Task( ) while (lock == LOCKED) /* Wait for lock to be released */ ; lock = LOCKED; // Indicate using LEDs WriteLEDASM(LED3_ON); lock = UNLOCKED; } void LED4_Task( ) while (lock == LOCKED) /* Wait for lock to be released */ ; lock = LOCKED; // Indicate using LEDs WriteLEDASM(LED4_ON); lock = UNLOCKED; } 11/4/2015 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 30 / 28 Suppose LED3_Task gets switched out here and LED4_Task runs LED4_Task thinks the resource is free to use

11/4/2015 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 31 / 28

Need to know in future lectures Need to understand “interrupts” on the Blackfin Need to understand how the “core timer” and “watch dog timer” work and are programmed. Useful to understand how the scheduler works – but not necessary unless we plan to change it 11/4/2015 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 32 / 28