Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REFACTOR] Refactor device management framework #2

Open
s3785111 opened this issue Jan 24, 2025 · 0 comments
Open

[REFACTOR] Refactor device management framework #2

s3785111 opened this issue Jan 24, 2025 · 0 comments
Assignees
Labels
refactor Changes to implementation

Comments

@s3785111
Copy link
Member

s3785111 commented Jan 24, 2025

[REFACTOR] Refactor device management framework

Summary

The current device management framework is lacking in thread safety and maintainability, as the implementation for shell programs was simply repurposed for convenience at the time.

As it stands, functional operation of the device system is opaque and non trivial to understand at a glance.

A refactor is proposed to improve the structure of device management, allowing new devices to be added through a more streamlined process with greater clarity to developers not familiar with the codebase.

Detailed Description

Key areas for improvement:

  • Device Handle Management:
    Implement a static array of device handles indexed by a header-defined enum. Provide a unified getter and setter for accessing device handles based on index.

  • Encapsulation:
    Make device state variables opaque and expose getters and setters in the device API struct.

  • Thread Safety:
    Assign a mutex to the state variables of each device driver. Add mutex locking to methods that modify device state to prevent race conditions.

  • Error Checking:
    Add comprehensive error checking across device drivers -- in particular device initialisation and handle creation -- to ensure robustness and inform users of device status.

Optional
  • Configuration:
    Extract device configuration variables to a header-defined struct and pass it to an initialization method to simplify and standardize device setup.

Example Implementation

Example code pending.

  • example.c
  • example.h
#ifndef EXAMPLE_H
#define EXAMPLE_H

#endif

Motivation

This refactor will improve:

  • Readability: By redesigning the approach to device management to consider a simpler implementation.

  • Thread Safety: Ensuring consistent and safe device state manipulation in multi-threaded environments with critical sections where appropriate.

  • Scalability: Simplifying the addition of new devices by following a clearer standardized framework.

  • Portability: By allowing configuration parameters to be passed as a struct during initialization, making configuration more programmatic compared to the current design requiring positional arguments.

Dependencies

N/A

Other Considerations

N/A

@s3785111 s3785111 added the refactor Changes to implementation label Jan 24, 2025
@s3785111 s3785111 moved this to Todo in Australis Avionics Jan 24, 2025
@s3785111 s3785111 moved this from Todo to In Progress in Australis Avionics Jan 28, 2025
@s3785111 s3785111 self-assigned this Jan 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Changes to implementation
Projects
Status: In Progress
Development

When branches are created from issues, their pull requests are automatically linked.

1 participant