lab 2 – hallowen experience with new...

27
Two Approaches – Your choice 1) Move your Lab 1 state machines from the super loop TARDOS to the more flexible uTTCOS but with changes to prepare for Lab 3 measurements involving timing of the thermal sensor whose pulse width changes with temperature 2. OR – GO CRAZY AND DEVELOP SOMETHING EQUIVALENT TO THE GOLDILOCKS AND THE 3 CHRISTINES VIDEO GAME Goldilocks is from a famous children’s story Christine is the “killer car” from a Stephen King novel 3. MY RECOMMENDATION Do Part 1 as a capture thread and a playback thread that act one after the other Once Part 1 is working, then add a few embellishments, extra LEDs and the like to get the video game going Most of the difference between part 1 and part 2 is in the story telling – You need to describe your story to TA (and your friends) as you demonstrate Lab 2 If you find your Lab 2 state machines are better than your Lab 1 state machines, then use them in your Lab 1 demo 4. UPLOAD LAB 1 / LAB 2 CODE WITH SCREEN CAPTURES NO LATER THAN 14 TH NOVEMBER. YOU WILL HAVE TIME TO FIX THINGS, BUT MUST DEMO SOME TIME BEFORE QUIZ 3 Lab 2 – Hallowen Experience with new OS

Upload: others

Post on 25-Mar-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lab 2 – Hallowen Experience with new OSpeople.ucalgary.ca/~smithmr/2017webs/encm511_17/17_Labs/17_Lab2... · Modify the Lab 1 car drive state machine so that it can display the

Two Approaches – Your choice1) Move your Lab 1 state machines from the super loop TARD‐OS to the more flexible 

uTTC‐OS but with changes to prepare for Lab 3 measurements involving timing of the thermal sensor whose pulse width changes with temperature

2. OR – GO CRAZY AND DEVELOP SOMETHING EQUIVALENT TOTHE GOLDI‐LOCKS AND THE 3 CHRISTINES VIDEO GAME • Goldilocks is from a famous children’s story• Christine is the “killer car” from a Stephen King novel

3. MY RECOMMENDATION• Do Part 1 as a capture thread and a playback thread that act one after the other• Once Part 1 is working, then add a few embellishments, extra LEDs

and the like to get the video game going• Most of the difference between part 1 and part 2 is in the story telling – You need 

to describe your story to TA (and your friends) as you demonstrate Lab 2• If you find your Lab 2 state machines are better than your Lab 1 state machines, 

then use them in your Lab 1 demo

4. UPLOAD LAB 1 / LAB 2 CODE WITH SCREEN CAPTURES NO LATER THAN 14THNOVEMBER. YOU WILL HAVE TIME TO FIX THINGS, BUT MUST DEMO SOME TIME BEFORE QUIZ 3

Lab 2 – Hallowen Experience with new OS

Page 2: Lab 2 – Hallowen Experience with new OSpeople.ucalgary.ca/~smithmr/2017webs/encm511_17/17_Labs/17_Lab2... · Modify the Lab 1 car drive state machine so that it can display the

Read Stephen King’s “Christine” or rent the DVD and watch one night with friendsPersonally – I think “The Shining” or Dr. Who’s “Angels” are much more scary

Activate a uTTCOS project

Modify the Lab 1 car drive state machine so that it can display the prime numbers 1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37 in binary

You start with 2 cookies

Add a switch state machine that runs every 1 / 10 second to read the switches

Start the car state machine to display first number and start a timer thread for 3 seconds

If the person can press the switches  to represent the same number on the LEDs, then move up to the next game level

Next game level means – you get an extra cookie, the car drive state machine moves to display the next prime number  and the timer thread is restarted

If the timer thread (actually a watch dog style timer)  times out before the player has pressed the correct code, then a cookie is eaten by the Cylon from Battlestar Galactica – and very briefly – the number of cookies left are displayed

When all cookies are eaten – the game ends with the Cylon smile remaining on the screenThe LEDS display 1, 2, 3, 4, 5, 6, 5 , 4, 3, 2, 1 2, 3

If you get to 37 – then celebrate by flashing all the LEDs randomly

Prelab -- Quick video game using uTTCOS

Page 3: Lab 2 – Hallowen Experience with new OSpeople.ucalgary.ca/~smithmr/2017webs/encm511_17/17_Labs/17_Lab2... · Modify the Lab 1 car drive state machine so that it can display the

Now we will have one TARD‐OS super loop start up to read your switch commands and store them into an array.

Then, we will ʺkillʺ this super‐loop and a new TARD‐OS super loop will start up and play back your new commands. 

Then we will kill that superloop and restart the first super‐loop. All the time, PowerOn_Flash_LED6 must work without a hiccup

1. Plan to build a uTTCOS project and launch a thread that uses your Lab 1  state machine(s) to read your switch commands and store them into an array. 

2. When the array is full – kill all the step 1 sub‐threads and launch a new thread that uses your Lab 1  state machine(s) to play back your new commands

3. When all the commands are played back, kill this  thread, and restart the first thread

4. All the time LED6 the heart beat must work without a hiccup

Option 1 – Same idea as Lab 1 except with uTTCOSg

Page 4: Lab 2 – Hallowen Experience with new OSpeople.ucalgary.ca/~smithmr/2017webs/encm511_17/17_Labs/17_Lab2... · Modify the Lab 1 car drive state machine so that it can display the

Now you have moved the Lab 1 TARD‐OS code to run under uTTC‐OS you need to refactor to do the following Refactor switch code so instead of Press – Release of SW4 causing storage of the 

drive car commands you have Press SW4 for about 2 seconds will store the drive car commands Press SW4 for about 1 second will delete the last car command Press SW4 for about 3 seconds will be the same as issuing a STOP command Otherwise ignore SW4 commands

You might find that initially you want to make the switch presses longer

Option 1 continued

Page 5: Lab 2 – Hallowen Experience with new OSpeople.ucalgary.ca/~smithmr/2017webs/encm511_17/17_Labs/17_Lab2... · Modify the Lab 1 car drive state machine so that it can display the

The narrator (Flashing LED 6) starts the storyOne day, 42 years from now, in a land far‐far away 511 light years from earth  Little Red Riding Hood is happily skipping through the woods watching the (2) early Christmas lights twinkling.  She is joined by Cinderella.   Each character is an LED controlled by a state machine with a different characteristic

When suddenly the Christine comes out from behind a tree and starts destroying the feeling of Christmas cheer.   Christine is the killer car from Stephen King’s novel.  The first thing Christine does is to take over the personality of one of the Christmas lights (unless you want to modify the GPIO interface to have outputs controlling the LEDs on the logic lab as Christmas lights as extra lights)

Goldilocks, the woodchopper’s daughter is in the neighbourhood.  She rushes in and waves her magic wand (or do we want to hit things with a glass slipper that Cinderella left behind) and Christine vanishes. Peace and tranquility is restored, leaving Goldilocks,  Little Red Riding Hood, Snow White (Narrator, and twinkle lights) once again dancing in the wood.  

Explanation – magic wand waving means  issuing an illegal car command (LEFT and RIGHT) and holding SW4 for exactly 1 second.  Illegal car commands will always frighten a killer car. 

Unfortunately if Goldilocks waved her wand for “too short a time”, then the horrid Christine comes back more vicious than before taking over the personalities of all the Christmas lights and Little Red Riding Hood. Goldilocks waves her magic wand again, and the Christine is again vanquished and runs back into the darkness. 

However if Goldilocks waved her wand for “too long a time”, and the Christine will come back again – now very, very angry and doing ‘terrible’ things – meaning she starts destroying the other threads in a random way – one every two seconds – The rules are Christine can’t remove herself from the game.

Finally, although her heart is beating much faster now, Goldilocks waves her magic wand for ‘just the right way’ and the Christine vanishes for ever and the three friends enter into Grandma’s house for the next part of the story.  

Explanation – just the right way means that there must be 3 magic wand wavings followed by the really illegal car command (LEFT, RIGHT and FORWARD) while holding SW4 for exactly 1 second

GoldiLocks and the Three Christines, Big Bad Wolf and TrollsIf you don’t like my story behind doing Lab. 2 -- Make up your own and include in

your report, You have to tell your story while doing the Lab. 2 demo

Page 6: Lab 2 – Hallowen Experience with new OSpeople.ucalgary.ca/~smithmr/2017webs/encm511_17/17_Labs/17_Lab2... · Modify the Lab 1 car drive state machine so that it can display the

The narrator (Flashing LED 6) continues the storyFinally, although her heart is beating much faster now, Goldilockswaves her magic wand for ‘just the right way’ and the Christine vanishes for ever and the three friends enter into Grandma’s house for the next part of the story.  Explanation – just the right way means that there must be 3 magic wand wavingsfollowed by the really illegal car command (LEFT, RIGHT and FORWARD) and holding SW4 for exactly 1 secondOnce inside Grandma’s house, Goldilocks brings out her cell‐phone and starts calling Uber.  Using the switches, she describes the 15 car directions to escape her house.  These new commands must be typed in within 2 minutes as otherwise the big‐bad‐wolf will jump out of the chimney where he was hiding, eat the narrator and the story endsWith the commands entered, the Uber car arrives and the car directions are played back at 1 second intervals.  When the car arrives at the safe house, everybody starts dancing.  Unfortunately, after 10 seconds or so of dancing, the happiness wakes up the troll from under the rickety rackety bridge (lights flashing 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6) who eats everybody and then goes to sleep for 20 minutes as the troll had just become friend with Ric Van Winkle.

GoldiLocks and the Three ChristinesIf you don’t like my story behind doing Lab. 2 -- Make up your own and include in

your report, You have to tell your story while doing the Lab. 2 demo

Page 7: Lab 2 – Hallowen Experience with new OSpeople.ucalgary.ca/~smithmr/2017webs/encm511_17/17_Labs/17_Lab2... · Modify the Lab 1 car drive state machine so that it can display the

Start, or end the story with the Cheshire cat smile from Alice in Wonderland

Cheshire cat smile The LEDs slowly come on from the centre growing brighter and brighter as the smile gets wider.  In previous years, this was called “Opening the shuttle door” on the Enterprise. 

Now there is a new Enterprise then I suppose that rather than driving off into the sunset with Uber then Goldilocks and friends could catch the Voyager shuttle

Once fully bright – the smile slowly fades away and the quiet of the woods is full restored

This is about 40 uTTCOS commands within a state machine.   

Not complicated – just time consuming and not the best thing to complete afte

Optional -- If you really want to make the story more “realistic” with more characters

Page 8: Lab 2 – Hallowen Experience with new OSpeople.ucalgary.ca/~smithmr/2017webs/encm511_17/17_Labs/17_Lab2... · Modify the Lab 1 car drive state machine so that it can display the

Activate a uTTCOS project

Modify the Lab 1 car drive state machine so that it can display the prime numbers 1, 2, 3, 5, 7, 11, 13, 17, 19, 23

You start with 2 cookies

Add a switch state machine that runs every 1 / 10 second to read the switches

Start the car state machine to display first number and start a timer thread for 3 seconds

If the person can press the switches  to represent the same number on the LEDs, then move up to the next game level

Next game level means – you get an extra cookie, the car drive state machine moves to display the next prime number  and the timer thread is restarted

If the timer thread (actually a watch dog style timer)  times out before the player has pressed the correct code, then a cookie is eaten by the Cylon from Battlestar Galactica – and very briefly – the number of cookies left are displayed

When all cookies are eaten – the game ends with the Cylon smile remaining on the screenThe LEDS display 1, 2, 3, 4, 5, 6, 5 , 4, 3, 2, 1 2, 3 for ever

Prelab -- Quick video game using uTTCOS

Page 9: Lab 2 – Hallowen Experience with new OSpeople.ucalgary.ca/~smithmr/2017webs/encm511_17/17_Labs/17_Lab2... · Modify the Lab 1 car drive state machine so that it can display the

uTTCOSg_Start_Scheduler(maxNumberThreads);    If you use a lot of threads – then increase maxNumberThreads Don’t make it too large as it slows down the ISR driving uTTCOSg

Give each thread a single job to do Start a timer thread for 3 seconds This thread simply counts the number of times it has run and when it counts to 3 seconds – it sets a global message – time up – that can be read by other threads

Switch thread Perhaps this thread simple reads the switches, does all the anding and oring needed and set a global message  ‐‐ current switch values – that can be read by other threads

This thread makes no decisions – it simply worries about getting the switch values correct

Things to worry about.  Stopping and restarting a thread stste machineExample from Prelab 2:  Each time you correctly enter the switch values that match the LEDs then you restart the timer. DOES YOUR CODE reset the timer thread so it counts for a NEW 3 seconds and not just finish off the old count?

Some important ideas

Page 10: Lab 2 – Hallowen Experience with new OSpeople.ucalgary.ca/~smithmr/2017webs/encm511_17/17_Labs/17_Lab2... · Modify the Lab 1 car drive state machine so that it can display the

TARD‐OS and uTTC‐OS are both co‐operative OS Co‐operative means that no normal thread can start before the previous normal thread finishes. Co‐operative means that if your state machine is not co‐operative –it has a loop “waiting for something” – then it will stop all other threads. This means your code will loop something like this If nothing has changed – don’t wait – exit thread and let another runelse – set SM to next state and exit

Co‐operative also means that if one SM changes a memory location or reads a device, it is guaranteed that no other SM will read or change that memory location at the same time This means that Co‐operative OS can NEVER have a data race condition and can pass very simple messages  to each other  

uTTCOSg – The “C” means co-operative

Page 11: Lab 2 – Hallowen Experience with new OSpeople.ucalgary.ca/~smithmr/2017webs/encm511_17/17_Labs/17_Lab2... · Modify the Lab 1 car drive state machine so that it can display the

Handled by 2 threads sharing a message

typedef unsigned char uMESSAGE;

typedef unsigned short int sMESSAGE;

volatile MESSAGE LED_ValueTo_Display = 0;

static LED patternToDisplay[ ] = {…, …, ….,       };

Thread 1 – running every second – It is ONLY responsible for copying a value from patternToDisplay[ ] to LED_ValueTo_Display

Thread 2 – running every ¼ second ‐‐ It is ONLY responsible for copying the LED_ValueTo_Display to the LEDs, and making them brighter

Cheshire Cat example -- where the SMILE gets slowly brighter

Page 12: Lab 2 – Hallowen Experience with new OSpeople.ucalgary.ca/~smithmr/2017webs/encm511_17/17_Labs/17_Lab2... · Modify the Lab 1 car drive state machine so that it can display the

This thread does NOT do AND or OR operations when using WriteLED( ) 

All the OTHER threads are responsible for doing AND or OR operations on LED_ValueTo_Display

Thread 2 SM – uses its own ENABLE array perhapsFirst 4 times – Show 0, 0, 0, LED_ValueTo_DisplaySecond 4 times – Show 0, LED_ValueTo_Display, 0, LED_ValueTo_DisplayThird 4 times – Show LED_ValueTo_Display, LED_ValueTo_Display, 

LED_ValueTo_Display, LED_ValueTo_DisplayFourth 4 times – Show 0, LED_ValueTo_Display, 0, LED_ValueTo_DisplayFifth 4 times – Show 0, 0, 0, LED_ValueTo_DisplaySixth 4 times – Show 0, 0, 0, 0

This will go from dark to bright and back again every 6 seconds.

Would look more impressive to run about 5 times faster once running

Thread 2 running every 1 / 4 secondBasically complicated LED 5 from Lab 0

Page 13: Lab 2 – Hallowen Experience with new OSpeople.ucalgary.ca/~smithmr/2017webs/encm511_17/17_Labs/17_Lab2... · Modify the Lab 1 car drive state machine so that it can display the

Currently we have the Narrator just be LED 6 flashing.

Suppose instead, we have the Narrator get involved in the story

Imagine that the Narrator and Goldilocks have both had heart transplants and their new hearts are linked by a Blue‐tooth connection. This means that when Goldilocks’ heart speeds up, so does the Narrators This can be done easily using ideas from the previous slide Big Narrator array, with the state machine sometimes changing state by 1, 2 or more

You work out the details 

To make Lab Option 2 more interesting

Page 14: Lab 2 – Hallowen Experience with new OSpeople.ucalgary.ca/~smithmr/2017webs/encm511_17/17_Labs/17_Lab2... · Modify the Lab 1 car drive state machine so that it can display the

We need to know the cast

6  or morew Threads using uTTCOS LED operations (Lab 0)

1 Thread using MyReadSwitchesASM operations (Lab 1)

And the salary of the cast the Number of L.O.C. that need to be written

Provided you plan the tasks rather thanJust start coding

Page 15: Lab 2 – Hallowen Experience with new OSpeople.ucalgary.ca/~smithmr/2017webs/encm511_17/17_Labs/17_Lab2... · Modify the Lab 1 car drive state machine so that it can display the

You have to plan what each thread is going to do

Make sure each thread has only one task to do

Plan the actors

Here is a plan from a number of years back – which does not match the current Lab 2 – so make the design changes

Design on paper You can’t just start coding

Page 16: Lab 2 – Hallowen Experience with new OSpeople.ucalgary.ca/~smithmr/2017webs/encm511_17/17_Labs/17_Lab2... · Modify the Lab 1 car drive state machine so that it can display the

Name Played by  Salary

Red Riding Hood Lab 0  ‐ Flash_LED3 1 uTTCOS L.O.C. to activate

Snow White Lab 0 ‐‐ Flash_LED1 1 uTTCOS L.O.C. to activate 

Christine – the young Flash LED1,2,3,5 1 uTTCOS L.O.C. to activate plus copying LED3 and modifying LED3 (3 uTTCOS L.O.C.)

Christine – the vicious Modified Lab 1 ‐ Auto drive the Car

1 uTTCOS L. O.C. to activate plus change drive array ( 3 L. O.C.) – Can be done before or after  the Lab1 “Drive the car automatically“ Thread completed.

Christine – the angry Flash LED2 1 uTTCOS L. O.C. to activate plus new uTTCOS lines of code to get really angry

Goldilocks – Heart Lab1 – Flash_LED6 I uTTCOS L.O.C. to activate. 3 uTTCOS L.O.C. to change heart rate

Goldilocks – Wand Spell Flash_ LED4 3 or 4 uTTCOS L.O.C. to activate plus copying and modifying LED3 (6 uTTCOS L.O.C.)

Goldilocks – Wand action Lab 1 – Capture the car commands

1 uTTCOS L. O.C. to activate plus change drive array ( 12 L. O.C.) – Can be done before or after  Lab 1 “Capture the car commands “Thread completed

Page 17: Lab 2 – Hallowen Experience with new OSpeople.ucalgary.ca/~smithmr/2017webs/encm511_17/17_Labs/17_Lab2... · Modify the Lab 1 car drive state machine so that it can display the

This is the proper state machine formation for all Lab. 2 LED tasks

NOTE – Everything happens on a OS TIC and at no other time 

Task 3.B: Fix Flash_LED1 thread so that it properly configured for an embedded system state-machine thread

START

IF MUST BE ON

IF MUST BE OFF

First call orFlash Init

On TICturn onLED1

On TICturn offLED1

On TICInitLED if not doneSet LED1 OFF

Page 18: Lab 2 – Hallowen Experience with new OSpeople.ucalgary.ca/~smithmr/2017webs/encm511_17/17_Labs/17_Lab2... · Modify the Lab 1 car drive state machine so that it can display the

// Discuss use of threadID to remove thread later during Lab 2 itself

volatile unsigned int ID_christmasLight_LED1 = 0;    

volatile unsigned int threadID_Flash_LED3 = 0;      etc

void ReadRidingHood_LEDControl_ThreadCPP(void) {  // Launched as RUN ONCE taskID_christmasLight_LED1  = uTTCOS_AddThread(Flash_LED1, 

TEN_SECOND_DELAY, EVERY_SECOND / 3.14);

etc.   // This will cause the first Christmas light to appear after 10 seconds}

Add the following declarations to Lab2.h  ‐Quiz question – Understanding “C / C++” – why there?

extern volatile unsigned int ID_christmasLight_LED1; extern volatile unsigned int threadID_Flash_LED3;   etcWhy does extern volatile unsigned int ID_christmasLight_LED1 = 0; cause an error?

Launching a thread with the ability to allow the later removing (kill) of a thread that is already running

Page 19: Lab 2 – Hallowen Experience with new OSpeople.ucalgary.ca/~smithmr/2017webs/encm511_17/17_Labs/17_Lab2... · Modify the Lab 1 car drive state machine so that it can display the

1. Launch (ADD) a RUN_ONCE, 20 second delayGoldiLocks_WandControl_ThreadCPP thread from  Lab2_Demo uTTCOS_main( )

2. Establish “blue‐tooth” link between Goldilock’s heart  to the  Narrators Flash_LED6( ) thread so that LED6 flashes at around a normal heart rate in this lab 

This is before Christine appears so 70 beats a minute is good enough, not 170 beats / minute – that comes later when Goldilocks starts fighting Christine with  her magic wand

3. Launch the Goldilock’s Wand Flash_LED4( ) thread 

The wand just occasionally flashes as Goldilocks skips happily through the wood not knowing the adventures she is about to experience. 

4. B.L.L.R. – Get the Goldilocks and Red Riding Hood characters signed off if a T.A. is available.   This counts as a demo of Lab.0

Goldilocks enters the woods

Page 20: Lab 2 – Hallowen Experience with new OSpeople.ucalgary.ca/~smithmr/2017webs/encm511_17/17_Labs/17_Lab2... · Modify the Lab 1 car drive state machine so that it can display the

Do you know what the object to the side of this presentation is? Did you know that many course outlines say “no calculators in exams” but say nothing about bringing one of these in to the quiz 

Can you use one?

As an engineer – are you interested enough in wanting to learn how to use one? I will put aside a tutorial after the midterm to show you if people are interested. I have a teaching one of these hanging up in my office

If one of your relatives “have been engineers for a long time”, then they may have one to loan you

Or else you can Xerox a picture of  one and paste it onto wood of cardboard

F.Y.I. – Strange choice of border provided byPowerPoint in 2014

Page 21: Lab 2 – Hallowen Experience with new OSpeople.ucalgary.ca/~smithmr/2017webs/encm511_17/17_Labs/17_Lab2... · Modify the Lab 1 car drive state machine so that it can display the

Follow Lab. 1 Task 1 to check the station1. Install cables on logic laboratory station cables to check LLS switches and LED2. Power down LLS3. Connect 50 pin cable to Blackfin4. Run a Lab 0 code to check CCES, J‐TAG and Blackfin

1. You can also use your audio cable in the lab kit to connect your iPod to the Blackfinand listen to music

5. Run a Lab 1 task to check switches, LLS and 50‐pin cable connections

Lab 2 start -- Check Set up

Page 22: Lab 2 – Hallowen Experience with new OSpeople.ucalgary.ca/~smithmr/2017webs/encm511_17/17_Labs/17_Lab2... · Modify the Lab 1 car drive state machine so that it can display the

Short term goal – Demonstrate killing Christine with a software wand‐wave 

When you activate the Goldilocks add a CheckWandWaveThread ( ). After your code is running,  make the video game more interesting, by having the wand have a weak battery and not get charged up for 20 seconds (Launch with a delay).

Don’t run the WandWave thread too often otherwise it will always kill Christine but might not give any time for other threads to run.

The WandWave thread does not read the switches – instead it reads the message sent by the ReadSwitches thread

If the Wand Wave thread sees the simple illegal car command happen in the message (or the extra strong illegal command) then it can do the following

Add a RUN_ONCE thread that will in ONE TIC deleting the Christine Task information from the uTTCOS Do_List

void SoftwareWandWave_Kill_Christine_Thread(void) {uTTCOS_DeleteThread(

task_ID_Christine_Conquers_The_World_ThreadCPP);}

Add another RUN_ONCE thread that will in TWO TICS restart another Christine Task with a 10 second (or faster) delay.  It is easier to debug if you don’t start another Christine Task from inside CheckWand thread but in a later thread

Being able to “Kill” the Christine virus thread with a wand wave (flip of a switch or a hit from a glass slipper)

Page 23: Lab 2 – Hallowen Experience with new OSpeople.ucalgary.ca/~smithmr/2017webs/encm511_17/17_Labs/17_Lab2... · Modify the Lab 1 car drive state machine so that it can display the

Three ways of writing STATE MACHINES were shown in the Flash LED code for Lab. 1 and discussed in class.

First thing – write down the states that describe the system operation – then code

E.g Flash_LED 6 – normal heart beat flash State 1 – Not started – If system is not initialized, init it, go to state 2  State 2 – ON – go to state 3  State 3 – ON – go to state 4  State 4 – OFF – go to state 5  State 5 ‐‐ OFF– go to state 2 

Example of a state machine concept that could be used when building a SW 4 wand-wave thread

Page 24: Lab 2 – Hallowen Experience with new OSpeople.ucalgary.ca/~smithmr/2017webs/encm511_17/17_Labs/17_Lab2... · Modify the Lab 1 car drive state machine so that it can display the

First thing – write down the states – then code

EXAMPLE   Flash_LED 6 –heart beat thread that speeds up when message is true State 1 – Not started – If system is not initialized, init it, go to state 2  State 2 – ON – if message if false go to state 3; else go to state 5  State 3 – ON – go to stage 4  State 4 – OFF – go to state 5  State 5 ‐‐ OFF– go to state 2

Example – Using a state machine concept to make LED 6 flash faster using a message

Page 25: Lab 2 – Hallowen Experience with new OSpeople.ucalgary.ca/~smithmr/2017webs/encm511_17/17_Labs/17_Lab2... · Modify the Lab 1 car drive state machine so that it can display the

Once you have got the `wand wave’ thread working (at least demoed three times)

Reactivate the Red Riding Hood thread and make sure that wand‐waving does not stop Red Riding Hood and her friends  from skipping through the woods watching the flashing Christmas lights

Task 8: Functionality Test of Wand Wave thread

Page 26: Lab 2 – Hallowen Experience with new OSpeople.ucalgary.ca/~smithmr/2017webs/encm511_17/17_Labs/17_Lab2... · Modify the Lab 1 car drive state machine so that it can display the

Plan ahead so that you will be able to get the wand wave times correct. Can I get SW4 to start a new task when pressed and released?

When that is done – then get switch timing working If SW4 held for less than 2 second before release – Short LED4 flash If SW4 held for more than 2.4 seconds before release – Long LED4  flash If SW4 held between 2 and 2.4  seconds before release –Joyous  LED 4 flashed

Note – with a SW4  state machine this is about 20 lines of uTTCOS calls

Ideas about Goldilock’s wand thread

Page 27: Lab 2 – Hallowen Experience with new OSpeople.ucalgary.ca/~smithmr/2017webs/encm511_17/17_Labs/17_Lab2... · Modify the Lab 1 car drive state machine so that it can display the

Above main add  extern “C” void BlackfinBF533_uTTCOSg_Audio_Rx_Tx_Task(void);

Add thread to main.cppuTTCOSg_AddPreEmptiveThread(BlackfinBF533_uTTCOSg_Audio_Rx_Tx_Task, 

NO_DELAY, EVERYTICK)

Close CCES and then down load the Lab 2 audio file.cpp from my webside into your project

Restart CCES – connect audio signal to CJ2 connector

Connect ear‐phones to CJ3 – but removed from your head

Start uTTCOSg – and bring ear‐phones up to your ears

If that works – then remove the pre‐emptive thread from main.cpp and change touTTCOSg_AddThread(BlackfinBF533_uTTCOSg_Audio_Rx_Tx_Task, 

NO_DELAY, EVERYTICK)

Check that it works (it may not)

After this – any time your code if incorrectly written and starts stealing cycles from other SM, then the audio SM will dies and all audio will stop

NOTE – If running as PreEmptive Thread then this thread has priority and will always work.

Getting the Audio to work