Developing a multi-thread product -- Introduction M. Smith Electrical Engineering, University of Calgary Smithmr @ ucalgary.ca 12/4/2018
Tackled today GPS example of a multi-tasking DSP problem What is GPS and how does it fit into Lab. 4? Lab. 4 concepts VisualDSP VDK environment – 1 hour prelab. Adding a boot thread Adding (and then creating) free-running threads Adding Semaphore so threads communicate 12/4/2018
References Understanding GPS Principles and Applications, 1996, Elliott D. Kaplan Digital Signal Processing – A Practical Approach, 1993, Emmanuel C. Ifeachor, Barrie W. Jervis ADSP-TS101 TigerSHARC and Blackfin Processor Programming References, Analog Devices Articles submitted to Circuit Cellar magazine by M. Smith, March 2004 12/4/2018
Introduction GPS traditionally done with ASIC/Processor combination Looking at FPGA/DSP combination for low end GPS receivers Technological interest in software radio Cheaper, quicker development cycle. Customizations for special applications From a talk by Darrell Anklovitch for ENEL619.23 12/4/2018
What is GPS? Global Positioning System 24 satellite (SV) constellation Orbiting 20,000 km from the surface of the Earth in 12 hour cycles Orbits are set-up to give global coverage 24 hours a day Need at least 4 satellites in view to calculate a position (1) 12/4/2018
GPS Positioning Concepts (1) For now make 2 assumptions: We know the distance to each satellite We know where each satellite is Require 3 satellites for a 3-D position in this “ideal” scenario Requires 4 satellites to account for local receiver clock drift. 12/4/2018
GPS Signal Structure Each satellite transmits 2 carrier frequencies referred to as L1 (1575 MHz) and L2 (1227 MHz) Each carrier frequency is BPSK modulated with a unique PRN (pseudo random number) code The PRN code on L1 is called CA code (coarse acquisition), The PRN code on L2 is called P code (precise) CA code takes 1 ms for full PRN transmission at 1MHz chip (bit) rate. P code takes 1.5 s for full PRN transmission at ~10MHz chip rate Also modulated on each carrier is 50 Hz data that includes the current position of the satellite 12/4/2018
Determining Time Use the PRN code to determine time (1) Use the PRN code to determine time Use time to determine distance to the satellite distance = speed of light * time 12/4/2018
Algorithms to Find PRN Phase Time-domain Cross correlation: 1/N ∑ x1 (n) * x2(n) Coding equivalent to FIR filter, but need to filter N sets of data, each shifted by one data point Correlation of perfectly matching signals gives a maximum value Correlation of 2 random data sequences tends to 0 PRN code from different satellites are designed to correlate to 0. Frequency domain correlation: 1/N F-1[X1(k)X2(k)] where F-1 is the inverse Discrete Fourier Transform and the X’s are the Discrete Fourier Transforms of two sequences D 12/4/2018
Timing Frequency Domain 1/N F-1[X1(k)X2(k)] 1024 point FFT (2 * NLOG2N) 1024 MULTS (N) 1024 point INV FFT (NLOG2N) Time Domain 1/N ∑ x1 (n) * x2(n) n = 0 1024 MACs (N) 1024 Phases (N) 30,000 Complex operations N-1 1,048,576 operations (N2) 12/4/2018
TigerSHARC -- TS101 and TS201 TS101 TS201 Low-cost version $45 / chip Evaluation boards $950 each educational price 12/4/2018
Lab. 4 and Take-Home Quiz 4 Demonstrate developing a multi-threaded environment involving the receiving and analysis of 3 satellite signals Lab 4 VDK environment Use of current assembly FIR code for correlation analysis Take-home quiz (Done individually) Use Analog Devices provided FFT code Develop your own assembly language code using CLU functionality -- XCORRS 12/4/2018
Lab. 4 – Parts 1, 2 and 3 – done as pre-laboratory tasks – about 1 hour Part 1 -- Create an Initialization Thread Use VDK::Sleep(200) sleep as a work load Part 2 – Launch (create) Satellite Receiver Tasks as free running tasks Use VDK::Sleep(X) as a work load ClearReceiverThread X = 100 ReceiveSatellite1 X = 10 ReceiveSatellite2 X = 20 ReceiveSatellite3 X = 30 Part 3 – Add semaphores to get satellite tasks running in proper time sequences 12/4/2018
Lab. 4 – Continued – details to be added Part 4 -- Add Satellite Receiver Tasks Payloads Download payload code from the web – code provided Part 5 – Generate E-TTD tests for correlation function designed using your existing FIR filter code Part 6 – Add analysis and reporting threads Part 7 – adjust task priorities to make realistic and working Demo and code hand-in with minor write-up 12/4/2018
Adding the initialization Thread Blackfin code (VisualDSP 3.5) can be found at http://www.enel.ucalgary.ca/People/Smith/2005webs/encm515_05/05Labs/05Lab4/04IntroductionVDK.ppt TigerSHARC VDK Different implementation for each version of processor (0.1 or 1.0) because of number of available timers on the chips Slightly different setup between Visual DSP 3.5 and 4.0 because of the silicon differences mentioned above. 12/4/2018
VDK set-up for TigerSHARC (3.5) 12/4/2018
VDK Setup – Visual DSP 4.0 12/4/2018
Adding the Initialization Thread 12/4/2018
Making the InitializationThread a Boot-Thread Automatically Generated Thread Code 12/4/2018
Adding a VDK::Sleep(200) work load to the Initialization Thread VDK-Thread activity window can be activated through VIEW | VDK window menu option – you can Zoom into find fine details of certain activities WARNINGL If the silicon option are incorrect – only the IDLE thread seen 12/4/2018
Thread window legend (Right click in thread window to activate) Running Sleeping Status change Tick (0.05 ms default) 12/4/2018
Now add the following threads with following VDK::Sleep( ) periods ReceiverControlThread -- 100 ticks ReceiverBufferClear -- 10 ticks Receive1Satellite -- 10 ticks Receive2Satellite -- 20 ticks Receive3Satellite -- 30 ticks 12/4/2018
Thread code automatically generated Example after running the code Problem – the threads have not been created – so they exist but don’t run 12/4/2018
Still problems All threads are launched But one thread has taken over all the resources of the system 12/4/2018
Reason for Problem Thread is just spinning its wheels Forgot to add the sleep? 12/4/2018
Solution Thread now all in existence – but free running Need to add “semaphores” to gain control 12/4/2018
Receiver Requirements On receipt of “Capture Signal” semaphore Clear ReceiverBuffer When receiver buffer is cleared Grab satellite signals 1, 2 and 3 12/4/2018
Requirements rephrased ReceiverControlThread VDK::PendSemaphore(kCaptureSignalSTART, 0); On receipt of “Capture Signal” semaphore VDK::PostSemaphore(kReceiverBufferClearSTART) Clear ReceiverBuffer VDK::PendSemaphore(kReceiverBufferClearDONE, 0); When receiver buffer is cleared VDK::PostSemaphore(kReceiver1SatelliteSTART); VDK::PostSemaphore(kReceiver2SatelliteSTART); VDK::PostSemaphore(kReceiver3SatelliteSTART); Grab satellite signals 1, 2 and 3 VDK::Sleep (200) VDK::PostSemaphore(kCaptureSignalDONE); 12/4/2018
Requirements rephrased ReceiverBufferClear VDK::PendSemaphore(ReceiverBufferClearSTART, 0); VDK::Sleep (10); // Will be replaced by process later VDK::PostSemaphore(ReceiverBufferClearDONE); Typical Satellite Thread VDK::PendSemaphore(ReceiverXSatelliteSTART, 0); VDK::Sleep (X); // Will be replaced by process later VDK::PostSemaphore(ReceiverXSatelliteDONE); What are the syntax errors in the code? 12/4/2018
Adding a semaphore 12/4/2018
Method code added Why does not anything work? What do you have to do to get this? 1 line change 12/4/2018
Some issues remaining Blue bar means what? Why is distance between Init Thread Green bar means what? and start of Receiver Control thread Grey bar means what? changing? Yellow arrow means what? Is it a problem that Satellite 3 task finishes after receiver control thread starts to sleep? 12/4/2018
Tackled today GPS example of a multi-tasking DSP problem What is GPS and how does it fit into Lab. 4? Lab. 4 concepts VisualDSP VDK environment – 1 hour prelab. Adding a boot thread Adding (and then creating) free-running threads Adding Semaphore so threads communicate 12/4/2018