Giter Site home page Giter Site logo

templated-memmap-register's Introduction

Memory-Mapped Register Library

This is a C++ library for working with memory-mapped registers in embedded systems. It provides a flexible and type-safe way to access and manipulate registers of various sizes.

Features

  • Support for memory-mapped registers of 8, 16, 32, and 64 bits.
  • Access control for read-only, write-only, and read-write registers.
  • Bitfield access for individual bits within registers.
  • Type-safe conversions between enums and their underlying types.

Usage

To use this library in your embedded project, follow these steps:

  1. Clone the repository to your development environment:

    git clone https://github.com/IvoBrandao/memory-mapped-register-library.git
  2. Include the Library Header

    To access the library's functionality in your C++ source code, include the mmregister.h header file at the beginning of your source files:

    #include "mmregister.h"
  3. Define and Initialize Registers

    Use the Register class to define and initialize memory-mapped registers. Specify the register size (in bits) as a template parameter and provide the memory address of the register as an argument to the constructor. Here's an example of defining a 32-bit read-write register at memory address 0x40000000:

    Register<32> myRegister(0x40000000);
  4. Reading Register Values

    To read the value of a register, simply use the register variable in your code. For example:

    // Read the value of myRegister
    uint32_t value = myRegister;

    This will store the current value of the register in the value variable

  5. Writing Register Values

    To write a value to a register, use the assignment operator (=) with the register variable. For example:

    // Write the value 0x12345678 to myRegister
    myRegister = 0x12345678;

    This will update the register's value to 0x12345678.

  6. Accessing Individual Bits

    The library provides a Bitfield class for accessing individual bits within registers. You can use the Bitfield class to read, write, and manipulate specific bits. Here's an example:

    // Example usage for a 16-bit read-write register at address 0x40000004
    Register<16> statusRegister(0x40000004);
    
    // Access bit 3 of the register
    Register<16>::Bitfield bit3 = statusRegister[3];
    
    // Read the value of bit 3
    bool isBitSet = bit3;
    
    // Set bit 3 to 1
    bit3 = 1;
    

    Use the Bitfield class to interact with individual bits when needed.

License

This library is provided under the MIT License. See the LICENSE file for details.

templated-memmap-register's People

Contributors

ivobrandao avatar

Stargazers

 avatar Micha Hoiting avatar

Watchers

James Cloos avatar  avatar Paulo Felipe Ferreira avatar

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.