Skip to content

OpenTX Developer Guide

Max Paperno edited this page Mar 24, 2017 · 1 revision

This page is work in progress..

This page describes OpenTX source code organization, the system architecture and basic concepts used. This information is intended for future developers to help them get started with contributing to OpenTX. See also Github issue workflow.

The OpenTX github project consist of two sub-projects:

  • the radio firmware (runs on radio)
  • the Companion (runs on computer)

Radio firmware

OpenTX has evolved from other open-source projects. It also supports various radios - platforms. All this results in a source code that is sometimes difficult to read and understand for a new developer. The most confusing is the plethora of #ifdef statements that are not only used to differentiate code sections for various platforms, but also for various build options.

The code has evolved since the beginnings, where almost all source was in one file opentx.cpp. Over time a lot of stuff has been moved to new files and grouped according to its functionality. So now we have for example file mixes.cpp where mixer processing takes place.

The most informative file about various platforms and build options is the main makefile radio/src/Makefile. The beginning of that file contains a configuration section with a short descriptions of possible configurations options.

Source tree organization

Radio firmware is in radio/src directory. It contains various files and directories. Their meaning:

  • (root) - various common files, the main() function is in opentx.cpp
  • /CoOS - configured source of CooCox CoOS RTOS which is used on ARM platforms
  • /FatFs - configured source of FatFs (driver for FAT32 file-system)
  • /GSC_Mavlink - todo
  • /bitmaps - graphics that are included in source
  • /bootloader - source for Bootloader (actually most of the source code is taken from existing radio source tree, like drivers)
  • /fonts - fonts
  • /gui - user interface (menus, views, etc...)
  • /lua - configured and patched source of Lua interpreter
  • /pulses - drivers for various channel outputs (PPM, DSM2, etc..)
  • /targets - HAL layer for various platforms
    • /targets/common_avr - common stuff for AVR platforms (9X, Gruvin9X, etc...)
    • /targets/gruvin9x
    • /targets/mega2560
    • /targets/simu - simulation of actual hardware for stand-alone simulator
    • /targets/sky9x
    • /targets/stock - 9X drivers
    • /targets/taranis - Taranis (all variants) drivers
  • /telemetry - telemetry processing code
  • /tests - a suite of unit tests based on Google Test framework
  • /translations - support for different languages (displayed texts and text to speech algorithms)

There are also various utility programs in radio/util. Some of them are needed for compilation of opentx firmware.

Directory radio/wizard source code for new model wizard written in Lua.

For OpenTX compiling instructions see OpenTX Linux Build Instructions or OpenTX Windows Build Instructions.

Basic working model for ARM platforms

ARM platforms are all radios that use ARM based CPU: 9XR-PRO, Sky9x, Taranis(all versions). These are much more capable than AVR platforms and have more resources (RAM and FLASH). Therefore an RTOS is used on this platforms.

Startup:

  • after power-on the OpenTX firmware is started
  • low level system initialization (stack, clocks, C++ constructors). All this happens before the call to main()
  • the state of trims is checked and if right combination the bootloader is started.
  • initialization of subsystems (pheripherials, LCD, etc...)
  • creation of several tasks
  • RTOS is run

Shutdown:

  • if changed and not yet written, the settings are written to EEPROM
  • devices are closed (like FAT file-system)
  • task are stopped
  • LCD is turned off
  • power is switched off

Tasks

Menus task is responsible of implementing user interface (response to keys, LCD content generation). It is lowest priority task.

Audio task is responsible for generation of audio signal. It reads files from SD card, generates tones, mixes them together and plays them via DAC. It has higher priority than Menus task.

Mixer task is responsible for calculation of channel output values. This is highest priority task and is also guarded by a hardware watchdog.

Debug task is used for debugging and only created if DEBUG=YES make option is defined.

Bluetooth task todo

Periodic Interrupts

todo

FLASH organization

Bootloader is in the first 32K bytes of FLASH. The main OpenTX firmware starts at 32K.

Basic working model for old (AVR) platforms

todo

Stand-alone simulator

todo

Automatic unit testing

todo

Companion

todo

Clone this wiki locally