Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sys/fmt: Add print_s64_dec to header #15979

Merged
merged 3 commits into from
Feb 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions sys/include/fmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,15 @@ void print_u64_hex(uint64_t val);
*/
void print_u64_dec(uint64_t val);

/**
* @brief Print int64 value as decimal to stdout
*
* @note This uses fmt_s64_dec(), which uses ~400b of code.
*
* @param[in] val Value to print
*/
void print_s64_dec(uint64_t val);

/**
* @brief Print float value
*
Expand Down
18 changes: 18 additions & 0 deletions tests/fmt_print/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,24 @@
int main(void)
{
print_str("If you can read this:\n");
print_u32_dec(0xFFFFFFFF);
print_str("\n");
print_s32_dec(0x80000000);
print_str("\n");
print_byte_hex(0xFA);
print_str("\n");
print_s32_dec(0x80000000);
print_str("\n");
print_u32_hex(0x12345678);
print_str("\n");
print_u64_hex(0x123456789ABCDEF0);
print_str("\n");
print_u64_dec(0xFFFFFFFFFFFFFFFF);
print_str("\n");
print_s64_dec(0x8000000000000000);
print_str("\n");
print_float(1.2345, 5);
print_str("\n");
print_str("Test successful.\n");

return 0;
Expand Down
9 changes: 9 additions & 0 deletions tests/fmt_print/tests/01-run.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@

def testfunc(child):
child.expect_exact('If you can read this:')
child.expect_exact('4294967295')
child.expect_exact('-2147483648')
child.expect_exact('FA')
child.expect_exact('-2147483648')
child.expect_exact('12345678')
child.expect_exact('123456789ABCDEF0')
child.expect_exact('18446744073709551615')
child.expect_exact('-9223372036854775808')
child.expect_exact('1.23450')
child.expect_exact('Test successful.')


Expand Down
10 changes: 0 additions & 10 deletions tests/periph_ptp_clock/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,6 @@
static mutex_t sync_mutex = MUTEX_INIT_LOCKED;
static atomic_uint_least64_t timestamp;

static inline void print_s64_dec(int64_t _num)
{
uint64_t num = _num;
if (_num < 0) {
print_str("-");
num = -_num;
}
print_u64_dec(num);
}

static void speed_adj_cb(void *arg, int chan)
{
(void)arg;
Expand Down