Lines Matching refs:offset
55 static bool sam_flash_validate_offset_len(off_t offset, size_t len) in sam_flash_validate_offset_len() argument
57 if (offset < 0) { in sam_flash_validate_offset_len()
61 if ((offset + len) < len) { in sam_flash_validate_offset_len()
73 static bool sam_flash_offset_is_on_write_page_boundary(off_t offset) in sam_flash_offset_is_on_write_page_boundary() argument
75 return sam_flash_aligned(offset, SAM_FLASH_WRITE_PAGE_SIZE); in sam_flash_offset_is_on_write_page_boundary()
137 static bool sam_flash_section_is_within_area(const struct device *dev, off_t offset, size_t len) in sam_flash_section_is_within_area() argument
141 if ((offset + ((off_t)len)) < offset) { in sam_flash_section_is_within_area()
145 if ((offset >= 0) && ((offset + len) <= config->area_size)) { in sam_flash_section_is_within_area()
150 (size_t)offset, (size_t)(offset + len), (size_t)config->area_size); in sam_flash_section_is_within_area()
156 off_t offset, size_t len) in sam_flash_section_is_aligned_with_write_block_size() argument
160 if (sam_flash_aligned(offset, config->parameters.write_block_size) && in sam_flash_section_is_aligned_with_write_block_size()
166 (size_t)offset, (size_t)(offset + len), config->parameters.write_block_size); in sam_flash_section_is_aligned_with_write_block_size()
171 static bool sam_flash_section_is_aligned_with_pages(const struct device *dev, off_t offset, in sam_flash_section_is_aligned_with_pages() argument
178 if (flash_get_page_info_by_offs(dev, offset, &pages_info) < 0) { in sam_flash_section_is_aligned_with_pages()
183 if (offset != pages_info.start_offset) { in sam_flash_section_is_aligned_with_pages()
188 if ((offset + len) == (config->area_size)) { in sam_flash_section_is_aligned_with_pages()
193 if (flash_get_page_info_by_offs(dev, offset + len, &pages_info) < 0) { in sam_flash_section_is_aligned_with_pages()
198 if ((offset + len) != pages_info.start_offset) { in sam_flash_section_is_aligned_with_pages()
205 static int sam_flash_read(const struct device *dev, off_t offset, void *data, size_t len) in sam_flash_read() argument
215 if (!sam_flash_validate_offset_len(offset, len)) { in sam_flash_read()
219 if (!sam_flash_section_is_within_area(dev, offset, len)) { in sam_flash_read()
224 memcpy(data, (uint8_t *)(sam_config->area_address + offset), len); in sam_flash_read()
229 static int sam_flash_write_latch_buffer_to_page(const struct device *dev, off_t offset) in sam_flash_write_latch_buffer_to_page() argument
233 uint32_t page = offset / SAM_FLASH_WRITE_PAGE_SIZE; in sam_flash_write_latch_buffer_to_page()
240 static int sam_flash_write_latch_buffer_to_previous_page(const struct device *dev, off_t offset) in sam_flash_write_latch_buffer_to_previous_page() argument
242 return sam_flash_write_latch_buffer_to_page(dev, offset - SAM_FLASH_WRITE_PAGE_SIZE); in sam_flash_write_latch_buffer_to_previous_page()
245 static void sam_flash_write_dword_to_latch_buffer(off_t offset, uint32_t dword) in sam_flash_write_dword_to_latch_buffer() argument
247 *((uint32_t *)offset) = dword; in sam_flash_write_dword_to_latch_buffer()
251 static int sam_flash_write_dwords_to_flash(const struct device *dev, off_t offset, in sam_flash_write_dwords_to_flash() argument
255 sam_flash_write_dword_to_latch_buffer(offset, dwords[i]); in sam_flash_write_dwords_to_flash()
256 offset += sizeof(uint32_t); in sam_flash_write_dwords_to_flash()
257 if (sam_flash_offset_is_on_write_page_boundary(offset)) { in sam_flash_write_dwords_to_flash()
258 sam_flash_write_latch_buffer_to_previous_page(dev, offset); in sam_flash_write_dwords_to_flash()
262 if (!sam_flash_offset_is_on_write_page_boundary(offset)) { in sam_flash_write_dwords_to_flash()
263 sam_flash_write_latch_buffer_to_page(dev, offset); in sam_flash_write_dwords_to_flash()
269 static int sam_flash_write(const struct device *dev, off_t offset, const void *data, size_t len) in sam_flash_write() argument
278 if (!sam_flash_validate_offset_len(offset, len)) { in sam_flash_write()
282 if (!sam_flash_section_is_aligned_with_write_block_size(dev, offset, len)) { in sam_flash_write()
286 LOG_DBG("Writing sector from 0x%x to 0x%x", (size_t)offset, (size_t)(offset + len)); in sam_flash_write()
289 if (sam_flash_write_dwords_to_flash(dev, offset, data, len / sizeof(uint32_t)) < 0) { in sam_flash_write()
417 static int sam_flash_erase(const struct device *dev, off_t offset, size_t size) in sam_flash_erase() argument
426 if (!sam_flash_validate_offset_len(offset, size)) { in sam_flash_erase()
430 if (!sam_flash_section_is_aligned_with_pages(dev, offset, size)) { in sam_flash_erase()
434 LOG_DBG("Erasing sector from 0x%x to 0x%x", (size_t)offset, (size_t)(offset + size)); in sam_flash_erase()
437 sam_data->erase_data.section_start = offset; in sam_flash_erase()
438 sam_data->erase_data.section_end = offset + size; in sam_flash_erase()