Recent Changes - Search:

edit SideBar

CreatingTheCTemplateFile

Back to mbed

Overview

The template file can be used in two different situations, it can be paired with an adapter in the form of actorname.c, or it can be used inside the embedded code actor (as plain text).

There are two main qualities of the c template file:

  • Code blocks to be placed into the different aspects of the actor, such as the fire or initialize function.
  • Macros used to replace keywords with parameters or unique identifiers from the actor.

Code Blocks

The code blocks start and end are notated with /*** functionName(Parameters...) ***/ and end with /**/, the code blocks are in between. A few block names to get started:

  • preinitBlock
    • This contains all the header code, declare local static variables and include files here. This will be put at the top of the file, not in a function.
  • initBlock
    • This is called at the creation of the actor, and will be put in a code block, so you are free to initiate variables, and access parameters that came from the actor itself (they are initialized in the preinitBlock)
  • fireBlock
    • This is called each time the actor is fired, so the code in this block runs similarly to a while(1) loop in a program's main.
  • More to come, but another example used with the display actor: BooleanPrintBlock($name, $channel), which is used it the input to the actor happens to be a boolean. TODO: Add more details about how this part works.

Macros

Macros are used to replace parts of the code block with items from the actor. The always start with the $ symbol. Here are a list if some of the more common macros used.

  • input#$channel
    • Used to get the channel of the input, and fed into other macros listed below.
  • $get(input#$channel)
    • Gets the input token from the current channel.
  • $getAndFree(input#$channel)
    • Experimental: Gets the input token from the current channel and frees the token.
  • $hasToken(input#$channel)
    • Used in an if statement to verify if the port has a token.
  • $param(var)
    • Replaces this with a parameter from the actor with the name give, in this case "var". This will take on the value that was given to the actor, and can be changed just like any actor parameter.
  • $actorSymbol(sym)
    • This will create a unique symbol for every actor that is initiated with this. This is needed if you want more than one of the same actor to generate code that works! For example, my GPIOWriter actor used a variable named "myled" to store the LED class. If "myled" is used, then two actors will generate a variable with the same name, and the code will not compile. Instead, use "$actorSymbol(myled)" and a name will be generated unique to each instance of the actor.

Adding Actors to Vergil

Edit - History - Print - Recent Changes - Search
Page last modified on April 25, 2015, at 11:03 PM