310 likes | 412 Vues
Lab. 1 – Required Tasks. For more details – see the Lab. 1 web-site. Laboratory 1 – Tasks. Download the C++ Talk-through program. Board check -- Check that you can hear the audio output Develop and test the code for initializing the Flash Memory and writing to the LED’s
E N D
Lab. 1 – Required Tasks. For more details – see the Lab. 1 web-site
Laboratory 1 – Tasks • Download the C++ Talk-through program. • Board check -- Check that you can hear the audio output • Develop and test the code for initializing the Flash Memory and writing to the LED’s • Use the provided tests to check your code • Routine for initializing the PF GPIO lines (programmable flags) • Use the provided tests to check your code • Develop the ReadProgrammableFlagsASM( ) to read the switches • Use the provided tests to check your code • Develop the Read-and-Store switch values in C++ and ASM – use to drive the car
Set up for Task 1 AUDIO-IN AUDIO-OUT
Task 1Download audio-talk-through program • If you have not already done so, download and expand ENCM511Directory.zip file so that you have the correct directory. structure and test driven development environment needed for Laboratory 1 and Assignments1. • Download and expand the files in CPP_Talkthrough.zip into your AudioDemo directory. • Build an AudioDemo Blackfin project in your AudioDemo directory and add the (provided) files into the project -- 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 AudioDemo.dxe executable and check that the talk through program is working. • This task demonstrated your ability to build VDSP Blackfin projects and run the code.
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)
The talk through program (C++) Prepare to run C++ code (before you get to main( )) Every1 / 44,000 s Set up the EBIUExternal Bus Unit Store A/D register value(DMA) into memory Use EBIUto initialize A/D and D/A Call ProcessDataCPP( )or ProcessDataASM( ) SET UP theA/D and D/A interrupts Set messages and flagsto main( ) ACTIVATE the A/D and D/A interrupts Load memory (DMA) into D/A register while (1) {/* Wait for messages */ } main( ) ISR -- Interrupt Service Routine
main( ) The system prepares theprocessor to run C++ code(before you get to 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) { /* */ } } Set up the EBIUExternal Bus Unit Use EBIUto initialize A/D and D/A SET UP theA/D and D/A interrupts ACTIVATE the A/D and D/A interrupts while (1) {/* Wait for messages */ }
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 Voice-activated radio-controlled car works by modifying the ProcessData( ) subroutine
Building a voice activated radio controlled car -- 4 Threads at least SWITCHES ON FRONT PANEL“INPUT COMMANDS: LED LIGHTS ON FRONT PANEL“CONTROLSIGNALS TO RF TRANS: PROGRAMMABLE FLAGS LED-CONTROLREGISTER FIO_FLAG_D Register EBIU INTERFACE YOUR PROGRAM RUNNING ON THE BLACKFIN int ReadSwitches( ) void WriteLED(int ) ProcessDataASM( ) subroutine VOICE A/D D/A EARPHONES A/D D/A Interrupt routine
Set-up for “Laboratory 1” interfacing.“Make the switches work” • 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”
Special “power-connector” for Blackfin interface on logic lab. station
Special “power-connector” for Blackfin interface on logic lab. station • Picture of the “power connector” taken with a camera with a finger-print on the lens. Check that has not been stolen. Extras in your lab. kit is needed (perhaps)
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 – toggle switches and LEDs CHEK each lab. As fuses can just wear out
Task – 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 FLAGData register
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
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 Design Error “Changes all pins
Setting FIO_DIR to zero for “ONLY” pins 8, 9, 10 and 11. Other pins unchanged
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
Making sure that the FIO_INEN is correct for enable of pins 8 to 11 Write the Blackfin assembly language instruction(s) to load the address of the internal programmable flag FIO_INEN register into pointer register P1 – then ENABLE the Blackfin PF lines as inputs Design Error “Changes all pins
Setting FIO_INEN to one for “ONLY” pins 8, 9, 10 and 11. Other pins unchanged
Registers used to control PF pins • Flag Data register (FIO_FLAG_D) • Used to read the PF bits as an input -- (1 or 0) • Need to read pins PF11 to PF8, ignore all other pins values
Task – Setting up the programmable flag interface • Follow the instructions carefully • FIO_DIR – direction register – write 0’s to bits 8 to 11 • FIO_INEN – input enable register – write 1’s to bits 8, 9, 10, 11 • Other registers “bits” leave “unchanged: • There are 6 registers in total • To provide a screen dump of the test result to show your code works • Use PRT-SCR button and then paste in .doc file.
How to use int ReadBlackFinGPIOFlagsASM( ) int GPIO_setting = ReadBlackfinGPIOFlagsASM( ); (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???????? SWITCHES ON FRONT PANEL PROGRAMMABLE FLAGS FIO_FLAG_D Register int ReadSwitches( ) Binary ? Means – we don’t know what the answer is
How to use int ReadBlackfinGPIOFlagsASM( ) int GPIO_setting = ReadBlackfinGPIOFlagsASM( ); (FIO_POLAR register = 0) All switches unpressed Binary Pattern in FIO_FLAG_D register B XXXX0000XXXXXXXX All switches pressed Binary Pattern in FIO_FLAG_D register B XXXX1111XXXXXXXX SWITCHES ON FRONT PANEL PROGRAMMABLE FLAGS FIO_FLAG_D Register int ReadSwitches( ) Binary X Means – we don’t know what the answer is – and don’t care
Echoing the switches to the LEDCode in main( ) – written in C++ int main( ) { InitializeGPIOInterface( ); // Check Lab. 1 for “exact name needed” InitializeFlashLEDInterface( ); // Check Lab. 1 for “exact name needed” #define SWITCHBITS 0x0F00 // Look in MIPs notes about // using a mask and the // AND bit-wise operation // to select “desired bits” while (1) { // Forever loop int GPIO_value = ReadBlackfinGPIOFlagsASM ( ); int desired_bits = GPIO_value & SWITCHBITS; int LED_light_values = desired_bits >> 8; // Bits in wrong position WriteFlashLEDLights(LED_light_values); // to display on LEDS } }
Avoid this common mistake • Many seem to think that the switch routine returns 1 if SW1 is pressed, 2 if SW2 is pressed, 3 if SW3 is pressed. • This is NOT correct as the switch routine has to be able to return 16 different values • Value meaning SW1 pressed, SW2, SW3, SW4 not pressed (0x0100) • Value meaning SW1 and SW4 pressed with SW2 and SW3 not pressed (0x0900)
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 (???? ) { // conditional loop int GPIO_value = Read ReadBlackfinGPIOFlagsASM ( ); int desired_bits = GPIO_value & SWITCHBITS; int LED_light_values = desired_bits >> 8; // Bits in wrong position WriteFlashLEDLightsASM(LED_light_values); ???? } }
Laboratory 1 – Tasks • Download the C++ Talk-through program. • Board check -- Check that you can hear the audio output • Develop and test the code for initializing the Flash Memory and writing to the LED’s • Use the provided tests to check your code • Routine for initializing the PF GPIO lines (programmable flags) • Use the provided tests to check your code • Develop the ReadProgrammableFlagsASM( ) to read the switches • Use the provided tests to check your code • Develop the Morse code program in C++ and ASM