GPS Device
Loading...
Searching...
No Matches
IO Public API

Public functions to interact with the IO subsystem. More...

Collaboration diagram for IO Public API:

Functions

ERR_te io_init_subsys (void)
 Initializes the IO subsystem.
ERR_te io_deinit_subsys (void)
 Deinitializes the IO subsystem.
ERR_te io_start_subsys (void)
 Starts the IO subsystem.
ERR_te io_stop_subsys (void)
 Stops the IO subsystem.
ERR_te io_init_handle (IO_CFG_ts *io_cfg, IO_HANDLE_ts **io_handle_o)
 Initializes and registers an IO handle.
ERR_te io_deinit_handle (IO_HANDLE_ts const *io_handle)
 Deinitializes an IO handle.
ERR_te io_write (IO_HANDLE_ts *io_handle, PIN_STATUS_te pin_status)
 Writes a logic level to an IO pin.
ERR_te io_read (IO_HANDLE_ts const *io_handle, PIN_STATUS_te *pin_status_o)
 Reads the current logic level of an IO pin.

Detailed Description

Public functions to interact with the IO subsystem.

Function Documentation

◆ io_init_subsys()

ERR_te io_init_subsys ( void )

Initializes the IO subsystem.

Resets the internal state, registers the CLI commands, and initializes the logging dependency.

Must be called before any other IO API function.

Returns
  • ERR_OK on success
  • ERR_MODULE_ALREADY_INITIALIZED if the subsystem is already initialized
  • Propagated error from cmd_register on failure
Note
Should only be called once during system startup.
See also
io_init_subsys

Definition at line 120 of file io.c.

120 {
121 ERR_te err = 0;
122
123 if(internal_state.initialized) {
125 }
126
127 internal_state = (struct internal_state_s){ 0 };
128
129 internal_state.log_level = LOG_LEVEL_INFO;
130 internal_state.subsys = MODULES_IO;
131 internal_state.initialized = true;
132 internal_state.started = false;
133
134 init_log();
135
137 if(err != ERR_OK) {
138 LOG_ERROR(
139 internal_state.subsys,
140 internal_state.log_level,
141 "io_init_subsys: cmd_register error"
142 );
143
144 return err;
145 }
146 LOG_INFO(
147 internal_state.subsys,
148 internal_state.log_level,
149 "io_init_subsys: subsys initialized"
150 );
151
152 return ERR_OK;
153}
static struct internal_state_s internal_state
Singleton instance of the SysTick driver internal state.
ERR_te cmd_register(CMD_CLIENT_INFO_ts *cmd_client_info)
Registers a client with the command subsystem.
Definition cmd.c:51
ERR_te
Standard return type used by all public API functions.
Definition err.h:35
@ ERR_OK
Definition err.h:36
@ ERR_MODULE_ALREADY_INITIALIZED
Definition err.h:54
ERR_te init_log(void)
Initializes the logging subsystem.
Definition init.c:25
#define LOG_ERROR(subsys, lvl, fmt,...)
Definition log.h:258
#define LOG_INFO(subsys, lvl, fmt,...)
Definition log.h:255
@ LOG_LEVEL_INFO
Definition log.h:64
@ MODULES_IO
Definition modules.h:46
static CMD_CLIENT_INFO_ts io_cmd_client_info
Registration descriptor passed to the command subsystem.
Definition io.c:107
Internal state of the SysTick driver.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ io_deinit_subsys()

ERR_te io_deinit_subsys ( void )

Deinitializes the IO subsystem.

Resets the internal state to zero and deregisters the CLI commands. The subsystem must be stopped before calling this function.

Returns
  • ERR_OK on success
  • ERR_DEINITIALIZATION_FAILURE if the subsystem is not initialized or still running
Note
All IO handles should be deinitialized before calling this function.
See also
io_deinit_subsys

Definition at line 156 of file io.c.

156 {
157 if(internal_state.initialized && !internal_state.started) {
158 internal_state = (struct internal_state_s){ 0 };
159
161 }
162 else {
163 LOG_ERROR(
164 internal_state.subsys,
165 internal_state.log_level,
166 "io_deinit_subsys: subsys is not initialized or not stopped"
167 );
168
170 }
171 LOG_INFO(
172 internal_state.subsys,
173 internal_state.log_level,
174 "io_deinit_subsys: subsys deinitialized"
175 );
176
177 return ERR_OK;
178}
ERR_te cmd_deregister(CMD_CLIENT_INFO_ts const *cmd_client_info)
Deregisters a client from the command subsystem.
Definition cmd.c:66
@ ERR_DEINITIALIZATION_FAILURE
Definition err.h:44
Here is the call graph for this function:

◆ io_start_subsys()

ERR_te io_start_subsys ( void )

Starts the IO subsystem.

Enables runtime operations. After calling this function, io_write and io_read may be called.

Returns
  • ERR_OK on success
  • ERR_UNKNOWN if the subsystem is not initialized or already started
Note
Must be called after io_init_subsys.
See also
io_start_subsys

Definition at line 181 of file io.c.

181 {
182 if(internal_state.initialized && !internal_state.started) {
183 internal_state.started = true;
184
185 LOG_INFO(
186 internal_state.subsys,
187 internal_state.log_level,
188 "io_start_subsys: subsys started"
189 );
190 }
191 else {
192 LOG_ERROR(
193 internal_state.subsys,
194 internal_state.log_level,
195 "io_start_subsys: subsys not initialized or already started"
196 );
197
198 return ERR_UNKNOWN;
199 }
200
201 return ERR_OK;
202}
@ ERR_UNKNOWN
Definition err.h:37
Here is the caller graph for this function:

◆ io_stop_subsys()

ERR_te io_stop_subsys ( void )

Stops the IO subsystem.

Disables runtime operations. After calling this function, io_write and io_read will return an error.

Returns
  • ERR_OK on success
  • ERR_UNKNOWN if the subsystem is not initialized or already stopped
Note
Call this before deinitializing the subsystem or handles.
See also
io_stop_subsys

Definition at line 205 of file io.c.

205 {
206 if(internal_state.initialized && internal_state.started) {
207 internal_state.started = false;
208
209 LOG_INFO(
210 internal_state.subsys,
211 internal_state.log_level,
212 "io_stop_subsys: subsys stopped"
213 );
214 }
215 else {
216 LOG_ERROR(
217 internal_state.subsys,
218 internal_state.log_level,
219 "io_stop_subsys: subsys not initialized or already already stopped"
220 );
221
222 return ERR_UNKNOWN;
223 }
224
225 return ERR_OK;
226}

◆ io_init_handle()

ERR_te io_init_handle ( IO_CFG_ts * io_cfg,
IO_HANDLE_ts ** io_handle_o )

Initializes and registers an IO handle.

Configures the GPIO pin described by io_cfg and allocates an internal handle from the pool.

Parameters
[in]io_cfgPointer to the IO configuration structure.
[out]io_handle_oPointer to a handle pointer that will be set to the allocated IO instance.
Returns
  • ERR_OK on success
  • ERR_NOT_ENOUGH_SPACE if the maximum number of IO handles is reached
See also
io_init_handle

Definition at line 229 of file io.c.

229 {
230 if(internal_state.io_num == CONFIG_IO_MAX_OBJECTS) {
231 LOG_ERROR(
232 internal_state.subsys,
233 internal_state.log_level,
234 "io_init_handle: subsystem out of memory space"
235 );
236
238 }
239
240 gpio_init(io_cfg->gpio_handle);
241
242 for(uint32_t i = 0; i < CONFIG_IO_MAX_OBJECTS; i++) {
243 if(internal_state.ios[i].in_use == false) {
244 internal_state.ios[i].gpio_cfg = *io_cfg->gpio_handle;
245 txt_cpy(internal_state.ios[i].name,
246 io_cfg->name,
247 get_str_len(io_cfg->name) + 1);
248
249 internal_state.ios[i].in_use = true;
250
251 internal_state.io_num++;
252
253 *io_handle_o = &internal_state.ios[i];
254
255 LOG_INFO(
256 internal_state.subsys,
257 internal_state.log_level,
258 "io_init_handle: io handle %s initialized",
259 internal_state.ios[i].name
260 );
261
262 break;
263 }
264 }
265
266 return ERR_OK;
267}
uint32_t get_str_len(char const *str)
Returns the length of a string, excluding the null terminator.
Definition common.c:22
int txt_cpy(char *txt_to, const char *txt_from, uint32_t len)
Copies a fixed-length block of text into a destination buffer.
Definition common.c:350
@ ERR_NOT_ENOUGH_SPACE
Definition err.h:49
void gpio_init(GPIO_CFG_ts *gpio_cfg)
Initializes a GPIO pin according to the given configuration.
char name[CONFIG_IO_MAX_NAME_LEN]
Definition io.h:58
GPIO_CFG_ts * gpio_handle
Definition io.h:55
Here is the call graph for this function:
Here is the caller graph for this function:

◆ io_deinit_handle()

ERR_te io_deinit_handle ( IO_HANDLE_ts const * io_handle)

Deinitializes an IO handle.

Releases the internal resources associated with the given handle and marks the slot as available for reuse.

Parameters
[in]io_handlePointer to the handle to deinitialize.
Returns
  • ERR_OK on success
  • ERR_UNINITIALZIED_OBJECT if no handles exist or the handle is not found
See also
io_deinit_handle

Definition at line 270 of file io.c.

270 {
271 if(internal_state.io_num == 0) {
272 LOG_ERROR(
273 internal_state.subsys,
274 internal_state.log_level,
275 "io_deinit_handle: no such handle to deinitialize"
276 );
277
279 }
280
281 for(uint32_t i = 0; i < CONFIG_IO_MAX_OBJECTS; i++) {
282 if(&internal_state.ios[i] == io_handle) {
283 internal_state.ios[i].gpio_cfg = (GPIO_CFG_ts){ 0 };
284
285 uint8_t name_len = get_str_len(internal_state.ios[i].name) + 1;
286 char name[name_len];
287
288 str_cpy(name, internal_state.ios[i].name, name_len);
289
290 for(uint32_t j = 0; j < name_len; j++) {
291 internal_state.ios[i].name[j] = '\0';
292 }
293
294 internal_state.ios[i].in_use = false;
295
296 internal_state.io_num--;
297
298 LOG_INFO(
299 internal_state.subsys,
300 internal_state.log_level,
301 "io_deinit_handle: io handle %s deinitialized",
302 name
303 );
304
305 break;
306 }
307
308 if(i == CONFIG_IO_MAX_OBJECTS - 1) {
309 LOG_ERROR(
310 internal_state.subsys,
311 internal_state.log_level,
312 "io_deinit_handle: no such handle to deinitialize"
313 );
314
316 }
317 }
318
319 return ERR_OK;
320}
int str_cpy(char *str_to, const char *str_from, uint32_t len)
Copies a null-terminated string into a destination buffer.
Definition common.c:333
@ ERR_UNINITIALZIED_OBJECT
Definition err.h:42
Configuration structure for initializing a GPIO pin.
Here is the call graph for this function:

◆ io_write()

ERR_te io_write ( IO_HANDLE_ts * io_handle,
PIN_STATUS_te pin_status )

Writes a logic level to an IO pin.

Parameters
[in]io_handlePointer to the IO handle to write to.
[in]pin_statusThe logic level to drive on the pin (HIGH or LOW).
Returns
  • ERR_OK on success
  • ERR_UNKNOWN if the subsystem is not initialized or started
See also
io_write

Definition at line 323 of file io.c.

323 {
324 if(internal_state.initialized && internal_state.started) {
326 io_handle->gpio_cfg.port,
327 io_handle->gpio_cfg.pin,
328 pin_status
329 );
330 }
331 else {
332 LOG_ERROR(
333 internal_state.subsys,
334 internal_state.log_level,
335 "io_write: subsystem not initialized or started"
336 );
337
338 return ERR_UNKNOWN;
339 }
340
341 return ERR_OK;
342}
void gpio_write(GPIO_REGDEF_ts *gpio_port, uint8_t gpio_pin, PIN_STATUS_te pin_status)
Drives a GPIO output pin high or low.
GPIO_REGDEF_ts * port
GPIO_PIN_te pin
GPIO_CFG_ts gpio_cfg
Definition io.c:31
Here is the call graph for this function:
Here is the caller graph for this function:

◆ io_read()

ERR_te io_read ( IO_HANDLE_ts const * io_handle,
PIN_STATUS_te * pin_status_o )

Reads the current logic level of an IO pin.

Parameters
[in]io_handlePointer to the IO handle to read from.
[out]pin_status_oPointer to a variable that will receive the current pin level (HIGH or LOW).
Returns
  • ERR_OK on success
  • ERR_UNKNOWN if the subsystem is not initialized or started
See also
io_read

Definition at line 345 of file io.c.

345 {
346 if(internal_state.initialized && internal_state.started) {
347 *pin_status_o = gpio_read(
348 io_handle->gpio_cfg.port,
349 io_handle->gpio_cfg.pin
350 );
351 }
352 else {
353 LOG_ERROR(
354 internal_state.subsys,
355 internal_state.log_level,
356 "io_read: subsystem not initialized or started"
357 );
358
359 return ERR_UNKNOWN;
360 }
361
362 return ERR_OK;
363}
PIN_STATUS_te gpio_read(GPIO_REGDEF_ts const *gpio_port, uint8_t gpio_pin)
Reads the current logic level of a GPIO input pin.
Here is the call graph for this function:
Here is the caller graph for this function: