Mistake on this page?
Report an issue in GitHub or email us
mx_wifi_mbed_os.h
1 /**
2  * <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
3  * SPDX-License-Identifier: BSD-3-Clause
4  * All rights reserved.</center></h2>
5  *
6  * This software component is licensed by ST under BSD 3-Clause license,
7  * the "License"; You may not use this file except in compliance with the
8  * License. You may obtain a copy of the License at:
9  * opensource.org/licenses/BSD-3-Clause
10  *
11  ******************************************************************************
12  */
13 
14 /* Define to prevent recursive inclusion -------------------------------------*/
15 #ifndef MX_WIFI_CMSIS_OS_H
16 #define MX_WIFI_CMSIS_OS_H
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
22 
23 /* Includes ------------------------------------------------------------------*/
24 #include <stdlib.h>
25 #include <stdbool.h>
26 #include <stdint.h>
27 #include "mbed_assert.h"
28 
29 #ifndef MX_WIFI_MALLOC
30 #define MX_WIFI_MALLOC malloc
31 #endif /* MX_WIFI_MALLOC */
32 
33 #ifndef MX_WIFI_FREE
34 #define MX_WIFI_FREE free
35 #endif /* MX_WIFI_FREE */
36 
37 #define BASIC_MALLOC 1
38 /* Assume that OS is not used when bypass is disabled */
39 
40 #if BASIC_MALLOC
41 typedef struct mx_buf {
42  uint32_t len;
43  uint32_t header_len;
44  uint8_t data[1];
45 } mx_buf_t;
46 
47 static inline mx_buf_t *mx_buf_alloc(uint32_t len)
48 {
49  mx_buf_t *p = (mx_buf_t *) MX_WIFI_MALLOC(len + sizeof(mx_buf_t) -1U);
50  if (NULL != p) {
51  p->len = len;
52  p->header_len = 0;
53  }
54  return p;
55 
56 }
57 
58 #define MX_NET_BUFFER_ALLOC(len) mx_buf_alloc(len)
59 #define MX_NET_BUFFER_FREE(p) MX_WIFI_FREE(p)
60 #define MX_NET_BUFFER_HIDE_HEADER(p, n) (p)->header_len += (n)
61 #define MX_NET_BUFFER_PAYLOAD(p) &(p)->data[(p)->header_len]
62 #define MX_NET_BUFFER_SET_PAYLOAD_SIZE(p, size) (p)->len = (size)
63 #define MX_NET_BUFFER_GET_PAYLOAD_SIZE(p) (p)->len
64 
65 #else /* BASIC_ALLOC */
66 
67 #define MX_NET_BUFFER_ALLOC(len) mx_buf_alloc((len))
68 #define MX_NET_BUFFER_FREE(p) mx_buf_free((p))
69 #define MX_NET_BUFFER_HIDE_HEADER(p, n) mx_buf_hide_header((p),(n))
70 #define MX_NET_BUFFER_PAYLOAD(p) mx_buf_payload((p))
71 #define MX_NET_BUFFER_SET_PAYLOAD_SIZE(p, size) mx_buf_set_size((p),(size))
72 #define MX_NET_BUFFER_GET_PAYLOAD_SIZE(p) mx_buf_get_size((p))
73 
74 
75 typedef void mx_buf_t;
76 
77 mx_buf_t *mx_buf_alloc(uint32_t len);
78 void mx_buf_free(mx_buf_t *p);
79 void mx_buf_hide_header(mx_buf_t *p, int32_t n);
80 uint8_t *mx_buf_payload(mx_buf_t *p);
81 uint32_t mx_buf_get_size(mx_buf_t *p);
82 void mx_buf_set_size(mx_buf_t *p, int32_t n);
83 
84 #endif /* BASIC_ALLOC */
85 
86 
87 void mbed_delay(uint32_t delay);
88 void *mbed_mutex_new(void);
89 void mbed_mutex_delete(void *);
90 void mbed_mutex_lock(void *);
91 void mbed_mutex_unlock(void *);
92 
93 
94 void *mbed_sem_new(uint32_t count);
95 void mbed_sem_delete(void *sem);
96 bool mbed_sem_signal(void *sem);
97 bool mbed_sem_wait(void *sem, uint32_t timeout);
98 
99 void *mbed_queue_new(uint32_t count);
100 void mbed_queue_delete(void *sem);
101 void *mbed_queue_pop(void *sem, uint32_t timeout);
102 
103 
104 bool mbed_queue_push(void *sem, void *value, uint32_t timeout);
105 
106 void *mbed_thread_new(void (*thread_entry)(void), uint32_t stacksize, uint32_t priority);
107 void mbed_thread_delete(void *thread);
108 void mbed_thread_terminate(void *thread);
109 
110 
111 #define MX_ASSERT(a) MBED_ASSERT(a)
112 
113 #define LOCK_DECLARE(A) void* A
114 #define LOCK_INIT(A) A = mbed_mutex_new()
115 #define LOCK_DEINIT(A) mbed_mutex_delete(A)
116 #define LOCK(A) mbed_mutex_lock(A)
117 #define UNLOCK(A) mbed_mutex_unlock(A)
118 
119 #define SEM_DECLARE(A) void *A
120 #define SEM_INIT(A,COUNT) A = mbed_sem_new(COUNT);
121 #define SEM_DEINIT(A) mbed_sem_delete(A)
122 #define SEM_SIGNAL(A) mbed_sem_signal(A)
123 #define SEM_WAIT(A,TIMEOUT,IDLE_FUNC) mbed_sem_wait(A,TIMEOUT)
124 
125 #define THREAD_DECLARE(A) void *A
126 #define THREAD_INIT(A, THREAD_FUNC, THREAD_CONTEXT, STACKSIZE, PRIORITY) (((A = mbed_thread_new((THREAD_CONTEXT_FUNC_TYPE)THREAD_FUNC,STACKSIZE, PRIORITY))!= NULL)?true:false)
127 #define THREAD_DEINIT(A) mbed_thread_delete(A)
128 #define THREAD_TERMINATE(A) mbed_thread_terminate(A)
129 #define THREAD_CONTEXT_TYPE void
130 #define THREAD_CONTEXT_FUNC_TYPE void (*)(void)
131 
132 #define FIFO_DECLARE(QUEUE) void* QUEUE
133 #define FIFO_PUSH(QUEUE, VALUE, TIMEOUT, IDLE_FUNC) mbed_queue_push(QUEUE, VALUE, TIMEOUT)
134 #define FIFO_POP(QUEUE, TIMEOUT, IDLE_FUNC) mbed_queue_pop(QUEUE, TIMEOUT)
135 #define FIFO_INIT(QUEUE,QSIZE) QUEUE = mbed_queue_new(QSIZE)
136 #define FIFO_DEINIT(QUEUE) mbed_queue_delete(QUEUE)
137 
138 
139 #define WAIT_FOREVER 0xffffffff
140 #define SEM_OK true
141 #define THREAD_OK true
142 #define QUEUE_OK true
143 #define FIFO_OK true
144 #define OSPRIORITYNORMAL 1
145 #define OSPRIORITYREALTIME 2
146 #define OSPRIORITYABOVENORMAL 3
147 #define DELAYms(n) mbed_delay(n)
148 
149 #ifdef __cplusplus
150 }
151 #endif
152 
153 
154 #endif /* MX_WIFI_MBED_OS_H */
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.