2009-10-11 19:43:13 +00:00
|
|
|
/*
|
2016-03-18 10:29:35 +00:00
|
|
|
ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio.
|
2009-10-11 19:43:13 +00:00
|
|
|
|
2015-01-11 13:45:54 +00:00
|
|
|
This file is part of ChibiOS.
|
2009-10-11 19:43:13 +00:00
|
|
|
|
2015-01-11 13:45:54 +00:00
|
|
|
ChibiOS is free software; you can redistribute it and/or modify
|
2009-10-11 19:43:13 +00:00
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
2015-01-11 13:45:54 +00:00
|
|
|
ChibiOS is distributed in the hope that it will be useful,
|
2009-10-11 19:43:13 +00:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2016-02-16 10:07:00 +00:00
|
|
|
* @file chmem.h
|
|
|
|
* @brief Memory alignment macros and structures.
|
2010-02-06 12:31:09 +00:00
|
|
|
*
|
2016-02-16 10:07:00 +00:00
|
|
|
* @addtogroup mem
|
2009-10-11 19:43:13 +00:00
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2016-03-23 18:43:19 +00:00
|
|
|
#ifndef CHALIGN_H
|
|
|
|
#define CHALIGN_H
|
2013-07-19 14:51:35 +00:00
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Module constants. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Module pre-compile time settings. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Derived constants and error checks. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Module data structures and types. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Module macros. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2011-08-22 17:18:52 +00:00
|
|
|
/**
|
2016-02-16 10:07:00 +00:00
|
|
|
* @name Memory alignment support macros
|
2011-08-22 17:18:52 +00:00
|
|
|
*/
|
2011-02-24 14:57:38 +00:00
|
|
|
/**
|
2016-02-16 10:07:00 +00:00
|
|
|
* @brief Alignment mask constant.
|
|
|
|
*
|
|
|
|
* @param[in] a alignment, must be a power of two
|
2011-02-24 14:57:38 +00:00
|
|
|
*/
|
2016-02-16 10:07:00 +00:00
|
|
|
#define MEM_ALIGN_MASK(a) ((size_t)(a) - 1U)
|
2011-02-24 14:57:38 +00:00
|
|
|
|
2009-10-11 19:43:13 +00:00
|
|
|
/**
|
2016-02-16 10:07:00 +00:00
|
|
|
* @brief Aligns to the previous aligned memory address.
|
|
|
|
*
|
|
|
|
* @param[in] p variable to be aligned
|
|
|
|
* @param[in] a alignment, must be a power of two
|
2009-10-11 19:43:13 +00:00
|
|
|
*/
|
2016-04-03 09:27:34 +00:00
|
|
|
#define MEM_ALIGN_PREV(p, a) \
|
|
|
|
/*lint -save -e9033 [10.8] The cast is safe.*/ \
|
|
|
|
((size_t)(p) & ~MEM_ALIGN_MASK(a)) \
|
|
|
|
/*lint -restore*/
|
2011-02-24 14:57:38 +00:00
|
|
|
|
|
|
|
/**
|
2016-02-16 10:07:00 +00:00
|
|
|
* @brief Aligns to the new aligned memory address.
|
|
|
|
*
|
|
|
|
* @param[in] p variable to be aligned
|
|
|
|
* @param[in] a alignment, must be a power of two
|
2011-02-24 14:57:38 +00:00
|
|
|
*/
|
2016-04-03 09:27:34 +00:00
|
|
|
#define MEM_ALIGN_NEXT(p, a) \
|
|
|
|
/*lint -save -e9033 [10.8] The cast is safe.*/ \
|
|
|
|
MEM_ALIGN_PREV((size_t)(p) + MEM_ALIGN_MASK(a), (a)) \
|
|
|
|
/*lint -restore*/
|
2009-10-11 19:43:13 +00:00
|
|
|
|
|
|
|
/**
|
2016-02-16 10:07:00 +00:00
|
|
|
* @brief Returns whatever a pointer or memory size is aligned.
|
|
|
|
*
|
|
|
|
* @param[in] p variable to be aligned
|
|
|
|
* @param[in] a alignment, must be a power of two
|
2009-10-11 19:43:13 +00:00
|
|
|
*/
|
2016-02-16 10:07:00 +00:00
|
|
|
#define MEM_IS_ALIGNED(p, a) (((size_t)(p) & MEM_ALIGN_MASK(a)) == 0U)
|
2009-10-16 17:45:19 +00:00
|
|
|
|
|
|
|
/**
|
2016-02-16 10:07:00 +00:00
|
|
|
* @brief Returns whatever a constant is a valid alignment.
|
|
|
|
* @details Valid alignments are powers of two.
|
|
|
|
*
|
|
|
|
* @param[in] a alignment to be checked, must be a constant
|
2009-10-16 17:45:19 +00:00
|
|
|
*/
|
2016-02-16 10:07:00 +00:00
|
|
|
#define MEM_IS_VALID_ALIGNMENT(a) \
|
|
|
|
(((size_t)(a) != 0U) && (((size_t)(a) & ((size_t)(a) - 1U)) == 0U))
|
2011-08-22 17:18:52 +00:00
|
|
|
/** @} */
|
2009-10-11 19:43:13 +00:00
|
|
|
|
2013-07-19 14:51:35 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* External declarations. */
|
|
|
|
/*===========================================================================*/
|
2009-10-17 09:21:59 +00:00
|
|
|
|
2009-10-11 19:43:13 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
2016-02-16 10:07:00 +00:00
|
|
|
|
2009-10-11 19:43:13 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-07-19 14:51:35 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* Module inline functions. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2016-03-23 18:43:19 +00:00
|
|
|
#endif /* CHALIGN_H */
|
2009-10-11 19:43:13 +00:00
|
|
|
|
|
|
|
/** @} */
|