mbed-ce@master + fixes + gcc 11 support (#135)

* Fix rtos::Mutex stub, add trylock() method

* LowPowerTicker - Add ::attach(...) method + call callback

* mbed_power_management - rename sleep --> mbed_sleep to avoid conflicts

Fixes conflicts w/ unistd.h and boost::ut

* GCC 11/C++ 20 - Remove deprecated type_traits

* GCC 11/C++ 20 - Remove redundant templating of methods

* Warning - pragma ignore invalid-noreturn for unit tests

* Fix astyle errors

* Fix missing mbed_sleep() calls
pull/15437/head
Ladislas de Toldi 2023-02-21 18:04:34 +01:00 committed by GitHub
parent eda766ec8f
commit 3176fc7ca5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 33 additions and 25 deletions

View File

@ -148,7 +148,7 @@ extern "C" {
// critical section to complete sleep with locked deepsleep // critical section to complete sleep with locked deepsleep
core_util_critical_section_enter(); core_util_critical_section_enter();
sleep_manager_lock_deep_sleep(); sleep_manager_lock_deep_sleep();
sleep(); mbed_sleep();
sleep_manager_unlock_deep_sleep(); sleep_manager_unlock_deep_sleep();
core_util_critical_section_exit(); core_util_critical_section_exit();
} }

View File

@ -1915,7 +1915,7 @@ public:
* attribute value that equals sizeof(T). For a variable length alternative, * attribute value that equals sizeof(T). For a variable length alternative,
* use GattCharacteristic directly. * use GattCharacteristic directly.
*/ */
ReadOnlyGattCharacteristic<T>( ReadOnlyGattCharacteristic(
const UUID &uuid, const UUID &uuid,
T *valuePtr, T *valuePtr,
uint8_t additionalProperties = BLE_GATT_CHAR_PROPERTIES_NONE, uint8_t additionalProperties = BLE_GATT_CHAR_PROPERTIES_NONE,
@ -1958,7 +1958,7 @@ public:
* attribute value with maximum size equal to sizeof(T). For a fixed length * attribute value with maximum size equal to sizeof(T). For a fixed length
* alternative, use GattCharacteristic directly. * alternative, use GattCharacteristic directly.
*/ */
WriteOnlyGattCharacteristic<T>( WriteOnlyGattCharacteristic(
const UUID &uuid, const UUID &uuid,
T *valuePtr, T *valuePtr,
uint8_t additionalProperties = BLE_GATT_CHAR_PROPERTIES_NONE, uint8_t additionalProperties = BLE_GATT_CHAR_PROPERTIES_NONE,
@ -2000,7 +2000,7 @@ public:
* attribute value with maximum size equal to sizeof(T). For a fixed length * attribute value with maximum size equal to sizeof(T). For a fixed length
* alternative, use GattCharacteristic directly. * alternative, use GattCharacteristic directly.
*/ */
ReadWriteGattCharacteristic<T>( ReadWriteGattCharacteristic(
const UUID &uuid, const UUID &uuid,
T *valuePtr, T *valuePtr,
uint8_t additionalProperties = BLE_GATT_CHAR_PROPERTIES_NONE, uint8_t additionalProperties = BLE_GATT_CHAR_PROPERTIES_NONE,
@ -2043,7 +2043,7 @@ public:
* attribute value with maximum size equal to sizeof(T) * NUM_ELEMENTS. * attribute value with maximum size equal to sizeof(T) * NUM_ELEMENTS.
* For a fixed length alternative, use GattCharacteristic directly. * For a fixed length alternative, use GattCharacteristic directly.
*/ */
WriteOnlyArrayGattCharacteristic<T, NUM_ELEMENTS>( WriteOnlyArrayGattCharacteristic(
const UUID &uuid, const UUID &uuid,
T valuePtr[NUM_ELEMENTS], T valuePtr[NUM_ELEMENTS],
uint8_t additionalProperties = BLE_GATT_CHAR_PROPERTIES_NONE, uint8_t additionalProperties = BLE_GATT_CHAR_PROPERTIES_NONE,
@ -2087,7 +2087,7 @@ public:
* attribute value that equals sizeof(T) * NUM_ELEMENTS. For a variable * attribute value that equals sizeof(T) * NUM_ELEMENTS. For a variable
* length alternative, use GattCharacteristic directly. * length alternative, use GattCharacteristic directly.
*/ */
ReadOnlyArrayGattCharacteristic<T, NUM_ELEMENTS>( ReadOnlyArrayGattCharacteristic(
const UUID &uuid, const UUID &uuid,
T valuePtr[NUM_ELEMENTS], T valuePtr[NUM_ELEMENTS],
uint8_t additionalProperties = BLE_GATT_CHAR_PROPERTIES_NONE, uint8_t additionalProperties = BLE_GATT_CHAR_PROPERTIES_NONE,
@ -2132,7 +2132,7 @@ public:
* attribute value with maximum size equal to sizeof(T) * NUM_ELEMENTS. * attribute value with maximum size equal to sizeof(T) * NUM_ELEMENTS.
* For a fixed length alternative, use GattCharacteristic directly. * For a fixed length alternative, use GattCharacteristic directly.
*/ */
ReadWriteArrayGattCharacteristic<T, NUM_ELEMENTS>( ReadWriteArrayGattCharacteristic(
const UUID &uuid, const UUID &uuid,
T valuePtr[NUM_ELEMENTS], T valuePtr[NUM_ELEMENTS],
uint8_t additionalProperties = BLE_GATT_CHAR_PROPERTIES_NONE, uint8_t additionalProperties = BLE_GATT_CHAR_PROPERTIES_NONE,

View File

@ -17,6 +17,8 @@
#ifndef MBED_LOWPOWERTICKER_H #ifndef MBED_LOWPOWERTICKER_H
#define MBED_LOWPOWERTICKER_H #define MBED_LOWPOWERTICKER_H
#include <chrono>
#include "hal/ticker_api.h" #include "hal/ticker_api.h"
#include "Callback.h" #include "Callback.h"
@ -28,21 +30,23 @@ namespace mbed {
class LowPowerTicker { class LowPowerTicker {
public: public:
LowPowerTicker() LowPowerTicker() = default;
{
}
virtual ~LowPowerTicker() virtual ~LowPowerTicker() = default;
void attach(Callback<void()> func, std::chrono::microseconds t)
{ {
func();
} }
void attach_us(Callback<void()> func, us_timestamp_t t) void attach_us(Callback<void()> func, us_timestamp_t t)
{ {
func();
} }
void detach() void detach()
{ {
// nothing to do
} }
}; };

View File

@ -218,7 +218,7 @@ bool equeue_sema_wait(equeue_sema_t *s, int ms)
core_util_critical_section_enter(); core_util_critical_section_enter();
while (!*s && ms != 0) { while (!*s && ms != 0) {
sleep(); mbed_sleep();
core_util_critical_section_exit(); core_util_critical_section_exit();
__ISB(); __ISB();
core_util_critical_section_enter(); core_util_critical_section_enter();

View File

@ -142,7 +142,7 @@ void lp_ticker_deepsleep_test()
TEST_ASSERT_TRUE(sleep_manager_can_deep_sleep_test_check()); TEST_ASSERT_TRUE(sleep_manager_can_deep_sleep_test_check());
while (!intFlag) { while (!intFlag) {
sleep(); mbed_sleep();
} }
TEST_ASSERT_EQUAL(1, intFlag); TEST_ASSERT_EQUAL(1, intFlag);

View File

@ -80,7 +80,7 @@ void rtc_sleep_test_support(bool deepsleep_mode)
TEST_ASSERT(sleep_manager_can_deep_sleep_test_check() == deepsleep_mode); TEST_ASSERT(sleep_manager_can_deep_sleep_test_check() == deepsleep_mode);
while (!expired) { while (!expired) {
sleep(); mbed_sleep();
} }
const auto stop = RealTimeClock::now(); const auto stop = RealTimeClock::now();

View File

@ -79,7 +79,7 @@ void sleep_usticker_test()
us_ticker_set_interrupt(next_match_timestamp); us_ticker_set_interrupt(next_match_timestamp);
sleep(); mbed_sleep();
const unsigned int wakeup_timestamp = us_ticker_read(); const unsigned int wakeup_timestamp = us_ticker_read();
@ -130,7 +130,7 @@ void deepsleep_lpticker_test()
Since this interrupt wakes-up the board from the sleep we need to go to sleep after CMPOK is handled. */ Since this interrupt wakes-up the board from the sleep we need to go to sleep after CMPOK is handled. */
TEST_ASSERT_TRUE(sleep_manager_can_deep_sleep_test_check()); TEST_ASSERT_TRUE(sleep_manager_can_deep_sleep_test_check());
sleep(); mbed_sleep();
/* On some targets like STM family boards with LPTIM enabled an interrupt is triggered on counter rollover. /* On some targets like STM family boards with LPTIM enabled an interrupt is triggered on counter rollover.
We need special handling for cases when next_match_timestamp < start_timestamp (interrupt is to be fired after rollover). We need special handling for cases when next_match_timestamp < start_timestamp (interrupt is to be fired after rollover).
@ -140,7 +140,7 @@ void deepsleep_lpticker_test()
if ((next_match_timestamp < start_timestamp) && lp_ticker_read() < next_match_timestamp) { if ((next_match_timestamp < start_timestamp) && lp_ticker_read() < next_match_timestamp) {
lp_ticker_set_interrupt(next_match_timestamp); lp_ticker_set_interrupt(next_match_timestamp);
wait_ns(200000); wait_ns(200000);
sleep(); mbed_sleep();
} }
#endif #endif
@ -182,7 +182,7 @@ void deepsleep_high_speed_clocks_turned_off_test()
const unsigned int us_ticks_before_sleep = us_ticker_read(); const unsigned int us_ticks_before_sleep = us_ticker_read();
sleep(); mbed_sleep();
const unsigned int us_ticks_after_sleep = us_ticker_read(); const unsigned int us_ticks_after_sleep = us_ticker_read();
const unsigned int lp_ticks_after_sleep = lp_ticker_read(); const unsigned int lp_ticks_after_sleep = lp_ticker_read();

View File

@ -210,7 +210,6 @@ using std::is_trivial;
using std::is_trivially_copyable; using std::is_trivially_copyable;
using std::is_standard_layout; using std::is_standard_layout;
using std::is_pod; using std::is_pod;
using std::is_literal_type;
using std::is_empty; using std::is_empty;
using std::is_polymorphic; using std::is_polymorphic;
using std::is_abstract; using std::is_abstract;
@ -274,8 +273,6 @@ using std::decay;
using std::decay_t; using std::decay_t;
using std::common_type; using std::common_type;
using std::common_type_t; using std::common_type_t;
using std::result_of;
using std::result_of_t;
/* C++20 remove_cvref */ /* C++20 remove_cvref */
template <typename T> template <typename T>

View File

@ -192,7 +192,7 @@ void sleep_manager_sleep_auto(void);
* Flash re-programming and the USB serial port will remain active, but the mbed program will no longer be * Flash re-programming and the USB serial port will remain active, but the mbed program will no longer be
* able to access the LocalFileSystem * able to access the LocalFileSystem
*/ */
static inline void sleep(void) static inline void mbed_sleep(void)
{ {
#if DEVICE_SLEEP #if DEVICE_SLEEP
#if (MBED_CONF_RTOS_PRESENT == 0) || (DEVICE_SYSTICK_CLK_OFF_DURING_SLEEP == 0) || defined(MBED_TICKLESS) #if (MBED_CONF_RTOS_PRESENT == 0) || (DEVICE_SYSTICK_CLK_OFF_DURING_SLEEP == 0) || defined(MBED_TICKLESS)

View File

@ -170,7 +170,7 @@ void do_sleep_operation(OpT &op)
// we go round to set the timer again. // we go round to set the timer again.
if (op.sleep_prepared()) { if (op.sleep_prepared()) {
// Enter HAL sleep (normal or deep) // Enter HAL sleep (normal or deep)
sleep(); mbed_sleep();
} }
} }

View File

@ -20,6 +20,8 @@
#include <stdio.h> #include <stdio.h>
#include <stdbool.h> #include <stdbool.h>
#pragma GCC diagnostic ignored "-Winvalid-noreturn"
bool mbed_assert_throw_errors = false; bool mbed_assert_throw_errors = false;
extern "C" void mbed_assert_internal(const char *expr, const char *file, int line) extern "C" void mbed_assert_internal(const char *expr, const char *file, int line)

View File

@ -36,3 +36,8 @@ osStatus rtos::Mutex::unlock()
{ {
return osOK; return osOK;
} }
bool rtos::Mutex::trylock()
{
return true;
}