Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mattjesc/dsm-mt-eh-zephyr-rtos

Dynamic State Machine with Multithreading and Event Handling in Zephyr RTOS
https://github.com/mattjesc/dsm-mt-eh-zephyr-rtos

c embedded embedded-systems firmware freertos iot linux microcontroller rtos zephyr zephyr-rtos

Last synced: 10 days ago
JSON representation

Dynamic State Machine with Multithreading and Event Handling in Zephyr RTOS

Awesome Lists containing this project

README

        

## Dynamic State Machine with Multithreading and Event Handling in Zephyr RTOS

![image](https://github.com/user-attachments/assets/4ded47da-827f-47ec-9753-f48e3ea7339c)

### Introduction

This project demonstrates the implementation of a dynamic state machine with multithreading and event handling using the Zephyr Real-Time Operating System (RTOS). The application is designed to showcase how multiple threads can interact through event-driven programming and manage different states.

### Prerequisites

- **Operating System**: Make sure you have a compatible Linux distribution installed (Ubuntu is recommended).
- **Zephyr RTOS**: This project was built and tested using Zephyr RTOS version 3.7.99. Compatibility with future versions is not guaranteed.
- **Board Compatibility**: This project is designed to be flexible with any board supported by Zephyr RTOS. However, for maximum compatibility and ease of use, especially for those who want to quickly clone and try the project on their systems without additional hardware, we use the QEMU emulated board (`qemu_x86`). This allows you to simulate a Zephyr environment directly on your computer.

### Initial Setup

Follow these steps to set up your environment for developing with Zephyr RTOS version 3.7.99.

1. **Select and Update OS**: Ensure your Linux distribution is up to date.
2. **Install Dependencies**:
```bash
sudo apt-get update
sudo apt-get install --no-install-recommends git cmake ninja-build gperf ccache dfu-util \
device-tree-compiler wget \
python3-pip python3-setuptools python3-tk python3-wheel xz-utils file make gcc \
gcc-multilib libsdl2-dev
```
3. **Get Zephyr and Install Python Dependencies**:
```bash
pip3 install --user west
west init ~/zephyrproject
cd ~/zephyrproject
west update
west zephyr-export
pip3 install --user -r zephyr/scripts/requirements.txt
```
4. **Install the Zephyr SDK**:
- Download the SDK from the [Zephyr SDK Releases](https://github.com/zephyrproject-rtos/sdk-ng/releases).
- Install the SDK following the instructions for your platform.
- Set up the environment variables:
```bash
export ZEPHYR_SDK_INSTALL_DIR=~/zephyr-sdk
```
5. **Build the Blinky Sample** (to verify your setup):
```bash
west build -p auto -b qemu_x86 samples/basic/blinky
```

### Project Setup

1. **Clone the Project Repository**:
```bash
git clone https://github.com/YOUR_USERNAME/zephyr-multithreading-example.git
cd zephyr-multithreading-example
```

2. **Integrate with Zephyr Project**:
- **Place the downloaded files** into your Zephyr project setup. Navigate to your Zephyr base directory (typically `~/zephyrproject/zephyr`) and move the `src` folder, `CMakeLists.txt`, and `prj.conf` file directly into a new project directory of your choice under `zephyr`.
- You could structure it like this:
```
zephyr/
├── applications/
├── boards/
├── drivers/
├── include/
├── kernel/
├── your_project_name/
│ ├── src/
│ ├── CMakeLists.txt
│ └── prj.conf
└── samples/
```
- Replace `your_project_name` with a suitable name for your project.

3. **Build the Project**:
```bash
cd ~/zephyrproject/zephyr/your_project_name
west build -b qemu_x86 .
```

4. **Run the Project**:
```bash
west build -t run
```

### Notes

- This project utilizes specific features available in Zephyr RTOS version 3.7.99. Be aware that differences in future Zephyr versions may affect compatibility.
- The dynamic state machine and multithreading handling are tailored for educational purposes and might require optimizations for production environments.
- **Further Setup and Configuration**: For more comprehensive setup and configuration guidelines, you can refer to the [Zephyr Project Documentation](https://docs.zephyrproject.org/latest/).

### Troubleshooting

Refer to the [Zephyr Project Documentation](https://docs.zephyrproject.org/latest/) for troubleshooting common issues with setup and development.

### License

This project is licensed under the Apache 2.0 License - see the LICENSE file for details.