zephyr/drivers/flash/flash_page_layout.c
Patrik Flykt 4344e27c26 all: Update reserved function names
Update reserved function names starting with one underscore, replacing
them as follows:
   '_k_' with 'z_'
   '_K_' with 'Z_'
   '_handler_' with 'z_handl_'
   '_Cstart' with 'z_cstart'
   '_Swap' with 'z_swap'

This renaming is done on both global and those static function names
in kernel/include and include/. Other static function names in kernel/
are renamed by removing the leading underscore. Other function names
not starting with any prefix listed above are renamed starting with
a 'z_' or 'Z_' prefix.

Function names starting with two or three leading underscores are not
automatcally renamed since these names will collide with the variants
with two or three leading underscores.

Various generator scripts have also been updated as well as perf,
linker and usb files. These are
   drivers/serial/uart_handlers.c
   include/linker/kobject-text.ld
   kernel/include/syscall_handler.h
   scripts/gen_kobject_list.py
   scripts/gen_syscall_header.py

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-03-11 13:48:42 -04:00

111 lines
2.4 KiB
C

/*
* Copyright (c) 2017 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <flash.h>
static int _flash_get_page_info(struct device *dev, off_t offs,
bool use_addr, struct flash_pages_info *info)
{
const struct flash_driver_api *api = dev->driver_api;
const struct flash_pages_layout *layout;
size_t page_count = 0;
off_t group_offs = 0;
u32_t num_in_group;
off_t end = 0;
size_t layout_size;
api->page_layout(dev, &layout, &layout_size);
while (layout_size--) {
if (use_addr) {
end += layout->pages_count * layout->pages_size;
} else {
end += layout->pages_count;
}
if (offs < end) {
info->size = layout->pages_size;
if (use_addr) {
num_in_group = (offs - group_offs) /
layout->pages_size;
} else {
num_in_group = offs - page_count;
}
info->start_offset = group_offs +
num_in_group * layout->pages_size;
info->index = page_count + num_in_group;
return 0;
}
group_offs += layout->pages_count * layout->pages_size;
page_count += layout->pages_count;
layout++;
}
return -EINVAL; /* page of the index doesn't exist */
}
int z_impl_flash_get_page_info_by_offs(struct device *dev, off_t offs,
struct flash_pages_info *info)
{
return _flash_get_page_info(dev, offs, true, info);
}
int z_impl_flash_get_page_info_by_idx(struct device *dev, u32_t page_index,
struct flash_pages_info *info)
{
return _flash_get_page_info(dev, page_index, false, info);
}
size_t z_impl_flash_get_page_count(struct device *dev)
{
const struct flash_driver_api *api = dev->driver_api;
const struct flash_pages_layout *layout;
size_t layout_size;
size_t count = 0;
api->page_layout(dev, &layout, &layout_size);
while (layout_size--) {
count += layout->pages_count;
layout++;
}
return count;
}
void flash_page_foreach(struct device *dev, flash_page_cb cb, void *data)
{
const struct flash_driver_api *api = dev->driver_api;
const struct flash_pages_layout *layout;
struct flash_pages_info page_info;
size_t block, num_blocks, page = 0, i;
off_t off = 0;
api->page_layout(dev, &layout, &num_blocks);
for (block = 0; block < num_blocks; block++) {
const struct flash_pages_layout *l = &layout[block];
page_info.size = l->pages_size;
for (i = 0; i < l->pages_count; i++) {
page_info.start_offset = off;
page_info.index = page;
if (!cb(&page_info, data)) {
return;
}
off += page_info.size;
page++;
}
}
}