1 /* sema_b.c */
2 
3 /*
4  * Copyright (c) 1997-2010, 2013-2015 Wind River Systems, Inc.
5  *
6  * SPDX-License-Identifier: Apache-2.0
7  */
8 
9 #include "master.h"
10 
11 /**
12  * @brief Semaphore signal speed test
13  */
sema_test(void)14 void sema_test(void)
15 {
16 	uint32_t et; /* elapsed Time */
17 	int i;
18 	timing_t  start;
19 	timing_t  end;
20 
21 	PRINT_STRING(dashline);
22 	start = timing_timestamp_get();
23 	for (i = 0; i < NR_OF_SEMA_RUNS; i++) {
24 	  k_sem_give(&SEM0);
25 	}
26 	end = timing_timestamp_get();
27 	et = (uint32_t)timing_cycles_get(&start, &end);
28 
29 	PRINT_F(FORMAT, "signal semaphore",
30 		SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_SEMA_RUNS));
31 
32 	k_sem_reset(&SEM1);
33 	k_sem_give(&STARTRCV);
34 
35 	start = timing_timestamp_get();
36 	for (i = 0; i < NR_OF_SEMA_RUNS; i++) {
37 		k_sem_give(&SEM1);
38 	}
39 	end = timing_timestamp_get();
40 	et = (uint32_t)timing_cycles_get(&start, &end);
41 
42 	PRINT_F(FORMAT, "signal to waiting high pri task",
43 		SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_SEMA_RUNS));
44 
45 	start = timing_timestamp_get();
46 	for (i = 0; i < NR_OF_SEMA_RUNS; i++) {
47 		k_sem_give(&SEM1);
48 	}
49 	end = timing_timestamp_get();
50 	et = (uint32_t)timing_cycles_get(&start, &end);
51 
52 	PRINT_F(FORMAT, "signal to waiting high pri task, with timeout",
53 		SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_SEMA_RUNS));
54 }
55