helper/align.h: use it

Use the new helper to make the code more readable.

Change-Id: I11b2a79dbc6f93f6cfde382bcc00dd7ff710d908
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/6375
Tested-by: jenkins
Reviewed-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
This commit is contained in:
Antonio Borneo
2021-05-14 00:48:31 +02:00
parent 9544cd653d
commit 08a0cfdeeb
4 changed files with 12 additions and 8 deletions

View File

@@ -24,6 +24,7 @@
#endif
#include "imp.h"
#include <helper/align.h>
#include <helper/binarybuffer.h>
#include <target/algorithm.h>
#include <target/armv7m.h>
@@ -1591,7 +1592,7 @@ static int stm32l4_probe(struct flash_bank *bank)
* max_flash_size is always power of two, so max_pages too
*/
uint32_t max_pages = stm32l4_info->part_info->max_flash_size_kb / page_size_kb;
assert((max_pages & (max_pages - 1)) == 0);
assert(IS_PWR_OF_2(max_pages));
/* in dual bank mode number of pages is doubled, but extra bit is bank selection */
stm32l4_info->wrpxxr_mask = ((max_pages >> (stm32l4_info->dual_bank_mode ? 1 : 0)) - 1);

View File

@@ -11,6 +11,7 @@
#endif
#include "imp.h"
#include <helper/align.h>
#include <helper/binarybuffer.h>
#include <target/algorithm.h>
#include <target/armv7m.h>
@@ -256,12 +257,12 @@ static int xmc1xxx_write(struct flash_bank *bank, const uint8_t *buffer,
LOG_DEBUG("Infineon XMC1000 write at 0x%08" PRIx32 " (%" PRIu32 " bytes)",
offset, byte_count);
if (offset & (NVM_BLOCK_SIZE - 1)) {
if (!IS_ALIGNED(offset, NVM_BLOCK_SIZE)) {
LOG_ERROR("offset 0x%" PRIx32 " breaks required block alignment",
offset);
return ERROR_FLASH_DST_BREAKS_ALIGNMENT;
}
if (byte_count & (NVM_BLOCK_SIZE - 1)) {
if (!IS_ALIGNED(byte_count, NVM_BLOCK_SIZE)) {
LOG_WARNING("length %" PRIu32 " is not block aligned, rounding up",
byte_count);
}