How to properly print a uint64_t on CYW43907

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

I am using a CYW43907, specifically the nanosecond clock functions:

uint64_t wiced_get_nanosecond_clock_value( void );

void wiced_deinit_nanosecond_clock( void );

void wiced_reset_nanosecond_clock( void );

void wiced_init_nanosecond_clock( void );

However the top one returns a uint64_t and in order to print it I must use the correct placeholder within the print function as seen below:

#include <inttypes.h>

[...]

uint64_t nano = 4294967295;

WPRINT_APP_INFO(("%"PRIu64"\n", nano));

[...]

However the function either returns 0 or 1610612819 which leads me to believe the way uint64_t is defined is what is causing the problem. This stack overflow thread stdint - How to print a int64_t type in C - Stack Overflow is the basis for my use of PRIu64. I also tried casting nano as a (unsigned long long int) to no avail.

Has anyone dealt with this problem before? Is there an available function to print a uint64_t? Should I be using a different typecast or approach altogether?

Thanks

0 Likes
1 Solution
PriyaM_16
Moderator
Moderator
Moderator
250 replies posted 100 replies posted 50 replies posted

Hi, You can print the int value by typecasting it to double and using the float identifier i.e., WPRINT_APP_INFO((" %f", (double)nano));

As per my understanding, the number is printed in correct format. The least significant half is not printed first.

Can you elaborate a bit on the second question? As per the apps core frequency of 320Mhz, you should be able to get delay of 16microseconds.

View solution in original post

6 Replies
PriyaM_16
Moderator
Moderator
Moderator
250 replies posted 100 replies posted 50 replies posted

I could print the hex value by using WPRINT_APP_INFO((" print nano: %x%x\n", *(((int*)(&nano ))+1), nano )). I will try to figure out the way to print int meanwhile. 

Anonymous
Not applicable

Hi I've been able to use your code to print hex values. A few questions:

1) why do you print the least significant half of the numbers first?

2) What accuracy can we expect with this clock? We are trying to time a 16 microsecond delay and have gotten ~1800 microseconds as an output using the nanosecond clock.

I'd really appreciate the code to print out the int still

Thank you!!

Anonymous
Not applicable

Hi,

Have you made progress printing the decimal value of the uint64_t? I am dealing with the same issue and would greatly appreciate the help.

Thanks for your time!

0 Likes
PriyaM_16
Moderator
Moderator
Moderator
250 replies posted 100 replies posted 50 replies posted

Hi, You can print the int value by typecasting it to double and using the float identifier i.e., WPRINT_APP_INFO((" %f", (double)nano));

As per my understanding, the number is printed in correct format. The least significant half is not printed first.

Can you elaborate a bit on the second question? As per the apps core frequency of 320Mhz, you should be able to get delay of 16microseconds.

Riya was right.... but this seems like a bug on WICED that should be fixed.

See the "C" Mac desktop comparison below

============================================

============== WICED Source: =================

============================================

#include "wiced.h"

void application_start( )

{

    wiced_init(); /* Initialize the WICED device */

    //The LED is initialized in platform.c. If it was not, you would need the following:

    //wiced_gpio_init(WICED_LED1, OUTPUT_PUSH_PULL); */

    char *time_c = "1522462712511";

    WPRINT_APP_INFO(( "----- String time: ----- [%s]\n ",  time_c));

    unsigned long long time = strtoull(time_c, NULL, 10);

    WPRINT_APP_INFO(( "----- long long x: (f cast as double)----- [%f]\n ", (double)time));

    WPRINT_APP_INFO(( "----- long long x: (ld cast as long)------ [%ld]\n ", (long)time));

    WPRINT_APP_INFO(( "----- long long x: (d cast as int)-------- [%d]\n ", (int)time));

    WPRINT_APP_INFO(( "----- long long x: (x)-------------------- [%x]\n ", time));

    WPRINT_APP_INFO(( "----- long long x: (llu)------------------ [%llu]\n ", time));

}

============== Output: =================

Starting WICED Wiced_006.001.000.0085

Platform CYW943907AEVAL1F initialised

Started ThreadX v5.8

Initialising NetX_Duo v5.10_sp3

Creating Packet pools

WLAN MAC Address : A4:08:EA:D9:C1:CC

WLAN Firmware    : wl0: Feb 12 2018 23:35:27 version 7.15.168.108 (r683813) FWID 01-81fd72af

WLAN CLM         : API: 12.2 Data: 9.10.74 Compiler: 1.31.3 ClmImport: 1.36.3 Creation: 2018-02-12 23:30:46

----- String time: ----- [1522462712511]

----- long long x: (f cast as double)----- [1522462712511.000000]

----- long long x: (ld cast as long)------ [2044289727]

----- long long x: (d cast as int)-------- [2044289727]

----- long long x: (x)-------------------- [4b5ff8]

----- long long x: (llu)------------------ [4939818]

========================================================

======= Comparison "C" Source Written on Mac: =================

========================================================

#include <stdio.h>      /* printf, NULL */

#include <stdlib.h>     /* strtoull */

int main ()

{

    //The LED is initialized in platform.c. If it was not, you would need the following:

    //wiced_gpio_init(WICED_LED1, OUTPUT_PUSH_PULL); */

    char *time_c = "1522462712511";

    printf( "----- String time: ----- [%s]\n ",  time_c);

    unsigned long long time = strtoull(time_c, NULL, 10);

    printf( "----- long long x: (f cast as double)----- [%f]\n ", (double)time);

    printf( "----- long long x: (ld cast as long)------ [%ld]\n ", (long)time);

    printf( "----- long long x: (d cast as int)-------- [%d]\n ", (int)time);

    printf( "----- long long x: (x)-------------------- [%x]\n ", time);

    printf( "----- long long x: (llu)------------------ [%llu]\n ", time);

}

============== Mac "C" Output: =================

$ ./testull

----- String time: ----- [1522462712511]

----- long long x: (f cast as double)----- [1522462712511.000000]

----- long long x: (ld cast as long)------ [1522462712511]

----- long long x: (d cast as int)-------- [2044289727]

----- long long x: (x)-------------------- [79d962bf]

----- long long x: (llu)------------------ [1522462712511]

craig.detter_3090586 wrote:

Riya was right.... but this seems like a bug on WICED that should be fixed.

See the "C" Mac desktop comparison below

============================================

============== WICED Source: =================

============================================

#include "wiced.h"

void application_start( )

{

    wiced_init(); /* Initialize the WICED device */

    //The LED is initialized in platform.c. If it was not, you would need the following:

    //wiced_gpio_init(WICED_LED1, OUTPUT_PUSH_PULL); */

    char *time_c = "1522462712511";

    WPRINT_APP_INFO(( "----- String time: ----- [%s]\n ",  time_c));

    unsigned long long time = strtoull(time_c, NULL, 10);

    WPRINT_APP_INFO(( "----- long long x: (f cast as double)----- [%f]\n ", (double)time));

    WPRINT_APP_INFO(( "----- long long x: (ld cast as long)------ [%ld]\n ", (long)time));

    WPRINT_APP_INFO(( "----- long long x: (d cast as int)-------- [%d]\n ", (int)time));

    WPRINT_APP_INFO(( "----- long long x: (x)-------------------- [%x]\n ", time));

    WPRINT_APP_INFO(( "----- long long x: (llu)------------------ [%llu]\n ", time));

}

============== Output: =================

Starting WICED Wiced_006.001.000.0085

Platform CYW943907AEVAL1F initialised

Started ThreadX v5.8

Initialising NetX_Duo v5.10_sp3

Creating Packet pools

WLAN MAC Address : A4:08:EA:D9:C1:CC

WLAN Firmware    : wl0: Feb 12 2018 23:35:27 version 7.15.168.108 (r683813) FWID 01-81fd72af

WLAN CLM         : API: 12.2 Data: 9.10.74 Compiler: 1.31.3 ClmImport: 1.36.3 Creation: 2018-02-12 23:30:46

----- String time: ----- [1522462712511]

----- long long x: (f cast as double)----- [1522462712511.000000]

----- long long x: (ld cast as long)------ [2044289727]

----- long long x: (d cast as int)-------- [2044289727]

This is because long is 32 bits on WICED, but it's 64 bits on Mac.

You can check it by:

printf("sizeof(long)=%d \n", sizeof(long));

0 Likes