Port to Your Hardware

The QSL and the underlying C Library are written to be used as-is in any C-based platform; however, you have to implement a handful of functions to adapt them to a specific platform. These functions are implemented in the example code provided for certain platforms (presented in later chapters), so you can skip the details of this section for now if you plan on using these (or simply wish to have a look at the examples first).

 The necessary functions are declared in following header files:

  • dn_uart.h: These functions allow the SmartMesh C Library to send bytes over the serial port, and receive bytes from the serial port. A "flush" function is provided in case the serial (UART) driver of the user platform is frame-oriented rather than byte-oriented.
  • dn_lock.h: These functions allow the SmartMesh C Library to operate in a multi-threaded environment. If this is the case in the user system, the implementation of these functions would typically consist of pending/posting a mutual exclusion semaphore (mutex); if not, simply use stub functions (i.e. "empty functions").
  • dn_endianness.h: These functions are used to match multi-byte API fields (which are big-endian) to the endianness of the platform.
  • dn_time.h: These functions allows the QSL to perform timing and schedule tasks.
  • dn_watchdog.h: These functions allow the QSL to make sure any watchdog in the user application is fed during processes that can take some time (e.g. searching for a network). If no watchdog is present, simply use stub functions.

The QSL is currently meant to be run in a single threaded environment, thus you can just use stub functions for the prototypes in dn_lock.h. If you wish to run the QSL in a multi-threaded environment, you should create your own mutex (separate from the prototypes in dn_lock.h) to be locked/unlocked before/after calls to the QSL API.

C Library Specific

Refer to the C Library documentation for further details on how to port the prototypes in these headers.

QuickStart Library Specific

dn_time.h
uint32_t dn_time_ms(void):
void dn_sleep_ms(uint32_t milliseconds);

These functions allows the QSL to perform timing, schedule tasks and sleep to save power.

  • time_ms: Simply needs to return time in milliseconds. The absolute value is irrelevant; as long as the time returned from subsequent calls will differ by the actual time passed between them.
  • sleep_ms: Make the CPU sleep for the set number of milliseconds. If power consumption is not a big concern, an alternative is to simply add a delay.
Make sure time_ms counts to the full 32 bit range (i.e. up to 4294967295 or 0xFFFFFFFF) before it wraps around to ensure correct behaviour; the QSL will trigger a timeout too early if it is scheduled right before an unexpected wrap around.
dn_watchdog.h
void dn_watchdog_feed(void);

This function allows the QSL to make sure any watchdog in the user application is fed during processes that can take some time (e.g. searching for a network).

  • watchdog_feed: Feed any watchdog that might be implemented in the platform; simply use stub function if none.