General purpose timers

Slides:



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

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.
Blackfin BF533 EZ-KIT Control The O in I/O Activating a FLASH memory “output line” Part 2.
Embedded System Timers Details of independent timers build into the Blackfin Assignment 2-- Watchdog Timer can be used to prevent the OS system from locking.
Lab 3 Details. Lab 3 Develop a bio-feedback system based on a PWM (pulse width modulated) thermal sensor Use temperature setting to control the delays.
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.
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.
Microprocessor or Microcontroller Not just a case of “you say tomarto and I say tomayto” M. Smith, ECE University of Calgary, Canada.
Display Interrupt Service Routine for cargo monitoring system Overview of concepts demonstrated during Labs 3 and 4.
A Play Core Timer Interrupts Acted by the Human Microcontroller Ensemble from ENCM415.
Core Timer Code Development How you could have done the Take- Home Quiz using a test driven development (TDD) approach.
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.
Lab. 2 Overview 1. What concepts are you expected to understand after the Lab. 2 is finished? 2. How do you demonstrate that you have that knowledge?
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.
Peripherals and their Control An overview of industrially available “peripheral devices” that use “pulse-width modulation” for information passing. Review.
Blackfin Timers Independent timers build into the processor Watchdog Timer is a major part of Lab. 2 (Code provided to you to use)
M. Smith University of Calgary.  Many people like to sing in the shower.  However, its rather boring as there is no accompaniment.  The McVASH device.
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.
Timer Timer is a device, which counts the input at regular interval (δT) using clock pulses at its input. The counts increment on each pulse and store.
Moving Arrays -- 1 Completion of ideas needed for a general and complete program Final concepts needed for Final Review for Final – Loop efficiency.
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.
Handling multiple input signals Version #2 – co-operative scheduler Version #3 – pre-emptive scheduler.
A Play Core Timer Interrupts Acted by the Human Microcontroller Ensemble from ENCM415.
“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.
Computer Architecture
Moving Arrays -- 1 Completion of ideas needed for a general and complete program Final concepts needed for Final Review for Final – Loop efficiency.
Lab. 2 Overview – Earlier Tasks Prelaboratory T1, T3, T4 and T5
Lab. 2 Overview.
Generating the “Rectify” code (C++ and assembly code)
A Play Core Timer Interrupts
Thermal arm-wrestling
Handling Arrays Completion of ideas needed for a general and complete program Final concepts needed for Final.
TigerSHARC processor and evaluation board
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
Using Arrays Completion of ideas needed for a general and complete program Final concepts needed for Final.
Lab. 4 – Part 1 Demonstrating and understanding multi-processor boot
A Play Lab. 2 Task 8 Core Timer Interrupts
General purpose timers
Moving Arrays -- 2 Completion of ideas needed for a general and complete program Final concepts needed for Final DMA.
Handling Arrays Completion of ideas needed for a general and complete program Final concepts needed for Final.
HD44780 LCD programming From the Hardware Side
HD44780 LCD programming From the Hardware Side
Getting serious about “going fast” on the TigerSHARC
Thermal arm-wrestling
Concept of TDD Test Driven Development
Explaining issues with DCremoval( )
Blackfin Timers Independent timers build into the Blackfin
Lab. 4 – Part 2 Demonstrating and understanding multi-processor boot
Independent timers build into the processor Basis for Lab. 2
Handling Arrays Completion of ideas needed for a general and complete program Final concepts needed for Final.
Blackfin Timers Independent timers build into the processor
Independent timers build into the processor
Lab. 2 Overview Move the tasks you developed in Lab. 1 into the more controllable TTCOS operating system.
Thermal arm-wrestling
Mistakes, Errors and Defects
Post Lab Quiz 3 Review Assignment 2 Help
Display Interrupt Service Routine for cargo monitoring system
Blackfin Syntax Moves and Adds
Blackfin Syntax Stores, Jumps, Calls and Conditional Jumps
Presentation transcript:

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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