Hello, Real-Time World!
The transpilation tool, in addition to performing code translation, is used to create new Termina projects. Thus, the tool supports different commands. In particular, the new command allows you to create a new project containing an initial directory tree and a project configuration file with default parameters.
In our case, we are going to create a new project named hello_world. To do this, we will execute the following command from the terminal:
After executing the command, a new directory called hello_world containing the following elements will have been generated:
The file termina.yaml stores the project configuration parameters. The app directory contains the main Termina source code file of the application. By default, this file is named app.fin. The src directory will contain the additional modules that are part of the project. In our case, we will not add any files to this directory. The output directory will store the files generated by the transpiler from the Termina code.
Next, we are going to modify the app.fin file, adding the following content:
task class HelloWorldClass {
timer_port : sink TimeVal triggers timeout;
system_port : access SystemAPI;
action timeout(&priv self, _current_time : TimeVal) -> Status<i32> {
let msg : [char; 128] = "Hello, Real-Time World!";
let ret : Status<i32> = Success;
self->system_port.println(128, &msg);
return ret;
}
};
emitter timer : PeriodicTimer = {
period = {
tv_sec = 1,
tv_usec = 0
}
};
#[priority(10)]
task hello_world_task : HelloWorldClass = {
timer_port <- timer,
system_port <-> system_entry
};
The next step is to update the termina.yaml configuration file, where we will need to add the following line at the end:
Finally, we will generate the application code with the following commands:
If the command has been executed successfully, the output directory should contain the modules resulting from the transpilation. In order to compile and run the project, we will have to execute the following commands in the terminal:
The program will print the message “Hello, Real-Time World!” on the screen every second. To exit, it will be necessary to interrupt the execution of the program by entering the key combination Ctrl+C in the terminal.