Giter VIP home page Giter VIP logo

noos's Introduction

NoOs

GitHub PRs Welcome

[toc]

简介

NoOs 名字的寓意取自于:"NoOs is not an operating system"。虽然不是传统意义的操作系统,但是 NoOs 的目标是提供类似RTOS的开发方式,其代码量比较小,使用简单易懂,占用资源非常小,适用于资源较小的嵌入式系统,能够帮助你快速实现产品。因为是纯 C 语言实现,易于移植到不同的平台。

遵循 Apache License 2.0 开源许可协议,可以免费在商业产品中使用,并且不需要公开私有代码。

代码目录

NoOs 源代码的结构如下所示:

Name Description
NoOs NoOs 的源代码和头文件

API 说明

外部使用的 API 极少,只有四个,所以使用起来相当的简单。

  • void InitNoOs(void);

    描述:初始化 NoOs 系统。

  • void StartNoOsScheduler(void);

    描述:用于调度加入调度器的任务。

  • InitNoOsTask(NoOsTaskDef NewTask, void(Callback)(void), uint32_t Priority);

    描述:用于初始化新的任务并将其加入调度器。

    输入参数:

    • NewTask:新任务
    • Callback:新任务的回调函数
    • Priority:任务的优先级(数字越低,优先级越高)
  • uint32_t GetNoOsTick(void);

    描述:获取系统时钟心跳的次数。

移植

因为 NoOs 是纯 C 语言实现的,所以在不同的硬件设备间移植起来很简单。

详细移植过程如下所示:

  • 将源代码目录中的 NoOs.c 加入项目工程目录。

    STM32Keil MDK5 开发为例:

    image-20210807092758057

  • 将源代码目录中的 NoOs.h 加入项目工程头文件包含路径。

    STM32Keil MDK5 开发为例:

    image-20210807093328520

  • 1ms 硬件中断中函数中,加入 NoOsTick++;

  • main.c 函数中加入 InitNoOs() 函数,用于初始化 NoOs 系统,main函数的最后调用 StartNoOsScheduler() 函数,用于调度任务。

    以 STM32 在 Keil MDK5 开发为例:

    #include "NoOs.h"
    
    int main(void)
    {
      /* MCU Configuration--------------------------------------------------------*/
      /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
      HAL_Init();
      /* Configure the system clock */
      SystemClock_Config();
      /* Initialize all configured peripherals */
      MX_GPIO_Init();
    
      /* Init NoOs */
      InitNoOs();
        
      StartNoOsScheduler();
    }

快速上手

以建立一个 LED 闪烁显示的任务为例,使用的硬件依然是 STM32

首先完成任务运行基础:

  • 使用 STM32CubeMx 建立 STM32 工程,完成基本设置,配置好 LED 控制引脚 对应的 GPIO 引脚,设置 SysTick 时钟,默认是 1ms 中断一次。
  • 按上节移植过程配置好 NoOs 运行的基本条件。

建立 LED 显示任务:

  • 定义 LED 任务的结构体

    NoOsTaskDef LedDisplayTask;
  • 定义 LED 任务的回调函数(其中GetNoOsTick()用于实现非阻塞延时),功能是让 LED 灯 1Hz 频率闪烁。

    void LedDisplayCallback(void)
    {
        static uint32_t LedDelayTick;
        
        if((GetNoOsTick() - LedDelayTick) > 500)
        {
            LedDelayTick = GetNoOsTick();
            HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_8);
        }
    }
  • main() 中的 InitNoOs() 后调用任务初始化函数,成功将其加入任务调度中,将上面的回调函数加入初始化参数列表,且优先级设置为 1。

    InitNoOsTask(&LedDisplayTask, LedDisplayCallback, 1); 

下面是完整的代码:

#include "NoOs.h"

NoOsTaskDef LedDisplayTask;

void LedDisplayCallback(void)
{
    static uint32_t LedDelayTick;
    
    if((GetNoOsTick() - LedDelayTick) > 500) //500ms
    {
        LedDelayTick = GetNoOsTick();
        HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_8);
    }
}

int main(void)
{
  /* MCU Configuration--------------------------------------------------------*/
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();
  /* Configure the system clock */
  SystemClock_Config();
  /* Initialize all configured peripherals */
  MX_GPIO_Init();

  /* Init NoOs */
  InitNoOs();
  
  /* Init LedDisplay task */
  InitNoOsTask(&LedDisplayTask, LedDisplayCallback, 1); 
    
  StartNoOsScheduler();
}

实现效果如下所示:

led2

更多示例

敬请期待!

License

NoOs 是一个开源软件,遵循 Apache-2.0 许可版本。许可证信息和版权信息一般可以在代码的开头看到::

/*
 * Copyright (c) 2021, Eureka1024 <[email protected]>
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * ......
 */

noos's People

Contributors

eureka1024 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.