Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
MaJerle committed Dec 19, 2021
2 parents f6a07f2 + 2645a66 commit d005587
Show file tree
Hide file tree
Showing 32 changed files with 108 additions and 104 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"configurations": [
{
"name": "(Windows) Launch",
"type": "cppvsdbg",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}\\build\\LwLibPROJECT.exe",
"miDebuggerPath": "c:\\msys64\\mingw64\\bin\\gdb.exe",
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## Develop

## v2.0.0

- Remove `len` parameter for regions definition. Affected functions: `lwmem_assignmem` and `lwmem_assignmem_ex`
- Create separate branch for v1.x, for critical maintenance purpose only

## v1.6.0

- Add option to define regions with array only, setting length to `0` by default
Expand Down
1 change: 0 additions & 1 deletion dev/VisualStudio/lwmem_opts.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
* This file is part of Lightweight dynamic memory manager library.
*
* Author: Tilen MAJERLE <tilen@majerle.eu>
* Version: v1.6.0
*/
#ifndef LWMEM_HDR_OPTS_H
#define LWMEM_HDR_OPTS_H
Expand Down
2 changes: 1 addition & 1 deletion docs/examples_src/example_minimal.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ lwmem_region_t regions[] = {

/* Later in the initialization process */
/* Assign regions for manager */
lwmem_assignmem(regions, 0);
lwmem_assignmem(regions);

/* Usage in program... */

Expand Down
2 changes: 1 addition & 1 deletion docs/examples_src/example_realloc_enlarge_full.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ main(void) {
printf("Cannot allocate memory for regions for debug purpose!\r\n");
return -1;
}
lwmem_assignmem(regions_used, regions_count);
lwmem_assignmem(regions_used);
printf("Manager is ready!\r\n");
lwmem_debug_print(1, 1);

Expand Down
5 changes: 3 additions & 2 deletions docs/examples_src/example_realloc_region.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ static unsigned char region_mem[128];
static
lwmem_region_t regions[] = {
/* Set start address and size of each region */
{ region_mem, sizeof(region_mem) }
{ region_mem, sizeof(region_mem) },
{ NULL, 0 }
};

/* Later in the initialization process */
/* Assign regions for manager */
lwmem_assignmem(regions, sizeof(regions) / sizeof(regions[0]));
lwmem_assignmem(regions);
lwmem_debug_free(); /* This is debug function for sake of this example */
9 changes: 2 additions & 7 deletions docs/examples_src/example_regions_definitions.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#include "lwmem/lwmem.h"

/* Set to 1 to describe regions only with array */
#define DESCRIBE_REGIONS_WITH_ARRAY_ONLY 1

/*
* \brief Define regions for memory manager
*/
Expand All @@ -12,13 +9,11 @@ lwmem_region_t regions[] = {
{ (void *)0x10000000, 0x00001000 },
{ (void *)0xA0000000, 0x00008000 },
{ (void *)0xC0000000, 0x00008000 },
#if DESCRIBE_REGIONS_WITH_ARRAY_ONLY
{ NULL, 0},
#endif
};

/* Later in the initialization process */
/* Assign regions for manager */
lwmem_assignmem(regions, DESCRIBE_REGIONS_WITH_ARRAY_ONLY ? 0 : (sizeof(regions) / sizeof(regions[0])));
lwmem_assignmem(regions);
/* or */
lwmem_assignmem_ex(NULL, regions, DESCRIBE_REGIONS_WITH_ARRAY_ONLY ? 0 : (sizeof(regions) / sizeof(regions[0])));
lwmem_assignmem_ex(NULL, regions);
3 changes: 2 additions & 1 deletion docs/examples_src/example_regions_definitions_custom.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ lwmem_region_t regions[] = {
{ (void *)0x10000000, 0x00001000 },
{ (void *)0xA0000000, 0x00008000 },
{ (void *)0xC0000000, 0x00008000 },
{ NULL, 0 }
};

/* Later in the initialization process */
/* Assign regions for custom instance */
lwmem_assignmem_ex(&lw_custom, regions, sizeof(regions) / sizeof(regions[0]));
lwmem_assignmem_ex(&lw_custom, regions);
7 changes: 2 additions & 5 deletions docs/user-manual/how-it-works.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ For the sake of this understanding, application is using ``3`` regions
* Region ``1`` memory starts at ``0x1000 0000`` and is ``0x0000 1000`` bytes long
* Region ``2`` memory starts at ``0xA000 0000`` and is ``0x0000 8000`` bytes long
* Region ``3`` memory starts at ``0xC000 0000`` and is ``0x0000 8000`` bytes long
* Entry ``4`` indicates end of regions array descriptor

.. note::
Total size of memory used by application for memory manager is ``0x0001 1000`` bytes or ``69 kB``.
This is a sum of all ``3`` regions.
Last entry indicates end of regions with start address set as ``NULL`` and size as ``0``

Example also assumes that:

Expand All @@ -36,11 +38,6 @@ First step is to define custom regions and assign them to memory manager.
.. note::
Order of regions must be lower address first. Regions must not overlap with their sizes.

.. tip::
Regions could be defined with array descriptor only, where last entry must be set to `NULL` address and `0` size.
This is useful for dynamic length definition with single descriptor file/address.
It allows application to define regions by setting linker scripts when compiling the code.

When calling :c:macro:`lwmem_assignmem`, manager prepares memory blocks and assigns default values.

.. figure:: ../static/images/structure_default.svg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
* This file is part of LwMEM - Lightweight dynamic memory manager library.
*
* Author: Tilen MAJERLE <tilen@majerle.eu>
* Version: v1.6.0
*/
#ifndef LWMEM_HDR_OPTS_H
#define LWMEM_HDR_OPTS_H
Expand Down
1 change: 0 additions & 1 deletion examples/stm32/lwmem_rtos_stm32l496_discovery/inc/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
* OTHER DEALINGS IN THE SOFTWARE.
*
* Author: Tilen MAJERLE <tilen@majerle.eu>
* Version: v1.6.0
*/
#ifndef __MAIN_H
#define __MAIN_H
Expand Down
4 changes: 2 additions & 2 deletions examples/stm32/lwmem_rtos_stm32l496_discovery/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
* OTHER DEALINGS IN THE SOFTWARE.
*
* Author: Tilen MAJERLE <tilen@majerle.eu>
* Version: v1.6.0
*/
#include "main.h"
#include "cmsis_os.h"
Expand All @@ -49,6 +48,7 @@ static lwmem_region_t
regions[] = {
{ region1_data, sizeof(region1_data) },
/* Add more regions if needed */
{ NULL, 0 }
};

static void app_thread(void* arg);
Expand All @@ -68,7 +68,7 @@ main(void) {

/* Initialize LwMEM */
printf("Initializing LwMEM...\r\n");
if (!lwmem_assignmem(regions, sizeof(regions) / sizeof(regions[0]))) {
if (!lwmem_assignmem(regions)) {
printf("Cannot initialize LwMEM. Make sure your regions are not overlapping each other and are in ascending memory order\r\n");
while (1) {}
} else {
Expand Down
1 change: 0 additions & 1 deletion examples/stm32/lwmem_stm32l496_discovery/inc/lwmem_opts.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
* This file is part of LwMEM - Lightweight dynamic memory manager library.
*
* Author: Tilen MAJERLE <tilen@majerle.eu>
* Version: v1.6.0
*/
#ifndef LWMEM_HDR_OPTS_H
#define LWMEM_HDR_OPTS_H
Expand Down
1 change: 0 additions & 1 deletion examples/stm32/lwmem_stm32l496_discovery/inc/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
* OTHER DEALINGS IN THE SOFTWARE.
*
* Author: Tilen MAJERLE <tilen@majerle.eu>
* Version: v1.6.0
*/
#ifndef __MAIN_H
#define __MAIN_H
Expand Down
4 changes: 2 additions & 2 deletions examples/stm32/lwmem_stm32l496_discovery/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
* OTHER DEALINGS IN THE SOFTWARE.
*
* Author: Tilen MAJERLE <tilen@majerle.eu>
* Version: v1.6.0
*/
#include "main.h"
#include "lwmem/lwmem.h"
Expand All @@ -48,6 +47,7 @@ static lwmem_region_t
regions[] = {
{ region1_data, sizeof(region1_data) },
/* Add more regions if needed */
{ NULL, 0 }
};

/**
Expand All @@ -65,7 +65,7 @@ main(void) {

/* Initialize LwMEM */
printf("Initializing LwMEM...\r\n");
if (!lwmem_assignmem(regions, sizeof(regions) / sizeof(regions[0]))) {
if (!lwmem_assignmem(regions)) {
printf("Cannot initialize LwMEM. Make sure your regions are not overlapping each other and are in ascending memory order\r\n");
while (1) {}
} else {
Expand Down
1 change: 0 additions & 1 deletion examples/win32/lwmem/lwmem_opts.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
* This file is part of LwMEM - Lightweight dynamic memory manager library.
*
* Author: Tilen MAJERLE <tilen@majerle.eu>
* Version: v1.6.0
*/
#ifndef LWMEM_HDR_OPTS_H
#define LWMEM_HDR_OPTS_H
Expand Down
8 changes: 4 additions & 4 deletions examples/win32/lwmem/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@

/* Define single region */
uint8_t region_data[1024];
lwmem_region_t region = {
.start_addr = region_data,
.size = sizeof(region_data)
lwmem_region_t regions[] = {
{ .start_addr = region_data, .size = sizeof(region_data) },
{ .start_addr = NULL, .size = 0 }
};

int
main(void) {
void* ptr, *ptr2;

/* Initialize default LwMEM instance with single region */
if (!lwmem_assignmem(&region, 1)) {
if (!lwmem_assignmem(regions)) {
printf("Could not initialize LwMEM!");
return -1;
}
Expand Down
1 change: 0 additions & 1 deletion examples/win32/lwmem_multi_ins_multi_region/lwmem_opts.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
* This file is part of LwMEM - Lightweight dynamic memory manager library.
*
* Author: Tilen MAJERLE <tilen@majerle.eu>
* Version: v1.6.0
*/
#ifndef LWMEM_HDR_OPTS_H
#define LWMEM_HDR_OPTS_H
Expand Down
13 changes: 8 additions & 5 deletions examples/win32/lwmem_multi_ins_multi_region/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,25 @@

#include "lwmem/lwmem.h"
#include <stdio.h>
#include <string.h>

/* Define multiple regions for default instance */
uint8_t lw0_region1_data[1024];
uint8_t lw0_region2_data[256];
lwmem_region_t lw0_regions[] = {
{ .start_addr = lw0_region1_data, .size = sizeof(lw0_region1_data) },
{ .start_addr = lw0_region2_data, .size = sizeof(lw0_region2_data) }
{ .start_addr = lw0_region2_data, .size = sizeof(lw0_region2_data) },
{ .start_addr = NULL, .size = 0 },
};

/* Define second LwMEM instance and multiple regions for new instance */
lwmem_t lw1;
uint8_t lw1_region1_data[1024];
uint8_t lw1_region2_data[512];
lwmem_region_t lw1_regions[] = {
{.start_addr = lw1_region1_data, .size = sizeof(lw1_region1_data) },
{.start_addr = lw1_region2_data, .size = sizeof(lw1_region2_data) }
{ .start_addr = lw1_region1_data, .size = sizeof(lw1_region1_data) },
{ .start_addr = lw1_region2_data, .size = sizeof(lw1_region2_data) },
{ .start_addr = NULL, .size = 0 },
};

int
Expand All @@ -45,14 +48,14 @@ main(void) {
}

/* Initialize default LwMEM instance with single region */
if (!lwmem_assignmem(lw0_regions, LWMEM_ARRAYSIZE(lw0_regions))) {
if (!lwmem_assignmem(lw0_regions)) {
printf("Could not initialize default LwMEM instance!");
return -1;
}
printf("Default LwMEM instance initialized and ready to use!\r\n");

/* Initialize custom LwMEM instance with its custom regions */
if (!lwmem_assignmem_ex(&lw1, lw1_regions, LWMEM_ARRAYSIZE(lw1_regions))) {
if (!lwmem_assignmem_ex(&lw1, lw1_regions)) {
printf("Could not initialize custom LwMEM instance!");
return -1;
}
Expand Down
1 change: 0 additions & 1 deletion examples/win32/lwmem_multi_region/lwmem_opts.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
* This file is part of LwMEM - Lightweight dynamic memory manager library.
*
* Author: Tilen MAJERLE <tilen@majerle.eu>
* Version: v1.6.0
*/
#ifndef LWMEM_HDR_OPTS_H
#define LWMEM_HDR_OPTS_H
Expand Down
6 changes: 4 additions & 2 deletions examples/win32/lwmem_multi_region/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@

#include "lwmem/lwmem.h"
#include <stdio.h>
#include <string.h>

/* Define multiple regions */
uint8_t region1_data[1024];
uint8_t region2_data[256];
lwmem_region_t regions[] = {
{ .start_addr = region1_data, .size = sizeof(region1_data) },
{ .start_addr = region2_data, .size = sizeof(region2_data) }
{ .start_addr = region2_data, .size = sizeof(region2_data) },
{ .start_addr = NULL, .size = 0 },
};

int
Expand All @@ -28,7 +30,7 @@ main(void) {
}

/* Initialize default LwMEM instance with single region */
if (!lwmem_assignmem(regions, LWMEM_ARRAYSIZE(regions))) {
if (!lwmem_assignmem(regions)) {
printf("Could not initialize LwMEM!");
return -1;
}
Expand Down
1 change: 0 additions & 1 deletion examples/win32/lwmem_os/lwmem_opts.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
* This file is part of LwMEM - Lightweight dynamic memory manager library.
*
* Author: Tilen MAJERLE <tilen@majerle.eu>
* Version: v1.6.0
*/
#ifndef LWMEM_HDR_OPTS_H
#define LWMEM_HDR_OPTS_H
Expand Down
8 changes: 4 additions & 4 deletions examples/win32/lwmem_os/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

/* Define single region */
uint8_t region_data[1024];
lwmem_region_t region = {
.start_addr = region_data,
.size = sizeof(region_data)
lwmem_region_t regions[] = {
{ .start_addr = region_data, .size = sizeof(region_data) },
{ .start_addr = NULL, .size = 0 },
};

/* Thread declaration */
Expand All @@ -21,7 +21,7 @@ static int thread_func(void* arg);
int
main(void) {
/* Initialize default LwMEM instance with single region */
if (!lwmem_assignmem(&region, 1)) {
if (!lwmem_assignmem(regions)) {
printf("Could not initialize LwMEM!");
return -1;
}
Expand Down
6 changes: 4 additions & 2 deletions library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "LwMEM",
"version": "1.6.0",
"version": "2.0.0",
"description": "Lightweight dynamic memory manager optimized for embedded systems",
"keywords": "lwmem, memory, dynamic, heap, malloc, calloc, realloc, free, lightweight, manager, embedded, stm32, win32",
"repository": {
Expand All @@ -23,10 +23,12 @@
"platforms": "*",
"export": {
"exclude": [
".github",
"dev"
"docs",
"**/.vs",
"**/Debug",
"third_party/embedded-libs/st_hal/CMSIS/Lib/ARM"
"build",
]
}
}
Loading

0 comments on commit d005587

Please sign in to comment.