Safe API Framework 0.1.0 build 384e6ae
Layered API framework for safety-related applications (ERTMS RBC reference targeting CENELEC EN 50128 SIL 4)
Loading...
Searching...
No Matches
rte_nvm.c
Go to the documentation of this file.
1
10
12
14
17static const rte_osadapter_nvm_t *s_osadapter = NULL;
18
20
22
23
26{
27 rte_status_t lifecycle_status;
28
29 if (osadapter == NULL)
30 {
32 }
33 /* REQ-LIFECYCLE-001 (ADR-026): registering an OSAdapter is a setup-only
34 * action - refuse once the application's setup phase has been locked. */
35 lifecycle_status = rte_lifecycle_check_setup_allowed();
36 if (lifecycle_status != RTE_STATUS_OK)
37 {
38 return lifecycle_status;
39 }
40 s_osadapter = osadapter;
41 return RTE_STATUS_OK;
42}
43
44rte_status_t rte_nvm_open(rte_nvm_storage_t *storage,
45 const rte_nvm_config_t *config,
46 rte_nvm_handle_t *out_handle)
47{
48 if ((storage == NULL) || (config == NULL) || (out_handle == NULL))
49 {
51 }
52 if ((config->region_name == NULL) || (config->region_size == 0U))
53 {
55 }
56 *out_handle = NULL;
57 /* REQ-LIFECYCLE-001/003 (ADR-026, OSA rules): setup-only - refused and reported once the setup phase is locked. */
58 {
60
61 if (lifecycle_status != RTE_STATUS_OK)
62 {
63 return lifecycle_status;
64 }
65 }
66 if (s_osadapter == NULL)
67 {
69 }
70 if (s_osadapter->open == NULL)
71 {
73 }
74 return s_osadapter->open(storage, config, out_handle);
75}
76
78 size_t offset,
79 void *out_buffer,
80 size_t buffer_size)
81{
82 if ((handle == NULL) || (out_buffer == NULL) || (buffer_size == 0U))
83 {
85 }
86 if (s_osadapter == NULL)
87 {
89 }
90 if (s_osadapter->read == NULL)
91 {
93 }
94 return s_osadapter->read(handle, offset, out_buffer, buffer_size);
95}
96
98 size_t offset,
99 const void *buffer,
100 size_t buffer_size)
101{
102 if ((handle == NULL) || (buffer == NULL) || (buffer_size == 0U))
103 {
105 }
106 if (s_osadapter == NULL)
107 {
109 }
110 if (s_osadapter->write == NULL)
111 {
113 }
114 return s_osadapter->write(handle, offset, buffer, buffer_size);
115}
116
118{
119 if (handle == NULL)
120 {
122 }
123 if (s_osadapter == NULL)
124 {
126 }
127 if (s_osadapter->sync == NULL)
128 {
130 }
131 return s_osadapter->sync(handle);
132}
133
135{
136 if (handle == NULL)
137 {
139 }
140 if (s_osadapter == NULL)
141 {
143 }
144 if (s_osadapter->close == NULL)
145 {
147 }
148 return s_osadapter->close(handle);
149}
rte_status_t rte_lifecycle_check_setup_allowed(void)
Convenience check for a setup-only constructor: call this as one of the first checks in any function ...
rte_status_t rte_nvm_read(rte_nvm_handle_t handle, size_t offset, void *out_buffer, size_t buffer_size)
Reads and integrity-checks data from an NVM region.
Definition rte_nvm.c:77
rte_status_t rte_nvm_close(rte_nvm_handle_t handle)
Closes an NVM region handle.
Definition rte_nvm.c:134
rte_status_t rte_nvm_write(rte_nvm_handle_t handle, size_t offset, const void *buffer, size_t buffer_size)
Writes data and its integrity metadata to an NVM region.
Definition rte_nvm.c:97
rte_status_t rte_nvm_sync(rte_nvm_handle_t handle)
Forces any buffered writes to durable storage.
Definition rte_nvm.c:117
struct rte_nvm_impl_s * rte_nvm_handle_t
Opaque handle to an open NVM region, returned by rte_nvm_open().
Definition rte_nvm.h:30
rte_status_t rte_nvm_open(rte_nvm_storage_t *storage, const rte_nvm_config_t *config, rte_nvm_handle_t *out_handle)
Opens (creating if necessary) a named NVM region.
Definition rte_nvm.c:44
rte_status_t
Common result/status codes.
Definition rte_status.h:27
@ RTE_STATUS_OK
Definition rte_status.h:28
@ RTE_STATUS_INVALID_PARAM
Definition rte_status.h:29
@ RTE_STATUS_NOT_SUPPORTED
Definition rte_status.h:34
@ RTE_STATUS_NOT_INITIALIZED
Definition rte_status.h:30
static const rte_osadapter_clocksync_t * s_osadapter
Process-wide application setup-phase lock (ADR-026).
OS Abstraction Layer - Non-Volatile Memory service.
OSAdapter interface for non-volatile memory (NVM).
rte_status_t rte_osadapter_nvm_register(const rte_osadapter_nvm_t *adapter)
Registers the OSAdapter NVM implementation.
Definition rte_nvm.c:25
Configuration for rte_nvm_open().
Definition rte_nvm.h:34
const char * region_name
Definition rte_nvm.h:35
size_t region_size
Definition rte_nvm.h:36
OSAdapter NVM operations vtable.