Hi. My name is Jonny and I design and write Flowcode.
Most of my work is behind the scenes adding features and fixing bugs – trying to ascertain what our users want from Flowcode.
We are preparing for 6.1 at the moment – there is a lot to be done on this, but the down side is I very rarely get to play around with Flowcode itself, so I thought as a short blog I would show you how to link existing C code into Flowcode and package it as a component – useful if you have a lot of existing libraries.
The first thing you need is to have some C code. Flowcode has a supplementary code feature and this can be exported with a component. You could add a hash-include for your source file or add it to the compiler arguments as a library. For the purposes of this demo we will write a small routine to make a string upper-case and use this instead.
So here is a C routine that makes a string upper-case. If you don’t know C, don’t worry about how this code works – it is only to serve as an illustration
We can add this routine to the supplementary code defines section, which can be exported as part of a component. Just cut and paste the text into the definitions section.
Once we have added the supplementary code, we must remember to tell the component to export it. In the settings manager under ‘Advanced’ select ‘Use supplementary Header Code’. This will tell Flowcode to package the header code with an exported component.
Now our C code is part of this project, we need to provide an interface to it. For this, create a macro with the same parameters as your code. Remember Flowcode will automatically add the ‘Length’ parameter when it sees a string or array, so you do not need to add this. Make sure you un-check to make a local copy of the Buffer String, so the upper-case result can be passed back to the caller.
Flowcode does not know what C code this will be linked to in the chip so will use the contents of the flowchart during simulation.
So we can add a simulation version of our routine using the ToUpper$() call on Buffer.
The final stage of the component creation is to declare an interface. Flowcode needs to know what macros you want to be available to the user and how to call them.
In the Interface Manager select the MakeUpperCase macro and from the drop-down select an ‘Embedded Macro.’ This tells Flowcode that while you want to simulate using the flowchart, the C code to download to the chip is already embedded in the program somewhere.
The function name to use on download can be expanded using several variables you can see in this drop-down list. We have a fixed name for our C function, which makes things nice and easy – just add the name into the Native Macro field.
Everything is set now, Flowcode has enough information to create a component, so its time to export. Just make sure that the front end of the component is correct, give it a tool-tip and the default icon. Now your component is exported into the Misc category you should see it in the lists.
To test the component, open a new instance of Flowcode, add your component to the system and create a simple test routine. Simulate the program, and you will see the simulation routine working. However if you look at the C code, all Flowcode is calling is the routine we have embedded in the supplementary code.
This method is the same for pretty much any component using embedded code. Some components such as the CAL even create additional consoles or other interfaces during simulation to help in testing.
Here are the source files and compiled component used in this example; Blog source files.
30,083 total views, 8 views today