1 /* mailbox_r.c */
2 
3 /*
4  * Copyright (c) 1997-2010, 2013-2014 Wind River Systems, Inc.
5  *
6  * SPDX-License-Identifier: Apache-2.0
7  */
8 
9 #include "receiver.h"
10 #include "master.h"
11 
12 /*
13  * Function prototypes.
14  */
15 void mailbox_get(struct k_mbox *mailbox,
16 		int size,
17 		int count,
18 		unsigned int *time);
19 
20 /*
21  * Function declarations.
22  */
23 
24 /* mailbox transfer speed test */
25 
26 /**
27  * @brief Receive task
28  */
mailrecvtask(void)29 void mailrecvtask(void)
30 {
31 	int getsize;
32 	unsigned int gettime;
33 	int getcount;
34 	struct getinfo getinfo;
35 
36 	getcount = NR_OF_MBOX_RUNS;
37 
38 	getsize = 0;
39 	mailbox_get(&MAILB1, getsize, getcount, &gettime);
40 	getinfo.time = gettime;
41 	getinfo.size = getsize;
42 	getinfo.count = getcount;
43 	/* acknowledge to master */
44 	k_msgq_put(&MB_COMM, &getinfo, K_FOREVER);
45 
46 	for (getsize = 8; getsize <= MESSAGE_SIZE; getsize <<= 1) {
47 		mailbox_get(&MAILB1, getsize, getcount, &gettime);
48 		getinfo.time = gettime;
49 		getinfo.size = getsize;
50 		getinfo.count = getcount;
51 		/* acknowledge to master */
52 		k_msgq_put(&MB_COMM, &getinfo, K_FOREVER);
53 	}
54 }
55 
56 
57 /**
58  * @brief Receive data portions from the specified mailbox
59  *
60  * @return 0
61  *
62  * @param mailbox   The mailbox to read data from.
63  * @param size      Size of each data portion.
64  * @param count     Number of data portions.
65  * @param time      Resulting time.
66  */
mailbox_get(struct k_mbox * mailbox,int size,int count,unsigned int * time)67 void mailbox_get(struct k_mbox *mailbox,
68 		 int size,
69 		 int count,
70 		 unsigned int *time)
71 {
72 	int i;
73 	timing_t  start;
74 	timing_t  end;
75 	int32_t return_value = 0;
76 	struct k_mbox_msg Message;
77 
78 	Message.rx_source_thread = K_ANY;
79 	Message.size = size;
80 
81 	/* sync with the sender */
82 	k_sem_take(&SEM0, K_FOREVER);
83 	start = timing_timestamp_get();
84 	for (i = 0; i < count; i++) {
85 		return_value |= k_mbox_get(mailbox,
86 					  &Message,
87 					  &data_recv,
88 					  K_FOREVER);
89 	}
90 	end = timing_timestamp_get();
91 	*time = timing_cycles_get(&start, &end);
92 
93 	if (return_value != 0) {
94 		k_panic();
95 	}
96 }
97