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:
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:
- Launch NBEclipse and create a new project
- Select the following wizard options:
- Standard Initialization
- Web Server
- 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>
#include <init.h>
#include <stdio.h>
#include <nbrtos.h>
#include <http.h>
const char * AppName = "AppWizard";
void UserMain(void * pd)
{
printf("Application %s started\n", AppName);
while (1)
{
}
}
#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
┌─────────────────────┐
│ • stdio setup │
│ • Task priority │
│ • Monitor enable │
│ • Debug setup │
└──────────┬──────────┘
│
v
┌─────────────────────┐
│ WaitForActiveNetwork│
│ (timeout: 5 sec) │
└──────────┬──────────┘
│
v
┌─────────────────────┐
│ 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:**
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:
Timing Considerations
Always use TICKS_PER_SECOND for time-based calculations:
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:
- Network Communication - TCP/IP, UDP protocols
- Web Server Development - Dynamic content, forms, APIs
- Serial Communications - UART configuration and protocols
- Real-Time Features - Task management, interrupts
- Advanced Topics - SSL/TLS, MQTT, custom protocols
Each subsequent section builds upon this template application, adding functionality progressively.
Quick Reference
Critical Constants
#define MAIN_PRIO
Recommend UserMain priority.
Definition constants.h:130
Core Functions
OSTimeDly(ticks)
printf(format, ...)
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