Giter Club home page Giter Club logo

kos-avr's Introduction

Kevin's RTOS (KOS)

Kevin Cuzner

This is a preemptive task-based real-time operating system designed to consume as few resources as possible while increasing the effective utilization of systems using AVR microcontrollers.

The motivation for this project stems from my own desire to write something like this. There are many other options available which are likely better written and easier to use, but I'm going to have more fun doing it this way.

Goals

  1. Small codebase that is easy enough to read.
  2. Small memory footprint.

Operation

Tasks

The basic operational unit is a Task. A Task is created from a pointer to the function to invoke to begin the task and a pointer to the top of the memory to use as a stack. The absolute minimum stack size is 35 bytes, but this will likely run into problems since most programs use part of the stack as storage for variables and such. Tasks should each contain a loop which never exits. The operating system is optimized for the case where tasks always exist.

The order in which tasks are created sets their priority. The last task created will have the highest priority.

Preemption

As a preempting operating system, tasks can be suspended at any time. At the point where a task is suspended, the next program counter, status register, and 32 registers are pushed onto the current stack.

In general, preemption will occur in response to an interrupt. This means that if interrupts are disabled, the task won't be interrupted. Since no two tasks can have the same priority, there is no time-slicing or round-robin support. A task will run until it blocks or is interrupted.

Scheduling & Dispatching

The scheduler is first run with a call to kos_run(). When it is invoked, it will follow the list of tasks in priority order and find the highest priority task that is ready. It will then invoke the dispatcher on this task.

The dispatcher works by storing the context of the current task on the stack, overwriting the stack pointer with the next task's stack pointer, popping all the previously stored register values, and then executing a ret or reti (if interrupts are enabled) to jump back into executing the (next, now current) task.

Blocking

Tasks are blocked by calling functions which change the state of the current task to "blocked". In general, they also store a pointer to some data which can be used to determine how to unblock the task. Examples of blocking functions are:

  • kos_semaphore_pend
  • kos_queue_pend

When these functions are executed, there is a chance that the current task will have its state changed to blocked. The scheduler will be called and the first ready task (which won't be the current task, since it was just blocked) will be dispatched.

Un-blocking

A task is unblocked simply by changing its status back to "ready". Examples of functions which do this are:

  • kos_semaphore_post
  • kos_queue_post

These functions all traverse the task list, mark a single task as ready (if needed), and then call the scheduler. If the current task is higher priority than the task that was unblocked, then no context switch occurs. However, if a higher priority task is unblocked, then the current task is suspended and the higher priority task is resumed.

Conveniences

Any RTOS is almost useless if it just consists of tasks and a dispatcher. It needs something to allow the tasks to switch. KOS provides the following:

  • Semaphores
  • Queues (NOTE: There is no full checking, these are implemented as circular buffers and will overwrite un-dequeued data).

kos-avr's People

Contributors

kcuzner avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

kos-avr's Issues

Xmega adaptation

Hey, I tried to make your kos running on an Xmega,

they use in theorie the same avr core sou it should be fine,

but the mcu is crashing after the dispatcher runs.

Any Ideas ?

regards,

Matthias

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.