diff --git a/CooperativeMultitasking.md b/CooperativeMultitasking.md index 6fe095b..794b870 100644 --- a/CooperativeMultitasking.md +++ b/CooperativeMultitasking.md @@ -238,7 +238,7 @@ Now let's look at how that information gets sent to the rest of the code: ## newEvent() -Here's a block diagram of the message flow ![](dispatch1.jpg) +Here's a block diagram of the message flow ![message flow](dispatch1.jpg) How do we send the information (events/messages) from the interrupt service routine to the @@ -433,7 +433,7 @@ discussion about [shared timers](#timers-as-a-resource) The other task of this project simply flashes the LED on and off. -![](led_state_simple.png) +![LED state machine, basic](led_state_simple.png) The code for this might be: @@ -473,7 +473,7 @@ void ledTask(uint8 evt) { Perhaps a more accurate state diagram might be: -![](led_state.png) +![LED state machine, alternate](led_state.png) As you build the code from the diagram, I *strongly* suggest that you use a `switch(currentState) ....case STATE_1` approach to the task routine. @@ -705,19 +705,14 @@ easily handle *dozens* of tasks, even on sub-$1 processors. ## Variations - - Now that the infrastructure is in place, it's easy to expand or modify the code for changes in the project definition. For example, suppose we want the `respondToButtonTask()` to restart the LED timer on each key press: -![](rtb_state_2.png){.imageleft} - +
+![RTB (respond to button) state machine, with restart](rtb_state_2.png)\ ```C void rtbTask(uint8 event) { switch(rtbState) { @@ -742,13 +737,14 @@ void rtbTask(uint8 event) { } } ``` +

Or have a 2nd press of the button cause the LED to extinguish early: -![](rtb_state_3.png){.imageleft} - +
+![RTB state machine, with early-off](rtb_state_3.png)\ ```C void rtbTask(uint8 event) { switch(rtbState) { @@ -774,6 +770,7 @@ void rtbTask(uint8 event) { } } ``` +

@@ -781,7 +778,9 @@ void rtbTask(uint8 event) { How about have the button start a flash sequence, and a 2nd press stops it: (see also [substates](#substates)) -![](rtb_state_4.png){.imageright} +
+ +![RTB state machine, push to stop](rtb_state_4.png)\ ```C void rtbTask(uint8 event) { @@ -822,7 +821,7 @@ void rtbTask(uint8 event) { } } ``` - +

Each of these diagrams corresponds to trivial changes in the state code. @@ -999,6 +998,7 @@ void taskWindow(char event, int windowIndex) { } } ``` + @@ -1014,7 +1014,7 @@ and turn off the light and alarm. And if the door closes during the 90 seconds, Here is the state diagram. -![](fridge_state.png) +![fridge state machine](fridge_state.png) And here is the corresponding code. @@ -1596,7 +1596,7 @@ void (*myvectors[])(void) __attribute__ ((section(".vectors")))= { For things like flashing LED's, you could create two states, and toggle between them, like this: -![](rtb_state_4.png) +![RTB state machine, with substates](rtb_state_4.png)
@@ -1614,7 +1614,8 @@ Alternatively, you could use the *timer counter* variable, and make changes at the half-way point through the count. This simplifies the substate design to this: -![](rtb_state_5.png){.imageright} +
+![RTB state machine, with substates](rtb_state_5.png)\ ```C const uint16 FLASH_CYCLE_TIME 150; @@ -1651,6 +1652,7 @@ void rtbTaskCode(char event) { } ``` +
## State Machine Initialization diff --git a/c.xml b/c.xml index a608dce..95791e1 100644 --- a/c.xml +++ b/c.xml @@ -96,10 +96,14 @@ void int8_t int16_t + int8 + int16 + int32 int32_t int64_t uint8 uint16 + uint32 uint8_t uint16_t uint32_t