chprintf and 64-bit numbers

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

chprintf and 64-bit numbers

Post by tsichevski »

Hi,
Is it possible to use 64-bit values with chprintf?
Regards,
Vladimir
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: chprintf and 64-bit numbers

Post by Giovanni »

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

Post by tsichevski »

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: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: chprintf and 64-bit numbers

Post by Giovanni »

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: 834
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 12 times
Been thanked: 138 times

Re: chprintf and 64-bit numbers

Post by steved »

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

Post by tsichevski »

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: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: chprintf and 64-bit numbers

Post by Giovanni »

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

Post by tsichevski »

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: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: chprintf and 64-bit numbers

Post by Giovanni »

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

Post by tsichevski »

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 547 times
Post Reply