Supporting a new platform in the C target - lf-lang/lingua-franca GitHub Wiki

One of the objectives of the C target is be able to generate code that will be cross compiled and will run on embedded platforms.

Platform support for a new target

To support a new target (board, processor, etc.), do the following:

  1. LFC changes: The platform must be added as a target property:
target C {
  platform: Patmos
 }

This should make the LFC define a Cmake flag called CMAKE_SYSTEM_NAME and set it to "Patmos"

  1. core/platform/Platform.cmake This file is included by the CMakeLists.txt and it looks at CMAKE_SYSTEM_NAME and sets the variable LF_PLATFORM_NAME which is added to the sources. In Platform.cmake and CMkaeLists.txt lf_patmos_support.c should be added. TODO: why is the information here duplicated?

  2. lf_patmos_support.c/h The API defined in platform.h must be implemented in lf_patmos_support.c. If you have a pthread implementation you can just #include "lf_POSIX_threads_support.c". This is what lf_linux_support.c does

  3. Add an entry in the enum Platform in TargetProperty.java

  4. Add an entry in pickCompilePlatform in CGenerator.java

Cross compilation using a build script

If the platform in question does not have cmake support, then you can create a shell script to perform the cross compilation and, if you wish, uploading the compiled code to the board in question. To specify to use your build script, include in your .lf file the following:

target C {
    build: "path_to_script/my_script.sh"
};

Instructions for writing the script can be found here: https://www.lf-lang.org/docs/handbook/target-declaration?target=c#build

An example can be found here: https://github.com/icyphy/lf-buckler/blob/main/scripts/build_nrf_unix.sh

Examples