1 /* master.h */
2 
3 /*
4  * Copyright (c) 1997-2010, 2014-2015 Wind River Systems, Inc.
5  *
6  * SPDX-License-Identifier: Apache-2.0
7  */
8 
9 #ifndef _MASTER_H
10 #define _MASTER_H
11 
12 #include <zephyr/kernel.h>
13 
14 #include <stdio.h>
15 
16 #include "receiver.h"
17 
18 #include <zephyr/timestamp.h>
19 
20 #include <string.h>
21 
22 #include <zephyr/sys/util.h>
23 
24 #include <zephyr/app_memory/app_memdomain.h>
25 #include <zephyr/timing/timing.h>
26 
27 /* printf format defines. */
28 #define FORMAT "| %-65s|%10u|\n"
29 
30 /* length of the output line */
31 #define SLINE_LEN 256
32 
33 #define NR_OF_MSGQ_RUNS 500
34 #define NR_OF_SEMA_RUNS 500
35 #define NR_OF_MUTEX_RUNS 1000
36 #define NR_OF_MAP_RUNS 1000
37 #define NR_OF_MBOX_RUNS 128
38 #define NR_OF_PIPE_RUNS 256
39 #define SEMA_WAIT_TIME (5000)
40 
41 #ifdef CONFIG_USERSPACE
42 #define BENCH_BMEM  K_APP_BMEM(bench_mem_partition)
43 #define BENCH_DMEM  K_APP_DMEM(bench_mem_partition)
44 #else
45 #define BENCH_BMEM
46 #define BENCH_DMEM
47 #endif
48 
49 /* global data */
50 
51 extern char msg[MAX_MSG];
52 extern char data_bench[MESSAGE_SIZE];
53 extern struct k_pipe *test_pipes[];
54 extern char sline[];
55 
56 #define dashline \
57 	"|--------------------------------------" \
58 	"---------------------------------------|\n"
59 
60 /*
61  * To avoid divisions by 0 faults, wrap the divisor with this macro
62  */
63 #define SAFE_DIVISOR(a) (((a) != 0) ? (a) : 1)
64 
65 
66 /* pipe amount of content to receive (0+, 1+, all) */
67 enum pipe_options {
68 	_0_TO_N = 0x0,
69 	_1_TO_N = 0x1,
70 	_ALL_N  = 0x2,
71 };
72 
73 /* other external functions */
74 
75 extern void recvtask(void *p1, void *p2, void *p3);
76 
77 extern void mailbox_test(void);
78 extern void sema_test(void);
79 extern void message_queue_test(void);
80 extern void mutex_test(void);
81 extern void memorymap_test(void);
82 extern void pipe_test(void);
83 
84 /* kernel objects needed for benchmarking */
85 extern struct k_mutex DEMO_MUTEX;
86 
87 extern struct k_sem SEM0;
88 extern struct k_sem SEM1;
89 extern struct k_sem SEM2;
90 extern struct k_sem SEM3;
91 extern struct k_sem SEM4;
92 extern struct k_sem STARTRCV;
93 
94 extern struct k_msgq DEMOQX1;
95 extern struct k_msgq DEMOQX4;
96 extern struct k_msgq DEMOQX192;
97 extern struct k_msgq MB_COMM;
98 extern struct k_msgq CH_COMM;
99 
100 extern struct k_mbox MAILB1;
101 
102 extern struct k_pipe PIPE_NOBUFF;
103 extern struct k_pipe PIPE_SMALLBUFF;
104 extern struct k_pipe PIPE_BIGBUFF;
105 
106 
107 extern struct k_mem_slab MAP1;
108 
109 /* PRINT_STRING
110  * Macro to print an ASCII NULL terminated string.
111  */
112 #define PRINT_STRING(string)  printk("%s", string)
113 
114 /* PRINT_F
115  * Macro to print a formatted output string.
116  * Assumed that sline character array of SLINE_LEN + 1 characters
117  * is defined in the main file
118  */
119 
120 #define PRINT_F(fmt, ...)					        \
121 {									\
122 	snprintf(sline, SLINE_LEN, fmt, ##__VA_ARGS__);                 \
123 	PRINT_STRING(sline);					        \
124 }
125 
126 __syscall void test_thread_priority_set(k_tid_t thread, int prio);
127 __syscall timing_t timing_timestamp_get(void);
128 
129 #include <syscalls/master.h>
130 
131 #endif /* _MASTER_H */
132