Policy to create and use cfg and hw include for BeRTOS module.

Overview

BeRTOS, to be simple an portable on every target, has an abstraction layer that separates generic code implementation from hardware specific one. This allow the user to write an application on one target and, without effort, to port it on another target only rewriting the hardware specific code.
In this way your core application is the same on different kind of target.
To manage this different king of target, in BeRTOS we have a cfg and hw directory.
The cfg directory contain a configuration file for each BeRTOS module, while the hw directory contain the hardware low level function or settings for select target.
When we write our application we could use a default settings of BeRTOS in cfg dir or use a customized collection of configuration file that we put in our application folder, in one directory that we call cfg.
For hardware specific function and definition we can use a BeRTOS bordplates that are contained in hw dir, to make an our low level function implementation for select target.
Then, we put these files in hw dir contained in our application folder.

Cfg directory

In bertos/cfg directory, we put all module configuration.
Every module in BeRTOS have a standard configuration, (for example a seriar baudrate,
serial tx/rx buffer len, the number of dc motor, ecc..) that is write in file named cfg_<module_name>.h. If we not want to use a default cfg file, we can copy it in our application folder, and change it. Otherewise we write a new module, we can create a new cfg file called cfg_<new_module_name> and put it in <our_folder_app>/cfg.
When we use a customized cfg file, we should observe some simple rules:

  • when we include in module we write:
    #include "cfg/cfg_<module_name>.h"
    
    We use a double mark to underline to user that we are use a local cfg (if it exist) and not a default cfg.
  • we put this include on the top of other include, like this:
    #include "<module_name>.h"
    
    #include "cfg/cfg_<module_name>.h"
    /* include ..other cfg module ..*/
    
    /* inclue hw module */
    /* include driver module */
    /* include library and other not bertos specific */
    
    In this way is more simple to individuate which cfg module we are use.

Note: Is important to specify the cfg dir when we include it, so the makefile system include the correct
cfg file.

HW directory

The bertos/hw directory contain all low level function and define implementation specific for select target.
In the BeRTOS hw directory you can find the borderplates for a specific module. You should copy the hw/hw_<module_name>.h (and hw/hw_<module_name>.c if exist)
in <yor_app_folder>/hw, and then edit it.
Generally the hw module implement a low level functions that are target specific, like hw/hw_cpu.h where is write a cpu clock frequency or a hw_spibitbag.h module that emulate a spi driver moving some micro pins. So, when we use one module that needs a low level function we should create or implement a hw file module.
Like for cfg module the hw module as the same simple rules:

  • when we include in module we write:
    #include "hw/hw_<module_name>.h"
    
    We use a double mark to underline to user that we are use a local cfg (if it exist) and not a default hw.
  • we put this include on the top of other include, after a cfg include, like this:
    #include "<module_name>.h"
    
    /* include "cfg/cfg_<module_name>.h */
    /* include ..other cfg module ..*/
    
    /* include "hw/hw_<module_name>.h */
    /* include ..other hw module ..*/
    
    /* include driver module */
    /* include library and other not bertos specific */