<commit_before>/*
 * Copyright (C) 2015-19 <NAME> <<EMAIL>>
 *               2013 INRIA
 *               2017 HAW Hamburg
 *
 * This file is subject to the terms and conditions of the GNU Lesser
 * General Public License v2.1. See the file LICENSE in the top level
 * directory for more details.
 */

/**
 * @ingroup tests
 * @{
 *
 * @file
 * @brief       xtimer_msg test application
 *
 * @author      <NAME> <<EMAIL>>
 * @author      <NAME> <<EMAIL>>
 * @author      <NAME> <mehlis@inf.fu-berlin.de>
 * @author      <NAME> <<EMAIL>>
 * @}
 */

#include <stdio.h>

#include "ztimer.h"
#include "thread.h"
#include "msg.h"
#include "timex.h"

#ifdef MODULE_ZTIMER_MSEC
#define ZTIMER ZTIMER_MSEC
#define TICKS_PER_SEC MS_PER_SEC
#else
#define ZTIMER ZTIMER_USEC
#define TICKS_PER_SEC US_PER_SEC
#endif

char timer_stack[THREAD_STACKSIZE_DEFAULT];
char timer_stack_local[THREAD_STACKSIZE_DEFAULT];

struct timer_msg {
    ztimer_t timer;
    uint32_t interval;
    char *text;
    msg_t msg;
};

struct timer_msg msg_a = { .interval = (2 * TICKS_PER_SEC),
                           .text = "Hello World" };
struct timer_msg msg_b = { .interval = (5 * TICKS_PER_SEC),
                           .text = "This is a Test" };

void *timer_thread(void *arg)
{
    (void) arg;

    printf("This is thread %" PRIkernel_pid "\n", thread_getpid());

    /* The queue is required to avoid loss of a 2nd message, when the 1st is
     * still processed. The timing ensures that at most 1 message is queued.
     */
    msg_t msgq[1];
    msg_init_queue(msgq, 1);

    while (1) {
        msg_t m;
        msg_receive(&m);
        struct timer_msg *tmsg = m.content.ptr;
        uint32_t now = ztimer_now(ZTIMER);
        printf("now=%" PRIu32 ":%" PRIu32 " -> every %" PRIu32 ".%" PRIu32 "s: %s\n",
               (now / TICKS_PER_SEC),
               (now % TICKS_PER_SEC),
               tmsg->interval / TICKS_PER_SEC,
               tmsg->interval % TICKS_PER_SEC,
               tmsg->text);

        tmsg->msg.type = 12345;
        tmsg->msg.content.ptr = tmsg;
        ztimer_set_msg(ZTIMER, &tmsg->timer, tmsg->interval, &tmsg->msg, thread_getpid());
    }
}

void *timer_thread_local(void *arg)
{
    (void) arg;

    printf("This is thread %" PRIkernel_pid "\n", thread_getpid());
<commit_msg>tests/ztimer_msg: Use %lu to print times<commit_after>/*
 * Copyright (C) 2015-19 <NAME> <<EMAIL>>
 *               2013 INRIA
 *               2017 HAW Hamburg
 *
 * This file is subject to the terms and conditions of the GNU Lesser
 * General Public License v2.1. See the file LICENSE in the top level
 * directory for more details.
 */

/**
 * @ingroup tests
 * @{
 *
 * @file
 * @brief       xtimer_msg test application
 *
 * @author      <NAME> <<EMAIL>>
 * @author      <NAME> <<EMAIL>>
 * @author      <NAME> <<EMAIL>.fu-berlin.de>
 * @author      <NAME> <<EMAIL>>
 * @}
 */

#include <stdio.h>

#include "ztimer.h"
#include "thread.h"
#include "msg.h"
#include "timex.h"

#ifdef MODULE_ZTIMER_MSEC
#define ZTIMER ZTIMER_MSEC
#define TICKS_PER_SEC MS_PER_SEC
#else
#define ZTIMER ZTIMER_USEC
#define TICKS_PER_SEC US_PER_SEC
#endif

char timer_stack[THREAD_STACKSIZE_DEFAULT];
char timer_stack_local[THREAD_STACKSIZE_DEFAULT];

struct timer_msg {
    ztimer_t timer;
    uint32_t interval;
    char *text;
    msg_t msg;
};

struct timer_msg msg_a = { .interval = (2 * TICKS_PER_SEC),
                           .text = "Hello World" };
struct timer_msg msg_b = { .interval = (5 * TICKS_PER_SEC),
                           .text = "This is a Test" };

void *timer_thread(void *arg)
{
    (void) arg;

    printf("This is thread %" PRIkernel_pid "\n", thread_getpid());

    /* The queue is required to avoid loss of a 2nd message, when the 1st is
     * still processed. The timing ensures that at most 1 message is queued.
     */
    msg_t msgq[1];
    msg_init_queue(msgq, 1);

    while (1) {
        msg_t m;
        msg_receive(&m);
        struct timer_msg *tmsg = m.content.ptr;
        uint32_t now = ztimer_now(ZTIMER);
        printf("now=%lu:%lu -> every %lu.%lus: %s\n",
               (now / TICKS_PER_SEC),
               (now % TICKS_PER_SEC),
               tmsg->interval / TICKS_PER_SEC,
               tmsg->interval % TICKS_PER_SEC,
               tmsg->text);

        tmsg->msg.type = 12345;
        tmsg->msg.content.ptr = tmsg;
        ztimer_set_msg(ZTIMER, &tmsg->timer, tmsg->interval, &tmsg->msg, thread_getpid());
    }
}

void *timer_thread_local(void *arg)
{
    (void) arg;

    printf("This is thread %" PRIkernel_pid "\n", thread_getpid());

{'fraction_non_alphanumeric': 0.12762237762237763, 'fraction_numerical': 0.016171328671328672, 'mean_word_length': 2.485910129474486, 'pattern_counts': {'":': 1, '<': 34, '<?xml version=': 0, '>': 52, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2938061', 'n_tokens_mistral': 1689, 'n_tokens_neox': 1624, 'n_words': 421}