All Projects → sendyne → cppreg

sendyne / cppreg

Licence: other
A C++11 header-only library for MMIO registers

Programming Languages

C++
36643 projects - #6 most used programming language
CMake
9771 projects
c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to cppreg

ctrdata
Aggregate and analyse information on clinical trials from public registers
Stars: ✭ 26 (-39.53%)
Mutual labels:  register
mcp4725
mcp4725 full function driver
Stars: ✭ 15 (-65.12%)
Mutual labels:  mcu
at24cxx
at24cxx full function driver
Stars: ✭ 28 (-34.88%)
Mutual labels:  mcu
bmp388
bmp388 full function driver
Stars: ✭ 14 (-67.44%)
Mutual labels:  mcu
pcf8591
pcf8591 full function driver
Stars: ✭ 32 (-25.58%)
Mutual labels:  mcu
ina219
ina219 full function driver
Stars: ✭ 27 (-37.21%)
Mutual labels:  mcu
angular-PubSub
Angular 1.x implementation of the Publish–Subscribe pattern.
Stars: ✭ 32 (-25.58%)
Mutual labels:  register
janus-gateway-live
RTMP edge speed with janus-gateway
Stars: ✭ 38 (-11.63%)
Mutual labels:  mcu
ssd1351
ssd1351 full function driver
Stars: ✭ 34 (-20.93%)
Mutual labels:  mcu
sgp30
sgp30 full function driver
Stars: ✭ 24 (-44.19%)
Mutual labels:  mcu
ionic-login-component
Free sample of Premium Ionic Login Component
Stars: ✭ 17 (-60.47%)
Mutual labels:  register
kurento-group-call-node
kurento group call server
Stars: ✭ 49 (+13.95%)
Mutual labels:  mcu
speaker.app
Source code for https://speaker.app, a batteries-included, web-based, quasi-decentralized, WebRTC networking platform, with a primary focus on audio and screen-sharing, and a secondary focus on chat messages and peripheral features.
Stars: ✭ 26 (-39.53%)
Mutual labels:  mcu
Apriliya-Api
Simple Web API with user authentication
Stars: ✭ 19 (-55.81%)
Mutual labels:  register
FNET
The FNET is a free, open source, dual TCP/IPv4 and IPv6 Stack (under Apache Version 2.0 license) for building embedded communication software on 32bit MCUs.
Stars: ✭ 97 (+125.58%)
Mutual labels:  mcu
RN-login-register-screen
Usage of login / sign-in screen with register / sign-up and forget password screen for authentication in react-native with navigation and Async local storage of input values
Stars: ✭ 32 (-25.58%)
Mutual labels:  register
nanoFramework.Hardware.Esp32
📦 nanoFramework Hardware.Esp32 Class Library
Stars: ✭ 25 (-41.86%)
Mutual labels:  mcu
w25qxx
w25qxx full function driver
Stars: ✭ 440 (+923.26%)
Mutual labels:  mcu
pigweed
pigweed.dev
Stars: ✭ 134 (+211.63%)
Mutual labels:  mcu
non-api-fb-scraper
Scrape public FaceBook posts from any group or user into a .csv file without needing to register for any API access
Stars: ✭ 40 (-6.98%)
Mutual labels:  register

cppreg

Copyright Sendyne Corp., 2010-2019. All rights reserved (LICENSE).

Description

cppreg is a header-only C++11 library to facilitate the manipulation of MMIO registers (i.e., memory-mapped I/O registers) in embedded devices. The idea is to provide a way to write expressive code and minimize the likelihood of ill-defined expressions when dealing with hardware registers on a MCU. The current features are:

  • expressive syntax which shows the intent of the code when dealing with registers and fields,
  • efficiency and performance on par with traditional C implementations (e.g. CMSIS C code) when at least some compiler optimizations are enabled,
  • emphasis on ensuring the assembly is the same if not better than CMSIS versions,
  • field access policies (e.g. read-only vs read-write) detect ill-defined access at compile-time,
  • compile-time detection of overflow,
  • register memory can easily be mocked up so that testing is possible.

For a short introduction and how-to see the quick start guide. A more complete and detailed documentation is available here.

The features provided by cppreg come with no overhead or performance penalty compared to traditional low-level C approaches. We give here an example comparing the assembly generated by a CMSIS-like implementation versus a cppreg-based one.

Requirements

cppreg is designed to be usable on virtually any hardware that satisfies the following requirements:

  • MMIO register sizes are integral numbers of bytes (e.g., 8 bits, 16 bits, ...),
  • registers are properly aligned: a N-bit register is aligned on a N-bit boundary,

GCC (4.8 and above) and Clang (3.3 and above) are supported and it is expected that any other C++11-compliant compiler should work (see the quick start guide for recommended compiler settings).

Manifest

This project started when looking at this type of C code:

// Now we enable the PLL as source for MCGCLKOUT.
MCG->C6 |= (1u << MCG_C6_PLLS_SHIFT);

// Wait for the MCG to use the PLL as source clock.
while ((MCG->S & MCG_S_PLLST_MASK) == 0)
    __NOP();

This piece of code is part of the clock setup on a flavor of the K64F MCU. MCG is a peripheral and MCG->C6 and MCG->S are registers containing some fields which are required to be set to specific values to properly clock the MCU. Some of the issues with such code are:

  • the intent of the code is poorly expressed, and it requires at least the MCU data sheet or reference manual to be somewhat deciphered/understood,
  • since the offsets and masks are known at compile time, it is error prone and somewhat tedious that the code has to re-implement shifting and masking operations,
  • the code syntax itself is extremely error prone; for example, forget the | in |= and you are most likely going to spend some time debugging the code,
  • there is no safety at all, that is, you might overflow the field, or you might try to write to a read-only field and no one will tell you (not the compiler, not the linker, and at runtime this could fail in various ways with little, if any, indication of where is the error coming from).

This does not have to be this way, and C++11 brings a lot of features and concepts that make it possible to achieve the same goal while clearly expressing the intent and being aware of any ill-formed instructions. Some will argue this will come at the cost of a massive performance hit, but this is actually not always the case (and more often than not, a C++ implementation can be very efficient; see Ken Smith paper and the example below).

This project has been inspired by the following previous works:

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].