assignment overview thermal oscillator one of the encm415 laboratory 2 items oscillator out gnd +5v

24
Assignment Overview Thermal oscillator One of the ENCM415 Laboratory 2 items Oscillator out GND +5V

Post on 18-Dec-2015

218 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Assignment Overview Thermal oscillator One of the ENCM415 Laboratory 2 items Oscillator out GND +5V

Assignment Overview

Thermal oscillatorOne of the ENCM415 Laboratory 2 items

Oscillator out

GND

+5V

Page 2: Assignment Overview Thermal oscillator One of the ENCM415 Laboratory 2 items Oscillator out GND +5V

2 /24

Useful items listed as useful for Assignment 1

Links from ENCM415 September web page Example Blackfin assembly code file

examplecode.asm – had many assignment answers

Blackfin assembly language quick reference sheet

BF533 Blackfin Hardware Reference BF533 Blackfin Programming Reference

Page 3: Assignment Overview Thermal oscillator One of the ENCM415 Laboratory 2 items Oscillator out GND +5V

3 /24

Write the Blackfin assembly language instruction(s) to load the address of the internal timer count register into pointer register P1

For details of TIMER COUNTER register -- see index of hardware manual15-9Or look in the example assembly language file for answer

#include <defsBF533.h>

#include <macros.h>

P1.L = lo (TIMER0_COUNTER);

P1.H = hi (TIMER0_COUNTER);

#include <defsBF533.h>

#include <macros.h>

P1.L = lo (TCOUNT);

P1.H = hi (TCOUNT);

The important thing to rememberJust like the MIPS processor – must load 32-bit address in two 16-bit sections

Special Blackfin – if using a special register built into (internal to) the Blackfin then these address MUST be loaded using the MACROS hi( ) and lo( )-- These are defined in the file <macros.h>

Page 4: Assignment Overview Thermal oscillator One of the ENCM415 Laboratory 2 items Oscillator out GND +5V

4 /24

Write the Blackfin assembly language instruction(s) to load the address of the internal timer count register into pointer register P5. Why does this require a different answer to Q2E?

#include <defsBF533.h>

#include <macros.h>

P1.L = lo (TIMER0_COUNTER);

P1.H = hi (TIMER0_COUNTER);

[--SP] = P5;P5.L = lo (TIMER0_COUNT);

P5.H = hi (TIMER0_COUNT);

#include <defsBF533.h>

#include <macros.h>

P1.L = lo (TCOUNT);

P1.H = hi (TCOUNT);

[--SP] = P5;P5.L = lo (TCOUNT);

P5.H = hi (TCOUNT);

The important thing to rememberJust like the MIPS processor – some of the Blackfin registers must be saved on the stack if you plan to use them in a subroutine (non-volatile or compiler-preserved)

Page 5: Assignment Overview Thermal oscillator One of the ENCM415 Laboratory 2 items Oscillator out GND +5V

5 /24

Registers used to control PF pins

Flag Data register (FIO_FLAG_D) Used to read the PF bits (1 or 0) Need to read pins PF11 to PF8, ignore all other pins values

Page 6: Assignment Overview Thermal oscillator One of the ENCM415 Laboratory 2 items Oscillator out GND +5V

6 /24

#include <defsBF533.h>

#include <macros.h>

.global _ReadProgrammableFlags__Fv;

_ReadProgrammableFlags__Fv

LINK 16;

P1.L = lo (FIO_FLAG_D); // could be P0

P1.H = hi (FIO_FLAG_D);

R0 = W[P1] (Z);

P0 = [FP + 4];

UNLINK;

_ReadProgrammableFlags__Fv; JUMP (P0);

Must use W [ ]since the manual shows that FIO_FLAG_D register is 16-bits

Must use W[P1] (Z) zero-extend as this adds 16 zeros to the 16 bits from FIO_FLAG_D register to make 32-bits to place into R0

int ReadProgrammableFlags( )

Page 7: Assignment Overview Thermal oscillator One of the ENCM415 Laboratory 2 items Oscillator out GND +5V

7 /24

#include <defsBF533.h>

#include <macros.h>

.global _ReadProgrammableFlags__Fv;

_ReadProgrammableFlags__Fv

LINK 16;

P1.L = lo (FIO_FLAG_D); // could be P0

P1.H = hi (FIO_FLAG_D);

R0.L = W[P1]; R0.H = 0; P0 = [FP + 4];

UNLINK;

_ReadProgrammableFlags__Fv; JUMP (P0);

FIO_FLAG_D register is 16-bits

Here we use a more direct method of filling R0 with the correct values

Load (read) the bottom 16 bits of R0 (R0.L)

Put zeros into the top 16 bits of R0 (R0.H)

int ReadProgrammableFlags( )

Page 8: Assignment Overview Thermal oscillator One of the ENCM415 Laboratory 2 items Oscillator out GND +5V

8 /24

Why do you need to know how to do read (load) and write (store) on internal registers?

Flag Direction register (FIO_DIR) Used to determine if the PF bit is to be used for input or

output -- WARNING SMOKE POSSIBLE ISSUE Need to set pins PF11 to PF8 for input, leave all other pins

unchanged

Page 9: Assignment Overview Thermal oscillator One of the ENCM415 Laboratory 2 items Oscillator out GND +5V

9 /24

Registers used to control PF pins

Flag Input Enable Register Only activate the pins you want to use (saves power in

telecommunications situation) Need to activate pins PF11 to PF8 for input, leave all other pins

unchanged

Page 10: Assignment Overview Thermal oscillator One of the ENCM415 Laboratory 2 items Oscillator out GND +5V

10 /24

Registers used to control PF pins

Flag Polarity Register (FIO_POLAR) Set pins PF11 to PF8 for active HIGH, leave all other

pins unchanged

Page 11: Assignment Overview Thermal oscillator One of the ENCM415 Laboratory 2 items Oscillator out GND +5V

11 /24

Array handling// int SimpleSum(void) {

// int InsideRoutine_FOOarray[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

// static int InsideRoutine_FARarray[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

// InsideRoutine_FOOarray[0] = 6;

// InsideRoutine_FARarray[0] = 6;

// ………

Just as in MIPS InsideRoutine_FOOarray[ ] is placed “on the stack”. This array vanishes each time the subroutine SimpleSum( ) exits and gets rebuilt each time the subroutine starts again – C++ has code to reset InsideRoutine_FOOarray[0] = 1 at the start of the function

static int InsideRoutine_Fararray[10] – This use of the C++ word STATIC means that array DOES NOT VANISH each time the subroutine SimpleSum( ) exits. Next time you call the subroutine, the values stored in the array InsideRoutine_Fararray[10] are still there looking the same as when the subroutine exitted. InsideRoutine_FARarray[0] = 6;

Page 12: Assignment Overview Thermal oscillator One of the ENCM415 Laboratory 2 items Oscillator out GND +5V

12 /24

Array handling// int OutsideRoutine_FOOarray[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};// static int OutsideRoutine_FARarray[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

// int SimpleSum(void) {

// OutsideRoutine_FOOarray[0] = 6;

// OutsideRoutine_FARarray[0] = 6;

// ………

Just as in MIPS OutsideRoutine_FOOarray[ ] is NOT placed “on the stack”. This array DOES NOT vanish each time the subroutine SimpleSum( ) exits and gets DOES NOT GET rebuilt each time the subroutine starts again – OutsideRoutine_FOOarray[0] = 6

static int OUTSIDERoutine_Fararray[10] – This use of the C++ word STATIC means that array CAN NOT BE ACCESSED BY ANY FUNCTION THAT IS NOT IN THE SAME FILE AS OUTSIDERoutine_Fararray. NOT ON THE STACK -- DOES NOT VANISH each time the subroutine SimpleSum( ) exits.

Page 13: Assignment Overview Thermal oscillator One of the ENCM415 Laboratory 2 items Oscillator out GND +5V

13 /24

Array handling// int OutsideRoutine_FOOarray[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};// static int OutsideRoutine_FARarray[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

// int ExampleFum(void) {

// OutsideRoutine_FOOarray[0] = 6;

// OutsideRoutine_FARarray[0] = 6;

.section L1_data;

.global _OutsideRoutine_FOOarray; // Can be seen outside this file

.var _OutsideRoutine_FOOarray[ ] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

// There is no global statement – Can’t be seen outside of this file.var _OutsideRoutine_FOOarray[ ] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

.section program;

_ExampleFum__Fv:

Page 14: Assignment Overview Thermal oscillator One of the ENCM415 Laboratory 2 items Oscillator out GND +5V

14 /24

Array handling// int OutsideRoutine_FOOarray[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};// static int OutsideRoutine_FARarray[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

// int ExampleFum (void) {

// OutsideRoutine_FOOarray[0] = 6;// OutsideRoutine_FARarray[0] = 6;

.section L1_data;

.global _OutsideRoutine_FOOarray; // Can be seen outside this file

.var _OutsideRoutine_FOOarray[ ] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};// There is no global statement – Can’t be seen outside of this file.var _OutsideRoutine_FOOarray[ ] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

.section program;

_ExampleFum__Fv:

P0.L = _OutsideRoutine_FOOarray; P0.H = _OutsideRoutine_FOOarray; R0 = 6; [P0] = R0; P0.L = _OutsideRoutine_FARarray; P0.H = _OutsideRoutine_FARarray; R0 = 6; [P0] = R0;

Page 15: Assignment Overview Thermal oscillator One of the ENCM415 Laboratory 2 items Oscillator out GND +5V

15 /24

Array handling// int ExampleFum (void) { // int InsideRoutine_FOOarray[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};// static int InsideRoutine_FARarray[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

// InsideRoutine_FOOarray[0] = 6;

// InsideRoutine_FARarray[0] = 6;

.section L1_data; // STATIC ARRAYS CAN’T BE ON THE STACK .var _InsideRoutine_FARarray[ ] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

.section program;_ExampleFum__Fv; LINK 16 + (10 * 4); // Make room on the stack – SP points to start of // _InsideRoutine_FOOarray[ ] P0 = SP; // Now must rebuild InsideRoutine_FOOarray[ ] R0 = 1; [P0++] = R0; R0 = 2; [P0++] = R0; ………….

P0 = SP; // Now point to the start of the array again

THIS IS JUST LIKE THE OPERATIONS ON THE MIPS

Page 16: Assignment Overview Thermal oscillator One of the ENCM415 Laboratory 2 items Oscillator out GND +5V

16 /24

Back to assignment ideas

// Prototypeint SimpleSum(void);

int SimpleSum(void) { // Demonstrate “zero-over head” loops int sum2 = 0;

for (count = 0; count < 5; count++) { sum2 += Fooarray[count]; }

return (sum2);}

Problem with this code – only works with ONE array

Page 17: Assignment Overview Thermal oscillator One of the ENCM415 Laboratory 2 items Oscillator out GND +5V

17 /24

Better version of the simple sum

// Prototypeint SimpleSum(int passedFooarray[ ], int Numpts);

int SimpleSum(int passedFooarray[ ], int Numpts) { // Demonstrate “zero-over head” loops int sum2 = 0;

for (count = 0; count < Numpts; count++) { sum2 += passedFooarray[count]; }

return (sum2);}

Now we have passed in “a copy” of the start of the array passedFooarrayTogether with “a copy” of the size of the array Numpts

Page 18: Assignment Overview Thermal oscillator One of the ENCM415 Laboratory 2 items Oscillator out GND +5V

18 /24

Different version of the simple sumVersion 2// Prototypeint SimpleSum(int *passedFooarray, int Numpts);

int SimpleSum(int *passedFooarray, int Numpts) { // Demonstrate “zero-over head” loops int sum2 = 0;

for (count = 0; count < Numpts; count++) { sum2 += passedFooarray[count]; }

return (sum2);}

Does exactly the same thing

Page 19: Assignment Overview Thermal oscillator One of the ENCM415 Laboratory 2 items Oscillator out GND +5V

19 /24

Better version of the simple sumVersion 3// Prototypeint SimpleSum(int *passedFooarray, int Numpts);

int SimpleSum(int *passedFooarray, int Numpts) { // Demonstrate “zero-over head” loops int sum2 = 0;

for (count = 0; count < Numpts; count++) { sum2 += *passedFooarray++; }

return (sum2);}

Does exactly the same thing

The compiler in “DEBUG” mode will code this for highest speedThe compiler in “RELEASE” (optimizing, intelligent) mode will recognize thatall the versions are the same thing – and code for this version

Page 20: Assignment Overview Thermal oscillator One of the ENCM415 Laboratory 2 items Oscillator out GND +5V

20 /24

What do we need to know? If this was MIPS then the parameters of the subroutine

int SimpleSum(int *passedFooarray, int Numpts);

would be passed in which registers?

a0 contains the value of the address int *passedFooarray a1 contains the value of the number int Numpts

Since this is a Blackfin then the parameters of the subroutine

int SimpleSum(int *passedFooarray, int Numpts);

would be passed as

R0 contains the value of the address int *passedFooarray R1 contains the value of the number int Numpts

Page 21: Assignment Overview Thermal oscillator One of the ENCM415 Laboratory 2 items Oscillator out GND +5V

21 /24

Translate the easy bits first

int SimpleSum(int passedFooarray[ ], int Numpts) {

// Demonstrate “zero-over head” loops int sum2 = 0;

for (count = 0; count < Numpts; count++) { sum2 += passedFooarray[count]; }

return (sum2);}

R0 contains value of the address int * passedFooarray

R1 contains value of the number int Numpts

.section program; .global _SimpleSum_FPii;

_SimpleSum_FPii: LINK 16;#define sum2_R2 R2 sum2_R2 = 0; // Can’t be R0 or R1

R0 = sum_R2; P0 = [FP + 4]; UNLINK;_SimpleSum_FPii.END: JUMP (P0);

Page 22: Assignment Overview Thermal oscillator One of the ENCM415 Laboratory 2 items Oscillator out GND +5V

22 /24

Now get the “start address of the array” (R0) and “the number of points in the array” (R1)

int SimpleSum(int passedFooarray[ ], int Numpts) {

// Demonstrate “zero-over head” loops int sum2 = 0;

for (count = 0; count < Numpts; count++) { sum2 += passedFooarray[count]; }

return (sum2);}

R0 contains value of the address int * passedFooarray

R0 can’t be used to access an arrayMUST BE MOVED INTO POINTER

.section program; .global _SimpleSum_FPii;

_SimpleSum_FPii: LINK 16;#define sum2_R2 R2 sum2_R2 = 0;

#define start_FOOarray_P0 P0 start_FOOarray_P0 = R0;

// since Numpts is already in R1// leave it there#define Numpts_R1 R1 ; R0 = sum2_R2; P0 = [FP + 4]; UNLINK;_SimpleSum_FPii.END: JUMP (P0);

Page 23: Assignment Overview Thermal oscillator One of the ENCM415 Laboratory 2 items Oscillator out GND +5V

23 /24

Solution for “while loop” form

int SimpleSum(int passedFooarray[ ], int Numpts) {

// Demonstrate “zero-over head” loops int sum2 = 0;

for (count = 0; count < Numpts; count++) { sum2 += passedFooarray[count]; }

return (sum2);}

R0 started of containingvalue of the address int * passedFooarraywhich was then destroyed whenno longer needed

R1 contains value of the number int Numpts

#define sum2_R2 R2 sum2_R2 = 0;#define start_FOOarray_P0 P0 start_FOOarray_P0 = R0;// since Numpts is already in R1// leave it there#define Numpts_R1 R1 #define count_R3 R3WHILE: CC = Numpts_R1 <= count_R3; IF CC JUMP END_WHILE; R0 = [start_FOOarray_P0++]; sum2_R2 = sum2_R2 + R0; count_R3 += 1; JUMP WHILE;END_WHILE: R0 = sum2_R2;

Page 24: Assignment Overview Thermal oscillator One of the ENCM415 Laboratory 2 items Oscillator out GND +5V

24 /24

Now set up the “zero-overhead” loop

int SimpleSum(int passedFooarray[ ], int Numpts) {

// Demonstrate “zero-over head” loops int sum2 = 0;

for (count = 0; count < Numpts; count++) { sum2 += passedFooarray[count]; }

return (sum2);}

WARNING loop_end is ILLEGAL as a label

_SimpleSum_FPii: LINK 16;#define sum2_R2 R2 sum2_R2 = 0;#define start_FOOarray_P0 P0 start_FOOarray_P0 = R0;// since Numpts is already in R1// leave it there#define Numpts_R1 R1 LC0 = Numpts_R1; LSETUP(loop_start, loop_finish) LC0;

loop_start: R0 = [start_FOOarray_P0++];loop_finish; sum2_R2 = sum2_R2 + R0; R0 = sum2_R2;

ASSEMBLER ACCEPTSBUT ISSUES WARNINGABOUT PROCESSOR PIPELINEINEFFICIENCY