• Stars
    star
    3
  • Rank 3,963,521 (Top 79 %)
  • Language
    Ada
  • License
    BSD 3-Clause "New...
  • Created over 2 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Chests are bounded containers

Chests are bounded containers.

Wooden chest (domed lid) with fittings, 17th c.

Many embedded systems do not support dynamic memory allocation, but sometimes you need to process variable-sized things. Chests.Stacks and Chests.Ring_Buffers are generic packages that have a fixed Capacity and only use statically allocated memory.

Getting Started

In your Alire crate's working directory, run

alr with chests

Example

with Chests.Ring_Buffers;
with Ada.Text_IO;

procedure Example is
   package Character_Ring_Buffers is new Chests.Ring_Buffers
      (Element_Type => Character,
       Capacity     => 16);
   use Character_Ring_Buffers;

   Send_Message : constant String := "Hello";
   RB : Ring_Buffer;
begin
   --  Ensure that the buffer is initialized by clearing it
   Clear (RB);

   --  Pretend we're receiving these characters from a UART or something in an
   --  interrupt handler
   for Ch of Send_Message loop
      if not Is_Full (RB) then
         Append (RB, Ch);
      end if;
   end loop;

   --  Now back in the main thread, we've decided it's time to consume all of
   --  the characters in the buffer and convert the message to a string.
   declare
      Receive_Message : String (1 .. Length (RB));
   begin
      for I in Receive_Message'Range loop
         Receive_Message (I) := First_Element (RB);
         Delete_First (RB);
      end loop;
      Ada.Text_IO.Put_Line (Receive_Message);
   end;
end Example;

Why not Ada.Containers.Bounded_Vectors?

The Ada standard library includes some bounded containers. Annex A recommends, but does not require, that implementations of those containers avoid dynamic allocation. Further, these packages depend on other units that are not available with minimal runtimes (aka. ZFP, Light, nostd). Chests have no external dependencies and should work with any Ada runtime.

Performance

All Stack and Ring_Buffer operations are O(1) complexity.

Concurrency

If you need multiple reader/writer concurrency with these data structures, the atomic crate contains locking primitives. For more advanced lock-free buffers, see bbqueue.

Ring_Buffers

The ring buffer can be modified concurrently as long as only one thread is modifying the head or tail of the buffer at a time. For example, you could have a writer calling Append and a reader calling First_Element and Delete_First. Make sure to check not Is_Full and not Is_Empty before performing these operations. Clear is not thread safe.

Stacks

Stack operations are not atomic. Put a lock around it.

Testing

The unit tests run with a set of restrictions that ensure these packages work in ZFP and -nostdlib environments. GNATcoverage reports 100% coverage at the stmt+mcdc level.

Changelog

0.1.1

2022-04-17

  • Removed Chests.Stacks.Elements due to questionable secondary stack usage
  • Element_Array is now with Pack, considerably reducing memory consumption for small element types
  • Chests.Ring_Buffers are now Atomic, with some limitations (see README)
  • Unit tests with ZFP restrictions
  • Added an example program
  • GitHub Actions for CI
  • README updates

0.1.0

2022-04-14

Initial release!

More Repositories

1

tablesnap

Uses inotify to monitor Cassandra SSTables and upload them to S3
Python
181
star
2

repoman

A reprepro and pbuilder management API with a RESTful interface
Python
85
star
3

rp2040_hal

Ada drivers for the Raspberry Pi RP2040 SoC
Ada
35
star
4

pico_examples

Ada examples for the Raspberry Pi Pico
Ada
30
star
5

python-poster

DEPRECATED Streaming HTTP uploads and multipart/form-data encoding
Python
16
star
6

python-digg

Python client implementation for Digg's new writable API
Python
16
star
7

pico_bsp

Ada BSP for the Raspberry Pi Pico
Ada
15
star
8

codenames

Generate codenames similar to those used by the US Armed Forces
Shell
15
star
9

mpegts

Python module for decoding MPEG2 transport streams
Python
12
star
10

notcursesada

Ada bindings for the notcurses text user interface library
Ada
12
star
11

noaaport

NWS NOAAPORT and EMWIN client library for Python
Python
11
star
12

rfid

Python library for interfacing with RFID modules from Seeed Studio
Python
8
star
13

rp

Ada on RP2040 proof of concept
Ada
8
star
14

scrobbleshark

Scrobble track plays from GrooveShark to Last.fm (Python)
Python
8
star
15

fincore

A port of fincore from linux-ftools to a Python C extension
C
7
star
16

dewpoint

A utility library for interacting with clouds
Python
7
star
17

pynewspaper

A python based RSS and NNTP reader
Python
6
star
18

clustoclient

Python client library and utilities for Clusto (http://clusto.org/)
Python
6
star
19

cobalt

A frontend and server for Graphite using nvd3 and clusto
JavaScript
5
star
20

epoll-ada

Ada binding for Linux epoll
Ada
5
star
21

gophernews

Gopher server for reading Digg and Hacker News
Python
5
star
22

pagercal

Generate an iCal feed for PagerDuty schedules
Python
4
star
23

picolua

A minimal example of Lua with Raspberry Pi pico-sdk
C
4
star
24

hue-tricks

Scripts for automating Philips Hue lights.
Python
4
star
25

drivers

An assortment of drivers
Ada
4
star
26

linux_hal

Ada HAL drivers for Linux GPIO and SPI interfaces
Ada
4
star
27

infra

Client tools for clusto
Python
4
star
28

carrier

A RESTful KVM control daemon
Python
4
star
29

advent

Advent of Code - Ada
Ada
4
star
30

wacc

Ada
3
star
31

ipstack

AdaCore TCP/IP stack for high-integrity systems
Ada
3
star
32

tiny_text

Low resolution bitmap font with a small memory footprint
Ada
3
star
33

fah-docker

Folding@Home in a docker container
Dockerfile
3
star
34

bigstack

format stack size reports from GCC's -fstack-usage output
Python
2
star
35

retry

retry: run a command until it succeeds
Ada
2
star
36

synack_misc

Miscellaneous useful packages for embedded projects
Ada
2
star
37

meta-clockwork

Yocto BSP for ClockworkPi boards
PHP
2
star
38

clusto-viz

Visualization tools for clusto
Python
2
star
39

cities

2
star
40

pyfat

A python module for interacting with FAT images
2
star
41

flameon

Campfire to IRC bridge
Python
2
star
42

ada-builder

Docker environment for cross-compiling Ada arm-eabi binaries on x86_64
Dockerfile
2
star
43

robokad

Python
1
star
44

ev3

LEGO Mindstorms EV3
HTML
1
star
45

the_grid

A game demo for the Pimoroni Picosystem
Ada
1
star
46

cyw43

CYW43439 wireless driver
C
1
star
47

picow_test

Test program for Raspberry Pi Pico W
Ada
1
star
48

macropad_bsp

Adafruit Macropad RP2040 BSP (Ada)
Ada
1
star
49

chromesdr

Software Defined Radio in a Chrome App
JavaScript
1
star
50

adafruit_metro_rp2040_bsp

Adafruit Metro RP2040 BSP
Ada
1
star
51

quisk

Software Defined Radio (SDR) written in Python and C
Python
1
star
52

i2c_led_matrix

Ada
1
star
53

msp430test

Demo of SPARK/Ada on MSP430
C
1
star
54

ravenscar_full_rp2040

Ada
1
star
55

ietfnotify

IETF event notification service
1
star
56

learnesp32

Ada on ESP32-C3: Proof of concept
Ada
1
star
57

pico_doc

Documentation for Ada on the Raspberry Pi Pico
HTML
1
star
58

feather51

An 8051 based Feather main-board
Roff
1
star
59

breakouts

Random breakout boards, rarely useful
1
star