Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / examples / platform / k32w / app / support / FreeRtosMbedtlsUtils.c
1 /*
2  *
3  *    Copyright (c) 2020 Google LLC.
4  *    All rights reserved.
5  *
6  *    Licensed under the Apache License, Version 2.0 (the "License");
7  *    you may not use this file except in compliance with the License.
8  *    You may obtain a copy of the License at
9  *
10  *        http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *    Unless required by applicable law or agreed to in writing, software
13  *    distributed under the License is distributed on an "AS IS" BASIS,
14  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *    See the License for the specific language governing permissions and
16  *    limitations under the License.
17  *
18  */
19
20 #include "FreeRtosMbedtlsUtils.h"
21
22 #include "FreeRTOS.h"
23 #include "semphr.h"
24
25 #include <assert.h>
26
27 #include <stdio.h>
28 #include <string.h>
29
30 static inline void mutex_init(mbedtls_threading_mutex_t * p_mutex)
31 {
32     assert(p_mutex != NULL);
33     *p_mutex = xSemaphoreCreateMutex();
34     assert(*p_mutex != NULL);
35 }
36
37 static inline void mutex_free(mbedtls_threading_mutex_t * p_mutex)
38 {
39     assert(p_mutex != NULL);
40     assert(*p_mutex != NULL);
41     vSemaphoreDelete(*p_mutex);
42 }
43
44 static inline int mutex_lock(mbedtls_threading_mutex_t * p_mutex)
45 {
46     assert(p_mutex != NULL);
47     assert(*p_mutex != NULL);
48     return xSemaphoreTake(*p_mutex, portMAX_DELAY) != pdTRUE;
49 }
50
51 static inline int mutex_unlock(mbedtls_threading_mutex_t * p_mutex)
52 {
53     assert(p_mutex != NULL);
54     assert(*p_mutex != NULL);
55     return xSemaphoreGive(*p_mutex) != pdTRUE;
56 }
57
58 void freertos_mbedtls_mutex_init(void)
59 {
60     mbedtls_threading_set_alt(mutex_init, mutex_free, mutex_lock, mutex_unlock);
61 }
62
63 void freertos_mbedtls_mutex_free(void)
64 {
65     mbedtls_threading_free_alt();
66 }