Lab. 1 – Earlier Tasks. Needed by both application and demonstration lab. streams 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 prelab- quiz. You CAN’T access the web or use your partner’s notes
2 /25 Laboratory 1 – Early tasks 1.Download the C++ Talk-through program. Check that you can hear the audio output 2.Convert the ProceessDataCPP( ) code into assembly code ProcessDataASM( ) Check that you can hear the audio output 3.Routine for initializing the PF lines (programmable flags) Use the provided tests to check your code 4.Develop the ReadProgrammableFlagsASM( ) to read the switches Use switch information according to laboratory stream requirements
3 /25 Set up for Tasks 1 and Task 2 AUDIO-IN AUDIO-OUT
4 /25 Task 1 Download audio-talk-through program If you have not already done so, download and expand ENCM415Directory2006.zip file so that you have the correct directory. structure and test driven development environment needed for Laboratory 1. ENCM415Directory2006.zip Download and expand the files in CPP_Talkthrough.zip into your Lab1 directory.CPP_Talkthrough.zip 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.
5 /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)
6 /25 The talk through program (C++) 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 while (1) { /* Wait for messages */ } ACTIVATE the A/D and D/A interrupts Every 1 / 44,000 s Store A/D register value (DMA) into memory Call ProcessDataCPP( ) or ProcessDataASM( ) Load memory (DMA) into D/A register Set messages and flags to main( ) main( ) ISR -- Interrupt Service Routine
7 /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 while (1) { /* */ } } 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 while (1) { /* Wait for messages */ } ACTIVATE the A/D and D/A interrupts
8 /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
9 /25 Task 2 -- ProcessDataASM( ) extern volatile int iChannel0LeftIn, ………….; // #include "Talkthrough.h" // void Process_DataASM(void) // { //iChannel0LeftOut = iChannel0LeftIn; //iChannel0RightOut = iChannel0RightIn; //iChannel1LeftOut = iChannel1LeftIn; //iChannel1RightOut = iChannel1RightIn; // } TASK 2 – Replace ProcessDataCPP( ) by ProcessDataASM( ) and check that it works Need an audio in signal (Ipod, CD player) Need ear-phones to check output signal.extern _iChannel0LeftIn;.section program.global _Process_DataASM__Fv;
10 /25 Task 2 -- Convert ProcessDataCPP( ) to ProcessDataASM ( ) 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
11 /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
12 /25 How we are building the volume controller SWITCHES ON FRONT PANEL PROGRAMMABLE FLAGS FIO_FLAG_D Register YOUR PROGRAM RUNNING ON THE BLACKFIN LED LIGHTS ON FRONT PANEL LED-CONTROLREGISTER EBIU INTERFACE ProcessDataASM( ) subroutine A/D D/A Interrupt routine D/A EAR PHONES A/D IPOD CD int ReadSwitches( )void WriteLED(int )
13 /25 Set-up for Tasks 3 and 4 1.De-activate Visual DSP 2.Power down Blackfin 3.Connect power to “special Blackfin interface” connector 4.Connect 50-pin cable to logic-lab 5.Connect 50-pin cable to Blackfin 6.Power up logic lab. station 7.Power up Blackfin 8.Reactivate Visual DSP 9.Check that station works using “Lab. 1 test-executable”
14 /25 Special “power-connector” for Blackfin interface on logic lab. station
15 /25 Special “power-connector” for Blackfin interface on logic lab. station
16 /25 Connect 50-pin cable to Blackfin
17 /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
18 /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
19 /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
20 /25 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 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 later Making sure that the FIO_DIR is correct for LAB. 1 – NOTE may need to change for later labaoratories
21 /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
22 /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
23 /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.
24 /25 Task 4 – Demonstration stream Final laboratory requirements Wait for button1 (SW1 – PF8) to be pressed and released (ReadButtonASM() ), then play the sound at half-volume. Wait for button2 (SW2 – PF9) to be pressed and released, play the sound at normal volume Each time button3 (SW3 – PF10) is pressed and released, transfer a known value from an array to the LED display (WriteLEDASM( ) ) and check that the expected value is displayed (ReadLEDASM( ) ) Wait for button4 t (SW4 – PF11) o be pressed and released, quit the program (turn off the sound and stop the processor) Build Initialize_ProgrammableFlagsASM ( ) Modify main( ) and ProcessDataASM( ) so that button-operation and volume operation works MUST HAVE 50 pin cable connected between logic board and Blackfin Logic board power supply must be turned on
25 /25 Task 4 – Application stream 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
26 /25 #include.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 ReadProgrammableFlagsASM( )
27 /25 How to use int ReadProgrammableFlagsASM( ) int switch_setting = ReadProgrammableFlagsASM( ) ; SWITCHES ON FRONT PANEL PROGRAMMABLE FLAGS FIO_FLAG_D Register int ReadSwitches( ) (FIO_POLAR register = 0) All switches unpressed Binary Pattern in FIO_FLAG_D register B????0000???????? All switches pressed Binary Pattern in FIO_FLAG_D register B????1111???????? Binary ? Means – we don’t know what the answer is
28 /25 How to use int ReadProgrammableFlagsASM( ) int switch_setting = ReadProgrammableFlagsASM( ) ; SWITCHES ON FRONT PANEL PROGRAMMABLE FLAGS FIO_FLAG_D Register int ReadSwitches( ) (FIO_POLAR register = 0) All switches unpressed Binary Pattern in FIO_FLAG_D register BXXXX0000XXXXXXXX All switches pressed Binary Pattern in FIO_FLAG_D register BXXXX1111XXXXXXXX Binary X Means – we don’t know what the answer is – and don’t care
29 /25 Echoing the switches to the LED Code in main( ) – written in C++ int main( ) { InitializeSwitchInterface( ); // Check Lab. 1 for “exact name needed” InitializeLEDInterface( ); #define SWITCHBITS 0x0F00 // 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); }
30 /25 Practice example -- Rewrite the code so that loop stops if all the switches are pressed at the same time int main( ) { InitializeSwitchInterface( ); // Check Lab. 1 for “exact name needed” InitializeLEDInterface( ); #define SWITCHBITS 0x0F00 // 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); }
31 /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( ); // Check Lab. 1 for “exact name needed” InitializeLEDInterface( ); #define SWITCHBITS 0x0F00 // 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); }
32 /25 Laboratory 1 – Tasks 1 to 4 in detail 1.Download the C++ Talk-through program. Check that you can hear the audio output 2.Convert the ProceessDataCPP( ) code into assembly code ProcessDataASM( ) Check that you can hear the audio output 3.Routine for initializing the PF lines (programmable flags) Use the provided tests to check your code 4.Develop the ReadProgrammableFlagsASM( ) to read the switches Use switch information according to laboratory stream requirements