px-fwlib 0.10.0
Cross-platform embedded library and documentation for 8/16/32-bit microcontrollers generated with Doxygen 1.9.2
px_log_fs_glue_at25s.c
1/* =============================================================================
2 ____ ___ ____ ___ _ _ ___ __ __ ___ __ __ TM
3 | _ \ |_ _| / ___| / _ \ | \ | | / _ \ | \/ | |_ _| \ \/ /
4 | |_) | | | | | | | | | | \| | | | | | | |\/| | | | \ /
5 | __/ | | | |___ | |_| | | |\ | | |_| | | | | | | | / \
6 |_| |___| \____| \___/ |_| \_| \___/ |_| |_| |___| /_/\_\
7
8 Copyright (c) 2019 Pieter Conradie <https://piconomix.com>
9
10 License: MIT
11 https://github.com/piconomix/px-fwlib/blob/master/LICENSE.md
12
13 Title: px_log_fs_glue.h : Physical device glue layer for Log FS
14 Author(s): Pieter Conradie
15 Creation Date: 2019-01-11
16
17============================================================================= */
18
19/* _____STANDARD INCLUDES____________________________________________________ */
20
21/* _____PROJECT INCLUDES_____________________________________________________ */
22#include "px_log_fs_glue.h"
23#include "px_log_fs_cfg.h"
24#include "px_at25s.h"
25#include "px_log.h"
26
27/* _____LOCAL DEFINITIONS____________________________________________________ */
28PX_LOG_NAME("px_log_fs_glue");
29
30/* _____MACROS_______________________________________________________________ */
31
32/* _____GLOBAL VARIABLES_____________________________________________________ */
33
34/* _____LOCAL VARIABLES______________________________________________________ */
35
36/* _____LOCAL FUNCTION DECLARATIONS__________________________________________ */
37
38/* _____LOCAL FUNCTIONS______________________________________________________ */
39
40/* _____GLOBAL FUNCTIONS_____________________________________________________ */
41void px_log_fs_glue_rd(void * buf,
42 uint16_t page,
43 uint16_t start_byte_in_page,
44 uint16_t nr_of_bytes)
45{
46 // Sanity checks
47 PX_LOG_ASSERT(start_byte_in_page < PX_LOG_FS_CFG_PAGE_SIZE);
48 PX_LOG_ASSERT(nr_of_bytes <= (PX_LOG_FS_CFG_PAGE_SIZE - start_byte_in_page));
49
50 // Read data from Serial Flash
51 px_at25s_rd_page_offset(buf, page, start_byte_in_page, nr_of_bytes);
52}
53
54void px_log_fs_glue_wr(const void * buf,
55 uint16_t page,
56 uint16_t start_byte_in_page,
57 uint16_t nr_of_bytes)
58{
59 // Sanity checks
60 PX_LOG_ASSERT(start_byte_in_page < PX_LOG_FS_CFG_PAGE_SIZE);
61 PX_LOG_ASSERT(nr_of_bytes <= (PX_LOG_FS_CFG_PAGE_SIZE - start_byte_in_page));
62
63 // Write data to Serial Flash
64 px_at25s_wr_page_offset(buf, page, start_byte_in_page, nr_of_bytes);
65}
66
67void px_log_fs_glue_erase_block(uint16_t page)
68{
69 // Sanity checks
71
72#if (PX_LOG_FS_CFG_ERASE_BLOCK_SIZE == PX_AT25S_PAGES_PER_BLOCK_4KB)
73
74 // Erase 4 KB block
75 px_at25s_erase(PX_AT25S_BLOCK_4KB, page);
76
77#elif (PX_LOG_FS_CFG_ERASE_BLOCK_SIZE == PX_AT25S_PAGES_PER_BLOCK_32KB)
78
79 // Erase 32 KB block
80 px_at25s_erase(PX_AT25S_BLOCK_32KB, page);
81
82#elif (PX_LOG_FS_CFG_ERASE_BLOCK_SIZE == PX_AT25S_PAGES_PER_BLOCK_64KB)
83
84 // Erase 64 KB block
85 px_at25s_erase(PX_AT25S_BLOCK_64KB, page);
86
87#else
88 #error "Invalid block size specified");
89#endif
90}
void px_at25s_wr_page_offset(const void *buf, uint16_t page, uint8_t start_byte_in_page, uint16_t nr_of_bytes)
Partial write of data in a page of Serial Flash.
Definition: px_at25s.c:168
void px_at25s_erase(px_at25s_block_t block, uint16_t page)
Erase a block of Serial Flash.
Definition: px_at25s.c:190
void px_at25s_rd_page_offset(void *buf, uint16_t page, uint8_t start_byte_in_page, uint16_t nr_of_bytes)
Partial read of data in a page of Serial Flash.
Definition: px_at25s.c:141
void px_log_fs_glue_wr(const void *buf, uint16_t page, uint16_t start_byte_in_page, uint16_t nr_of_bytes)
Writes data to Serial Flash.
#define PX_LOG_FS_CFG_ERASE_BLOCK_SIZE
Erase block size (in pages) for file system.
#define PX_LOG_FS_CFG_PAGE_SIZE
Page size for file system.
void px_log_fs_glue_rd(void *buf, uint16_t page, uint16_t start_byte_in_page, uint16_t nr_of_bytes)
Read data from Serial Flash.
void px_log_fs_glue_erase_block(uint16_t page)
Erases data in Serial Flash.
#define PX_LOG_NAME(name)
Macro to declare a log name string once for each file to reduce code size.
Definition: px_log.h:349
#define PX_LOG_ASSERT(expression)
Macro that will test an expression, and block indefinitely if false.
Definition: px_log.h:440