This is the standard multiple include protection mechanism. The include file will be processed only on the first time it is included

In document Openrg Programmer Guide 5.5 LATEST (Page 54-57)

Development Tutorial

Line 1-2,7 This is the standard multiple include protection mechanism. The include file will be processed only on the first time it is included

Line 4,5 These lines define the Watchdog initialization and un-initialization functions that will be invoked during OpenRG start-up and shutdown procedures, respectively.

For now, we will create an empty implementation of the Watchdog initialization as described below and in file rg/pkg/watchdog/watchdog_init.c. We include main/mt_main.h to get the API of OpenRG that will be used later on in the initialization of the package:

rg/pkg/watchdog/watchdog_init.c

#include <main/mt_main.h>

void watchdog_init(void) {

rg_error(LCONSOLE, "Initializing Watchdog components.");

}

void watchdog_uninit(void) {

rg_error(LCONSOLE, "Un-initializing Watchdog components.");

}

Finally, we need to link the Watchdog object to OpenRG's main process and invoke the initialization of the Watchdog from the OpenRG initialization process. The OpenRG main process is built in rg/pkg/main , and the Makefile in this package should be modified to link in the Watchdog object. Here is the line that should be added to this Makefile:

JMK_L_OBJS_$(MT_TARGET)+=$(JMKE_BUILDDIR)/pkg/watchdog/watchdog.o

The JMK_L_OBJS_$(MT_TARGET) variable defines the list of objects that should be linked with OpenRG's main process. This line adds the Watchdog object file created in rg/pkg/

watchdog. JMKE_BUILDDIR is used since this is an object file and all output files are created under the build directory. The OpenRG main process start up and shut down procedures are defined in rg/pkg/main/mt_init.c. In order to include the Watchdog init and uninit functions in this process, the following lines must be added to this file in the relevant sections:

rg/pkg/main/mt_init.c

watchdog_uninit();

...

}

The include file will introduce the Watchdog initialization API to OpenRG. The mt_init and mt_uninit functions, which start up and shut down OpenRG, will invoke the Watchdog

init and uninit functions respectively. Note that the function calls should be included inside the #ifdef __TARGET__ conditional compilation. If you want your new package to generate separate log messages from the rest of the components in the log file (rather than be logged as "Other"), perform the following. Add your package to the enum in pkg/include/

log_entity_id.h:

...

LOG_ENTITY_WATCHDOG = 400, ...

Then, add your package to the entities array in pkg/mgt/lib/log_entity.c:

...

{ LOG_ENTITY_WATCHDOG, "watchdog", T_PTR(Tlog_entity_watchdog), LOG_USER, LOG_BUFFER_VARLOG },

...

LOG_ENTITY_WATCHDOG The package identifier.

watchdog Specifies the code for the new package. This argument will be used in the CLI to specify your package.

T_PTR(Tlog_entity_watchdog) The string that the user will see in the WBM for this package. This string (the T<name> variable) should be added to the pkg/mgt/lib/

log_entity_lang.csv language file.

LOG_USER The facility that will be used for your package when syslog protocol log messages are sent to a remote syslog server. The most common facility is LOG_USER.

LOG_BUFFER_VARLOG The log buffer to which messages from your package are redirected. The common one is the "varlog" buffer (the default system logging buffer). Some entities, however, can be redirected to the security log.

Testing that the Watchdog and OpenRG are integrated is done by recompiling the OpenRG's tree and loading it to the board:

$ cd rg

$ make

OpenRG now includes the new (and empty) Watchdog package. The rg/build/openrg.rmt file can now be loaded to the target board, using the remote firmware upgrade procedure.

5.3.4 Lesson Summary

Going through the steps described above, you have learnt:

How to create a new package and modify the rg/pkg/Makefile to include it with the tutorial feature.

• How to create Makefile for a new package.

• How to write and integrate the package initialization.

• How the build stages work.

• How to build your package.

For a complete reference regarding the files used in this stage, refer to this tutorial's appendix (Section 5.8).

5.4 Stage 2 – The Configuration Database

Every application that runs on OpenRG should be able to store and retrieve its own

configuration data. OpenRG stores application data in the configuration database: rg_conf.

The configuration database is consisted of volatile and persistent (non-volatile) sections. The volatile section is rg_conf_ram, while the persistent is simply rg_conf. This stage describes how to:

• Add a new management component to the Watchdog package, which will manage the data in the configuration database.

• Extend the configuration database with new entries, both volatile and persistent.

• Define and implement an API to store and retrieve the configuration database entries of the Watchdog application.

• Extend the Command Line Interface (CLI) to view and modify the values of the Watchdog configuration.

5.4.1 Adding the Watchdog Management Component

The Watchdog application requires adding new entries to the configuration database, and implementing an API to access these entries. We will implement this API in the mgt directory.

To add this component to the Watchdog package, we need to create a sub-directory mgt under the rg/pkg/watchdog directory, write a new Makefile in that directory, and have the Watchdog Makefile enter this sub-directory during compilation.

• The first step is to create the directory:

$ cd ~/rg/pkg/watchdog

$ mkdir mgt

The next step is to enhance the Watchdog Makefile so it enters the mgt sub-directory, and link the object from this directory to the Watchdog object. Following are the lines to be added. The first line adds the mgt directory to the JMK_SUBDIRS variable. The second line adds the mgt object file to the link of the Watchdog object.

JMK_SUBDIRS+=mgt

JMK_L_OBJS+=mgt/watchdog_mgt.o

The last step is to add the Makefile to the mgt directory and develop the code.

rg/pkg/watchdog/mgt/Makefile

1 ifndef JMKE_ENV_INCLUDED 2 JMK_ROOT=../../../

3 include $(JMK_ROOT)/jmk/env_root.mak 4 endif

5

6 JMK_EXPORT_HEADERS_DIR=watchdog/mgt

7 JMK_EXPORT_HEADERS+=watchdog_mgt.h watchdog_mgt_init.h 8

9 JMK_O_TARGET=watchdog_mgt.o 10 JMK_O_OBJS+=mgt.o commands.o 11

12 $(call JMKE_INCLUDE_RULES)

This Makefile is very similar to the Makefile of the Watchdog package added earlier. The only differences are the names of the files that are created and exported.

In document Openrg Programmer Guide 5.5 LATEST (Page 54-57)

Related documents