1 Star 0 Fork 0

LY / embedded-c-scheduler

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

Embedded C Scheduler

Task scheduler library for embedded (bare metal) projects. It has support for both tick based scheduling, as well as hand coded slot scheduling. It has no direct hardware dependencies, so it is portable to many platforms.

Installation

This library can be installed into your project using clib:

$ clib install bradschl/embedded-c-scheduler

Example

#include <project.h>
#include "sched/sched.h"

static uint32_t
get_current_time(void * hint)
{
    (void) hint;

    // Timer is 1us resolution. The hardware counts down from the maximum
    // value, so the raw value needs to be flipped to be compatible with the
    // scheduler
    return Timer_1_INIT_PERIOD - Timer_1_ReadCounter();
}


struct foo_task_ctx {
    /* ... */
}

static void
foo_task(void * hint)
{
    struct foo_task_ctx * ctx = (struct foo_task_ctx *) hint;
    /* Do tasks stuff */
}


int
main()
{
    // Create the scheduler, 1000us (1ms) per tick
    Timer_1_Start();

    struct sched_ctx * scheduler = sched_alloc_context(
        NULL, get_current_time, Timer_1_INIT_PERIOD, 1000);

    ASSERT_NOT_NULL(scheduler);


    // Create the task
    struct foo_task_ctx foo_ctx;

    struct sched_task * foo_task_handle = sched_alloc_task(
        scheduler, foo_ctx, foo_task, "my foo task", TASK_TICK_4);

    ASSERT_NOT_NULL(foo_task_handle);


    for(;;) {
        sched_run(scheduler);

        /* ...  */
    }
}

API

See sched.h for the C API.

Dependencies and Resources

This library uses heap when allocating structures. After initialization, additional allocations will not be made. This should be fine for an embedded target, since memory fragmentation only happens if memory is freed.

Compiled, this library is only a few kilobytes. Runtime memory footprint is very small, and is dependent on the number of tasks allocated.

License

MIT license for all files.

# Embedded C Scheduler Task scheduler library for embedded (bare metal) projects. It has support for both tick based scheduling, as well as hand coded slot scheduling. It has no direct hardware dependencies, so it is portable to many platforms. ## Installation This library can be installed into your project using [clib](https://github.com/clibs/clib): ``` $ clib install bradschl/embedded-c-scheduler ``` ## Example ```C #include <project.h> #include "sched/sched.h" static uint32_t get_current_time(void * hint) { (void) hint; // Timer is 1us resolution. The hardware counts down from the maximum // value, so the raw value needs to be flipped to be compatible with the // scheduler return Timer_1_INIT_PERIOD - Timer_1_ReadCounter(); } struct foo_task_ctx { /* ... */ } static void foo_task(void * hint) { struct foo_task_ctx * ctx = (struct foo_task_ctx *) hint; /* Do tasks stuff */ } int main() { // Create the scheduler, 1000us (1ms) per tick Timer_1_Start(); struct sched_ctx * scheduler = sched_alloc_context( NULL, get_current_time, Timer_1_INIT_PERIOD, 1000); ASSERT_NOT_NULL(scheduler); // Create the task struct foo_task_ctx foo_ctx; struct sched_task * foo_task_handle = sched_alloc_task( scheduler, foo_ctx, foo_task, "my foo task", TASK_TICK_4); ASSERT_NOT_NULL(foo_task_handle); for(;;) { sched_run(scheduler); /* ... */ } } ``` ## API See [sched.h](src/sched/sched.h) for the C API. ## Dependencies and Resources This library uses heap when allocating structures. After initialization, additional allocations will not be made. This should be fine for an embedded target, since memory fragmentation only happens if memory is freed. Compiled, this library is only a few kilobytes. Runtime memory footprint is very small, and is dependent on the number of tasks allocated. ## License MIT license for all files.

简介

暂无描述 展开 收起
C 等 3 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/claud_ling/embedded-c-scheduler.git
git@gitee.com:claud_ling/embedded-c-scheduler.git
claud_ling
embedded-c-scheduler
embedded-c-scheduler
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891