NetBurner 3.5.6
PDF Version
Introduction

Intro to NetBurner Programming

Overview

The NetBurner Programming Guide provides a comprehensive overview of the features and capabilities of the NetBurner Network Development Kit (NNDK). This guide focuses on practical implementation of network applications using NetBurner hardware, software, and development tools through a hands-on, example-driven approach.

Prerequisites

Before beginning this guide, ensure you have:

  • Installed the NetBurner Network Development Kit
  • Configured a running NetBurner device on your network
  • Familiarity with either:
    • NBEclipse development environment (see NBEclipse Getting Started Guide), or
    • Command-line tools and your preferred development environment
  • Knowledge of your target device's network configuration
  • Successfully created and deployed a test project to your target device

Learning Approach

This guide employs a learn-by-example methodology. Each example builds upon a foundational template application that serves as a starting point for most NetBurner projects. Progressive examples demonstrate increasingly complex networking capabilities.

Development Flow
┌─────────────┐
│ Template │
│ Application│
└──────┬──────┘
v
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ Basic │ --> │ Network │ --> │ Advanced │
│ Examples │ │ Protocols │ │ Features │
└─────────────┘ └─────────────┘ └─────────────┘

Source Code Location

All example programs referenced in this guide are located in the following directory:

<NNDK_ROOT>/examples/

Where <NNDK_ROOT> is your NetBurner tools installation directory.


Creating Your First Application

Using the NBEclipse Application Wizard

The quickest way to start is with the NBEclipse Application Wizard:

  1. Launch NBEclipse and create a new project
  2. Select the following wizard options:
    • Standard Initialization
    • Web Server
  3. Complete the wizard to generate your project

If you're unfamiliar with NBEclipse, consult the NBEclipse Getting Started Guide before proceeding.

Template Application Structure

The Application Wizard generates a main.cpp file with the following structure:

#include <predef.h> // System level options and definitions
#include <init.h> // Initialization functions
#include <stdio.h> // Standard I/O functions
#include <nbrtos.h> // NetBurner Real Time Operating System (RTOS)
#include <http.h> // HTTP functions
const char * AppName = "AppWizard"; // Application name for discovery
void UserMain(void * pd)
{
init(); // Initialize system
WaitForActiveNetwork(TICKS_PER_SECOND * 5); // Wait up to 5 seconds
StartHttp(); // Start web server
printf("Application %s started\n", AppName);
while (1) // Main application loop
{
OSTimeDly(TICKS_PER_SECOND);
}
}
#define TICKS_PER_SECOND
System clock ticks per second.
Definition constants.h:49
void StartHttp(uint16_t port, bool RunConfigMirror)
Start the HTTP web server. Further documentation in the Initialization section Initialization - Syste...
void init()
System initialization. Ideally called at the beginning of all applications, since the easiest Recover...
bool WaitForActiveNetwork(uint32_t ticks_to_wait=120 *TICKS_PER_SECOND, int interface=-1)
Wait for an active network connection on at least one interface.

Application Execution Flow

System Boot
v
┌─────────────────────┐
│ RTOS Starts │
│ Automatically │
└──────────┬──────────┘
v
┌─────────────────────┐
│ UserMain() Task │
│ Created & Started │
└──────────┬──────────┘
v
┌─────────────────────┐
init() Function │
│ • stdio setup │
│ • Config read
│ • Network init
│ • Task priority │
│ • Monitor enable │
│ • Debug setup │
└──────────┬──────────┘
v
┌─────────────────────┐
│ WaitForActiveNetwork│
│ (timeout: 5 sec) │
└──────────┬──────────┘
v
┌─────────────────────┐
StartHttp() │
│ Web server on :80 │
└──────────┬──────────┘
v
┌─────────────────────┐
│ Application Code │
│ Runs in Loop │
└──────────┬──────────┘
v
[Infinite Loop]
int read(int fd, char *buf, int nbytes)
Read data from a file descriptor (fd).

Key System Functions

init()

The init() function performs critical system initialization:

  • stdio Configuration: Initializes standard I/O to the debug/console port
  • Configuration Processing: Reads system settings including:
    • Network interface parameters
    • Serial port configuration
    • Boot options
  • Network Stack: Initializes the TCP/IP stack
  • Task Priority: Sets UserMain() priority to MAIN_PRIO
  • Task Monitor: Enables task monitoring utilities
  • Debug Support: Activates GDB debugger in debug builds

WaitForActiveNetwork()

Blocks execution until a network link is established or timeout occurs.

Parameters:**

StartHttp()

Launches the HTTP web server.

Default Configuration:**

  • Port: 80 (standard HTTP)
  • Can specify alternate port: StartHttp(8080)

    Secure Alternative:**

  • Use StartHttps() for SSL/TLS support

Output Functions

printf() vs printf()

NetBurner supports both standard output functions:

Function Description Use Case
printf() Full formatting support including floating-point General purpose output
printf() Integer-only formatting Resource-constrained applications

Recommendation:** Use printf() when floating-point output is not required to conserve system resources.

Example:**

printf("Application %s started\n", AppName);
printf("Network IP: %d.%d.%d.%d\n", ip[0], ip[1], ip[2], ip[3]);

Application Design Principles

The Main Loop

Your application must never return from UserMain(). The standard pattern uses an infinite loop:

while (1)
{
OSTimeDly(TICKS_PER_SECOND); // Yield CPU periodically
}

Timing Considerations

Always use TICKS_PER_SECOND for time-based calculations:

// Correct: Portable timing
OSTimeDly(TICKS_PER_SECOND * 2); // Delay 2 seconds
// Avoid: Hard-coded tick values
OSTimeDly(200); // Not portable!

Why?** The TICKS_PER_SECOND constant ensures code portability if system tick rates change across platforms or configurations.

Resource Management

Application Resource Flow
┌──────────────────────────────────────┐
│ UserMain() Task │
│ │
│ ┌────────┐ ┌────────┐ ┌────────┐ │
│ │ stdio │ │Network │ │ HTTP │ │
│ │ I/O │ │ Stack │ │ Server │ │
│ └───┬────┘ └───┬────┘ └───┬────┘ │
│ │ │ │ │
│ v v v │
│ ┌─────────────────────────────────┐ │
│ │ Application Logic │ │
│ │ • Event processing │ │
│ │ • Protocol handling │ │
│ │ • Data management │ │
│ └─────────────────────────────────┘ │
└──────────────────────────────────────┘
v
[Hardware Resources]

Next Steps

With this foundation, you're ready to explore:

  1. Network Communication - TCP/IP, UDP protocols
  2. Web Server Development - Dynamic content, forms, APIs
  3. Serial Communications - UART configuration and protocols
  4. Real-Time Features - Task management, interrupts
  5. Advanced Topics - SSL/TLS, MQTT, custom protocols

Each subsequent section builds upon this template application, adding functionality progressively.


Quick Reference

Critical Constants

TICKS_PER_SECOND // System tick rate
MAIN_PRIO // UserMain task priority
#define MAIN_PRIO
Recommend UserMain priority.
Definition constants.h:130

Core Functions

init() // System initialization
WaitForActiveNetwork(ticks) // Network wait
StartHttp() // HTTP server
StartHttps() // HTTPS server
OSTimeDly(ticks) // Task delay
printf(format, ...) // Stdout printf
void StartHttps(uint16_t ssl_port, uint16_t http_port)
Start the HTTPS secure web server.

Architecture Overview

NetBurner Application Stack
┌─────────────────────────────────────────┐
│ Application Layer │ < UserMain()
│ (Your Code Runs Here) │
├─────────────────────────────────────────┤
│ Protocol Layer │
│ HTTP │ HTTPS │ MQTT │ TCP │ UDP │ ... │
├─────────────────────────────────────────┤
│ Network Stack │
│ TCP/IP │ DHCP │ DNS │ ARP │ ICMP │
├─────────────────────────────────────────┤
│ NetBurner RTOS │
│ Task Scheduler │ Memory │ Sync
├─────────────────────────────────────────┤
│ Hardware Abstraction │
│ Ethernet │ Serial │ GPIO │ Timers │
├─────────────────────────────────────────┤
│ Hardware Platform │
│ (MOD5441X, MODM7AE70, etc.) │
└─────────────────────────────────────────┘
@ Sync
Synchronous mode. All signals synchronized to SEMC clock. Supports burst transfers....
DHCP Namespace.
Definition dhcpd.h:39
MQTT Namespace.
Definition mqtt.h:81
Address Resolution Protocol packet structure.
Definition arp.h:1035