Lab1Task1to4

advertisement
Lab. 1 – Task 1 to 4 details
For more details – see the Lab. 1 web-site
There will be a 20 min prelab-quiz (based on
Assignment 1 and 2) at the start of the lab. session
You can make use of YOUR class notes during the prelabquiz. You CAN’T access the web or use your partner’s notes
Laboratory 1 – Tasks 1 to 4 in detail
1.
Download the C++ Talk-through program.

2.
Convert the ProceessDataCPP( ) code into assembly
code ProcessDataASM( )

3.
Check that you can hear the audio output
Routine for initializing the PF lines (programmable
flags)

4.
Check that you can hear the audio output
Use the provided tests to check your code
Develop the ReadProgrammableFlagsASM( ) to read
the switches

MUTE-BUTTON -- Develop code so that if switch 1 is pressed,
the sound stops. If switch 1 is released, then the sound starts
again.
2 /25
Set up for Tasks 1 and Task 2
AUDIO-IN
AUDIO-OUT
3 /25
Task 1
Download audio-talk-through program
 If you have not already done so, download and expand
ENCM415Directory.zip file so that you have the correct directory.
structure and test driven development environment needed for
Laboratory 1.
 Download and expand the files in CPP_Talkthrough.zip into your
Lab1 directory.
 Add the CPP_Talkthrough project in your Lab. 1 directory to the
VisualDSP environment -- compile and link.
 Download the executable (.dxe) file onto the BF533 processor.
 Hook up your CD or IPOD output to the CJ2 stereo input.
 Hook up your ear-phones to the CJ3 stereo output.
 Run the CPP_Talkthrough.dxe executable and check that the talk
through program is working.
4 /25
Question
What is a “talk-through program”?
 Clear example of applying the first two rules of
assembly language programming
 Rule 1: If you have a choice – don’t use
assembly code
It takes as much time (and SOST) to “design, code,
review, test and maintain” one line of C++ code as it
does assembly code, but one line of C++ often can do
more
 Rule 2: If somebody has a working example,
cannibalize it for your own work (if legal)
5 /25
The talk through program
Prepare to run C++ code
(before you get to main( ))
Set up the EBIU
External Bus Unit
Use EBIU
to initialize A/D and D/A
SET UP the
A/D and D/A interrupts
ACTIVATE the
A/D and D/A interrupts
(C++)
Every
1 / 44,000 s
Store A/D register value
(DMA) into memory
Call ProcessDataCPP( )
or ProcessDataASM( )
Set messages and flags
to main( )
Load memory (DMA)
into D/A register
while (1) {
/* Wait for messages */ }
main( )
ISR -- Interrupt Service Routine6 /25
main( )
int main(void)
{
sysreg_write(reg_SYSCFG, 0x32);
//Initialize System Configuration Register
Init_EBIU();
Init_Flash();
Init1836();
Init_Sport0(); // Serial PORT
Init_DMA();
Init_Sport_Interrupts();
Enable_DMA_Sport0(); // Serial PORT
Prepare to run C++ code
(before you get to main( ))
Set up the EBIU
External Bus Unit
Use EBIU
to initialize A/D and D/A
SET UP the
A/D and D/A interrupts
ACTIVATE the
A/D and D/A interrupts
while (1) { /* */ }
}
while (1) {
/* Wait for messages */ }
7 /25
ProcessDataCPP( )
#include "Talkthrough.h"
extern volatile int iChannel0LeftIn, iChannel0LeftOut;
void Process_DataCPP(void)
{
iChannel0LeftOut = iChannel0LeftIn;
iChannel0RightOut = iChannel0RightIn;
iChannel1LeftOut = iChannel1LeftIn;
iChannel1RightOut = iChannel1RightIn;
}
TASK 1 – Download the Talkthrough program and check that it works
Need an audio in signal (Ipod, CD player)
Need ear-phones to check output signal
8 /25
Task 2 -- ProcessDataASM( )
.extern _iChannel0LeftIn;
.section program
extern volatile int iChannel0LeftIn, ………….;
// #include "Talkthrough.h"
.global _Process_DataASM__Fv;
// void Process_DataASM(void)
// {
//
iChannel0LeftOut = iChannel0LeftIn;
//
iChannel0RightOut = iChannel0RightIn;
//
iChannel1LeftOut = iChannel1LeftIn;
//
iChannel1RightOut = iChannel1RightIn;
// }
TASK 2 – Replace ProcessDataCPP( ) by ProcessDataASM( )
and check that it works
This is essentially Q2 from assignment 2
Need an audio in signal (Ipod, CD player)
Need ear-phones to check output signal
9 /25
Task 2 -- Convert ProcessDataCPP( ) to
ProcessDataASM () – Assign. 2 Q2
 In talkthrough.h. add a prototype for your assembly code function
Process_DataASM;
 In ISR.cpp change to
// call function that contains user code
#if 0
Process_DataCPP(); // Use the C++ version
#else
Process_DataASM(); // C assembly code routines especially developed
for Lab. 1
#endif
 Right-click on ProcessDataCPP.cpp entry. Use "FILE OPTIONS“ to exclude
linking
 Use PROJECT | clean project
 Add your ProcessDataASM.asm file to the project, recompile and link.
Check that your code works
 More details on the Lab. 1 web pages
10 /25
Things to remember
 Both MIPS and Blackfin are “RISC” type of processors
 They have a “LOAD / STORE” architecture
iChannel0LeftOut = iChannel0LeftIn;
BECOMES
Set P0 to point to address iChannel0LeftIn
Move memory value into register
R0 = [P0]; LOAD
Set P1 to point to address iChannel0Out
Move register value into memory
[P1] = R0; STORE
REMEMBER – addresses and int, unsigned int values together with
long int, unsigned long int values are 32-bits on this processor
11 /25
How we are building the volume controller
SWITCHES ON FRONT PANEL
LED LIGHTS ON FRONT PANEL
PROGRAMMABLE FLAGS
LED-CONTROLREGISTER
FIO_FLAG_D Register
EBIU INTERFACE
int ReadSwitches( )
void WriteLED(int )
YOUR PROGRAM RUNNING ON THE BLACKFIN
ProcessDataASM( ) subroutine
IPOD
CD
A/D
A/D D/A Interrupt routine
D/A
EAR
PHONES
12 /25
Set-up for Tasks 3 and 4
1.
2.
3.
4.
5.
6.
7.
8.
9.
De-activate Visual DSP
Power down Blackfin
Connect power to “special Blackfin interface”
connector
Connect 50-pin cable to logic-lab
Connect 50-pin cable to Blackfin
Power up logic lab. station
Power up Blackfin
Reactivate Visual DSP
Check that station works using “Lab. 1 test-executable”
13 /25
Special “power-connector” for Blackfin
interface on logic lab. station
14 /25
Special “power-connector” for Blackfin
interface on logic lab. station
15 /25
Connect 50-pin cable to Blackfin
16 /25
Connect 50-pin cable to logic lab
 Make sure that
all 50-pin
connections are
secure and
proper.
 Power up the
logic lab.
station and
check that is
working
17 /25
Task 3 – Initialize the Programmable flag
interface – 16 I/O lines on the Blackfin
 Warning – could burn out the Blackfin processor if
done incorrectly
 You need to set (store a known value to) a number
of Blackfin internal registers
 Most important ones
 FIO_DIR – Data DIRection – 0 for input ****
 FIO_INEN – INterface ENable – 1 for enabled
 FIO_FLAG_D – Programmable FLAG Data register
18 /25
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
19 /25
Making sure that the FIO_DIR is correct
for LAB. 1 – NOTE may need to change
for later labaoratories
Write the Blackfin assembly language instruction(s) to load the
address of the internal programmable flag FIO_DIR register into
pointer register P1 – then set the Blackfin PF lines to act as inputs
#include <defsBF533.h>
#include <macros.h>
P1.L = lo (FIO_DIR);
P1.H = hi (FIO_DIR);
// Check the requirements – need to have all input
// Manual says “setting a line for input means setting bit values to 0”
R0 = 0;
W[P1] = R0;
ssync;
// Force Blackfin to do the write (store) NOW not later20 /25
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
21 /25
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
22 /25
Task 3 – Setting up the programmable
flag interface
 Follow the instructions carefully
 FIO_DIR – direction register – write 0’s to all bits
 In later laboratories will be writing 1’s to some bits and writing 0’s
to other bits – DO IT RIGHT
 FIO_INEN – input enable register – write 1’s to bits 8, 9,
10, 11
 Other registers set to 0
 There is a test program (Weds lecture) that will enable
you to check your code – provide a screen dump of the
test result to show it works
 Use PRT-SCR button and then paste in .doc file.
23 /25
Task 4 – Read the switches on the front
pannel
 Final laboratory requirements
 SW1 connected to PF8 -- Mute button (This task)
 SW2 connected to PF9 -- Gargle button (Task 5)
 SW3 connected to PF10 -- Volume up (Task 7)
 SW4 connected to PF11 -- Volume down (Task 7)
 Build Initialize_ProgrammableFlagsASM ( )
 Modify main( ) and ProcessDataASM( ) so that MUTE-operation
works
 MUST HAVE 50 pin cable connected between logic board and
Blackfin
 Logic board power supply must be turned on
24 /25
int ReadProgrammableFlags( )
#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
25 /25
How to use int ReadProgrammableFlags( )
int switch_setting = ReadProgrammableFlags( );
SWITCHES ON FRONT PANEL
(FIO_POLAR register = 0)
All switches unpressed
PROGRAMMABLE FLAGS
Binary Pattern in FIO_FLAG_D
register
B????0000????????
FIO_FLAG_D Register
int ReadSwitches( )
Binary ? Means – we don’t know
what the answer is
All switches pressed
Binary Pattern in FIO_FLAG_D
register
B????1111????????
26 /25
How to use int ReadProgrammableFlags( )
int switch_setting = ReadProgrammableFlags( );
SWITCHES ON FRONT PANEL
(FIO_POLAR register = 0)
All switches unpressed
PROGRAMMABLE FLAGS
Binary Pattern in FIO_FLAG_D
register
BXXXX0000XXXXXXXX
FIO_FLAG_D Register
int ReadSwitches( )
Binary X Means – we don’t know
what the answer is – and don’t care
All switches pressed
Binary Pattern in FIO_FLAG_D
register
BXXXX1111XXXXXXXX
27 /25
Echoing the switches to the LED
Code in main( ) – written in C++
int main( ) {
InitializeSwitchInterface( );
InitializeLEDInterface( );
#define SWITCHBITS 0x0F00
// Check Lab. 1 for “exact name needed”
// Looking in MIPs notes about
//
using a mask and the
//
AND bit-wise operation
//
to select “desired bits”
while (1) {
// Forever loop
int switch_value = ReadProgrammableFlagsASM( );
int desired_bits = switch_value & SWITCHBITS;
int LED_light_values = desired_bits >> 8;
// Bits in wrong position
WriteLEDLights(LED_light_values);
}
}
28 /25
Practice example -- Rewrite the code so
that loop stops if all the switches are
pressed at the same time
int main( ) {
InitializeSwitchInterface( );
InitializeLEDInterface( );
#define SWITCHBITS 0x0F00
// Check Lab. 1 for “exact name needed”
// Looking in MIPs notes about MASKS
while (1) {
// Forever loop
int switch_value = ReadProgrammableFlagsASM( );
int desired_bits = switch_value & SWITCHBITS;
int LED_light_values = desired_bits >> 8;
// Bits in wrong position
WriteLEDLights(LED_light_values);
}
}
29 /25
Practice example 2 -- Rewrite the code so that
(1) loop stops if all the switches are pressed at the same time
and
(2) if SW1 is pressed then the volatile int mute_on variable is set
to 1, otherwise it is set to 0
(3) Always show (in the lights) the last value of the switches
int main( ) {
InitializeSwitchInterface( );
InitializeLEDInterface( );
#define SWITCHBITS 0x0F00
// Check Lab. 1 for “exact name needed”
// Looking in MIPs notes about MASKS
while (1) {
// Forever loop
int switch_value = ReadProgrammableFlagsASM( );
int desired_bits = switch_value & SWITCHBITS;
int LED_light_values = desired_bits >> 8;
// Bits in wrong position
WriteLEDLights(LED_light_values);
}
}
30 /25
Laboratory 1 – Tasks 1 to 4 in detail
1.
Download the C++ Talk-through program.

2.
Convert the ProceessDataCPP( ) code into assembly
code ProcessDataASM( )

3.
Check that you can hear the audio output
Routine for initializing the PF lines (programmable
flags)

4.
Check that you can hear the audio output
Use the provided tests to check your code
Develop the ReadProgrammableFlagsASM( ) to read
the switches

MUTE-BUTTON -- Develop code so that if switch 1 is pressed,
the sound stops. If switch 1 is released, then the sound starts
again.
31 /25
Download