Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lab. 2 – More details – Later tasks

Similar presentations


Presentation on theme: "Lab. 2 – More details – Later tasks"— Presentation transcript:

1 Lab. 2 – More details – Later tasks
What concepts are you expected to understand after the Lab. 2 is finished? How do you demonstrate that you have that knowledge?

2 Show understanding of what concepts?
How to write up a “valid” (working) “C++” interrupt service routine for the timers on a microcontroller. How to set up a timer to be able to cause an interrupt. How to set-up the “C++” to handle a new interrupt without crashing Demonstrate “multi-tasking” – a main program and a background “interrupt” routine Using a test driven development approach to demonstrate validation of the other concepts 12/29/2018 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

3 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, 3, 4 and 5 – Prelab. TDD development of CORETIMER Initialize the core timer registers -- Task 7 Start and stop function for core timer – Task 8 How to “software test” a hardware interrupt – Task 9 Task Learning how to get the processor to “walk and chew gum” at the same time Foreground task – display the movie Background task – demonstrate the VCR operation under interrupt control of the core timer Application stream only – use large TV screen Tasks 6, 11 and 12 12/29/2018 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

4 Recap of what has been discussed Prelaboratory T1, T3, T4 and T5
Download the "Watchdog Timer" Video Game T1 - Video Game Do not do Task 2 as part of Lab. 2 pre-laboratory exercises Generate and use your ASM functions to control WatchDog interrupts T2 - My WatchDog Control Functions Task 2 is meant as a practice exercise for the Midterm Exam Build a simple timer T3 --Non interrupt driven timer Watch a movie T4 - on a small movie screen Setting up E-TDD environment (Assignment 1 and 2) T5 - Automated tests for Lab. 2 Application stream only tasks (not prelab) Watch a sailing movie  T6 - using a LARGE movie screen Watch a sailing movie with the help of the T11 -- Snoopy and Red Baron 12/29/2018 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

5 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 12/29/2018 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

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

7 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 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 12/29/2018 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

8 Write a test to check stub works Init_CoreTimer06ASM( )
12/29/2018 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

9 TDD for the control of the TCOUNT core timer register - 2
12/29/2018 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

10 TDD FOR TCOUNT and TSCALE
12/29/2018 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

11 Full Test for Init_CoreTimerASM( )
12/29/2018 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

12 Tasks 10 -- Concept main( ) Set up LED and PF operation
Set up Timer Interrupts and THEN activate them Show the picture using C++ wait loop Demonstration stream SMALL SCREEN 4,3,2,1,0 Application stream LARGE SCREEN 14 …. 0) Interrupt service routine in the background suspends operation of main( ) at certain time intervals When CORE-TIMER expires – unpredictable when it will occur Task 10 – flashes LED 5 – SMALLEST (UNSET) VCR Application stream Flash LED 15 for larger VCR (or do something more fancy with interrupts 12/29/2018 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

13 Task 5 details 12/29/2018 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

14 Stop and start timer code TDD
12/29/2018 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

15 How do you clear a sticky bit
How do you clear a sticky bit? Very carefully – apparent documentation error W1C IF THE PROCESSOR SETS THE STICKY BIT DURING AN INTERRUPT W0C IF YOU (accidentally) SET THE STICKY BIT BY POOR PROGRAMMING 12/29/2018 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

16 Build the C++ ISR routine -- TLD
LEARN THE KEY ELEMENTS OF C++ ISR CODING 12/29/2018 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

17 Key components of C++ ISR -- 1
SPECIAL C++ HEADER FILES VOLATILE VARIABLES FOR PASSING INFORMATION STORED IN MEMORY – NOT SUBROUTINE PARAMETERS IN REGISTERS 12/29/2018 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

18 Key components of C++ ISR -- 2
SPECIAL “TYPE” THIS SPECIAL NAME IS DEFINED IN THE SPECIAL HEADER FILES MANY ERROR MESSAGES IFHEADER NOT INCLUDED 12/29/2018 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

19 Know the error messages in case you make this mistake
THE LIST GOES ON FOR ABOUT TWO PAGES FIX THE PROBLEM YOURSELF Don’t ask T.A. for help 12/29/2018 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

20 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 12/29/2018 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

21 Testing of C++ ISR -- 2 Big Problem
The 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. Hardware driven interrupts are “unpredictable” and therefore it is difficult to test that the ISR works as required! THIS IS A PROBLEM MUST BE SOLVED OFTEN IN INDUSTRY (AND ALWAYS IN 415 MIDTERM and FINALS) 12/29/2018 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

22 Solution for Testing ISR -- 1
Make sure that no CORETIMER interrupt can accidentally occur 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: The register-handler C++ instruction just sets up the INTERRUPT VECTOR – it does not start the interrupt 12/29/2018 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

23 Solution of Testing ISR -- 2
Set KNOWN CONDITIONS Use “raise( )” to “raise bit_IVTMR” which (by software) forces the CORE TIMER interrupt to occur. SOFTWARE INTERRUPT Then check that 1) volatile variable led_toggle changed 2) The correct value was output on the LED lights 12/29/2018 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

24 FOUR STEPS NEEDED for setting up and then activate the CORE TIMER ISR
Now back in Lab. 2 project and NOT in Lab2Tests – all the tests are automatically disconnected VCR light should now BLINK void ActivateMovie(void) { The four steps IN THIS ORDER AVOID RACE CONDITIONS interrupts going off when not expected 12/29/2018 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

25 Tasks 10 -- Foreground task (Walk) ISR – Background task (and Chew gum)
main( ) Set up LED and PF operation Set up Timer Interrupts and THEN activate them Show the picture using C++ wait loop Demonstration stream SMALL SCREEN 4,3,2,1,0 Application stream LARGE SCREEN 14 …. 0) Interrupt service routine in the background suspends operation of main( ) at certain time intervals When CORE-TIMER expires – unpredictable when it will occur Task 10 – flashes LED 5 – SMALLEST (UNSET) VCR Application stream Flash LED 15 for larger VCR (or do something more fancy with interrupts 12/29/2018 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada


Download ppt "Lab. 2 – More details – Later tasks"

Similar presentations


Ads by Google