Page 1 of 1

chprintf and unsigned long long type (uint64_t)

Posted: Thu May 08, 2014 12:22 pm
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?

Re: chprintf and unsigned long long type (uint64_t)

Posted: Thu May 08, 2014 12:40 pm
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

Re: chprintf and unsigned long long type (uint64_t)

Posted: Fri May 09, 2014 7:07 pm
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

Re: chprintf and unsigned long long type (uint64_t)

Posted: Sun Jun 18, 2017 2:40 am
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?

Re: chprintf and unsigned long long type (uint64_t)

Posted: Sun Jun 18, 2017 6:44 am
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.