SinelaboreRT Header Logo

SinelaboreRT

As simple as possible, but not any simpler!

User Tools

Site Tools


wiki:news:10oct2013

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
wiki:news:10oct2013 [2013/09/21 18:51] – [Provide an own Instance Structure] pmuellerwiki:news:10oct2013 [2022/08/17 19:44] (current) – Discussion status changed pmueller
Line 1: Line 1:
 ====== Multiple instances of the same machine ====== ====== Multiple instances of the same machine ======
  
-Sometimes you want to run the same state machine multiple times. E.g. processing tree serial interfaces with the same state machine. In object orient languages this is easy as the concept of objects is the basis of these languages. You would simply instantiate the class three times.+Sometimes you want to run the same state machine multiple times. E.g. processing three serial interfaces with the same state machine. In object orient languages this is easy as the concept of objects is the basis of these languages. You would simply instantiate the class three times.
  
-Luckily in C there there is also a well known concept to do this. Instead of defining objects you define structures that contain all local data a function needs access to. When calling that function a pointer to such a structure is handed over. In our case the function is the state machine handler. And the structure contains all the state variables etc. need by the state machine. The code generator automatically creates all that for you.+Luckily in C there is also a well known concept to do this. Instead of defining objects you define a (instance) structure that contains all local data a function needs. When calling that function a pointer to the instance data structure is handed over. In our case the function is the state machine handler. The code generator automatically creates the instance data structure automatically for you.
  
 In this example we will show you how to "create multiple instances" of the state machine. In this example we will show you how to "create multiple instances" of the state machine.
Line 23: Line 23:
 You can now simply declare multiple variables of type TESTCASE_INSTANCEDATA_T which contains the data per instance. When calling the state machine just point to one of these variables.  You can now simply declare multiple variables of type TESTCASE_INSTANCEDATA_T which contains the data per instance. When calling the state machine just point to one of these variables. 
  
-To let the state machine know which object number it currently works with a predefined member of the struct called ''inst_id'' is available. You can set it to any value that makes sense in the state handler (e.g. provide the COM port number the machine currently processes).+Sometimes it is necessary that a state machine knows on which object it currently works on. Therefore a predefined member called ''inst_id'' is generated by default. You can set it to any value that makes sense in your context (e.g. provide the COM port number the machine currently processes).
  
 <code c> <code c>
Line 50: Line 50:
  
 ===== Provide an own Instance Structure ===== ===== Provide an own Instance Structure =====
-Sometimes it makes sense to provide an own instance structure. In our example we want to store the baud rate, parity and other values relevant for each serial port. So the state machine can store there all local data and makes it "object oriented" this way.+Sometimes it makes sense to provide an own instance structure. In our example we want to store the baud rate, parity and other values relevant for each serial port.
  
-So first define an own struct in a file called ''own_inst_type.h'' (as an example). As you can see all local data like the noRxBytes is defined there but also variables that are initialized just once like the bit rate which is more like a parameter.+So first define an own struct in a file called ''own_inst_type.h'' (as an example). The example below shows how to define local variables like the ''noRxBytes'' (number of already defined bytes) as well as parameters like the parity etc.
  
 <code c> <code c>
Line 110: Line 110:
 ===== Putting all Things Together ===== ===== Putting all Things Together =====
  
-Coming back now to the example of three serial interfaces. The following figure shows a simplified state machine for handling a serial interface. The state machine is generic. If com0 or com1 or com2 is processed is determined from the content of the instance variable.+Coming back now to the example of three serial interfaces. The following figure shows a simplified state machine for handling a serial interface. The state machine is generic. Whether COM0 or COM1 or COM2 is processed is determined only from the content of the instance variable. And also other parameters are stored there and of course the local machine variables.
  
 +{{:wiki:news:multiple_instances.png?nolink}}
  
 +I hope that the concepts how to run multiple state machines of the same type are clearer now. And also how to define an own instance structure that is necessary for more complex machines.
  
-Hope that the concepts how to run multiple state machines of the same type is clear. And also how to define an own instance structure that is necessary for more complex machines.+In case of any questions don't hesitate to contact me!
  
-In case of any questions don't hesitate to contact us! 
  
  
-{(rater>id=3|name=How do you like this article?|type=rate)} +~~DISCUSSION:closed|Leave your comments~~
-~~DISCUSSION|Leave your comments~~+
wiki/news/10oct2013.1379782292.txt.gz · Last modified: 2013/09/21 18:51 by pmueller

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki