Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Lab. 2 Overview Move the tasks you developed in Lab. 1 into the more controllable TTCOS operating system Manual control of RC car."— Presentation transcript:

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

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

3 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

4 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?

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

6 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

7 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 www.tte-systems.com/downloads/pttes_0408a.pdf www.tte-systems.com/downloads/pttes_0408a.pdf 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

8 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

9 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

10 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

11 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

12 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

13 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

14 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

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

16 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

17 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

18 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

19 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

20 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

21 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

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

23 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

24 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

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

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

27 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

28 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

29 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

30 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

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

32 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


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

Similar presentations


Ads by Google