Step CCES and selectpeople.ucalgary.ca/~smithmr/2015webs/encm511_15/15_Lectures/1… · 6) Click...
Transcript of Step CCES and selectpeople.ucalgary.ca/~smithmr/2015webs/encm511_15/15_Lectures/1… · 6) Click...
Building a COFFEE POT simulation on CCESS 2.0.0 for Blackfin BF533
Introduction for Lab0 and Assignment 1CCES is based on Eclipse
There is an ARM IAR plug‐in for Eclipsewhich allows the same approach to occur there
(Discovery board and MPEG boards)
Starting a CCES project• Step 1 – Activate CCES and select H:ENCM511_2015Workspace directory and then dismiss “Help” window
• Step 2 – Set the project Name• Step 3 – Set processor type
• Step 4 – Take a deep breath to control the excitement
Build a CCES project continued – 5 to 75) Click on Configure Project then Template code screen
– Change to “add default” C++ – You will need to delete the project and start again
if you click on default C because of the different calling procedures found between C and C++ (Name mangling)
– Click Finish
6) Click FINISH on Projects and Settings Window” (Slow when writing to USB)
7) Click on little triangle next to the Project name CoffeePot_2015Assignment, and expand all directories
– also click on Console tab– Click on app_startup.s file
Possible Quiz question • What is purpose of the C++ files automatically
placed inside the directory startup_ldf?• What is the tab Startup Code / LDF?• What happens if you click on system.svc?
Adding a folder, find LDF(Do same if
using Eclipse IAR MIPS plugin)8) Right click on CoffeePot_2015Assignment
– Select NEW |Folder – MAGIC stuff associated with
USE_CCES_GUI simulator (W.A.I.L.)• Use folder name “SCADA TRANSMISSIONS”
(Name change has occurred during design and coding)
9) MAGIC – right click on system.svc file and OPEN
– Click on tab – LDF– W.A.I.N. ‐‐Will need this when we want to
“Add a simulated coffeepot to the address and data busses of the “real Blackfin processor.
– W.A.I.L. – How does changing the LDF match to “REAL” hardware
LDF – loader descriptor file – describes where the LINKER places program code and program data in the microprocessor memory
CoffeePot_2015Assignment
SCADA TRANSMISSION
Add “your” files to the project 10) Right click on “src” folder icon
• Rename CoffeePot_2015Assignment1.cpp to CoffeePot_main.cpp – go inside file and comment out “main( )” (pretend we forgot to write a “main”)
• Rename CoffeePot_2015Assignment1.h to CoffeePot.h(Causes hidden bug – W.U.W.N.T.F.L.)
• NEW | File from template • MyCoffeePotFunctions.h• DoSimulation_CPP.cpp• DoSimulation_ASM.asm• MyCoffeePotFunctionsCPP.cpp
• Using _CPP.cpp and _ASM_asmis part if my PSP (M.I.M.A.M.)
• All these files are currently empty and need to be filled
• Cut‐and‐pasting from lecturepdf works (with a caution)
Risk management – Learn a little aboutwhat the correct ASM format looks like• Click on DoSimulation_ASM.asm icon to open the file inside the editor
• Add the information we had from previous presentation – see next slide (Cut‐and‐paste from pdf)
• Right click on DoSimulation_ASM.asm icon and select –Build Selected File(s)– Click on Console tab to see errors– Expect errors – should see them as markers against each line in editor
– Comment out all error lines– Build with no errors
ASM code entered in showing requiredcourse formatting (Before we clicked BUILD)
DO A CODE REVIEW BEFORE GOING FURTHERSomething is DEFINITELY wrong here. There is a change of text colour
Looks “sort of good” as is recognized – probably correct syntax
SyntaxDefects found after build
Meansproblem at assemblersource file
DEFECT RECOGNIZED BY COMPILER
NOT YET REACHED THELINKER STAGEwhich groups files together into executable)stage
Look up “correct” assembly code syntax
• Use last year’s notes• Or Download BF533 Assembly Language manualhttp://www.analog.com/en/processors‐dsp/blackfin/products/manuals/resources/index.html
– Link is available from ENCM511 website
WE HAVE PASSED THE COMPILER STAGE
Right Click on project NameBuild Project – results in “LINKER error”Linker wants to load functions into memory – but can’t find them
Understanding linker errors
• CCES can handle many processors or multi‐core systems (p0, p1, p2 etc..– This LINKER error message says the “processor p0” code is missing two functions
• Different from a COMPILER error message which might complain about compiler error with REGISTER P0
– .doj extension indicates an object file – a file that has undergone the conversion C++ asm almost machine code or asm almost machine code(performed by compiler and assembler) (performed by assembler)
– Many .doj files linked together form executable program .dxe that can be downloaded to the board (or run in the BF533 simulator)
– Function UpDateSimulationDisplay needed in file DoSimulation_ASM.doj (object file you wrote)
– Function main( ) needed in file app_startup.doj• app_startup.doj is an object file from a C++ / C / asm file you did not write, but was placed
into your project automatically when you made a project • Probably a system file that makes the C++ environment work – do not change or delete this
Let’s add a “does‐system‐still‐work”main( ) to CoffeePot_main.cpp
• Before clicking “Build project”– Do a CODE REVIEW BEFORE compiling (PSP ‐‐ Personal Software Process)– Fix all syntax errors that editor is telling you about– The number of syntax not found – indicates possible logical mistakes
(now DEFECTS) left behind in your code – not found by you or compiler
LOGICAL DEFECTS willtake MUCH timeto correct as youDON’T KNOWwhen you made them,where they are,and what “knock‐on”effect they are having
Build is improving Coding mistakes found before moving onto next
phase are called Coding ErrorsDesign mistakes found before moving onto next phase are called Design Errors.Design mistakes not found before moving onto next phrase are Design DefectsDEFECTS are expensive to fix as you don’t know where you made them
Too many things wrong with the .asmfile – Let’s exclude it for now (not remove it as we need it later)
• Right click on .asm file – select properties
• Click on C++ Build• Click on Settings• Click on “Exclude resource from
build”• Click “OK”• So Project | Clean
(Recommended)• Rebuild Project
(F7)
Outside A301 / A305 ‐‐ you can run project using a simulator session
Inside A301 / A305 ‐‐ you can ALSO run project using a emulator session
• If built with no errors• Right click Project name
– Select Debug as | CrossCore application• In Select Processor window – chose Blackfin ADSP‐BF533 then NEXT
• In Select Connection type ‐‐ choose Emulator then FINISH
• In Create, Manage and Run window, select CoffeePot_.... Program, click APPLY, click DEBUG
• In CONFIRM Perspective Switch SHOULD WE click Yes or No to switching to Debug display mode
HINT: Either close ALL projects except the one you are working on, or carefully check
which project CCES want to run
Now do RUN | RESUME
PSP – Check that program has made a VALID EXIT
When program stops, cclick on white arrow icon,Select current program counterCHECK STOPPED AT ___lib_prog_term
My Personal Software Process (PSP)
• Never have code that occupies more than a screen (Turn screen sideways is a partial fix)
• If code occupies more than a screen – then move code portions into a subroutine / function – Abstraction
• Plan the project in parts• Fix things in order – make code readable
– main( ) – series of calls to functions (flow, 7 +‐ 2); – Add YOUR function prototypes (interface) into header– Add stubs (placeholder code) for all your functions– Compile, Link, Download, Run and(IYAG) move to next stage
Plan Ahead in small chunks
• Tell simulator how many coffeepots to simulate• Check that it did so• Find out where the “plug‐and‐play” control system placed the coffeepots you requested
• Control whether you do simulation using C / C++ code or using Assembly code
• Find out about some hints for doing Assignment 2
• Learn how to recognize some standard LSD issues– LSD are Little Stupid Details causing catastrophic errors
Identify code for
Choice of ASM or C++
Check Sim activated
How to waste BEACOUP de tempin assignments and laboratories
• Ignore all the warning message from the IDE tools that code is wrong
• Just activate “Build project” command and watch the defects appear, and waste time fixing them, rather than avoiding them
Get into PSP habit of “Code Review” as you go along
Fixes and why• Is it a COMPILER, LINKER or RUN‐TIME error
– Need to recognize which – different solutions– Look in Console window for answer (P.Q.1.Q.)
• X‐error ‐‐ Header file not found “CoffeePot2015Assignment1.h” – We changed some file names. – Would using “CCES refactor | rename” option have prevented this error?
• Click on “Bug” icon – Unresolved error– Have not included “system” header file (.h), “your project” header file, or did not do CODE REVIEW and catch typo errors
Compile – Just to show progress
Syntax error – need #endif
Rest are “Unresolved errors” which means “*.h” missing info
Fix “your header” issues
P.Q.Q.COFFEEPTOT1Is a PSP CODE REVIEW “DEFECT” not an PSP “ERROR”
How to recognize other error types and how to fix them
• Init_CoffeePotSimulation( ) used incorrectly– May be due the “2015” update that has occurred
• What other functions are used incorrectly or just unknown
CoffeePot_SimulatorFunctions2015.h Will let you fix these DEFECTS(DEFECTS as got past CODE REVIEW)
• DEFECT ‐‐‐ Humpheys calls them “ERRORS OUT OF PHASE”, meaning mistakes introduced in an earlier part of the project and not caught when introduced
• Moved onto new type of problem
FATAL LINKER ISSUES
NOTE: “NAME MANGLING” is occurring, which is the way C++ handles “Overloaded functions” when generating the “assembly code” needed for the project
Add code choice about doing Coffeepot hardware simulation in C++ or ASM
These are C++ syntax errors associated with we have not told the compiler how to handle all these functions. ** Note compiler only wants “prototype” How to handle information – Not interested in code details
– just the INTERFACE INFORMATION(how to call the function, parameters called)
• Check time – probably stop here • and review and continue in the next lecture
Fixing Linker errors• WIDFI ‐‐Add “Do_Simulation_CPP( ) “STUB” code to fix our linker error
• Add “Library” .dlb (See Lab0 Familiarization) to fix other linker errors
Rebuild projectReady to RUN‐TEST‐OF‐MAIN
• Will get an error about missing “Symbol” USE_CCES_GUI_Delay when you link
• Add the following MAGIC code to “MyCoffeePotFunctions_CPP.cpp” – WAIL
void USE_CCES_GUI_Delay(void) { /* DO NOTHING */ }
“BUILD PROJECT”
Then “DEBUG AS” and see what happens
Runtime Defect caused by mistake in defining “COFFEEPOT1” in enum
• Computers count from 0; USERS count from 1• NOTE: I am running at home using a Blackfin533 simulator session (no hardware needed)
• Fix defect (error out of phase) and run again
Oh!! We all had a tragic accidentRemember: Embedded Systems are safety critical,
so “Practice Safe Programming” habits
• Real World ‐‐ Nobody remembered to plug in coffeepot – embedded system crashed
• Embedded World – Program tried to access non‐existent memory. – This caused an EXCEPTION– No EXCEPTION HANDLER was provided so EVERYTHING FAILE!
Pragma #message (Visual C++)Pragma #warning (ADI CCES C++)PRAGMA – compiler specific C++ extension
Pseudo code for other functionsvoid PrepareTheCoffeePot_CPP (COFFEEPOT_DEVICE *baseAddress) { • Set the INITandSTAYPOWERED bit in control register• Update the simulator• In a loop
Update the simulatorExit the loop when DEVICE_READY bit is on
}
void TurnOnHeater_CPP(COFFEEPOT_DEVICE *baseAddress, unsigned char heaterLevel) {Equivalent to TurnOnWater_CPP( ) function
– different bits in COFFEEPOT structure}
Design DEFECT recognizedWe said // LED CONTROL (Bits 15 to 12) ‐‐W1S#define LED_CONTROL_OFFSET 12#define LED1 (1 << (LED_CONTROL_OFFSET + 0)) // 0x1 – LED 1#define LED2 (1 << (LED_CONTROL_OFFSET + 1)) // 0x2 – LED 2#define LED3 (1 << (LED_CONTROL_OFFSET + 2)) // 0x4 – LED 3#define LED4 (1 << (LED_CONTROL_OFFSET + 3)) // 0x8 – LED 4
Which requires the control register be “unsigned short int” – 16 bits
• But we saidunsigned char ReadControlRegister_CPP(COFFEEPOT_DEVICE *baseAddress );
Which makes the control register “unsigned char” – 8 bits
BIG QUIZ HINTDESIGN ERROR – Found in design phase when we made the mistake before moving onto next phase of projectDESIGN DEFECT ‐‐ Found the mistake at a much later phase of project – can be costly to fix
This design defect is easy to fix as we are not at a “too much later” phase in the project// LED CONTROL (Bits 7 to 4) ‐‐W1S#define LED_CONTROL_OFFSET 4
BUT LET’S NOT CHANGE unsigned char to unsigned int AND SEE WHAT WEIRD STUFF HAPPENSAND WHEN THE WEIRD STUFF HAPPENS – As would happen if we made a defect in a real project
QUIZ AND LAB HINT – Can you predict what might happen if this design defect is not fixed?
Lets build and run the project
Hover over coffeePot1_BaseAddress ‐‐ 0x0000000 ‐‐ we are using illegal base address
Enum issue (Editor problem)Also – system is complaining about COFFEEPOT1 – even though that is a defined enumin
MyCoffeePotFunctions.h
Temporary fix – make a copy of the enum declaration in main.cpp.Makes matters worse – complains of double define of enum
WAIL fix – enum only used in our main( ) at the moment – so only declare it there –comment out in MyCoffeePotFunctions.h with warning message so we know where to fix things global if this code decision comes back to haunt us.
Still crashes system when it is executed – but if hover the mouse over COFFEEPOT1 in the code window – shows as 1 after the crash so that can’t be the reason for the crash
Next step
• Add the proper coffeepot simulator library
• Next lectureBuilding a library – Process – not code detail