lab. 2 overview. lab. 2 and assignment 3 many lab. 2 and assignment 3 tasks involve...
TRANSCRIPT
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.
When the code is run, some special characteristics of the processor are examinedWatchdog timer in a video gamePower management (speed) optional
04/21/23TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 2 / 28
Assignment 3
Labs. 2, 3 and 4 require the “true” speed of the processor to be known.
Download C++ code to “flash” the LED and then adjust a constant to get 1 second flash
Need to count “Processor cycles” with Blackfin 64-bit system register (CYCLES (low-32) / CYCLES2 (high 32))StartCyclesCountASM( ) and
StopCyclesCountASM( ) providedYou provide ReadCyclesCounterASM( )
04/21/23TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 3 / 28
Lab. 2 Task 1 Retest equipment and code
Project is provided that will retest Lab. 1 code and the Blackfin.Reuses your Lab. 1 code and your Lab. 1
TestsProject is provided that will retest your
Assignment 3 codeReuses your Assignment 3 code.Assignment 3 tests are provided
04/21/23TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 4 / 28
Task 2 – 6-pixel Video Game
void ExplainGame(void) { puts("\nWhen LED 1 is blinking, the aeroplane is under Blackfin control"); puts("\nTo show that the aeroplane crew is still awake"); puts("They must match the lights (LED 4, 3 and 2) on the LED panel"); puts(" by pushing the corresponding switches"); puts("LED 1 is ignored so you don't need to use SW1\n"); }
04/21/23TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 5 / 28
Task 2 – Video “game”
Demonstrates the concept of “waiting for input” and associated problems Main problem – other tasks can’t be done will
processor waits for your input
Tests your reaction time
Download C++ code main( ) and watchdog timer code (Friday’s lecture)
No new code needs to be developed Makes use of your Lab. 1 and Assignment 3 code
04/21/23TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 6 / 28
Task 2 main( )
WatchDogTimerHowled = 0; ActivateWatchDogTimer( ); // Background interrupt task while (WatchDogTimerHowled != 1) { ResetWatchDogTimer( ); GoControlTheAeroPlane( ); // Shown by blinking LED 1 CheckIfCrewAreAwake( ); // Test response time } // Should never get here unless Watch Dog Timer 'Howled' StopWatchDogTimer( ); WriteFlashLEDASM(0); CrewErrorOccurred( );
04/21/23TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 7 / 28
Task 3 -- OPTIONAL
Important to be able to set microprocessor into low power mode (while waiting) and then back to high speed mode (while doing things) Dynamic Power Management (Chapter 8) means
that can be done by software and not hardware changes. (Good Final Exam Q9)
SO important that can be done as a “build option” when setting up your project.
04/21/23TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 8 / 28
Interrupt Handling – Chief issues
Interrupts occur “randomly”The hardware must work to accept
interrupts.The interrupt service routine must work
to process the interrupts and perform the correct action
The processor must be told how to handle this random event
04/21/23TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 9 / 28
4 things to tackle
All 4 things must work the first timeHighly “unlikely”
Everybody using microprocessors must be able to handle interrupts and ISR
Processors have special features to make the development easier
Chief feature – software interruptsTemporarily remove the hardware from the
development process
04/21/23TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 10 / 28
Task 4 – Set up a test for the software up interrupt
// Hardware Manual Figure 4.5
// Get hardware interface ready
// Step 1 -- set the core event (interrupt) vector table SetVectorTableLab2Task4CPP();
// Tells the processor which ISR when interrupt occurs
// Step 2 -- set the SIC_IMASK -- system interrupt mask
// Hardware Manual Fig. 4-8 -- PF Interrupt A SetSIC_IMASKLab2Task4ASM( );
// Step 3 -- set IMASK -- Core Interrupt Mask SetIMASKLab2Task4ASM( );
04/21/23TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 11 / 28
Task 4 – Actual Test Code
SetVectorTableLab2Task4CPP();
SetSIC_IMASKLab2Task4ASM( ); CHECK_VALUES(numberSW4Interrupts, ==, 0);
SetIMASKLab2Task4ASM( );
StartCycleCOunterASM( ); unsigned long long int firstTimeMeasurement = ReadCycleCOunterASM( );
CauseSWI(PRETEND_GPIO_INTERRUPT);
CHECK_VALUES(numberSW4Interrupts, ==, 1);
04/21/23TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 12 / 28
Interrupts Key issue to remember
You can pass information to a subroutine using parameters passed in R0, R1, etcPassing parameters is possible as
subroutines occur “when you want” as part of your code.
You pass information into interrupt service routines using “semaphores” and “messages”These are “volatile” global variable
04/21/23TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 13 / 28
Semaphores and message to ISR
extern volatile unsigned long int numberSW4Interrupts;
extern volatile unsigned long long int ISRloggedTimeMeasurement[ ];
04/21/23TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 14 / 28
Interrupt service routine in C++
EX_INTERRUPT_HANDLER(GPIO_INTERRUPT) { // Make the interrupt service routine software somewhat software testable by // counting the interrupts that have occurred // and, via the LED, show the "humans" that something has occurred numberSW4Interrupts = numberSW4Interrupts + 1; WriteFlashLEDASM(numberSW4Interrupts); }
04/21/23TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 15 / 28
Task 5 – Hardware interrupts
InitGPIOFlags( ) -- Lab. 1SetGPIOFlagsInterruptsASM( )
Modify the FIO_MASK_A register to allow interrupts to occur when you press SW4 and not when you press the other switches
ClearIMASKLab2Task4ASM( ) is the opposite of SetIMask( ) – WHY NEEDED?
The rest of the code uses Lab. 1 code and Task 4 code
04/21/23TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 16 / 28
Task 6 – Improved video game
With the interrupt on SW4 working, we can now improve the “aircraft control” software to control the plane AND test the reaction time of the crew simultaneously
Down load the code, and will it auto-link to Lab. 1, Assignment 3 and other tasks
04/21/23TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 17 / 28
Task 7 – Light sensor
Wire up the 8 pin light sensor chip Info is printed in course notesSpecial Circuit Cellar magazine article on
using light sensor for blood oxygen sensorVcc (+5V), Ground and output
Output connects to SW4 (PF11)Other pins control
Light sensitivity (1, 10, 100)Frequency range
04/21/23TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 18 / 28
Task 7 – Light sensor
Check light sensor is working using oscilloscope
Light sensor outputs a +5V 50% duty cycle pulse whose frequency changes with light intensityMeasure frequency at low and high light
levels
04/21/23TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 19 / 28
Task 8 – Measure the light level
Design part of the lab. We are going to display the light levels in the
laboratory on a scale of 0 (dark) to 31 (brightest). The display has to respond to light levels, but the
scale does not have to be linear. (Would take too long.).
Your design to be done in C++ or ASM, your choice I provide a description of what I did Essentially a cut and paste job on the earlier tasks to change
the names of functions from Lab2Task4XXXX( ) to Lab2Task8XXXX( ) and then change 11 lines
04/21/23TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 20 / 28
Task 9 – Does it really work
Download the provided audio project Hook-up your ear phones and "music", and the light
sensor to PF11 on the Blackfin breakout board Compile the project DoesYourLab2CodeReallyWork
and run the code. You should be able to listen to the music and press
switches at the same time -- same as Lab. 1 Task 9 You should be able to cover the light sensor and get
the music to switch from the left channel to the right channel
04/21/23TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 21 / 28
Lab. 3
Replaces light sensor with temperature sensor Need to display temperature in C on the LED
screen Need to print temperature every 5 seconds
Treat as take-home lab. Quiz that is done during lab. Time One lab. Partner hooks sensor to PF10, and the
other hooks sensor to PF9
04/21/23TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 22 / 28
Lab. 4
I understand what is going on at the “low level” when dealing with peripherals
I would prefer NOT to code at a low level any more
Using “drivers” and “services” to do DMA activity and then send message “MERRY CHRISTMAS” to an LCD screen over an SPI interface
04/21/23TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 23 / 28