display interrupt service routine for cargo monitoring system overview of concepts demonstrated...

29
Display Interrupt Service Routine for cargo monitoring system Overview of concepts demonstrated during Labs 3 and 4

Post on 19-Dec-2015

213 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Display Interrupt Service Routine for cargo monitoring system Overview of concepts demonstrated during Labs 3 and 4

Display Interrupt Service Routine for cargo monitoring system

Overview of concepts demonstrated during Labs 3 and 4

Page 2: Display Interrupt Service Routine for cargo monitoring system Overview of concepts demonstrated during Labs 3 and 4

2 / 28

Cargo Monitoring System

During transport Quick indication of health of product NOW Acceleration in range – accuracy of +- 1 / 8 G Temperature steady – accuracy of +- 1 / 32 C

On delivery Display of ranges that cargo has experienced Range of temperatures and accelerations Other cargo information

Page 3: Display Interrupt Service Routine for cargo monitoring system Overview of concepts demonstrated during Labs 3 and 4

3 / 28

Overall designInitialize stuff (C++)

Calculate Temperature

Store temperature, calculate averages

and ranges

Calculate Acceleration

Store acceleration, calculate averages

and ranges

General Purpose Timercontrolling Display as

ISR

Temperature / Accelerationgraphic (non-text) display

Changes, actual temperatures

Core temperatureISR clockused for

Temperature / Accelerationdetermination

Communications with LCDMOSI / MISO format -- ISR

Temperature / AccelerationinformationText format

main( )

Page 4: Display Interrupt Service Routine for cargo monitoring system Overview of concepts demonstrated during Labs 3 and 4

4 / 28

Develop first test -- Requirements variable acceleration_changing is modified in

main( ) depending on whether current acceleration is greater than, equal to, or less than the average acceleration

Display ISR uses this information to modify how the LED flash (flicker up, flicker down, steady)

Set_Acceleration_Mode( current_Acc, average_ACC)

Page 5: Display Interrupt Service Routine for cargo monitoring system Overview of concepts demonstrated during Labs 3 and 4

5 / 28

DisplayISR( ) Development

This routine will be responsible for displaying both temperature and acceleration values You develop the necessary ISR for handling the

Temperature display in Lab. 3 I’ll discuss the code for handling the

Acceleration display in the lectures

Page 6: Display Interrupt Service Routine for cargo monitoring system Overview of concepts demonstrated during Labs 3 and 4

6 / 28

Test that can call an ISR and return from the interrupt without crashing system Most of the notes from last Monday’s lecture on the

general purpose timer interrupt service routine cover the topics here

Need to test using “Software interrupt” generation using the “raise( )” C++ code

Display under the control of interrupts from the general purpose timer 0

Page 7: Display Interrupt Service Routine for cargo monitoring system Overview of concepts demonstrated during Labs 3 and 4

7 / 28

Test that can access and return from ISR#include <sys\exception.h>

#include <cdefBF533.h>#include <ccblkfn.h>#include <sysreg.h>#include <signal.h>EX_INTERRUPT_HANDLER(Display_ISR_CPP);

TEST(LinkToDisplayISR, SMITH_TEST) {

register_handler(ik_ivg11, Display_ISR_CPP);CHECK(true);

register_handler(ik_ivg11, Display_ISR_ASM);CHECK(true);

register_handler(ik_ivg11, EX_INT_IGNORE);

}

Page 8: Display Interrupt Service Routine for cargo monitoring system Overview of concepts demonstrated during Labs 3 and 4

8 / 28

Recap -Minimum interrupt C++ stub for timer 0EX_INTERRUPT_HANDLER(Display_ISR_CPP) {

*pTIMER_STATUS |= 1; // Clear TIMIL0 (WIC) // See page 15 – 8

}

Make sure you understand why this particular bit needs clearing in the timer status register and what would happen if were using general purpose TIMER1 or TIMER2 instead of TIMER0!

Page 9: Display Interrupt Service Routine for cargo monitoring system Overview of concepts demonstrated during Labs 3 and 4

9 / 28

Recap - Assembly language versionMinimum interrupt stub for timer 0

. section program;

.global _Display_ISR_ASM__FiN21; // Question – why ISR name mangle __FiN21_Display_ISR_ASM__FiN21: // when we can’t pass it any parameters?

[--SP] = ASTAT;[--SP] = FP;[--SP] = (R7:0, P5:0); // Gross over-killLINK 16; // Needs to refactored for speed

P0.L = lo(TIMER_STATUS); // Clear the status bit TIMIL0 (W1C) p15-8

P0.H = hi(TIMER_STATUS); R0 = 1; W[P0] = R0; UNLINK; (R7:0, P5:0) = [SP++]; FP = [SP++]; ASTAT = [SP++]; _Display_ISR_ASM__FiN21.END:

RTI;

Page 10: Display Interrupt Service Routine for cargo monitoring system Overview of concepts demonstrated during Labs 3 and 4

10 / 28

Display Average Acceleration -- part of the GPT ISR

Use WriteLEDASM( ) to display whether the average acceleration (calculated in main( )) is increasing, decreasing or staying the same

Sort of “acceleration dancing lights”

If staying 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

Page 11: Display Interrupt Service Routine for cargo monitoring system Overview of concepts demonstrated during Labs 3 and 4

11 / 28

Design details addedInitialize stuff (C++)

Calculate Temperature

Store temperature, calculate averages

and ranges

Calculate Acceleration

Store acceleration, calculate averages

and ranges

General Purpose Timercontrolling Display as

ISR

Temperature / Accelerationgraphic (non-text) display

Changes, actual temperatures

#define ACCELERATION_STEADY 1#define ACCELERATION_DECREASING 2#define ACCELERATION_INCREASING 3

variable acceleration_changing

Communicationbetweenmain( )

and ISR

main( )

Page 12: Display Interrupt Service Routine for cargo monitoring system Overview of concepts demonstrated during Labs 3 and 4

12 / 28

Display Average Acceleration -- part of the GPT ISRUse WriteLEDASM( ) to display whether the average

acceleration (calculated in main( )) is increasing, decreasing or staying the same

Sort of “acceleration dancing lights”

If staying the same – flash all lights on and off

Page 13: Display Interrupt Service Routine for cargo monitoring system Overview of concepts demonstrated during Labs 3 and 4

13 / 28

Again write the Test Then write the code to satisfy the testTEST(StableAcceleration_ISR_CPP, DEVELOPER_TEST) {

InitializeLEDInterfaceASM( ); ResetDisplay( );register_handler(ik_ivg11, Display_ISR_CPP);

acceleration_changing = 0;

raise(SIGIVG11); // SWI – SoftWare Interruptlong int display_value = ReadLEDASM( );CHECK(display_value == 0x00); // All lights off

raise(SIGIVG11);display_value = ReadLEDASM( );CHECK( display_value == 0x3F); // All lights on

register_handler(ik_ivg11, EX_INT_IGNORE);}

Page 14: Display Interrupt Service Routine for cargo monitoring system Overview of concepts demonstrated during Labs 3 and 4

14 / 28

ResetDisplay( );

Why is this function call here?

No idea at the moment But sounds like a good idea to be able to do this.

If we are going to run a series of tests and then check the display output, we will probably want to put the display into a known mode

If not needed – then we will REFACTOR this function out of the code and the project. Calling a “do-nothing” routine does not hurt at this stage in

project development

Page 15: Display Interrupt Service Routine for cargo monitoring system Overview of concepts demonstrated during Labs 3 and 4

15 / 28

Write the tests for 20 SWI activations and display checking -- Max 10 lines of code

TEST(MultipleTests_StableAcceleration_ISR_CPP, DEVELOPER_TEST) {

}

Page 16: Display Interrupt Service Routine for cargo monitoring system Overview of concepts demonstrated during Labs 3 and 4

16 / 28

Now write the code to satisfy the testEX_INTERRUPT_HANDLER(Display_ISR_CPP) {

*pTIMER_STATUS |= 1; // Clear TIMIL0 (WIC) // See page 15 – 8

DisplayAverageAcceleration( ); // This is a subroutine // called from inside // an ISR

// Perhaps later// DisplayAverageTemperature( ); // This is a subroutine

// called from inside // an ISR

}

Page 17: Display Interrupt Service Routine for cargo monitoring system Overview of concepts demonstrated during Labs 3 and 4

17 / 28

Now write the code to satisfy the test// This is a subroutine called from inside an ISR// LATER will need to REFACTOR for speed, removing// all unnecessary code

volatile long int acceleration_changing = 0;

void DisplayAverageAcceleration(void) { static long int LEDdisplay_output = 0;

if (acceleration_changing == 0) { LEDdisplay_output = 0x3F – LEDdisplay_output;

WriteLEDASM(LEDdisplay_output);}

}

Page 18: Display Interrupt Service Routine for cargo monitoring system Overview of concepts demonstrated during Labs 3 and 4

18 / 28

Display Average Acceleration -- part of the GPT ISRUse WriteLEDASM( ) to display whether the average

acceleration (calculated in main( )) is increasing, decreasing or staying the same

Sort of “acceleration dancing lights”

If increasing acceleration – race the lights to the left(0x00, 0x01, 0x02, 0x04, 0x08 etc)

Page 19: Display Interrupt Service Routine for cargo monitoring system Overview of concepts demonstrated during Labs 3 and 4

19 / 28

Again write the Test Then write the code to satisfy the testTEST(IncreasingAcceleration_ISR_CPP, DEVELOPER_TEST) {

InitializeLEDInterfaceASM( ); ResetDisplay( );register_handler(ik_ivg11, Display_ISR_CPP);

acceleration_changing = 1;

raise(SIGIVG11); // SWI – SoftWare Interruptlong int display_value = ReadLEDASM( );CHECK(display_value == 0x00); // All lights off

raise(SIGIVG11);display_value = ReadLEDASM( );CHECK( display_value == 0x01); // First light on

register_handler(ik_ivg11, EX_INT_IGNORE);}

Page 20: Display Interrupt Service Routine for cargo monitoring system Overview of concepts demonstrated during Labs 3 and 4

20 / 28

Write the tests for 20 SWI activations and display checking -- Max 10 lines of code

TEST(MultipleTests_IncreasingAcceleration_ISR_CPP, DEVELOPER_TEST) {

}

Page 21: Display Interrupt Service Routine for cargo monitoring system Overview of concepts demonstrated during Labs 3 and 4

21 / 28

Now write the code to satisfy the test

Page 22: Display Interrupt Service Routine for cargo monitoring system Overview of concepts demonstrated during Labs 3 and 4

22 / 28

Write the tests for decreasing acceleration,then write the code

Page 23: Display Interrupt Service Routine for cargo monitoring system Overview of concepts demonstrated during Labs 3 and 4

23 / 28

Cargo Monitoring System -- update During transport

Quick indication of health of product NOW Acceleration in range – accuracy of +- 1/8 G Temperature steady – accuracy of +- 1 / 32 C

If average acceleration staying the same – flash all lights on and off

If average acceleration increasing – race the lights to the left(0x00, 0x01, 0x02, 0x04, 0x08 etc)

If average acceleration decreasing – race the lights to the right(0x00, 0x20, 0x10, 0x08 etc)

Need a mechanism to able to display “current acceleration” as a value or display “average acceleration”

Perhaps the switching will be caused by pressing SW3 on front panel

Page 24: Display Interrupt Service Routine for cargo monitoring system Overview of concepts demonstrated during Labs 3 and 4

24 / 28

Must go back and modify the testTEST(StableAcceleration_ISR_CPP, DEVELOPER_TEST) {

InitializeLEDInterfaceASM( ); ResetDisplay( );register_handler(ik_ivg11, Display_ISR_CPP);

acceleration_changing = 0; display_true_acceleration = false;

raise(SIGIVG11); // SWI – SoftWare Interruptlong int display_value = ReadLEDASM( );CHECK(display_value == 0x00); // All lights off

raise(SIGIVG11);display_value = ReadLEDASM( );CHECK( display_value == 0x3F); // All lights on

register_handler(ik_ivg11, EX_INT_IGNORE);}

Page 25: Display Interrupt Service Routine for cargo monitoring system Overview of concepts demonstrated during Labs 3 and 4

25 / 28

Must go back and modify the test fordisplaying the “average acceleration”

TEST(StableAcceleration_ISR_CPP, DEVELOPER_TEST) {

InitializeLEDInterfaceASM( ); ResetDisplay( );register_handler(ik_ivg11, Display_ISR_CPP);

display_true_acceleration = false;acceleration_changing = 0;

raise(SIGIVG11); // SWI – SoftWare Interruptlong int display_value = ReadLEDASM( );CHECK(display_value == 0x00); // All lights off

raise(SIGIVG11);display_value = ReadLEDASM( );CHECK( display_value == 0x3F); // All lights on

register_handler(ik_ivg11, EX_INT_IGNORE);}

Page 26: Display Interrupt Service Routine for cargo monitoring system Overview of concepts demonstrated during Labs 3 and 4

26 / 28

Now write the code to satisfy the testvolatile bool display_true_acceleration = false;

EX_INTERRUPT_HANDLER(Display_ISR_CPP) {

*pTIMER_STATUS |= 1; // Clear TIMIL0 (WIC) // See page 15 – 8

if (display_true_acceleration == false) DisplayAverageAcceleration( ); // This is a subroutine // called from inside // an ISR

// Perhaps later// DisplayAverageTemperature( ); // This is a subroutine

// called from inside // an ISR

}

Page 27: Display Interrupt Service Routine for cargo monitoring system Overview of concepts demonstrated during Labs 3 and 4

27 / 28

Write a test for displaying accelerationRemember 1 g is stored as 0x10000

TEST(TemperatureDisplay_ISR_CPP, DEVELOPER_TEST) {InitializeLEDInterfaceASM( ); ResetDisplay( );register_handler(ik_ivg11, Display_ISR_CPP);

display_true_acceleration = true; acceleration = 0;

raise(SIGIVG11); // SWI – SoftWare Interruptlong int display_value = ReadLEDASM( );CHECK(display_value == 0x00); // All lights off

acceleration = 1 * ACCELERATION_SCALE_FACTOR; raise(SIGIVG11);

display_value = ReadLEDASM( );CHECK( display_value == 0x10); // represent 0x1.0 g

register_handler(ik_ivg11, EX_INT_IGNORE);}

Page 28: Display Interrupt Service Routine for cargo monitoring system Overview of concepts demonstrated during Labs 3 and 4

28 / 28

Now write the code to satisfy the testvolatile bool display_true_acceleration = false;

EX_INTERRUPT_HANDLER(Display_ISR_CPP) {

*pTIMER_STATUS |= 1; // Clear TIMIL0 (WIC) // See page 15 – 8

if (display_true_acceleration == true) // I prefer “positive tests” DisplayTrueAcceleration( ); // REFACTOR the code to match thiselse DisplayAverageAcceleration( ); // This is a subroutine // called from inside // an ISR

// Perhaps later// DisplayAverageTemperature( ); // This is a subroutine

// called from inside // an ISR

}

Page 29: Display Interrupt Service Routine for cargo monitoring system Overview of concepts demonstrated during Labs 3 and 4

29 / 28

Only thing left in Cargo Monitoring System to do is “measure the acceleration” During transport

Quick indication of health of product NOW Acceleration in range – accuracy of +- 1 / 8 G Temperature steady – accuracy of +- 1 / 32 C

On delivery Display of ranges that cargo has experienced Range of temperatures and accelerations Other cargo information