Skip to content

Commit

Permalink
Merge branch 'main' into chibios-platform-heap-implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
networkfusion committed Apr 26, 2023
2 parents 8cc5e0e + e3864c2 commit 30000ae
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 130 deletions.
11 changes: 5 additions & 6 deletions src/HAL/Include/nanoHAL_v2.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
#include <stdlib.h>

// defines to prevent use of malloc, free and realloc
// the platform implementations: platform_malloc(), platform_free and platform_realloc
// are the preferred calls to use as they ensure thread safety and RTOS integration
#define malloc YOU_SHALL_NOT_USE_malloc
#define free YOU_SHALL_NOT_USE_free
#define realloc YOU_SHALL_NOT_USE_realloc
// the platform implementations: platform_malloc(), platform_free() should be used instead.
// realloc should never be used.
// as these the preferred calls to use as they ensure thread safety and RTOS integration.
#define malloc YOU_SHALL_NOT_USE_malloc
#define free YOU_SHALL_NOT_USE_free

#endif

Expand Down Expand Up @@ -241,7 +241,6 @@ extern "C"

void *platform_malloc(size_t size);
void platform_free(void *ptr);
void *platform_realloc(void *ptr, size_t size);

#ifdef __cplusplus
}
Expand Down
7 changes: 0 additions & 7 deletions targets/AzureRTOS/_common/platform_heap.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,3 @@ void platform_free(void *ptr)
uint32_t freeStatus = tx_byte_release(ptr);
ASSERT(freeStatus == TX_SUCCESS);
}

void *platform_realloc(void *ptr, size_t size)
{
(void)size;

return ptr;
}
5 changes: 0 additions & 5 deletions targets/ESP32/_common/platform_heap.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,3 @@ void platform_free(void *ptr)
{
heap_caps_free(ptr);
}

void *platform_realloc(void *ptr, size_t size)
{
return heap_caps_realloc(ptr, size, DEFAULT_MALLOC_CAPS);
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ static const CLR_RT_MethodHandler method_lookup[] =
NULL,
NULL,
NULL,
NULL,
Library_sys_dev_ble_native_nanoFramework_Device_Bluetooth_Advertisement_BluetoothLEAdvertisementReceivedEventArgs::NativeCreateFromEvent___BOOLEAN__I4,
NULL,
NULL,
Expand Down Expand Up @@ -432,6 +433,7 @@ static const CLR_RT_MethodHandler method_lookup[] =
NULL,
NULL,
NULL,
NULL,
Library_sys_dev_ble_native_nanoFramework_Device_Bluetooth_BluetoothLEAdvertisementWatcher::NativeStartAdvertisementWatcher___VOID__I4,
Library_sys_dev_ble_native_nanoFramework_Device_Bluetooth_BluetoothLEAdvertisementWatcher::NativeStopAdvertisementWatcher___VOID,
NULL,
Expand Down Expand Up @@ -746,7 +748,7 @@ static const CLR_RT_MethodHandler method_lookup[] =
const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_nanoFramework_Device_Bluetooth =
{
"nanoFramework.Device.Bluetooth",
0xCB007524,
0xA7C14F9F,
method_lookup,
{ 100, 0, 4, 0 }
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

#include <string.h>

// clang-format off

typedef enum __nfpack BluetoothLEAdvertisementFlags
{
BluetoothLEAdvertisementFlags_None = 0,
Expand Down Expand Up @@ -295,8 +297,7 @@ struct Library_sys_dev_ble_native_nanoFramework_Device_Bluetooth_Advertisement_B
//--//
};

struct
Library_sys_dev_ble_native_nanoFramework_Device_Bluetooth_Advertisement_BluetoothLEAdvertisementWatcherStoppedEventArgs
struct Library_sys_dev_ble_native_nanoFramework_Device_Bluetooth_Advertisement_BluetoothLEAdvertisementWatcherStoppedEventArgs
{
static const int FIELD___error = 1;

Expand Down Expand Up @@ -357,8 +358,7 @@ struct Library_sys_dev_ble_native_nanoFramework_Device_Bluetooth_GenericAttribut
//--//
};

struct
Library_sys_dev_ble_native_nanoFramework_Device_Bluetooth_GenericAttributeProfile_GattLocalCharacteristicParameters
struct Library_sys_dev_ble_native_nanoFramework_Device_Bluetooth_GenericAttributeProfile_GattLocalCharacteristicParameters
{
static const int FIELD___writeProtectionLevel = 1;
static const int FIELD___readProtectionLevel = 2;
Expand Down Expand Up @@ -414,8 +414,7 @@ struct Library_sys_dev_ble_native_nanoFramework_Device_Bluetooth_DevicePairingRe

NANOCLR_NATIVE_DECLARE(NativeAcceptYesNo___U2__U2__nanoFrameworkDeviceBluetoothDevicePairingKinds__I4);
NANOCLR_NATIVE_DECLARE(NativeAcceptPasskey___U2__U2__nanoFrameworkDeviceBluetoothDevicePairingKinds__I4);
NANOCLR_NATIVE_DECLARE(
NativeAcceptCredentials___U2__U2__nanoFrameworkDeviceBluetoothDevicePairingKinds__SZARRAY_U1__SZARRAY_U1);
NANOCLR_NATIVE_DECLARE(NativeAcceptCredentials___U2__U2__nanoFrameworkDeviceBluetoothDevicePairingKinds__SZARRAY_U1__SZARRAY_U1);

//--//
};
Expand Down Expand Up @@ -450,8 +449,7 @@ struct Library_sys_dev_ble_native_nanoFramework_Device_Bluetooth_BluetoothNanoDe
static const int FIELD_STATIC___mode = 2;

NANOCLR_NATIVE_DECLARE(NativeInitilise___STATIC__VOID);
NANOCLR_NATIVE_DECLARE(
NativeSetOperationMode___STATIC__VOID__nanoFrameworkDeviceBluetoothBluetoothNanoDeviceMode__STRING__U2);
NANOCLR_NATIVE_DECLARE(NativeSetOperationMode___STATIC__VOID__nanoFrameworkDeviceBluetoothBluetoothNanoDeviceMode__STRING__U2);

//--//
};
Expand Down Expand Up @@ -528,8 +526,7 @@ struct Library_sys_dev_ble_native_nanoFramework_Device_Bluetooth_GenericAttribut
//--//
};

struct
Library_sys_dev_ble_native_nanoFramework_Device_Bluetooth_GenericAttributeProfile_GattSessionStatusChangedEventArgs
struct Library_sys_dev_ble_native_nanoFramework_Device_Bluetooth_GenericAttributeProfile_GattSessionStatusChangedEventArgs
{
static const int FIELD___status = 1;
static const int FIELD___bluetoothError = 2;
Expand Down Expand Up @@ -673,8 +670,7 @@ struct Library_sys_dev_ble_native_nanoFramework_Device_Bluetooth_GenericAttribut
static const int FIELD__ValueChanged = 12;

NANOCLR_NATIVE_DECLARE(NativeStartDiscoveryDescriptors___U2__U2__U2__U2);
NANOCLR_NATIVE_DECLARE(
NativeUpdateDescriptor___VOID__U2__U2__U2__nanoFrameworkDeviceBluetoothGenericAttributeProfileGattDescriptor);
NANOCLR_NATIVE_DECLARE(NativeUpdateDescriptor___VOID__U2__U2__U2__nanoFrameworkDeviceBluetoothGenericAttributeProfileGattDescriptor);
NANOCLR_NATIVE_DECLARE(NativeReadEventData___SZARRAY_U1__U2__U2);

//--//
Expand All @@ -691,8 +687,7 @@ struct Library_sys_dev_ble_native_nanoFramework_Device_Bluetooth_GenericAttribut
static const int FIELD___eventComplete = 7;

NANOCLR_NATIVE_DECLARE(NativeDiscoverCharacteristics___U2__U2__U2__U2__U2);
NANOCLR_NATIVE_DECLARE(
NativeUpdateCharacteristic___VOID__U2__U2__U2__nanoFrameworkDeviceBluetoothGenericAttributeProfileGattCharacteristic);
NANOCLR_NATIVE_DECLARE(NativeUpdateCharacteristic___VOID__U2__U2__U2__nanoFrameworkDeviceBluetoothGenericAttributeProfileGattCharacteristic);

//--//
};
Expand Down Expand Up @@ -724,8 +719,7 @@ struct Library_sys_dev_ble_native_nanoFramework_Device_Bluetooth_BluetoothLEDevi
NANOCLR_NATIVE_DECLARE(NativeDisconnect___VOID__U2);
NANOCLR_NATIVE_DECLARE(NativeDispose___VOID__U2);
NANOCLR_NATIVE_DECLARE(NativeDiscoverServices___U2__U2);
NANOCLR_NATIVE_DECLARE(
NativeUpdateService___VOID__U2__nanoFrameworkDeviceBluetoothGenericAttributeProfileGattDeviceService);
NANOCLR_NATIVE_DECLARE(NativeUpdateService___VOID__U2__nanoFrameworkDeviceBluetoothGenericAttributeProfileGattDeviceService);
NANOCLR_NATIVE_DECLARE(NativeStartReadValue___U2__U2__U2);
NANOCLR_NATIVE_DECLARE(NativeReadValue___SZARRAY_U1__U2__U2);
NANOCLR_NATIVE_DECLARE(NativeStartWriteValue___U2__U2__U2__BOOLEAN__SZARRAY_U1__U2);
Expand Down Expand Up @@ -763,20 +757,24 @@ struct Library_sys_dev_ble_native_nanoFramework_Device_Bluetooth_BluetoothEventL
//--//
};

struct Library_sys_dev_ble_native_nanoFramework_Device_Bluetooth_BluetoothSignalStrengthFilter
struct Library_sys_dev_ble_native_nanoFramework_Device_Bluetooth_BluetoothSignalStrengthFilter__ScanItem
{
static const int FIELD___inRangeThresholdInDBm = 1;
static const int FIELD___outOfRangeThresholdInDBm = 2;
static const int FIELD___outOfRangeTimeout = 3;
static const int FIELD__Rssi = 1;
static const int FIELD__InRange = 2;
static const int FIELD__OutRangeTime = 3;
static const int FIELD__Active = 4;

//--//
};

struct Library_sys_dev_ble_native_nanoFramework_Device_Bluetooth_BluetoothLEAdvertisementWatcher__ScanItem
struct Library_sys_dev_ble_native_nanoFramework_Device_Bluetooth_BluetoothSignalStrengthFilter
{
static const int FIELD__rssi = 1;
static const int FIELD__inRange = 2;
static const int FIELD__outRangeTime = 3;
static const int FIELD___inRangeThresholdInDBm = 1;
static const int FIELD___outOfRangeThresholdInDBm = 2;
static const int FIELD___outOfRangeTimeout = 3;
static const int FIELD___scanCheck = 4;
static const int FIELD___scanResults = 5;
static const int FIELD___scanResultsLock = 6;

//--//
};
Expand All @@ -787,9 +785,8 @@ struct Library_sys_dev_ble_native_nanoFramework_Device_Bluetooth_BluetoothLEAdve
static const int FIELD___scanningMode = 2;
static const int FIELD___advertisementFilter = 3;
static const int FIELD___signalStrengthFilter = 4;
static const int FIELD___scanResults = 5;
static const int FIELD__Received = 6;
static const int FIELD__Stopped = 7;
static const int FIELD__Received = 5;
static const int FIELD__Stopped = 6;

NANOCLR_NATIVE_DECLARE(NativeStartAdvertisementWatcher___VOID__I4);
NANOCLR_NATIVE_DECLARE(NativeStopAdvertisementWatcher___VOID);
Expand Down Expand Up @@ -820,8 +817,7 @@ struct Library_sys_dev_ble_native_nanoFramework_Device_Bluetooth_GenericAttribut
//--//
};

struct
Library_sys_dev_ble_native_nanoFramework_Device_Bluetooth_GenericAttributeProfile_GattReadClientCharacteristicConfigurationDescriptorResult
struct Library_sys_dev_ble_native_nanoFramework_Device_Bluetooth_GenericAttributeProfile_GattReadClientCharacteristicConfigurationDescriptorResult
{
static const int FIELD___config = 1;
static const int FIELD___protocolError = 2;
Expand All @@ -830,8 +826,7 @@ struct
//--//
};

struct
Library_sys_dev_ble_native_nanoFramework_Device_Bluetooth_GenericAttributeProfile_GattServiceProviderAdvertisingParameters
struct Library_sys_dev_ble_native_nanoFramework_Device_Bluetooth_GenericAttributeProfile_GattServiceProviderAdvertisingParameters
{
static const int FIELD___isDiscoverable = 1;
static const int FIELD___isConnectable = 2;
Expand Down Expand Up @@ -913,4 +908,6 @@ extern const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_nanoFramework_Device

#include "sys_ble.h"

// clang-format on

#endif //_SYS_DEV_BLE_NATIVE_H_
56 changes: 0 additions & 56 deletions targets/FreeRTOS/_common/platform_heap.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,59 +15,3 @@ void platform_free(void *ptr)
{
vPortFree(ptr);
}

typedef struct A_BLOCK_LINK
{
struct A_BLOCK_LINK *pxNextFreeBlock; /*<< The next free block in the list. */
size_t xBlockSize; /*<< The size of the free block. */
} BlockLink_t;

#define heapBITS_PER_BYTE ((size_t)8)
static const size_t xHeapStructSize =
(sizeof(BlockLink_t) + ((size_t)(portBYTE_ALIGNMENT - 1))) & ~((size_t)portBYTE_ALIGNMENT_MASK);
static size_t xBlockAllocatedBit = ((size_t)1) << ((sizeof(size_t) * heapBITS_PER_BYTE) - 1);

static size_t mem_size(void *pv)
{
uint8_t *puc = (uint8_t *)pv;
BlockLink_t *pxLink;

if (pv != NULL)
{
/* The memory being freed will have an BlockLink_t structure immediately
before it. */
puc -= xHeapStructSize;

/* This casting is to keep the compiler from issuing warnings. */
pxLink = (void *)puc;

return pxLink->xBlockSize & ~xBlockAllocatedBit;
}

return 0;
}

void *platform_realloc(void *ptr, size_t size)
{
void *newPtr;
size_t curSize;

if (ptr == 0)
{
return pvPortMalloc(size);
}

curSize = mem_size(ptr);

if (size <= curSize)
{
return ptr;
}

newPtr = pvPortMalloc(size);

memcpy(ptr, newPtr, size);

vPortFree(ptr);
return newPtr;
}
12 changes: 0 additions & 12 deletions targets/TI_SimpleLink/_common/platform_heap.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,3 @@ void platform_free(void *ptr)
// define back
#define malloc YOU_SHALL_NOT_USE_free
}

void *platform_realloc(void *ptr, size_t size)
{

// need to undef in order to call the real function
#undef realloc

return realloc(ptr, size);

// define back
#define realloc YOU_SHALL_NOT_USE_realloc
}
12 changes: 0 additions & 12 deletions targets/win32/nanoCLR/platform_heap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,3 @@ void platform_free(void *ptr)
// define back
#define free YOU_SHALL_NOT_USE_free
}

void *platform_realloc(void *ptr, size_t size)
{

// need to undef in order to call the real function
#undef realloc

return realloc(ptr, size);

// define back
#define realloc YOU_SHALL_NOT_USE_realloc
}

0 comments on commit 30000ae

Please sign in to comment.