Handling multiple input signals Version #2 – co-operative scheduler Version #3 – pre-emptive scheduler.

Slides:



Advertisements
Similar presentations
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.
Advertisements

Interrupts, Low Power Modes and Timer A (Chapters 6 & 8)
Over-view of Lab. 1 For more details – see the Lab. 1 web-site There will be a 20 min prelab quiz (based on Assignment 1 and 2) at the start of the lab.
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.
Lab3 -- Lab 4 Design and implementation details on the way to a valid SPI-LCD interface driver.
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.
Building a simple loop using Blackfin assembly code M. Smith, Electrical and Computer Engineering, University of Calgary, Canada.
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.
Software and Hardware Circular Buffer Operations First presented in ENCM There are 3 earlier lectures that are useful for midterm review. M. R.
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.
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.
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.
Later tasks of Lab. 1 For more details – see the Lab. 1 web-site There will be a 20 min prelab quiz (based on Assignment 1 and 2) at the start of the lab.
Microprocessor or Microcontroller Not just a case of “you say tomarto and I say tomayto” M. Smith, ECE University of Calgary, Canada.
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.
Developing a bicycle speed-o-meter Midterm Review.
Peripherals and their Control An overview of industrially available “peripheral devices” that use “pulse-width modulation” for information passing. Review.
Input Laboratory: GPIO Pin control needed to have the Blackfin accept your commands Re-uses information from ENEL353 and ENCM369 courses and text books.
A Simple Tour of the MSP430. Light LEDs in C LEDs can be connected in two standard ways. Active high circuit, the LED illuminates if the pin is driven.
Blackfin Timers Independent timers build into the processor Watchdog Timer is a major part of Lab. 2 (Code provided to you to use)
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.
ECS642U Embedded Systems Cyclic Execution and Polling William Marsh.
Moving Arrays -- 1 Completion of ideas needed for a general and complete program Final concepts needed for Final Review for Final – Loop efficiency.
SDRAM Load and Play By Hernacki, Kevin ECE3551 Final Project 25 April 2008.
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.
1 Interrupts, Resets Today: First Hour: Interrupts –Section 5.2 of Huang’s Textbook –In-class Activity #1 Second Hour: More Interrupts Section 5.2 of Huang’s.
The right and wrong ways for constructing tasks for the Labs and Assignment.
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.
Embedded Programming and Robotics Lesson 11 Arduino Interrupts 1.
A Play Core Timer Interrupts Acted by the Human Microcontroller Ensemble from ENCM415.
Handling multiple input signals. Midterm question Light sensor is in front of the door  Light signs on light sensor  If person blocking light – light.
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.
Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir. A.C. Verschueren Eindhoven University of Technology Section of Digital.
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.
Developing a bicycle speed-o-meter
Lab. 2 Overview.
A Play Core Timer Interrupts
Thermal arm-wrestling
ENCM K Interrupts Theory and Practice
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.
Thermal arm-wrestling
A Play Lab. 2 Task 8 Core Timer Interrupts
Moving Arrays -- 2 Completion of ideas needed for a general and complete program Final concepts needed for Final DMA.
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.
Thermal arm-wrestling
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
Input Laboratory: GPIO Pin control needed to have the Blackfin accept your commands Re-uses information from ENEL353 and ENCM369 courses and text books.
Blackfin Timers Independent timers build into the processor
Independent timers build into the processor
Developing a bicycle speed-o-meter
Developing a bicycle speed-o-meter
Thermal arm-wrestling
Post Lab Quiz 3 Review Assignment 2 Help
Handling multiple input signals
Working with the Compute Block
Interrupts.
Presentation transcript:

Handling multiple input signals Version #2 – co-operative scheduler Version #3 – pre-emptive scheduler

Midterm question Light sensor is in front of the door  Light signs on light sensor  If person blocking light – light sensor output is low -- Active low logic  Output of light sensor connected to PF5 Program stops “immediately” when owner pushes and releases a button.  Button connected to PF6 line Show the count of the people on the LCD using WriteLCD( int count). 10k resistor +5V GROUND PF6 GROUND

Design component Key part of the design – Neither action must block the other action Light sensor  If high – nobody has ever blocked the sensor, or somebody has blocked the sensor at moved on  If low – somebody is still blocking the sensor  Must count “1 person enter or leave” as the signal goes from low to high Button  If high – owner has not pressed the button or else has pressed the button and released it.  If low – is pressing the button – people can still be entering and leaving store.  Must stop the program as the signal goes from low to high

Approach #1 – Superloop approach based on Lab. 1 ideas While (loop is not stopped) { Read GPIO Flags 4 possible things possible At least 2 true at the same time 1. Light sensor PF 5 is high 2. Light sensor PF 5 is low 3. Button PF 6 is high 4. Button PF 6 is low We want to take action – on the “edge of the signal”. We don’t want to take action on the “level of the signal” }

One solution for the code int count = 0; int stop = 0; #define PF5Mask 0x20 int oldPF5state = 0; int Midterm(void) { InitAllInterFaces( ); oldPF5State = ReadGPIOASM( ) & PF5Mask ; While (stop != 1) { int newPF5State = ReadGPIOASM( ) & PF5Mask ; If PF5 was high before and high now – do nothing If PF5 was low before and low now – do nothing If PF5 was high before and low now – do nothing If PF5 was low before and high now – ACT if ( (oldPF5State == 0) && (newPF5State == PF5Mask) ) count++; WriteLCD(count); oldPF5State = newPF5State You write the other code for the button } return count; }

Using Lab. 2 ideas Co-operative Scheduler TTCOS_Init_Scheduler( ); // Assume Ticks occur every 1 ms – which is faster than people move or press buttons TTCOS_Add_Task(InitInterfaces, 0, 0) TTCOS_Add_Task(WriteToLCD, 50, 100); // Update LCD every 1/10 second – faster than the eye // These tasks ONLY work if no task waits, and no task causes an interrupt TTCOS_Add_Task(Count_People, 5, 10); // Worry about people moving TTCOS_Add_Task(CheckButton, 6, 10); // Worry about the button being pressed TTCOS_Add_Task(Stop_System, 7, 10); // Do we need to stop the system TTCOS_Star_Scheduler( ); While (1) { TTCOS_GoToSleep( ); TTCOS_DispatchTasks( ); }

Using Lab. 2 ideas Co-operative Scheduler int count_G = 0; int stop_G = 0; int oldState_G = 0; void InitInterfaces(void) { InitAllInterfaces( ); oldState_G = ReadGPIO( ) & PEOPLEMASK; } void WriteToLCD(void) { WriteLCD(count_G); 50, 100); } void Count_People(void) { int newstate = ReadGPIO( ) & PEOPLEMASK; if ( (oldstate == 0) && (newState == PEOPLEMASK) ) count_G++; oldState = newState; } void StopSystem(void) { static systemStopped = 0; if (systemStopped == 1) return; if (stop_G == 1) { TTCOS_Stop(WriteToLCD); TTCOS_Stop(CountPeople); TTCOS_Stop(CheckButton) systemStopped = 1; } FINAL EXAM HINT You write the code for CheckButton( ) and convert into assembly code

Using Lab. 2 ideas Event Driven Using Interrupts InitAllInterfaces( ); SetUpPFInterrupts( ); StartPFInterrupts( ); while (1) { /* Wait for interrupts to occur in the background */ idle( ); -- Low power mode }

void InitAllInterfaces(void) { InitLEDs( ); InitLCDScreen( ); // Init GPIO using C/C++ *pFIO_DIR = 0; // Do properly with AND and OR *pFIO_MASKA_D = 0; // All interrupts off – channel 1 *pFIO_MASKB_D = 0; // All Interrupts off – channel 2 *pFIO_POLAR = 0; *pFIO_EDGE = 0; // Will become very important *pFIO_BOTH = 0; // Will become important *pFIO_INEN = 0x0600; need PF5 (0x20) and PF6 (0x40); }

1/11/2016Thermal Arm Wrestling, Copyright M. Smith, ECE, University of Calgary, Canada 10 / 24 + extras PF registers Direction, Data, Polarity and Enable all the same from Lab. 1 Flag Mask registers –  Flag mask Interrupt data register – basically which PF pins have been set to allow to cause interrupt Flag mask Interrupt Set register – sets PF pin that is allowed to cause an interrupt, without the need for a read – or mask – write operation Flag Mask Interrupt Clear register – which PF pin is no longer allowed to cause an interrupt without the need for a read – and mask – write operation  Flag interrupt Sensitivity register (FIO_EDGE) – set for edge-sensitive FIO_BOTH allows you to cause interrupts on “both” leading and trailing edges of PF signals

EX_INTERRUPT_HANDLER(PFInter) All PF interrupts are multiplexed. That means any interrupt on PF line gets to same ISR We get here if  PF5 line goes from low to high  PF6 line goes from low to high How do we know which one interrupted  If PF5 interrupt then FIO_FLAG bit 5 is high  If PF6 interrupt then FIO_FLAG bit 6 is high

Interrupt routine looks like this #define BIT5 0x20 #define BIT6 0x40 extern volatile int count; extern volatile int stop; EX_INTERRUPT_HANDLER(PFInterrupt) { short int whichInterrupt = *pFIO_FLAG_D & (BIT6 | BIT5); // Brackets around (BIT6 | BIT5); very important in Quiz 3 if ( (whichInterrupt & BIT5) == BIT5) { // Brackets important in Quiz 3 count++; *pFIO_FLAG_D &= ~BIT5; // Clear interrupt bit or *pFIO_FLAG_C = BIT5;// Clear interrupt bit } if ( (whichInterrupt & BIT6) == BIT6) { // Brackets important in Quiz 3 stop = 1; *pFIO_FLAG_D &= ~BIT6; // Clear interrupt bit or *pFIO_FLAG_C = BIT6;// Clear interrupt bit } } // Can you translate this into assembly code for post-lab quiz 3

Getting interrupts to work void SetUpInterrupts( ) { // SetUp_VectorTable( );Lab. 3 // SetUp_IMASK( ); Lab. 3 register_handler(ik_ivg12, PFInterrupt); SetUp_SIC_MASK( ); Lab. 3 SetUp_PFLinesForInterrupts( ); Lab. 3 }

Getting interrupts to work void SetUpInterrupts( ) { // SetUp_VectorTable( ); Lab. 2 // SetUp_IMASK( ); Lab. 2 register_handler(ik_ivg12, PFInterrupt); // SetUp_SIC_MASK( ); Lab. 2 *pSIC_IMASK = 0x // SetUp_PFLinesForInterrupts( ); *pFIO_FLAG_D = 0; // In case interrupt waiting *pFIO_MASKA_S = (BIT5 | BIT 6); }

void StartInterrupts( ) { *pFIO_FLAG_C = (BIT4 | BIT5); // Waiting *pFIO_MASKA_D = (BIT4 | BIT5); Lab. 2 }

Other approaches We could Use PF Interrupt A for PF5 line and PF Interrupt B for PF6 line Writing 2 ISR’s

Example interrupt routine In assembly code Design the code Start the special ISR instructions Write “the subroutine” part of the ISR Finish the special ISR instructions Test the code Optimize for FAST ISR  ISR routines are marked for efficiency

Design the code

Fix the easy bits -- Unoptimized code okay at this point

Add in the code HINT: Easier to optimize if use higher registers first

Optimize the code – save ONLY the registers used ENTER 10 cyles ? jump Missing ssync( ) 236 RTI 10 cycles