|
NetBurner 3.5.8
PDF Version |
Example Path: examples/OverloadDirectory
Additional instructions if the overload directory is used in an NBEclipse project:
This example demonstrates how to use the NetBurner overload directory feature to override system files in a project-specific manner. The overload directory allows developers to modify system configuration files without affecting other projects or the original NNDK installation.
The Overload Directory Example is a basic demonstration of the overload directory in a project. The overload directory is used to override any system file by including local copies of system source files or headers. This allows the user to make changes to system files exclusively for a project. The overload directory provides an alternative to modifying the original system files, which would affect all projects.
To use this feature, the file to be overloaded should be placed in the overload directory under a directory structure that matches the file's location relative to the NNDK install directory.
This example application utilizes the overload directory to override predef.h (a NetBurner configuration header file). The overloaded predef.h defines the macro NBRTOS_STACKCHECK, which is commented out (not defined) by default. Enabling RTOS stack-integrity checking during development is a common, real-world reason to override predef.h.
To overload the predef.h header, the directory structure is replicated inside the overload directory. For example, predef.h is located in the following directory in the NNDK install:
`/nburn/nbrtos/include/predef.h`
Therefore, the directory structure is replicated inside the overload directory with the following structure:
`<project root>/overload/nbrtos/include/predef.h`
The Overload Directory Example is a simple NetBurner application that showcases the overload directory functionality by:
OSDumpTCBStacks() function, which is only available when the NBRTOS_STACKCHECK macro is definedThe example also serves a small web page (browse to the device's IP address) that displays the same per-task stack-usage table live in a browser. The page's <!--CPPCALL ShowStackUsage --> tag hands the HTTP socket to a function in main.cpp, which briefly redirects its stdout to that socket and calls the same OSDumpTCBStacks() used over serial — so the browser shows exactly what the device prints. A Refresh button (and optional 2-second auto-refresh) re-fetches the table.
The Min Free column — each task's stack high-water mark — appears only because the overloaded predef.h defines NBRTOS_STACKCHECK; this is the overload's effect made visible. The page uses a self-contained stylesheet (plain CSS, no framework or CDN).
The overload directory provides a mechanism to override any system file by including local copies of system source files or headers. This approach offers several advantages:
This project demonstrates overloading the predef.h system header file to define the NBRTOS_STACKCHECK macro, which enables run-time stack-integrity checking and the OSDumpTCBStacks() diagnostic function.
The overload directory must replicate the directory structure of the file being overridden relative to the NNDK install directory.
The main application file that:
OSDumpTCBStacks() function (available due to overloaded predef.h)Contains the overloaded configuration that defines:
This macro enables run-time stack-integrity checking in the NetBurner system library, along with the stack/task diagnostic dump functions.
The original documentation explaining the overload directory concept and usage instructions.
If using this example in an NBEclipse project, additional configuration is required:
After adding an overload folder to the "Include paths" list or adding new files to the overload folder:
Once properly configured, modifying overloaded files (like predef.h) will automatically rebuild the necessary NetBurner Library files when the project builds.
When running the application:
OSDumpTCBStacks()OSDumpTCBStacks() function is only available when NBRTOS_STACKCHECK is defined in predef.hThis example overloads predef.h to enable one feature (NBRTOS_STACKCHECK), but the same technique is used throughout the SDK to switch on capabilities that are off by default. Each of these examples ships its own overload/nbrtos/include/predef-overload.h defining a different macro:
NBRTOS_STACKOVERFLOW / NBRTOS_STACKUNDERFLOW for real-time stack overflow/underflow protection (the closest cousin to this example)NBRTOS_TIME to enable per-task run-time profilingMULTIHOME to run multiple IP interfaces on one deviceNB_SSH_SUPPORTED to add SSH to the command processorENABLE_SNMP to enable the SNMP agent