1*a8f7f3fcSMatthias Ringwald /*
2*a8f7f3fcSMatthias Ringwald * Copyright (c) 2013-2017 ARM Limited. All rights reserved.
3*a8f7f3fcSMatthias Ringwald *
4*a8f7f3fcSMatthias Ringwald * SPDX-License-Identifier: Apache-2.0
5*a8f7f3fcSMatthias Ringwald *
6*a8f7f3fcSMatthias Ringwald * Licensed under the Apache License, Version 2.0 (the License); you may
7*a8f7f3fcSMatthias Ringwald * not use this file except in compliance with the License.
8*a8f7f3fcSMatthias Ringwald * You may obtain a copy of the License at
9*a8f7f3fcSMatthias Ringwald *
10*a8f7f3fcSMatthias Ringwald * www.apache.org/licenses/LICENSE-2.0
11*a8f7f3fcSMatthias Ringwald *
12*a8f7f3fcSMatthias Ringwald * Unless required by applicable law or agreed to in writing, software
13*a8f7f3fcSMatthias Ringwald * distributed under the License is distributed on an AS IS BASIS, WITHOUT
14*a8f7f3fcSMatthias Ringwald * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15*a8f7f3fcSMatthias Ringwald * See the License for the specific language governing permissions and
16*a8f7f3fcSMatthias Ringwald * limitations under the License.
17*a8f7f3fcSMatthias Ringwald *
18*a8f7f3fcSMatthias Ringwald * ----------------------------------------------------------------------
19*a8f7f3fcSMatthias Ringwald *
20*a8f7f3fcSMatthias Ringwald * $Date: 10. January 2017
21*a8f7f3fcSMatthias Ringwald * $Revision: V1.2
22*a8f7f3fcSMatthias Ringwald *
23*a8f7f3fcSMatthias Ringwald * Project: CMSIS-RTOS API V1
24*a8f7f3fcSMatthias Ringwald * Title: cmsis_os_v1.c V1 module file
25*a8f7f3fcSMatthias Ringwald *---------------------------------------------------------------------------*/
26*a8f7f3fcSMatthias Ringwald
27*a8f7f3fcSMatthias Ringwald #include <string.h>
28*a8f7f3fcSMatthias Ringwald #include "cmsis_os.h"
29*a8f7f3fcSMatthias Ringwald
30*a8f7f3fcSMatthias Ringwald #if (osCMSIS >= 0x20000U)
31*a8f7f3fcSMatthias Ringwald
32*a8f7f3fcSMatthias Ringwald
33*a8f7f3fcSMatthias Ringwald // Thread
osThreadCreate(const osThreadDef_t * thread_def,void * argument)34*a8f7f3fcSMatthias Ringwald osThreadId osThreadCreate (const osThreadDef_t *thread_def, void *argument) {
35*a8f7f3fcSMatthias Ringwald
36*a8f7f3fcSMatthias Ringwald if (thread_def == NULL) {
37*a8f7f3fcSMatthias Ringwald return (osThreadId)NULL;
38*a8f7f3fcSMatthias Ringwald }
39*a8f7f3fcSMatthias Ringwald return osThreadNew((osThreadFunc_t)thread_def->pthread, argument, &thread_def->attr);
40*a8f7f3fcSMatthias Ringwald }
41*a8f7f3fcSMatthias Ringwald
42*a8f7f3fcSMatthias Ringwald
43*a8f7f3fcSMatthias Ringwald // Signals
44*a8f7f3fcSMatthias Ringwald
45*a8f7f3fcSMatthias Ringwald #define SignalMask ((1U<<osFeature_Signals)-1U)
46*a8f7f3fcSMatthias Ringwald
osSignalSet(osThreadId thread_id,int32_t signals)47*a8f7f3fcSMatthias Ringwald int32_t osSignalSet (osThreadId thread_id, int32_t signals) {
48*a8f7f3fcSMatthias Ringwald uint32_t flags;
49*a8f7f3fcSMatthias Ringwald
50*a8f7f3fcSMatthias Ringwald flags = osThreadFlagsSet(thread_id, (uint32_t)signals);
51*a8f7f3fcSMatthias Ringwald if ((flags & 0x80000000U) != 0U) {
52*a8f7f3fcSMatthias Ringwald return ((int32_t)0x80000000U);
53*a8f7f3fcSMatthias Ringwald }
54*a8f7f3fcSMatthias Ringwald return ((int32_t)(flags & ~((uint32_t)signals)));
55*a8f7f3fcSMatthias Ringwald }
56*a8f7f3fcSMatthias Ringwald
osSignalClear(osThreadId thread_id,int32_t signals)57*a8f7f3fcSMatthias Ringwald int32_t osSignalClear (osThreadId thread_id, int32_t signals) {
58*a8f7f3fcSMatthias Ringwald uint32_t flags;
59*a8f7f3fcSMatthias Ringwald
60*a8f7f3fcSMatthias Ringwald if (thread_id != osThreadGetId()) {
61*a8f7f3fcSMatthias Ringwald return ((int32_t)0x80000000U);
62*a8f7f3fcSMatthias Ringwald }
63*a8f7f3fcSMatthias Ringwald flags = osThreadFlagsClear((uint32_t)signals);
64*a8f7f3fcSMatthias Ringwald if ((flags & 0x80000000U) != 0U) {
65*a8f7f3fcSMatthias Ringwald return ((int32_t)0x80000000U);
66*a8f7f3fcSMatthias Ringwald }
67*a8f7f3fcSMatthias Ringwald return ((int32_t)flags);
68*a8f7f3fcSMatthias Ringwald }
69*a8f7f3fcSMatthias Ringwald
osSignalWait(int32_t signals,uint32_t millisec)70*a8f7f3fcSMatthias Ringwald osEvent osSignalWait (int32_t signals, uint32_t millisec) {
71*a8f7f3fcSMatthias Ringwald osEvent event;
72*a8f7f3fcSMatthias Ringwald uint32_t flags;
73*a8f7f3fcSMatthias Ringwald
74*a8f7f3fcSMatthias Ringwald if (signals != 0) {
75*a8f7f3fcSMatthias Ringwald flags = osThreadFlagsWait((uint32_t)signals, osFlagsWaitAll, millisec);
76*a8f7f3fcSMatthias Ringwald } else {
77*a8f7f3fcSMatthias Ringwald flags = osThreadFlagsWait(SignalMask, osFlagsWaitAny, millisec);
78*a8f7f3fcSMatthias Ringwald }
79*a8f7f3fcSMatthias Ringwald if ((flags > 0U) && (flags < 0x80000000U)) {
80*a8f7f3fcSMatthias Ringwald event.status = osEventSignal;
81*a8f7f3fcSMatthias Ringwald event.value.signals = (int32_t)flags;
82*a8f7f3fcSMatthias Ringwald } else {
83*a8f7f3fcSMatthias Ringwald switch ((int32_t)flags) {
84*a8f7f3fcSMatthias Ringwald case osErrorResource:
85*a8f7f3fcSMatthias Ringwald event.status = osOK;
86*a8f7f3fcSMatthias Ringwald break;
87*a8f7f3fcSMatthias Ringwald case osErrorTimeout:
88*a8f7f3fcSMatthias Ringwald event.status = osEventTimeout;
89*a8f7f3fcSMatthias Ringwald break;
90*a8f7f3fcSMatthias Ringwald case osErrorParameter:
91*a8f7f3fcSMatthias Ringwald event.status = osErrorValue;
92*a8f7f3fcSMatthias Ringwald break;
93*a8f7f3fcSMatthias Ringwald default:
94*a8f7f3fcSMatthias Ringwald event.status = (osStatus)flags;
95*a8f7f3fcSMatthias Ringwald break;
96*a8f7f3fcSMatthias Ringwald }
97*a8f7f3fcSMatthias Ringwald }
98*a8f7f3fcSMatthias Ringwald return event;
99*a8f7f3fcSMatthias Ringwald }
100*a8f7f3fcSMatthias Ringwald
101*a8f7f3fcSMatthias Ringwald
102*a8f7f3fcSMatthias Ringwald // Timer
osTimerCreate(const osTimerDef_t * timer_def,os_timer_type type,void * argument)103*a8f7f3fcSMatthias Ringwald osTimerId osTimerCreate (const osTimerDef_t *timer_def, os_timer_type type, void *argument) {
104*a8f7f3fcSMatthias Ringwald
105*a8f7f3fcSMatthias Ringwald if (timer_def == NULL) {
106*a8f7f3fcSMatthias Ringwald return (osTimerId)NULL;
107*a8f7f3fcSMatthias Ringwald }
108*a8f7f3fcSMatthias Ringwald return osTimerNew((osTimerFunc_t)timer_def->ptimer, type, argument, &timer_def->attr);
109*a8f7f3fcSMatthias Ringwald }
110*a8f7f3fcSMatthias Ringwald
111*a8f7f3fcSMatthias Ringwald
112*a8f7f3fcSMatthias Ringwald // Mutex
osMutexCreate(const osMutexDef_t * mutex_def)113*a8f7f3fcSMatthias Ringwald osMutexId osMutexCreate (const osMutexDef_t *mutex_def) {
114*a8f7f3fcSMatthias Ringwald
115*a8f7f3fcSMatthias Ringwald if (mutex_def == NULL) {
116*a8f7f3fcSMatthias Ringwald return (osMutexId)NULL;
117*a8f7f3fcSMatthias Ringwald }
118*a8f7f3fcSMatthias Ringwald return osMutexNew(mutex_def);
119*a8f7f3fcSMatthias Ringwald }
120*a8f7f3fcSMatthias Ringwald
121*a8f7f3fcSMatthias Ringwald
122*a8f7f3fcSMatthias Ringwald // Semaphore
123*a8f7f3fcSMatthias Ringwald
124*a8f7f3fcSMatthias Ringwald #if (defined (osFeature_Semaphore) && (osFeature_Semaphore != 0U))
125*a8f7f3fcSMatthias Ringwald
osSemaphoreCreate(const osSemaphoreDef_t * semaphore_def,int32_t count)126*a8f7f3fcSMatthias Ringwald osSemaphoreId osSemaphoreCreate (const osSemaphoreDef_t *semaphore_def, int32_t count) {
127*a8f7f3fcSMatthias Ringwald
128*a8f7f3fcSMatthias Ringwald if (semaphore_def == NULL) {
129*a8f7f3fcSMatthias Ringwald return (osSemaphoreId)NULL;
130*a8f7f3fcSMatthias Ringwald }
131*a8f7f3fcSMatthias Ringwald return osSemaphoreNew((uint32_t)count, (uint32_t)count, semaphore_def);
132*a8f7f3fcSMatthias Ringwald }
133*a8f7f3fcSMatthias Ringwald
osSemaphoreWait(osSemaphoreId semaphore_id,uint32_t millisec)134*a8f7f3fcSMatthias Ringwald int32_t osSemaphoreWait (osSemaphoreId semaphore_id, uint32_t millisec) {
135*a8f7f3fcSMatthias Ringwald osStatus_t status;
136*a8f7f3fcSMatthias Ringwald uint32_t count;
137*a8f7f3fcSMatthias Ringwald
138*a8f7f3fcSMatthias Ringwald status = osSemaphoreAcquire(semaphore_id, millisec);
139*a8f7f3fcSMatthias Ringwald switch (status) {
140*a8f7f3fcSMatthias Ringwald case osOK:
141*a8f7f3fcSMatthias Ringwald count = osSemaphoreGetCount(semaphore_id);
142*a8f7f3fcSMatthias Ringwald return ((int32_t)count + 1);
143*a8f7f3fcSMatthias Ringwald case osErrorResource:
144*a8f7f3fcSMatthias Ringwald case osErrorTimeout:
145*a8f7f3fcSMatthias Ringwald return 0;
146*a8f7f3fcSMatthias Ringwald default:
147*a8f7f3fcSMatthias Ringwald break;
148*a8f7f3fcSMatthias Ringwald }
149*a8f7f3fcSMatthias Ringwald return -1;
150*a8f7f3fcSMatthias Ringwald }
151*a8f7f3fcSMatthias Ringwald
152*a8f7f3fcSMatthias Ringwald #endif // Semaphore
153*a8f7f3fcSMatthias Ringwald
154*a8f7f3fcSMatthias Ringwald
155*a8f7f3fcSMatthias Ringwald // Memory Pool
156*a8f7f3fcSMatthias Ringwald
157*a8f7f3fcSMatthias Ringwald #if (defined(osFeature_Pool) && (osFeature_Pool != 0))
158*a8f7f3fcSMatthias Ringwald
osPoolCreate(const osPoolDef_t * pool_def)159*a8f7f3fcSMatthias Ringwald osPoolId osPoolCreate (const osPoolDef_t *pool_def) {
160*a8f7f3fcSMatthias Ringwald
161*a8f7f3fcSMatthias Ringwald if (pool_def == NULL) {
162*a8f7f3fcSMatthias Ringwald return (osPoolId)NULL;
163*a8f7f3fcSMatthias Ringwald }
164*a8f7f3fcSMatthias Ringwald return ((osPoolId)(osMemoryPoolNew(pool_def->pool_sz, pool_def->item_sz, &pool_def->attr)));
165*a8f7f3fcSMatthias Ringwald }
166*a8f7f3fcSMatthias Ringwald
osPoolAlloc(osPoolId pool_id)167*a8f7f3fcSMatthias Ringwald void *osPoolAlloc (osPoolId pool_id) {
168*a8f7f3fcSMatthias Ringwald return osMemoryPoolAlloc((osMemoryPoolId_t)pool_id, 0U);
169*a8f7f3fcSMatthias Ringwald }
170*a8f7f3fcSMatthias Ringwald
osPoolCAlloc(osPoolId pool_id)171*a8f7f3fcSMatthias Ringwald void *osPoolCAlloc (osPoolId pool_id) {
172*a8f7f3fcSMatthias Ringwald void *block;
173*a8f7f3fcSMatthias Ringwald uint32_t block_size;
174*a8f7f3fcSMatthias Ringwald
175*a8f7f3fcSMatthias Ringwald block_size = osMemoryPoolGetBlockSize((osMemoryPoolId_t)pool_id);
176*a8f7f3fcSMatthias Ringwald if (block_size == 0U) {
177*a8f7f3fcSMatthias Ringwald return NULL;
178*a8f7f3fcSMatthias Ringwald }
179*a8f7f3fcSMatthias Ringwald block = osMemoryPoolAlloc((osMemoryPoolId_t)pool_id, 0U);
180*a8f7f3fcSMatthias Ringwald if (block != NULL) {
181*a8f7f3fcSMatthias Ringwald memset(block, 0, block_size);
182*a8f7f3fcSMatthias Ringwald }
183*a8f7f3fcSMatthias Ringwald return block;
184*a8f7f3fcSMatthias Ringwald }
185*a8f7f3fcSMatthias Ringwald
osPoolFree(osPoolId pool_id,void * block)186*a8f7f3fcSMatthias Ringwald osStatus osPoolFree (osPoolId pool_id, void *block) {
187*a8f7f3fcSMatthias Ringwald return osMemoryPoolFree((osMemoryPoolId_t)pool_id, block);
188*a8f7f3fcSMatthias Ringwald }
189*a8f7f3fcSMatthias Ringwald
190*a8f7f3fcSMatthias Ringwald #endif // Memory Pool
191*a8f7f3fcSMatthias Ringwald
192*a8f7f3fcSMatthias Ringwald
193*a8f7f3fcSMatthias Ringwald // Message Queue
194*a8f7f3fcSMatthias Ringwald
195*a8f7f3fcSMatthias Ringwald #if (defined(osFeature_MessageQ) && (osFeature_MessageQ != 0))
196*a8f7f3fcSMatthias Ringwald
osMessageCreate(const osMessageQDef_t * queue_def,osThreadId thread_id)197*a8f7f3fcSMatthias Ringwald osMessageQId osMessageCreate (const osMessageQDef_t *queue_def, osThreadId thread_id) {
198*a8f7f3fcSMatthias Ringwald (void)thread_id;
199*a8f7f3fcSMatthias Ringwald
200*a8f7f3fcSMatthias Ringwald if (queue_def == NULL) {
201*a8f7f3fcSMatthias Ringwald return (osMessageQId)NULL;
202*a8f7f3fcSMatthias Ringwald }
203*a8f7f3fcSMatthias Ringwald return ((osMessageQId)(osMessageQueueNew(queue_def->queue_sz, sizeof(uint32_t), &queue_def->attr)));
204*a8f7f3fcSMatthias Ringwald }
205*a8f7f3fcSMatthias Ringwald
osMessagePut(osMessageQId queue_id,uint32_t info,uint32_t millisec)206*a8f7f3fcSMatthias Ringwald osStatus osMessagePut (osMessageQId queue_id, uint32_t info, uint32_t millisec) {
207*a8f7f3fcSMatthias Ringwald return osMessageQueuePut((osMessageQueueId_t)queue_id, &info, 0U, millisec);
208*a8f7f3fcSMatthias Ringwald }
209*a8f7f3fcSMatthias Ringwald
osMessageGet(osMessageQId queue_id,uint32_t millisec)210*a8f7f3fcSMatthias Ringwald osEvent osMessageGet (osMessageQId queue_id, uint32_t millisec) {
211*a8f7f3fcSMatthias Ringwald osStatus_t status;
212*a8f7f3fcSMatthias Ringwald osEvent event;
213*a8f7f3fcSMatthias Ringwald uint32_t message;
214*a8f7f3fcSMatthias Ringwald
215*a8f7f3fcSMatthias Ringwald status = osMessageQueueGet((osMessageQueueId_t)queue_id, &message, NULL, millisec);
216*a8f7f3fcSMatthias Ringwald switch (status) {
217*a8f7f3fcSMatthias Ringwald case osOK:
218*a8f7f3fcSMatthias Ringwald event.status = osEventMessage;
219*a8f7f3fcSMatthias Ringwald event.value.v = message;
220*a8f7f3fcSMatthias Ringwald break;
221*a8f7f3fcSMatthias Ringwald case osErrorResource:
222*a8f7f3fcSMatthias Ringwald event.status = osOK;
223*a8f7f3fcSMatthias Ringwald break;
224*a8f7f3fcSMatthias Ringwald case osErrorTimeout:
225*a8f7f3fcSMatthias Ringwald event.status = osEventTimeout;
226*a8f7f3fcSMatthias Ringwald break;
227*a8f7f3fcSMatthias Ringwald default:
228*a8f7f3fcSMatthias Ringwald event.status = status;
229*a8f7f3fcSMatthias Ringwald break;
230*a8f7f3fcSMatthias Ringwald }
231*a8f7f3fcSMatthias Ringwald return event;
232*a8f7f3fcSMatthias Ringwald }
233*a8f7f3fcSMatthias Ringwald
234*a8f7f3fcSMatthias Ringwald #endif // Message Queue
235*a8f7f3fcSMatthias Ringwald
236*a8f7f3fcSMatthias Ringwald
237*a8f7f3fcSMatthias Ringwald // Mail Queue
238*a8f7f3fcSMatthias Ringwald
239*a8f7f3fcSMatthias Ringwald #if (defined(osFeature_MailQ) && (osFeature_MailQ != 0))
240*a8f7f3fcSMatthias Ringwald
241*a8f7f3fcSMatthias Ringwald typedef struct os_mail_queue_s {
242*a8f7f3fcSMatthias Ringwald osMemoryPoolId_t mp_id;
243*a8f7f3fcSMatthias Ringwald osMessageQueueId_t mq_id;
244*a8f7f3fcSMatthias Ringwald } os_mail_queue_t;
245*a8f7f3fcSMatthias Ringwald
osMailCreate(const osMailQDef_t * queue_def,osThreadId thread_id)246*a8f7f3fcSMatthias Ringwald osMailQId osMailCreate (const osMailQDef_t *queue_def, osThreadId thread_id) {
247*a8f7f3fcSMatthias Ringwald os_mail_queue_t *ptr;
248*a8f7f3fcSMatthias Ringwald (void)thread_id;
249*a8f7f3fcSMatthias Ringwald
250*a8f7f3fcSMatthias Ringwald if (queue_def == NULL) {
251*a8f7f3fcSMatthias Ringwald return (osMailQId)NULL;
252*a8f7f3fcSMatthias Ringwald }
253*a8f7f3fcSMatthias Ringwald
254*a8f7f3fcSMatthias Ringwald ptr = queue_def->mail;
255*a8f7f3fcSMatthias Ringwald if (ptr == NULL) {
256*a8f7f3fcSMatthias Ringwald return (osMailQId)NULL;
257*a8f7f3fcSMatthias Ringwald }
258*a8f7f3fcSMatthias Ringwald
259*a8f7f3fcSMatthias Ringwald ptr->mp_id = osMemoryPoolNew (queue_def->queue_sz, queue_def->item_sz, &queue_def->mp_attr);
260*a8f7f3fcSMatthias Ringwald ptr->mq_id = osMessageQueueNew(queue_def->queue_sz, sizeof(void *), &queue_def->mq_attr);
261*a8f7f3fcSMatthias Ringwald if ((ptr->mp_id == (osMemoryPoolId_t)NULL) || (ptr->mq_id == (osMessageQueueId_t)NULL)) {
262*a8f7f3fcSMatthias Ringwald if (ptr->mp_id != (osMemoryPoolId_t)NULL) {
263*a8f7f3fcSMatthias Ringwald osMemoryPoolDelete(ptr->mp_id);
264*a8f7f3fcSMatthias Ringwald }
265*a8f7f3fcSMatthias Ringwald if (ptr->mq_id != (osMessageQueueId_t)NULL) {
266*a8f7f3fcSMatthias Ringwald osMessageQueueDelete(ptr->mq_id);
267*a8f7f3fcSMatthias Ringwald }
268*a8f7f3fcSMatthias Ringwald return (osMailQId)NULL;
269*a8f7f3fcSMatthias Ringwald }
270*a8f7f3fcSMatthias Ringwald
271*a8f7f3fcSMatthias Ringwald return (osMailQId)ptr;
272*a8f7f3fcSMatthias Ringwald }
273*a8f7f3fcSMatthias Ringwald
osMailAlloc(osMailQId queue_id,uint32_t millisec)274*a8f7f3fcSMatthias Ringwald void *osMailAlloc (osMailQId queue_id, uint32_t millisec) {
275*a8f7f3fcSMatthias Ringwald os_mail_queue_t *ptr = (os_mail_queue_t *)queue_id;
276*a8f7f3fcSMatthias Ringwald
277*a8f7f3fcSMatthias Ringwald if (ptr == NULL) {
278*a8f7f3fcSMatthias Ringwald return NULL;
279*a8f7f3fcSMatthias Ringwald }
280*a8f7f3fcSMatthias Ringwald return osMemoryPoolAlloc(ptr->mp_id, millisec);
281*a8f7f3fcSMatthias Ringwald }
282*a8f7f3fcSMatthias Ringwald
osMailCAlloc(osMailQId queue_id,uint32_t millisec)283*a8f7f3fcSMatthias Ringwald void *osMailCAlloc (osMailQId queue_id, uint32_t millisec) {
284*a8f7f3fcSMatthias Ringwald os_mail_queue_t *ptr = (os_mail_queue_t *)queue_id;
285*a8f7f3fcSMatthias Ringwald void *block;
286*a8f7f3fcSMatthias Ringwald uint32_t block_size;
287*a8f7f3fcSMatthias Ringwald
288*a8f7f3fcSMatthias Ringwald if (ptr == NULL) {
289*a8f7f3fcSMatthias Ringwald return NULL;
290*a8f7f3fcSMatthias Ringwald }
291*a8f7f3fcSMatthias Ringwald block_size = osMemoryPoolGetBlockSize(ptr->mp_id);
292*a8f7f3fcSMatthias Ringwald if (block_size == 0U) {
293*a8f7f3fcSMatthias Ringwald return NULL;
294*a8f7f3fcSMatthias Ringwald }
295*a8f7f3fcSMatthias Ringwald block = osMemoryPoolAlloc(ptr->mp_id, millisec);
296*a8f7f3fcSMatthias Ringwald if (block != NULL) {
297*a8f7f3fcSMatthias Ringwald memset(block, 0, block_size);
298*a8f7f3fcSMatthias Ringwald }
299*a8f7f3fcSMatthias Ringwald
300*a8f7f3fcSMatthias Ringwald return block;
301*a8f7f3fcSMatthias Ringwald
302*a8f7f3fcSMatthias Ringwald }
303*a8f7f3fcSMatthias Ringwald
osMailPut(osMailQId queue_id,const void * mail)304*a8f7f3fcSMatthias Ringwald osStatus osMailPut (osMailQId queue_id, const void *mail) {
305*a8f7f3fcSMatthias Ringwald os_mail_queue_t *ptr = (os_mail_queue_t *)queue_id;
306*a8f7f3fcSMatthias Ringwald
307*a8f7f3fcSMatthias Ringwald if (ptr == NULL) {
308*a8f7f3fcSMatthias Ringwald return osErrorParameter;
309*a8f7f3fcSMatthias Ringwald }
310*a8f7f3fcSMatthias Ringwald if (mail == NULL) {
311*a8f7f3fcSMatthias Ringwald return osErrorValue;
312*a8f7f3fcSMatthias Ringwald }
313*a8f7f3fcSMatthias Ringwald return osMessageQueuePut(ptr->mq_id, &mail, 0U, 0U);
314*a8f7f3fcSMatthias Ringwald }
315*a8f7f3fcSMatthias Ringwald
osMailGet(osMailQId queue_id,uint32_t millisec)316*a8f7f3fcSMatthias Ringwald osEvent osMailGet (osMailQId queue_id, uint32_t millisec) {
317*a8f7f3fcSMatthias Ringwald os_mail_queue_t *ptr = (os_mail_queue_t *)queue_id;
318*a8f7f3fcSMatthias Ringwald osStatus_t status;
319*a8f7f3fcSMatthias Ringwald osEvent event;
320*a8f7f3fcSMatthias Ringwald void *mail;
321*a8f7f3fcSMatthias Ringwald
322*a8f7f3fcSMatthias Ringwald if (ptr == NULL) {
323*a8f7f3fcSMatthias Ringwald event.status = osErrorParameter;
324*a8f7f3fcSMatthias Ringwald return event;
325*a8f7f3fcSMatthias Ringwald }
326*a8f7f3fcSMatthias Ringwald
327*a8f7f3fcSMatthias Ringwald status = osMessageQueueGet(ptr->mq_id, &mail, NULL, millisec);
328*a8f7f3fcSMatthias Ringwald switch (status) {
329*a8f7f3fcSMatthias Ringwald case osOK:
330*a8f7f3fcSMatthias Ringwald event.status = osEventMail;
331*a8f7f3fcSMatthias Ringwald event.value.p = mail;
332*a8f7f3fcSMatthias Ringwald break;
333*a8f7f3fcSMatthias Ringwald case osErrorResource:
334*a8f7f3fcSMatthias Ringwald event.status = osOK;
335*a8f7f3fcSMatthias Ringwald break;
336*a8f7f3fcSMatthias Ringwald case osErrorTimeout:
337*a8f7f3fcSMatthias Ringwald event.status = osEventTimeout;
338*a8f7f3fcSMatthias Ringwald break;
339*a8f7f3fcSMatthias Ringwald default:
340*a8f7f3fcSMatthias Ringwald event.status = status;
341*a8f7f3fcSMatthias Ringwald break;
342*a8f7f3fcSMatthias Ringwald }
343*a8f7f3fcSMatthias Ringwald return event;
344*a8f7f3fcSMatthias Ringwald }
345*a8f7f3fcSMatthias Ringwald
osMailFree(osMailQId queue_id,void * mail)346*a8f7f3fcSMatthias Ringwald osStatus osMailFree (osMailQId queue_id, void *mail) {
347*a8f7f3fcSMatthias Ringwald os_mail_queue_t *ptr = (os_mail_queue_t *)queue_id;
348*a8f7f3fcSMatthias Ringwald
349*a8f7f3fcSMatthias Ringwald if (ptr == NULL) {
350*a8f7f3fcSMatthias Ringwald return osErrorParameter;
351*a8f7f3fcSMatthias Ringwald }
352*a8f7f3fcSMatthias Ringwald if (mail == NULL) {
353*a8f7f3fcSMatthias Ringwald return osErrorValue;
354*a8f7f3fcSMatthias Ringwald }
355*a8f7f3fcSMatthias Ringwald return osMemoryPoolFree(ptr->mp_id, mail);
356*a8f7f3fcSMatthias Ringwald }
357*a8f7f3fcSMatthias Ringwald
358*a8f7f3fcSMatthias Ringwald #endif // Mail Queue
359*a8f7f3fcSMatthias Ringwald
360*a8f7f3fcSMatthias Ringwald
361*a8f7f3fcSMatthias Ringwald #endif // osCMSIS
362