mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2024-10-05 22:29:49 +00:00
Move alignment related #defines from mem.h to a better place: arch.h.
mem.h should only describe heap API, not architecture/port specific alignment helper macros.
This commit is contained in:
parent
b91e47b518
commit
98e92f6550
@ -124,6 +124,29 @@ typedef uintptr_t mem_ptr_t;
|
|||||||
#define LWIP_DECLARE_MEMORY_ALIGNED(variable_name, size) u8_t variable_name[LWIP_MEM_ALIGN_BUFFER(size)]
|
#define LWIP_DECLARE_MEMORY_ALIGNED(variable_name, size) u8_t variable_name[LWIP_MEM_ALIGN_BUFFER(size)]
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/** Calculate memory size for an aligned buffer - returns the next highest
|
||||||
|
* multiple of MEM_ALIGNMENT (e.g. LWIP_MEM_ALIGN_SIZE(3) and
|
||||||
|
* LWIP_MEM_ALIGN_SIZE(4) will both yield 4 for MEM_ALIGNMENT == 4).
|
||||||
|
*/
|
||||||
|
#ifndef LWIP_MEM_ALIGN_SIZE
|
||||||
|
#define LWIP_MEM_ALIGN_SIZE(size) (((size) + MEM_ALIGNMENT - 1U) & ~(MEM_ALIGNMENT-1U))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/** Calculate safe memory size for an aligned buffer when using an unaligned
|
||||||
|
* type as storage. This includes a safety-margin on (MEM_ALIGNMENT - 1) at the
|
||||||
|
* start (e.g. if buffer is u8_t[] and actual data will be u32_t*)
|
||||||
|
*/
|
||||||
|
#ifndef LWIP_MEM_ALIGN_BUFFER
|
||||||
|
#define LWIP_MEM_ALIGN_BUFFER(size) (((size) + MEM_ALIGNMENT - 1U))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/** Align a memory pointer to the alignment defined by MEM_ALIGNMENT
|
||||||
|
* so that ADDR % MEM_ALIGNMENT == 0
|
||||||
|
*/
|
||||||
|
#ifndef LWIP_MEM_ALIGN
|
||||||
|
#define LWIP_MEM_ALIGN(addr) ((void *)(((mem_ptr_t)(addr) + MEM_ALIGNMENT - 1) & ~(mem_ptr_t)(MEM_ALIGNMENT-1)))
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
@ -98,29 +98,6 @@ void *mem_calloc(mem_size_t count, mem_size_t size);
|
|||||||
void mem_free(void *mem);
|
void mem_free(void *mem);
|
||||||
#endif /* MEM_LIBC_MALLOC */
|
#endif /* MEM_LIBC_MALLOC */
|
||||||
|
|
||||||
/** Calculate memory size for an aligned buffer - returns the next highest
|
|
||||||
* multiple of MEM_ALIGNMENT (e.g. LWIP_MEM_ALIGN_SIZE(3) and
|
|
||||||
* LWIP_MEM_ALIGN_SIZE(4) will both yield 4 for MEM_ALIGNMENT == 4).
|
|
||||||
*/
|
|
||||||
#ifndef LWIP_MEM_ALIGN_SIZE
|
|
||||||
#define LWIP_MEM_ALIGN_SIZE(size) (((size) + MEM_ALIGNMENT - 1U) & ~(MEM_ALIGNMENT-1U))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/** Calculate safe memory size for an aligned buffer when using an unaligned
|
|
||||||
* type as storage. This includes a safety-margin on (MEM_ALIGNMENT - 1) at the
|
|
||||||
* start (e.g. if buffer is u8_t[] and actual data will be u32_t*)
|
|
||||||
*/
|
|
||||||
#ifndef LWIP_MEM_ALIGN_BUFFER
|
|
||||||
#define LWIP_MEM_ALIGN_BUFFER(size) (((size) + MEM_ALIGNMENT - 1U))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/** Align a memory pointer to the alignment defined by MEM_ALIGNMENT
|
|
||||||
* so that ADDR % MEM_ALIGNMENT == 0
|
|
||||||
*/
|
|
||||||
#ifndef LWIP_MEM_ALIGN
|
|
||||||
#define LWIP_MEM_ALIGN(addr) ((void *)(((mem_ptr_t)(addr) + MEM_ALIGNMENT - 1) & ~(mem_ptr_t)(MEM_ALIGNMENT-1)))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user