Public functions to interact with the IO subsystem.
More...
Public functions to interact with the IO subsystem.
◆ 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 {
122
125 }
126
128
133
135
141 "io_init_subsys: cmd_register error"
142 );
143
144 return err;
145 }
149 "io_init_subsys: subsys initialized"
150 );
151
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.
ERR_te
Standard return type used by all public API functions.
@ ERR_MODULE_ALREADY_INITIALIZED
ERR_te init_log(void)
Initializes the logging subsystem.
#define LOG_ERROR(subsys, lvl, fmt,...)
#define LOG_INFO(subsys, lvl, fmt,...)
static CMD_CLIENT_INFO_ts io_cmd_client_info
Registration descriptor passed to the command subsystem.
Internal state of the SysTick driver.
◆ 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 {
159
161 }
162 else {
166 "io_deinit_subsys: subsys is not initialized or not stopped"
167 );
168
170 }
174 "io_deinit_subsys: subsys deinitialized"
175 );
176
178}
ERR_te cmd_deregister(CMD_CLIENT_INFO_ts const *cmd_client_info)
Deregisters a client from the command subsystem.
@ ERR_DEINITIALIZATION_FAILURE
◆ 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 {
184
188 "io_start_subsys: subsys started"
189 );
190 }
191 else {
195 "io_start_subsys: subsys not initialized or already started"
196 );
197
199 }
200
202}
◆ 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 {
208
212 "io_stop_subsys: subsys stopped"
213 );
214 }
215 else {
219 "io_stop_subsys: subsys not initialized or already already stopped"
220 );
221
223 }
224
226}
◆ io_init_handle()
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_cfg | Pointer to the IO configuration structure. |
| [out] | io_handle_o | Pointer 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 {
234 "io_init_handle: subsystem out of memory space"
235 );
236
238 }
239
241
242 for(uint32_t i = 0; i < CONFIG_IO_MAX_OBJECTS; i++) {
248
250
252
254
258 "io_init_handle: io handle %s initialized",
260 );
261
262 break;
263 }
264 }
265
267}
uint32_t get_str_len(char const *str)
Returns the length of a string, excluding the null terminator.
int txt_cpy(char *txt_to, const char *txt_from, uint32_t len)
Copies a fixed-length block of text into a destination buffer.
void gpio_init(GPIO_CFG_ts *gpio_cfg)
Initializes a GPIO pin according to the given configuration.
char name[CONFIG_IO_MAX_NAME_LEN]
GPIO_CFG_ts * gpio_handle
◆ io_deinit_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_handle | Pointer 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 {
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++) {
284
286 char name[name_len];
287
289
290 for(uint32_t j = 0; j < name_len; j++) {
292 }
293
295
297
301 "io_deinit_handle: io handle %s deinitialized",
302 name
303 );
304
305 break;
306 }
307
308 if(i == CONFIG_IO_MAX_OBJECTS - 1) {
312 "io_deinit_handle: no such handle to deinitialize"
313 );
314
316 }
317 }
318
320}
int str_cpy(char *str_to, const char *str_from, uint32_t len)
Copies a null-terminated string into a destination buffer.
@ ERR_UNINITIALZIED_OBJECT
Configuration structure for initializing a GPIO pin.
◆ io_write()
Writes a logic level to an IO pin.
- Parameters
-
| [in] | io_handle | Pointer to the IO handle to write to. |
| [in] | pin_status | The 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 {
328 pin_status
329 );
330 }
331 else {
335 "io_write: subsystem not initialized or started"
336 );
337
339 }
340
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.
◆ io_read()
Reads the current logic level of an IO pin.
- Parameters
-
| [in] | io_handle | Pointer to the IO handle to read from. |
| [out] | pin_status_o | Pointer 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 {
348 io_handle->gpio_cfg.port,
349 io_handle->gpio_cfg.pin
350 );
351 }
352 else {
356 "io_read: subsystem not initialized or started"
357 );
358
360 }
361
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.