Mistake on this page?
Report an issue in GitHub or email us
ipc_queue.h
1 /* Copyright (c) 2018 ARM Limited
2  *
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 
19 #ifndef __PSA_MBED_IPC_QUEUE_H__
20 #define __PSA_MBED_IPC_QUEUE_H__
21 
22 
23 // Includes
24 // --------
25 
26 #include "mbed_assert.h"
27 #include "cmsis_os2.h"
28 #include "cmsis_compiler.h"
29 #include "rtx_lib.h"
30 
31 
32 // IPC Queue Definitions
33 // ---------------------
34 
35 
36 #ifndef IPC_QUEUE_SLOTS
37 #define IPC_QUEUE_SLOTS 4
38 #endif
39 
40 // Maximum number of queue items equals (IPC_QUEUE_SLOTS - 1).
41 // Therefore we enforce a minimum of 2 IPC_QUEUE_SLOTS
42 #if IPC_QUEUE_SLOTS <= 1
43 #undef IPC_QUEUE_SLOTS
44 #define IPC_QUEUE_SLOTS 2
45 #endif
46 
47 #define IPC_QUEUE_BASE_MAGIC 0x63284A0C
48 #define IPC_QUEUE_PRODUCER_MAGIC 0XA248D9FF
49 #define IPC_QUEUE_CONSUMER_MAGIC 0XA68B6542
50 
51 #define IPC_QUEUE_WAIT_ON_FULL_MS 500
52 #define IPC_QUEUE_WAIT_ON_EMPTY_MS 500
53 
54 #define IPC_QUEUE_SEM_MAX_COUNT (1UL) // Maximum number of available tokens for an IPC Queue semaphore
55 #define IPC_QUEUE_SEM_INITIAL_COUNT (0UL) // Initial number of available tokens for an IPC Queue semaphore
56 
57 // NOTE: STRUCT SIZE MUST BE 4 BYTES ALIGNED !!
58 typedef __PACKED_STRUCT ipc_queue_item_t {
59  uint32_t a;
60  uint32_t b;
61  uint32_t c;
62 
63 } __ALIGNED(4) ipc_queue_item_t;
64 MBED_STATIC_ASSERT((sizeof(ipc_queue_item_t) % sizeof(uint32_t) == 0), "ipc_queue_item_t: Struct size must be 4 bytes aligned!");
65 
66 
67 // NOTE: STRUCT SIZE MUST BE 4 BYTES ALIGNED !!
68 typedef __PACKED_STRUCT ipc_base_queue_t {
69  uint32_t magic;
70  volatile uint32_t read_idx;
71  volatile uint32_t write_idx;
72  ipc_queue_item_t data[IPC_QUEUE_SLOTS];
73 
74 } __ALIGNED(4) ipc_base_queue_t;
75 MBED_STATIC_ASSERT((sizeof(ipc_base_queue_t) % sizeof(uint32_t) == 0), "ipc_base_queue_t: Struct size must be 4 bytes aligned!");
76 
77 typedef struct ipc_producer_queue_t {
78  uint32_t magic;
79  volatile __PACKED uint32_t *read_idx;
80  volatile __PACKED uint32_t *write_idx;
81  __PACKED ipc_queue_item_t *data;
82  osMutexId_t mutex;
83  osSemaphoreId_t full_queue_sem;
84 
86 
87 typedef struct ipc_consumer_queue_t {
88  uint32_t magic;
89  volatile __PACKED uint32_t *read_idx;
90  volatile __PACKED uint32_t *write_idx;
91  __PACKED ipc_queue_item_t *data;
92  osSemaphoreId_t read_sem;
93 
95 
96 
97 // Event handling functions
98 // ------------------------
99 
100 void on_new_item(void);
101 void on_vacancy(void);
102 void on_popped_item(ipc_queue_item_t item);
103 
104 
105 // IPC Queue API
106 // -------------
107 
108 void ipc_producer_queue_init(ipc_producer_queue_t *queue,
109  ipc_base_queue_t *base_queue_mem,
110  osMutexId_t mutex,
111  osSemaphoreId_t full_queue_sem
112  );
113 
114 void ipc_consumer_queue_init(ipc_consumer_queue_t *queue,
115  ipc_base_queue_t *base_queue_mem,
116  osSemaphoreId_t read_sem
117  );
118 
119 void ipc_queue_enqueue(ipc_producer_queue_t *queue,
120  ipc_queue_item_t item_ptr
121  );
122 
123 void ipc_queue_drain(ipc_consumer_queue_t *queue);
124 
125 
126 #endif // __PSA_MBED_IPC_QUEUE_H__
#define MBED_STATIC_ASSERT(expr, msg)
MBED_STATIC_ASSERT Declare compile-time assertions, results in compile-time error if condition is fal...
Definition: mbed_assert.h:110
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.