NetBurner 3.5.6
PDF Version
Interval Timer

Interval Timer Example Application

Overview

The Interval Timer Example demonstrates how to use hardware timers on NetBurner platforms to schedule periodic interrupts for time-critical applications. This example showcases three different methods of utilizing interval timers for reliable timing operations.

The default for the timer constructor is to use the next available system timer, but you can also specify a specific timer as an optional parameter. Depending on the application requirements, the system may also use one or more of the available timers.

Warning
Always check the return value when creating a timer object. A value of less than 0 means a timer could not be allocated.

Features

The application provides three distinct timing mechanisms:

  1. Semaphore Posting - Posts to an OS semaphore at regular intervals
  2. Flag Posting - Posts to OS flags at specified frequencies
  3. Interrupt Callback - Triggers custom interrupt service routines

Hardware Timer Availability

The number of available timers varies by NetBurner platform:

  • MODM7AE70: Timers 0-11 (12 timers)
  • MOD54415, MOD54417, NANO54415, SB800EX: Timers 1-3 (3 timers)
  • MODRT1061: Timers 0-20 (21 timers)

Key Components

Timer Management

  • Automatic timer allocation using next available system timer
  • Manual timer specification supported via optional constructor parameter
  • Error handling for timer allocation failures (return value < 0)

Synchronization Objects

  • OS_SEM timerSem - Semaphore for timer-based synchronization
  • OS_FLAGS timerFlag - Flag group for event signaling
  • Global interrupt counter for callback demonstration

Application Menu Options

Option 1: Semaphore Timer

  • Prompts user for desired frequency (minimum 20 Hz)
  • Creates interval timer that posts to semaphore
  • Demonstrates semaphore counting mechanism
  • Reports total semaphore posts after completion

Option 2: Flag Timer

  • User-configurable flag posting frequency (minimum 20 Hz)
  • Interactive mode with manual termination
  • Shows flag pending and clearing operations
  • Counts and reports flag post events

Option 3: Interrupt Callback

  • Configurable interrupt frequency (minimum 20 Hz)
  • Demonstrates custom ISR callback implementation
  • Interactive termination via keypress
  • Tracks and reports interrupt occurrences

Important Implementation Notes

Timer Allocation

Always verify timer allocation success:

int timerNumber = IntervalOSSem(&timerSem, freq);
if (timerNumber < 0) {
printf("Error %d\r\n", timerNumber);
// Handle allocation failure
}
int IntervalOSSem(OS_SEM *p_toSem, int num_per_sec, int timer=FIRST_UNUSED_TIMER)
Create a periodic timer that posts to an RTOS semaphore.

Interrupt Service Routine Guidelines

The timer callback function (timerInterruptCallbackFunc) operates in interrupt context:

  • Keep execution time minimal
  • Avoid blocking operations
  • Use interrupt-safe functions only

Frequency Limitations

  • Minimum frequency enforced at 20 Hz for all timer modes
  • Higher frequencies possible but dependent on system capabilities
  • Consider system load when selecting frequencies

Code Structure

Main Components

  • UserMain() - Application entry point and main loop
  • displayMenu() - User interface display
  • processCommand() - Command processing and timer setup
  • timerInterruptCallbackFunc() - ISR callback demonstration

Dependencies

Usage Instructions

  1. Compile and flash the application to your NetBurner device
  2. Connect via serial terminal
  3. Wait for network initialization to complete
  4. Select desired timer mode (1, 2, or 3) from menu
  5. Enter frequency when prompted (minimum 20 Hz)
  6. Observe timer operation and results
  7. For interrupt mode, press any key to stop timing

System Requirements

  • NetBurner development environment
  • Compatible NetBurner hardware platform
  • Serial terminal for user interaction
  • Active network connection (for system diagnostics)

Error Handling

The application includes comprehensive error checking:

  • Timer allocation validation
  • Frequency boundary enforcement
  • User input validation
  • System timer availability verification

Performance Considerations

  • Timer precision depends on system clock accuracy
  • High frequencies may impact overall system performance
  • Multiple simultaneous timers share system resources
  • ISR execution time affects maximum achievable frequencies

Development Notes

  • System diagnostics enabled for development (consider removing for production)
  • Application runs in continuous loop for repeated testing
  • Memory cleanup handled automatically by RTOS
  • Thread-safe operations using NetBurner RTOS primitives