Zephyr Project API 3.7.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
main.c File Reference
#include <stdlib.h>
#include <zephyr/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)   (llabs((int64_t) ((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)
 TESTPOINT: init timer via K_TIMER_DEFINE.
 
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)
 
 ZTEST_USER (timer_api, test_timer_duration_period)
 Test duration and period of Timer.
 
 ZTEST_USER (timer_api, test_timer_restart)
 Test restart the timer.
 
 ZTEST_USER (timer_api, test_timer_period_0)
 Test Timer with zero period value.
 
 ZTEST_USER (timer_api, test_timer_period_k_forever)
 Test Timer with K_FOREVER period value.
 
 ZTEST_USER (timer_api, test_timer_expirefn_null)
 Test Timer without any timer expiry callback function.
 
static void tick_sync (void)
 
 ZTEST_USER (timer_api, test_timer_periodicity)
 Test to check timer periodicity.
 
 ZTEST_USER (timer_api, test_timer_status_get)
 Test Timer status and time remaining before next expiry.
 
 ZTEST_USER (timer_api, test_timer_status_get_anytime)
 Test Timer status randomly after certain duration.
 
 ZTEST_USER (timer_api, test_timer_status_sync)
 Test Timer thread synchronization.
 
 ZTEST_USER (timer_api, test_timer_k_define)
 Test statically defined Timer init.
 
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)
 
 ZTEST_USER (timer_api, test_timer_user_data)
 Test user-specific data associated with timer.
 
 ZTEST_USER (timer_api, test_timer_remaining)
 Test accuracy of k_timer_remaining_get()
 
 ZTEST_USER (timer_api, test_timeout_abs)
 
 ZTEST_USER (timer_api, test_sleep_abs)
 
static void timer_init (struct k_timer *timer, k_timer_expiry_t expiry_fn, k_timer_stop_t stop_fn)
 
void * setup_timer_api (void)
 
 ZTEST_SUITE (timer_api, NULL, setup_timer_api, NULL, NULL, NULL)
 

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:
#define k_us_to_ticks_ceil32(t)
Convert microseconds to ticks.
Definition time_units.h:901
__UINT64_TYPE__ uint64_t
Definition stdint.h:91
#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); \
} \
} while (0)

◆ WITHIN_ERROR

#define WITHIN_ERROR (   var,
  target,
  epsilon 
)    (llabs((int64_t) ((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

◆ setup_timer_api()

void * setup_timer_api ( void  )

◆ 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

◆ 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

◆ ZTEST_SUITE()

ZTEST_SUITE ( timer_api  ,
NULL  ,
setup_timer_api  ,
NULL  ,
NULL  ,
NULL   
)

◆ ZTEST_USER() [1/2]

ZTEST_USER ( timer_api  ,
test_sleep_abs   
)

◆ ZTEST_USER() [2/2]

ZTEST_USER ( timer_api  ,
test_timeout_abs   
)

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
}
struct k_timer timer2
Definition main.c:17