chprintf and unsigned long long type (uint64_t)

This forum is dedicated to feedback, discussions about ongoing or future developments, ideas and suggestions regarding the ChibiOS projects are welcome. This forum is NOT for support.
Post Reply
plyatov
Posts: 25
Joined: Tue Feb 25, 2014 10:24 am
Been thanked: 2 times

chprintf and unsigned long long type (uint64_t)

Post by plyatov »

Dear all,

I need uint64_t variables to store time in seconds. It need to be capacious enough to store many years without overflow.

Does somebody have patch or idea for chprintf function to support "unsigned long long" type or "uint64_t"?

Current implementation of chprintf() in ChibiOS-2.4.6 does not understand such a type.

Here is example, which print "123456 0" instead of "123456 78":

Code: Select all

uint64_t time = 123456;
uint16_t other_var = 78;

chprintf((BaseSequentialStream *)&SD1, "%ld %d\n\r", time, other_var);


Second example, which print "ld 123456" instead of "123456 78":

Code: Select all

uint64_t time = 123456;
uint16_t other_var = 78;

chprintf((BaseSequentialStream *)&SD1, "%lld %d\n\r", time, other_var);


Any ideas?
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: chprintf and unsigned long long type (uint64_t)

Post by Giovanni »

Hi,

chprintf() is meant to be an utility non a full implementation, you could just use the normal printf() in the C library.

Giovanni
Jacon
Posts: 143
Joined: Wed Dec 08, 2010 7:52 am
Has thanked: 50 times
Been thanked: 5 times

Re: chprintf and unsigned long long type (uint64_t)

Post by Jacon »

plyatov wrote:I need uint64_t variables to store time in seconds. It need to be capacious enough to store many years without overflow.
....
Any ideas?

Yep - do you really need count for more then 138 ( :!: ) years:

3600 * 24 * 30 * 12 * 138 ....... = 4292352000 < 2^32, i.e. uint32_t ;)
_hr___d___m__y___no of ys
rvanspaa
Posts: 11
Joined: Mon Apr 24, 2017 7:51 am

Re: chprintf and unsigned long long type (uint64_t)

Post by rvanspaa »

Giovanni wrote:Hi,

chprintf() is meant to be an utility non a full implementation, you could just use the normal printf() in the C library.

Giovanni

Hi Giovanni,

printf expects to print to stdout, however this isn't connected to a BaseSequentialStream under ChibiOS. How does one go about establishing such a connection?
rvanspaa
Posts: 11
Joined: Mon Apr 24, 2017 7:51 am

Re: chprintf and unsigned long long type (uint64_t)

Post by rvanspaa »

rvanspaa wrote:
Giovanni wrote:Hi,

chprintf() is meant to be an utility non a full implementation, you could just use the normal printf() in the C library.

Giovanni

Hi Giovanni,

Please ignore previous email, I found syscalls.c, but now can't find how to delete a post (delete icon missing from post). Must have been up too long already.
Post Reply