This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Printf wrapper with Log_print inside

Hello everyone,

(target C6678, CCS 5.5, BIOS 1.25, XDCTools 3.25, Syst Analyser 1.3)

The aim here is to write a printf wrapper (we'd call it UserPrintf) which supports variable arguments and use Log_print behind the scenes.

Log_print supports up to 6 IArg arguments so my idea is to use a sprintf-like before and feed the log_print with only 1 string.

here's what I've got so far :

void UserPrintf( CString fmt, ... )
{

    VaList va;
    Char buf[200];

     va_start(va, fmt);
     System_vsprintf(buf, fmt, va);
     va_end(va);

     Log_print0(Diags_USER6, buf);
}

UserPrintf("example %d",123);

but it doesn't seem to work
In System Analyser I see the log_print Events but the actual Message is "Timeout annot be zero". instead of "example 123"

(System proxy = SysMin) in ROV tool the output buffer of SysMin shows "example 123".

With SysStd in the Logs the Message is empty (why?). Nothing is displayed on the console (as expected).

Do you see what's wrong ?

Thank you,
Clement

  • Hi Clement,

    Can you check the return value of System_vsprintf in both cases?  Is it returning the number of characters written as you expect?

    Next, how have you configured your default logger?  Are you using LoggerBuf?

    Clement FR said:
    In System Analyser I see the log_print Events but the actual Message is "Timeout annot be zero".

    Do you have any idea where that message is coming from?  Are you sure these are corresponding to your calls to UserPrintf?  I've grepped around the code of XDC and BIOS but didn't see that message. Maybe it's coming from another component you're using.

    Steve

  • Hi Steve,

    I'll check the return value and let you know the results.

    ---------

    Here's the relevant part of my config

    Main.common$.diags_USER6         = Diags.ALWAYS_ON;

    var mainloggerParams                            = new LoggerCircBuf.Params();
    mainloggerParams.transferBufSize      = 2048;
    mainloggerParams.numCores              = 1;
    var mainlogger                                           = LoggerCircBuf.create(mainloggerParams);
    mainlogger.instance.name                     = "MainLogger";

    LoggingSetup.eventUploadMode                     = LoggingSetup.UploadMode_JTAGRUNMODE;
    LoggingSetup.mainLogger                            = mainlogger;

    ------------

    I have no idea where this message is coming from.
    The app is really minimalist : only the call to UserPrintf in a task.
    Yes it is corresponding because I make 5 consecutives calls to UserPrintf and in the logs I see 5 times the strange message "Timeout ...".
    The only part a bit complex is the cfg configuration which sets up XDC, BIOS, System Analyser and IPC via capsules.

    I'll try with a smaller set (more like the minimalist examples in SYS/BIOS).

    Otherwise you don't see anything fondamentally wrong with UserPrintf ?

    Regards
    Clement

  • Hi Clement,

    I think the problem is that System Analyzer does not actually read the string from the target.  I'm still trying to figure out what it's doing, but I believe it is using the address of the string to look up (somewhere).  I will ask around and get back to you with more details.

    I think it is still possible for you to write your Log_print wrapper, though.  I was able to reproduce what you are seeing, and then fix it using UIA's LogSnapshot.  I found this in the System Analyzer Tutorial 1D:

    http://processors.wiki.ti.com/index.php/SystemAnalyzerTutorial1D

    I changed your UserPrint() function to the following:

    #include <ti/uia/runtime/LogSnapshot.h>

    Char PrintBuffer[200];

    void UserPrintf( CString fmt, ... )

    {
        VaList va;

        va_start(va, fmt);
        System_vsprintf(PrintBuffer, fmt, va);
        va_end(va);

        LogSnapshot_writeString(0, "PrintBuffer", PrintBuffer,
                strlen(PrintBuffer));
        Log_print1(Diags_USER1, "%s", (IArg)PrintBuffer);
    }

    I made the print buffer global, so as not to be overwritten when the function goes out of scope.  With this method, I got the correct strings in System Analyzer.  I think you will have to ensure that the log event is read before the next one is written.  Otherwise you would just get the latest string.

    Best regards,

        Janet

  • Hi Janet,

    Thank you for your time and input,

    I have other urgencies to deal with before I can continue working on UserPrintf.

    I'll try the LogSnapshot suggestion ASAP and I'll get back to you on this thread when I have news.

    I hope that next week I'll be able to work on it.

    Clement

  • Sounds good.  I'm looking forward to see if this works.

    Best regards,

        Janet

  • Hi Janet,

    Good news I got the time to test your function today, it works fine.

    What do you mean by :
    "I think you will have to ensure that the log event is read before the next one is written.  Otherwise you would just get the latest string."

    I called UserPrintf 5 times consecutively and it worked just fine.

    You think it'll be different when I start using LoggerSM ?

    I also have to see if the execution time is not too high.

    Thank you for the help on this, the LogSnapshot use wasn't intuitive !

    Clement

  • I guess that was just my misunderstanding of how System Analyzer would use the LogSnapshot data.  I tested this out some more, and it seems to work fine.  I'm glad to hear this is working for you, too.

    Best regards,

        Janet