Presentation is loading. Please wait.

Presentation is loading. Please wait.

General purpose timers

Similar presentations


Presentation on theme: "General purpose timers"— Presentation transcript:

1 General purpose timers
Recap of Tasks of Lab.2 Second example of setting up timer interrupts – TIMER0 rather than CORE TIMER

2 To be tackled today Lab. 2 – Over View
Reminding about CORETIMER interrupts New example – General purpose timer interrupts Follows the same procedure as for the CORETIMER in Lab. 2 Needs essentially the same code, so use the Lab. 2 as a template to follow 2/19/2019 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

3 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 2/19/2019 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

4 First three tasks Lab. 2 are additional examples of what you did in Lab. 1
Set up THE SMALLEST TV IN THE WORLD – manually operated by switches Two new functions (around 6 C++ lines) developed Set up the “Testing environment” for Lab. 2. – basically downloading files 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 2/19/2019 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

5 Final tasks in Lab. 2 give first experience in interrupts
Final tasks in Lab. 2 give first experience in interrupts. Second example in Lab. 3 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). 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). 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 2/19/2019 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

6 Lab. 2 concept CORE TIMER MMR
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 2/19/2019 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

7 Lab. 2 Task 3 -- TDD for TCOUNT
You build the assembly code to copy the in-coming function parameters (passed in R0, R1 and R2) into the timer memory mapped registers TCOUNT, TPERIOD and TSCALE. Tests are provided. Make sure you read the hardware manual to understand interaction between these MMR Meaning does changing one register cause changes in another? 2/19/2019 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

8 Lab. 3 concept General purpose timer MMR -- 1
TIMER0_COUNTER -- timer counter register – p 15-9 ESSENTIALLY the same role as TCOUNT DIFFERENCE – when TIMER0 is running then the TIMER0 counter is R0 – stands for read only TIMER0_PERIOD -- timer period register – p 15-10 ESSENTIALLY the same role as TPERIOD TIMER0_WIDTH -- timer pulse width register – p 15-10 TIMER0_PERIOD TIMER0_WIDTH 2/19/2019 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

9 Lab. 3 concept General purpose timer MMR - 2
These four registers together play the same role as TCNTRL in the CORE TIMER. More registers since these timers are “fancier” – more general purpose – and can do more than the CORE-TIMER TIMER0_CONFIG -- timer configuration register. Set IRQ_ENA bit to enable the timer interrupts. TIMER_ENABLE and TIMER_DISABLE -- registers to control whether the timer is running or stopped. Note that these registers control ALL three of the general purpose timers -- you just need to set the appropriate bit for GP timer 0 TIMER_STATUS  -- timer status. In the ISR make sure that the the TIMIL0 latch (in register TIMER_STATUS) is cleared before the RTI instruction to ensure that the interrupt is not reissued. 2/19/2019 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

10 In Lab. 3 we perform similar tests on GPT as we did in Lab
In Lab. 3 we perform similar tests on GPT as we did in Lab. 2 on CORETIMER #define PERIOD_VALUE 0x30000 #define WIDTH_VALUE 0x40000 TEST(GPTimerPERIOD, SMITH_TEST) { StopGPTimer0ASM(); WatchDataClass<unsigned long int> timer_access(1, (unsigned long int *) pTIMER0_PERIOD); WATCH_MEMORY_RANGE(timer_access, Init_GPTimer0ASM(PERIOD_VALUE, WIDTH_VALUE)); CHECK(timer_access.getFinalValue(0) == PERIOD_VALUE); } TEST(GPTimerWidth_1, DEVELOPER_TEST) { WatchDataClass<unsigned long int> timer_access(1, (unsigned long int *) pTIMER0_WIDTH); CHECK(timer_access.getFinalValue(0) == PERIOD_VALUE - 1); 2/19/2019 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

11 Lab. 2 Tasks 5 and 6 -- Concept Lab. 3 – Same idea – except using GPT
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 2/19/2019 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

12 Lab. 2 Build the C++ ISR routine -- TLD
2/19/2019 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

13 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: This just sets up the INTERRUPT VECTOR – it does not start the interrupt 2/19/2019 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

14 Key components of C++ ISR -- 2
SPECIAL NAME THIS SPECIAL NAME IS DEFINED IN THE SPECIAL HEADER FILES MANY ERROR MESSAGES IF NOT INCLUDED 2/19/2019 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

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

16 Lab. 3 – Since we better understand interrupts can “build the tests first”
First test – can we link to the GPT ISR code? Need a stub C++ function for Timer0_ISR_CPP Need a stub asm function for Timer0_ISR_ASM When building the tests, the linker will inform you of the name-mangling you need to use in the ASM code TEST(LinkToISR, SMITH_TEST) { register_handler(ik_ivg11, Timer0_ISR_CPP); CHECK(true); register_handler(ik_ivg11, Timer0_ISR_ASM); register_handler(ik_ivg11, EX_INT_IGNORE); } CORETIMER used ik_timer 2/19/2019 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

17 What is the ISR going to be doing in Lab. 3
Uses many of the ideas from the smallest VCR and smallest TV problem in Lab. 2 Means that will be re-using a lot of the code from Lab. 2 Interrupt service routine will be using WriteLEDASM( ) within 2 new functions DisplayTemperatureCPP( ) DisplayAverageTemperatureModeCPP( ); 2/19/2019 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

18 DisplayTemperatureCPP( ) part of the GPT ISR
Use WriteLEDASM( ) to display the temperature in either Celsius or Fahrenheit volatile global short int variable temperature calculated as part of main( ) from reading from a thermal sensor – Analog Devices TMP03 For this test, set temperature to a known value Remember that short int requires R0 = W[Px] (X); type of operations in assembly code 2/19/2019 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

19 Example Test – display Celsius
TEST(ISRCPP_temperature_display, DEVELOPER_TEST) { InitializeLEDInterfaceASM( ); ResetDisplay( ); WriteLEDASM(0); temperature_display_mode = true; centigrade = true; temperature = 24; register_handler(ik_ivg11, Timer0_ISR_CPP); raise(SIGIVG11); long int LEDdisplay = ReadLEDASM( ); CHECK(LEDdisplay & BIT5); CHECK( (LEDdisplay & BITS4to0) == 24); 2/19/2019 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

20 Finish test – this time Fahrenheit
WriteLEDASM(0); temperature_display_mode = true; centigrade = false; temperature = 6; raise(SIGIVG11); LEDdisplay = ReadLEDASM( ); CHECK((LEDdisplay & BIT5) == 0); CHECK( (LEDdisplay & BITS4to0) == 3); } 2/19/2019 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

21 DisplayAverageTemperatureModeCPP( ); part of the GPT ISR
Use WriteLEDASM( ) to display whether the average temperature (calculated in main( )) is increasing, decreasing or staying the same Sort of “temperature dancing lights” If the same – flash all lights on and off If increasing – race the lights to the left (0x00, 0x01, 0x02, 0x04, 0x08 etc) If decreasing – race the lights to the right (0x00, 0x20, 0x10, 0x08 etc) Basically more practice with left and right shift 2/19/2019 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

22 Again write the Test Then write code to satisfy the test
TEST(StableTemperature_ISR_CPP, DEVELOPER_TEST) { InitializeLEDInterfaceASM( ); ResetDisplay( ); temperature_display_mode = false; temperature_change = 0; register_handler(ik_ivg11, Timer0_ISR_CPP); raise(SIGIVG11); long int first_value = ReadLEDASM( ); long int second_value = ReadLEDASM( ); CHECK( second_value == (0x3F - first_value)); 2/19/2019 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

23 Stable temperature test – part 2
for (int count = 0; count < 6; count++) { raise(SIGIVG11); first_value = ReadLEDASM( ); second_value = ReadLEDASM( ); CHECK( second_value == (0x3F - first_value)); } 2/19/2019 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

24 Test in a similar manner for increasing temperature
TEST(IncreasingTemperature_ISR_CPP, DEVELOPER_TEST) { InitializeLEDInterfaceASM( ); ResetDisplay( ); temperature_display_mode = false; temperature_change = 1; register_handler(ik_ivg11, Timer0_ISR_CPP); raise(SIGIVG11); long int first_value = ReadLEDASM( ); CHECK(first_value == 0x0); for (int count = 0; count < 6; count++) { first_value = ReadLEDASM( ); CHECK(first_value == (1 << count)); } 2/19/2019 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

25 Lab3 main( ) int main( ) { // Initialize_ProgrammableFlagsASM( );
// InitializeLEDInterfaceASM( ); // Now use Init_GPTimer0ASM( ) to set the GPTimer register values; // Use register_handler( ) to point C++ towards Timer0_ISR_ASM ResetDisplay( ); // 2 lines of code needed to activate the timer and timer interrupts long int switch_result = 0; while (1) { switch_result = ReadProgrammableFlagBitsASM( ); // Read the switches // Later -- in task 6 -- we will connect SW1 to the temperature sensor // and actually measure, rather than simulate, the temperature if ((switch_result & SW1) == SW1) temperature_change = 1; else temperature_change = 0; if ((switch_result & SW2) == SW2) temperature_display_mode = true; else temperature_display_mode = false; if ((switch_result & SW3) == SW3) temperature = 15; else temperature = 17; } 2/19/2019 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

26 To be tackled today Lab. 2 – Over View
Reminding about CORETIMER interrupts New example – General purpose timer interrupts Follows the same procedure as for the CORETIMER in Lab. 2 Needs essentially the same code, so use the Lab. 2 as a template to follow 2/19/2019 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada


Download ppt "General purpose timers"

Similar presentations


Ads by Google