From c5a0c7a3ee1718f2c702317e7ec2f3890d5237a3 Mon Sep 17 00:00:00 2001 From: Martin Turon Date: Mon, 14 May 2018 17:50:20 -0700 Subject: [PATCH] porting: Add support for running on 64-bit architectures --- porting/nimble/include/os/os_mempool.h | 2 +- porting/nimble/src/os_mempool.c | 20 ++++++++++---------- porting/nimble/src/os_msys_init.c | 4 ++-- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/porting/nimble/include/os/os_mempool.h b/porting/nimble/include/os/os_mempool.h index ab1ddc511..db80d4e40 100644 --- a/porting/nimble/include/os/os_mempool.h +++ b/porting/nimble/include/os/os_mempool.h @@ -65,7 +65,7 @@ struct os_mempool { /** Bitmap of OS_MEMPOOL_F_[...] values. */ uint8_t mp_flags; /** Address of memory buffer used by pool */ - uint32_t mp_membuf_addr; + uintptr_t mp_membuf_addr; STAILQ_ENTRY(os_mempool) mp_list; SLIST_HEAD(,os_memblock); /** Name for memory block */ diff --git a/porting/nimble/src/os_mempool.c b/porting/nimble/src/os_mempool.c index d83697d3b..fa223a7aa 100644 --- a/porting/nimble/src/os_mempool.c +++ b/porting/nimble/src/os_mempool.c @@ -82,7 +82,7 @@ os_mempool_init(struct os_mempool *mp, uint16_t blocks, uint32_t block_size, /* Blocks need to be sized properly and memory buffer should be * aligned */ - if (((uint32_t)membuf & (OS_ALIGNMENT - 1)) != 0) { + if (((uintptr_t)membuf & (OS_ALIGNMENT - 1)) != 0) { return OS_MEM_NOT_ALIGNED; } } @@ -94,7 +94,7 @@ os_mempool_init(struct os_mempool *mp, uint16_t blocks, uint32_t block_size, mp->mp_min_free = blocks; mp->mp_flags = 0; mp->mp_num_blocks = blocks; - mp->mp_membuf_addr = (uint32_t)membuf; + mp->mp_membuf_addr = (uintptr_t)membuf; mp->name = name; os_mempool_poison(membuf, true_block_size); SLIST_FIRST(mp) = membuf; @@ -155,24 +155,24 @@ os_mempool_is_sane(const struct os_mempool *mp) int os_memblock_from(const struct os_mempool *mp, const void *block_addr) { - uint32_t true_block_size; - uint32_t baddr32; - uint32_t end; + uintptr_t true_block_size; + uintptr_t baddr_ptr; + uintptr_t end; - _Static_assert(sizeof block_addr == sizeof baddr32, - "Pointer to void must be 32-bits."); + _Static_assert(sizeof block_addr == sizeof baddr_ptr, + "Pointer to void must be native word size."); - baddr32 = (uint32_t)block_addr; + baddr_ptr = (uintptr_t)block_addr; true_block_size = OS_MEMPOOL_TRUE_BLOCK_SIZE(mp); end = mp->mp_membuf_addr + (mp->mp_num_blocks * true_block_size); /* Check that the block is in the memory buffer range. */ - if ((baddr32 < mp->mp_membuf_addr) || (baddr32 >= end)) { + if ((baddr_ptr < mp->mp_membuf_addr) || (baddr_ptr >= end)) { return 0; } /* All freed blocks should be on true block size boundaries! */ - if (((baddr32 - mp->mp_membuf_addr) % true_block_size) != 0) { + if (((baddr_ptr - mp->mp_membuf_addr) % true_block_size) != 0) { return 0; } diff --git a/porting/nimble/src/os_msys_init.c b/porting/nimble/src/os_msys_init.c index 1daa9bf9f..4d42d184a 100644 --- a/porting/nimble/src/os_msys_init.c +++ b/porting/nimble/src/os_msys_init.c @@ -23,7 +23,7 @@ #if MYNEWT_VAL(MSYS_1_BLOCK_COUNT) > 0 #define SYSINIT_MSYS_1_MEMBLOCK_SIZE \ - OS_ALIGN(MYNEWT_VAL(MSYS_1_BLOCK_SIZE), 4) + OS_ALIGN(MYNEWT_VAL(MSYS_1_BLOCK_SIZE), OS_ALIGNMENT) #define SYSINIT_MSYS_1_MEMPOOL_SIZE \ OS_MEMPOOL_SIZE(MYNEWT_VAL(MSYS_1_BLOCK_COUNT), \ SYSINIT_MSYS_1_MEMBLOCK_SIZE) @@ -34,7 +34,7 @@ static struct os_mempool os_msys_init_1_mempool; #if MYNEWT_VAL(MSYS_2_BLOCK_COUNT) > 0 #define SYSINIT_MSYS_2_MEMBLOCK_SIZE \ - OS_ALIGN(MYNEWT_VAL(MSYS_2_BLOCK_SIZE), 4) + OS_ALIGN(MYNEWT_VAL(MSYS_2_BLOCK_SIZE), OS_ALIGNMENT) #define SYSINIT_MSYS_2_MEMPOOL_SIZE \ OS_MEMPOOL_SIZE(MYNEWT_VAL(MSYS_2_BLOCK_COUNT), \ SYSINIT_MSYS_2_MEMBLOCK_SIZE)