Download presentation
Presentation is loading. Please wait.
1
Developing a bicycle speed-o-meter Part 2 A comparison between the Analog Devices ADSP-BF533 (Blackfin) and Motorola MC68332
2
6/2/2015 Motorola Blackfin Comparison Part 1, Copyright M. Smith, ECE, University of Calgary, Canada 2 General Project concept Magnetic Sensor Signal High speed clock signal Blackfin Programmable Flag (PF) Input Motorola Parallel Interface Timer (PIT) Input
3
6/2/2015 Motorola Blackfin Comparison Part 1, Copyright M. Smith, ECE, University of Calgary, Canada 3 Main function concept ulong DetermineSpeed(ulong wheelDiameter, ulong clockFrequency) #define ulong unsigned long int; extern “C” ulong CountClockASM(const int); // Assembly code interface extern “C” ulong CalculateSpeedASM(ulong, ulong, ulong); extern “C” void SetupInterface(void); ulong DetermineSpeed(ulong wheelDiameter, ulong clockFrequency) { // Get to known position on magnetic sensor signal unsigned long discard_count; unsigned long count_high, count_low; SetupInterface( ); discard_count = CountClockASM(while_MagneticSensorHigh); discard_count = CountClockASM(while_MagneticSensorLow); count_high = CountClockASM(while_MagneticSensorHigh); count_low = CountClockASM(while_MagneticSensorLow); return CalculateSpeedASM(count_high + count_low, wheelDiameter, clockFrequency); }
4
6/2/2015 Motorola Blackfin Comparison Part 1, Copyright M. Smith, ECE, University of Calgary, Canada 4 Required Assembly Language extern “C” ulong CountClockASM(const int); // Assembly code interface extern “C” void SetupInterface(void); extern “C” ulong CalculateSpeedASM(ulong, ulong, ulong); ulong CountClockASM(const int high_low) { ulong clock_count = 0; while (magnetic_sensor = = high_low) { // if signal is unchanged from start // Must count just one clock signal low-to-high transition while (clock_signal = = high) /* wait */; while (clock_signal = = low) /* wait */; // Changes on low-to-high edge clock_count++; } return clock_count; }
5
6/2/2015 Motorola Blackfin Comparison Part 1, Copyright M. Smith, ECE, University of Calgary, Canada 5 Programming model MC68332Blackfin Data RegistersD0, D1 …. D7R0, R1 …. R7 Address RegistersA0, A1 …. A6 Pointer RegistersP0, P1 … P5 Frame Buffer Use A4 or A6FP Stack PointerSP (A7)SP Special DSP I0-I3, B0-B3, M0-M3, L0-L3
6
6/2/2015 Motorola Blackfin Comparison Part 1, Copyright M. Smith, ECE, University of Calgary, Canada 6 Syntax examples MC68332Blackfin Register to Register Move reg1 reg 2 32 bit operations MOVE.L D2, D1R1 = R2; Memory MovesMOVE.L #MEM1, A0 MOVE.L #MEM2, A1 MOVE.B (A0), (A1) (8-bits) P0.H = hi(MEM1); P0.L = lo(MEM1); P1.H = hi(MEM2); P1.L = lo(MEM2); R0 =W [P0]; W[P1] = R0; 16-bits Set the condition code registerCMP.L D0, D1CC = D1 == D0; CC = D1 < D0; CC = D1 <= D0; Conditional jumpBEQ NEXT_INSTR (D1 == D0) BLT NEXT_INSTR (D1 < D0) BLE NEXT_INSTR (D1 <= D0) IF CC JUMP NEXT_INSTR
7
6/2/2015 Motorola Blackfin Comparison Part 1, Copyright M. Smith, ECE, University of Calgary, Canada 7 Example loop code -- software loop C++ exampleMotorolaBlackfin sum = 0; for (loop = 0; loop < 6; loop++) sum = sum + loop; Set D0 = sum, D1 = loop MOVE.L #0, D0 MOVE.L #0, D1 LOOP: CMP.L #6, D1 BGE PAST_LOOP ADD.L D1, D0 ADD.L #1, D1 BRA LOOP PAST_LOOP: Set R0 = sum, R1 = loop R0 = 0; R1 = 0; R2 = 6; LOOP: CC = R2 <= R1; IF !CC JUMP PAST_LOOP; R0 = R0 + R1; R1 += 1; JUMP LOOP PAST_LOOP:
8
6/2/2015 Motorola Blackfin Comparison Part 1, Copyright M. Smith, ECE, University of Calgary, Canada 8 Hardware test – wait while magnetic signal is “high” C++MotorolaBlackfin Magnetic SignalBit 1 of PADR register of PI/T interface Bit 10 of FIO_FLAG_D register of PF interface while (mag_signal == HIGH) /* wait */ ; MASK EQU 0x1 MOVE.L #PITBASE, A0 WHILE: MOVE.B PADR(A0), D0 AND.B #MASK, D0 CMP.B #MASK, D0 BEQ WHILE #define MASK 0x400 P0.H = hi(FIO_FLAG_D); P0.L = lo(FIO_FLAG_D); R1 = MASK; WHILE: R0 = W[P0] (Z); R0 = R0 & R1; CC = R0 == R1; IF CC JUMP WHILE (BP);
9
6/2/2015 Motorola Blackfin Comparison Part 1, Copyright M. Smith, ECE, University of Calgary, Canada 9 Required 68K Assembly Language ulong CountClockASM(const int high_low) { ulong clock_count = 0; while (magnetic_sensor = = high_low) { // if signal is unchanged from start // Must count just one clock signal // low-to-high transition while (clock_signal = = high) /* wait */; while (clock_signal = = low) /* wait */; // Changes on low-to-high edge clock_count++; } return clock_count; } _CountClockASM: MOVEA.L #0, A1 // Use as counter MOVEA.L #PITBASE, A0 MOVE.L 4(SP), D0 WHILE: MOVE.B PADR(A0), D1 AND.B #MASKMAG, D1 CMP.B D0, D1 BNE END_WHILE HIGH: MOVE.B PADR(A0), D1 AND.B #MASKCLK, D1 BNE HIGH LOW: MOVE.B PADR(A0), D1 AND.B #MASKCLK, D1 BEQ LOW ADDA.L #1, A1 BRA WHILE END_WHILE: MOVE.L A1, D0 RTS
10
6/2/2015 Motorola Blackfin Comparison Part 1, Copyright M. Smith, ECE, University of Calgary, Canada 10 Required BF533 Assembly Language ulong CountClockASM(const int high_low) { ulong clock_count = 0; while (magnetic_sensor = = high_low) { // if signal is unchanged from start // Must count just one clock signal // low-to-high transition while (clock_signal = = high) /* wait */; while (clock_signal = = low) /* wait */; // Changes on low-to-high edge clock_count++; } return clock_count; } _CountClockASM: R0 contains the INPAR R1 = 0; P0.H = hi(FIO_FLAG_D); P0.L = lo(FIO_FLAG_D); WHILE: R2 = W[P0] (Z); R3 = MASKMAG; R2 = R2 & R3; CC = R2 == R0; IF !CC JUMP ENDWHILE; R3 = MASKCLK; HIGH: R2 = W[P0] (Z); R2 = R2 & R3; CC = R2 == R3 IF CC JUMP HIGH (BP); LOW : R2 = W[P0] (Z); R2 = R2 & R3; CC = R2 < R3 IF CC JUMP LOW (BP); R1 += 1; JUMP WHILE END_WHILE: R0 = R1; RTS
11
6/2/2015 Motorola Blackfin Comparison Part 1, Copyright M. Smith, ECE, University of Calgary, Canada 11 Compare 68K and Blackfin _CountClockASM: MOVEA.L #0, A1 // Use as counter MOVEA.L #PITBASE, A0 MOVE.L 4(SP), D0 WHILE: MOVE.B PADR(A0), D1 AND.B #MASKMAG, D1 CMP.B D0, D1 BNE END_WHILE HIGH: MOVE.B PADR(A0), D1 AND.B #MASKCLK, D1 BNE HIGH LOW: MOVE.B PADR(A0), D1 AND.B #MASKCLK, D1 BEQ LOW ADDA.L #1, A1 BRA WHILE END_WHILE: MOVE.L A1, D0 RTS _CountClockASM: R0 contains the INPAR R1 = 0; P0.H = hi(FIO_FLAG_D); P0.L = lo(FIO_FLAG_D); WHILE: R2 = W[P0] (Z); R3 = MASKMAG; R2 = R2 & R3; CC = R2 == R0; IF !CC JUMP ENDWHILE; R3 = MASKCLK; HIGH: R2 = W[P0] (Z); R2 = R2 & R3; CC = R2 == R3 IF CC JUMP HIGH (BP); LOW : R2 = W[P0] (Z); R2 = R2 & R3; CC = R2 < R3 IF CC JUMP LOW (BP); R1 += 1; JUMP WHILE END_WHILE: R0 = R1; RTS
12
6/2/2015 Motorola Blackfin Comparison Part 1, Copyright M. Smith, ECE, University of Calgary, Canada 12 Subroutine / Function calls C++MotorolaBlackfin extern “C” int FooASM(int, int, int) C = FooASM(1,2,3).IMPORT _FooASM FP EQU A6 LINK FP, -16 MOVE.L D4, 12(SP) MOVE.L #1, 0(SP) MOVE.L #2, 4(SP) MOVE.L #3, 8(SP) JSR _FooASM MOVE.L D0, D4.. Other code MOVE.L 12(SP), D4 UNLINK RTS.extern _FooASM LINK 20; [SP + 16] = R4; R0 = 1; R1 = 2; R2 = 3; CALL _FooASM; R4 = R0;.. Other code R4 = [SP + 16]; UNLINK; RTS;
13
6/2/2015 Motorola Blackfin Comparison Part 1, Copyright M. Smith, ECE, University of Calgary, Canada 13 Code conventions for subroutines / functions Motorola -- SDSBlackfin -- VisualDSP Volatile registersD0, D1 A0, A1 R0, R1, R2, R3 P0, P1, P2 Non-volatile registersD2, D2, D4, D5, D6, D7 A2, A3, A4, A5, A6, A7 R4, R5, R6, R7 P3, P4, P5, FP, SP Subroutine return value is passed in D0R0 Subroutine OUTPARSOUTPAR1 0(SP) OUTPAR2 4(SP) OUTPAR3 8(SP) OUTPAR4 12(SP) OUTPAR1 R0 OUTPAR2 R1 OUTPAR3 R2 OUTPAR4 12(SP)
14
6/2/2015 Motorola Blackfin Comparison Part 1, Copyright M. Smith, ECE, University of Calgary, Canada 14 Main 68K function concept ulong DetermineSpeed(ulong wheelDiameter, ulong clockFrequency) { // Get to known position on magnetic sensor signal unsigned long discard_count; unsigned long count_high, count_low; SetupInterface( ); discard_count = CountClockASM(while_MagneticSensorHigh); discard_count = CountClockASM(while_MagneticSensorLow); count_high = CountClockASM(while_MagneticSensorHigh); count_low = CountClockASM(while_MagneticSensorLow); return CalculateSpeedASM(count_high + count_low, wheelDiameter, clockFrequency); } _DetermineSpeed: LINK A6, -16 MOVE.L D4, 12(SP) JSR _SetupInterface MOVE.L #MASKMAG, 0(SP) JSR _CountClockASM MOVE.L #0, 0(SP) JSR _CountClockASM MOVE.L #MASKMAG, 0(SP) JSR _CountClockASM MOVE.L D0, D4 ; count_high MOVE.L #0, 0(SP) JSR _CountClockASM ADD.L D0, D4 ; high + low. MOVE.L D4, 0(SP) MOVE.L 8(FP), 4(SP) MOVE.L 12(FP), 8(SP) JSR _CalculateSpeedASM ; Return in D0 MOVE.L 12(SP), D4 UNLINK A6 RTS
15
6/2/2015 Motorola Blackfin Comparison Part 1, Copyright M. Smith, ECE, University of Calgary, Canada 15 Main Blackfin function concept ulong DetermineSpeed(ulong wheelDiameter, ulong clockFrequency) { // Get to known position on magnetic sensor signal unsigned long discard_count; unsigned long count_high, count_low; SetupInterface( ); discard_count = CountClockASM(while_MagneticSensorHigh); discard_count = CountClockASM(while_MagneticSensorLow); count_high = CountClockASM(while_MagneticSensorHigh); count_low = CountClockASM(while_MagneticSensorLow); return CalculateSpeedASM(count_high + count_low, wheelDiameter, clockFrequency); } _DetermineSpeed: LINK 20 [FP + 8] = R0; [FP + 12] = R1; // Save INPARS [SP + 16] = R4; CALL _SetupInterface; R0 = MASKMAG; CALL _CountClockASM; R0 = 0; CALL _CountClockASM R0 = MASKMAG; CALL _CountClockASM; R4 = R0; // count_high R0 = 0; CALL _CountClockASM R0 = R0 + R4; // high + low. R1 = [FP + 8]; // old INPAR1 R2 = [FP + 12]; // old INPAR2 CALL _CalculateSpeedASM // Return in R0 [SP + 16] = R4; UNLINK RTS
16
6/2/2015 Motorola Blackfin Comparison Part 1, Copyright M. Smith, ECE, University of Calgary, Canada 16 Compare 68K and Blackfin _DetermineSpeed: LINK A6, -16 MOVE.L D4, 12(SP) JSR _SetupInterface MOVE.L #MASKMAG, 0(SP) JSR _CountClockASM MOVE.L #0, 0(SP) JSR _CountClockASM MOVE.L #MASKMAG, 0(SP) JSR _CountClockASM MOVE.L D0, D4 ; count_high MOVE.L #0, 0(SP) JSR _CountClockASM ADD.L D0, D4 ; high + low. MOVE.L D4, 0(SP) MOVE.L 8(FP), 4(SP) MOVE.L 12(FP), 8(SP) JSR _CalculateSpeedASM ; Return in D0 MOVE.L 12(SP), D4 UNLINK A6 RTS _DetermineSpeed: LINK 20 [FP + 8] = R0; [FP + 12] = R1; // Save INPARS [SP + 16] = R4; CALL _SetupInterface; R0 = MASKMAG; CALL _CountClockASM; R0 = 0; CALL _CountClockASM R0 = MASKMAG; CALL _CountClockASM; R4 = R0; // count_high R0 = 0; CALL _CountClockASM R0 = R0 + R4; // high + low. R1 = [FP + 8]; // old INPAR1 R2 = [FP + 12]; // old INPAR2 CALL _CalculateSpeedASM // Return in R0 [SP + 16] = R4; UNLINK RTS
17
6/2/2015 Motorola Blackfin Comparison Part 2, Copyright M. Smith, ECE, University of Calgary, Canada 17 extern “C” void SetupInterface(void); MotorolaBlackfin Direction register 0 = input, 1 = output PADDR 8-bits FIO_DIR 16-bits Interrupt control bits in PACR, PGCR control H1, H2 FIO_MASKA_D on any bit Enable input (Power save issue) FIO_INEN on any bit Polarity bits in PGCR control H1, H2 FIO_POLAR on any bit Edge / Level sensitivity bits in PGCR control H1, H2 FIO_EDGE FIO_BOTH on any bit Magnetic signal Clock signal Bit 0 MASKMAG 0x1 Bit 1 MASKCLK 0x2 Bit 10 MASKMAG 0x200 Bit 11 MASKCLK 0x400
18
6/2/2015 Motorola Blackfin Comparison Part 2, Copyright M. Smith, ECE, University of Calgary, Canada 18 extern “C” void SetupInterface(void); SPECIFICS MotorolaBlackfin Magnetic signal Clock signal Bit 0 MASKMAG 0x1 Bit 1 MASKCLK 0x2 Bit 10 MASKMAG 0x200 Bit 11 MASKCLK 0x400 Direction register 0 = input, 1 = output D0 PADDR MASK OFF BITS 1, 0 PADDR D0 R0 FIO_DIR MASK OFF BITS 10, 11 FIO_DIR R0 Interrupt control bits in PACR, PGCR control H1, H2 R0 FIO_MASKA_D MASK OFF BITS 10, 11 FIO_MASKA_D R0 Enable input (Power save issue) R0 FIO_INEN OR BITS 10, 11 FIO_INEN R0 Polarity bits in PGCR control H1, H2 R0 FIO_POLAR MASK OFF BITS 10, 11 FIO_POLAR R0 Edge / Level sensitivity bits in PGCR control H1, H2 FIO_EDGE FIO_BOTH MASK OFF BITS 10, 11
19
6/2/2015 Motorola Blackfin Comparison Part 1, Copyright M. Smith, ECE, University of Calgary, Canada 19 In class exercise – Write 68K code for extern “C” void SetupInterface(void);
20
6/2/2015 Motorola Blackfin Comparison Part 1, Copyright M. Smith, ECE, University of Calgary, Canada 20 In class exercise – Write Blackfin code for extern “C” void SetupInterface(void);
21
6/2/2015 Motorola Blackfin Comparison Part 1, Copyright M. Smith, ECE, University of Calgary, Canada 21 Information taken from Analog Devices On-line Manuals with permission http://www.analog.com/processors/resources/technicalLibrary/manuals/ http://www.analog.com/processors/resources/technicalLibrary/manuals/ Information furnished by Analog Devices is believed to be accurate and reliable. However, Analog Devices assumes no responsibility for its use or for any infringement of any patent other rights of any third party which may result from its use. No license is granted by implication or otherwise under any patent or patent right of Analog Devices. Copyright Analog Devices, Inc. All rights reserved.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.