Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
main.c File Reference
#include <stdlib.h>
#include <ztest.h>
#include <zephyr/types.h>

Data Structures

struct  timer_data
 

Macros

#define DURATION   100
 
#define PERIOD   50
 
#define EXPIRE_TIMES   4
 
#define WITHIN_ERROR(var, target, epsilon)   (abs((target) - (var)) <= (epsilon))
 
#define INEXACT_MS_CONVERT   ((CONFIG_SYS_CLOCK_TICKS_PER_SEC % MSEC_PER_SEC) != 0)
 
#define BUSY_TICK_SLEW_PPM   0U
 
#define PPM_DIVISOR   1000000U
 
#define BUSY_SLEW_THRESHOLD_TICKS(_us)
 
#define TIMER_ASSERT(exp, tmr)
 

Functions

static void duration_expire (struct k_timer *timer)
 
static void duration_stop (struct k_timer *timer)
 
 K_TIMER_DEFINE (ktimer, duration_expire, duration_stop)
 
void test_time_conversions (void)
 
static void init_timer_data (void)
 
static bool interval_check (int64_t interval, int64_t desired)
 
static void period0_expire (struct k_timer *timer)
 
static void status_expire (struct k_timer *timer)
 
static void busy_wait_ms (int32_t ms)
 
static void status_stop (struct k_timer *timer)
 
void test_timer_duration_period (void)
 Test duration and period of Timer. More...
 
void test_timer_restart (void)
 Test restart the timer. More...
 
void test_timer_period_0 (void)
 Test Timer with zero period value. More...
 
void test_timer_period_k_forever (void)
 Test Timer with K_FOREVER period value. More...
 
void test_timer_expirefn_null (void)
 Test Timer without any timer expiry callback function. More...
 
static void tick_sync (void)
 
void test_timer_periodicity (void)
 Test to check timer periodicity. More...
 
void test_timer_status_get (void)
 Test Timer status and time remaining before next expiry. More...
 
void test_timer_status_get_anytime (void)
 Test Timer status randomly after certain duration. More...
 
void test_timer_status_sync (void)
 Test Timer thread synchronization. More...
 
void test_timer_k_define (void)
 Test statically defined Timer init. More...
 
static void user_data_timer_handler (struct k_timer *timer)
 
 K_TIMER_DEFINE (timer0, user_data_timer_handler, NULL)
 
 K_TIMER_DEFINE (timer1, user_data_timer_handler, NULL)
 
 K_TIMER_DEFINE (timer2, user_data_timer_handler, NULL)
 
 K_TIMER_DEFINE (timer3, user_data_timer_handler, NULL)
 
 K_TIMER_DEFINE (timer4, user_data_timer_handler, NULL)
 
void test_timer_user_data (void)
 Test user-specific data associated with timer. More...
 
void test_timer_remaining (void)
 Test accuracy of k_timer_remaining_get() More...
 
void test_timeout_abs (void)
 
void test_sleep_abs (void)
 
static void timer_init (struct k_timer *timer, k_timer_expiry_t expiry_fn, k_timer_stop_t stop_fn)
 
void test_main (void)
 

Variables

static struct k_timer duration_timer
 
static struct k_timer period0_timer
 
static struct k_timer expire_timer
 
static struct k_timer sync_timer
 
static struct k_timer periodicity_timer
 
static struct k_timer status_timer
 
static struct k_timer status_anytime_timer
 
static struct k_timer status_sync_timer
 
static struct k_timer remain_timer
 
static ZTEST_BMEM struct timer_data tdata
 
static ZTEST_DMEM struct k_timer * user_data_timer [5]
 
static const intptr_t user_data [5] = { 0x1337, 0xbabe, 0xd00d, 0xdeaf, 0xfade }
 
static ZTEST_BMEM int user_data_correct [5]
 

Macro Definition Documentation

◆ BUSY_SLEW_THRESHOLD_TICKS

#define BUSY_SLEW_THRESHOLD_TICKS (   _us)
Value:
static uint32_t k_us_to_ticks_ceil32(uint32_t t)
Convert microseconds to ticks.
Definition: time_units.h:523
#define BUSY_TICK_SLEW_PPM
Definition: main.c:38
#define PPM_DIVISOR
Definition: main.c:40

◆ BUSY_TICK_SLEW_PPM

#define BUSY_TICK_SLEW_PPM   0U

◆ DURATION

#define DURATION   100

◆ EXPIRE_TIMES

#define EXPIRE_TIMES   4

◆ INEXACT_MS_CONVERT

#define INEXACT_MS_CONVERT   ((CONFIG_SYS_CLOCK_TICKS_PER_SEC % MSEC_PER_SEC) != 0)

◆ PERIOD

#define PERIOD   50

◆ PPM_DIVISOR

#define PPM_DIVISOR   1000000U

◆ TIMER_ASSERT

#define TIMER_ASSERT (   exp,
  tmr 
)
Value:
do { \
if (!(exp)) { \
k_timer_stop(tmr); \
zassert_true(exp, NULL); \
} \
} while (0)

◆ WITHIN_ERROR

#define WITHIN_ERROR (   var,
  target,
  epsilon 
)    (abs((target) - (var)) <= (epsilon))

Function Documentation

◆ busy_wait_ms()

static void busy_wait_ms ( int32_t  ms)
static

◆ duration_expire()

static void duration_expire ( struct k_timer *  timer)
static

TESTPOINT: expire function

◆ duration_stop()

static void duration_stop ( struct k_timer *  timer)
static

◆ init_timer_data()

static void init_timer_data ( void  )
static

◆ interval_check()

static bool interval_check ( int64_t  interval,
int64_t  desired 
)
static

◆ K_TIMER_DEFINE() [1/6]

K_TIMER_DEFINE ( ktimer  ,
duration_expire  ,
duration_stop   
)

TESTPOINT: init timer via K_TIMER_DEFINE

◆ K_TIMER_DEFINE() [2/6]

K_TIMER_DEFINE ( timer0  ,
user_data_timer_handler  ,
NULL   
)

◆ K_TIMER_DEFINE() [3/6]

K_TIMER_DEFINE ( timer1  ,
user_data_timer_handler  ,
NULL   
)

◆ K_TIMER_DEFINE() [4/6]

K_TIMER_DEFINE ( timer2  ,
user_data_timer_handler  ,
NULL   
)

◆ K_TIMER_DEFINE() [5/6]

K_TIMER_DEFINE ( timer3  ,
user_data_timer_handler  ,
NULL   
)

◆ K_TIMER_DEFINE() [6/6]

K_TIMER_DEFINE ( timer4  ,
user_data_timer_handler  ,
NULL   
)

◆ period0_expire()

static void period0_expire ( struct k_timer *  timer)
static

◆ status_expire()

static void status_expire ( struct k_timer *  timer)
static

TESTPOINT: status get upon timer expired

TESTPOINT: remaining get upon timer expired

◆ status_stop()

static void status_stop ( struct k_timer *  timer)
static

TESTPOINT: remaining get upon timer stopped

◆ test_main()

void test_main ( void  )

test case main entry

◆ test_sleep_abs()

void test_sleep_abs ( void  )

◆ test_time_conversions()

void test_time_conversions ( void  )

◆ test_timeout_abs()

void test_timeout_abs ( void  )

◆ tick_sync()

static void tick_sync ( void  )
static

◆ timer_init()

static void timer_init ( struct k_timer *  timer,
k_timer_expiry_t  expiry_fn,
k_timer_stop_t  stop_fn 
)
static

◆ user_data_timer_handler()

static void user_data_timer_handler ( struct k_timer *  timer)
static

Variable Documentation

◆ duration_timer

struct k_timer duration_timer
static

◆ expire_timer

struct k_timer expire_timer
static

◆ period0_timer

struct k_timer period0_timer
static

◆ periodicity_timer

struct k_timer periodicity_timer
static

◆ remain_timer

struct k_timer remain_timer
static

◆ status_anytime_timer

struct k_timer status_anytime_timer
static

◆ status_sync_timer

struct k_timer status_sync_timer
static

◆ status_timer

struct k_timer status_timer
static

◆ sync_timer

struct k_timer sync_timer
static

◆ tdata

ZTEST_BMEM struct timer_data tdata
static

◆ user_data

const intptr_t user_data[5] = { 0x1337, 0xbabe, 0xd00d, 0xdeaf, 0xfade }
static

◆ user_data_correct

ZTEST_BMEM int user_data_correct[5]
static

◆ user_data_timer

ZTEST_DMEM struct k_timer* user_data_timer[5]
static
Initial value:
= {
&timer0, &timer1, &timer2, &timer3, &timer4
}