chprintf and 64-bit numbers

Discussions and support about ChibiOS/HAL, the MCU Hardware Abstraction Layer.
tsichevski
Posts: 35
Joined: Fri Feb 09, 2018 12:44 am
Has thanked: 2 times
Been thanked: 5 times

chprintf and 64-bit numbers

Postby tsichevski » Tue Nov 27, 2018 4:11 pm

Hi,
Is it possible to use 64-bit values with chprintf?
Regards,
Vladimir

User avatar
Giovanni
Site Admin
Posts: 13115
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 765 times
Been thanked: 647 times
Contact:

Re: chprintf and 64-bit numbers

Postby Giovanni » Tue Nov 27, 2018 6:24 pm

Hi,

Currently not, it is not meant for a full printf() replacement.

Giovanni

tsichevski
Posts: 35
Joined: Fri Feb 09, 2018 12:44 am
Has thanked: 2 times
Been thanked: 5 times

Re: chprintf and 64-bit numbers

Postby tsichevski » Tue Nov 27, 2018 7:20 pm

If I add the 64-bit support, would it be appropriate to add it to ChibiOS somehow?
Regards,
Vladimir

User avatar
Giovanni
Site Admin
Posts: 13115
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 765 times
Been thanked: 647 times
Contact:

Re: chprintf and 64-bit numbers

Postby Giovanni » Tue Nov 27, 2018 8:36 pm

Hi,

It depends on code size increase, it is just an utility and it is meant to run also on 8 bits cores, some compilers don't have 64 bits types at all.

Giovanni

steved
Posts: 734
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 10 times
Been thanked: 109 times

Re: chprintf and 64-bit numbers

Postby steved » Tue Nov 27, 2018 11:42 pm

Giovanni wrote:Hi,

It depends on code size increase, it is just an utility and it is meant to run also on 8 bits cores, some compilers don't have 64 bits types at all.

Giovanni

Maybe enable/disable dependent on 64-bit type support (c99 standard or later).

Or have a default setting which is processor dependent, with an option to override (default disable on 8-bit, F0; enable on F4, F7, H7 for example).

Or both.

tsichevski
Posts: 35
Joined: Fri Feb 09, 2018 12:44 am
Has thanked: 2 times
Been thanked: 5 times

Re: chprintf and 64-bit numbers

Postby tsichevski » Wed Nov 28, 2018 12:09 am

Giovanni wrote:Hi,

It depends on code size increase, it is just an utility and it is meant to run also on 8 bits cores, some compilers don't have 64 bits types at all.

Giovanni


In any case it should be coded with conditionals, like the following:

Code: Select all

#ifdef CHPRINTF_USE_LONGLONG
....
#endif // CHPRINTF_USE_LONGLONG

User avatar
Giovanni
Site Admin
Posts: 13115
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 765 times
Been thanked: 647 times
Contact:

Re: chprintf and 64-bit numbers

Postby Giovanni » Wed Nov 28, 2018 6:47 am

A conditional would be fine, note there are other conditionals, follow that pattern.

Giovanni

tsichevski
Posts: 35
Joined: Fri Feb 09, 2018 12:44 am
Has thanked: 2 times
Been thanked: 5 times

Re: chprintf and 64-bit numbers

Postby tsichevski » Tue Dec 04, 2018 5:45 pm

Done. There can I send the patched files? This forum does not allow to attach .c files :(

Regards,
Vladimir

User avatar
Giovanni
Site Admin
Posts: 13115
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 765 times
Been thanked: 647 times
Contact:

Re: chprintf and 64-bit numbers

Postby Giovanni » Tue Dec 04, 2018 6:35 pm

Hi,

You can attach zip/7z files.

Giovanni

tsichevski
Posts: 35
Joined: Fri Feb 09, 2018 12:44 am
Has thanked: 2 times
Been thanked: 5 times

Re: chprintf and 64-bit numbers

Postby tsichevski » Tue Dec 04, 2018 7:57 pm

The modified chprintf.c attached.

Also, you'll need to add something like

Code: Select all

/**
 * @brief   Long long type support.
 */
#if !defined(CHPRINTF_USE_LONGLONG) || defined(__DOXYGEN__)
#define CHPRINTF_USE_LONGLONG          TRUE
#endif


to the chprintf.h

Regards,
Vladimir
Attachments
chprintf.c.zip
(2.96 KiB) Downloaded 36 times


Return to “ChibiOS/HAL”

Who is online

Users browsing this forum: No registered users and 2 guests