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.

Similar presentations


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

1 Lab. 2 Overview Move the tasks you developed in Lab. 1 into the more controllable TTCOS operating system

2 Lab. 2 – Task 1 Echo Switches to LED (Lab1 Task 7)
4/18/2019 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

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 4 every 1 second Flash LED 5 every ½ second Flash LED 6 every ¼ second Etc etc 4/18/2019 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

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

5 From Pont’s book Control of an aeroplane
4/18/2019 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

6 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 4/18/2019 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

7 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 Friday Tasks run as random events Co-operative Scheduler -- discussed Friday Tasks run at predictable intervals 4/18/2019 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

8 Lab. 2 Task 2 – Download TTOS 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) 4/18/2019 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

9 The only lines of code that ever change
4/18/2019 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

10 The total code for Lab. 2 Task 2
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 4/18/2019 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

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

12 Can re-use of Lab. 1 Init functions as they have the form (prototype) void FooBar(void)
4/18/2019 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

13 We need a RUN ONCE TASK to clear the LEDs
We need a periodic task void Task_ReadSwitches (void) that gets the swiitch positions and stores the answer in a “shared variable” switch_result We need another periodic task void Task_WriteLED(void) that gets the value from the shared variable switch_result and displays it 4/18/2019 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

14 Rest of the code for Lab. 2 Task 3
4/18/2019 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

15 ZOO Christmas Challenge
4/18/2019 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

16 Lab. 1 Task 4 4/18/2019 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

17 Lab 2 Task 5 – Add one line of code and a VDSP object file (.doj)
Task 5 – Drive the car (manually) using switches 4/18/2019 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

18 Lab. 2 Task 6 – Use Lab. 1 Task 8 code to drive car using “stored values”
4/18/2019 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

19 ENCM Real time course Pre-emptive scheduler
Previous classes have used Analog Devices VDK Kernel which is a 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? 4/18/2019 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

20 What does code look like on pre-emptive scheduler?
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 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( ); } 4/18/2019 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

21 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? 4/18/2019 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

22 We think we can solve this problem using “locks” and “semaphores”
#define UNLOCKED 0 #define LOCKED 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 */ ; WriteLEDASM(LED4_ON); 4/18/2019 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

23 Solve this problem using “lock”
#define UNLOCKED 0 #define LOCKED 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( ) WriteLEDASM(LED4_ON); Suppose LED3_Task gets switched out here and LED4_Task runs LED4_Task thinks the resource is free to use 4/18/2019 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

24 4/18/2019 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

25 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 4/18/2019 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada


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

Similar presentations


Ads by Google