Skip to content

Bare metal operating system designed for low power embedded devices with a small memory footprint

License

Notifications You must be signed in to change notification settings

sebastianene07/calypso_os

Repository files navigation

This operating system is designed to run on low power embedded devices. It has a pre-emptive scheduling algorithm and offers a POSIX like interface to the apps.

Building

Download the sources with git clone and update the submodules for this project:

git clone https://github.com/sebastianene07/calypso_os.git
git submodule update --init --recursive

Example for building Calypso OS for Norfic NRF5X board:

make config MACHINE_TYPE=nrf5x/nrf52840
make -j

or if we have nrf52832:

make config MACHINE_TYPE=nrf5x/nrf52832
make -j

You can enable different features for your board by using the Kconfig menu selection.

make menuconfig

The above command requires you to have kconfig-mconf installed on your build machine.

Current features

1. Task scheduling and basic synchronization primitives

The OS defines two list :

g_tcb_waiting_list - is holding the tasks in one of the following states:  [READY, WAITING_FOR_SEM, HALT]  

g_tcb_list - is holding the tasks in the READY and RUNNING state  

The g_current_tcb pointer points to the current running task.   A task transitions from running to waiting for semaphore   when it tries to acquire a semaphore that has a value <= 0.   The task is placed in the g_tcb_waiting_list and it's context   is saved on the stack.  

To wakeup a task from the waiting for semaphore state   someone has to call sem_post on the semaphore   that keeps the task from running. Once this semaphore   is posted, the task enters the READY state and when the   Idle Task runs it moves the task from the g_tcb_waiting_list   to g_tcb_list list.  

2. Dynamic memory allocation

The allocator is implemented as part of a submodule in s_alloc. It can be configure to run with multipple heap objects depending on the needs. It supports the following operations: s_alloc, s_free, s_realloc and the code is tested in a sample program (main.c) that verify the integrity of the allocated blocks and monitors the fragmentation. The test also verifies that the allocated regions do not overlap. In the current configuration it supports up to 2 ^ 31 - 1 blocks of memory where the block size is defined by the code that it's using the allocator. The allocation is done in O(N) space time (searching through the list of free nodes) whereas the free operation can take O(N^2) because of the block merging and sorting.

3. Virtual File System

The virtual file system contains a tree like structure with nodes that allows us to interract with the system resources. The current nodes are:

                    "/"
             --------------------
           |    |    |    |    |
          dev  mnt  bin  otp  home
       /   |  \
 ttyUSB0  rtc0 spi0

A task contains a list of struct opened_resource_s which is essentially the struct file from Linux and has the same role. The registered nodes in the virtual file sytem are described by struct vfs_node_s and these keep informations such as:

  • device type
  • supported operations
  • name
  • private data

The open device flow:

open(..) -> vfs_get_matching_node(..) -------
            /\                              |
         Extract the node from the VFS      |
         and call into ops open_cb(..)      |
                                            |
                                      sched_allocate_resource() -----
                                      /\                            |
                               Allocate a new opened_resource_s     |
                               in the calling process.              |
                               Return the index of the              |
                               opened_resource_s structure as       |
                               the file descriptor.                 |
                                                                    |
                -----------------------------------------------------
                |-> vfs_node_open()
                      /\
                   Call the appropriate node open function.

TODO's


The project has a board associated to track issues & request new features:

https://github.com/users/sebastianene07/projects/1#card-30262282


1. Virtual file system support
  1.1 Add support for FatFS http://elm-chan.org/fsw/ff/00index_e.html (DONE)
  1.1.1 Implement SD/MMC driver                                       (DONE)
  1.1.2 Add MTD layer                                                 (DONE)

  1.2 Add functional tests for memory allocator                       (DONE)
  1.3 Add functional tests for the simulator which run in CI          (DONE)

2. Refactorization & Driver lower half/upper half separation          (DONE)
3. Tickless kernel                                                    (DONE)
4. Application support and basic shell                                (DONE)
5. BLE support (with nrf5x family and softdevice)                     (DONE)

Porting Guide

Run the script to add a new board:

user:~/calypso_os/$ ./add_board.sh
do you wish to create a new board [Y/y/n] ?
y
Yes
what name has the board ?
awesome_board
Confirm board name awesome_board [Y/y/n] ?
y
what arch is the board [arm sim template xtensa] ?
x86
ARCH x86 is new. Confirm adding it [Y/y/n] ?
y
Creating board in: arch/x86/awesome_board
Creating config entry in: config/awesome_board
Done !

After this, there are a bunch of filed generated from the template. This files contains sources, makefiles and Kconfig options. A good place to start is to edit the memory layout in the config/${board_name}/scripts/linker.ld The next step is to specify the CROSS COMPILER PREFIX from the defconfig. Check out the board interface defined here: https://github.com/sebastianene07/calypso_os/tree/master/config

To implement the minimum support, define and use the functions marked as MANDATORY.

Contributions

Contributions are welcome.

You can email me on: Sebastian Ene sebastian.ene07@gmail.com

About

Bare metal operating system designed for low power embedded devices with a small memory footprint

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages