lab. 2 – more details – tasks 4 to 6 1. what concepts are you expected to understand after the...
Post on 15-Jan-2016
219 views
TRANSCRIPT
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 that knowledge?
04/21/23 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada
2 / 28
To be tackled today
Lab. 2 – Concepts to be understood and demonstrated TDD – develop the tests THEN the code
Overview of Lab. 2 – Tasks 1 to 3 Details of Lab. 2 Task 4
TDD development of CORETIMER setup, start and stop function
Details of Lab. 2 Task 5 TDD development of CORETIMER interrupt routines Use of developed functions for “C++” interrupt routine to make
SMALLEST VCR IN THE WORLD Details of Lab. 2 Task 6
Complete the task of combining SMALLEST VCR and SMALLEST TV code – automatic operation
Your own approach – design – Also use TIMER0 interrupt?
04/21/23 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada
3 / 28
Show understanding of what concepts?
1. How to write up a “valid” (working) “C++” interrupt service routine for the timers on a microcontroller.
2. How to set up a timer to be able to cause an interrupt.
3. How to set-up the “C++” to handle a new interrupt without crashing
4. Demonstrate “multi-tasking” – a main program and a background “interrupt” routine
5. Using a test driven development approach to demonstrate validation of the other concepts
04/21/23 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada
4 / 28
Demonstration of these concepts - 1
1. Set up THE SMALLEST TV IN THE WORLD – manually operated by switches
Two new functions (around 6 C++ lines) developed
2. Set up the “Testing environment” for Lab. 2. – basically downloading files
3. Use the “testing environment” (in a “test last approach”) to valid the new functions developed in Task. 1 above
Mainly downloading files and modifying cut-and-pasted code (around 20 C++ lines modified)
These concepts are done as Assignment 3 where Task 1 must be done in assembly code and tested (Task 3), making good practice for Post Lab. 1 Quiz and cutting down time spent during Lab. 2
04/21/23 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada
5 / 28
SMALLEST TV IN THE WORLD – PRESSING SW2
This slide is brought to you by the letter “M”PRESS SW1
Clears the screen
PRESS SW2
7 rows of pixels
04/21/23 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada
6 / 28
L2 T1 – Final main( )Press SW2 repeatedly to display “picture”
04/21/23 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada
7 / 28
ERRORS AND DEFECTS
We have some new functions developed in Task 1
TLD - Test last development Need a systematic way to ensure that those functions work now
“Regression Testing” and a systematic way to ensure that they work in the future after
modification
“Defect free” development environment By discovering all the mistakes (called ERRORS) before developing
any further code based on these functions we can ensure that no hidden mistakes (CALLED DEFECTS) are present
Errors are easier, and less costly, to fix as you are in that part of the code where they have been introduced – you know where to look
04/21/23 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada
8 / 28
Lab. 2 Task 3 -- SW1 control Testing StartPictureCommand()
04/21/23 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada
9 / 28
Demonstration of these concepts - 2
4. Use a test driven development approach to set up core timer to known values withy ability to stop-and-start the core time (C++ and ASM approach).
5. Use a test driven development approach to set up and test core timer interrupts. Demonstrate the SMALLEST VCR IN THE WORLD (C++ and ASM approach).
6. Put everything together so that the SMALLEST VCR (in the world) and the SMALLEST TV (in the world) work together with or without human intervention
04/21/23 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada
10 / 28
CORE TIMER MMR Memory Mapped Registers
Registers BELONG to the CORE TIMER not the processor
The Core timer is a programmable interval timer which can generate periodic interrupts. Blackfin Hardware pages 15-45 onwards.
The Core timer runs at the core clock (CCLK) rate.
The timer includes four core Memory-Mapped Registers (MMRs), the Timer Control register (TCNTL) p 15-47, the Timer Count register (TCOUNT) p 15-47, the Timer Period register (TPERIOD) p 15-48, and the Timer Scale register (TSCALE) p 15-49.
04/21/23 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada
11 / 28
TDD of Init_CoreTimerASM( ) - 1
04/21/23 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada
12 / 28
TDD for TCOUNT - 2
04/21/23 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada
13 / 28
TDD FOR TCOUNT and TSCALE
04/21/23 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada
14 / 28
Full Test for Init_CoreTimerASM( )
04/21/23 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada
15 / 28
Tasks 5 and 6 -- Concept
main( )
Set up LED and PF operation Set up Timer Interrupts and
THEN activate them
Change volatile variables start_next_picture and next_line using SW1 and SW2 manually
Interrupt service routine in the background suspends operation of main( ) at
certain time intervals When CORE-TIMER expires –
unpredictable when it will occur
Task 5 – flashes LED 5 – SMALLEST (UNSET) VCR
Task 6 -- Change volatile variables start_next_picture and next_line very quickly and automatically SMALLEST TV AND VCR
04/21/23 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada
16 / 28
Task 5 details
04/21/23 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada
17 / 28
Steps 1 to 3
04/21/23 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada
18 / 28
Activate and Stop CORE TIMER
04/21/23 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada
19 / 28
Build the C++ ISR routine -- TLD
04/21/23 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada
20 / 28
Key components of C++ ISR -- 1
SPECIAL C++ HEADER FILES
VOLATILE VARIABLES FOR PASSING INFORMATION – NOT SUBROUTINE PARAMETERS
04/21/23 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada
21 / 28
Key components of C++ ISR -- 2
SPECIAL NAME
THIS SPECIAL NAME IS DEFINED IN THE SPECIAL HEADER FILES MANY ERROR MESSAGES IF NOT INCLUDED
04/21/23 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada
22 / 28
Key components of C++ ISR -- 3
MUST CLEAR INTERRUPT FLAG – W1C
IF THE INTERRUPT FLAG IS NOT CLEARED – THEN INTERRUPT SERVICE ROUTINE WILL IMMEDIATELY RESTART
04/21/23 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada
23 / 28
Testing of C++ ISR -- 2
Big ProblemThe ISR is called (works) ONLY when the
core timer counts down to zero We don’t know when that will happen
because that is a hardware issue
MUST BE SOLVED OFTEN IN INDUSTRY
04/21/23 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada
24 / 28
Solution for Testing ISR -- 1
Tell the operating system that when the core timer causes the special core timer bit (related to ik_timer) in the ILAT register to be set then the ISR called TIMER_ISR (our chosen name) should be called
NOTE: This just sets up the INTERRUPT VECTOR – it does not start the interrupt
Make sure that no CORETIMER interrupt can accidentally occur
04/21/23 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada
25 / 28
Solution of Testing ISR -- 2
Set KNOWN CONDITIONS
Use “raise( )” to “raise bit_IVTMR”
which (by software) forces the CORE TIMER interrupt to occur
Then check that1) volatile variable led_toggle changed2) The correct value was output on the LED lights
04/21/23 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada
26 / 28
FOUR STEPS NEEDED for setting up and then activate the CORE TIMER ISR
The four steps IN THIS ORDER AVOID RACE CONDITIONS interrupts going off when not expected
Now back in Lab. 2 project and NOTin Lab2Tests – all the tests areautomatically disconnected
VCR light should now BLINK
04/21/23 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada
27 / 28
Task 6 – design component
5% The VCR light flashes in bit 0 -- but that bit is being used by the TV. Adjust the code so that LED 5 and not LED 0 flashes
10% If you push the buttons to make the TV work, then every time the LED VCR
flashes -- you lose the picture Adjust the code so that when the VCR light flashes -- ONLY LED 5 changes Adjust the code so that when the TV is working -- ONLY LEDs 0 to 4 change
15% Finally, we have to get the CORETIMER ISR to not only flash the VCR light, but automatically display our initials on the SMALLEST TV in the world without any switch pressing. COULD USETIMER0 interrupt
This means that the interrupt routine is modified so that over a period of time (about 40 or 50 interrupts).
Turns start_picture_again = 1 briefly and then start_picture_again = 0 for about 5 seconds.
Turns next_line = 1 very briefly and then next_line = 1 very briefly -- Total of 7 times
04/21/23 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada
28 / 28
To be tackled today
Lab. 2 – Concepts to be understood and demonstrated TDD – develop the tests THEN the code
Overview of Lab. 2 – Tasks 1 to 3 Details of Lab. 2 Task 4
TDD development of CORETIMER setup, start and stop function
Details of Lab. 2 Task 5 TDD development of CORETIMER interrupt routines Use of developed functions for “C++” interrupt routine to make
SMALLEST VCR IN THE WORLD Details of Lab. 2 Task 6
Complete the task of combining SMALLEST VCR and SMALLEST TV code – automatic operation
Your own approach – design – Also use TIMER0 interrupt?