Merge pull request #8591 from 0xc0170/fix_coding_style_features

features: fix coding style
pull/8697/head
Cruz Monrreal 2018-11-09 09:40:56 -06:00 committed by GitHub
commit 9d95d46d6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
124 changed files with 1494 additions and 1385 deletions

View File

@ -3,17 +3,22 @@ cmsis
features/cryptocell features/cryptocell
features/mbedtls features/mbedtls
features/lwipstack/lwip features/lwipstack/lwip
features/lwipstack/lwip-sys
rtos/TARGET_CORTEX/rtx4 rtos/TARGET_CORTEX/rtx4
features/storage/filesystem/littlefs/littlefs/ features/storage/filesystem/littlefs/littlefs/
features/storage/filesystem/fat/ChaN features/storage/filesystem/fat/ChaN
features/storage/FEATURE_STORAGE features/storage/FEATURE_STORAGE
features/frameworks features/frameworks
features/FEATURE_BLE/targets features/FEATURE_BLE
features/unsupported/ features/unsupported/
features/netsocket/emac-drivers
hal/storage_abstraction hal/storage_abstraction
FEATURE_NANOSTACK/coap-service TESTS/mbed_hal/trng/pithy
FEATURE_NANOSTACK/sal-stack-nanostack features/nanostack/coap-service
features/nanostack/sal-stack-nanostack
rtos/TARGET_CORTEX/rtx5 rtos/TARGET_CORTEX/rtx5
TESTS/mbed_hal/trng/pithy TESTS/mbed_hal/trng/pithy
targets targets
components/802.15.4_RF
components/wifi
tools tools

View File

@ -66,6 +66,7 @@ Case cases[] = {
Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler); Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);
int main() { int main()
{
Harness::run(specification); Harness::run(specification);
} }

View File

@ -35,7 +35,8 @@ using namespace mbed;
// Ticker operations // Ticker operations
#if MBED_CONF_RTOS_PRESENT #if MBED_CONF_RTOS_PRESENT
unsigned equeue_tick() { unsigned equeue_tick()
{
return osKernelGetTickCount(); return osKernelGetTickCount();
} }
@ -59,12 +60,14 @@ static unsigned equeue_timer[
static unsigned equeue_ticker[ static unsigned equeue_ticker[
(sizeof(ALIAS_TICKER) + sizeof(unsigned) - 1) / sizeof(unsigned)]; (sizeof(ALIAS_TICKER) + sizeof(unsigned) - 1) / sizeof(unsigned)];
static void equeue_tick_update() { static void equeue_tick_update()
{
equeue_minutes += reinterpret_cast<ALIAS_TIMER *>(equeue_timer)->read_ms(); equeue_minutes += reinterpret_cast<ALIAS_TIMER *>(equeue_timer)->read_ms();
reinterpret_cast<ALIAS_TIMER *>(equeue_timer)->reset(); reinterpret_cast<ALIAS_TIMER *>(equeue_timer)->reset();
} }
static void equeue_tick_init() { static void equeue_tick_init()
{
MBED_STATIC_ASSERT(sizeof(equeue_timer) >= sizeof(ALIAS_TIMER), MBED_STATIC_ASSERT(sizeof(equeue_timer) >= sizeof(ALIAS_TIMER),
"The equeue_timer buffer must fit the class Timer"); "The equeue_timer buffer must fit the class Timer");
MBED_STATIC_ASSERT(sizeof(equeue_ticker) >= sizeof(ALIAS_TICKER), MBED_STATIC_ASSERT(sizeof(equeue_ticker) >= sizeof(ALIAS_TICKER),
@ -79,7 +82,8 @@ static void equeue_tick_init() {
equeue_tick_inited = true; equeue_tick_inited = true;
} }
unsigned equeue_tick() { unsigned equeue_tick()
{
if (!equeue_tick_inited) { if (!equeue_tick_inited) {
equeue_tick_init(); equeue_tick_init();
} }
@ -98,14 +102,19 @@ unsigned equeue_tick() {
#endif #endif
// Mutex operations // Mutex operations
int equeue_mutex_create(equeue_mutex_t *m) { return 0; } int equeue_mutex_create(equeue_mutex_t *m)
{
return 0;
}
void equeue_mutex_destroy(equeue_mutex_t *m) { } void equeue_mutex_destroy(equeue_mutex_t *m) { }
void equeue_mutex_lock(equeue_mutex_t *m) { void equeue_mutex_lock(equeue_mutex_t *m)
{
core_util_critical_section_enter(); core_util_critical_section_enter();
} }
void equeue_mutex_unlock(equeue_mutex_t *m) { void equeue_mutex_unlock(equeue_mutex_t *m)
{
core_util_critical_section_exit(); core_util_critical_section_exit();
} }
@ -113,7 +122,8 @@ void equeue_mutex_unlock(equeue_mutex_t *m) {
// Semaphore operations // Semaphore operations
#ifdef MBED_CONF_RTOS_PRESENT #ifdef MBED_CONF_RTOS_PRESENT
int equeue_sema_create(equeue_sema_t *s) { int equeue_sema_create(equeue_sema_t *s)
{
osEventFlagsAttr_t attr; osEventFlagsAttr_t attr;
memset(&attr, 0, sizeof(attr)); memset(&attr, 0, sizeof(attr));
attr.cb_mem = &s->mem; attr.cb_mem = &s->mem;
@ -123,15 +133,18 @@ int equeue_sema_create(equeue_sema_t *s) {
return !s->id ? -1 : 0; return !s->id ? -1 : 0;
} }
void equeue_sema_destroy(equeue_sema_t *s) { void equeue_sema_destroy(equeue_sema_t *s)
{
osEventFlagsDelete(s->id); osEventFlagsDelete(s->id);
} }
void equeue_sema_signal(equeue_sema_t *s) { void equeue_sema_signal(equeue_sema_t *s)
{
osEventFlagsSet(s->id, 1); osEventFlagsSet(s->id, 1);
} }
bool equeue_sema_wait(equeue_sema_t *s, int ms) { bool equeue_sema_wait(equeue_sema_t *s, int ms)
{
if (ms < 0) { if (ms < 0) {
ms = osWaitForever; ms = osWaitForever;
} }
@ -142,23 +155,28 @@ bool equeue_sema_wait(equeue_sema_t *s, int ms) {
#else #else
// Semaphore operations // Semaphore operations
int equeue_sema_create(equeue_sema_t *s) { int equeue_sema_create(equeue_sema_t *s)
{
*s = false; *s = false;
return 0; return 0;
} }
void equeue_sema_destroy(equeue_sema_t *s) { void equeue_sema_destroy(equeue_sema_t *s)
{
} }
void equeue_sema_signal(equeue_sema_t *s) { void equeue_sema_signal(equeue_sema_t *s)
{
*s = 1; *s = 1;
} }
static void equeue_sema_timeout(equeue_sema_t *s) { static void equeue_sema_timeout(equeue_sema_t *s)
{
*s = -1; *s = -1;
} }
bool equeue_sema_wait(equeue_sema_t *s, int ms) { bool equeue_sema_wait(equeue_sema_t *s, int ms)
{
int signal = 0; int signal = 0;
ALIAS_TIMEOUT timeout; ALIAS_TIMEOUT timeout;
if (ms == 0) { if (ms == 0) {

View File

@ -20,8 +20,7 @@
#include "AT_CellularDevice.h" #include "AT_CellularDevice.h"
namespace mbed namespace mbed {
{
class UBLOX_AT : public AT_CellularDevice { class UBLOX_AT : public AT_CellularDevice {
public: public:

View File

@ -21,11 +21,9 @@
#include "AT_CellularNetwork.h" #include "AT_CellularNetwork.h"
#include "APN_db.h" #include "APN_db.h"
namespace mbed namespace mbed {
{
class UBLOX_AT_CellularNetwork : public AT_CellularNetwork class UBLOX_AT_CellularNetwork : public AT_CellularNetwork {
{
public: public:
UBLOX_AT_CellularNetwork(ATHandler &atHandler); UBLOX_AT_CellularNetwork(ATHandler &atHandler);
virtual ~UBLOX_AT_CellularNetwork(); virtual ~UBLOX_AT_CellularNetwork();

View File

@ -20,11 +20,9 @@
#include "AT_CellularPower.h" #include "AT_CellularPower.h"
namespace mbed namespace mbed {
{
class UBLOX_AT_CellularPower : public AT_CellularPower class UBLOX_AT_CellularPower : public AT_CellularPower {
{
public: public:
UBLOX_AT_CellularPower(ATHandler &atHandler); UBLOX_AT_CellularPower(ATHandler &atHandler);
virtual ~UBLOX_AT_CellularPower(); virtual ~UBLOX_AT_CellularPower();

View File

@ -23,11 +23,9 @@
#include "drivers/Timer.h" #include "drivers/Timer.h"
namespace mbed namespace mbed {
{
class UBLOX_AT_CellularStack : public AT_CellularStack class UBLOX_AT_CellularStack : public AT_CellularStack {
{
public: public:
UBLOX_AT_CellularStack(ATHandler &atHandler, int cid, nsapi_ip_stack_t stack_type); UBLOX_AT_CellularStack(ATHandler &atHandler, int cid, nsapi_ip_stack_t stack_type);
virtual ~UBLOX_AT_CellularStack(); virtual ~UBLOX_AT_CellularStack();

View File

@ -21,4 +21,7 @@
MBED_DEPRECATED_SINCE("5.10", "FEATURE_LWIP is deprecated. You do not need to enable it anymore in mbed_app.json") MBED_DEPRECATED_SINCE("5.10", "FEATURE_LWIP is deprecated. You do not need to enable it anymore in mbed_app.json")
static void feature_lwip(void) { } static void feature_lwip(void) { }
void dummy_feature_lwip_is_deprecated(void) { feature_lwip(); } void dummy_feature_lwip_is_deprecated(void)
{
feature_lwip();
}

View File

@ -21,4 +21,7 @@
MBED_DEPRECATED_SINCE("5.10", "FEATURE_NANOSTACK is deprecated. You do not need to enable it anymore in mbed_app.json") MBED_DEPRECATED_SINCE("5.10", "FEATURE_NANOSTACK is deprecated. You do not need to enable it anymore in mbed_app.json")
static void feature_nanostack(void) { } static void feature_nanostack(void) { }
void dummy_feature_nanostack_is_deprecated(void) { feature_nanostack(); } void dummy_feature_nanostack_is_deprecated(void)
{
feature_nanostack();
}

View File

@ -184,8 +184,7 @@ typedef struct radio_events {
/** /**
* Interface for the radios, contains the main functions that a radio needs, and five callback functions. * Interface for the radios, contains the main functions that a radio needs, and five callback functions.
*/ */
class LoRaRadio class LoRaRadio {
{
public: public:

View File

@ -67,24 +67,29 @@ int LoRaMacCrypto::compute_mic(const uint8_t *buffer, uint16_t size,
if (NULL != cipher_info) { if (NULL != cipher_info) {
ret = mbedtls_cipher_setup(aes_cmac_ctx, cipher_info); ret = mbedtls_cipher_setup(aes_cmac_ctx, cipher_info);
if (0 != ret) if (0 != ret) {
goto exit; goto exit;
}
ret = mbedtls_cipher_cmac_starts(aes_cmac_ctx, key, key_length); ret = mbedtls_cipher_cmac_starts(aes_cmac_ctx, key, key_length);
if (0 != ret) if (0 != ret) {
goto exit; goto exit;
}
ret = mbedtls_cipher_cmac_update(aes_cmac_ctx, mic_block_b0, sizeof(mic_block_b0)); ret = mbedtls_cipher_cmac_update(aes_cmac_ctx, mic_block_b0, sizeof(mic_block_b0));
if (0 != ret) if (0 != ret) {
goto exit; goto exit;
}
ret = mbedtls_cipher_cmac_update(aes_cmac_ctx, buffer, size & 0xFF); ret = mbedtls_cipher_cmac_update(aes_cmac_ctx, buffer, size & 0xFF);
if (0 != ret) if (0 != ret) {
goto exit; goto exit;
}
ret = mbedtls_cipher_cmac_finish(aes_cmac_ctx, computed_mic); ret = mbedtls_cipher_cmac_finish(aes_cmac_ctx, computed_mic);
if (0 != ret) if (0 != ret) {
goto exit; goto exit;
}
*mic = (uint32_t)((uint32_t) computed_mic[3] << 24 *mic = (uint32_t)((uint32_t) computed_mic[3] << 24
| (uint32_t) computed_mic[2] << 16 | (uint32_t) computed_mic[2] << 16
@ -112,8 +117,9 @@ int LoRaMacCrypto::encrypt_payload(const uint8_t *buffer, uint16_t size,
mbedtls_aes_init(&aes_ctx); mbedtls_aes_init(&aes_ctx);
ret = mbedtls_aes_setkey_enc(&aes_ctx, key, key_length); ret = mbedtls_aes_setkey_enc(&aes_ctx, key, key_length);
if (0 != ret) if (0 != ret) {
goto exit; goto exit;
}
a_block[0] = 0x01; a_block[0] = 0x01;
a_block[5] = dir; a_block[5] = dir;
@ -133,8 +139,9 @@ int LoRaMacCrypto::encrypt_payload(const uint8_t *buffer, uint16_t size,
ctr++; ctr++;
ret = mbedtls_aes_crypt_ecb(&aes_ctx, MBEDTLS_AES_ENCRYPT, a_block, ret = mbedtls_aes_crypt_ecb(&aes_ctx, MBEDTLS_AES_ENCRYPT, a_block,
s_block); s_block);
if (0 != ret) if (0 != ret) {
goto exit; goto exit;
}
for (i = 0; i < 16; i++) { for (i = 0; i < 16; i++) {
enc_buffer[bufferIndex + i] = buffer[bufferIndex + i] ^ s_block[i]; enc_buffer[bufferIndex + i] = buffer[bufferIndex + i] ^ s_block[i];
@ -147,8 +154,9 @@ int LoRaMacCrypto::encrypt_payload(const uint8_t *buffer, uint16_t size,
a_block[15] = ((ctr) & 0xFF); a_block[15] = ((ctr) & 0xFF);
ret = mbedtls_aes_crypt_ecb(&aes_ctx, MBEDTLS_AES_ENCRYPT, a_block, ret = mbedtls_aes_crypt_ecb(&aes_ctx, MBEDTLS_AES_ENCRYPT, a_block,
s_block); s_block);
if (0 != ret) if (0 != ret) {
goto exit; goto exit;
}
for (i = 0; i < size; i++) { for (i = 0; i < size; i++) {
enc_buffer[bufferIndex + i] = buffer[bufferIndex + i] ^ s_block[i]; enc_buffer[bufferIndex + i] = buffer[bufferIndex + i] ^ s_block[i];
@ -181,20 +189,24 @@ int LoRaMacCrypto::compute_join_frame_mic(const uint8_t *buffer, uint16_t size,
if (NULL != cipher_info) { if (NULL != cipher_info) {
ret = mbedtls_cipher_setup(aes_cmac_ctx, cipher_info); ret = mbedtls_cipher_setup(aes_cmac_ctx, cipher_info);
if (0 != ret) if (0 != ret) {
goto exit; goto exit;
}
ret = mbedtls_cipher_cmac_starts(aes_cmac_ctx, key, key_length); ret = mbedtls_cipher_cmac_starts(aes_cmac_ctx, key, key_length);
if (0 != ret) if (0 != ret) {
goto exit; goto exit;
}
ret = mbedtls_cipher_cmac_update(aes_cmac_ctx, buffer, size & 0xFF); ret = mbedtls_cipher_cmac_update(aes_cmac_ctx, buffer, size & 0xFF);
if (0 != ret) if (0 != ret) {
goto exit; goto exit;
}
ret = mbedtls_cipher_cmac_finish(aes_cmac_ctx, computed_mic); ret = mbedtls_cipher_cmac_finish(aes_cmac_ctx, computed_mic);
if (0 != ret) if (0 != ret) {
goto exit; goto exit;
}
*mic = (uint32_t)((uint32_t) computed_mic[3] << 24 *mic = (uint32_t)((uint32_t) computed_mic[3] << 24
| (uint32_t) computed_mic[2] << 16 | (uint32_t) computed_mic[2] << 16
@ -217,13 +229,15 @@ int LoRaMacCrypto::decrypt_join_frame(const uint8_t *buffer, uint16_t size,
mbedtls_aes_init(&aes_ctx); mbedtls_aes_init(&aes_ctx);
ret = mbedtls_aes_setkey_enc(&aes_ctx, key, key_length); ret = mbedtls_aes_setkey_enc(&aes_ctx, key, key_length);
if (0 != ret) if (0 != ret) {
goto exit; goto exit;
}
ret = mbedtls_aes_crypt_ecb(&aes_ctx, MBEDTLS_AES_ENCRYPT, buffer, ret = mbedtls_aes_crypt_ecb(&aes_ctx, MBEDTLS_AES_ENCRYPT, buffer,
dec_buffer); dec_buffer);
if (0 != ret) if (0 != ret) {
goto exit; goto exit;
}
// Check if optional CFList is included // Check if optional CFList is included
if (size >= 16) { if (size >= 16) {
@ -247,16 +261,18 @@ int LoRaMacCrypto::compute_skeys_for_join_frame(const uint8_t *key, uint32_t key
mbedtls_aes_init(&aes_ctx); mbedtls_aes_init(&aes_ctx);
ret = mbedtls_aes_setkey_enc(&aes_ctx, key, key_length); ret = mbedtls_aes_setkey_enc(&aes_ctx, key, key_length);
if (0 != ret) if (0 != ret) {
goto exit; goto exit;
}
memset(nonce, 0, sizeof(nonce)); memset(nonce, 0, sizeof(nonce));
nonce[0] = 0x01; nonce[0] = 0x01;
memcpy(nonce + 1, app_nonce, 6); memcpy(nonce + 1, app_nonce, 6);
memcpy(nonce + 7, p_dev_nonce, 2); memcpy(nonce + 7, p_dev_nonce, 2);
ret = mbedtls_aes_crypt_ecb(&aes_ctx, MBEDTLS_AES_ENCRYPT, nonce, nwk_skey); ret = mbedtls_aes_crypt_ecb(&aes_ctx, MBEDTLS_AES_ENCRYPT, nonce, nwk_skey);
if (0 != ret) if (0 != ret) {
goto exit; goto exit;
}
memset(nonce, 0, sizeof(nonce)); memset(nonce, 0, sizeof(nonce));
nonce[0] = 0x02; nonce[0] = 0x02;

View File

@ -34,8 +34,7 @@ SPDX-License-Identifier: BSD-3-Clause
#include "mbedtls/cmac.h" #include "mbedtls/cmac.h"
class LoRaMacCrypto class LoRaMacCrypto {
{
public: public:
/** /**
* Constructor * Constructor

View File

@ -193,13 +193,16 @@ static const uint8_t datarates_AU915[] = {12, 11, 10, 9, 8, 7, 8, 0, 12, 11, 10,
*/ */
static const uint32_t bandwidths_AU915[] = { 125000, 125000, 125000, 125000, static const uint32_t bandwidths_AU915[] = { 125000, 125000, 125000, 125000,
125000, 125000, 500000, 0, 500000, 500000, 500000, 500000, 500000, 500000, 125000, 125000, 500000, 0, 500000, 500000, 500000, 500000, 500000, 500000,
0, 0 }; 0, 0
};
/*! /*!
* Up/Down link data rates offset definition * Up/Down link data rates offset definition
*/ */
static const int8_t datarate_offsets_AU915[7][6] = { { DR_8, DR_8, DR_8, DR_8, static const int8_t datarate_offsets_AU915[7][6] = { {
DR_8, DR_8 }, // DR_0 DR_8, DR_8, DR_8, DR_8,
DR_8, DR_8
}, // DR_0
{ DR_9, DR_8, DR_8, DR_8, DR_8, DR_8 }, // DR_1 { DR_9, DR_8, DR_8, DR_8, DR_8, DR_8 }, // DR_1
{ DR_10, DR_9, DR_8, DR_8, DR_8, DR_8 }, // DR_2 { DR_10, DR_9, DR_8, DR_8, DR_8, DR_8 }, // DR_2
{ DR_11, DR_10, DR_9, DR_8, DR_8, DR_8 }, // DR_3 { DR_11, DR_10, DR_9, DR_8, DR_8, DR_8 }, // DR_3
@ -212,13 +215,15 @@ DR_8, DR_8 }, // DR_0
* Maximum payload with respect to the datarate index. Cannot operate with repeater. * Maximum payload with respect to the datarate index. Cannot operate with repeater.
*/ */
static const uint8_t max_payload_AU915[] = { 51, 51, 51, 115, 242, 242, static const uint8_t max_payload_AU915[] = { 51, 51, 51, 115, 242, 242,
242, 0, 53, 129, 242, 242, 242, 242, 0, 0 }; 242, 0, 53, 129, 242, 242, 242, 242, 0, 0
};
/*! /*!
* Maximum payload with respect to the datarate index. Can operate with repeater. * Maximum payload with respect to the datarate index. Can operate with repeater.
*/ */
static const uint8_t max_payload_with_repeater_AU915[] = { 51, 51, 51, 115, static const uint8_t max_payload_with_repeater_AU915[] = { 51, 51, 51, 115,
222, 222, 222, 0, 33, 109, 222, 222, 222, 222, 0, 0 }; 222, 222, 222, 0, 33, 109, 222, 222, 222, 222, 0, 0
};
static const uint16_t fsb_mask[] = MBED_CONF_LORA_FSB_MASK; static const uint16_t fsb_mask[] = MBED_CONF_LORA_FSB_MASK;

View File

@ -212,8 +212,7 @@ LoRaPHYCN470::LoRaPHYCN470()
// Channels // Channels
// 125 kHz channels // 125 kHz channels
for( uint8_t i = 0; i < CN470_MAX_NB_CHANNELS; i++ ) for (uint8_t i = 0; i < CN470_MAX_NB_CHANNELS; i++) {
{
channels[i].frequency = 470300000 + i * 200000; channels[i].frequency = 470300000 + i * 200000;
channels[i].dr_range.value = (DR_5 << 4) | DR_0; channels[i].dr_range.value = (DR_5 << 4) | DR_0;
channels[i].band = 0; channels[i].band = 0;
@ -375,8 +374,7 @@ bool LoRaPHYCN470::rx_config(rx_config_params_t* config)
_radio->unlock(); _radio->unlock();
if( config->rx_slot == RX_SLOT_WIN_1 ) if (config->rx_slot == RX_SLOT_WIN_1) {
{
// Apply window 1 frequency // Apply window 1 frequency
frequency = CN470_FIRST_RX1_CHANNEL + (config->channel % 48) * CN470_STEPWIDTH_RX1_CHANNEL; frequency = CN470_FIRST_RX1_CHANNEL + (config->channel % 48) * CN470_STEPWIDTH_RX1_CHANNEL;
} }

View File

@ -192,8 +192,7 @@ static const uint32_t bandwidths_US915[] = {125000, 125000, 125000, 125000, 5000
/*! /*!
* Up/Down link data rates offset definition * Up/Down link data rates offset definition
*/ */
static const int8_t datarate_offsets_US915[5][4] = static const int8_t datarate_offsets_US915[5][4] = {
{
{ DR_10, DR_9, DR_8, DR_8 }, // DR_0 { DR_10, DR_9, DR_8, DR_8 }, // DR_0
{ DR_11, DR_10, DR_9, DR_8 }, // DR_1 { DR_11, DR_10, DR_9, DR_8 }, // DR_1
{ DR_12, DR_11, DR_10, DR_9 }, // DR_2 { DR_12, DR_11, DR_10, DR_9 }, // DR_2
@ -572,8 +571,7 @@ uint8_t LoRaPHYUS915::accept_rx_param_setup_req(rx_param_setup_req_t* params)
} }
// Verify datarate offset // Verify datarate offset
if (val_in_range( params->dr_offset, US915_MIN_RX1_DR_OFFSET, US915_MAX_RX1_DR_OFFSET ) == 0 ) if (val_in_range(params->dr_offset, US915_MIN_RX1_DR_OFFSET, US915_MAX_RX1_DR_OFFSET) == 0) {
{
status &= 0xFB; // Rx1DrOffset range KO status &= 0xFB; // Rx1DrOffset range KO
} }

View File

@ -26,8 +26,7 @@ SPDX-License-Identifier: BSD-3-Clause
#include "lorawan_data_structures.h" #include "lorawan_data_structures.h"
class LoRaWANTimeHandler class LoRaWANTimeHandler {
{
public: public:
LoRaWANTimeHandler(); LoRaWANTimeHandler();
~LoRaWANTimeHandler(); ~LoRaWANTimeHandler();

View File

@ -186,7 +186,7 @@ void LWIP::Interface::netif_link_irq(struct netif *netif)
if (interface->client_callback && connectedStatusPrev != interface->connected if (interface->client_callback && connectedStatusPrev != interface->connected
&& interface->connected != NSAPI_STATUS_GLOBAL_UP /* advertised by netif_status_irq */ && interface->connected != NSAPI_STATUS_GLOBAL_UP /* advertised by netif_status_irq */
&& interface->connected != NSAPI_STATUS_DISCONNECTED) /* advertised by bring_down */ { && interface->connected != NSAPI_STATUS_DISCONNECTED) { /* advertised by bring_down */
interface->client_callback(NSAPI_EVENT_CONNECTION_STATUS_CHANGE, interface->connected); interface->client_callback(NSAPI_EVENT_CONNECTION_STATUS_CHANGE, interface->connected);
} }
} }
@ -235,7 +235,7 @@ void LWIP::Interface::netif_status_irq(struct netif *netif)
} }
if (interface->client_callback && (connectedStatusPrev != interface->connected) if (interface->client_callback && (connectedStatusPrev != interface->connected)
&& interface->connected != NSAPI_STATUS_DISCONNECTED) /* advertised by bring_down */ { && interface->connected != NSAPI_STATUS_DISCONNECTED) { /* advertised by bring_down */
interface->client_callback(NSAPI_EVENT_CONNECTION_STATUS_CHANGE, interface->connected); interface->client_callback(NSAPI_EVENT_CONNECTION_STATUS_CHANGE, interface->connected);
} }
} }

View File

@ -74,8 +74,7 @@ err_t LWIP::Interface::emac_igmp_mac_filter(struct netif *netif, const ip4_addr_
LWIP::Interface *mbed_if = static_cast<LWIP::Interface *>(netif->state); LWIP::Interface *mbed_if = static_cast<LWIP::Interface *>(netif->state);
switch (action) { switch (action) {
case NETIF_ADD_MAC_FILTER: case NETIF_ADD_MAC_FILTER: {
{
uint32_t group23 = ntohl(group->addr) & 0x007FFFFF; uint32_t group23 = ntohl(group->addr) & 0x007FFFFF;
uint8_t addr[6]; uint8_t addr[6];
addr[0] = LL_IP4_MULTICAST_ADDR_0; addr[0] = LL_IP4_MULTICAST_ADDR_0;
@ -112,8 +111,7 @@ err_t LWIP::Interface::emac_mld_mac_filter(struct netif *netif, const ip6_addr_t
LWIP::Interface *mbed_if = static_cast<LWIP::Interface *>(netif->state); LWIP::Interface *mbed_if = static_cast<LWIP::Interface *>(netif->state);
switch (action) { switch (action) {
case NETIF_ADD_MAC_FILTER: case NETIF_ADD_MAC_FILTER: {
{
uint32_t group32 = ntohl(group->addr[3]); uint32_t group32 = ntohl(group->addr[3]);
uint8_t addr[6]; uint8_t addr[6];
addr[0] = LL_IP6_MULTICAST_ADDR_0; addr[0] = LL_IP6_MULTICAST_ADDR_0;

View File

@ -485,7 +485,8 @@ nsapi_size_or_error_t LWIP::socket_recvfrom(nsapi_socket_t handle, SocketAddress
return recv; return recv;
} }
int32_t LWIP::find_multicast_member(const struct mbed_lwip_socket *s, const nsapi_ip_mreq_t *imr) { int32_t LWIP::find_multicast_member(const struct mbed_lwip_socket *s, const nsapi_ip_mreq_t *imr)
{
uint32_t count = 0; uint32_t count = 0;
uint32_t index = 0; uint32_t index = 0;
// Set upper limit on while loop, should break out when the membership pair is found // Set upper limit on while loop, should break out when the membership pair is found
@ -662,7 +663,8 @@ void LWIP::socket_attach(nsapi_socket_t handle, void (*callback)(void *), void *
s->data = data; s->data = data;
} }
LWIP &LWIP::get_instance() { LWIP &LWIP::get_instance()
{
static LWIP lwip; static LWIP lwip;
return lwip; return lwip;
} }
@ -672,7 +674,8 @@ LWIP &LWIP::get_instance() {
#define LWIP 0x11991199 #define LWIP 0x11991199
#if MBED_CONF_NSAPI_DEFAULT_STACK == LWIP #if MBED_CONF_NSAPI_DEFAULT_STACK == LWIP
#undef LWIP #undef LWIP
OnboardNetworkStack &OnboardNetworkStack::get_default_instance() { OnboardNetworkStack &OnboardNetworkStack::get_default_instance()
{
return LWIP::get_instance(); return LWIP::get_instance();
} }
#endif #endif

View File

@ -487,21 +487,29 @@ private:
struct mbed_lwip_socket *arena_alloc(); struct mbed_lwip_socket *arena_alloc();
void arena_dealloc(struct mbed_lwip_socket *s); void arena_dealloc(struct mbed_lwip_socket *s);
static uint32_t next_registered_multicast_member(const struct mbed_lwip_socket *s, uint32_t index) { static uint32_t next_registered_multicast_member(const struct mbed_lwip_socket *s, uint32_t index)
while (!(s->multicast_memberships_registry & (0x0001 << index))) { index++; } {
while (!(s->multicast_memberships_registry & (0x0001 << index))) {
index++;
}
return index; return index;
} }
static uint32_t next_free_multicast_member(const struct mbed_lwip_socket *s, uint32_t index) { static uint32_t next_free_multicast_member(const struct mbed_lwip_socket *s, uint32_t index)
while ((s->multicast_memberships_registry & (0x0001 << index))) { index++; } {
while ((s->multicast_memberships_registry & (0x0001 << index))) {
index++;
}
return index; return index;
} }
static void set_multicast_member_registry_bit(struct mbed_lwip_socket *s, uint32_t index) { static void set_multicast_member_registry_bit(struct mbed_lwip_socket *s, uint32_t index)
{
s->multicast_memberships_registry |= (0x0001 << index); s->multicast_memberships_registry |= (0x0001 << index);
} }
static void clear_multicast_member_registry_bit(struct mbed_lwip_socket *s, uint32_t index) { static void clear_multicast_member_registry_bit(struct mbed_lwip_socket *s, uint32_t index)
{
s->multicast_memberships_registry &= ~(0x0001 << index); s->multicast_memberships_registry &= ~(0x0001 << index);
} }
static int32_t find_multicast_member(const struct mbed_lwip_socket *s, const nsapi_ip_mreq_t *imr); static int32_t find_multicast_member(const struct mbed_lwip_socket *s, const nsapi_ip_mreq_t *imr);

View File

@ -27,7 +27,8 @@
#include "netsocket/nsapi_types.h" #include "netsocket/nsapi_types.h"
/* LWIP error remapping */ /* LWIP error remapping */
nsapi_error_t LWIP::err_remap(err_t err) { nsapi_error_t LWIP::err_remap(err_t err)
{
switch (err) { switch (err) {
case ERR_OK: case ERR_OK:
case ERR_CLSD: case ERR_CLSD:

View File

@ -268,7 +268,8 @@ static void ppp_input()
return; return;
} }
static void stream_cb() { static void stream_cb()
{
if (my_stream && !event_queued) { if (my_stream && !event_queued) {
event_queued = true; event_queued = true;
if (event_queue->call(callback(ppp_input)) == 0) { if (event_queue->call(callback(ppp_input)) == 0) {

View File

@ -70,12 +70,14 @@ public:
* @param stack Network stack as target for socket * @param stack Network stack as target for socket
* @return 0 on success, negative error code on failure * @return 0 on success, negative error code on failure
*/ */
virtual nsapi_error_t open(NetworkStack *stack) { virtual nsapi_error_t open(NetworkStack *stack)
{
return tcp_socket.open(stack); return tcp_socket.open(stack);
} }
template <typename S> template <typename S>
nsapi_error_t open(S *stack) { nsapi_error_t open(S *stack)
{
return open(nsapi_create_stack(stack)); return open(nsapi_create_stack(stack));
} }

View File

@ -50,7 +50,8 @@ TLSSocketWrapper::TLSSocketWrapper(Socket *transport, const char *hostname, cont
} }
} }
TLSSocketWrapper::~TLSSocketWrapper() { TLSSocketWrapper::~TLSSocketWrapper()
{
if (_transport) { if (_transport) {
close(); close();
} }
@ -139,7 +140,8 @@ nsapi_error_t TLSSocketWrapper::set_client_cert_key(const void *client_cert, siz
} }
nsapi_error_t TLSSocketWrapper::do_handshake() { nsapi_error_t TLSSocketWrapper::do_handshake()
{
nsapi_error_t _error; nsapi_error_t _error;
const char DRBG_PERS[] = "mbed TLS client"; const char DRBG_PERS[] = "mbed TLS client";
@ -228,7 +230,8 @@ nsapi_error_t TLSSocketWrapper::do_handshake() {
} }
nsapi_error_t TLSSocketWrapper::send(const void *data, nsapi_size_t size) { nsapi_error_t TLSSocketWrapper::send(const void *data, nsapi_size_t size)
{
int ret; int ret;
if (!_transport) { if (!_transport) {
@ -255,7 +258,8 @@ nsapi_size_or_error_t TLSSocketWrapper::sendto(const SocketAddress &, const void
return send(data, size); return send(data, size);
} }
nsapi_size_or_error_t TLSSocketWrapper::recv(void *data, nsapi_size_t size) { nsapi_size_or_error_t TLSSocketWrapper::recv(void *data, nsapi_size_t size)
{
int ret; int ret;
if (!_transport) { if (!_transport) {
@ -287,7 +291,8 @@ nsapi_size_or_error_t TLSSocketWrapper::recvfrom(SocketAddress *address, void *d
return recv(data, size); return recv(data, size);
} }
void TLSSocketWrapper::print_mbedtls_error(const char *name, int err) { void TLSSocketWrapper::print_mbedtls_error(const char *name, int err)
{
#ifdef MBEDTLS_ERROR_C #ifdef MBEDTLS_ERROR_C
char *buf = new char[128]; char *buf = new char[128];
mbedtls_strerror(err, buf, 128); mbedtls_strerror(err, buf, 128);
@ -329,10 +334,9 @@ int TLSSocketWrapper::my_verify(void *data, mbedtls_x509_crt *crt, int depth, ui
mbedtls_x509_crt_info(buf, buf_size - 1, " ", crt); mbedtls_x509_crt_info(buf, buf_size - 1, " ", crt);
tr_debug("%s", buf); tr_debug("%s", buf);
if (*flags == 0) if (*flags == 0) {
tr_info("No verification issue for this certificate\n"); tr_info("No verification issue for this certificate\n");
else } else {
{
mbedtls_x509_crt_verify_info(buf, buf_size, " ! ", *flags); mbedtls_x509_crt_verify_info(buf, buf_size, " ! ", *flags);
tr_info("%s\n", buf); tr_info("%s\n", buf);
} }
@ -345,7 +349,8 @@ int TLSSocketWrapper::my_verify(void *data, mbedtls_x509_crt *crt, int depth, ui
#endif /* MBED_CONF_TLS_SOCKET_DEBUG_LEVEL > 0 */ #endif /* MBED_CONF_TLS_SOCKET_DEBUG_LEVEL > 0 */
int TLSSocketWrapper::ssl_recv(void *ctx, unsigned char *buf, size_t len) { int TLSSocketWrapper::ssl_recv(void *ctx, unsigned char *buf, size_t len)
{
int recv; int recv;
TLSSocketWrapper *my = static_cast<TLSSocketWrapper *>(ctx); TLSSocketWrapper *my = static_cast<TLSSocketWrapper *>(ctx);
@ -365,7 +370,8 @@ int TLSSocketWrapper::ssl_recv(void *ctx, unsigned char *buf, size_t len) {
return recv; return recv;
} }
int TLSSocketWrapper::ssl_send(void *ctx, const unsigned char *buf, size_t len) { int TLSSocketWrapper::ssl_send(void *ctx, const unsigned char *buf, size_t len)
{
int size = -1; int size = -1;
TLSSocketWrapper *my = static_cast<TLSSocketWrapper *>(ctx); TLSSocketWrapper *my = static_cast<TLSSocketWrapper *>(ctx);

View File

@ -159,7 +159,9 @@ static nsapi_error_t do_sim_pin_check(ATCmdParser *at, const char *pin)
success = at->send("AT+CLCK=\"SC\",0,\"%s\"", pin) && at->recv("OK"); success = at->send("AT+CLCK=\"SC\",0,\"%s\"", pin) && at->recv("OK");
} }
if (success) return NSAPI_ERROR_OK; if (success) {
return NSAPI_ERROR_OK;
}
return NSAPI_ERROR_AUTH_FAILURE; return NSAPI_ERROR_AUTH_FAILURE;
} }
@ -444,7 +446,8 @@ nsapi_error_t PPPCellularInterface::initialize_sim_card()
return nsapi_error; return nsapi_error;
} }
void PPPCellularInterface::set_sim_pin(const char *pin) { void PPPCellularInterface::set_sim_pin(const char *pin)
{
/* overwrite the default pin by user provided pin */ /* overwrite the default pin by user provided pin */
_pin = pin; _pin = pin;
} }

View File

@ -229,7 +229,8 @@ Case cases[] = { Case("UDP echo test", test_udp_echo),
Case("TCP async echo test", test_tcp_echo_async), Case("TCP async echo test", test_tcp_echo_async),
#endif #endif
Case("Connect with credentials", test_connect_credentials), Case("Connect with credentials", test_connect_credentials),
Case("Connect with preset credentials", test_connect_preset_credentials) }; Case("Connect with preset credentials", test_connect_preset_credentials)
};
Specification specification(test_setup, cases); Specification specification(test_setup, cases);

View File

@ -45,7 +45,8 @@ const struct {
// Simple test that read/writes random set of blocks // Simple test that read/writes random set of blocks
void test_read_write() { void test_read_write()
{
uint8_t *dummy = new (std::nothrow) uint8_t[TEST_BLOCK_DEVICE_SIZE]; uint8_t *dummy = new (std::nothrow) uint8_t[TEST_BLOCK_DEVICE_SIZE];
TEST_SKIP_UNLESS_MESSAGE(dummy, "Not enough memory for test"); TEST_SKIP_UNLESS_MESSAGE(dummy, "Not enough memory for test");
delete[] dummy; delete[] dummy;
@ -155,7 +156,8 @@ end:
// Test setup // Test setup
utest::v1::status_t test_setup(const size_t number_of_cases) { utest::v1::status_t test_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(30, "default_auto"); GREENTEA_SETUP(30, "default_auto");
return verbose_test_setup_handler(number_of_cases); return verbose_test_setup_handler(number_of_cases);
} }
@ -166,6 +168,7 @@ Case cases[] = {
Specification specification(test_setup, cases); Specification specification(test_setup, cases);
int main() { int main()
{
return !Harness::run(specification); return !Harness::run(specification);
} }

View File

@ -232,7 +232,8 @@ end:
// Test setup // Test setup
utest::v1::status_t test_setup(const size_t number_of_cases) { utest::v1::status_t test_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(10, "default_auto"); GREENTEA_SETUP(10, "default_auto");
return verbose_test_setup_handler(number_of_cases); return verbose_test_setup_handler(number_of_cases);
} }
@ -245,6 +246,7 @@ Case cases[] = {
Specification specification(test_setup, cases); Specification specification(test_setup, cases);
int main() { int main()
{
return !Harness::run(specification); return !Harness::run(specification);
} }

View File

@ -36,7 +36,8 @@ using namespace utest::v1;
// Simple test which read/writes blocks on a sliced block device // Simple test which read/writes blocks on a sliced block device
void test_slicing() { void test_slicing()
{
uint8_t *dummy = new (std::nothrow) uint8_t[BLOCK_COUNT * BLOCK_SIZE]; uint8_t *dummy = new (std::nothrow) uint8_t[BLOCK_COUNT * BLOCK_SIZE];
TEST_SKIP_UNLESS_MESSAGE(dummy, "Not enough memory for test"); TEST_SKIP_UNLESS_MESSAGE(dummy, "Not enough memory for test");
delete[] dummy; delete[] dummy;
@ -141,7 +142,8 @@ end:
} }
// Simple test which read/writes blocks on a chain of block devices // Simple test which read/writes blocks on a chain of block devices
void test_chaining() { void test_chaining()
{
uint8_t *dummy = new (std::nothrow) uint8_t[BLOCK_COUNT * BLOCK_SIZE]; uint8_t *dummy = new (std::nothrow) uint8_t[BLOCK_COUNT * BLOCK_SIZE];
TEST_SKIP_UNLESS_MESSAGE(dummy, "Not enough memory for test"); TEST_SKIP_UNLESS_MESSAGE(dummy, "Not enough memory for test");
delete[] dummy; delete[] dummy;
@ -211,7 +213,8 @@ end:
} }
// Simple test which read/writes blocks on a chain of block devices // Simple test which read/writes blocks on a chain of block devices
void test_profiling() { void test_profiling()
{
uint8_t *dummy = new (std::nothrow) uint8_t[BLOCK_COUNT * BLOCK_SIZE]; uint8_t *dummy = new (std::nothrow) uint8_t[BLOCK_COUNT * BLOCK_SIZE];
TEST_SKIP_UNLESS_MESSAGE(dummy, "Not enough memory for test"); TEST_SKIP_UNLESS_MESSAGE(dummy, "Not enough memory for test");
delete[] dummy; delete[] dummy;
@ -287,7 +290,8 @@ end:
// Test setup // Test setup
utest::v1::status_t test_setup(const size_t number_of_cases) { utest::v1::status_t test_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(10, "default_auto"); GREENTEA_SETUP(10, "default_auto");
return verbose_test_setup_handler(number_of_cases); return verbose_test_setup_handler(number_of_cases);
} }
@ -300,6 +304,7 @@ Case cases[] = {
Specification specification(test_setup, cases); Specification specification(test_setup, cases);
int main() { int main()
{
return !Harness::run(specification); return !Harness::run(specification);
} }

View File

@ -35,7 +35,8 @@ HeapBlockDevice bd(128*BLOCK_SIZE, BLOCK_SIZE);
// Test formatting // Test formatting
void test_format() { void test_format()
{
int err = FATFileSystem::format(&bd); int err = FATFileSystem::format(&bd);
TEST_ASSERT_EQUAL(0, err); TEST_ASSERT_EQUAL(0, err);
} }
@ -43,7 +44,8 @@ void test_format() {
// Simple test for reading/writing files // Simple test for reading/writing files
template <ssize_t TEST_SIZE> template <ssize_t TEST_SIZE>
void test_read_write() { void test_read_write()
{
FATFileSystem fs("fat"); FATFileSystem fs("fat");
int err = fs.mount(&bd); int err = fs.mount(&bd);
@ -86,7 +88,8 @@ void test_read_write() {
// Simple test for iterating dir entries // Simple test for iterating dir entries
void test_read_dir() { void test_read_dir()
{
FATFileSystem fs("fat"); FATFileSystem fs("fat");
int err = fs.mount(&bd); int err = fs.mount(&bd);
@ -147,7 +150,8 @@ void test_read_dir() {
// Test setup // Test setup
utest::v1::status_t test_setup(const size_t number_of_cases) { utest::v1::status_t test_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(10, "default_auto"); GREENTEA_SETUP(10, "default_auto");
return verbose_test_setup_handler(number_of_cases); return verbose_test_setup_handler(number_of_cases);
} }
@ -161,6 +165,7 @@ Case cases[] = {
Specification specification(test_setup, cases); Specification specification(test_setup, cases);
int main() { int main()
{
return !Harness::run(specification); return !Harness::run(specification);
} }

View File

@ -37,7 +37,8 @@ HeapBlockDevice bd(BLOCK_COUNT*BLOCK_SIZE, BLOCK_SIZE);
// Test formatting and partitioning // Test formatting and partitioning
void test_format() { void test_format()
{
// Create two partitions splitting device in ~half // Create two partitions splitting device in ~half
int err = MBRBlockDevice::partition(&bd, 1, 0x83, 0, (BLOCK_COUNT / 2) * BLOCK_SIZE); int err = MBRBlockDevice::partition(&bd, 1, 0x83, 0, (BLOCK_COUNT / 2) * BLOCK_SIZE);
TEST_ASSERT_EQUAL(0, err); TEST_ASSERT_EQUAL(0, err);
@ -72,7 +73,8 @@ void test_format() {
// Simple multipartition test for reading/writing files // Simple multipartition test for reading/writing files
template <ssize_t TEST_SIZE> template <ssize_t TEST_SIZE>
void test_read_write() { void test_read_write()
{
// Load both partitions // Load both partitions
MBRBlockDevice part1(&bd, 1); MBRBlockDevice part1(&bd, 1);
int err = part1.init(); int err = part1.init();
@ -163,7 +165,8 @@ void test_read_write() {
TEST_ASSERT_EQUAL(0, err); TEST_ASSERT_EQUAL(0, err);
} }
void test_single_mbr() { void test_single_mbr()
{
int err = bd.init(); int err = bd.init();
TEST_ASSERT_EQUAL(0, err); TEST_ASSERT_EQUAL(0, err);
@ -205,7 +208,8 @@ void test_single_mbr() {
// Test setup // Test setup
utest::v1::status_t test_setup(const size_t number_of_cases) { utest::v1::status_t test_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(10, "default_auto"); GREENTEA_SETUP(10, "default_auto");
return verbose_test_setup_handler(number_of_cases); return verbose_test_setup_handler(number_of_cases);
} }
@ -219,6 +223,7 @@ Case cases[] = {
Specification specification(test_setup, cases); Specification specification(test_setup, cases);
int main() { int main()
{
return !Harness::run(specification); return !Harness::run(specification);
} }

View File

@ -40,8 +40,7 @@ typedef uint64_t bd_size_t;
/** A hardware device capable of writing and reading blocks /** A hardware device capable of writing and reading blocks
*/ */
class BlockDevice class BlockDevice {
{
public: public:
/** Return the default block device /** Return the default block device

View File

@ -31,8 +31,7 @@
* after a configurable number of cycles. * after a configurable number of cycles.
* *
*/ */
class ExhaustibleBlockDevice : public BlockDevice class ExhaustibleBlockDevice : public BlockDevice {
{
public: public:
/** Lifetime of the block device /** Lifetime of the block device
* *

View File

@ -50,8 +50,7 @@
* } * }
* @endcode * @endcode
*/ */
class HeapBlockDevice : public BlockDevice class HeapBlockDevice : public BlockDevice {
{
public: public:
/** Lifetime of the memory block device /** Lifetime of the memory block device

View File

@ -87,8 +87,7 @@ enum {
* - At most 4 partitions are supported * - At most 4 partitions are supported
* - Extended partitions are currently not supported and will error during init * - Extended partitions are currently not supported and will error during init
*/ */
class MBRBlockDevice : public BlockDevice class MBRBlockDevice : public BlockDevice {
{
public: public:
/** Format the MBR to contain the following partition /** Format the MBR to contain the following partition
* *

View File

@ -27,8 +27,7 @@
#include "platform/Callback.h" #include "platform/Callback.h"
class ObservingBlockDevice : public BlockDevice class ObservingBlockDevice : public BlockDevice {
{
public: public:
/** Lifetime of the block device /** Lifetime of the block device

View File

@ -43,8 +43,7 @@
* printf("erase count: %lld\n", profiler.get_erase_count()); * printf("erase count: %lld\n", profiler.get_erase_count());
* @endcode * @endcode
*/ */
class ProfilingBlockDevice : public BlockDevice class ProfilingBlockDevice : public BlockDevice {
{
public: public:
/** Lifetime of the memory block device /** Lifetime of the memory block device
* *

View File

@ -26,8 +26,7 @@
#include "PlatformMutex.h" #include "PlatformMutex.h"
class ReadOnlyBlockDevice : public BlockDevice class ReadOnlyBlockDevice : public BlockDevice {
{
public: public:
/** Lifetime of the block device /** Lifetime of the block device

View File

@ -45,8 +45,7 @@
* SlicingBlockDevice slice3(&mem, 16*512, -16*512); * SlicingBlockDevice slice3(&mem, 16*512, -16*512);
* @endcode * @endcode
*/ */
class SlicingBlockDevice : public BlockDevice class SlicingBlockDevice : public BlockDevice {
{
public: public:
/** Lifetime of the memory block device /** Lifetime of the memory block device
* *

View File

@ -139,7 +139,8 @@ size_t FileSystem::dir_size(fs_dir_t dir)
template <typename F> template <typename F>
class Managed : public F { class Managed : public F {
public: public:
virtual int close() { virtual int close()
{
int err = F::close(); int err = F::close();
delete this; delete this;
return err; return err;
@ -159,7 +160,8 @@ int FileSystem::open(FileHandle **file, const char *path, int flags)
return 0; return 0;
} }
int FileSystem::open(DirHandle **dir, const char *path) { int FileSystem::open(DirHandle **dir, const char *path)
{
Dir *d = new Managed<Dir>; Dir *d = new Managed<Dir>;
int err = d->open(this, path); int err = d->open(this, path);
if (err) { if (err) {

View File

@ -280,7 +280,8 @@ DRESULT disk_ioctl(BYTE pdrv, BYTE cmd, void *buff)
// Filesystem implementation (See FATFilySystem.h) // Filesystem implementation (See FATFilySystem.h)
FATFileSystem::FATFileSystem(const char *name, BlockDevice *bd) FATFileSystem::FATFileSystem(const char *name, BlockDevice *bd)
: FileSystem(name), _id(-1) { : FileSystem(name), _id(-1)
{
if (bd) { if (bd) {
mount(bd); mount(bd);
} }

View File

@ -33,17 +33,28 @@ extern "C" void lfs_crc(uint32_t *crc, const void *buffer, size_t size)
static int lfs_toerror(int err) static int lfs_toerror(int err)
{ {
switch (err) { switch (err) {
case LFS_ERR_OK: return 0; case LFS_ERR_OK:
case LFS_ERR_IO: return -EIO; return 0;
case LFS_ERR_NOENT: return -ENOENT; case LFS_ERR_IO:
case LFS_ERR_EXIST: return -EEXIST; return -EIO;
case LFS_ERR_NOTDIR: return -ENOTDIR; case LFS_ERR_NOENT:
case LFS_ERR_ISDIR: return -EISDIR; return -ENOENT;
case LFS_ERR_INVAL: return -EINVAL; case LFS_ERR_EXIST:
case LFS_ERR_NOSPC: return -ENOSPC; return -EEXIST;
case LFS_ERR_NOMEM: return -ENOMEM; case LFS_ERR_NOTDIR:
case LFS_ERR_CORRUPT: return -EILSEQ; return -ENOTDIR;
default: return err; case LFS_ERR_ISDIR:
return -EISDIR;
case LFS_ERR_INVAL:
return -EINVAL;
case LFS_ERR_NOSPC:
return -ENOSPC;
case LFS_ERR_NOMEM:
return -ENOMEM;
case LFS_ERR_CORRUPT:
return -EILSEQ;
default:
return err;
} }
} }
@ -62,10 +73,14 @@ static int lfs_fromflags(int flags)
static int lfs_fromwhence(int whence) static int lfs_fromwhence(int whence)
{ {
switch (whence) { switch (whence) {
case SEEK_SET: return LFS_SEEK_SET; case SEEK_SET:
case SEEK_CUR: return LFS_SEEK_CUR; return LFS_SEEK_SET;
case SEEK_END: return LFS_SEEK_END; case SEEK_CUR:
default: return whence; return LFS_SEEK_CUR;
case SEEK_END:
return LFS_SEEK_END;
default:
return whence;
} }
} }
@ -73,31 +88,39 @@ static int lfs_tomode(int type)
{ {
int mode = S_IRWXU | S_IRWXG | S_IRWXO; int mode = S_IRWXU | S_IRWXG | S_IRWXO;
switch (type) { switch (type) {
case LFS_TYPE_DIR: return mode | S_IFDIR; case LFS_TYPE_DIR:
case LFS_TYPE_REG: return mode | S_IFREG; return mode | S_IFDIR;
default: return 0; case LFS_TYPE_REG:
return mode | S_IFREG;
default:
return 0;
} }
} }
static int lfs_totype(int type) static int lfs_totype(int type)
{ {
switch (type) { switch (type) {
case LFS_TYPE_DIR: return DT_DIR; case LFS_TYPE_DIR:
case LFS_TYPE_REG: return DT_REG; return DT_DIR;
default: return DT_UNKNOWN; case LFS_TYPE_REG:
return DT_REG;
default:
return DT_UNKNOWN;
} }
} }
////// Block device operations ////// ////// Block device operations //////
static int lfs_bd_read(const struct lfs_config *c, lfs_block_t block, static int lfs_bd_read(const struct lfs_config *c, lfs_block_t block,
lfs_off_t off, void *buffer, lfs_size_t size) { lfs_off_t off, void *buffer, lfs_size_t size)
{
BlockDevice *bd = (BlockDevice *)c->context; BlockDevice *bd = (BlockDevice *)c->context;
return bd->read(buffer, (bd_addr_t)block * c->block_size + off, size); return bd->read(buffer, (bd_addr_t)block * c->block_size + off, size);
} }
static int lfs_bd_prog(const struct lfs_config *c, lfs_block_t block, static int lfs_bd_prog(const struct lfs_config *c, lfs_block_t block,
lfs_off_t off, const void *buffer, lfs_size_t size) { lfs_off_t off, const void *buffer, lfs_size_t size)
{
BlockDevice *bd = (BlockDevice *)c->context; BlockDevice *bd = (BlockDevice *)c->context;
return bd->program(buffer, (bd_addr_t)block * c->block_size + off, size); return bd->program(buffer, (bd_addr_t)block * c->block_size + off, size);
} }
@ -125,13 +148,15 @@ LittleFileSystem::LittleFileSystem(const char *name, BlockDevice *bd,
, _read_size(read_size) , _read_size(read_size)
, _prog_size(prog_size) , _prog_size(prog_size)
, _block_size(block_size) , _block_size(block_size)
, _lookahead(lookahead) { , _lookahead(lookahead)
{
if (bd) { if (bd) {
mount(bd); mount(bd);
} }
} }
LittleFileSystem::~LittleFileSystem() { LittleFileSystem::~LittleFileSystem()
{
// nop if unmounted // nop if unmounted
unmount(); unmount();
} }
@ -212,7 +237,8 @@ int LittleFileSystem::unmount()
int LittleFileSystem::format(BlockDevice *bd, int LittleFileSystem::format(BlockDevice *bd,
lfs_size_t read_size, lfs_size_t prog_size, lfs_size_t read_size, lfs_size_t prog_size,
lfs_size_t block_size, lfs_size_t lookahead) { lfs_size_t block_size, lfs_size_t lookahead)
{
LFS_INFO("format(%p, %ld, %ld, %ld, %ld)", LFS_INFO("format(%p, %ld, %ld, %ld, %ld)",
bd, read_size, prog_size, block_size, lookahead); bd, read_size, prog_size, block_size, lookahead);
int err = bd->init(); int err = bd->init();

View File

@ -666,7 +666,8 @@ clean:
utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason)
{
greentea_case_failure_abort_handler(source, reason); greentea_case_failure_abort_handler(source, reason);
return STATUS_CONTINUE; return STATUS_CONTINUE;
} }

View File

@ -38,8 +38,7 @@ static const uint16_t master_record_key = 0xFFE;
static const uint16_t no_key = 0xFFF; static const uint16_t no_key = 0xFFF;
static const uint16_t last_reserved_key = master_record_key; static const uint16_t last_reserved_key = master_record_key;
typedef struct typedef struct {
{
uint16_t key_and_flags; uint16_t key_and_flags;
uint16_t size_and_owner; uint16_t size_and_owner;
uint32_t crc; uint32_t crc;
@ -88,10 +87,12 @@ static const uint8_t blank_flash_val = 0xFF;
#endif #endif
NVStore::nvstore_area_data_t NVStore::initial_area_params[] = {{NVSTORE_AREA_1_ADDRESS, NVSTORE_AREA_1_SIZE}, NVStore::nvstore_area_data_t NVStore::initial_area_params[] = {{NVSTORE_AREA_1_ADDRESS, NVSTORE_AREA_1_SIZE},
{NVSTORE_AREA_2_ADDRESS, NVSTORE_AREA_2_SIZE}}; {NVSTORE_AREA_2_ADDRESS, NVSTORE_AREA_2_SIZE}
};
#else #else
NVStore::nvstore_area_data_t NVStore::initial_area_params[] = {{0, 0}, NVStore::nvstore_area_data_t NVStore::initial_area_params[] = {{0, 0},
{0, 0}}; {0, 0}
};
#endif #endif
typedef enum { typedef enum {

View File

@ -113,7 +113,8 @@ static osThreadId_t os_libspace_id[OS_THREAD_LIBSPACE_NUM] \
__attribute__((section(".bss.os.libspace"))); __attribute__((section(".bss.os.libspace")));
// Check if Kernel has been started // Check if Kernel has been started
static uint32_t os_kernel_is_active (void) { static uint32_t os_kernel_is_active(void)
{
static uint8_t os_kernel_active = 0U; static uint8_t os_kernel_active = 0U;
if (os_kernel_active == 0U) { if (os_kernel_active == 0U) {
@ -125,7 +126,8 @@ static uint32_t os_kernel_is_active (void) {
} }
// Provide libspace for current thread // Provide libspace for current thread
void *__user_perthread_libspace (void) { void *__user_perthread_libspace(void)
{
osThreadId_t id; osThreadId_t id;
uint32_t n; uint32_t n;
@ -218,21 +220,24 @@ __USED int _mutex_initialize(mutex *m)
} }
/* Acquire mutex */ /* Acquire mutex */
__USED void _mutex_acquire(mutex *m) { __USED void _mutex_acquire(mutex *m)
{
if (os_kernel_is_active() != 0U) { if (os_kernel_is_active() != 0U) {
(void)osMutexAcquire(*m, osWaitForever); (void)osMutexAcquire(*m, osWaitForever);
} }
} }
/* Release mutex */ /* Release mutex */
__USED void _mutex_release(mutex *m) { __USED void _mutex_release(mutex *m)
{
if (os_kernel_is_active() != 0U) { if (os_kernel_is_active() != 0U) {
(void)osMutexRelease(*m); (void)osMutexRelease(*m);
} }
} }
/* Free mutex */ /* Free mutex */
__USED void _mutex_free(mutex *m) { __USED void _mutex_free(mutex *m)
{
mutex *slot = NULL; mutex *slot = NULL;
core_util_critical_section_enter(); core_util_critical_section_enter();
for (int i = 0; i < OS_MUTEX_STATIC_NUM; i++) { for (int i = 0; i < OS_MUTEX_STATIC_NUM; i++) {

View File

@ -86,7 +86,8 @@ void mbed_toolchain_init()
} }
extern int __real_main(void); extern int __real_main(void);
int __wrap_main(void) { int __wrap_main(void)
{
/* For backwards compatibility */ /* For backwards compatibility */
return __real_main(); return __real_main();
} }