From 5939b12ac067c47b242cdb21ce4502dbd710bbf7 Mon Sep 17 00:00:00 2001 From: Riven Zheng Date: Fri, 9 Feb 2024 13:26:12 +0800 Subject: [PATCH] Add the first thread usage into README.md. --- {samples => .github/samples}/README.md | 0 .../samples}/kernal_sample/.gitignore | 0 .../samples}/kernal_sample/CMakeLists.txt | 2 +- .../samples}/kernal_sample/main.c | 0 {script => .github/script}/auto-version.cmd | 0 {script => .github/script}/auto-version.ps1 | 2 +- .github/workflows/kernal-sample.yml | 2 +- .github/workflows/trigger-version-release.yml | 2 +- README.md | 89 ++++++++++++++++++- kernal/include/at_rtos.h | 3 +- 10 files changed, 93 insertions(+), 7 deletions(-) rename {samples => .github/samples}/README.md (100%) rename {samples => .github/samples}/kernal_sample/.gitignore (100%) rename {samples => .github/samples}/kernal_sample/CMakeLists.txt (97%) rename {samples => .github/samples}/kernal_sample/main.c (100%) rename {script => .github/script}/auto-version.cmd (100%) rename {script => .github/script}/auto-version.ps1 (99%) diff --git a/samples/README.md b/.github/samples/README.md similarity index 100% rename from samples/README.md rename to .github/samples/README.md diff --git a/samples/kernal_sample/.gitignore b/.github/samples/kernal_sample/.gitignore similarity index 100% rename from samples/kernal_sample/.gitignore rename to .github/samples/kernal_sample/.gitignore diff --git a/samples/kernal_sample/CMakeLists.txt b/.github/samples/kernal_sample/CMakeLists.txt similarity index 97% rename from samples/kernal_sample/CMakeLists.txt rename to .github/samples/kernal_sample/CMakeLists.txt index 7576248..3c25dd0 100644 --- a/samples/kernal_sample/CMakeLists.txt +++ b/.github/samples/kernal_sample/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.20) project(kernal_sample LANGUAGES C) -set(At_RTOS_PATH "../../") +set(At_RTOS_PATH "../../../") include(${At_RTOS_PATH}/CMakeLists.txt) diff --git a/samples/kernal_sample/main.c b/.github/samples/kernal_sample/main.c similarity index 100% rename from samples/kernal_sample/main.c rename to .github/samples/kernal_sample/main.c diff --git a/script/auto-version.cmd b/.github/script/auto-version.cmd similarity index 100% rename from script/auto-version.cmd rename to .github/script/auto-version.cmd diff --git a/script/auto-version.ps1 b/.github/script/auto-version.ps1 similarity index 99% rename from script/auto-version.ps1 rename to .github/script/auto-version.ps1 index d8e1ac3..f498d52 100644 --- a/script/auto-version.ps1 +++ b/.github/script/auto-version.ps1 @@ -1,5 +1,5 @@ $VersionFile = "atos_version.h" -$VersionPath = "../kernal/include" +$VersionPath = "../../kernal/include" $FileContent = '/** * Copyright (c) Riven Zheng (zhengheiot@gmail.com). * diff --git a/.github/workflows/kernal-sample.yml b/.github/workflows/kernal-sample.yml index 12e61b3..5de5980 100644 --- a/.github/workflows/kernal-sample.yml +++ b/.github/workflows/kernal-sample.yml @@ -20,7 +20,7 @@ jobs: - name: Build Kernal Sample CMake shell: bash - working-directory: samples/kernal_sample + working-directory: .github/samples/kernal_sample run: | cmake -S . -B build cmake --build build diff --git a/.github/workflows/trigger-version-release.yml b/.github/workflows/trigger-version-release.yml index 9a77fc7..113adef 100644 --- a/.github/workflows/trigger-version-release.yml +++ b/.github/workflows/trigger-version-release.yml @@ -18,7 +18,7 @@ jobs: - name: Execute Version Script id: version shell: powershell - working-directory: script + working-directory: .github/script run: | $message = powershell.exe -ExecutionPolicy bypass .\auto-version.ps1 echo "value=$message" >> "$env:GITHUB_OUTPUT" diff --git a/README.md b/README.md index 81b52e3..cb6e9d2 100644 --- a/README.md +++ b/README.md @@ -7,9 +7,7 @@ The goal of the project is to explore and try to provide a lot useful interfaces If this project was useful to you, give it a ⭐️ and I'll keep improving it. moreover, you can share your ideas we can together improve it. Welcome PRs!!!

- At-RTOS -

## Introduction @@ -26,6 +24,93 @@ If this project was useful to you, give it a ⭐️ and I'll keep improving it. * **Tiny footprint:** It's as low as 1KB ROM/few bytes of RAM. * **Learn Once, Write Anywhere:** We don't make assumptions about the rest of your technology stack, so you can develop new features in At-RTOS without rewriting existing code. +## Kernal Structure + +```shell +# At-RTOS source code tree +At-RTOS +├── arch +│ ├── arch32 +│ │ └── arm +│ │ └── cmsis +│ │ └── include +│ │ └── *.h +│ ├── arch.h +│ └── CMakeLists.txt +├── clock +│ ├── include +│ │ └── clock_tick.h +│ ├── clock_systick.c +│ └── CMakeLists.txt +├── port +│ ├── include +│ │ └── port.h +│ ├── port_keil.c +│ └── CMakeLists.txt +├── include +│ ├── atos_configuration.h +│ └── CMakeLists.txt +├── kernal +│ ├── include +│ │ ├── at_rtos.h +│ │ ├── atos_version.h +│ │ └── *.h +│ ├── basic.c +│ ├── event.c +│ ├── kernal.c +│ ├── kernal_thread.c +│ ├── linker.c +│ ├── list.c +│ ├── mutex.c +│ ├── queue.c +│ ├── semaphore.c +│ ├── thread.c +│ ├── timer.c +│ ├── trace.c +│ └── CMakeLists.txt +├── kernal_idle.c +└── CMakeLists.txt +``` + +- **arch :** This folder was used to store all the chip architectures supported by the current At-RTOS. +- **clock :** It was implemented for At-RTOS kernal system tick to support system timers. +- **port :** It's used to support different compiler such as KEIL, IAR and GCC. +- **include :** It used to contain the At-RTOS kernal header file such as the At-RTOS user configurations. +- **kernal :** Ihis folder was implemented for the At-RTOS kernal files. + +## Usage + +Create Your First Thread: +```shell +# Include the At-RTOS interface's header file +#include "at_rtos.h" + +# Define a thread hook to specific the stack size and prioriy of the thread +ATOS_THREAD_DEFINE(first_thread, 1024, 7); // Set the thread stack size to 1024 bytes and the schedule prioriy level to 7. + +# User thread's entry function +static void first_thread_entry(void) +{ + while (1) + { + AtOS.thread_sleep(1000u); + } +} + +# The main routine +int main(void) +{ + /* Initialize the your first thread */ + os_thread_id_t first_id = thread_init(first_thread, first_thread_entry); + if (os_id_is_invalid(first_id)) + { + printf("Thread %s init failed\n", first_id.pName); + } + + AtOS.at_rtos_run(); // The AtOS kernal schedule starts to run. +} +``` + ## What's New [v1.0.0] Welcome to At-RTOS. v1.0.0 was released now. A basic RTOS feature was implemented in the kernal system, Pls enjoy it (: diff --git a/kernal/include/at_rtos.h b/kernal/include/at_rtos.h index 088aee3..d7b4a84 100644 --- a/kernal/include/at_rtos.h +++ b/kernal/include/at_rtos.h @@ -39,6 +39,7 @@ S_ASSERT((((thread_priority) >= OS_PRIORITY_USER_THREAD_HIGHEST_LEVEL) && ((thre * @return The value of thread unique id. ** * demo usage: + *#include "at_rtos.h" * *ATOS_THREAD_DEFINE(sample_thread, 512, 5); * @@ -46,12 +47,12 @@ S_ASSERT((((thread_priority) >= OS_PRIORITY_USER_THREAD_HIGHEST_LEVEL) && ((thre * { * while(1) * { + * AtOS.thread_sleep(1000u); * } * } * * int main(void) * { - * ATOS_PRIORITY_DEFINE(sample_pri, 5); * os_thread_id_t sample_id = thread_init(sample_thread, thread_sample_function); * if (os_id_is_invalid(sample_id)) * {