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.

Slides:



Advertisements
Similar presentations
Copyright © 2000, Daniel W. Lewis. All Rights Reserved. CHAPTER 8 SCHEDULING.
Advertisements

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.
Microprocessor or Microcontroller Not just a case of “you say tomarto and I say tomayto” M. Smith, ECE University of Calgary, Canada.
Lab3 -- Lab 4 Design and implementation details on the way to a valid SPI-LCD interface driver.
1 CMSC421: Principles of Operating Systems Nilanjan Banerjee Principles of Operating Systems Acknowledgments: Some of the slides are adapted from Prof.
Boot Issues Processor comparison TigerSHARC multi-processor system Blackfin single-core.
6/2/2015 Labs in ENCM415. Laboratory 2 PF control, Copyright M. Smith, ECE, University of Calgary, Canada 1 Temperature Sensor Laboratory 2 Part 2 – Developing.
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.
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?
1 CS318 Project #3 Preemptive Kernel. 2 Continuing from Project 2 Project 2 involved: Context Switch Stack Manipulation Saving State Moving between threads,
Timers and Timing Signals Tutorial. 6/18/2015 Timer Control Copyright M. Smith, ECE, University of Calgary, Canada 2 / 31 Temperature Sensor -- Lab 3.
Microprocessor or Microcontroller Not just a case of “you say tomarto and I say tomayto” M. Smith, ECE University of Calgary, Canada.
7/14/20151 Introduction toVisual DSP Kernel VDK for Multi-threaded environment ENCM491 – Real Time (in 1 hour) M. Smith, Electrical and Computer Engineering,
Microprocessor or Microcontroller Not just a case of “you say tomarto and I say tomayto” M. Smith, ECE University of Calgary, Canada.
Operating Systems CSE 411 CPU Management Sept Lecture 11 Instructor: Bhuvan Urgaonkar.
Introduction to Embedded Systems
Peripherals and their Control An overview of industrially available “peripheral devices” that use “pulse-width modulation” for information passing. Review.
Nachos Phase 1 Code -Hints and Comments
Introduction to Embedded Systems Rabie A. Ramadan 6.
Operating Systems. Definition An operating system is a collection of programs that manage the resources of the system, and provides a interface between.
A Play Core Timer Interrupts Acted by the Human Microcontroller Ensemble from ENCM511.
Lab. 2 Overview Move the tasks you developed in Lab. 1 into the more controllable TTCOS operating system Manual control of RC car.
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.
Multi-threaded projects Services and Drivers Alternate ways of doing Labs 1, 2, 3 and 4.
1 Computer Systems II Introduction to Processes. 2 First Two Major Computer System Evolution Steps Led to the idea of multiprogramming (multiple concurrent.
Discussion Week 2 TA: Kyle Dewey. Overview Concurrency Process level Thread level MIPS - switch.s Project #1.
Operating Systems CSE 411 CPU Management Sept Lecture 10 Instructor: Bhuvan Urgaonkar.
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.
Operating Systems CMPSC 473 Signals, Introduction to mutual exclusion September 28, Lecture 9 Instructor: Bhuvan Urgaonkar.
Lab. 1 – GPIO Pin control Using information ENEL353 and ENCM369 text books combined with Blackfin DATA manual.
Slides created by: Professor Ian G. Harris Operating Systems  Allow the processor to perform several tasks at virtually the same time Ex. Web Controlled.
Implementing Lock. From the Previous Lecture  The “too much milk” example shows that writing concurrent programs directly with load and store instructions.
Embedded Programming and Robotics Lesson 11 Arduino Interrupts 1.
A Play Core Timer Interrupts Acted by the Human Microcontroller Ensemble from ENCM415.
“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,
Implementing Mutual Exclusion Andy Wang Operating Systems COP 4610 / CGS 5765.
An operating system for a large-scale computer that is used by many people at once is a very complex system. It contains many millions of lines of instructions.
Lab3 -- Lab 4 Design and implementation details on the way to a valid SPI-LCD interface driver.
CS 6560: Operating Systems Design
CS703 – Advanced Operating Systems
Lab. 2 Overview – Earlier Tasks Prelaboratory T1, T3, T4 and T5
Lab. 2 Overview.
A Play Core Timer Interrupts
Embedded C for 8051: Primer for CompEng 3150
TigerSHARC processor and evaluation board
Lab. 2 – More details – Later tasks
Moving Arrays -- 1 Completion of ideas needed for a general and complete program Final concepts needed for Final Review for Final – Loop efficiency.
Moving Arrays -- 2 Completion of ideas needed for a general and complete program Final concepts needed for Final DMA.
A Play Lab. 2 Task 8 Core Timer Interrupts
CSE 451 Autumn 2003 Section 3 October 16.
Single Value Processing Multi-Threaded Process
Moving Arrays -- 2 Completion of ideas needed for a general and complete program Final concepts needed for Final DMA.
Implementing Mutual Exclusion
EE 472 – Embedded Systems Dr. Shwetak Patel.
Lab. 4 – Part 2 Demonstrating and understanding multi-processor boot
CSE 451: Operating Systems Autumn 2001 Lecture 2 Architectural Support for Operating Systems Brian Bershad 310 Sieg Hall 1.
Lab. 1 – GPIO Pin control Using information ENEL353 and ENCM369 text books combined with Blackfin DATA manual.
Implementing Mutual Exclusion
Independent timers build into the processor
Lab. 2 Overview Move the tasks you developed in Lab. 1 into the more controllable TTCOS operating system.
CSE 153 Design of Operating Systems Winter 2019
Blackfin Syntax Moves and Adds
Blackfin Syntax Stores, Jumps, Calls and Conditional Jumps
Presentation transcript:

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

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 12/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) { TaskFlashLED3( ); TaskFlashLED2( ); value = ReadSwitches( ); WriteLED(value >> 8); } 12/4/2015 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 4 / 28 Questions 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?

Auto control of an aeroplane Lists the tasks 12/4/2015 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 5 / 28

From Pont’s book 12/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 12/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 Co-operative Scheduler 12/4/2015 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 8 / 28

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

ENCM Real time course Previous classes have used Analog Devices VDK Kernel which has 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 Memory that controls LED Represents something ‘important’ Can’t have 2 things writing to same device Operating systems class 12/4/2015 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 10 / 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; } 12/4/2015 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 11 / 28

Pre-emptive scheduler What if task gets switched out at ‘critical time’? 12/4/2015 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 12 / 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; } 12/4/2015 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 13 / 28 Suppose LED3_Task gets switched out here and LED4_Task runs LED4_Task thinks the resource is free to use

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

Scheduler code looks like this int main( ) { Init_Scheduler( ); Add_Task(LED3_Task, 0, 2000); Add_Task(LED4_Task, 0, 1000); StartScheduler( ); while (1) { time = ReadCycleCounter( ); Dispatch_Tasks(time); } } Dispatch_Tasks(time) { if time to run LED3_Task then run LED3_Task( ); if time to run LED4_Task then run LED4_Task ( ); } 12/4/2015TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 15 / 28

Power saving code int main( ) { Init_Scheduler( ); Add_Task(LED3_Task, 0, 2000); Add_Task(LED4_Task, 0, 1000); StartScheduler( ); -- this activates a “timer” which causes an interrupt while (1) { GoToSleepUntil_InterruptOccurs( ); time = ReadCycleCounter( ); Dispatch_Tasks(time); } } Dispatch_Tasks(time) { if time to run LED3_Task then run LED3_Task( ); if time to run LED4_Task then run LED4_Task ( ); } 12/4/2015TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 16 / 28

Lab. 2 I have found a “co-operative scheduler” that works for the 8051 using the 8051 timer interrupts. Lets suppose it could be made to work for Blackfin The scheduler is easy to use and the tasks are easy to write (using your existing Lab. 1 code and assignment code) 12/4/2015 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 17 / 28

Task are easy to develop void LED3_Task( ) Uses Read LED( ) and WriteLED( ) from Lab. 1 if LED3 is on turn it off if LED3 is off turn it on } void LED4_Task( ) Uses Read LED( ) and WriteLED( ) from Lab. 1 if LED4 is on turn it off if LED4 is off turn it on } 12/4/2015 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 18 / 28

Scheduler functions TTCOS_AddTask(TaskName, Delay, Period) Thus TTCOS_AddTask (Led3, 0, 1000); Means “run” LED3 task with “no delay” the first time it is run, and then run it again after “1000 clock-ticks”. This will cause LED3 to turn on for 1000 ticks and off for 1000 ticks 12/4/2015 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 19 / 28

Scheduler functions TTCOS_AddTask(TaskName, Delay, Period) Thus TTCOS_AddTask Led3, 0, 1000); TTCOS_AddTask (Led4, 0, 2000); Now Led3 task runs for a short time every 1000 ticks, and Led4 task runs for a short time every 2000 ticks 12/4/2015 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 20 / 28

Other Scheduler Functions TTCOS_511Init( ); -- Initialize the scheduler TTCOS_Start(15); -- Start the scheduler TTCOS_GoToSleep( ); -- Go to low power mode TTCOS_DispatchTasks( ) -- Causes the tasks to run at the required times Details all hidden – if you want the details – read Pont’s book 12/4/2015 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 21 / 28

Lab. 2 code looks like this int main(int) { TTCOS_511Init( ); TTCOS_AddTask(InitFlash_Task, NO_DELAY, RUN_ONCE); TTCOS_AddTask (InitPF_Task, NO_DELAY, RUN_ONCE); TTCOS_AddTask(LED3_Flash, NO_DELAY, EVERY_2000_TICKS); TTCOS_AddTask(LED4_Flash, NO_DELAY, EVERY_2000_TICKS / 2); TTCOS_Start( ); // Allow 10 user (max 15) and 5 system threads while (1) {// Super loop // Wait, in low power mode, for an interrupt TTCOS_GoToSleep( ); // Run all the tasks in the system according to timing information TTCOS_DispatchTasks( ); } return 0; } 12/4/2015 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 22 / 28

Lab. 2 – what’s missing I have found a “co-operative scheduler” that works for the 8051 using the 8051 timer interrupts. We need to change this to work with the Blackfin interrupts – 5 routines needed InitializeTimer( ); StartTimer( ); StopTimer( ); EnterLowPowerMode( ); -- Enter low power mode until woken up by interrupt TimerISR( ); -- What to do when the timer interrupt occurs 12/4/2015 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 23 / 28

Need to know 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 or move to a different processor 12/4/2015 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 24 / 28