Skip to content

It is an alternative implementation of the printf family suitable for embedded systems.

License

Notifications You must be signed in to change notification settings

rafagafe/xprintf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

xprintf

Build Status

The xprintf module is an alternative implementation of the printf family of the standard library of C.

The main feature of xprintf is that it lets you print in user defined output stream. In this way the user can print directly on a serial port or on an RTOS queue.

  • It supports almost all printf functionality except floating point.
  • It is a very light implementation. It is suitable for embedded systems.
  • It has a low stack usage profile. It is suitable for multi-thread systems.
  • Supports several compilation options to reduce program memory by eliminating features.

Example

We have a queue module with this interface:

// File: queue.h

struct queue;

void queue_push( struct queue* queue, unsigned char byte );

We need print in this queue with a function like this:

// File: qprintf.h

int qprintf( struct queue* queue, char const* fmt, ... );

We implement the qprintf function by using the xvprintf function:

// File: qprintf.c

#include "xprintf.h"

/* Callback function for user defined output stream. */
static void print2queue( void* p, void const* src, int len ) {
    unsigned char* data = (unsigned char*)src;
    struct queue* queue = (struct queue*)p;
    for( int i = 0; i < len; ++i )
        queue_push( queue, data[i] );
}

/* Print formatted data to a queue. */
int qprintf( struct queue* queue, char const* fmt, ... ) {
    struct ostrm const ostrm = {
        .p    = (void*)queue,
        .func = print2queue
    };
    va_list va;
    va_start( va, fmt );
    int const rslt = xvprintf( &ostrm, fmt, va );
    va_end( va );
    return rslt;
}

About

It is an alternative implementation of the printf family suitable for embedded systems.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published