Safe API Framework
Layered API framework for safety-related applications (ERTMS RBC reference targeting CENELEC EN 50128 SIL 4)
Loading...
Searching...
No Matches
sapi_nvm.c
Go to the documentation of this file.
1
10
12
14
17static const sapi_nvm_backend_t *s_backend = NULL;
18
20
22
23
26{
27 sapi_status_t lifecycle_status;
28
29 if (backend == NULL)
30 {
32 }
33 /* REQ-LIFECYCLE-001 (ADR-026): registering a backend is a setup-only
34 * action - refuse once the application's setup phase has been locked. */
35 lifecycle_status = sapi_lifecycle_check_setup_allowed();
36 if (lifecycle_status != SAPI_STATUS_OK)
37 {
38 return lifecycle_status;
39 }
40 s_backend = backend;
41 return SAPI_STATUS_OK;
42}
43
44sapi_status_t sapi_nvm_open(sapi_nvm_storage_t *storage,
45 const sapi_nvm_config_t *config,
46 sapi_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 if (s_backend == NULL)
58 {
60 }
61 if (s_backend->open == NULL)
62 {
64 }
65 return s_backend->open(storage, config, out_handle);
66}
67
69 size_t offset,
70 void *out_buffer,
71 size_t buffer_size)
72{
73 if ((handle == NULL) || (out_buffer == NULL) || (buffer_size == 0U))
74 {
76 }
77 if (s_backend == NULL)
78 {
80 }
81 if (s_backend->read == NULL)
82 {
84 }
85 return s_backend->read(handle, offset, out_buffer, buffer_size);
86}
87
89 size_t offset,
90 const void *buffer,
91 size_t buffer_size)
92{
93 if ((handle == NULL) || (buffer == NULL) || (buffer_size == 0U))
94 {
96 }
97 if (s_backend == NULL)
98 {
100 }
101 if (s_backend->write == NULL)
102 {
104 }
105 return s_backend->write(handle, offset, buffer, buffer_size);
106}
107
109{
110 if (handle == NULL)
111 {
113 }
114 if (s_backend == NULL)
115 {
117 }
118 if (s_backend->sync == NULL)
119 {
121 }
122 return s_backend->sync(handle);
123}
124
126{
127 if (handle == NULL)
128 {
130 }
131 if (s_backend == NULL)
132 {
134 }
135 if (s_backend->close == NULL)
136 {
138 }
139 return s_backend->close(handle);
140}
sapi_status_t sapi_lifecycle_check_setup_allowed(void)
Convenience check for a setup-only constructor: call this as one of the first checks in any function ...
sapi_status_t sapi_nvm_register_backend(const sapi_nvm_backend_t *backend)
Registers the backend implementation used by every sapi_nvm_* call (ADR-005 section 2....
Definition sapi_nvm.c:25
sapi_status_t sapi_nvm_open(sapi_nvm_storage_t *storage, const sapi_nvm_config_t *config, sapi_nvm_handle_t *out_handle)
Opens (creating if necessary) a named NVM region.
Definition sapi_nvm.c:44
sapi_status_t sapi_nvm_sync(sapi_nvm_handle_t handle)
Forces any buffered writes to durable storage.
Definition sapi_nvm.c:108
sapi_status_t sapi_nvm_close(sapi_nvm_handle_t handle)
Closes an NVM region handle.
Definition sapi_nvm.c:125
sapi_status_t sapi_nvm_read(sapi_nvm_handle_t handle, size_t offset, void *out_buffer, size_t buffer_size)
Reads and integrity-checks data from an NVM region.
Definition sapi_nvm.c:68
struct sapi_nvm_impl_s * sapi_nvm_handle_t
Opaque handle to an open NVM region, returned by sapi_nvm_open().
Definition sapi_nvm.h:30
sapi_status_t sapi_nvm_write(sapi_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 sapi_nvm.c:88
sapi_status_t
Common result/status codes.
Definition sapi_status.h:27
@ SAPI_STATUS_NOT_SUPPORTED
Definition sapi_status.h:34
@ SAPI_STATUS_INVALID_PARAM
Definition sapi_status.h:29
@ SAPI_STATUS_NOT_INITIALIZED
Definition sapi_status.h:30
@ SAPI_STATUS_OK
Definition sapi_status.h:28
static const sapi_clocksync_backend_t * s_backend
Process-wide application setup-phase lock (ADR-026).
OS Abstraction Layer - Non-Volatile Memory service.
OS-backend adaptation surface for the NVM service (ADR-005, ADR-021).
Backend vtable: an integrator's implementation of the NVM service for a specific storage medium (ADR-...
sapi_status_t(*) write(sapi_nvm_handle_t handle, size_t offset, const void *buffer, size_t buffer_size)
Backend implementation of sapi_nvm_write(). May be NULL.
sapi_status_t(*) close(sapi_nvm_handle_t handle)
Backend implementation of sapi_nvm_close(). May be NULL.
sapi_status_t(*) sync(sapi_nvm_handle_t handle)
Backend implementation of sapi_nvm_sync(). May be NULL.
sapi_status_t(*) read(sapi_nvm_handle_t handle, size_t offset, void *out_buffer, size_t buffer_size)
Backend implementation of sapi_nvm_read(). May be NULL.
sapi_status_t(*) open(sapi_nvm_storage_t *storage, const sapi_nvm_config_t *config, sapi_nvm_handle_t *out_handle)
Backend implementation of sapi_nvm_open(). May be NULL.
Configuration for sapi_nvm_open().
Definition sapi_nvm.h:34
const char * region_name
Definition sapi_nvm.h:35
size_t region_size
Definition sapi_nvm.h:36