Import Mbed OS hard-float snapshot

This commit is contained in:
Beslan
2026-06-01 20:15:04 +03:00
commit d3738e2f89
16278 changed files with 10628036 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
/*
* Copyright (c) 2017, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MBED_PERIPHERALNAMES_H
#define MBED_PERIPHERALNAMES_H
#endif

View File

@@ -0,0 +1,52 @@
/*
* Copyright (c) 2017, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MBED_PINNAMES_H
#define MBED_PINNAMES_H
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
PIN_INPUT,
PIN_OUTPUT
} PinDirection;
typedef enum {
PTC0 = 0,
PTC1 = 1,
NC = (int)0xFFFFFFFF
} PinName;
typedef enum {
PullNone = 0,
PullDown = 1,
PullUp = 2,
PullDefault = PullUp
} PinMode;
typedef enum {
PortA = 0,
} PortName;
#ifdef __cplusplus
}
#endif
#include "pinmap.h"
#endif

View File

@@ -0,0 +1,16 @@
/*
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

View File

@@ -0,0 +1,32 @@
/*
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MBED_CMSIS_H
#define MBED_CMSIS_H
#include <stdint.h>
static inline uint32_t __RBIT(uint32_t x)
{
x = ((x & 0xaaaaaaaa) >> 1) | ((x & 0x55555555) << 1);
x = ((x & 0xcccccccc) >> 2) | ((x & 0x33333333) << 2);
x = ((x & 0xf0f0f0f0) >> 4) | ((x & 0x0f0f0f0f) << 4);
x = ((x & 0xff00ff00) >> 8) | ((x & 0x00ff00ff) << 8);
x = (x >> 16) | (x << 16);
return x;
}
#endif

View File

@@ -0,0 +1,16 @@
/*
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

View File

@@ -0,0 +1,30 @@
/*
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef CMSIS_OS_H_
#define CMSIS_OS_H_
#include "cmsis_os2.h"
#define osPriority osPriority_t
#define osThreadId osThreadId_t
typedef struct {
} osEvent;
#endif

View File

@@ -0,0 +1,109 @@
/*
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __CMSIS_OS2_H__
#define __CMSIS_OS2_H__
#ifdef __cplusplus
extern "C"
{
#endif
#include <inttypes.h>
//If conflicts, then remove these, copied from cmsis_os.h
typedef int32_t osStatus;
//These are from cmsis_os2.h
typedef void *osSemaphoreId_t;
typedef struct {
const char *name; ///< name of the semaphore
uint32_t attr_bits; ///< attribute bits
void *cb_mem; ///< memory for control block
uint32_t cb_size; ///< size of provided memory for control block
} osSemaphoreAttr_t;
/// Status code values returned by CMSIS-RTOS functions.
typedef enum {
osOK = 0, ///< Operation completed successfully.
osError = -1, ///< Unspecified RTOS error: run-time error but no other error message fits.
osErrorTimeout = -2, ///< Operation not completed within the timeout period.
osErrorResource = -3, ///< Resource not available.
osErrorParameter = -4, ///< Parameter error.
osErrorNoMemory = -5, ///< System is out of memory: it was impossible to allocate or reserve memory for the operation.
osErrorISR = -6, ///< Not allowed in ISR context: the function cannot be called from interrupt service routines.
osStatusReserved = 0x7FFFFFFF ///< Prevents enum down-size compiler optimization.
} osStatus_t;
//Thread
typedef enum {
osPriorityNormal = 24 ///< Priority: normal
} osPriority_t;
typedef void *osThreadId_t;
typedef void *osMutexId_t;
typedef void *osEventFlagsId_t;
/// Attributes structure for thread.
typedef struct {
int unused;
} osThreadAttr_t;
#define osWaitForever 0xFFFFFFFFU ///< Wait forever timeout value.
// Flags options (\ref osThreadFlagsWait and \ref osEventFlagsWait).
#define osFlagsWaitAny 0x00000000U ///< Wait for any flag (default).
#define osFlagsWaitAll 0x00000001U ///< Wait for all flags.
#define osFlagsNoClear 0x00000002U ///< Do not clear flags which have been specified to wait for.
// Flags errors (returned by osThreadFlagsXxxx and osEventFlagsXxxx).
#define osFlagsError 0x80000000U ///< Error indicator.
#define osFlagsErrorUnknown 0xFFFFFFFFU ///< osError (-1).
#define osFlagsErrorTimeout 0xFFFFFFFEU ///< osErrorTimeout (-2).
#define osFlagsErrorResource 0xFFFFFFFDU ///< osErrorResource (-3).
#define osFlagsErrorParameter 0xFFFFFFFCU ///< osErrorParameter (-4).
#define osFlagsErrorISR 0xFFFFFFFAU ///< osErrorISR (-6).
// Thread attributes (attr_bits in \ref osThreadAttr_t).
#define osThreadDetached 0x00000000U ///< Thread created in detached mode (default)
#define osThreadJoinable 0x00000001U ///< Thread created in joinable mode
// Mutex attributes (attr_bits in \ref osMutexAttr_t).
#define osMutexRecursive 0x00000001U ///< Recursive mutex.
#define osMutexPrioInherit 0x00000002U ///< Priority inherit protocol.
#define osMutexRobust 0x00000008U ///< Robust mutex.
/// Acquire a Mutex or timeout if it is locked.
/// \param[in] mutex_id mutex ID obtained by \ref osMutexNew.
/// \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
/// \return status code that indicates the execution status of the function.
osStatus_t osMutexAcquire(osMutexId_t mutex_id, uint32_t timeout);
/// Release a Mutex that was acquired by \ref osMutexAcquire.
/// \param[in] mutex_id mutex ID obtained by \ref osMutexNew.
/// \return status code that indicates the execution status of the function.
osStatus_t osMutexRelease(osMutexId_t mutex_id);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,24 @@
/*
* Copyright (c) 2017, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MBED_DEVICE_H
#define MBED_DEVICE_H
#include "objects.h"
#include "PinNames.h"
#endif

View File

@@ -0,0 +1,53 @@
/*
* Copyright (c) 2018-2019 Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MBED_LOWPOWERTICKER_H
#define MBED_LOWPOWERTICKER_H
#include "hal/ticker_api.h"
#include "Callback.h"
namespace mbed {
/** mock Low Power Ticker
*
*/
class LowPowerTicker {
public:
LowPowerTicker()
{
}
virtual ~LowPowerTicker()
{
}
void attach_us(Callback<void()> func, us_timestamp_t t)
{
}
void detach()
{
}
};
} // namespace mbed
#endif

View File

@@ -0,0 +1,52 @@
/*
* Copyright (c) 2018-2019 Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MBED_TICKER_H
#define MBED_TICKER_H
#include "drivers/TimerEvent.h"
#include "platform/Callback.h"
namespace mbed {
/** \addtogroup drivers */
/** mock Ticker
*
*/
class Ticker {
public:
Ticker()
{
}
void attach_us(Callback<void()> func, us_timestamp_t t)
{
}
void detach()
{
}
~Ticker()
{
}
};
} // namespace mbed
#endif

View File

@@ -0,0 +1,37 @@
/*
* Copyright (c) 2017, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MBED_GPIO_OBJECT_H
#define MBED_GPIO_OBJECT_H
#include "mbed_assert.h"
#include "PeripheralNames.h"
#include "PinNames.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
int unused;
} gpio_t;
#ifdef __cplusplus
}
#endif
#endif

34
UNITTESTS/target_h/mbed.h Normal file
View File

@@ -0,0 +1,34 @@
/*
* Copyright (c) 2018, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MBED_H
#define MBED_H
#include <cstdio>
#include <cstring>
#include "events/mbed_events.h"
#include "events/mbed_shared_queues.h"
namespace mbed {
#include "platform/Callback.h"
};
using namespace mbed;
using namespace std;
#endif // MBED_H

View File

@@ -0,0 +1,16 @@
/*
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

View File

@@ -0,0 +1,20 @@
/*
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OS_STACK_SIZE
#define OS_STACK_SIZE 0
#endif

View File

@@ -0,0 +1,225 @@
/*
* Copyright (c) 2018, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "CellularContext.h"
#include "ControlPlane_netif_stub.h"
namespace mbed {
class myCellularContext : public CellularContext {
public:
std::list<nsapi_error_t> return_values;
nsapi_error_t return_value;
ControlPlane_netif_stub *my_cp_netif;
myCellularContext()
{
return_value = 0;
my_cp_netif = NULL;
}
~myCellularContext()
{
if (my_cp_netif) {
delete my_cp_netif;
my_cp_netif = NULL;
}
}
nsapi_error_t configure_hup(PinName dcd_pin, bool active_high)
{
return NSAPI_ERROR_OK;
};
void enable_hup(bool enable)
{
};
nsapi_error_t connect()
{
return NSAPI_ERROR_OK;
};
nsapi_error_t set_device_ready()
{
return NSAPI_ERROR_OK;
};
nsapi_error_t set_sim_ready()
{
return NSAPI_ERROR_OK;
};
nsapi_error_t register_to_network()
{
return NSAPI_ERROR_OK;
};
nsapi_error_t attach_to_network()
{
return NSAPI_ERROR_OK;
};
nsapi_error_t check_operation(nsapi_error_t err, ContextOperation op)
{
return NSAPI_ERROR_OK;
};
uint32_t get_timeout_for_operation(ContextOperation op) const
{
uint32_t timeout = 10 * 60 * 1000; // default timeout is 10 minutes as registration and attach may take time
return timeout;
};
bool is_connected()
{
return true;
};
NetworkStack *get_stack()
{
return NULL;
};
nsapi_error_t get_ip_address(SocketAddress *address)
{
return NSAPI_ERROR_UNSUPPORTED;
}
const char *get_ip_address()
{
return NULL;
};
void attach(Callback<void(nsapi_event_t, intptr_t)> status_cb)
{
};
nsapi_error_t set_blocking(bool blocking)
{
return NSAPI_ERROR_OK;
};
void set_plmn(const char *plmn)
{
};
void set_sim_pin(const char *sim_pin)
{
};
nsapi_error_t connect(const char *sim_pin, const char *apn, const char *uname,
const char *pwd)
{
return NSAPI_ERROR_OK;
};
void set_credentials(const char *apn, const char *uname, const char *pwd)
{
};
bool get_context()
{
return true;
};
const char* get_nonip_context_type_str() {
return "Non-IP";
}
bool set_new_context(int cid)
{
return true;
};
nsapi_error_t do_activate_context()
{
return NSAPI_ERROR_OK;
};
void do_connect()
{
};
nsapi_error_t disconnect()
{
return NSAPI_ERROR_OK;
};
nsapi_error_t get_apn_backoff_timer(int &backoff_timer)
{
return NSAPI_ERROR_OK;
};
nsapi_error_t get_rate_control(
CellularContext::RateControlExceptionReports &reports,
CellularContext::RateControlUplinkTimeUnit &timeUnit, int &uplinkRate)
{
return NSAPI_ERROR_OK;
};
nsapi_error_t get_pdpcontext_params(pdpContextList_t &params_list)
{
return NSAPI_ERROR_OK;
};
// Called by CellularDevice for network and cellular device changes
void cellular_callback(nsapi_event_t ev, intptr_t ptr)
{
};
ControlPlane_netif_stub *get_cp_netif()
{
if (!my_cp_netif) {
my_cp_netif = new ControlPlane_netif_stub();
}
return my_cp_netif;
};
nsapi_error_t activate_non_ip_context()
{
return NSAPI_ERROR_OK;
};
nsapi_error_t setup_control_plane_opt()
{
return NSAPI_ERROR_OK;
};
void deactivate_ip_context()
{
};
void deactivate_non_ip_context()
{
};
void set_disconnect()
{
};
void set_cid(int cid)
{
};
void do_connect_with_retry()
{
};
};
}

View File

@@ -0,0 +1,193 @@
/*
* Copyright (c) 2018, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MY_CELLULARDEVICE_H_
#define MY_CELLULARDEVICE_H_
#include "AT_CellularDevice.h"
#include "AT_CellularNetwork.h"
#include "FileHandle_stub.h"
#include "ATHandler_stub.h"
#include "AT_CellularContext.h"
#include "gtest/gtest.h"
#include "drivers/BufferedSerial.h"
using namespace events;
namespace mbed {
class CellularSMS;
class CellularInformation;
class CellularContext;
class FileHandle;
class myCellularDevice : public AT_CellularDevice {
public:
myCellularDevice(FileHandle *fh) : AT_CellularDevice(fh), _context_list(0), _network(0) {}
virtual ~myCellularDevice()
{
delete _context_list;
delete _network;
}
virtual nsapi_error_t set_pin(const char *sim_pin)
{
return NSAPI_ERROR_OK;
}
virtual nsapi_error_t get_sim_state(SimState &state)
{
return NSAPI_ERROR_OK;
}
virtual CellularContext *create_context(const char *apn = NULL, bool cp_req = false, bool nonip_req = false)
{
if (_context_list) {
return _context_list;
}
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
_context_list = new AT_CellularContext(at, this);
return _context_list;
}
virtual void delete_context(CellularContext *context)
{
delete _context_list;
}
virtual CellularNetwork *open_network()
{
if (_network) {
return _network;
}
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
_network = new AT_CellularNetwork(at, *this);
return _network;
}
virtual CellularSMS *open_sms()
{
return NULL;
}
virtual CellularInformation *open_information()
{
return NULL;
}
virtual void close_network()
{
delete _network;
}
virtual void close_sms() {}
virtual void close_information() {}
virtual void set_timeout(int timeout) {}
virtual void modem_debug_on(bool on) {}
virtual nsapi_error_t init()
{
return NSAPI_ERROR_OK;
}
virtual nsapi_error_t is_ready()
{
return NSAPI_ERROR_OK;
}
virtual nsapi_error_t hard_power_on()
{
return NSAPI_ERROR_OK;
}
virtual nsapi_error_t hard_power_off()
{
return NSAPI_ERROR_OK;
}
virtual nsapi_error_t soft_power_on()
{
return NSAPI_ERROR_OK;
}
virtual nsapi_error_t soft_power_off()
{
return NSAPI_ERROR_OK;
}
virtual void set_ready_cb(Callback<void()> callback)
{
}
nsapi_error_t set_power_save_mode(int periodic_time, int active_time)
{
return NSAPI_ERROR_OK;
}
virtual CellularContext *get_context_list() const
{
return _context_list;
}
void cellular_callback(nsapi_event_t ev, intptr_t ptr)
{
CellularDevice::cellular_callback(ev, ptr);
}
virtual ATHandler *get_at_handler()
{
return NULL;
}
virtual nsapi_error_t release_at_handler(ATHandler *at_handler)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t set_baud_rate(int baud_rate)
{
return NSAPI_ERROR_OK;
}
void verify_timeout_array(const uint16_t timeout[], int array_len)
{
if (array_len > CELLULAR_RETRY_ARRAY_SIZE) {
FAIL();
}
uint16_t get_timeouts[CELLULAR_RETRY_ARRAY_SIZE];
int get_timeouts_len = 0;
get_retry_timeout_array(get_timeouts, get_timeouts_len);
EXPECT_EQ(array_len, get_timeouts_len);
for (int i = 0; i < array_len; i++) {
EXPECT_EQ(timeout[i], get_timeouts[i]);
}
}
AT_CellularNetwork *_network;
AT_CellularContext *_context_list;
};
} // namespace
#endif /* MY_CELLULARDEVICE_H_ */

View File

@@ -0,0 +1,16 @@
/*
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

View File

@@ -0,0 +1,32 @@
/*
* Copyright (c) 2017, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef NVIC_WRAPPER_H
#define NVIC_WRAPPER_H
#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */
void NVIC_SystemReset(void);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif //NVIC_WRAPPER_H

View File

@@ -0,0 +1,79 @@
/*
* Copyright (c) 2017, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MBED_OBJECTS_H
#define MBED_OBJECTS_H
#include <stdint.h>
#include "PeripheralNames.h"
#include "PinNames.h"
#ifdef __cplusplus
extern "C" {
#endif
struct gpio_irq_s {
uint32_t ch;
};
struct serial_s {
int x;
};
struct dac_s {
int unused;
};
struct i2c_s {
int unused;
};
struct qspi_s {
int unused;
};
struct spi_s {
int unused;
};
struct analogin_s {
int unused;
};
struct port_s {
int unused;
};
struct pwmout_s {
int unused;
};
struct flash_s {
int unused;
};
struct can_s {
int unused;
};
#include "gpio_object.h"
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,52 @@
/* Copyright (c) 2019 ARM Limited
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __CTHUNK_H__
#define __CTHUNK_H__
/**
* Class for created a pointer with data bound to it
*
* @note Synchronization level: Not protected
*/
template<class T>
class CThunk {
public:
typedef void (T::*CCallbackSimple)(void);
typedef void (T::*CCallback)(void *context);
CThunk()
{}
CThunk(T *instance)
{}
CThunk(T &instance)
{}
void callback(CCallback callback)
{}
void callback(CCallbackSimple callback)
{
}
uint32_t entry(void)
{
return 0;
}
};
#endif/*__CTHUNK_H__*/

View File

@@ -0,0 +1,110 @@
/* mbed Microcontroller Library
* Copyright (c) 2019 ARM Limited
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MSTD_ALGORITHM_
#define MSTD_ALGORITHM_
/* <mstd_algorithm>
*
* - provides <algorithm>
* - For ARM C 5, standard C++11/14 features:
* - std::min, std::max for std::initializer_list
* - std::all_of, std::any_of, std::none_of
* - std::find_if_not
* - std::equal (2-range forms)
* - std::copy_n, std::move, std::move_backward
* - mstd::min, mstd::max constexpr replacements
*/
#include <algorithm>
namespace mstd {
using std::min;
using std::max;
using std::minmax;
using std::initializer_list;
using std::all_of;
using std::any_of;
using std::none_of;
using std::for_each;
using std::find;
using std::find_if;
using std::find_if_not;
using std::find_end;
using std::find_first_of;
using std::adjacent_find;
using std::count;
using std::count_if;
using std::mismatch;
using std::equal;
using std::search;
using std::search_n;
using std::copy;
using std::copy_n;
using std::copy_if;
using std::move;
using std::move_backward;
using std::swap_ranges;
using std::iter_swap;
using std::transform;
using std::replace;
using std::replace_if;
using std::replace_copy;
using std::replace_copy_if;
using std::fill;
using std::fill_n;
using std::generate;
using std::generate_n;
using std::remove;
using std::remove_if;
using std::remove_copy;
using std::remove_copy_if;
using std::unique;
using std::unique_copy;
using std::reverse;
using std::reverse_copy;
using std::rotate;
using std::rotate_copy;
using std::partition;
using std::stable_partition;
using std::sort;
using std::stable_sort;
using std::partial_sort;
using std::partial_sort_copy;
using std::nth_element;
using std::lower_bound;
using std::upper_bound;
using std::equal_range;
using std::binary_search;
using std::merge;
using std::inplace_merge;
using std::includes;
using std::set_union;
using std::set_intersection;
using std::set_difference;
using std::set_symmetric_difference;
using std::push_heap;
using std::pop_heap;
using std::make_heap;
using std::sort_heap;
using std::min_element;
using std::max_element;
using std::lexicographical_compare;
using std::next_permutation;
using std::prev_permutation;
}
#endif // MSTD_ALGORITHM_

View File

@@ -0,0 +1,58 @@
/*
* Copyright (c) 2017 ARM Limited
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MSTD_ATOMIC_
#define MSTD_ATOMIC_
#include <atomic>
namespace mstd {
using std::atomic;
using std::atomic_is_lock_free;
using std::atomic_store;
using std::atomic_store_explicit;
using std::atomic_load;
using std::atomic_load_explicit;
using std::atomic_exchange;
using std::atomic_exchange_explicit;
using std::atomic_compare_exchange_weak;
using std::atomic_compare_exchange_weak_explicit;
using std::atomic_compare_exchange_strong;
using std::atomic_compare_exchange_strong_explicit;
using std::atomic_fetch_add;
using std::atomic_fetch_add_explicit;
using std::atomic_fetch_sub;
using std::atomic_fetch_sub_explicit;
using std::atomic_fetch_and;
using std::atomic_fetch_and_explicit;
using std::atomic_fetch_or;
using std::atomic_fetch_or_explicit;
using std::atomic_fetch_xor;
using std::atomic_fetch_xor_explicit;
using std::atomic_flag;
using std::atomic_flag_test_and_set;
using std::atomic_flag_test_and_set_explicit;
using std::atomic_flag_clear;
using std::atomic_flag_clear_explicit;
using std::atomic_init;
using std::memory_order;
using std::kill_dependency;
using std::atomic_thread_fence;
using std::atomic_signal_fence;
}
#endif

View File

@@ -0,0 +1,54 @@
/* mbed Microcontroller Library
* Copyright (c) 2019 ARM Limited
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MSTD_CSTDDEF_
#define MSTD_CSTDDEF_
/* <mstd_cstddef>
*
* - provides <cstddef>
* - For ARM C 5, standard C++11/14 features:
* - - adds macro replacements for alignof and alignas keywords
* - - adds missing std::nullptr_t
* - For all toolchains:
* - - MSTD_CONSTEXPR_XX_14 macros that can be used to mark
* things that are valid as constexpr only for C++14 or later,
* permitting constexpr use where ARM C 5 would reject it.
*/
#include <cstddef>
/* Macros that can be used to mark functions and objects that are
* constexpr in C++14 or later, but not in earlier versions.
*/
#if __cplusplus >= 201402
#define MSTD_CONSTEXPR_FN_14 constexpr
#define MSTD_CONSTEXPR_OBJ_14 constexpr
#else
#define MSTD_CONSTEXPR_FN_14 inline
#define MSTD_CONSTEXPR_OBJ_14 const
#endif
namespace mstd
{
using std::size_t;
using std::ptrdiff_t;
using std::nullptr_t;
using std::max_align_t;
}
#endif // MSTD_CSTDDEF_

View File

@@ -0,0 +1,141 @@
/* mbed Microcontroller Library
* Copyright (c) 2019 ARM Limited
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under tUNChe License.
*/
#ifndef MSTD_FUNCTIONAL_
#define MSTD_FUNCTIONAL_
/* <mstd_functional>
*
* - includes toolchain's <functional>
* - For ARM C 5, standard C++11/14 features:
* - std::mem_fn,
* - std::reference_wrapper, std::ref, std::cref
* - transparent std::plus<> etc
* - std::bit_and, std::bit_or, std::bit_xor, std::bit_not
* - For all toolchains, C++17/20 backports:
* - mbed::not_fn (C++17)
* - mbed::invoke (C++17)
* - mstd::unwrap_reference, mstd::unwrap_ref_decay (C++20)
*/
#include <functional>
#include <mstd_memory> // addressof
#include <mstd_utility> // forward
#include <mstd_type_traits>
namespace mstd {
// [func.invoke]
#if __cpp_lib_invoke >= 201411
using std::invoke;
#else
template <typename F, typename... Args>
invoke_result_t<F, Args...> invoke(F&& f, Args&&... args)
{
return impl::INVOKE(std::forward<F>(f), std::forward<Args>(args)...);
}
#endif // __cpp_lib_invoke
} // namespace mstd
namespace mstd {
using std::reference_wrapper;
using std::ref;
using std::cref;
using std::plus;
using std::minus;
using std::multiplies;
using std::divides;
using std::modulus;
using std::negate;
using std::equal_to;
using std::not_equal_to;
using std::greater;
using std::less;
using std::greater_equal;
using std::less_equal;
using std::logical_and;
using std::logical_or;
using std::logical_not;
using std::bit_and;
using std::bit_or;
using std::bit_xor;
using std::bit_not;
#if __cpp_lib_not_fn >= 201603
using std::not_fn;
#else
namespace impl {
// [func.not_fn]
template <typename F>
class not_fn_t {
std::decay_t<F> fn;
public:
explicit not_fn_t(F&& f) : fn(std::forward<F>(f)) { }
not_fn_t(const not_fn_t &other) = default;
not_fn_t(not_fn_t &&other) = default;
template<typename... Args>
auto operator()(Args&&... args) & -> decltype(!std::declval<invoke_result_t<std::decay_t<F> &, Args...>>())
{
return !mstd::invoke(fn, std::forward<Args>(args)...);
}
template<typename... Args>
auto operator()(Args&&... args) const & -> decltype(!std::declval<invoke_result_t<std::decay_t<F> const &, Args...>>())
{
return !mstd::invoke(fn, std::forward<Args>(args)...);
}
template<typename... Args>
auto operator()(Args&&... args) && -> decltype(!std::declval<invoke_result_t<std::decay_t<F>, Args...>>())
{
return !mstd::invoke(std::move(fn), std::forward<Args>(args)...);
}
template<typename... Args>
auto operator()(Args&&... args) const && -> decltype(!std::declval<invoke_result_t<std::decay_t<F> const, Args...>>())
{
return !mstd::invoke(std::move(fn), std::forward<Args>(args)...);
}
};
}
template <typename F>
impl::not_fn_t<F> not_fn_t(F&& f)
{
return impl::not_fn_t<F>(std::forward<F>(f));
}
#endif
/* C++20 unwrap_reference */
template <typename T>
struct unwrap_reference : type_identity<T> { };
template <typename T>
struct unwrap_reference<std::reference_wrapper<T>> : type_identity<T &> { };
template <typename T>
using unwrap_reference_t = typename unwrap_reference<T>::type;
/* C++20 unwrap_ref_decay */
template <typename T>
struct unwrap_ref_decay : unwrap_reference<std::decay_t<T>> { };
template <typename T>
using unwrap_ref_decay_t = typename unwrap_ref_decay<T>::type;
}
#endif // MSTD_FUNCTIONAL_

View File

@@ -0,0 +1,149 @@
/* mbed Microcontroller Library
* Copyright (c) 2019 ARM Limited
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MSTD_ITERATOR_
#define MSTD_ITERATOR_
/* <mstd_iterator>
*
* - includes toolchain's <iterator>
* - For ARM C 5, C++11/14 features:
* - std::begin, std::end, etc
* - std::move_iterator, std::make_move_iterator
* - For all toolchains, C++17/20 backports:
* - mbed::size
* - mbed::ssize
* - mbed::empty
* - mbed::data
*/
#include <iterator>
#include <mstd_type_traits>
namespace mstd {
using std::initializer_list;
using std::iterator_traits;
// omitting deprecated std::iterator
using std::input_iterator_tag;
using std::output_iterator_tag;
using std::forward_iterator_tag;
using std::bidirectional_iterator_tag;
using std::random_access_iterator_tag;
using std::advance;
using std::distance;
using std::next;
using std::prev;
using std::reverse_iterator;
using std::make_reverse_iterator;
using std::back_insert_iterator;
using std::back_inserter;
using std::front_insert_iterator;
using std::front_inserter;
using std::insert_iterator;
using std::inserter;
using std::move_iterator;
using std::make_move_iterator;
using std::istream_iterator;
using std::ostream_iterator;
using std::istreambuf_iterator;
using std::ostreambuf_iterator;
using std::begin;
using std::end;
using std::cbegin;
using std::cend;
using std::rbegin;
using std::rend;
using std::crbegin;
using std::crend;
#if __cpp_lib_nonmember_container_access >= 201411
using std::size;
using std::empty;
using std::data;
#else
// [iterator.container]
template <class C>
constexpr auto size(const C &c) -> decltype(c.size())
{
return c.size();
}
template <class T, size_t N>
constexpr size_t size(const T (&)[N]) noexcept
{
return N;
}
template <class C>
constexpr auto empty(const C &c) -> decltype(c.empty())
{
return c.empty();
}
template <class T, size_t N>
constexpr bool empty(T (&)[N]) noexcept
{
return false;
}
template <class E>
constexpr bool empty(initializer_list<E> il)
{
return il.size() == 0;
}
template <class C>
constexpr auto data(C &c) -> decltype(c.data())
{
return c.data();
}
template <class C>
constexpr auto data(const C &c) -> decltype(c.data())
{
return c.data();
}
template <class T, size_t N>
constexpr T *data(T (&array)[N]) noexcept
{
return array;
}
template <class E>
constexpr const E *data(initializer_list<E> il)
{
return il.begin();
}
#endif
// C++20
template <class C>
constexpr auto ssize(const C &c) -> common_type_t<ptrdiff_t, make_signed_t<decltype(c.size())>>
{
return static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(c.size())>>>(c.size());
}
template <class T, ptrdiff_t N>
constexpr ptrdiff_t ssize(const T (&)[N]) noexcept
{
return N;
}
}
#endif // MSTD_ITERATOR_

View File

@@ -0,0 +1,138 @@
/* mbed Microcontroller Library
* Copyright (c) 2019 ARM Limited
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MSTD_MEMORY_
#define MSTD_MEMORY_
/* <mstd_memory>
*
* - includes toolchain's <memory>
* - For ARM C 5, C++11/14 features:
* - std::align
* - std::addressof
* - std::uninitialized_copy_n
* - std::unique_ptr, std::make_unique, std::default_delete
* - For all toolchains, C++17 backports:
* - mstd::uninitialized_default_construct, mstd::uninitialized_value_construct
* - mstd::uninitialized_move, mstd::uninitialized_move_n
* - mstd::destroy_at, mstd::destroy, mstd::destroy_n
*/
#include <memory>
#include <mstd_type_traits>
#include <mstd_utility> // std::pair
#include <mstd_iterator> // std::iterator_traits
namespace mstd {
using std::align;
using std::allocator;
using std::addressof;
// [uninitialized.construct.default] (C++17)
template <class ForwardIterator, class Size>
void uninitialized_default_construct(ForwardIterator first, ForwardIterator last) {
for (; first != last; ++first) {
::new (static_cast<void*>(addressof(*first)))
typename std::iterator_traits<ForwardIterator>::value_type;
}
}
template <class ForwardIterator, class Size>
ForwardIterator uninitialized_default_construct_n(ForwardIterator first, Size n) {
for (; n; ++first, --n) {
::new (static_cast<void*>(addressof(*first)))
typename std::iterator_traits<ForwardIterator>::value_type;
}
return first;
}
// [uninitialized.construct.value] (C++17)
template <class ForwardIterator, class Size>
void uninitialized_value_construct(ForwardIterator first, ForwardIterator last) {
for (; first != last; ++first) {
::new (static_cast<void*>(addressof(*first)))
typename std::iterator_traits<ForwardIterator>::value_type();
}
}
template <class ForwardIterator, class Size>
ForwardIterator uninitialized_value_construct_n(ForwardIterator first, Size n) {
for (; n; ++first, --n) {
::new (static_cast<void*>(addressof(*first)))
typename std::iterator_traits<ForwardIterator>::value_type();
}
return first;
}
// [uninitialized.move] (C++17)
template <class InputIterator, class ForwardIterator>
ForwardIterator uninitialized_move(InputIterator first, InputIterator last, ForwardIterator result) {
for (; first != last; ++result, (void) ++first) {
::new (static_cast<void*>(addressof(*result)))
typename std::iterator_traits<ForwardIterator>::value_type(move(*first));
}
return result;
}
template <class InputIterator, class Size, class ForwardIterator>
std::pair<InputIterator, ForwardIterator> uninitialized_move_n(InputIterator first, Size n, ForwardIterator result) {
for ( ; n > 0; ++result, (void) ++first, --n) {
::new (static_cast<void*>(addressof(*result)))
typename std::iterator_traits<ForwardIterator>::value_type(std::move(*first));
}
return { first, result };
}
using std::uninitialized_copy;
using std::uninitialized_copy_n;
using std::uninitialized_fill;
using std::uninitialized_fill_n;
// [specialized.destroy] (C++17)
template <class T>
void destroy_at(T *location)
{
location->~T();
}
template <class ForwardIterator>
void destroy(ForwardIterator first, ForwardIterator last)
{
for (; first != last; ++first) {
destroy_at(addressof(*first));
}
}
template <class ForwardIterator, class Size>
ForwardIterator destroy_n(ForwardIterator first, Size n)
{
for (; n > 0; (void)++first, --n) {
destroy_at(addressof(*first));
}
return first;
}
using std::default_delete;
using std::unique_ptr;
using std::make_unique;
}
#endif // MSTD_MEMORY_

View File

@@ -0,0 +1,92 @@
/* mbed Microcontroller Library
* Copyright (c) 2019 ARM Limited
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MSTD_MUTEX_
#define MSTD_MUTEX_
#include <mutex>
namespace mstd {
using std::defer_lock;
using std::defer_lock_t;
using std::try_to_lock;
using std::try_to_lock_t;
using std::adopt_lock;
using std::adopt_lock_t;
using std::lock_guard;
using std::unique_lock;
using std::try_lock;
using std::lock;
#if __cpp_lib_scoped_lock >= 201703
using std::scoped_lock;
#else
// [thread.lock.scoped]
// 2+ locks - use std::lock
template <class... MutexTypes>
class scoped_lock
#if 0 // no definition yet - needs tuple
tuple<MutexTypes &...> pm;
static void ignore(...) { }
public:
explicit scoped_lock(MutexTypes &... m) : pm(tie(m...)) { mstd::lock(m...); }
explicit scoped_lock(adopt_lock_t, MutexTypes &... m) noexcept : pm(mstd::tie(m...)) { }
~scoped_lock() { mstd::apply([](MutexTypes &... m) { ignore( (void(m.unlock()),0) ...); }, pm); }
scoped_lock(const scoped_lock &) = delete;
scoped_lock &operator=(const scoped_lock &) = delete;
}
#else
;
#endif
// 0 locks - no-op
template <>
class scoped_lock<> {
public:
explicit scoped_lock() = default;
explicit scoped_lock(adopt_lock_t) noexcept { }
~scoped_lock() = default;
scoped_lock(const scoped_lock &) = delete;
scoped_lock &operator=(const scoped_lock &) = delete;
};
// 1 lock - simple lock, equivalent to lock_guard<Mutex>
template <class Mutex>
class scoped_lock<Mutex> {
Mutex &pm;
public:
using mutex_type = Mutex;
explicit scoped_lock(Mutex &m) : pm(m) { m.lock(); }
explicit scoped_lock(adopt_lock_t, Mutex &m) noexcept : pm(m) { }
~scoped_lock() { pm.unlock(); }
scoped_lock(const scoped_lock &) = delete;
scoped_lock &operator=(const scoped_lock &) = delete;
};
#endif
using std::once_flag;
using std::call_once;
using std::mutex;
using std::recursive_mutex;
}
#endif // MSTD_MUTEX_

View File

@@ -0,0 +1,56 @@
/* mbed Microcontroller Library
* Copyright (c) 2019 ARM Limited
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MSTD_NEW_
#define MSTD_NEW_
/* <mstd_new>
*
* - includes toolchain's <new>
* - For all toolchains, C++17 backports:
* - mstd::launder
*/
#include <new>
#if __cpp_lib_launder < 201606
#include <type_traits>
#endif
namespace mstd
{
using std::nothrow_t;
using std::nothrow;
using std::new_handler;
using std::set_new_handler;
#if __cpp_lib_launder >= 201606
using std::launder;
#else
template <typename T>
constexpr T *launder(T *p) noexcept
{
static_assert(!std::is_function<T>::value && !std::is_void<T>::value, "Can only launder complete object types");
#if defined __clang__ || __GNUC__ >= 9
return __builtin_launder(p);
#else
return p;
#endif
}
#endif
} // namespace mstd
#endif // MSTD_NEW_

View File

@@ -0,0 +1,469 @@
/* mbed Microcontroller Library
* Copyright (c) 2019 ARM Limited
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MSTD_TYPE_TRAITS_
#define MSTD_TYPE_TRAITS_
/* <mstd_type_traits>
*
* - includes toolchain's <type_traits>
* - For ARM C 5, standard C++11/14 features:
* - std::integral_constant, std::true_type, std::false_type
* - primary type categories (std::is_void, std::is_integral etc)
* - composite type categories (std::is_reference etc)
* - type properties (std::is_const, std::is_constructible etc), except std::is_final
* - type property queries (std::alignment_of, std::rank, std::extent)
* - type relations (std::is_same, std::is_base_of, std::is_convertible)
* - const-volatile modifications (std::remove_cv, std::add_const etc)
* - reference modifications (std::remove_reference, std::add_lvalue_reference etc)
* - sign modifications (std::make_signed, std::make_unsigned)
* - array modifications (std::remove_extent, std::remove_all_extents)
* - pointer modifications (std::remove_pointer, std::add_pointer)
* - other modifications:
* - std::aligned_storage
* - std::decay
* - std::enable_if
* - std::conditional
* - std::common_type
* - std::underlying_type
* - std::result_of
* - For all toolchains, C++17/20 backports:
* - mstd::type_identity
* - mstd::bool_constant
* - mstd::void_t
* - mstd::is_invocable, mbed::is_invocable_r, etc
* - mstd::invoke_result
* - logical operator traits (mstd::conjunction, mstd::disjunction, mstd::negation)
*/
#include <mstd_cstddef>
#include <type_traits>
// The template stuff in here is too confusing for astyle
// *INDENT-OFF*
namespace mstd {
/* C++20 type identity */
template<typename T>
struct type_identity {
using type = T;
};
template <typename T>
using type_identity_t = typename type_identity<T>::type;
/* C++17 void_t (foundation for detection idiom) */
/* void_t<Args...> is void if args are valid, else a substitution failure */
#if __cpp_lib_void_t >= 201411
using std::void_t;
#else
template <typename...>
using void_t = void;
#endif
/* C++17 bool_constant */
#if __cpp_lib_bool_constant >= 201505
using std::bool_constant;
#else
template <bool B>
using bool_constant = std::integral_constant<bool, B>;
#endif
/* Forward declarations */
#if __cpp_lib_is_invocable >= 201703
using std::invoke_result;
#else
template <typename F, typename... Args>
struct invoke_result;
#endif
using std::is_same;
using std::conditional;
using std::conditional_t;
using std::enable_if;
using std::enable_if_t;
using std::is_convertible;
using std::is_object;
using std::is_reference;
/* Reinvent or pull in good stuff not in C++14 into namespace mstd */
/* C++17 logical operations on traits */
#if __cpp_lib_logical_traits >= 201510
using std::conjunction;
using std::disjunction;
using std::negation;
#else
template<class...>
struct conjunction : std::true_type { };
template<class B1>
struct conjunction<B1> : B1 { };
template<class B1, class... BN>
struct conjunction<B1, BN...> : std::conditional_t<bool(B1::value), conjunction<BN...>, B1> { };
template<class...>
struct disjunction : std::false_type { };
template<class B1>
struct disjunction<B1> : B1 { };
template<class B1, class... BN>
struct disjunction<B1, BN...> : std::conditional_t<bool(B1::value), B1, disjunction<BN...>> { };
template<class B>
struct negation : bool_constant<!bool(B::value)> { };
#endif
/* C++ detection idiom from Library fundamentals v2 TS */
/* Place into mstd::experimental to match their std::experimental */
namespace experimental {
namespace impl {
template <class Default, class Void, template<class...> class Op, class... Args>
struct detector {
using value_t = std::false_type;
using type = Default;
};
template <class Default, template<class...> class Op, class... Args>
struct detector<Default, void_t<Op<Args...>>, Op, Args...> {
using value_t = std::true_type;
using type = Op<Args...>;
};
} // namespace impl
struct nonesuch {
~nonesuch() = delete;
nonesuch(nonesuch const &) = delete;
void operator=(nonesuch const &) = delete;
};
#if 0
/* Deactivated because impl::detector appears to not work on ARM C 5; it seems to produce
* hard errors in the template template parameter expansion. You can use void_t directly instead.
*
* Reactivate if working ARM C 5 implementation discovered, or ARM C 5 support
* dropped.
*/
template<template<class...> class Op, class... Args>
using is_detected = typename impl::detector<nonesuch, void, Op, Args...>::value_t;
template<template<class...> class Op, class... Args>
using detected_t = typename impl::detector<nonesuch, void, Op, Args...>::type;
template<class Default, template<class...> class Op, class... Args>
using detected_or = typename impl::detector<Default, void, Op, Args...>;
template<class Default, template<class...> class Op, class... Args>
using detected_or_t = typename detected_or<Default, Op, Args...>::type;
template<class Expected, template<class...> class Op, class... Args>
using is_detected_exact = std::is_same<Expected, detected_t<Op, Args...>>;
template<class To, template<class...> class Op, class... Args>
using is_detected_convertible = std::is_convertible<detected_t<Op, Args...>, To>;
#endif // if 0 - deactivated detector idiom
} // namespace experimental
} // namespace mstd
/* More post-C++14 stuff */
namespace mstd {
using std::remove_const;
using std::remove_const_t;
using std::remove_volatile;
using std::remove_volatile_t;
using std::remove_cv;
using std::remove_cv_t;
using std::add_const;
using std::add_const_t;
using std::add_volatile;
using std::add_volatile_t;
using std::add_cv;
using std::add_cv_t;
using std::remove_reference;
using std::remove_reference_t;
using std::add_lvalue_reference;
using std::add_rvalue_reference;
using std::is_void;
using std::is_null_pointer;
using std::is_integral;
using std::is_floating_point;
using std::is_array;
using std::is_pointer;
using std::is_lvalue_reference;
using std::is_rvalue_reference;
using std::is_enum;
using std::is_union;
using std::is_class;
using std::is_function;
using std::is_member_function_pointer;
using std::is_member_object_pointer;
using std::is_reference;
using std::is_arithmetic;
using std::is_fundamental;
using std::is_compound;
using std::is_member_pointer;
using std::is_scalar;
using std::is_object;
using std::is_const;
using std::is_volatile;
using std::is_trivial;
using std::is_trivially_copyable;
using std::is_standard_layout;
using std::is_pod;
using std::is_literal_type;
using std::is_empty;
using std::is_polymorphic;
using std::is_abstract;
using std::is_signed;
using std::is_unsigned;
using std::is_constructible;
using std::is_default_constructible;
using std::is_copy_constructible;
using std::is_move_constructible;
using std::is_assignable;
using std::is_copy_assignable;
using std::is_move_assignable;
using std::is_destructible;
using std::is_trivially_constructible;
using std::is_trivially_default_constructible;
using std::is_trivially_copy_constructible;
using std::is_trivially_move_constructible;
using std::is_trivially_assignable;
using std::is_trivially_copy_assignable;
using std::is_trivially_move_assignable;
using std::is_trivially_destructible;
// Exceptions are disabled in mbed, so short-circuit nothrow tests
// (Compilers don't make noexcept() return false with exceptions
// disabled, presumably to preserve binary compatibility, so the
// std versions of these are unduly pessimistic).
template <typename T, typename... Args>
struct is_nothrow_constructible : is_constructible<T, Args...> { };
template <typename T>
struct is_nothrow_default_constructible : is_default_constructible<T> { };
template <typename T>
struct is_nothrow_copy_constructible : is_copy_constructible<T> { };
template <typename T>
struct is_nothrow_move_constructible : is_move_constructible<T> { };
template <typename To, typename From>
struct is_nothrow_assignable: is_assignable<To, From> { };
template <typename T>
struct is_nothrow_copy_assignable : is_copy_assignable<T> { };
template <typename T>
struct is_nothrow_move_assignable : is_move_assignable<T> { };
using std::has_virtual_destructor;
using std::alignment_of;
using std::rank;
using std::extent;
using std::is_convertible;
using std::is_base_of;
using std::make_signed;
using std::make_signed_t;
using std::make_unsigned;
using std::make_unsigned_t;
using std::remove_extent;
using std::remove_extent_t;
using std::remove_all_extents;
using std::remove_all_extents_t;
using std::remove_pointer;
using std::remove_pointer_t;
using std::add_pointer;
using std::add_pointer_t;
using std::aligned_storage;
using std::aligned_storage_t;
using std::decay;
using std::decay_t;
using std::common_type;
using std::common_type_t;
using std::result_of;
using std::result_of_t;
/* C++20 remove_cvref */
template <typename T>
struct remove_cvref : type_identity<std::remove_cv_t<std::remove_reference_t<T>>> { };
template <typename T>
using remove_cvref_t = typename remove_cvref<T>::type;
}
#if __cpp_lib_invoke < 201411
#include <utility> // want std::forward
#include <functional> // want std::reference_wrapper
#elif __cpp_lib_is_invocable < 201703
#include <functional> // want std::invoke
#endif
namespace mstd {
/* C++17 invoke_result, is_invocable, invoke */
#if __cpp_lib_is_invocable >= 201703
/* Library has complete suite - pull it into mstd */
using std::invoke_result;
using std::invoke_result_t;
using std::is_invocable;
using std::is_nothrow_invocable;
using std::is_invocable_r;
using std::is_nothrow_invocable_r;
#else // __cpp_lib_is_invocable
namespace impl {
#if __cpp_lib_invoke >= 201411
/* Library has just invoke - make it our impl::INVOKE so we can create invoke_result */
template <typename F, typename... Args>
using INVOKE = std::invoke<F, Args...>;
#else // __cpp_lib_invoke
/* Define our own INVOKE */
template <typename T>
struct is_reference_wrapper : std::false_type { };
template <typename T>
struct is_reference_wrapper<std::reference_wrapper<T>> : std::true_type { };
/* F is pointer to member function, and 1st arg decays to matching class */
template<typename Base, typename F, typename T1, class... Args>
auto INVOKE(F Base::* fn, T1 &&target, Args &&...args)
// Noexcept specifications generate compiler errors unpacking args
//noexcept(noexcept((std::forward<T1>(target).*fn)(std::forward<Args>(args)...)))
-> std::enable_if_t<std::is_function<F>::value &&
std::is_base_of<Base, std::decay_t<T1>>::value,
decltype((std::forward<T1>(target).*fn)(std::forward<Args>(args)...))>
{
return (std::forward<T1>(target).*fn)(std::forward<Args>(args)...);
}
/* F is pointer to member function, and 1st arg is a reference wrapper */
template<typename Base, typename F, typename T1, class... Args>
auto INVOKE(F Base::* fn, T1 &&target, Args &&...args)
//noexcept(noexcept((std::forward<T1>(target).get().*fn)(std::forward<Args>(args)...)))
-> std::enable_if_t<std::is_function<F>::value &&
is_reference_wrapper<std::decay_t<T1>>::value,
decltype((std::forward<T1>(target).get().*fn)(std::forward<Args>(args)...))>
{
return (std::forward<T1>(target).get().*fn)(std::forward<Args>(args)...);
}
/* F is pointer to member function, and 1st arg doesn't match class and isn't reference wrapper - assume pointer */
template<typename Base, typename F, typename T1, class... Args>
auto INVOKE(F Base::* fn, T1 &&target, Args &&...args)
//noexcept(noexcept(((*std::forward<T1>(target)).*fn)(std::forward<Args>(args)...)))
-> std::enable_if_t<std::is_function<F>::value &&
!std::is_base_of<Base, std::decay_t<T1>>::value &&
!is_reference_wrapper<std::decay_t<T1>>::value,
decltype(((*std::forward<T1>(target)).*fn)(std::forward<Args>(args)...))>
{
return ((*std::forward<T1>(target)).*fn)(std::forward<Args>(args)...);
}
/* F is pointer to member object, and only arg decays to matching class */
template<typename Base, typename F, typename T1>
auto INVOKE(F Base::* obj, T1 &&target)
//noexcept(noexcept(std::forward<T1>(target).*obj))
-> std::enable_if_t<!std::is_function<F>::value &&
std::is_base_of<Base, std::decay_t<T1>>::value,
decltype(std::forward<T1>(target).*obj)>
{
return std::forward<T1>(target).*obj;
}
/* F is pointer to member object, and only arg is a reference wrapper */
template<typename Base, typename F, typename T1>
auto INVOKE(F Base::* obj, T1 &&target)
//noexcept(noexcept(std::forward<T1>(target).get().*obj))
-> std::enable_if_t<!std::is_function<F>::value &&
is_reference_wrapper<std::decay_t<T1>>::value,
decltype(std::forward<T1>(target).get().*obj)>
{
return std::forward<T1>(target).get().*obj;
}
/* F is pointer to member object, and only arg doesn't match class and isn't reference wrapper - assume pointer */
template<typename Base, typename F, typename T1>
auto INVOKE(F Base::* obj, T1 &&target)
//noexcept(noexcept((*std::forward<T1>(target)).*obj))
-> std::enable_if_t<!std::is_function<F>::value &&
!std::is_base_of<Base, std::decay_t<T1>>::value &&
!is_reference_wrapper<std::decay_t<T1>>::value,
decltype((*std::forward<T1>(target)).*obj)>
{
return (*std::forward<T1>(target)).*obj;
}
/* F is not a pointer to member */
template<typename F, typename... Args>
auto INVOKE(F&& f, Args&&... args)
//noexcept(noexcept(std::forward<F>(f)(std::forward<Args>(args)...)))
-> std::enable_if_t<!std::is_member_pointer<std::decay_t<F>>::value ||
(std::is_member_object_pointer<std::decay_t<F>>::value && sizeof...(args) != 1),
decltype(std::forward<F>(f)(std::forward<Args>(args)...))>
{
return std::forward<F>(f)(std::forward<Args>(args)...);
}
#endif // __cpp_lib_invoke
template <typename Void, typename F, typename... Args>
struct invoke_result { };
template <typename F, typename... Args> // void_t<decltype(INVOKE)> appears not to work here - why?
struct invoke_result<decltype(void(INVOKE(std::declval<F>(), std::declval<Args>()...))), F, Args...> :
type_identity<decltype(INVOKE(std::declval<F>(), std::declval<Args>()...))> { };
// This would be a lot shorter if we could get the detector idiom to work and use it
template <typename R, typename InvokeResult, typename = void>
struct is_invocable_r : std::false_type { };
template <typename R, typename InvokeResult>
struct is_invocable_r <R, InvokeResult, void_t<typename InvokeResult::type>> :
disjunction<std::is_void<R>, std::is_convertible<typename InvokeResult::type, R>> { };
template <typename R, typename InvokeResult, typename = void>
struct is_nothrow_invocable_r : std::false_type { };
template <typename R, typename InvokeResult>
struct is_nothrow_invocable_r<R, InvokeResult, void_t<typename InvokeResult::type>> :
disjunction<std::is_void<R>,
conjunction<std::is_convertible<typename InvokeResult::type, R>,
std::is_nothrow_constructible<R, typename InvokeResult::type>>> { };
} //namespace impl
template <class F, class... Args>
struct invoke_result : impl::invoke_result<void, F, Args...> { };
template <class F, class... Args>
using invoke_result_t = typename invoke_result<F, Args...>::type;
template <class F, class... Args>
struct is_invocable : impl::is_invocable_r<void, invoke_result<F, Args...>> { };
#if 0 // No exceptions in mbed OS
template <class F, class... Args>
struct is_nothrow_invocable : impl::is_nothrow_invocable_r<void, invoke_result<F, Args...>> { };
#else
template <class F, class... Args>
struct is_nothrow_invocable : impl::is_invocable_r<void, invoke_result<F, Args...>> { };
#endif
template <typename R, typename F, typename... Args>
struct is_invocable_r : impl::is_invocable_r<R, invoke_result<F, Args...>> { };
#if 0 // No exceptions in mbed OS
template <typename R, typename F, typename... Args>
struct is_nothrow_invocable_r : conjunction<impl::is_nothrow_invocable_r<R, invoke_result<F>>,
std::is_convertible<invoke_result_t<F, Args...>, R>> { };
#else
template <typename R, typename F, typename... Args>
struct is_nothrow_invocable_r : impl::is_invocable_r<R, invoke_result<F, Args...>> { };
#endif
#endif // __cpp_lib_is_invocable
} // namespace mstd
#endif /* MSTD_TYPE_TRAITS_ */

View File

@@ -0,0 +1,75 @@
/* mbed Microcontroller Library
* Copyright (c) 2019 ARM Limited
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MSTD_UTILITY_
#define MSTD_UTILITY_
/* <mstd_utility>
*
* - includes toolchain's <utility>
* - For ARM C 5, standard C++11/14 features:
* - include <initializer_list>
* - std::move, std::forward, std::exchange
* - std::declval
* - std::integer_sequence
* - include <algorithm> to get default std::swap
* - mstd::swap - substitute for std::swap that can move
* - std::swap(array)
* - Swap assistance, to ensure moves happen on ARM C 5
* - mstd::swap - alias for std::swap, or a local moving implementation for ARM C 5
* - For all toolchains, C++17/20 backports:
* - mstd::as_const
*/
#include <utility>
namespace mstd {
using std::swap;
namespace rel_ops { using namespace std::rel_ops; }
using std::initializer_list;
using std::exchange;
using std::forward;
using std::move;
// No exceptions in mbed OS
template <typename T>
T &&move_if_noexcept(T &t) noexcept
{
return mstd::move(t);
}
using std::declval;
using std::make_pair;
using std::get;
using std::pair;
using std::integer_sequence;
// C++17 [utility.as_const] */
#if __cpp_lib_as_const >= 201510
using std::as_const;
#else
template <typename _TypeT>
constexpr std::add_const_t<_TypeT> &as_const(_TypeT &__t) noexcept
{
return __t;
}
template <typename _TypeT>
void as_const(_TypeT &&) = delete;
#endif
} // namespace mstd
#endif // MSTD_UTILITY_

View File

@@ -0,0 +1,139 @@
/** \addtogroup platform */
/** @{*/
/**
* \defgroup platform_Assert Assert macros
* @{
*/
/*
* Copyright (c) 2018--2019 Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MBED_ASSERT_H
#define MBED_ASSERT_H
#include "mbed_preprocessor.h"
#include "mbed_toolchain.h"
#ifdef __cplusplus
extern "C" {
#endif
/** Internal mbed assert function which is invoked when MBED_ASSERT macro fails.
* This function is active only if NDEBUG is not defined prior to including this
* assert header file.
* In case of MBED_ASSERT failing condition, error() is called with the assertation message.
* @param expr Expression to be checked.
* @param file File where assertation failed.
* @param line Failing assertation line number.
*/
// mbed_assert_internal UT stub only prints an assert trace and returns, so therefore
// MBED_NORETURN must not be defined for UTs.
#ifndef UNITTEST
MBED_NORETURN
#endif
void mbed_assert_internal(const char *expr, const char *file, int line);
#ifdef __cplusplus
}
#endif
/**
* For unittests: Global flag to select whether MBED_ASSERT
* throws error. Default false.
*/
extern bool mbed_assert_throw_errors;
/** MBED_ASSERT
* Declare runtime assertions: results in runtime error if condition is false
*
* @note
* Use of MBED_ASSERT is limited to Debug and Develop builds.
*
* @code
*
* int Configure(serial_t *obj) {
* MBED_ASSERT(obj);
* }
* @endcode
*/
#define MBED_ASSERT(expr) \
do { \
if (!(expr)) { \
mbed_assert_internal(#expr, __FILE__, __LINE__); \
} \
} while (0)
/** MBED_STATIC_ASSERT
* Declare compile-time assertions, results in compile-time error if condition is false
*
* The assertion acts as a declaration that can be placed at file scope, in a
* code block (except after a label), or as a member of a C++ class/struct/union.
*
* @note
* Use of MBED_STATIC_ASSERT as a member of a struct/union is limited:
* - In C++, MBED_STATIC_ASSERT is valid in class/struct/union scope.
* - In C, MBED_STATIC_ASSERT is not valid in struct/union scope, and
* MBED_STRUCT_STATIC_ASSERT is provided as an alternative that is valid
* in C and C++ class/struct/union scope.
*
* @code
* MBED_STATIC_ASSERT(MBED_LIBRARY_VERSION >= 120,
* "The mbed library must be at least version 120");
*
* int main() {
* MBED_STATIC_ASSERT(sizeof(int) >= sizeof(char),
* "An int must be larger than a char");
* }
* @endcode
*/
#if defined(__cplusplus) && (__cplusplus >= 201103L || __cpp_static_assert >= 200410L)
#define MBED_STATIC_ASSERT(expr, msg) static_assert(expr, msg)
#elif !defined(__cplusplus) && __STDC_VERSION__ >= 201112L
#define MBED_STATIC_ASSERT(expr, msg) _Static_assert(expr, msg)
#elif defined(__cplusplus) && defined(__GNUC__) && defined(__GXX_EXPERIMENTAL_CXX0X__) \
&& (__GNUC__*100 + __GNUC_MINOR__) > 403L
#define MBED_STATIC_ASSERT(expr, msg) __extension__ static_assert(expr, msg)
#elif !defined(__cplusplus) && defined(__GNUC__) \
&& (__GNUC__*100 + __GNUC_MINOR__) > 406L
#define MBED_STATIC_ASSERT(expr, msg) __extension__ _Static_assert(expr, msg)
#elif defined(__ICCARM__)
#define MBED_STATIC_ASSERT(expr, msg) static_assert(expr, msg)
#else
#define MBED_STATIC_ASSERT(expr, msg) \
enum {MBED_CONCAT(MBED_ASSERTION_AT_, __LINE__) = sizeof(char[(expr) ? 1 : -1])}
#endif
/** MBED_STRUCT_STATIC_ASSERT
* Declare compile-time assertions, results in compile-time error if condition is false
*
* Unlike MBED_STATIC_ASSERT, MBED_STRUCT_STATIC_ASSERT can and must be used
* as a member of a C/C++ class/struct/union.
*
* @code
* struct thing {
* MBED_STATIC_ASSERT(2 + 2 == 4,
* "Hopefully the universe is mathematically consistent");
* };
* @endcode
*/
#define MBED_STRUCT_STATIC_ASSERT(expr, msg) int : (expr) ? 0 : -1
#endif
/**@}*/
/**@}*/

View File

@@ -0,0 +1,37 @@
/*
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/** Resets the processor and most of the sub-system
*
* @note Does not affect the debug sub-system
*/
#ifndef MBED_POWER_MGMT_H
#define MBED_POWER_MGMT_H
extern void mock_system_reset();
static inline void system_reset(void)
{
mock_system_reset();
}
void sleep_manager_unlock_deep_sleep(void);
void sleep_manager_lock_deep_sleep(void);
#endif

View File

@@ -0,0 +1,425 @@
/*
* Copyright (c) 2017, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef RETARGET_H
#define RETARGET_H
#include <inttypes.h>
#include <sys/types.h>
#include <stdio.h>
#include <time.h>
namespace mbed {
#define NAME_MAX 255
#undef EPERM
#define EPERM 1 /* Operation not permitted */
#undef ENOENT
#define ENOENT 2 /* No such file or directory */
#undef ESRCH
#define ESRCH 3 /* No such process */
#undef EINTR
#define EINTR 4 /* Interrupted system call */
#undef EIO
#define EIO 5 /* I/O error */
#undef ENXIO
#define ENXIO 6 /* No such device or address */
#undef E2BIG
#define E2BIG 7 /* Argument list too long */
#undef ENOEXEC
#define ENOEXEC 8 /* Exec format error */
#undef EBADF
#define EBADF 9 /* Bad file number */
#undef ECHILD
#define ECHILD 10 /* No child processes */
#undef EAGAIN
#define EAGAIN 11 /* Try again */
#undef ENOMEM
#define ENOMEM 12 /* Out of memory */
#undef EACCES
#define EACCES 13 /* Permission denied */
#undef EFAULT
#define EFAULT 14 /* Bad address */
#undef ENOTBLK
#define ENOTBLK 15 /* Block device required */
#undef EBUSY
#define EBUSY 16 /* Device or resource busy */
#undef EEXIST
#define EEXIST 17 /* File exists */
#undef EXDEV
#define EXDEV 18 /* Cross-device link */
#undef ENODEV
#define ENODEV 19 /* No such device */
#undef ENOTDIR
#define ENOTDIR 20 /* Not a directory */
#undef EISDIR
#define EISDIR 21 /* Is a directory */
#undef EINVAL
#define EINVAL 22 /* Invalid argument */
#undef ENFILE
#define ENFILE 23 /* File table overflow */
#undef EMFILE
#define EMFILE 24 /* Too many open files */
#undef ENOTTY
#define ENOTTY 25 /* Not a typewriter */
#undef ETXTBSY
#define ETXTBSY 26 /* Text file busy */
#undef EFBIG
#define EFBIG 27 /* File too large */
#undef ENOSPC
#define ENOSPC 28 /* No space left on device */
#undef ESPIPE
#define ESPIPE 29 /* Illegal seek */
#undef EROFS
#define EROFS 30 /* Read-only file system */
#undef EMLINK
#define EMLINK 31 /* Too many links */
#undef EPIPE
#define EPIPE 32 /* Broken pipe */
#undef EDOM
#define EDOM 33 /* Math argument out of domain of func */
#undef ERANGE
#define ERANGE 34 /* Math result not representable */
#undef EDEADLK
#define EDEADLK 35 /* Resource deadlock would occur */
#undef ENAMETOOLONG
#define ENAMETOOLONG 36 /* File name too long */
#undef ENOLCK
#define ENOLCK 37 /* No record locks available */
#undef ENOSYS
#define ENOSYS 38 /* Function not implemented */
#undef ENOTEMPTY
#define ENOTEMPTY 39 /* Directory not empty */
#undef ELOOP
#define ELOOP 40 /* Too many symbolic links encountered */
#undef EWOULDBLOCK
#define EWOULDBLOCK EAGAIN /* Operation would block */
#undef ENOMSG
#define ENOMSG 42 /* No message of desired type */
#undef EIDRM
#define EIDRM 43 /* Identifier removed */
#undef ECHRNG
#define ECHRNG 44 /* Channel number out of range */
#undef EL2NSYNC
#define EL2NSYNC 45 /* Level 2 not synchronized */
#undef EL3HLT
#define EL3HLT 46 /* Level 3 halted */
#undef EL3RST
#define EL3RST 47 /* Level 3 reset */
#undef ELNRNG
#define ELNRNG 48 /* Link number out of range */
#undef EUNATCH
#define EUNATCH 49 /* Protocol driver not attached */
#undef ENOCSI
#define ENOCSI 50 /* No CSI structure available */
#undef EL2HLT
#define EL2HLT 51 /* Level 2 halted */
#undef EBADE
#define EBADE 52 /* Invalid exchange */
#undef EBADR
#define EBADR 53 /* Invalid request descriptor */
#undef EXFULL
#define EXFULL 54 /* Exchange full */
#undef ENOANO
#define ENOANO 55 /* No anode */
#undef EBADRQC
#define EBADRQC 56 /* Invalid request code */
#undef EBADSLT
#define EBADSLT 57 /* Invalid slot */
#undef EDEADLOCK
#define EDEADLOCK EDEADLK /* Resource deadlock would occur */
#undef EBFONT
#define EBFONT 59 /* Bad font file format */
#undef ENOSTR
#define ENOSTR 60 /* Device not a stream */
#undef ENODATA
#define ENODATA 61 /* No data available */
#undef ETIME
#define ETIME 62 /* Timer expired */
#undef ENOSR
#define ENOSR 63 /* Out of streams resources */
#undef ENONET
#define ENONET 64 /* Machine is not on the network */
#undef ENOPKG
#define ENOPKG 65 /* Package not installed */
#undef EREMOTE
#define EREMOTE 66 /* Object is remote */
#undef ENOLINK
#define ENOLINK 67 /* Link has been severed */
#undef EADV
#define EADV 68 /* Advertise error */
#undef ESRMNT
#define ESRMNT 69 /* Srmount error */
#undef ECOMM
#define ECOMM 70 /* Communication error on send */
#undef EPROTO
#define EPROTO 71 /* Protocol error */
#undef EMULTIHOP
#define EMULTIHOP 72 /* Multihop attempted */
#undef EDOTDOT
#define EDOTDOT 73 /* RFS specific error */
#undef EBADMSG
#define EBADMSG 74 /* Not a data message */
#undef EOVERFLOW
#define EOVERFLOW 75 /* Value too large for defined data type */
#undef ENOTUNIQ
#define ENOTUNIQ 76 /* Name not unique on network */
#undef EBADFD
#define EBADFD 77 /* File descriptor in bad state */
#undef EREMCHG
#define EREMCHG 78 /* Remote address changed */
#undef ELIBACC
#define ELIBACC 79 /* Can not access a needed shared library */
#undef ELIBBAD
#define ELIBBAD 80 /* Accessing a corrupted shared library */
#undef ELIBSCN
#define ELIBSCN 81 /* .lib section in a.out corrupted */
#undef ELIBMAX
#define ELIBMAX 82 /* Attempting to link in too many shared libraries */
#undef ELIBEXEC
#define ELIBEXEC 83 /* Cannot exec a shared library directly */
#undef EILSEQ
#define EILSEQ 84 /* Illegal byte sequence */
#undef ERESTART
#define ERESTART 85 /* Interrupted system call should be restarted */
#undef ESTRPIPE
#define ESTRPIPE 86 /* Streams pipe error */
#undef EUSERS
#define EUSERS 87 /* Too many users */
#undef ENOTSOCK
#define ENOTSOCK 88 /* Socket operation on non-socket */
#undef EDESTADDRREQ
#define EDESTADDRREQ 89 /* Destination address required */
#undef EMSGSIZE
#define EMSGSIZE 90 /* Message too long */
#undef EPROTOTYPE
#define EPROTOTYPE 91 /* Protocol wrong type for socket */
#undef ENOPROTOOPT
#define ENOPROTOOPT 92 /* Protocol not available */
#undef EPROTONOSUPPORT
#define EPROTONOSUPPORT 93 /* Protocol not supported */
#undef ESOCKTNOSUPPORT
#define ESOCKTNOSUPPORT 94 /* Socket type not supported */
#undef EOPNOTSUPP
#define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */
#undef EPFNOSUPPORT
#define EPFNOSUPPORT 96 /* Protocol family not supported */
#undef EAFNOSUPPORT
#define EAFNOSUPPORT 97 /* Address family not supported by protocol */
#undef EADDRINUSE
#define EADDRINUSE 98 /* Address already in use */
#undef EADDRNOTAVAIL
#define EADDRNOTAVAIL 99 /* Cannot assign requested address */
#undef ENETDOWN
#define ENETDOWN 100 /* Network is down */
#undef ENETUNREACH
#define ENETUNREACH 101 /* Network is unreachable */
#undef ENETRESET
#define ENETRESET 102 /* Network dropped connection because of reset */
#undef ECONNABORTED
#define ECONNABORTED 103 /* Software caused connection abort */
#undef ECONNRESET
#define ECONNRESET 104 /* Connection reset by peer */
#undef ENOBUFS
#define ENOBUFS 105 /* No buffer space available */
#undef EISCONN
#define EISCONN 106 /* Transport endpoint is already connected */
#undef ENOTCONN
#define ENOTCONN 107 /* Transport endpoint is not connected */
#undef ESHUTDOWN
#define ESHUTDOWN 108 /* Cannot send after transport endpoint shutdown */
#undef ETOOMANYREFS
#define ETOOMANYREFS 109 /* Too many references: cannot splice */
#undef ETIMEDOUT
#define ETIMEDOUT 110 /* Connection timed out */
#undef ECONNREFUSED
#define ECONNREFUSED 111 /* Connection refused */
#undef EHOSTDOWN
#define EHOSTDOWN 112 /* Host is down */
#undef EHOSTUNREACH
#define EHOSTUNREACH 113 /* No route to host */
#undef EALREADY
#define EALREADY 114 /* Operation already in progress */
#undef EINPROGRESS
#define EINPROGRESS 115 /* Operation now in progress */
#undef ESTALE
#define ESTALE 116 /* Stale NFS file handle */
#undef EUCLEAN
#define EUCLEAN 117 /* Structure needs cleaning */
#undef ENOTNAM
#define ENOTNAM 118 /* Not a XENIX named type file */
#undef ENAVAIL
#define ENAVAIL 119 /* No XENIX semaphores available */
#undef EISNAM
#define EISNAM 120 /* Is a named type file */
#undef EREMOTEIO
#define EREMOTEIO 121 /* Remote I/O error */
#undef EDQUOT
#define EDQUOT 122 /* Quota exceeded */
#undef ENOMEDIUM
#define ENOMEDIUM 123 /* No medium found */
#undef EMEDIUMTYPE
#define EMEDIUMTYPE 124 /* Wrong medium type */
#undef ECANCELED
#define ECANCELED 125 /* Operation Canceled */
#undef ENOKEY
#define ENOKEY 126 /* Required key not available */
#undef EKEYEXPIRED
#define EKEYEXPIRED 127 /* Key has expired */
#undef EKEYREVOKED
#define EKEYREVOKED 128 /* Key has been revoked */
#undef EKEYREJECTED
#define EKEYREJECTED 129 /* Key was rejected by service */
#undef EOWNERDEAD
#define EOWNERDEAD 130 /* Owner died */
#undef ENOTRECOVERABLE
#define ENOTRECOVERABLE 131 /* State not recoverable */
#define _IFMT 0170000 //< type of file
#define _IFSOCK 0140000 //< socket
#define _IFLNK 0120000 //< symbolic link
#define _IFREG 0100000 //< regular
#define _IFBLK 0060000 //< block special
#define _IFDIR 0040000 //< directory
#define _IFCHR 0020000 //< character special
#define _IFIFO 0010000 //< fifo special
#ifndef S_IFMT
#define S_IFMT _IFMT //< type of file
#endif
#ifndef S_IFSOCK
#define S_IFSOCK _IFSOCK //< socket
#endif
#ifndef S_IFLNK
#define S_IFLNK _IFLNK //< symbolic link
#endif
#ifndef S_IFREG
#define S_IFREG _IFREG //< regular
#endif
#ifndef S_IFBLK
#define S_IFBLK _IFBLK //< block special
#endif
#ifndef S_IFDIR
#define S_IFDIR _IFDIR //< directory
#endif
#ifndef S_IFCHR
#define S_IFCHR _IFCHR //< character special
#endif
#ifndef S_IFIFO
#define S_IFIFO _IFIFO //< fifo special
#endif
#ifndef S_IRWXU
#define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
#define S_IRUSR 0000400 ///< read permission, owner
#define S_IWUSR 0000200 ///< write permission, owner
#define S_IXUSR 0000100 ///< execute/search permission, owner
#endif /* S_IRWXU */
#ifndef S_IRWXG
#define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
#define S_IRGRP 0000040 ///< read permission, group
#define S_IWGRP 0000020 ///< write permission, group
#define S_IXGRP 0000010 ///< execute/search permission, group
#endif /* S_IRWXG */
#ifndef S_IRWXO
#define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
#define S_IROTH 0000004 ///< read permission, other
#define S_IWOTH 0000002 ///< write permission, other
#define S_IXOTH 0000001 ///< execute/search permission, other
#endif /* S_IRWXO */
#define O_RDONLY 0 ///< Open for reading
#define O_WRONLY 1 ///< Open for writing
#define O_RDWR 2 ///< Open for reading and writing
#define O_NONBLOCK 0x0004 ///< Non-blocking mode
#define O_APPEND 0x0008 ///< Set file offset to end of file prior to each write
#define O_CREAT 0x0200 ///< Create file if it does not exist
#define O_TRUNC 0x0400 ///< Truncate file to zero length
#define O_EXCL 0x0800 ///< Fail if file exists
#define O_BINARY 0x8000 ///< Open file in binary mode
#define O_ACCMODE (O_RDONLY|O_WRONLY|O_RDWR)
#define NAME_MAX 255 ///< Maximum size of a name in a file path
#define STDIN_FILENO 0
#define STDOUT_FILENO 1
#define STDERR_FILENO 2
#ifndef _STAT_VER
struct stat {
dev_t st_dev; ///< Device ID containing file
ino_t st_ino; ///< File serial number
mode_t st_mode; ///< Mode of file
nlink_t st_nlink; ///< Number of links to file
uid_t st_uid; ///< User ID
gid_t st_gid; ///< Group ID
off_t st_size; ///< Size of file in bytes
time_t st_atime; ///< Time of last access
time_t st_mtime; ///< Time of last data modification
time_t st_ctime; ///< Time of last status change
};
#endif
struct statvfs {
unsigned long f_bsize; ///< Filesystem block size
unsigned long f_frsize; ///< Fragment size (block size)
unsigned long long f_blocks; ///< Number of blocks
unsigned long long f_bfree; ///< Number of free blocks
unsigned long long f_bavail; ///< Number of free blocks for unprivileged users
unsigned long f_fsid; ///< Filesystem ID
unsigned long f_namemax; ///< Maximum filename length
};
struct dirent {
char d_name[NAME_MAX + 1]; ///< Name of file
uint8_t d_type; ///< Type of file
};
enum {
DT_UNKNOWN, ///< The file type could not be determined.
DT_FIFO, ///< This is a named pipe (FIFO).
DT_CHR, ///< This is a character device.
DT_DIR, ///< This is a directory.
DT_BLK, ///< This is a block device.
DT_REG, ///< This is a regular file.
DT_LNK, ///< This is a symbolic link.
DT_SOCK, ///< This is a UNIX domain socket.
};
/* fcntl.h defines */
#define F_GETFL 3
#define F_SETFL 4
struct pollfd {
int fd;
short events;
short revents;
};
}
#endif //RETARGET_H

View File

@@ -0,0 +1,32 @@
/* mbed Microcontroller Library
* Copyright (c) 2018 ARM Limited
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MBED_WAIT_API_H
#define MBED_WAIT_API_H
#ifdef __cplusplus
extern "C" {
#endif
void wait_us(int us);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,29 @@
/*
* Copyright (c) 2017, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MBED_PLATFORM_H
#define MBED_PLATFORM_H
#include <cstddef>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include "platform/mbed_retarget.h"
#include "nvic_wrapper.h"
#endif

View File

@@ -0,0 +1,27 @@
/*
* Copyright (c) 2017, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef FEATURES_CELLULAR_UNITTESTS_TARGET_H_RANDLIB_H_
#define FEATURES_CELLULAR_UNITTESTS_TARGET_H_RANDLIB_H_
#include <stdint.h>
extern void randLIB_seed_random(void);
uint16_t randLIB_get_random_in_range(uint16_t min, uint16_t max);
#endif /* FEATURES_CELLULAR_UNITTESTS_TARGET_H_RANDLIB_H_ */

View File

@@ -0,0 +1,49 @@
/*
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __MUTEX_H__
#define __MUTEX_H__
#include <inttypes.h>
#include "rtos/mbed_rtos_types.h"
#include "rtos/internal/mbed_rtos1_types.h"
namespace rtos {
class Mutex {
public:
Mutex();
Mutex(const char *name);
osStatus lock();
bool trylock();
bool trylock_for(uint32_t millisec);
bool trylock_until(uint64_t millisec);
osStatus unlock();
osThreadId_t get_owner();
~Mutex();
};
}
#endif

View File

@@ -0,0 +1,42 @@
/* Copyright (c) 2019 ARM Limited
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef SEMAPHORE_H
#define SEMAPHORE_H
#include <stdint.h>
#include "cmsis_os2.h"
#include "rtos/Kernel.h"
namespace rtos {
class Semaphore {
public:
Semaphore(int32_t count = 0);
Semaphore(int32_t count, uint16_t max_count);
void acquire();
bool try_acquire();
bool try_acquire_for(uint32_t millisec);
bool try_acquire_for(Kernel::Clock::duration_u32 rel_time);
bool try_acquire_until(uint64_t millisec);
bool try_acquire_until(Kernel::Clock::time_point abs_time);
osStatus release(void);
~Semaphore();
private:
void constructor(int32_t count, uint16_t max_count);
};
}
#endif

View File

@@ -0,0 +1,111 @@
/*
* Copyright (c) 2019 ARM Limited
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef THREAD_H
#define THREAD_H
#include <stdint.h>
#include "cmsis_os.h"
#include "platform/Callback.h"
#define OS_STACK_SIZE 0
namespace rtos {
class Thread {
public:
Thread(osPriority priority = osPriorityNormal,
uint32_t stack_size = OS_STACK_SIZE,
unsigned char *stack_mem = nullptr, const char *name = nullptr)
{
}
Thread(uint32_t tz_module, osPriority priority = osPriorityNormal,
uint32_t stack_size = OS_STACK_SIZE,
unsigned char *stack_mem = nullptr, const char *name = nullptr)
{
}
osStatus start(mbed::Callback<void()> task);
osStatus join() {return 0;};
osStatus terminate();
osStatus set_priority(osPriority priority){return 0;};
osPriority get_priority() const{return osPriorityNormal;};
uint32_t flags_set(uint32_t flags){return 0;};
/** State of the Thread */
enum State {
Inactive, /**< NOT USED */
Ready, /**< Ready to run */
Running, /**< Running */
WaitingDelay, /**< Waiting for a delay to occur */
WaitingJoin, /**< Waiting for thread to join. Only happens when using RTX directly. */
WaitingThreadFlag, /**< Waiting for a thread flag to be set */
WaitingEventFlag, /**< Waiting for a event flag to be set */
WaitingMutex, /**< Waiting for a mutex event to occur */
WaitingSemaphore, /**< Waiting for a semaphore event to occur */
WaitingMemoryPool, /**< Waiting for a memory pool */
WaitingMessageGet, /**< Waiting for message to arrive */
WaitingMessagePut, /**< Waiting for message to be send */
WaitingInterval, /**< NOT USED */
WaitingOr, /**< NOT USED */
WaitingAnd, /**< NOT USED */
WaitingMailbox, /**< NOT USED (Mail is implemented as MemoryPool and Queue) */
/* Not in sync with RTX below here */
Deleted, /**< The task has been deleted or not started */
};
State get_state() const {
return Ready;
};
uint32_t stack_size() const {
return 0;
};
uint32_t free_stack() const {
return 0;
};
uint32_t used_stack() const {
return 0;
};
uint32_t max_stack() const {
return 0;
};
const char *get_name() const {
return "";
};
osThreadId_t get_id() const {
return 0;
};
virtual ~Thread();
private:
// Required to share definitions without
// delegated constructors
void constructor(osPriority priority = osPriorityNormal,
uint32_t stack_size = OS_STACK_SIZE,
unsigned char *stack_mem = nullptr,
const char *name = nullptr);
};
}
#endif

View File

@@ -0,0 +1,24 @@
/*
* Copyright (c) 2017, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MBED_RTOS1_TYPES_H
#define MBED_RTOS1_TYPES_H
#include "cmsis_os.h"
#include "mbed_rtos_storage.h"
#endif // MBED_RTOS1_TYPES_H

View File

@@ -0,0 +1,38 @@
/*
* Copyright (c) 2017, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MBED_RTOS_STORAGE_H
#define MBED_RTOS_STORAGE_H
#ifdef __cplusplus
extern "C" {
#endif
#include "cmsis_os2.h"
#include "rtx_os.h"
#include "rtx_lib.h"
#include "mbed_rtx_conf.h"
typedef os_semaphore_t mbed_rtos_storage_semaphore_t;
typedef os_thread_t mbed_rtos_storage_thread_t;
typedef osRtxEventFlags_t mbed_rtos_storage_event_flags_t;
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,26 @@
/*
* Copyright (c) 2018, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef RTOS_H
#define RTOS_H
typedef enum {
osTimerOnce = 0, ///< One-shot timer.
osTimerPeriodic = 1 ///< Repeating timer.
} os_timer_type;
#endif /* RTOS_H */

View File

@@ -0,0 +1,25 @@
/*
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __RTX_LIB_H__
#define __RTX_LIB_H__
#include "rtx_os.h"
#define os_semaphore_t osRtxSemaphore_t
#define os_thread_t osRtxThread_t
#endif

View File

@@ -0,0 +1,70 @@
/*
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __RTX_OS__
#define __RTX_OS__
#include "inttypes.h"
typedef struct osRtxSemaphore_s {
uint8_t id; ///< Object Identifier
uint8_t state; ///< Object State
uint8_t flags; ///< Object Flags
uint8_t reserved;
const char *name; ///< Object Name
uint16_t tokens; ///< Current number of tokens
uint16_t max_tokens; ///< Maximum number of tokens
} osRtxSemaphore_t;
typedef struct osRtxThread_s {
uint8_t id; ///< Object Identifier
uint8_t state; ///< Object State
uint8_t flags; ///< Object Flags
uint8_t attr; ///< Object Attributes
const char *name; ///< Object Name
struct osRtxThread_s *thread_next; ///< Link pointer to next Thread in Object list
struct osRtxThread_s *thread_prev; ///< Link pointer to previous Thread in Object list
struct osRtxThread_s *delay_next; ///< Link pointer to next Thread in Delay list
struct osRtxThread_s *delay_prev; ///< Link pointer to previous Thread in Delay list
struct osRtxThread_s *thread_join; ///< Thread waiting to Join
uint32_t delay; ///< Delay Time
int8_t priority; ///< Thread Priority
int8_t priority_base; ///< Base Priority
uint8_t stack_frame; ///< Stack Frame (EXC_RETURN[7..0])
uint8_t flags_options; ///< Thread/Event Flags Options
uint32_t wait_flags; ///< Waiting Thread/Event Flags
uint32_t thread_flags; ///< Thread Flags
struct osRtxMutex_s *mutex_list; ///< Link pointer to list of owned Mutexes
void *stack_mem; ///< Stack Memory
uint32_t stack_size; ///< Stack Size
uint32_t sp; ///< Current Stack Pointer
uint32_t thread_addr; ///< Thread entry address
uint32_t tz_memory; ///< TrustZone Memory Identifier
void *context; ///< Context for OsEventObserver objects
} osRtxThread_t;
typedef struct {
uint8_t id; ///< Object Identifier
uint8_t state; ///< Object State
uint8_t flags; ///< Object Flags
uint8_t reserved;
const char *name; ///< Object Name
osRtxThread_t *thread_list; ///< Waiting Threads List
uint32_t event_flags; ///< Event Flags
} osRtxEventFlags_t;
#endif

View File

@@ -0,0 +1,17 @@
/*
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define NAME_MAX 255