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.
plyatov
Posts: 25
Joined: Tue Feb 25, 2014 10:24 am
Been thanked: 2 times

chprintf and unsigned long long type (uint64_t)

Postby plyatov » Thu May 08, 2014 12:22 pm

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: 14455
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: chprintf and unsigned long long type (uint64_t)

Postby Giovanni » Thu May 08, 2014 12:40 pm

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: 141
Joined: Wed Dec 08, 2010 7:52 am
Has thanked: 48 times
Been thanked: 5 times

Re: chprintf and unsigned long long type (uint64_t)

Postby Jacon » Fri May 09, 2014 7:07 pm

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)

Postby rvanspaa » Sun Jun 18, 2017 2:40 am

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)

Postby rvanspaa » Sun Jun 18, 2017 6:44 am

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.


Return to “Development and Feedback”

Who is online

Users browsing this forum: No registered users and 5 guests