-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlwipMiscellaneous.cpp
43 lines (35 loc) · 1.5 KB
/
lwipMiscellaneous.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
* \file
* \brief Definitions of miscellaneous functions for lwIP
*
* \author Copyright (C) 2019 Kamil Szczygiel http://www.distortec.com http://www.freddiechopin.info
*
* \par License
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not
* distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include "lwip/sys.h"
#include "distortos/DynamicThread.hpp"
#include "distortos/ThreadIdentifier.hpp"
#include <cstring>
static_assert(sizeof(sys_thread_t) == sizeof(distortos::ThreadIdentifier) &&
alignof(sys_thread_t) == alignof(distortos::ThreadIdentifier),
"sys_thread_t doesn't match distortos::ThreadIdentifier!");
/*---------------------------------------------------------------------------------------------------------------------+
| global functions
+---------------------------------------------------------------------------------------------------------------------*/
void sys_init()
{
}
sys_thread_t sys_thread_new(const char*, const lwip_thread_fn function, void* const argument, const int stackSize,
const int priority)
{
auto thread = distortos::makeAndStartDynamicThread({static_cast<size_t>(stackSize), static_cast<uint8_t>(priority)},
function, argument);
const auto identifier = thread.getIdentifier();
const auto ret = thread.detach();
assert(ret == 0);
sys_thread_t convertedIdentifier;
memcpy(&convertedIdentifier, &identifier, sizeof(convertedIdentifier));
return convertedIdentifier;
}