Skip to content

Commit 9355d08

Browse files
committed
applied patch from fep low power
1 parent e4b81f6 commit 9355d08

File tree

17 files changed

+571
-96
lines changed

17 files changed

+571
-96
lines changed

drivers/I2C.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include "hal/i2c_api.h"
2626
#include "platform/SingletonPtr.h"
2727
#include "platform/PlatformMutex.h"
28-
#include "platform/NonCopyable.h"
2928

3029
#if DEVICE_I2C_ASYNCH
3130
#include "platform/CThunk.h"
@@ -79,7 +78,7 @@ namespace mbed {
7978
* }
8079
* @endcode
8180
*/
82-
class I2C : private NonCopyable<I2C> {
81+
class I2C {
8382

8483
public:
8584
enum RxStatus {
@@ -108,6 +107,10 @@ class I2C : private NonCopyable<I2C> {
108107
I2C(const i2c_pinmap_t &static_pinmap);
109108
I2C(const i2c_pinmap_t &&) = delete; // prevent passing of temporary objects
110109

110+
/** Create an I2C Master interface from an existing object
111+
*/
112+
I2C(const I2C&) = default;
113+
111114
/** Set the frequency of the I2C interface
112115
*
113116
* @param hz The bus frequency in hertz
@@ -176,6 +179,14 @@ class I2C : private NonCopyable<I2C> {
176179
*/
177180
void stop(void);
178181

182+
/** Recover I2C bus, when stuck with SDA low
183+
*
184+
* @returns
185+
* '0' - Successfully recovered
186+
* 'I2C_ERROR_BUS_BUSY' - In case of failure
187+
*/
188+
int recover(void);
189+
179190
/** Acquire exclusive access to this I2C bus
180191
*/
181192
virtual void lock(void);

drivers/source/I2C.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,15 @@ void I2C::stop(void)
148148
unlock();
149149
}
150150

151+
int I2C::recover(void)
152+
{
153+
lock();
154+
int ret = recover(_sda, _scl);
155+
i2c_init(&_i2c, _sda, _scl);
156+
unlock();
157+
return ret;
158+
}
159+
151160
void I2C::lock()
152161
{
153162
_mutex->lock();

drivers/source/SerialBase.cpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@
2424
namespace mbed {
2525

2626
SerialBase::SerialBase(PinName tx, PinName rx, int baud) :
27+
_init_func(&SerialBase::_init),
2728
#if DEVICE_SERIAL_ASYNCH
2829
_thunk_irq(this),
2930
#endif
3031
_baud(baud),
3132
_tx_pin(tx),
32-
_rx_pin(rx),
33-
_init_func(&SerialBase::_init)
33+
_rx_pin(rx)
3434
{
3535
// No lock needed in the constructor
3636

@@ -42,6 +42,7 @@ SerialBase::SerialBase(PinName tx, PinName rx, int baud) :
4242
}
4343

4444
SerialBase::SerialBase(const serial_pinmap_t &static_pinmap, int baud) :
45+
_init_func(&SerialBase::_init_direct),
4546
#if DEVICE_SERIAL_ASYNCH
4647
_thunk_irq(this), _tx_usage(DMA_USAGE_NEVER),
4748
_rx_usage(DMA_USAGE_NEVER), _tx_callback(NULL),
@@ -52,8 +53,7 @@ SerialBase::SerialBase(const serial_pinmap_t &static_pinmap, int baud) :
5253
_baud(baud),
5354
_tx_pin(static_pinmap.tx_pin),
5455
_rx_pin(static_pinmap.rx_pin),
55-
_static_pinmap(&static_pinmap),
56-
_init_func(&SerialBase::_init_direct)
56+
_static_pinmap(&static_pinmap)
5757
{
5858
// No lock needed in the constructor
5959

@@ -107,17 +107,9 @@ void SerialBase::attach(Callback<void()> func, IrqType type)
107107
// Disable interrupts when attaching interrupt handler
108108
core_util_critical_section_enter();
109109
if (func) {
110-
// lock deep sleep only the first time
111-
if (!_irq[type]) {
112-
sleep_manager_lock_deep_sleep();
113-
}
114110
_irq[type] = func;
115111
serial_irq_set(&_serial, (SerialIrq)type, 1);
116112
} else {
117-
// unlock deep sleep only the first time
118-
if (_irq[type]) {
119-
sleep_manager_unlock_deep_sleep();
120-
}
121113
_irq[type] = NULL;
122114
serial_irq_set(&_serial, (SerialIrq)type, 0);
123115
}

events/EventQueue.h

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -746,12 +746,17 @@ class EventQueue : private mbed::NonCopyable<EventQueue> {
746746
{
747747
void *p = equeue_alloc(&_equeue, sizeof(F));
748748
if (!p) {
749+
queue_full(QUEUE_FULL_CALL, sizeof(F));
749750
return 0;
750751
}
751752

752753
F *e = new (p) F(f);
753754
equeue_event_dtor(e, &EventQueue::function_dtor<F>);
754-
return equeue_post(&_equeue, &EventQueue::function_call<F>, e);
755+
int id = equeue_post(&_equeue, &EventQueue::function_call<F>, e);
756+
if (id == 0) {
757+
queue_full(QUEUE_FULL_CALL, sizeof(F));
758+
}
759+
return id;
755760
}
756761

757762

@@ -821,13 +826,18 @@ class EventQueue : private mbed::NonCopyable<EventQueue> {
821826
{
822827
void *p = equeue_alloc(&_equeue, sizeof(F));
823828
if (!p) {
829+
queue_full(QUEUE_FULL_CALL_IN, sizeof(F));
824830
return 0;
825831
}
826832

827833
F *e = new (p) F(f);
828834
equeue_event_delay(e, ms);
829835
equeue_event_dtor(e, &EventQueue::function_dtor<F>);
830-
return equeue_post(&_equeue, &EventQueue::function_call<F>, e);
836+
int id = equeue_post(&_equeue, &EventQueue::function_call<F>, e);
837+
if (id == 0) {
838+
queue_full(QUEUE_FULL_CALL_IN, sizeof(F));
839+
}
840+
return id;
831841
}
832842

833843
/** Calls an event on the queue after a specified delay
@@ -900,14 +910,19 @@ class EventQueue : private mbed::NonCopyable<EventQueue> {
900910
{
901911
void *p = equeue_alloc(&_equeue, sizeof(F));
902912
if (!p) {
913+
queue_full(QUEUE_FULL_CALL_EVERY, sizeof(F));
903914
return 0;
904915
}
905916

906917
F *e = new (p) F(f);
907918
equeue_event_delay(e, ms);
908919
equeue_event_period(e, ms);
909920
equeue_event_dtor(e, &EventQueue::function_dtor<F>);
910-
return equeue_post(&_equeue, &EventQueue::function_call<F>, e);
921+
int id = equeue_post(&_equeue, &EventQueue::function_call<F>, e);
922+
if (id == 0) {
923+
queue_full(QUEUE_FULL_CALL_EVERY, sizeof(F));
924+
}
925+
return id;
911926
}
912927

913928
/** Calls an event on the queue periodically
@@ -1239,6 +1254,18 @@ class EventQueue : private mbed::NonCopyable<EventQueue> {
12391254
((F *)p)->~F();
12401255
}
12411256

1257+
enum queue_full_call_type {
1258+
QUEUE_FULL_CALL,
1259+
QUEUE_FULL_CALL_IN,
1260+
QUEUE_FULL_CALL_EVERY,
1261+
};
1262+
1263+
/** Error callback. Called when task is rejected because queue is full */
1264+
virtual void queue_full(queue_full_call_type call_type, size_t function_size) const
1265+
{
1266+
// Can be overridden in subclass
1267+
}
1268+
12421269
// Context structures
12431270
template <typename F, typename... ContextArgTs>
12441271
struct context;

platform/mbed_rtc_time.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ struct timeval {
3838
time_t tv_sec;
3939
int32_t tv_usec;
4040
};
41+
#else
42+
#include <sys/time.h>
4143
#endif
4244

4345
/** Implementation of the C time.h functions

platform/source/mbed_error.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static bool is_reboot_error_valid = false;
7373
//we dont have many uses cases to create a C wrapper for MbedCRC and the data
7474
//we calculate CRC on in this context is very less we will use a local
7575
//implementation here.
76-
static unsigned int compute_crc32(const void *data, int datalen)
76+
__attribute__ ((unused)) static unsigned int compute_crc32(const void *data, int datalen)
7777
{
7878
const unsigned int polynomial = 0x04C11DB7; /* divisor is 32bit */
7979
unsigned int crc = 0; /* CRC value is 32bit */
@@ -200,7 +200,13 @@ static mbed_error_status_t handle_error(mbed_error_status_t error_status, unsign
200200
#if MBED_CONF_PLATFORM_ERROR_FILENAME_CAPTURE_ENABLED
201201
//Capture filename/linenumber if provided
202202
//Index for tracking error_filename
203-
strncpy(current_error_ctx.error_filename, filename, MBED_CONF_PLATFORM_MAX_ERROR_FILENAME_LEN);
203+
const char* copy_from = strrchr(filename, '/');
204+
if (!copy_from) {
205+
copy_from = filename;
206+
} else {
207+
++copy_from; // Skip the '/'
208+
}
209+
strncpy(current_error_ctx.error_filename, copy_from, MBED_CONF_PLATFORM_MAX_ERROR_FILENAME_LEN);
204210
current_error_ctx.error_line_number = line_number;
205211
#endif
206212

platform/source/mbed_os_timer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ namespace internal {
3838
OsTimer *os_timer;
3939

4040
namespace {
41-
uint64_t os_timer_data[(sizeof(OsTimer) + 7) / 8];
41+
[[maybe_unused]] uint64_t os_timer_data[(sizeof(OsTimer) + 7) / 8];
4242
}
4343

4444
OsTimer *init_os_timer()

platform/source/mbed_power_mgmt.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "platform/mbed_wait_api.h"
2929

3030
#include <stdio.h>
31+
#include <string.h>
3132

3233
#if DEVICE_SLEEP
3334

platform/source/minimal-printf/mbed_printf_wrapper.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#ifdef MBED_MINIMAL_PRINTF
1818

1919
#include "mbed_printf_implementation.h"
20+
#include "mbed_toolchain.h"
2021

2122
#include <limits.h>
2223

@@ -60,7 +61,7 @@
6061
#warning "This compiler is not yet supported."
6162
#endif
6263

63-
int SUB_PRINTF(const char *format, ...)
64+
MBED_USED int SUB_PRINTF(const char *format, ...)
6465
{
6566
va_list arguments;
6667
va_start(arguments, format);
@@ -70,7 +71,7 @@ int SUB_PRINTF(const char *format, ...)
7071
return result;
7172
}
7273

73-
int SUB_SPRINTF(char *buffer, const char *format, ...)
74+
MBED_USED int SUB_SPRINTF(char *buffer, const char *format, ...)
7475
{
7576
va_list arguments;
7677
va_start(arguments, format);
@@ -80,7 +81,7 @@ int SUB_SPRINTF(char *buffer, const char *format, ...)
8081
return result;
8182
}
8283

83-
int SUB_SNPRINTF(char *buffer, size_t length, const char *format, ...)
84+
MBED_USED int SUB_SNPRINTF(char *buffer, size_t length, const char *format, ...)
8485
{
8586
va_list arguments;
8687
va_start(arguments, format);
@@ -90,22 +91,22 @@ int SUB_SNPRINTF(char *buffer, size_t length, const char *format, ...)
9091
return result;
9192
}
9293

93-
int SUB_VPRINTF(const char *format, va_list arguments)
94+
MBED_USED int SUB_VPRINTF(const char *format, va_list arguments)
9495
{
9596
return mbed_minimal_formatted_string(NULL, LONG_MAX, format, arguments, stdout);
9697
}
9798

98-
int SUB_VSPRINTF(char *buffer, const char *format, va_list arguments)
99+
MBED_USED int SUB_VSPRINTF(char *buffer, const char *format, va_list arguments)
99100
{
100101
return mbed_minimal_formatted_string(buffer, LONG_MAX, format, arguments, NULL);
101102
}
102103

103-
int SUB_VSNPRINTF(char *buffer, size_t length, const char *format, va_list arguments)
104+
MBED_USED int SUB_VSNPRINTF(char *buffer, size_t length, const char *format, va_list arguments)
104105
{
105106
return mbed_minimal_formatted_string(buffer, length, format, arguments, NULL);
106107
}
107108

108-
int SUB_FPRINTF(FILE *stream, const char *format, ...)
109+
MBED_USED int SUB_FPRINTF(FILE *stream, const char *format, ...)
109110
{
110111
va_list arguments;
111112
va_start(arguments, format);
@@ -115,7 +116,7 @@ int SUB_FPRINTF(FILE *stream, const char *format, ...)
115116
return result;
116117
}
117118

118-
int SUB_VFPRINTF(FILE *stream, const char *format, va_list arguments)
119+
MBED_USED int SUB_VFPRINTF(FILE *stream, const char *format, va_list arguments)
119120
{
120121
return mbed_minimal_formatted_string(NULL, LONG_MAX, format, arguments, stream);
121122
}

targets/TARGET_STM/TARGET_STM32F4/analogin_device.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ uint16_t adc_read(analogin_t *obj)
213213
adcValue = (uint16_t)HAL_ADC_GetValue(&obj->handle);
214214
}
215215
LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE((&obj->handle)->Instance), LL_ADC_PATH_INTERNAL_NONE);
216+
217+
HAL_ADC_Stop(&obj->handle);
218+
216219
return adcValue;
217220
}
218221

0 commit comments

Comments
 (0)