diff --git a/API.md b/API.md index a6e6782..8cf3c7c 100644 --- a/API.md +++ b/API.md @@ -1,5 +1,5 @@ # cppreg: API # -Copyright Sendyne Corp., 2010-2018. All rights reserved ([LICENSE](LICENSE)). +Copyright Sendyne Corp., 2010-2019. All rights reserved ([LICENSE](LICENSE)). ## Introduction ## @@ -17,15 +17,15 @@ The entire implementation is encapsulated in the `cppreg::` namespace. All the c The API was designed such that `cppreg`-based code is safer and more expressive than traditional low-level code while providing the same level of performance. -As explained below, when using `cppreg`, registers and fields are defined as C++ types specializing pre-defined template types. This can be done by explicitly deriving from the specialized template type or by using the `using` keyword (both approaches are strictly equivalent). With the exception of the merged write mechanism discussed below, all methods provided by the `cppreg` types are static methods. +As explained below, when using `cppreg`, registers and fields are defined as C++ types specializing pre-defined template types. This can be done by explicitly deriving from the specialized template type or by using the `using` keyword (both approaches are strictly equivalent). With the exception of the merged write mechanism discussed below, all methods provided by the `cppreg` types are static methods. ## Data types ## `cppreg` introduces type aliases in order to parameterize the set of data types used in the implementation. By default the following types are defined (see [cppreg_Defines.h](cppreg_Defines.h) for more details): -* `Address_t` is the data type used to hold addresses of registers and fields; it is equivalent to `std::uintptr_t`, +* `Address` is the data type used to hold addresses of registers and fields; it is equivalent to `std::uintptr_t`, * register sizes are represented by the enumeration type `RegBitSize`, -* `FieldWidth_t` and `FieldOffset_t` are the data types to represent field sizes and offsets; both are equivalent to `std::uint8_t`. +* `FieldWidth` and `FieldOffset` are the data types to represent field sizes and offsets; both are equivalent to `std::uint8_t`. ### Register size ### The `RegBitSize` enumeration type represents the register sizes supported in `cppreg` and the values are: @@ -46,7 +46,7 @@ In `cppreg`, registers are represented as memory locations that contain fields, Most of the times registers are part of groups related to peripherals or specific functionalities within a MCU. It is therefore recommended to use the register pack implementation rather than the standalone one. This ensures that the assembly generated from `cppreg`-based code will be optimal. In other words, the difference between packed registers and standalone registers is only a matter of performance in the generated assembly: the packed register interface relies on mapping an array on the pack memory region, which provides to the compiler the ability to use offset between the various registers versus reloading their absolute addresses. -Moreover, the same level of functionality is provided by both implementations (`RegisterPack` is simply deriving from `Register` and redefining accessor and modifier methods). That is, a packed register type can be replaced by a standalone register type (and *vice versa*). +Moreover, the same level of functionality is provided by both implementations (`RegisterPack` is simply deriving from `Register`). That is, a packed register type can be replaced by a standalone register type (and *vice versa*). ### Register pack interface ### To define a pack of registers: @@ -73,7 +73,7 @@ The interface is (see [RegisterPack.h](register/RegisterPack.h)): | `reset_value` | register reset value (defaulted to zero) | | `use_shadow_value` | enable shadow value if `true` (see below) | -Note that, the reset value is only useful when a shadow value is used. +Note that, the reset value is only used when shadow value support is enabled. The following example defines a 4 bytes register pack starting at address 0xA4000000 and containing: two 8-bit register and a 16-bit register. The `cppreg` implementation is: @@ -106,7 +106,7 @@ struct SomePeripheral { } ``` -There are a few requirements for when defining packed registers: +There are a few requirements when defining packed registers: * for a register of size N bits, the pack base address has to be aligned on a N bits boundary, * for a register of size N bits, the pack base address plus the offset has to be aligned on a N bits boundary, @@ -126,7 +126,7 @@ The interface for standalone register is (see [Register.h](register/Register.h)) | `reset_value` | register reset value (defaulted to zero) | | `use_shadow_value` | enable shadow value if `true` (see below) | -Note that, the reset value is only useful when a shadow value is used. +Note that, the reset value is only used when shadow value support is enabled. For example, consider a 32-bit register `SomeRegister` mapped at `0x40004242`. The `Register` type is created using: @@ -226,7 +226,7 @@ static std::array some_buffer = {}; // Iterate over the pack and use a lambda. // Note the "auto index" ... this is required because the loop will // use std::integral_constant to pass the index while iterating. -pack_loop::apply([](auto index) { +pack_loop::apply([](auto index) { some_buffer[index] = Channels::elem::read(); Channels::elem::template write(); }); @@ -305,12 +305,12 @@ SomeField::write<0xAB>(); // Template version for constant value write. SomeField::write(0xAB); // Function argument version. ``` -The advantages of using the constant value version are: +The advantages of using the constant value form are: * `cppreg` will most of the time use a faster implementation for the write operation (this is particularly true if the field spans an entire register), * a compile-time error will occur if the value overflow the field. -Note that, even when using the non-constant value version overflow will not occur: only the bits part of the `Field`-type will be written and any data that does not fit the region of the memory assigned to the `Field`-type will not be modified. For example: +Note that, even when using the non-constant value form overflow will not occur: only the bits fitting in the `Field`-type will be written and any data that does not fit the region of the memory assigned to the `Field`-type will not be modified. For example: ```c++ // Register definition with nested fields definitions. @@ -332,7 +332,7 @@ SomeRegister::Frequency::write<0x111>(); ## Shadow value: a workaround for write-only fields ## -Write-only fields are somewhat special as extra-care has to be taken when manipulating them. The main difficulty resides in the fact that write-only field can be read but the value obtained by reading it is fixed (*e.g.*, it always reads as zero). `cppreg` assumes that write-only fields can actually be read from; if such an access on some given architecture would trigger an error (*à la FPGA*) then `cppreg` is not a good choice to deal with write-only fields on this particular architecture. +Write-only fields are somewhat special and extra-care has to be taken when manipulating them. The main difficulty resides in the fact that write-only field can be read but the value obtained by reading it is fixed (*e.g.* it always reads as zero). `cppreg` assumes that write-only fields can actually be read from; if such an access on some architecture would trigger an error (*à la FPGA*) then `cppreg` is not a good choice to deal with write-only fields on this particular architecture. Consider the following situation: @@ -364,7 +364,7 @@ As a workaround, `cppreg` offers a shadow value implementation which mitigates t struct Reg : Register< 0x40004242, // Register address RegBitSize::b32, // Register size - 0x42u // Register reset value + 0x42u, // Register reset value true // Enable shadow value for the register > { @@ -373,7 +373,7 @@ struct Reg : Register< }; ``` -The shadow value implementation for a write-only field works as follow: +The shadow value implementation for a write-only field works as follows: * at static initialization time, the reset value of the register owning the field is used to initialize the shadow value (the shadow value is used for the entire register content), * at each write access to any of the register fields, the shadow value will be updated and written to the entire register memory. @@ -388,9 +388,9 @@ A few safety guidelines: ## MergeWrite: writing to multiple fields at once ## -It is sometimes the case that multiple fields within a register needs to be written at the same time. For example, when setting the clock dividers in a MCU it is often recommended to write all their values to the corresponding register at the same time (to avoid overclocking part of the MCU). +It is sometimes the case that multiple fields within a register needs to be written at the same time. For example, when setting the clock dividers in a MCU it is often recommended to write all their values to the corresponding register at the same time (to avoid mis-clocking part of the MCU). -Consider the following setup (not so artifical; it is inspired by a real flash memory controller peripheral): +Consider the following setup (not so artificial; it is inspired by a real flash memory controller peripheral): ```c++ struct FlashCtrl : Register<0xF0008282, RegBitSize::b8> { @@ -414,14 +414,14 @@ struct FlashCtrl : Register<0xF0008282, RegBitSize::b8> { Now let's assume the following scenario: -1. The previous flash command failed because it attempted to write or erase in a protected section, at that point the content of the `FlashCtrl` register is `1001 XXXX` where `XXXX` is whatver value associated with the command that failed. +1. The previous flash command failed because it attempted to write or erase in a protected section, at that point the content of the `FlashCtrl` register is `1001 XXXX` where `XXXX` is whatever value associated with the command that failed. 2. Before we can perform a new flash command we need to clear the `ProtectionError` by writing 1 to it (otherwise the new command will not be started); so one could think about doing: ```c++ FlashCtrl::ProtectionError::set(); // Write to ProtectionError to clear it. ``` - however this write at `1000 XXXX | 0001 0000 = 1001 XXXX` at the register level and thus start the command that previously failed. + however this write `1000 XXXX | 0001 0000 = 1001 XXXX` at the register level and thus start the command that previously failed. 3. At this point one could try to set the value for the new command but that will fail as well (because `ProtectionError` was not cleared and it is required to be). 4. A possible alternative would be to fully zero out the `FlashCtrl` register but that would somewhat defeat the purpose of `cppreg`. @@ -434,7 +434,7 @@ FlashCtrl::merge_write().with().with(). ... .done()`. @@ -442,4 +442,3 @@ The `merge_write` method is only available in register type (`PackedRegister` or **Warning:** if`done()` is not called at the end of the successive write operations no write at all will be performed. Similarly to regular write operations it is recommended to use the template version (as shown in the example) if possible: this will enable overflow checking and possibly use faster write implementations. If not possible the values to be written are passed as arguments to the various calls. - diff --git a/Assembly_Comparison.png b/Assembly_Comparison.png index 279b311..dac9328 100644 Binary files a/Assembly_Comparison.png and b/Assembly_Comparison.png differ diff --git a/CMakeLists.txt b/CMakeLists.txt index aec08ea..72fdf49 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,48 +7,50 @@ # -------------------------------------------------------------------------- # -# --- cppreg library files --- +# --- cppreg library --- # Header directories. -set(CPPREG_HEADERS_DIRS +set(cppreg_headers_dirs . policies/ register/) # List of API headers. -set(CPPREG_API_HEADERS +set(cppreg_headers cppreg.h cppreg_Defines.h cppreg_Includes.h policies/AccessPolicy.h register/Field.h + register/Internals.h register/Mask.h - register/Overflow.h + register/Memory.h + register/MergeWrite.h register/Register.h register/RegisterPack.h register/ShadowValue.h register/Traits.h) # Refactor headers directories. -set(BUILD_HEADERS_DIRS "") -foreach(dir IN ITEMS ${CPPREG_HEADERS_DIRS}) - list(APPEND BUILD_HEADERS_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/${dir}") +set(build_cppreg_headers_dirs "") +foreach(dir IN ITEMS ${cppreg_headers_dirs}) + list(APPEND build_cppreg_headers_dirs "${CMAKE_CURRENT_SOURCE_DIR}/${dir}") endforeach() # Header-only library. add_library(cppreg INTERFACE) -target_include_directories(cppreg INTERFACE . register/ policies/) +target_include_directories(cppreg INTERFACE ${cppreg_headers_dirs}) # Include directories interfaces. # This properly setup the API headers for the build and install phase. set_property(TARGET cppreg PROPERTY INTERFACE_INCLUDE_DIRECTORIES - $ + $ $) # --- Install directives --- -install(FILES ${CPPREG_API_HEADERS} DESTINATION include/cppreg) -install(TARGETS cppreg DESTINATION lib EXPORT cppreg-libs) -install(EXPORT cppreg-libs DESTINATION include/cppreg) +install(FILES ${cppreg_headers} DESTINATION include/cppreg) +install(TARGETS cppreg DESTINATION lib EXPORT cppreg-target) +install(EXPORT cppreg-target DESTINATION include/cppreg) diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md deleted file mode 100644 index dc8c621..0000000 --- a/CODE_OF_CONDUCT.md +++ /dev/null @@ -1,46 +0,0 @@ -# Contributor Covenant Code of Conduct - -## Our Pledge - -In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. - -## Our Standards - -Examples of behavior that contributes to creating a positive environment include: - -* Using welcoming and inclusive language -* Being respectful of differing viewpoints and experiences -* Gracefully accepting constructive criticism -* Focusing on what is best for the community -* Showing empathy towards other community members - -Examples of unacceptable behavior by participants include: - -* The use of sexualized language or imagery and unwelcome sexual attention or advances -* Trolling, insulting/derogatory comments, and personal or political attacks -* Public or private harassment -* Publishing others' private information, such as a physical or electronic address, without explicit permission -* Other conduct which could reasonably be considered inappropriate in a professional setting - -## Our Responsibilities - -Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. - -Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. - -## Scope - -This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. - -## Enforcement - -Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at nclauvelin+github@sendyne.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. - -Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. - -## Attribution - -This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] - -[homepage]: http://contributor-covenant.org -[version]: http://contributor-covenant.org/version/1/4/ diff --git a/LICENSE b/LICENSE index ea72536..1716bfc 100644 --- a/LICENSE +++ b/LICENSE @@ -5,7 +5,7 @@ /____/\___/_/ /_/\__,_/\__, /_/ /_/\___/ \___/\____/_/ / .___(_). /____/ /_/ - Copyright 2010-2018 Sendyne Corporation. + Copyright 2010-2019 Sendyne Corporation. All rights reserved. Sendyne Corp., 250 West Broadway, New York, NY 10013, USA. diff --git a/Performance.md b/Performance.md index 95417c4..046424b 100644 --- a/Performance.md +++ b/Performance.md @@ -1,9 +1,9 @@ # Performance analysis -`cppreg` is heavily based on C++ templates and introduces various levels of abstractions compared to a traditional C CMSIS implementation. Because of C++'s *zero overhead* capabilities (see [this](https://www.youtube.com/watch?v=zBkNBP00wJE) for example) and when using at least some level of compiler otpimizations **all** the `cppreg` interface code is optimized away. Understandably most would question the validity of such a claim, so this document shows a classic example showing that a register interface written with `cppreg` is just as fast as the corresponding CMSIS based code written in C (and in this particular case is identical). +`cppreg` is heavily based on C++ templates and introduces various levels of abstractions compared to a traditional C CMSIS implementation. Because of C++'s *zero overhead* capabilities (see [this](https://www.youtube.com/watch?v=zBkNBP00wJE) for example) and when using at least some level of compiler otpimizations *all* the `cppreg` interface code is optimized away. Understandably most would question the validity of such a claim, so this document demonstrates a classic example showing that a register interface written with `cppreg` produced a compiled code identical to a CMSIS-based one. -## Test Setup -For the test example, let's use an imaginary Cortex-M0 based microcontroller with the intention of having the UART send out a small string and then toggle two LEDs (PIN1 and PIN3) after every full string transmission. Why imaginary? Because a real implementation will be longer than most screens. The example is written in C using CMSIS style, and then in C++ using `cppreg`. We then compare the assembly outputs of both using GCC ARM with links to GodBolt so that the examples can be fiddled with. +## Test setup +For the test example, let's use an imaginary Cortex-M0 based micro-controller with the intention of having the UART send out a small string and then toggle two LEDs (PIN1 and PIN3) after every transmission. Why imaginary? Because a real implementation will be longer than most screens. The example is written in C using CMSIS style, and then in C++ using `cppreg`. We then compare the assembly outputs of both using GCC ARM with links to GodBolt so that the examples can be fiddled with. ### Example peripheral @@ -165,9 +165,9 @@ void Demo_CPPReg(void){ ## Assembly results and comparison -[This][godbolt] is how GodBolt compares the CMSIS and `cppreg` versions. Looking at the assembly, it's pretty much identical, with the only difference being when to save registers onto the stack (in this case having no performance penalty). For this example (as well as others which have been tested), there is **no** performance penalty in `cppreg` implementation; here is a comparison of the assembly outputs (obtained with GCC ARM `-mthumb -Os`): +[This][godbolt] is how GodBolt compares the CMSIS and `cppreg` versions. Looking at the assembly, it's pretty much identical, with the only difference being when to save registers onto the stack (in this case having no performance penalty). For this example (as well as others which have been tested), there is *no* performance penalty in the `cppreg` implementation; here is a comparison of the assembly outputs (obtained with GCC ARM `-mthumb -Os`): ![Assembly Comparison](Assembly_Comparison.png) -[godbolt]: https://godbolt.org/#z:OYLghAFBqd5TKALEBjA9gEwKYFFMCWALugE4A0BIEAViAIzkA2AhgHaioCkATAEK8%2B5AM7oArqVTYQAcgD0csGADUqAA5rS2YMqYEARqRakAngDouABgCCcgFR2r15XeUABAGYEm2ZX//qmtoAtCxMTGZITi7uLGJESGT%2BygByBBiswsoAwqxiAG7YemzKEGyoeYXFbsLYbJgmbNhmGAC2AJTRrm4YaiakBMBIRDnofQNDIzyW9JbB0/QAHMoAynUNTaOkambK1uHKE8NZWrWkhZgWNi5yTnc8AMwE5UxiOMpcD9mowkSEbERPrh7k8Xm9fJ9skQTGpsAB9IhGYjCIEg54VcEfL4eMTlIgEdBsMKomy8UEY96QvStZEk6xOBSqDRaYBwgAi2C8TWEkTRHnqnJyAAUhQAlXAAcTh2RF4qlbNwADEAJIpXArOEACRBOC5vhlYsl0tlRoVKrVGu1NiJrWwwjULCkTKCOi4AHYBNd/GJhM8dNZMJhTsIEVi2cpfpgQCAxM8iGpEQjPp7nP46mJWqpMllRdo%2BMQVgQAF4Qj3RZL%2BfSLcgV8sV5T6egANhr/jrFf0Dx4rb87eS%2BibABZa17e262cn2z6/cpFQQipgAOoETAJUOfcOR6OxgGLJMPFPJaccWfzpiYADyHg8tSI64em7%2B27je8BB/bRGwrTUrE/WKhMJ1CwtrKAAKnSyS/KQYioCM0KwnCrQsMIADWHxlqOFYYGwvzYAAHpoEZECw%2BKoKohK/GByj5GEYgQg%2BRFRiAbAZtgAyoHC1K0l84EPLg0ZIXhECdO%2BmHuhOon0uOILrAQHi9qSNiMqBSJEDyUSko8ckCvJBpynCoGitYyqgZaOqcs8%2BomlKhnGaZWpODadoOk6gQsuhh7%2BJ%2B36/vR2S5sA%2BZEIWJarBB/hQTBIygYBKksNxnl%2BN5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12tnFjnZws7oc8ByXmz8x7PaVOATwEPoQkCADHBAA%3D%3D%3D diff --git a/QuickStart.md b/QuickStart.md index 61cd01a..cab61d8 100644 --- a/QuickStart.md +++ b/QuickStart.md @@ -1,5 +1,5 @@ # cppreg: quick start # -Copyright Sendyne Corp., 2010-2018. All rights reserved ([LICENSE](LICENSE)). +Copyright Sendyne Corp., 2010-2019. All rights reserved ([LICENSE](LICENSE)). This document is a brief introduction to `cppreg` and how to use it. For more details about the implementation refers to the [API documentation](API.md). @@ -14,7 +14,8 @@ There are two recommended ways to use `cppreg` in a project: # Include cppreg library. # The second argument is not necessarily required depending on the project setup. # This will import the cppreg target. - # Because cppreg is a header-only library the cppreg target is actually an INTERFACE library target. + # Because cppreg is a header-only library the cppreg target is actually an + # INTERFACE library target. add_subdirectory(/path/to/cppreg ${PROJECT_BINARY_DIR)/cppreg) ... @@ -59,7 +60,7 @@ The RX and TX data registers both contain a single DATA field occupying the whol The goal of `cppreg` is to facilitate the manipulation of such a peripheral. This can be done as follow: ```c++ -#include // use cppreg-all.h instead if you are using the single header. +#include // use cppreg-all.h if you are using the single header. using namespace cppreg; // Peripheral structure. @@ -150,7 +151,7 @@ while (true) { A few remarks: -* the `write` calls for the `Setup` register pass the data as template arguments, while the write call for the `TX` register pass it as a function argument: if the value to be written is known at compile time it is recommended to use the template form; the template form will detect overflow (see below) and will also make it possible to use a faster write implementation in some cases, +* the `write` calls for the `Setup` register pass the data as template arguments, while the write call for the `TX` register pass it as a function argument: if the value to be written is known at compile time it is recommended to use the template form; the template form will detect overflow (see below) and will also make it possible to use a more efficient write implementation in some cases, * `Field`-based types have `is_set` and `is_clear` defined to conveniently query their states. In this example, we can already see how `cppreg` limits the possibility of errors (see the [API documentation](API.md) for more details): diff --git a/README.md b/README.md index eef93df..022f3c2 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,24 @@ # cppreg # -Copyright Sendyne Corp., 2010-2018. All rights reserved ([LICENSE](LICENSE)). +Copyright Sendyne Corp., 2010-2019. All rights reserved ([LICENSE](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 make it possible to write expressive code and minimize the likelihood of ill-defined expressions when dealing with hardware registers on a MCU. The current features are: +`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, -* [huge emphasis](Performance.md) 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, +* efficiency and performance on par with traditional C implementations (*e.g.* CMSIS C code) when *at least some compiler optimizations* are enabled, +* [emphasis](Performance.md) 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, -* easily extendable to support, for example, mock-up. +* register memory can easily be mocked up so that testing is possible. For a short introduction and how-to see the [quick start guide](QuickStart.md). A more complete and detailed documentation is available [here](API.md). -The features provided by `cppreg` come with no overhead or performance penalty compared to traditional low-level C approaches. We give [here](Performance.md) an example comparing the assembly generated by a CMSIS-like implementation versus a `cppreg` one. +The features provided by `cppreg` come with no overhead or performance penalty compared to traditional low-level C approaches. We give [here](Performance.md) 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 statisfies the following 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, @@ -41,11 +41,11 @@ while ((MCG->S & MCG_S_PLLST_MASK) == 0) 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 manually implement shifting and masking operations, +* 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 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: diff --git a/cppreg.h b/cppreg.h index 759ec50..fbf3058 100644 --- a/cppreg.h +++ b/cppreg.h @@ -2,7 +2,7 @@ /** * @file cppreg.h * @author Nicolas Clauvelin (nclauvelin@sendyne.com) - * @copyright Copyright 2010-2018 Sendyne Corp. All rights reserved. + * @copyright Copyright 2010-2019 Sendyne Corp. All rights reserved. */ @@ -10,11 +10,11 @@ #define CPPREG_CPPREG_H +#include "Field.h" #include "Internals.h" #include "MergeWrite.h" #include "Register.h" #include "RegisterPack.h" -#include "Field.h" -#endif // CPPREG_CPPREG_H +#endif // CPPREG_CPPREG_H diff --git a/cppreg_Defines.h b/cppreg_Defines.h index b6d0046..4feccb9 100644 --- a/cppreg_Defines.h +++ b/cppreg_Defines.h @@ -2,7 +2,7 @@ /** * @file cppreg_Defines.h * @author Nicolas Clauvelin (nclauvelin@sendyne.com) - * @copyright Copyright 2010-2018 Sendyne Corp. All rights reserved. + * @copyright Copyright 2010-2019 Sendyne Corp. All rights reserved. * * This header mostly defines data types used across the project. These data * types have been defined with 32-bits address space hardware in mind. It @@ -17,50 +17,49 @@ #include "cppreg_Includes.h" -//! cppreg namespace. namespace cppreg { - //! Type alias for register and field addresses. - /** - * By design this type ensures that any address can be stored. - */ - using Address_t = std::uintptr_t; +//! Type alias for register and field addresses. +/** + * By design this type ensures that any address can be stored. + */ +using Address = std::uintptr_t; - //! Enumeration type for register size in bits. - /** - * This is used to enforce the supported register sizes. - */ - enum class RegBitSize { - b8, //!< 8-bit register. - b16, //!< 16-bit register. - b32, //!< 32-bit register. - b64 //!< 64-bit register. - }; - - - //! Type alias field width. - using FieldWidth_t = std::uint8_t; +//! Enumeration type for register size in bits. +/** + * This is used to enforce the supported register sizes. + */ +enum class RegBitSize : std::uint8_t { + b8, //!< 8-bit register. + b16, //!< 16-bit register. + b32, //!< 32-bit register. + b64 //!< 64-bit register. +}; - //! Type alias for field offset. - using FieldOffset_t = std::uint8_t; +//! Type alias field width. +using FieldWidth = std::uint8_t; - //! Shorthand for max value as a mask. - /** - * @tparam T Data type. - * - * This is used to define register masks. - */ - template - struct type_mask { - constexpr static const T value = std::numeric_limits::max(); - }; +//! Type alias for field offset. +using FieldOffset = std::uint8_t; -} +//! Shorthand for max value as a mask. +/** + * @tparam T Data type. + * + * This is used to define register masks. + */ +template +struct type_mask { + constexpr static const T value = std::numeric_limits::max(); +}; -#endif // CPPREG_CPPREG_DEFINES_H +} // namespace cppreg + + +#endif // CPPREG_CPPREG_DEFINES_H diff --git a/cppreg_Includes.h b/cppreg_Includes.h index 541217c..494b23c 100644 --- a/cppreg_Includes.h +++ b/cppreg_Includes.h @@ -2,7 +2,7 @@ /** * @file cppreg_Defines.h * @author Nicolas Clauvelin (nclauvelin@sendyne.com) - * @copyright Copyright 2010-2018 Sendyne Corp. All rights reserved. + * @copyright Copyright 2010-2019 Sendyne Corp. All rights reserved. */ @@ -15,4 +15,4 @@ #include -#endif // CPPREG_CPPREG_INCLUDES_H +#endif // CPPREG_CPPREG_INCLUDES_H diff --git a/policies/AccessPolicy.h b/policies/AccessPolicy.h index 898c400..4cabdbb 100644 --- a/policies/AccessPolicy.h +++ b/policies/AccessPolicy.h @@ -2,7 +2,7 @@ /** * @file AccessPolicy.h * @author Nicolas Clauvelin (nclauvelin@sendyne.com) - * @copyright Copyright 2010-2018 Sendyne Corp. All rights reserved. + * @copyright Copyright 2010-2019 Sendyne Corp. All rights reserved. * * Access policies are used to describe if register fields are read-write, * read-only or write-only. @@ -14,7 +14,7 @@ * the register proper masking and shifting is required. The switch between * trivial and non-trivial implementations is done automatically. * - The write implementation also distinguishes between writing constant - * values (i.e., known at compile time) and non-constant value. This was + * values (i.e., known at compile time) and non-constant value. This is * intended to make it possible to simplify operations at compile time and * minimize overhead. */ @@ -27,318 +27,288 @@ #include "cppreg_Defines.h" -//! cppreg namespace. namespace cppreg { - //! Register read implementation. +//!@{ Trivial register read/write detector. + +//! Boolean flag to detect trivial read/write. +/** + * @tparam T Register data type. + * @tparam mask Mask for the read operation. + * @tparam offset Offset for the read operation. + */ +template +struct is_trivial_rw + : std::integral_constant::value) + && (offset == FieldOffset{0})> {}; + +//! Trivial read/write enable_if helper. +/** + * @tparam T Register data type. + * @tparam mask Mask for the read operation. + * @tparam offset Offset for the read operation. + * @tparam U Enabled type if trivial. + */ +template +using is_trivial = + typename std::enable_if::value, U>::type; + +//! Non-trivial read/write enable_if helper. +/** + * @tparam T Register data type. + * @tparam mask Mask for the read operation. + * @tparam offset Offset for the read operation. + * @tparam U Enabled type if non-trivial. + */ +template +using is_not_trivial = + typename std::enable_if::value, U>::type; + +//!@} + + +//! Register read implementation. +/** + * @tparam MMIO Memory device type. + * @tparam T Register data type. + * @tparam mask Mask for the read operation. + * @tparam offset Offset for the read operation. + */ +template +struct RegisterRead { + + //! Non-trivial read implementation. /** - * @tparam MMIO_t Memory device type. - * @tparam T Register data type. - * @tparam mask Mask for the read operation. - * @tparam offset Offset for the read operation. - * - * The mask and offset are used to define a specific field within the - * register. + * @param mmio_device Pointer to the register memory device. + * @return The content of the register field. */ - template - struct RegisterRead { + template + static T read(const MMIO& mmio_device, + is_not_trivial* = nullptr) noexcept { + return static_cast((mmio_device & mask) >> offset); + } - //! Boolean flag for trivial implementation. - /** - * The trivial corresponds to reading the whole register, that is, - * the mask is identity and the offset is zero. - */ - constexpr static const bool is_trivial = - (mask == type_mask::value) && (offset == 0u); - - //! Non-trivial read implementation. - /** - * @param mmio_device Pointer to the register memory device. - * @return The content of the register field. - */ - template - static T read( - const MMIO_t& mmio_device, - typename std::enable_if::type = nullptr - ) noexcept { - return static_cast((mmio_device & mask) >> offset); - }; - - //! Trivial read implementation. - /** - * @param mmio_device Pointer to the register memory device. - * @return The content of the register field. - */ - template - static T read( - const MMIO_t& mmio_device, - typename std::enable_if::type = nullptr - ) noexcept { - return static_cast(mmio_device); - }; - - }; - - - //! Register write implementation. + //! Trivial read implementation. /** - * @tparam MMIO_t Memory device type. - * @tparam T Register data type. - * @tparam mask Mask for the read operation. - * @tparam offset Offset for the read operation. - * - * The mask and offset are used to define a specific field within the - * register. - * - * This write implementation is used only when the value to be written is - * not a constant expression. + * @param mmio_device Pointer to the register memory device. + * @return The content of the register field. */ - template - struct RegisterWrite { - - //! Boolean flag for trivial implementation. - /** - * The trivial corresponds to writing to the whole register, that is, - * the mask is identity and the offset is zero. - */ - constexpr static const bool is_trivial = - (mask == type_mask::value) && (offset == 0u); - - //! Non-trivial write implementation. - /** - * @param mmio_device Pointer to the register memory device. - * @param value Value to be written to the register field. - */ - template - static void write( - MMIO_t& mmio_device, - T value, - typename std::enable_if::type = nullptr - ) noexcept { - mmio_device = static_cast( - (mmio_device & ~mask) | ((value << offset) & mask) - ); - }; - - //! Trivial write implementation. - /** - * @param mmio_device Pointer to the register memory device. - * @param value Value to be written to the register field. - */ - template - static void write( - MMIO_t& mmio_device, - T value, - typename std::enable_if::type = nullptr - ) noexcept { - mmio_device = value; - }; - - }; + template + static T read(const MMIO& mmio_device, + is_trivial* = nullptr) noexcept { + return static_cast(mmio_device); + } +}; - //! Register write constant implementation. +//! Register write implementation. +/** + * @tparam MMIO Memory device type. + * @tparam T Register data type. + * @tparam mask Mask for the read operation. + * @tparam offset Offset for the read operation. + */ +template +struct RegisterWrite { + + //! Non-trivial write implementation. /** - * @tparam MMIO_t Memory device type. - * @tparam T Register data type. - * @tparam mask Mask for the read operation. - * @tparam offset Offset for the read operation. - * @tparam value Value to be written to the register field. - * - * The mask and offset are used to define a specific field within the - * register. - * - * This write implementation is used only when the value to be written is - * a constant expression. + * @param mmio_device Pointer to the register memory device. + * @param value Value to be written to the register field. */ - template < - typename MMIO_t, typename T, T mask, FieldOffset_t offset, T value - > - struct RegisterWriteConstant { + template + static void write(MMIO& mmio_device, + T value, + is_not_trivial* = nullptr) noexcept { + mmio_device = + static_cast((mmio_device & ~mask) | ((value << offset) & mask)); + } - //! Boolean flag for trivial implementation. - /** - * The trivial corresponds to writing to the whole register, that is, - * the mask is identity and the offset is zero. - */ - constexpr static const bool is_trivial = - (mask == type_mask::value) && (offset == 0u); - - //! Non-trivial write implementation. - /** - * @param mmio_device Pointer to the register memory device. - */ - template - static void write( - MMIO_t& mmio_device, - typename std::enable_if::type = nullptr - ) noexcept { - mmio_device = static_cast( - (mmio_device & ~mask) | ((value << offset) & mask) - ); - }; - - //! Trivial write implementation. - /** - * @param mmio_device Pointer to the register memory device. - */ - template - static void write( - MMIO_t& mmio_device, - typename std::enable_if::type = nullptr - ) noexcept { - mmio_device = value; - }; - - }; + //! Trivial write implementation. + /** + * @param mmio_device Pointer to the register memory device. + * @param value Value to be written to the register field. + */ + template + static void write(MMIO& mmio_device, + T value, + is_trivial* = nullptr) noexcept { + mmio_device = value; + } +}; - //! Read-only access policy. - struct read_only { +//! Register write constant implementation. +/** + * @tparam MMIO Memory device type. + * @tparam T Register data type. + * @tparam mask Mask for the read operation. + * @tparam offset Offset for the read operation. + * @tparam value Value to be written to the register field. + */ +template +struct RegisterWriteConstant { - //! Read access implementation. - /** - * @tparam MMIO_t Register memory device type. - * @tparam T Field data type. - * @tparam mask Field mask. - * @tparam offset Field offset. - * @param mmio_device Pointer to register mapped memory. - * @return The value at the field location. - */ - template - static T read(const MMIO_t& mmio_device) noexcept { - return RegisterRead::read(mmio_device); - }; + //! Non-trivial write implementation. + /** + * @param mmio_device Pointer to the register memory device. + */ + template + static void write(MMIO& mmio_device, + is_not_trivial* = nullptr) noexcept { + mmio_device = + static_cast((mmio_device & ~mask) | ((value << offset) & mask)); + } - }; + //! Trivial write implementation. + /** + * @param mmio_device Pointer to the register memory device. + */ + template + static void write(MMIO& mmio_device, + is_trivial* = nullptr) noexcept { + mmio_device = value; + } +}; - //! Read-write access policy. - struct read_write : read_only { +//! Read-only access policy. +struct read_only { - //! Write access implementation. - /** - * @tparam MMIO_t Register memory device type. - * @tparam T Field data type. - * @tparam mask Field mask. - * @tparam offset Field offset. - * @param mmio_device Pointer to register mapped memory. - * @param value Value to be written at the field location. - */ - template - static void write(MMIO_t& mmio_device, - const T value) noexcept { - RegisterWrite::write(mmio_device, value); - }; - - //! Write access implementation for constant value. - /** - * @tparam MMIO_t Register memory device type. - * @tparam T Field data type. - * @tparam mask Field mask. - * @tparam offset Field offset. - * @tparam value Value to be written at the field location. - * @param mmio_device Pointer to register mapped memory. - */ - template < - typename MMIO_t, typename T, T mask, FieldOffset_t offset, T value - > - static void write(MMIO_t& mmio_device) noexcept { - RegisterWriteConstant - ::write(mmio_device); - }; - - //! Set field implementation. - /** - * @tparam T Field data type. - * @tparam mask Field mask. - * @param mmio_device Pointer to register mapped memory. - */ - template - static void set(MMIO_t& mmio_device) - noexcept { - RegisterWriteConstant - ::write(mmio_device); - }; - - //! Clear field implementation. - /** - * @tparam MMIO_t Register memory device type. - * @tparam T Field data type. - * @tparam mask Field mask. - * @param mmio_device Pointer to register mapped memory. - */ - template - static void clear(MMIO_t& mmio_device) - noexcept { - RegisterWriteConstant - ::write(mmio_device); - }; - - //! Toggle field implementation. - /** - * @tparam MMIO_t Register memory device type. - * @tparam T Field data type. - * @tparam mask Field mask. - * @param mmio_device Pointer to register mapped memory. - */ - template - static void toggle(MMIO_t& mmio_device) - noexcept { - mmio_device = static_cast((mmio_device) ^ mask); - }; - - }; + //! Read access implementation. + /** + * @tparam MMIO Register memory device type. + * @tparam T Field data type. + * @tparam mask Field mask. + * @tparam offset Field offset. + * @param mmio_device Pointer to register mapped memory. + * @return The value at the field location. + */ + template + static T read(const MMIO& mmio_device) noexcept { + return RegisterRead::read(mmio_device); + } +}; - //! Write-only access policy. - struct write_only { +//! Read-write access policy. +struct read_write : read_only { - //! Write access implementation. - /** - * @tparam MMIO_t Register memory device type. - * @tparam T Field data type. - * @tparam mask Field mask. - * @tparam offset Field offset - * @param mmio_device Pointer to register mapped memory. - * @param value Value to be written at the field location. - */ - template - static void write(MMIO_t& mmio_device, const T value) noexcept { + //! Write access implementation. + /** + * @tparam MMIO Register memory device type. + * @tparam T Field data type. + * @tparam mask Field mask. + * @tparam offset Field offset. + * @param mmio_device Pointer to register mapped memory. + * @param value Value to be written at the field location. + */ + template + static void write(MMIO& mmio_device, const T value) noexcept { + RegisterWrite::write(mmio_device, value); + } - // For write-only fields we can only write to the whole register. - RegisterWrite::value, 0u>::write( - mmio_device, ((value << offset) & mask) - ); - }; + //! Write access implementation for constant value. + /** + * @tparam MMIO Register memory device type. + * @tparam T Field data type. + * @tparam mask Field mask. + * @tparam offset Field offset. + * @tparam value Value to be written at the field location. + * @param mmio_device Pointer to register mapped memory. + */ + template + static void write(MMIO& mmio_device) noexcept { + RegisterWriteConstant::write(mmio_device); + } - //! Write access implementation for constant value. - /** - * @tparam MMIO_t Register memory device type. - * @tparam T Field data type. - * @tparam mask Field mask. - * @tparam offset Field offset - * @tparam value Value to be written at the field location. - * @param mmio_device Pointer to register mapped memory. - */ - template < - typename MMIO_t, typename T, T mask, FieldOffset_t offset, T value - > - static void write(MMIO_t& mmio_device) noexcept { + //! Set field implementation. + /** + * @tparam T Field data type. + * @tparam mask Field mask. + * @param mmio_device Pointer to register mapped memory. + */ + template + static void set(MMIO& mmio_device) noexcept { + RegisterWriteConstant::write( + mmio_device); + } - // For write-only fields we can only write to the whole register. - RegisterWriteConstant< - MMIO_t, T, type_mask::value, 0u, ((value << offset) & mask) - > - ::write(mmio_device); + //! Clear field implementation. + /** + * @tparam MMIO Register memory device type. + * @tparam T Field data type. + * @tparam mask Field mask. + * @param mmio_device Pointer to register mapped memory. + */ + template + static void clear(MMIO& mmio_device) noexcept { + RegisterWriteConstant(~mask)>::write(mmio_device); + } - }; - - }; + //! Toggle field implementation. + /** + * @tparam MMIO Register memory device type. + * @tparam T Field data type. + * @tparam mask Field mask. + * @param mmio_device Pointer to register mapped memory. + */ + template + static void toggle(MMIO& mmio_device) noexcept { + mmio_device = static_cast((mmio_device) ^ mask); + } +}; -} +//! Write-only access policy. +struct write_only { + + //! Write access implementation. + /** + * @tparam MMIO Register memory device type. + * @tparam T Field data type. + * @tparam mask Field mask. + * @tparam offset Field offset + * @param mmio_device Pointer to register mapped memory. + * @param value Value to be written at the field location. + */ + template + static void write(MMIO& mmio_device, const T value) noexcept { + + // For write-only fields we can only write to the whole register. + RegisterWrite::value, FieldOffset{0}>::write( + mmio_device, ((value << offset) & mask)); + } + + //! Write access implementation for constant value. + /** + * @tparam MMIO Register memory device type. + * @tparam T Field data type. + * @tparam mask Field mask. + * @tparam offset Field offset + * @tparam value Value to be written at the field location. + * @param mmio_device Pointer to register mapped memory. + */ + template + static void write(MMIO& mmio_device) noexcept { + + // For write-only fields we can only write to the whole register. + RegisterWriteConstant::value, + FieldOffset{0}, + ((value << offset) & mask)>::write(mmio_device); + } +}; -#endif // CPPREG_ACCESSPOLICY_H +} // namespace cppreg + + +#endif // CPPREG_ACCESSPOLICY_H diff --git a/register/Field.h b/register/Field.h index 8a318be..76e8849 100644 --- a/register/Field.h +++ b/register/Field.h @@ -2,11 +2,11 @@ /** * @file Field.h * @author Nicolas Clauvelin (nclauvelin@sendyne.com) - * @copyright Copyright 2010-2018 Sendyne Corp. All rights reserved. + * @copyright Copyright 2010-2019 Sendyne Corp. All rights reserved. * * This header provides the definitions related to register field - * implementation. - * Strictly speaking a field is defined as a region of a register. + * implementation. Strictly speaking a field is defined as a region of a + * register. */ @@ -14,225 +14,195 @@ #define CPPREG_REGISTERFIELD_H -#include "Register.h" -#include "Mask.h" #include "AccessPolicy.h" -#include "ShadowValue.h" +#include "Internals.h" +#include "Mask.h" -//! cppreg namespace. namespace cppreg { - //! Register field implementation. + +//! Register field implementation. +/** + * @tparam BaseRegister Parent register. + * @tparam width Field width. + * @tparam offset Field offset. + * @tparam P Access policy type. + * + * This data structure provides static methods to deal with field access + * (read, write, set, clear, and toggle). These methods availability depends + * on the access policy (e.g., a read-only field does not implement a + * write method). + * In practice, fields are implemented by deriving from this class to + * create custom types. + */ +template +struct Field { + + //! Parent register for the field. + using parent_register = BaseRegister; + + //! Field data type derived from register data type. + using type = typename parent_register::type; + + //! MMIO type. + using MMIO = typename parent_register::MMIO; + + //! Field policy. + using policy = AccessPolicy; + + //! Field width. + constexpr static auto width = field_width; + + //! Field offset. + constexpr static auto offset = field_offset; + + //! Field mask. + constexpr static auto mask = make_shifted_mask(width, offset); + + //!@{ Helpers for write method selection based on shadow value. + template + using if_no_shadow = + typename std::enable_if::type; + template + using if_shadow = + typename std::enable_if::type; + //!@} + + //!@ Field read method. /** - * @tparam BaseRegister Parent register. - * @tparam width Field width. - * @tparam offset Field offset. - * @tparam P Access policy type. - * - * This data structure provides static methods to deal with field access - * (read, write, set, clear, and toggle). These methods availability depends - * on the access policy (e.g., a read-only field does not implement a - * write method). - * In practice, fields are implemented by deriving from this class to - * create custom types. + * @return Field value. */ - template < - typename BaseRegister, - FieldWidth_t field_width, - FieldOffset_t field_offset, - typename AccessPolicy - > - struct Field { + static type read() noexcept { + return policy::template read( + parent_register::ro_mem_device()); + } - //! Parent register for the field. - using parent_register = BaseRegister; + //! Field write value method (no shadow value). + /** + * @param value Value to be written to the field. + */ + template + static void write(const if_no_shadow value) noexcept { + policy::template write( + parent_register::rw_mem_device(), value); + } - //! Field data type derived from register data type. - using type = typename parent_register::type; + //! Field write value method (w/ shadow value). + /** + * @param value Value to be written to the field. + */ + template + static void write(const if_shadow value) noexcept { - //! MMIO type. - using MMIO_t = typename parent_register::MMIO_t; + // Update shadow value. + RegisterWrite::write( + parent_register::shadow::shadow_value, value); - //! Field policy. - using policy = AccessPolicy; - - //! Field width. - constexpr static const FieldWidth_t width = field_width; - - //! Field offset. - constexpr static const FieldOffset_t offset = field_offset; - - //! Field mask. - constexpr static const type mask = make_shifted_mask(width, - offset); - - //! Boolean flag indicating if a shadow value is used. - constexpr static const bool has_shadow = - parent_register::shadow::value; - - //! Customized overflow check implementation for Field types. - /** - * @tparam value Value to be checked for overflow. - * @return `true` if no overflow, `false` otherwise. - * - * This is only used for the template form of the write method. - */ - template - struct check_overflow : internals::check_overflow< - type, - value, - (mask >> offset) - > {}; - - //!@ Field read method. - /** - * @return Field value. - */ - static type read() noexcept { - return policy::template read( - parent_register::ro_mem_device() - ); - }; - - //! Field write method (no shadow value). - /** - * @param value Value to be written to the field. - */ - template - static void - write(const typename std::enable_if::type value) - noexcept { - policy::template write( + // Write as a block to the register, that is, we do not use the + // field mask and field offset. + policy:: + template write::value, FieldOffset{0}>( parent_register::rw_mem_device(), - value - ); - }; + parent_register::shadow::shadow_value); + } - //! Field write method (w/ shadow value). - /** - * @param value Value to be written to the field. - */ - template - static void - write(const typename std::enable_if::type value) - noexcept { + //! Field write constant method (no shadow value). + /** + * @tparam value Constant to be written to the field + * + * This method performs a compile-time check to avoid overflowing the + * field and uses the constant write implementation. + */ + template + static void write(if_no_shadow* = nullptr) noexcept { + policy::template write( + parent_register::rw_mem_device()); - // Update shadow value. - // This assumes that reading a write-only fields return some value. - RegisterWrite - ::write(parent_register::shadow::shadow_value, value); + // Check for overflow. + static_assert( + internals::check_overflow> offset)>::value, + "Field::write: value too large for the field"); + } - // Write as a block to the register, that is, we do not use the - // mask and offset. - policy::template write::value, 0u>( - parent_register::rw_mem_device(), - parent_register::shadow::shadow_value - ); + //! Field write constant method (w/ shadow value). + /** + * @tparam value Constant to be written to the field + * + * This method performs a compile-time check to avoid overflowing the + * field and uses the constant write implementation. + */ + template + static void write(if_shadow* = nullptr) noexcept { + // For this one we simply forward to the non-constant + // implementation because the shadow value needs to be updated. + write(value); - }; + // Check for overflow. + static_assert( + internals::check_overflow> offset)>::value, + "Field::write: value too large for the field"); + } - //! Field write method with overflow check (no shadow value). - /** - * @tparam value Value to be written to the field - * - * This method performs a compile-time check to avoid overflowing the - * field and uses the constant write implementation. - */ - template - static void write( - typename std::enable_if< - !has_shadow - && - check_overflow::value, - T - >::type* = nullptr - ) noexcept { - policy::template write( - parent_register::rw_mem_device() - ); - }; + //! Field set method. + /** + * This method will set all bits in the field. + */ + static void set() noexcept { + policy::template set( + parent_register::rw_mem_device()); + } - //! Field write method with overflow check (w/ shadow value). - /** - * @tparam value Value to be written to the field - * - * This method performs a compile-time check to avoid overflowing the - * field and uses the constant write implementation. - */ - template - static void write( - typename std::enable_if< - has_shadow - && - check_overflow::value, - T - >::type* = nullptr - ) noexcept { + //! Field clear method. + /** + * This method will clear all bits in the field. + */ + static void clear() noexcept { + policy::template clear( + parent_register::rw_mem_device()); + } - // For this particular we simply forward to the non-constant - // implementation because the shadow value needs to be updated. - write(value); + //! Field toggle method. + /** + * This method will toggle all bits in the field. + */ + static void toggle() noexcept { + policy::template toggle( + parent_register::rw_mem_device()); + } - }; + //! Is field set bool method. + /** + * @return `true` if all the bits are set to 1, `false` otherwise. + */ + static bool is_set() noexcept { + return (Field::read() == (mask >> offset)); + } - //! Field set method. - /** - * This method will set all bits in the field. - */ - static void set() noexcept { - policy::template - set(parent_register::rw_mem_device()); - }; + //! Is field clear bool method. + /** + * @return `true` if all the bits are set to 0, `false` otherwise. + */ + static bool is_clear() noexcept { + return (Field::read() == type{0}); + } - //! Field clear method. - /** - * This method will clear all bits in the field. - */ - static void clear() noexcept { - policy::template - clear(parent_register::rw_mem_device()); - }; - - //! Field toggle method. - /** - * This method will toggle all bits in the field. - */ - static void toggle() noexcept { - policy::template - toggle(parent_register::rw_mem_device()); - }; - - //! Is field set bool method. - /** - * @return `true` if all the bits are set to 1, `false` otherwise. - */ - static bool is_set() noexcept { - return (Field::read() == (mask >> offset)); - }; - - //! Is field clear bool method. - /** - * @return `true` if all the bits are set to 0, `false` otherwise. - */ - static bool is_clear() noexcept { - return (Field::read() == 0u); - }; - - // Consistency checking. - // The width of the field cannot exceed the register size and the - // width added to the offset cannot exceed the register size. - static_assert(parent_register::size >= width, - "field width is larger than parent register size"); - static_assert(parent_register::size >= width + offset, - "offset + width is larger than parent register size"); - static_assert(width != 0u, - "defining a Field type of width 0u is not allowed"); - - }; + // Consistency checking. + // The width of the field cannot exceed the register size and the + // width added to the offset cannot exceed the register size. + static_assert(parent_register::size >= width, + "Field:: field width is larger than parent register size"); + static_assert(parent_register::size >= width + offset, + "Field:: offset + width is larger than parent register size"); + static_assert(width != FieldWidth{0}, + "Field:: defining a Field type of zero width is not allowed"); +}; -} +} // namespace cppreg -#endif // CPPREG_REGISTERFIELD_H +#endif // CPPREG_REGISTERFIELD_H diff --git a/register/Internals.h b/register/Internals.h index e80f7f0..c8d5fe2 100644 --- a/register/Internals.h +++ b/register/Internals.h @@ -2,101 +2,52 @@ /** * @file Internals.h * @author Nicolas Clauvelin (nclauvelin@sendyne.com) - * @copyright Copyright 2010-2018 Sendyne Corp. All rights reserved. + * @copyright Copyright 2010-2019 Sendyne Corp. All rights reserved. * * This header collects various implementations which are required for cppreg * implementation but not intended to be fully exposed to the user. */ -#include "cppreg_Defines.h" -#include "Traits.h" - - #ifndef CPPREG_INTERNALS_H #define CPPREG_INTERNALS_H -//! cppreg::internals namespace. +#include "Traits.h" + + namespace cppreg { namespace internals { - //! Overflow check implementation. - /** - * @tparam T Data type. - * @tparam value Value to check. - * @tparam limit Overflow limit value. - * - * This structure defines a type result set to std::true_type if there is - * no overflow and set to std::false_type if there is overflow. - * There is overflow if value if strictly larger than limit. - */ - template < - typename T, - T value, - T limit - > - struct check_overflow : std::integral_constant {}; +//! Overflow check implementation. +/** + * @tparam T Data type. + * @tparam value Value to check. + * @tparam limit Overflow limit value. + * + * This structure defines a type result set to std::true_type if there is + * no overflow and set to std::false_type if there is overflow. + * There is overflow if value if strictly larger than limit. + */ +template +struct check_overflow : std::integral_constant {}; - //! is_aligned implementation. - /** - * @tparam address Address to be checked for alignment. - * @tparam alignment Alignment boundary in bytes. - * - * This will only derived from std::true_type if the address is aligned. - */ - template - struct is_aligned : std::integral_constant< - bool, - (address & (alignment - 1)) == 0 - > { - }; +//! is_aligned implementation. +/** + * @tparam address Address to be checked for alignment. + * @tparam alignment Alignment boundary in bytes. + * + * This will only derived from std::true_type if the address is aligned. + */ +template
+struct is_aligned + : std::integral_constant {}; - //! Memory map implementation for packed registers. - /** - * @tparam address Memory region base address. - * @tparam n Memory size in bytes. - * @tparam reg_size Register bit size enum value. - * - * This structure is used to map an array structure onto a memory region. - * The size of the array elements is defined by the register size. - */ - template - struct memory_map { - - //! Array type. - using mem_array_t = std::array< - volatile typename TypeTraits::type, - n / sizeof(typename TypeTraits::type) - >; - - //! Static reference to memory array. - static mem_array_t& array; - - // Alignment check. - static_assert( - is_aligned::byte_size>::value, - "memory_map: base address is mis-aligned for register type" - ); - - }; - - //! Memory array reference definition. - template - typename memory_map::mem_array_t& - memory_map::array = *( - reinterpret_cast - ::mem_array_t*>( - address - ) - ); +} // namespace internals +} // namespace cppreg -} -} - - -#endif // CPPREG_INTERNALS_H +#endif // CPPREG_INTERNALS_H diff --git a/register/Mask.h b/register/Mask.h index 36dd140..40d9a66 100644 --- a/register/Mask.h +++ b/register/Mask.h @@ -2,7 +2,7 @@ /** * @file Mask.h * @author Nicolas Clauvelin (nclauvelin@sendyne.com) - * @copyright Copyright 2010-2018 Sendyne Corp. All rights reserved. + * @copyright Copyright 2010-2019 Sendyne Corp. All rights reserved. * * The implementation is designed to compute masks prior to runtime by * relying on constexpr function. This will work as intended if the function @@ -17,42 +17,38 @@ #include "cppreg_Defines.h" -//! cppreg namespace. namespace cppreg { - //! Mask constexpr function. - /** - * @tparam Mask_t Mask data type (will be derived from register). - * @param width Mask width. - * @return The mask value. - */ - template - constexpr Mask_t make_mask(const FieldWidth_t width) noexcept { - return width == 0 ? - 0u - : - static_cast( - (make_mask(FieldWidth_t(width - 1)) << 1) | 1 - ); - }; - - - //! Shifted mask constexpr function. - /** - * @tparam Mask_t Mask data type (will be derived from register). - * @param width Mask width. - * @param offset Mask offset. - * @return The mask value. - */ - template - constexpr Mask_t make_shifted_mask(const FieldWidth_t width, - const FieldOffset_t offset) noexcept { - return static_cast(make_mask(width) << offset); - }; - - +//! Mask constexpr function. +/** + * @tparam Mask Mask data type (will be derived from register). + * @param width Mask width. + * @return The mask value. + */ +template +constexpr Mask make_mask(const FieldWidth width) noexcept { + return width == 0 ? static_cast(0u) + : static_cast( + (make_mask(FieldWidth(width - 1)) << 1) | 1); } -#endif // CPPREG_MASK_H +//! Shifted mask constexpr function. +/** + * @tparam Mask Mask data type (will be derived from register). + * @param width Mask width. + * @param offset Mask offset. + * @return The mask value. + */ +template +constexpr Mask make_shifted_mask(const FieldWidth width, + const FieldOffset offset) noexcept { + return static_cast(make_mask(width) << offset); +} + + +} // namespace cppreg + + +#endif // CPPREG_MASK_H diff --git a/register/Memory.h b/register/Memory.h new file mode 100644 index 0000000..9a13bf0 --- /dev/null +++ b/register/Memory.h @@ -0,0 +1,106 @@ +//! Memory device implementation. +/** + * @file Memory.h + * @author Nicolas Clauvelin (nclauvelin@sendyne.com) + * @copyright Copyright 2010-2019 Sendyne Corp. All rights reserved. + */ + + +#ifndef CPPREG_DEV_MEMORY_H +#define CPPREG_DEV_MEMORY_H + + +#include "Traits.h" + +#include + + +namespace cppreg { + + +//! Register pack base implementation. +/** + * @tparam base_address Pack base address. + * @tparam pack_byte_size Pack size in bytes. + */ +template
+struct RegisterPack { + + //! Base address. + constexpr static const Address pack_base = base_address; + + //! Pack size in bytes. + constexpr static const std::uint32_t size_in_bytes = pack_byte_size; +}; + + +//! Memory device. +/** + * @tparam mem_address Address of the memory device. + * @tparam mem_byte_size Memory device size in bytes. + */ +template
+struct MemoryDevice { + + //! Storage type. + using memory_storage = std::array; + + //! Memory device storage. + static memory_storage& _mem_storage; + + //! Accessor. + template + static const volatile typename TypeTraits::type& ro_memory() { + + // Check alignment. + static_assert( + internals::is_aligned::type>::value>::value, + "MemoryDevice:: ro request not aligned"); + + return *(reinterpret_cast::type*>( + &_mem_storage[byte_offset])); + } + + //! Modifier. + template + static volatile typename TypeTraits::type& rw_memory() { + + // Check alignment. + static_assert( + internals::is_aligned::type>::value>::value, + "MemoryDevice:: rw request not aligned"); + + return *( + reinterpret_cast::type*>( + &_mem_storage[byte_offset])); + } +}; + +//! Static reference definition. +template
+typename MemoryDevice::memory_storage& MemoryDevice::_mem_storage = + *(reinterpret_cast::memory_storage*>(a)); + + +//! Register memory device for register pack. +/** + * + * @tparam pack_address Register pack address. + * @tparam n_bytes Register pack size in bytes. + */ +template +struct RegisterMemoryDevice { + using mem_device = + MemoryDevice; +}; + + +} // namespace cppreg + + +#endif // CPPREG_DEV_MEMORY_H diff --git a/register/MergeWrite.h b/register/MergeWrite.h index 7ee95f9..5ac1077 100644 --- a/register/MergeWrite.h +++ b/register/MergeWrite.h @@ -2,7 +2,7 @@ /** * @file MergeWrite.h * @author Nicolas Clauvelin (nclauvelin@sendyne.com) - * @copyright Copyright 2010-2018 Sendyne Corp. All rights reserved. + * @copyright Copyright 2010-2019 Sendyne Corp. All rights reserved. * * The "merge write" implementation is designed to make it possible to merge * write operations on different fields into a single one. @@ -18,250 +18,213 @@ #define CPPREG_MERGEWRITE_H -#include "Internals.h" #include "AccessPolicy.h" -#include +#include "Internals.h" -//! cppreg namespace. namespace cppreg { - //! Merge write constant implementation. +//! Merge write constant implementation. +/** + * @tparam Register Register on which the merged write will be performed. + * @tparam mask Initial mask. + * @tparam offset Initial offset. + * @tparam value Initial value. + * + * The initial data will come from the field on which the merge write + * will be initiated. + * + * This implementation is designed for operations in which all data is + * available at compile time. This makes it possible to leverage a + * template implementation and simplify most of the operations (based on + * the access polict implementation that detects trivial operations). In + * addition, this will also perform overflow checking. + */ +template +class MergeWrite_tmpl { + +private: + // Type alias to register base type. + using base_type = typename Register::type; + + // Accumulated value. + constexpr static auto _accumulated_value = + base_type{(value << offset) & mask}; + + // Combined mask. + constexpr static auto _combined_mask = mask; + + // Type helper. + template + using propagated = + MergeWrite_tmpl; + + // Default constructor. + MergeWrite_tmpl() = default; + + // Disabled for shadow value register. + static_assert(!Register::shadow::value, + "merge write is not available for shadow value register"); + +public: + //! Instantiation method. + static MergeWrite_tmpl create() noexcept { + return {}; + } + + //!@{ Non-copyable and non-moveable. + MergeWrite_tmpl(const MergeWrite_tmpl&) = delete; + MergeWrite_tmpl& operator=(const MergeWrite_tmpl&) = delete; + MergeWrite_tmpl& operator=(MergeWrite_tmpl&&) = delete; + MergeWrite_tmpl operator=(MergeWrite_tmpl) = delete; + MergeWrite_tmpl(MergeWrite_tmpl&&) = delete; + //!@} + + //! Closure method. /** - * @tparam Register Register on which the merged write will be performed. - * @tparam mask Initial mask. - * @tparam offset Initial offset. - * @tparam value Initial value. - * - * The initial data will come from the field on which the merge write - * will be initiated. - * - * This implementation is designed for operations in which all data is - * available at compile time. This makes it possible to leverage a - * template implementation and simplify most of the operations (based on - * the access policies implementation that detects trivial operations). In - * addition, this will also perform overflow checking. + * This is where the write happens. */ - template < - typename Register, - typename Register::type mask, - FieldOffset_t offset, - typename Register::type value - > class MergeWrite_tmpl { + void done() const&& noexcept { + // Get memory pointer. + typename Register::MMIO& mmio_device = Register::rw_mem_device(); - private: + // Write to the whole register using the current accumulated value + // and combined mask. + // No offset needed because we write to the whole register. + RegisterWriteConstant::write(mmio_device); + } - // Type alias to register base type. - using base_type = typename Register::type; - - // Disabled for shadow value register. - static_assert(!Register::shadow::value, - "merge write is not available for shadow value register"); - - // Accumulated value. - constexpr static const base_type _accumulated_value = - ((value << offset) & mask); - - // Combined mask. - constexpr static const base_type _combined_mask = mask; - - // Default constructor. - MergeWrite_tmpl() = default; - - - public: - - //! Instantiation method. - static MergeWrite_tmpl make() noexcept { return {}; }; - - //!@{ Non-copyable and non-moveable. - MergeWrite_tmpl(const MergeWrite_tmpl&) = delete; - MergeWrite_tmpl& operator=(const MergeWrite_tmpl&) = delete; - MergeWrite_tmpl& operator=(MergeWrite_tmpl&&) = delete; - MergeWrite_tmpl operator=(MergeWrite_tmpl) = delete; - MergeWrite_tmpl(MergeWrite_tmpl&&) = delete; - //!@} - - //! Closure method. - /** - * This is where the write happens. - */ - void done() const && noexcept { - - // Get memory pointer. - typename Register::MMIO_t& mmio_device = - Register::rw_mem_device(); - - // Write to the whole register using the current accumulated value - // and combined mask. - // No offset needed because we write to the whole register. - RegisterWriteConstant< - typename Register::MMIO_t, - typename Register::type, - _combined_mask, - 0u, - _accumulated_value - >::write(mmio_device); - - }; - - //! With method for constant value. - /** - * @tparam F Field to be written - * @tparam new_value Value to write to the field. - * @return A new instance for chaining other write operations. - */ - template < - typename F, - base_type new_value, - typename T = MergeWrite_tmpl< - Register, - (_combined_mask | F::mask), - 0u, - (_accumulated_value & ~F::mask) | ((new_value << F::offset) & - F::mask) - > - > - typename std::enable_if< - (internals::check_overflow< - typename Register::type, new_value, (F::mask >> F::offset) - >::value), - T - >::type&& - with() const && noexcept { - - // Check that the field belongs to the register. - static_assert(std::is_same< - typename F::parent_register, - Register - >::value, - "field is not from the same register in merge_write"); - - return std::move(T::make()); - - }; - - - }; - - - //! Merge write implementation. + //! With method for constant value. /** - * @tparam Register Register on which the merged write will be performed. - * @tparam mask Initial mask. - * - * The initial mask will come from the field on which the merge write - * will be initiated. + * @tparam F Field to be written + * @tparam new_value Value to write to the field. + * @return A merge write instance with accumulated data. */ - template < - typename Register, - typename Register::type mask - > - class MergeWrite { + template + propagated&& with() const&& noexcept { + + // Check that the field belongs to the register. + static_assert( + std::is_same::value, + "MergeWrite_tmpl:: field is not from the same register"); + + // Check that there is no overflow. + constexpr auto no_overflow = + internals::check_overflow> F::offset)>::value; + static_assert(no_overflow, + "MergeWrite_tmpl:: field overflow in with() call"); + + return std::move(propagated{}); + } +}; - public: +//! Merge write implementation. +/** + * @tparam Register Register on which the merged write will be performed. + * @tparam mask Initial mask. + * + * The initial mask will come from the field on which the merge write + * will be initiated. + */ +template +class MergeWrite { - //! Type alias to register base type. - using base_type = typename Register::type; +private: + // Type alias to register base type. + using base_type = typename Register::type; + + // Accumulated value. + base_type _accumulated_value; + + // Combined mask. + constexpr static auto _combined_mask = mask; + + // Type helper. + template + using propagated = MergeWrite; + + // Private default constructor. + constexpr MergeWrite() : _accumulated_value{0} {}; + constexpr explicit MergeWrite(const base_type v) : _accumulated_value{v} {}; + + // Disabled for shadow value register. + static_assert(!Register::shadow::value, + "merge write is not available for shadow value register"); + +public: + //! Static instantiation method. + constexpr static MergeWrite create(const base_type value) noexcept { + return MergeWrite(value); + } + + //!@ Move constructor. + MergeWrite(MergeWrite&& mw) noexcept + : _accumulated_value{mw._accumulated_value} {}; + + //!@{ Non-copyable. + MergeWrite(const MergeWrite&) = delete; + MergeWrite& operator=(const MergeWrite&) = delete; + MergeWrite& operator=(MergeWrite&&) = delete; + //!@} + + //! Closure method. + /** + * This is where the write happens. + */ + void done() const&& noexcept { + + // Get memory pointer. + typename Register::MMIO& mmio_device = Register::rw_mem_device(); + + // Write to the whole register using the current accumulated value + // and combined mask. + // No offset needed because we write to the whole register. + RegisterWrite::write(mmio_device, _accumulated_value); + } + + //! With method. + /** + * @tparam F Field type describing where to write in the register. + * @param value Value to write to the register. + * @return A merge write instance with accumulated data. + */ + template + propagated with(const base_type value) const&& noexcept { + + // Check that the field belongs to the register. + static_assert( + std::is_same::value, + "field is not from the same register in merge_write"); + + // Update accumulated value. + const auto new_value = static_cast( + (_accumulated_value & ~F::mask) | ((value << F::offset) & F::mask)); + + return std::move(propagated::create(new_value)); + } +}; - private: - - // Combined mask. - constexpr static const base_type _combined_mask = mask; +} // namespace cppreg - public: - - //! Static instantiation method. - constexpr static MergeWrite make(const base_type value) noexcept { - return MergeWrite(value); - }; - - //!@ Move constructor. - MergeWrite(MergeWrite&& mw) noexcept - : _accumulated_value(mw._accumulated_value) {}; - - //!@{ Non-copyable. - MergeWrite(const MergeWrite&) = delete; - MergeWrite& operator=(const MergeWrite&) = delete; - MergeWrite& operator=(MergeWrite&&) = delete; - //!@} - - //! Closure method. - /** - * This is where the write happens. - */ - void done() const && noexcept { - - // Get memory pointer. - typename Register::MMIO_t& mmio_device = - Register::rw_mem_device(); - - // Write to the whole register using the current accumulated value - // and combined mask. - // No offset needed because we write to the whole register. - RegisterWrite< - typename Register::MMIO_t, - base_type, - _combined_mask, - 0u - >::write(mmio_device, _accumulated_value); - - }; - - //! With method. - /** - * @tparam F Field type describing where to write in the register. - * @param value Value to write to the register. - * @return A reference to the current merge write data. - */ - template - MergeWrite - with(const base_type value) && noexcept { - - // Check that the field belongs to the register. - static_assert(std::is_same< - typename F::parent_register, - Register - >::value, - "field is not from the same register in merge_write"); - - // Update accumulated value. - _accumulated_value = (_accumulated_value & ~F::mask) - | ((value << F::offset) & F::mask); - - return - std::move( - MergeWrite - ::make(_accumulated_value) - ); - - }; - - - private: - - // Disabled for shadow value register. - static_assert(!Register::shadow::value, - "merge write is not available for shadow value register"); - - // Private default constructor. - constexpr MergeWrite() : _accumulated_value(0u) {}; - constexpr explicit MergeWrite(const base_type v) : - _accumulated_value(v) {}; - - // Accumulated value. - base_type _accumulated_value; - - - }; - - -} - - -#endif // CPPREG_MERGEWRITE_H +#endif // CPPREG_MERGEWRITE_H diff --git a/register/Register.h b/register/Register.h index 143da58..0fe68e5 100644 --- a/register/Register.h +++ b/register/Register.h @@ -2,7 +2,7 @@ /** * @file Register.h * @author Nicolas Clauvelin (nclauvelin@sendyne.com) - * @copyright Copyright 2010-2018 Sendyne Corp. All rights reserved. + * @copyright Copyright 2010-2019 Sendyne Corp. All rights reserved. * * This header provides the definitions related to register implementation. */ @@ -12,127 +12,119 @@ #define CPPREG_REGISTER_H -#include "Traits.h" +#include "Memory.h" #include "MergeWrite.h" #include "ShadowValue.h" -//! cppreg namespace. namespace cppreg { - //! Register data structure. +//! Register data structure. +/** + * @tparam reg_address Register address. + * @tparam reg_size Register size enum value. + * @tparam reset_value Register reset value (0x0 if unknown). + * @tparam use_shadow shadow Boolean flag to enable shadow value. + * + * This data structure will act as a container for fields and is + * therefore limited to a strict minimum. It only carries information + * about the register base address, size, and reset value. + * In practice, register are implemented by deriving from this class to + * create custom types. + */ +template
::type reset_value = 0x0, + bool use_shadow = false> +struct Register { + + //! Register base type. + using type = typename TypeTraits::type; + + //! MMIO pointer type. + using MMIO = volatile type; + + //! Boolean flag for shadow value management. + using shadow = Shadow; + + //! Register base address. + constexpr static auto base_address = reg_address; + + //! Register size in bits. + constexpr static auto size = TypeTraits::bit_size; + + //! Register reset value. + constexpr static auto reset = reset_value; + + //! Register pack for memory device. + using pack = RegisterPack; + + //! Memory modifier. /** - * @tparam reg_address Register address. - * @tparam reg_size Register size enum value. - * @tparam reset_value Register reset value (0x0 if unknown). - * @tparam use_shadow shadow Boolean flag to enable shadow value. - * - * This data structure will act as a container for fields and is - * therefore limited to a strict minimum. It only carries information - * about the register base address, size, and reset value. - * In practice, register are implemented by deriving from this class to - * create custom types. + * @return A reference to the writable register memory. */ - template < - Address_t reg_address, - RegBitSize reg_size, - typename TypeTraits::type reset_value = 0x0, - bool use_shadow = false - > - struct Register { + static MMIO& rw_mem_device() { + using mem_device = typename RegisterMemoryDevice::mem_device; + return mem_device::template rw_memory(); + } - //! Register base type. - using type = typename TypeTraits::type; + //! Memory accessor. + /** + * @return A reference to the read-only register memory. + */ + static const MMIO& ro_mem_device() { + using mem_device = typename RegisterMemoryDevice::mem_device; + return mem_device::template ro_memory(); + } - //! MMIO pointer type. - using MMIO_t = volatile type; + //! Merge write start function. + /** + * @tparam F Field on which to perform the first write operation. + * @param value Value to be written to the field. + * @return A merge write data structure to chain further writes. + */ + template + static MergeWrite merge_write( + const typename F::type value) noexcept { + return MergeWrite::create( + static_cast((value << F::offset) & F::mask)); + } - //! Boolean flag for shadow value management. - using shadow = Shadow; + //! Merge write start function for constant value. + /** + * @tparam F Field on which to perform the first write operation. + * @tparam value Value to be written to the field. + * @return A merge write data structure to chain further writes. + */ + template > + static T&& merge_write() noexcept { - //! Register base address. - constexpr static const Address_t base_address = reg_address; - - //! Register size in bits. - constexpr static const std::uint8_t size = - TypeTraits::bit_size; - - //! Register reset value. - constexpr static const type reset = reset_value; - - //! Memory modifier. - /** - * @return A reference to the writable register memory. - */ - static MMIO_t& rw_mem_device() { - return *(reinterpret_cast(base_address)); - }; - - //! Memory accessor. - /** - * @return A reference to the read-only register memory. - */ - static const MMIO_t& ro_mem_device() { - return *(reinterpret_cast(base_address)); - }; - - //! Merge write start function. - /** - * @tparam F Field on which to perform the first write operation. - * @param value Value to be written to the field. - * @return A merge write data structure to chain further writes. - */ - template - static MergeWrite - merge_write(const typename F::type value) noexcept { - return - MergeWrite - ::make(((value << F::offset) & F::mask)); - }; - - //! Merge write start function for constant value. - /** - * @tparam F Field on which to perform the first write operation. - * @tparam value Value to be written to the field. - * @return A merge write data structure to chain further writes. - */ - template < - typename F, - type value, - typename T = MergeWrite_tmpl< - typename F::parent_register, - F::mask, - F::offset, - value - > - > - static - typename std::enable_if< - internals::check_overflow< - type, value, (F::mask >> F::offset) - >::value, - T - >::type&& - merge_write() noexcept { - return std::move(T::make()); - }; - - // Sanity check. - static_assert(size != 0u, - "Register: register definition with zero size"); - - // Enforce alignment. + // Check overflow. static_assert( - internals::is_aligned::byte_size> - ::value, - "Register: address is mis-aligned for register type" - ); + internals::check_overflow> F::offset)>:: + value, + "Register::merge_write:: value too large for the field"); - }; + return std::move(T::create()); + } + + // Sanity check. + static_assert(size != 0u, "Register:: register definition with zero size"); + + // Enforce alignment. + static_assert(internals::is_aligned::byte_size>::value, + "Register:: address is mis-aligned for register type"); +}; -} +} // namespace cppreg -#endif // CPPREG_REGISTER_H +#endif // CPPREG_REGISTER_H diff --git a/register/RegisterPack.h b/register/RegisterPack.h index 97160ef..eb9bedf 100644 --- a/register/RegisterPack.h +++ b/register/RegisterPack.h @@ -2,217 +2,179 @@ /** * @file RegisterPack.h * @author Nicolas Clauvelin (nclauvelin@sendyne.com) - * @copyright Copyright 2010-2018 Sendyne Corp. All rights reserved. + * @copyright Copyright 2010-2019 Sendyne Corp. All rights reserved. * - * This header provides the definitions related to register implementation. + * This header provides the definitions related to packed register + * implementation. */ -#include "Register.h" -#include "Internals.h" - - #ifndef CPPREG_REGISTERPACK_H #define CPPREG_REGISTERPACK_H -//! cppreg namespace. +#include "Internals.h" +#include "Memory.h" +#include "Register.h" + + namespace cppreg { - //! Register pack base implementation. +//! Packed register implementation. +/** + * @tparam RegisterPack Pack to which the register belongs. + * @tparam reg_size Register size enum value. + * @tparam bit_offset Offset in bits for the register with respect to base. + * @tparam reset_value Register reset value (0x0 if unknown). + * @tparam use_shadow Boolean flag to enable shadow value. + * + * This implementation is intended to be used when defining a register + * that belongs to a peripheral group. + */ +template ::type reset_value = 0x0, + bool use_shadow = false> +struct PackedRegister : Register { + + //! Register pack. + using pack = RegisterPack; + + //! Register type. + using base_reg = Register; + + //! Memory modifier. /** - * @tparam base_address Pack base address. - * @tparam pack_byte_size Pack size in bytes. + * @return A reference to the writable register memory. */ - template < - Address_t base_address, - std::uint32_t pack_byte_size - > struct RegisterPack { + static typename base_reg::MMIO& rw_mem_device() noexcept { + using mem_device = + typename RegisterMemoryDevice::mem_device; + return mem_device::template rw_memory(); + } - //! Base address. - constexpr static const Address_t pack_base = base_address; - - //! Pack size in bytes. - constexpr static const std::uint32_t size_in_bytes = pack_byte_size; - - }; - - - //! Packed register implementation. + //! Memory accessor. /** - * @tparam RegisterPack Pack to which the register belongs. - * @tparam reg_size Register size enum value. - * @tparam bit_offset Offset in bits for the register with respect to base. - * @tparam reset_value Register reset value (0x0 if unknown). - * @tparam use_shadow Boolean flag to enable shadow value. + * @return A reference to the read-only register memory. + */ + static const typename base_reg::MMIO& ro_mem_device() noexcept { + using mem_device = + typename RegisterMemoryDevice::mem_device; + return mem_device::template ro_memory(); + } + + // Safety check to detect if are overflowing the pack. + static_assert(TypeTraits::byte_size + (bit_offset / 8u) + <= RegisterPack::size_in_bytes, + "PackRegister:: packed register is overflowing the pack"); + + // A packed register of width N bits requires: + // - the pack address to be N-bits aligned (N/8 aligned), + // - the pack address with offset to be N-bits aligned (N/8 aligned). + static_assert( + internals::is_aligned::byte_size>::value, + "PackedRegister:: pack base address is mis-aligned for register type"); + static_assert( + internals::is_aligned::byte_size>::value, + "PackedRegister:: offset address is mis-aligned for register type"); +}; + + +//! Pack indexing structure. +/** + * @tparam T List of types (registers or fields) to index. + * + * This can be used to conveniently map indices over packed registers. + * The order in the variadic parameter pack will define the indexing + * (starting at zero). + */ +template +struct PackIndexing { + + //! Tuple type. + using tuple_t = typename std::tuple; + + //! Number of elements. + constexpr static const std::size_t n_elems = + std::tuple_size::value; + + //! Element accessor. + template + using elem = typename std::tuple_element::type; +}; + + +//! Template for loop implementation. +/** + * @tparam start Start index value. + * @tparam end End index value. + */ +template +struct for_loop { + + //! Loop method. + /** + * @tparam Func Function to be called at each iteration. * - * This implementation is intended to be used when defining a register - * that belongs to a peripheral group. + * This will call Op for the range [start, end). */ - template < - typename RegisterPack, - RegBitSize reg_size, - std::uint32_t bit_offset, - typename TypeTraits::type reset_value = 0x0, - bool use_shadow = false - > - struct PackedRegister : Register< - RegisterPack::pack_base + (bit_offset / 8u), - reg_size, - reset_value, - use_shadow - > { - - //! Register type. - using base_reg = Register< - RegisterPack::pack_base + (bit_offset / 8u), - reg_size, - reset_value, - use_shadow - >; - - //! Memory map type. - using mem_map_t = internals::memory_map< - RegisterPack::pack_base, - RegisterPack::size_in_bytes, - reg_size - >; - - //! Memory modifier. - /** - * @return A reference to the writable register memory. - */ - static typename base_reg::MMIO_t& rw_mem_device() noexcept { - return mem_map_t::array[bit_offset - / TypeTraits::bit_size]; - }; - - //! Memory accessor. - /** - * @return A reference to the read-only register memory. - */ - static const typename base_reg::MMIO_t& ro_mem_device() noexcept { - return mem_map_t::array[bit_offset - / TypeTraits::bit_size]; - }; - - // Safety check to detect if are overflowing the pack. - static_assert( - TypeTraits::byte_size + (bit_offset / 8u) <= - RegisterPack::size_in_bytes, - "PackRegister: packed register is overflowing the pack" - ); - - // A packed register of width N bits requires: - // - the pack address to be N-bits aligned (N/8 aligned), - // - the pack address with offset to be N-bits aligned (N/8 aligned). - static_assert( - internals::is_aligned< - RegisterPack::pack_base, - TypeTraits::byte_size - >::value, - "PackedRegister: pack base address is mis-aligned for register type" - ); - static_assert( - internals::is_aligned< - RegisterPack::pack_base + (bit_offset / 8u), - TypeTraits::byte_size - >::value, - "PackedRegister: offset address is mis-aligned for register type" - ); - - - }; - - - //! Pack indexing structure. - /** - * @tparam T List of types (registers or fields) to index. - * - * This can be used to conveniently map indices over packed registers. - * The order in the variadic parameter pack will define the indexing - * (starting at zero). - */ - template - struct PackIndexing { - - //! Tuple type. - using tuple_t = typename std::tuple; - - //! Number of elements. - constexpr static const std::size_t n_elems = - std::tuple_size::value; - - //! Element accessor. - template - using elem = typename std::tuple_element::type; - - }; - - - //! Template for loop implementation. - /** - * @tparam start Start index value. - * @tparam end End index value. - */ - template - struct for_loop { - - //! Loop method. - /** - * @tparam Func Function to be called at each iteration. - * - * This will call Op for the range [start, end). - */ - template - static void apply() noexcept { - Func().template operator()(); - if (start < end) - for_loop::template apply(); - }; + template + static void apply() noexcept { + Func().template operator()(); + if (start < end) + for_loop::template apply(); + } #if __cplusplus >= 201402L - //! Apply method. - /** - * @tparam Op Operator type to be called. - * - * This is only available with C++14 and up as this requires polymorphic - * lambdas to be used in a somewhat useful manner. - * - * Typical example: - * use lambda [](auto index) { index.value will be the loop index}; - */ - template - static void apply(Op&& f) noexcept { - if (start < end) { - f(std::integral_constant{}); - for_loop::apply(std::forward(f)); - }; - }; -#endif // __cplusplus 201402L - - }; - template - struct for_loop { - template - static void apply() noexcept {}; -#if __cplusplus >= 201402L - template - static void apply(Op&& f) noexcept {}; -#endif // __cplusplus 201402L - }; - - - //! Template range loop implementation. + //! Apply method. /** - * @tparam IndexedPack Indexed pack type. + * @tparam Op Operator type to be called. + * + * This is only available with C++14 and up as this requires polymorphic + * lambdas to be used in a somewhat useful manner. + * + * Typical example: + * use lambda [](auto index) { index.value will be the loop index}; */ - template - struct pack_loop : for_loop<0, IndexedPack::n_elems> {}; + template + static void apply(Op&& f) noexcept { + if (start < end) { + f(std::integral_constant{}); + for_loop::apply(std::forward(f)); + }; + } +#endif // __cplusplus 201402L +}; +template +struct for_loop { + template + static void apply() noexcept {} +#if __cplusplus >= 201402L + template + static void apply(Op&& f) noexcept {} +#endif // __cplusplus 201402L +}; -} +//! Template range loop implementation. +/** + * @tparam IndexedPack Indexed pack type. + */ +template +struct pack_loop : for_loop<0, IndexedPack::n_elems> {}; -#endif // CPPREG_REGISTERPACK_H +} // namespace cppreg + + +#endif // CPPREG_REGISTERPACK_H diff --git a/register/ShadowValue.h b/register/ShadowValue.h index 2725bb9..9c15fc3 100644 --- a/register/ShadowValue.h +++ b/register/ShadowValue.h @@ -2,7 +2,7 @@ /** * @file ShadowValue.h * @author Nicolas Clauvelin (nclauvelin@sendyne.com) - * @copyright Copyright 2010-2018 Sendyne Corp. All rights reserved. + * @copyright Copyright 2010-2019 Sendyne Corp. All rights reserved. */ @@ -13,39 +13,33 @@ #include "cppreg_Defines.h" -//! cppreg namespace. namespace cppreg { - //! Shadow value generic implementation. - /** - * @tparam Register Register type. - * @tparam use_shadow Boolean flag indicating if shadow value is required. - * - * This implementation is for register which do not require shadow value. - */ - template - struct Shadow : std::false_type {}; +//! Shadow value generic implementation. +/** + * @tparam Register Register type. + * @tparam use_shadow Boolean flag indicating if shadow value is required. + */ +template +struct Shadow : std::false_type {}; - //! Shadow value implementation. - /** - * @tparam Register Register type. - * - * This implementation is for register which do require shadow value. - * - * See - */ - template - struct Shadow : std::true_type { - static typename Register::type shadow_value; - }; - template - typename Register::type Shadow::shadow_value = - Register::reset; +//! Shadow value specialization. +/** + * @tparam Register Register type. + * + * This implementation is for register which do require shadow value. + */ +template +struct Shadow : std::true_type { + static typename Register::type shadow_value; +}; +template +typename Register::type Shadow::shadow_value = Register::reset; -} +} // namespace cppreg -#endif // CPPREG_SHADOWVALUE_H +#endif // CPPREG_SHADOWVALUE_H diff --git a/register/Traits.h b/register/Traits.h index b3359e0..68e41ab 100644 --- a/register/Traits.h +++ b/register/Traits.h @@ -2,7 +2,7 @@ /** * @file Traits.h * @author Nicolas Clauvelin (nclauvelin@sendyne.com) - * @copyright Copyright 2010-2018 Sendyne Corp. All rights reserved. + * @copyright Copyright 2010-2019 Sendyne Corp. All rights reserved. * * This header provides some traits for register type instantiation. */ @@ -15,47 +15,55 @@ #include "cppreg_Defines.h" -//! cppreg namespace. namespace cppreg { - //! Register type traits based on size. - /** - * @tparam S Register size in bits. - */ - template - struct TypeTraits; +//! Register type traits based on size. +/** + * @tparam S Register size in bits. + */ +template +struct TypeTraits {}; - //!@{ TypeTraits specializations. - //! 8-bit specialization. - template <> struct TypeTraits { - using type = std::uint8_t; - constexpr static const std::uint8_t bit_size = 8u; - constexpr static const std::uint8_t byte_size = bit_size / 8u; - }; - //! 16-bit specialization. - template <> struct TypeTraits { - using type = std::uint16_t; - constexpr static const std::uint8_t bit_size = 16u; - constexpr static const std::uint8_t byte_size = bit_size / 8u; - }; - //! 32-bit specialization. - template <> struct TypeTraits { - using type = std::uint32_t; - constexpr static const std::uint8_t bit_size = 32u; - constexpr static const std::uint8_t byte_size = bit_size / 8u; - }; - //! 64-bit specialization. - template <> struct TypeTraits { - using type = std::uint64_t; - constexpr static const std::uint8_t bit_size = 64u; - constexpr static const std::uint8_t byte_size = bit_size / 8u; - }; - //!@} +//!@{ TypeTraits specializations. + +//! 8-bit specialization. +template <> +struct TypeTraits { + using type = std::uint8_t; + constexpr static auto bit_size = std::uint8_t{8}; + constexpr static auto byte_size = std::uint8_t{bit_size / 8}; +}; + +//! 16-bit specialization. +template <> +struct TypeTraits { + using type = std::uint16_t; + constexpr static auto bit_size = std::uint8_t{16}; + constexpr static auto byte_size = std::uint8_t{bit_size / 8}; +}; + +//! 32-bit specialization. +template <> +struct TypeTraits { + using type = std::uint32_t; + constexpr static auto bit_size = std::uint8_t{32}; + constexpr static auto byte_size = std::uint8_t{bit_size / 8}; +}; + +//! 64-bit specialization. +template <> +struct TypeTraits { + using type = std::uint64_t; + constexpr static auto bit_size = std::uint8_t{64}; + constexpr static auto byte_size = std::uint8_t{bit_size / 8}; +}; + +//!@} -} +} // namespace cppreg -#endif // CPPREG_TRAITS_H +#endif // CPPREG_TRAITS_H diff --git a/single/cppreg-all.h b/single/cppreg-all.h index e9cd4d8..ce670e3 100644 --- a/single/cppreg-all.h +++ b/single/cppreg-all.h @@ -2,7 +2,7 @@ /** * @file cppreg-all.h * @author Nicolas Clauvelin (nclauvelin@sendyne.com) - * @copyright Copyright 2010-2018 Sendyne Corp. All rights reserved. + * @copyright Copyright 2010-2019 Sendyne Corp. All rights reserved. */ #include @@ -14,638 +14,565 @@ #ifndef CPPREG_CPPREG_DEFINES_H #define CPPREG_CPPREG_DEFINES_H namespace cppreg { - using Address_t = std::uintptr_t; - enum class RegBitSize { - b8, - b16, - b32, - b64 - }; - using FieldWidth_t = std::uint8_t; - using FieldOffset_t = std::uint8_t; - template - struct type_mask { - constexpr static const T value = std::numeric_limits::max(); - }; -} -#endif +using Address = std::uintptr_t; +enum class RegBitSize : std::uint8_t { + b8, + b16, + b32, + b64 +}; +using FieldWidth = std::uint8_t; +using FieldOffset = std::uint8_t; +template +struct type_mask { + constexpr static const T value = std::numeric_limits::max(); +}; +} +#endif // Traits.h #ifndef CPPREG_TRAITS_H #define CPPREG_TRAITS_H namespace cppreg { - template - struct TypeTraits; - template <> struct TypeTraits { - using type = std::uint8_t; - constexpr static const std::uint8_t bit_size = 8u; - constexpr static const std::uint8_t byte_size = bit_size / 8u; - }; - template <> struct TypeTraits { - using type = std::uint16_t; - constexpr static const std::uint8_t bit_size = 16u; - constexpr static const std::uint8_t byte_size = bit_size / 8u; - }; - template <> struct TypeTraits { - using type = std::uint32_t; - constexpr static const std::uint8_t bit_size = 32u; - constexpr static const std::uint8_t byte_size = bit_size / 8u; - }; - template <> struct TypeTraits { - using type = std::uint64_t; - constexpr static const std::uint8_t bit_size = 64u; - constexpr static const std::uint8_t byte_size = bit_size / 8u; - }; -} -#endif +template +struct TypeTraits {}; +template <> +struct TypeTraits { + using type = std::uint8_t; + constexpr static auto bit_size = std::uint8_t{8}; + constexpr static auto byte_size = std::uint8_t{bit_size / 8}; +}; +template <> +struct TypeTraits { + using type = std::uint16_t; + constexpr static auto bit_size = std::uint8_t{16}; + constexpr static auto byte_size = std::uint8_t{bit_size / 8}; +}; +template <> +struct TypeTraits { + using type = std::uint32_t; + constexpr static auto bit_size = std::uint8_t{32}; + constexpr static auto byte_size = std::uint8_t{bit_size / 8}; +}; +template <> +struct TypeTraits { + using type = std::uint64_t; + constexpr static auto bit_size = std::uint8_t{64}; + constexpr static auto byte_size = std::uint8_t{bit_size / 8}; +}; +} +#endif // Internals.h #ifndef CPPREG_INTERNALS_H #define CPPREG_INTERNALS_H namespace cppreg { namespace internals { - template < - typename T, - T value, - T limit - > - struct check_overflow : std::integral_constant {}; - template - struct is_aligned : std::integral_constant< - bool, - (address & (alignment - 1)) == 0 - > { - }; - template - struct memory_map { - using mem_array_t = std::array< - volatile typename TypeTraits::type, - n / sizeof(typename TypeTraits::type) - >; - static mem_array_t& array; +template +struct check_overflow : std::integral_constant {}; +template
+struct is_aligned + : std::integral_constant {}; +} +} +#endif + +// Memory.h +#ifndef CPPREG_DEV_MEMORY_H +#define CPPREG_DEV_MEMORY_H +namespace cppreg { +template
+struct RegisterPack { + constexpr static const Address pack_base = base_address; + constexpr static const std::uint32_t size_in_bytes = pack_byte_size; +}; +template
+struct MemoryDevice { + using memory_storage = std::array; + static memory_storage& _mem_storage; + template + static const volatile typename TypeTraits::type& ro_memory() { static_assert( - is_aligned::byte_size>::value, - "memory_map: base address is mis-aligned for register type" - ); - }; - template - typename memory_map::mem_array_t& - memory_map::array = *( - reinterpret_cast - ::mem_array_t*>( - address - ) - ); -} -} -#endif + internals::is_aligned::type>::value>::value, + "MemoryDevice:: ro request not aligned"); + return *(reinterpret_cast::type*>( + &_mem_storage[byte_offset])); + } + template + static volatile typename TypeTraits::type& rw_memory() { + static_assert( + internals::is_aligned::type>::value>::value, + "MemoryDevice:: rw request not aligned"); + return *( + reinterpret_cast::type*>( + &_mem_storage[byte_offset])); + } +}; +template
+typename MemoryDevice::memory_storage& MemoryDevice::_mem_storage = + *(reinterpret_cast::memory_storage*>(a)); +template +struct RegisterMemoryDevice { + using mem_device = + MemoryDevice; +}; +} +#endif // AccessPolicy.h #ifndef CPPREG_ACCESSPOLICY_H #define CPPREG_ACCESSPOLICY_H namespace cppreg { - template - struct RegisterRead { - constexpr static const bool is_trivial = - (mask == type_mask::value) && (offset == 0u); - template - static T read( - const MMIO_t& mmio_device, - typename std::enable_if::type = nullptr - ) noexcept { - return static_cast((mmio_device & mask) >> offset); - }; - template - static T read( - const MMIO_t& mmio_device, - typename std::enable_if::type = nullptr - ) noexcept { - return static_cast(mmio_device); - }; - }; - template - struct RegisterWrite { - constexpr static const bool is_trivial = - (mask == type_mask::value) && (offset == 0u); - template - static void write( - MMIO_t& mmio_device, - T value, - typename std::enable_if::type = nullptr - ) noexcept { - mmio_device = static_cast( - (mmio_device & ~mask) | ((value << offset) & mask) - ); - }; - template - static void write( - MMIO_t& mmio_device, - T value, - typename std::enable_if::type = nullptr - ) noexcept { - mmio_device = value; - }; - }; - template < - typename MMIO_t, typename T, T mask, FieldOffset_t offset, T value - > - struct RegisterWriteConstant { - constexpr static const bool is_trivial = - (mask == type_mask::value) && (offset == 0u); - template - static void write( - MMIO_t& mmio_device, - typename std::enable_if::type = nullptr - ) noexcept { - mmio_device = static_cast( - (mmio_device & ~mask) | ((value << offset) & mask) - ); - }; - template - static void write( - MMIO_t& mmio_device, - typename std::enable_if::type = nullptr - ) noexcept { - mmio_device = value; - }; - }; - struct read_only { - template - static T read(const MMIO_t& mmio_device) noexcept { - return RegisterRead::read(mmio_device); - }; - }; - struct read_write : read_only { - template - static void write(MMIO_t& mmio_device, - const T value) noexcept { - RegisterWrite::write(mmio_device, value); - }; - template < - typename MMIO_t, typename T, T mask, FieldOffset_t offset, T value - > - static void write(MMIO_t& mmio_device) noexcept { - RegisterWriteConstant - ::write(mmio_device); - }; - template - static void set(MMIO_t& mmio_device) - noexcept { - RegisterWriteConstant - ::write(mmio_device); - }; - template - static void clear(MMIO_t& mmio_device) - noexcept { - RegisterWriteConstant - ::write(mmio_device); - }; - template - static void toggle(MMIO_t& mmio_device) - noexcept { - mmio_device = static_cast((mmio_device) ^ mask); - }; - }; - struct write_only { - template - static void write(MMIO_t& mmio_device, const T value) noexcept { - RegisterWrite::value, 0u>::write( - mmio_device, ((value << offset) & mask) - ); - }; - template < - typename MMIO_t, typename T, T mask, FieldOffset_t offset, T value - > - static void write(MMIO_t& mmio_device) noexcept { - RegisterWriteConstant< - MMIO_t, T, type_mask::value, 0u, ((value << offset) & mask) - > - ::write(mmio_device); - }; - }; -} -#endif +template +struct is_trivial_rw + : std::integral_constant::value) + && (offset == FieldOffset{0})> {}; +template +using is_trivial = + typename std::enable_if::value, U>::type; +template +using is_not_trivial = + typename std::enable_if::value, U>::type; +template +struct RegisterRead { + template + static T read(const MMIO& mmio_device, + is_not_trivial* = nullptr) noexcept { + return static_cast((mmio_device & mask) >> offset); + } + template + static T read(const MMIO& mmio_device, + is_trivial* = nullptr) noexcept { + return static_cast(mmio_device); + } +}; +template +struct RegisterWrite { + template + static void write(MMIO& mmio_device, + T value, + is_not_trivial* = nullptr) noexcept { + mmio_device = + static_cast((mmio_device & ~mask) | ((value << offset) & mask)); + } + template + static void write(MMIO& mmio_device, + T value, + is_trivial* = nullptr) noexcept { + mmio_device = value; + } +}; +template +struct RegisterWriteConstant { + template + static void write(MMIO& mmio_device, + is_not_trivial* = nullptr) noexcept { + mmio_device = + static_cast((mmio_device & ~mask) | ((value << offset) & mask)); + } + template + static void write(MMIO& mmio_device, + is_trivial* = nullptr) noexcept { + mmio_device = value; + } +}; +struct read_only { + template + static T read(const MMIO& mmio_device) noexcept { + return RegisterRead::read(mmio_device); + } +}; +struct read_write : read_only { + template + static void write(MMIO& mmio_device, const T value) noexcept { + RegisterWrite::write(mmio_device, value); + } + template + static void write(MMIO& mmio_device) noexcept { + RegisterWriteConstant::write(mmio_device); + } + template + static void set(MMIO& mmio_device) noexcept { + RegisterWriteConstant::write( + mmio_device); + } + template + static void clear(MMIO& mmio_device) noexcept { + RegisterWriteConstant(~mask)>::write(mmio_device); + } + template + static void toggle(MMIO& mmio_device) noexcept { + mmio_device = static_cast((mmio_device) ^ mask); + } +}; +struct write_only { + template + static void write(MMIO& mmio_device, const T value) noexcept { + RegisterWrite::value, FieldOffset{0}>::write( + mmio_device, ((value << offset) & mask)); + } + template + static void write(MMIO& mmio_device) noexcept { + RegisterWriteConstant::value, + FieldOffset{0}, + ((value << offset) & mask)>::write(mmio_device); + } +}; +} +#endif // Mask.h #ifndef CPPREG_MASK_H #define CPPREG_MASK_H namespace cppreg { - template - constexpr Mask_t make_mask(const FieldWidth_t width) noexcept { - return width == 0 ? - 0u - : - static_cast( - (make_mask(FieldWidth_t(width - 1)) << 1) | 1 - ); - }; - template - constexpr Mask_t make_shifted_mask(const FieldWidth_t width, - const FieldOffset_t offset) noexcept { - return static_cast(make_mask(width) << offset); - }; +template +constexpr Mask make_mask(const FieldWidth width) noexcept { + return width == 0 ? static_cast(0u) + : static_cast( + (make_mask(FieldWidth(width - 1)) << 1) | 1); } -#endif +template +constexpr Mask make_shifted_mask(const FieldWidth width, + const FieldOffset offset) noexcept { + return static_cast(make_mask(width) << offset); +} +} +#endif // ShadowValue.h #ifndef CPPREG_SHADOWVALUE_H #define CPPREG_SHADOWVALUE_H namespace cppreg { - template - struct Shadow : std::false_type {}; - template - struct Shadow : std::true_type { - static typename Register::type shadow_value; - }; - template - typename Register::type Shadow::shadow_value = - Register::reset; -} -#endif +template +struct Shadow : std::false_type {}; +template +struct Shadow : std::true_type { + static typename Register::type shadow_value; +}; +template +typename Register::type Shadow::shadow_value = Register::reset; +} +#endif // MergeWrite.h #ifndef CPPREG_MERGEWRITE_H #define CPPREG_MERGEWRITE_H namespace cppreg { - template < - typename Register, - typename Register::type mask, - FieldOffset_t offset, - typename Register::type value - > class MergeWrite_tmpl { - private: - using base_type = typename Register::type; - static_assert(!Register::shadow::value, - "merge write is not available for shadow value register"); - constexpr static const base_type _accumulated_value = - ((value << offset) & mask); - constexpr static const base_type _combined_mask = mask; - MergeWrite_tmpl() = default; - public: - static MergeWrite_tmpl make() noexcept { return {}; }; - MergeWrite_tmpl(const MergeWrite_tmpl&) = delete; - MergeWrite_tmpl& operator=(const MergeWrite_tmpl&) = delete; - MergeWrite_tmpl& operator=(MergeWrite_tmpl&&) = delete; - MergeWrite_tmpl operator=(MergeWrite_tmpl) = delete; - MergeWrite_tmpl(MergeWrite_tmpl&&) = delete; - void done() const && noexcept { - typename Register::MMIO_t& mmio_device = - Register::rw_mem_device(); - RegisterWriteConstant< - typename Register::MMIO_t, - typename Register::type, - _combined_mask, - 0u, - _accumulated_value - >::write(mmio_device); - }; - template < - typename F, - base_type new_value, - typename T = MergeWrite_tmpl< - Register, - (_combined_mask | F::mask), - 0u, - (_accumulated_value & ~F::mask) | ((new_value << F::offset) & - F::mask) - > - > - typename std::enable_if< - (internals::check_overflow< - typename Register::type, new_value, (F::mask >> F::offset) - >::value), - T - >::type&& - with() const && noexcept { - static_assert(std::is_same< - typename F::parent_register, - Register - >::value, - "field is not from the same register in merge_write"); - return std::move(T::make()); - }; - }; - template < - typename Register, - typename Register::type mask - > - class MergeWrite { - public: - using base_type = typename Register::type; - private: - constexpr static const base_type _combined_mask = mask; - public: - constexpr static MergeWrite make(const base_type value) noexcept { - return MergeWrite(value); - }; - MergeWrite(MergeWrite&& mw) noexcept - : _accumulated_value(mw._accumulated_value) {}; - MergeWrite(const MergeWrite&) = delete; - MergeWrite& operator=(const MergeWrite&) = delete; - MergeWrite& operator=(MergeWrite&&) = delete; - void done() const && noexcept { - typename Register::MMIO_t& mmio_device = - Register::rw_mem_device(); - RegisterWrite< - typename Register::MMIO_t, - base_type, - _combined_mask, - 0u - >::write(mmio_device, _accumulated_value); - }; - template - MergeWrite - with(const base_type value) && noexcept { - static_assert(std::is_same< - typename F::parent_register, - Register - >::value, - "field is not from the same register in merge_write"); - _accumulated_value = (_accumulated_value & ~F::mask) - | ((value << F::offset) & F::mask); - return - std::move( - MergeWrite - ::make(_accumulated_value) - ); - }; - private: - static_assert(!Register::shadow::value, - "merge write is not available for shadow value register"); - constexpr MergeWrite() : _accumulated_value(0u) {}; - constexpr explicit MergeWrite(const base_type v) : - _accumulated_value(v) {}; - base_type _accumulated_value; - }; -} -#endif +template +class MergeWrite_tmpl { +private: + using base_type = typename Register::type; + constexpr static auto _accumulated_value = + base_type{(value << offset) & mask}; + constexpr static auto _combined_mask = mask; + template + using propagated = + MergeWrite_tmpl; + MergeWrite_tmpl() = default; + static_assert(!Register::shadow::value, + "merge write is not available for shadow value register"); +public: + static MergeWrite_tmpl create() noexcept { + return {}; + } + MergeWrite_tmpl(const MergeWrite_tmpl&) = delete; + MergeWrite_tmpl& operator=(const MergeWrite_tmpl&) = delete; + MergeWrite_tmpl& operator=(MergeWrite_tmpl&&) = delete; + MergeWrite_tmpl operator=(MergeWrite_tmpl) = delete; + MergeWrite_tmpl(MergeWrite_tmpl&&) = delete; + void done() const&& noexcept { + typename Register::MMIO& mmio_device = Register::rw_mem_device(); + RegisterWriteConstant::write(mmio_device); + } + template + propagated&& with() const&& noexcept { + static_assert( + std::is_same::value, + "MergeWrite_tmpl:: field is not from the same register"); + constexpr auto no_overflow = + internals::check_overflow> F::offset)>::value; + static_assert(no_overflow, + "MergeWrite_tmpl:: field overflow in with() call"); + return std::move(propagated{}); + } +}; +template +class MergeWrite { +private: + using base_type = typename Register::type; + base_type _accumulated_value; + constexpr static auto _combined_mask = mask; + template + using propagated = MergeWrite; + constexpr MergeWrite() : _accumulated_value{0} {}; + constexpr explicit MergeWrite(const base_type v) : _accumulated_value{v} {}; + static_assert(!Register::shadow::value, + "merge write is not available for shadow value register"); +public: + constexpr static MergeWrite create(const base_type value) noexcept { + return MergeWrite(value); + } + MergeWrite(MergeWrite&& mw) noexcept + : _accumulated_value{mw._accumulated_value} {}; + MergeWrite(const MergeWrite&) = delete; + MergeWrite& operator=(const MergeWrite&) = delete; + MergeWrite& operator=(MergeWrite&&) = delete; + void done() const&& noexcept { + typename Register::MMIO& mmio_device = Register::rw_mem_device(); + RegisterWrite::write(mmio_device, _accumulated_value); + } + template + propagated with(const base_type value) const&& noexcept { + static_assert( + std::is_same::value, + "field is not from the same register in merge_write"); + const auto new_value = static_cast( + (_accumulated_value & ~F::mask) | ((value << F::offset) & F::mask)); + return std::move(propagated::create(new_value)); + } +}; +} +#endif // Register.h #ifndef CPPREG_REGISTER_H #define CPPREG_REGISTER_H namespace cppreg { - template < - Address_t reg_address, - RegBitSize reg_size, - typename TypeTraits::type reset_value = 0x0, - bool use_shadow = false - > - struct Register { - using type = typename TypeTraits::type; - using MMIO_t = volatile type; - using shadow = Shadow; - constexpr static const Address_t base_address = reg_address; - constexpr static const std::uint8_t size = - TypeTraits::bit_size; - constexpr static const type reset = reset_value; - static MMIO_t& rw_mem_device() { - return *(reinterpret_cast(base_address)); - }; - static const MMIO_t& ro_mem_device() { - return *(reinterpret_cast(base_address)); - }; - template - static MergeWrite - merge_write(const typename F::type value) noexcept { - return - MergeWrite - ::make(((value << F::offset) & F::mask)); - }; - template < - typename F, - type value, - typename T = MergeWrite_tmpl< - typename F::parent_register, - F::mask, - F::offset, - value - > - > - static - typename std::enable_if< - internals::check_overflow< - type, value, (F::mask >> F::offset) - >::value, - T - >::type&& - merge_write() noexcept { - return std::move(T::make()); - }; - static_assert(size != 0u, - "Register: register definition with zero size"); +template
::type reset_value = 0x0, + bool use_shadow = false> +struct Register { + using type = typename TypeTraits::type; + using MMIO = volatile type; + using shadow = Shadow; + constexpr static auto base_address = reg_address; + constexpr static auto size = TypeTraits::bit_size; + constexpr static auto reset = reset_value; + using pack = RegisterPack; + static MMIO& rw_mem_device() { + using mem_device = typename RegisterMemoryDevice::mem_device; + return mem_device::template rw_memory(); + } + static const MMIO& ro_mem_device() { + using mem_device = typename RegisterMemoryDevice::mem_device; + return mem_device::template ro_memory(); + } + template + static MergeWrite merge_write( + const typename F::type value) noexcept { + return MergeWrite::create( + static_cast((value << F::offset) & F::mask)); + } + template > + static T&& merge_write() noexcept { static_assert( - internals::is_aligned::byte_size> - ::value, - "Register: address is mis-aligned for register type" - ); - }; -} -#endif + internals::check_overflow> F::offset)>:: + value, + "Register::merge_write:: value too large for the field"); + return std::move(T::create()); + } + static_assert(size != 0u, "Register:: register definition with zero size"); + static_assert(internals::is_aligned::byte_size>::value, + "Register:: address is mis-aligned for register type"); +}; +} +#endif // RegisterPack.h #ifndef CPPREG_REGISTERPACK_H #define CPPREG_REGISTERPACK_H namespace cppreg { - template < - Address_t base_address, - std::uint32_t pack_byte_size - > struct RegisterPack { - constexpr static const Address_t pack_base = base_address; - constexpr static const std::uint32_t size_in_bytes = pack_byte_size; - }; - template < - typename RegisterPack, - RegBitSize reg_size, - std::uint32_t bit_offset, - typename TypeTraits::type reset_value = 0x0, - bool use_shadow = false - > - struct PackedRegister : Register< - RegisterPack::pack_base + (bit_offset / 8u), - reg_size, - reset_value, - use_shadow - > { - using base_reg = Register< - RegisterPack::pack_base + (bit_offset / 8u), - reg_size, - reset_value, - use_shadow - >; - using mem_map_t = internals::memory_map< - RegisterPack::pack_base, - RegisterPack::size_in_bytes, - reg_size - >; - static typename base_reg::MMIO_t& rw_mem_device() noexcept { - return mem_map_t::array[bit_offset - / TypeTraits::bit_size]; - }; - static const typename base_reg::MMIO_t& ro_mem_device() noexcept { - return mem_map_t::array[bit_offset - / TypeTraits::bit_size]; - }; - static_assert( - TypeTraits::byte_size + (bit_offset / 8u) <= - RegisterPack::size_in_bytes, - "PackRegister: packed register is overflowing the pack" - ); - static_assert( - internals::is_aligned< - RegisterPack::pack_base, - TypeTraits::byte_size - >::value, - "PackedRegister: pack base address is mis-aligned for register type" - ); - static_assert( - internals::is_aligned< - RegisterPack::pack_base + (bit_offset / 8u), - TypeTraits::byte_size - >::value, - "PackedRegister: offset address is mis-aligned for register type" - ); - }; - template - struct PackIndexing { - using tuple_t = typename std::tuple; - constexpr static const std::size_t n_elems = - std::tuple_size::value; - template - using elem = typename std::tuple_element::type; - }; - template - struct for_loop { - template - static void apply() noexcept { - Func().template operator()(); - if (start < end) - for_loop::template apply(); - }; +template ::type reset_value = 0x0, + bool use_shadow = false> +struct PackedRegister : Register { + using pack = RegisterPack; + using base_reg = Register; + static typename base_reg::MMIO& rw_mem_device() noexcept { + using mem_device = + typename RegisterMemoryDevice::mem_device; + return mem_device::template rw_memory(); + } + static const typename base_reg::MMIO& ro_mem_device() noexcept { + using mem_device = + typename RegisterMemoryDevice::mem_device; + return mem_device::template ro_memory(); + } + static_assert(TypeTraits::byte_size + (bit_offset / 8u) + <= RegisterPack::size_in_bytes, + "PackRegister:: packed register is overflowing the pack"); + static_assert( + internals::is_aligned::byte_size>::value, + "PackedRegister:: pack base address is mis-aligned for register type"); + static_assert( + internals::is_aligned::byte_size>::value, + "PackedRegister:: offset address is mis-aligned for register type"); +}; +template +struct PackIndexing { + using tuple_t = typename std::tuple; + constexpr static const std::size_t n_elems = + std::tuple_size::value; + template + using elem = typename std::tuple_element::type; +}; +template +struct for_loop { + template + static void apply() noexcept { + Func().template operator()(); + if (start < end) + for_loop::template apply(); + } #if __cplusplus >= 201402L - template - static void apply(Op&& f) noexcept { - if (start < end) { - f(std::integral_constant{}); - for_loop::apply(std::forward(f)); - }; + template + static void apply(Op&& f) noexcept { + if (start < end) { + f(std::integral_constant{}); + for_loop::apply(std::forward(f)); }; -#endif - }; - template - struct for_loop { - template - static void apply() noexcept {}; + } +#endif +}; +template +struct for_loop { + template + static void apply() noexcept {} #if __cplusplus >= 201402L - template - static void apply(Op&& f) noexcept {}; -#endif - }; - template - struct pack_loop : for_loop<0, IndexedPack::n_elems> {}; -} -#endif + template + static void apply(Op&& f) noexcept {} +#endif +}; +template +struct pack_loop : for_loop<0, IndexedPack::n_elems> {}; +} +#endif // Field.h #ifndef CPPREG_REGISTERFIELD_H #define CPPREG_REGISTERFIELD_H namespace cppreg { - template < - typename BaseRegister, - FieldWidth_t field_width, - FieldOffset_t field_offset, - typename AccessPolicy - > - struct Field { - using parent_register = BaseRegister; - using type = typename parent_register::type; - using MMIO_t = typename parent_register::MMIO_t; - using policy = AccessPolicy; - constexpr static const FieldWidth_t width = field_width; - constexpr static const FieldOffset_t offset = field_offset; - constexpr static const type mask = make_shifted_mask(width, - offset); - constexpr static const bool has_shadow = - parent_register::shadow::value; - template - struct check_overflow : internals::check_overflow< - type, - value, - (mask >> offset) - > {}; - static type read() noexcept { - return policy::template read( - parent_register::ro_mem_device() - ); - }; - template - static void - write(const typename std::enable_if::type value) - noexcept { - policy::template write( +template +struct Field { + using parent_register = BaseRegister; + using type = typename parent_register::type; + using MMIO = typename parent_register::MMIO; + using policy = AccessPolicy; + constexpr static auto width = field_width; + constexpr static auto offset = field_offset; + constexpr static auto mask = make_shifted_mask(width, offset); + template + using if_no_shadow = + typename std::enable_if::type; + template + using if_shadow = + typename std::enable_if::type; + static type read() noexcept { + return policy::template read( + parent_register::ro_mem_device()); + } + template + static void write(const if_no_shadow value) noexcept { + policy::template write( + parent_register::rw_mem_device(), value); + } + template + static void write(const if_shadow value) noexcept { + RegisterWrite::write( + parent_register::shadow::shadow_value, value); + policy:: + template write::value, FieldOffset{0}>( parent_register::rw_mem_device(), - value - ); - }; - template - static void - write(const typename std::enable_if::type value) - noexcept { - RegisterWrite - ::write(parent_register::shadow::shadow_value, value); - policy::template write::value, 0u>( - parent_register::rw_mem_device(), - parent_register::shadow::shadow_value - ); - }; - template - static void write( - typename std::enable_if< - !has_shadow - && - check_overflow::value, - T - >::type* = nullptr - ) noexcept { - policy::template write( - parent_register::rw_mem_device() - ); - }; - template - static void write( - typename std::enable_if< - has_shadow - && - check_overflow::value, - T - >::type* = nullptr - ) noexcept { - write(value); - }; - static void set() noexcept { - policy::template - set(parent_register::rw_mem_device()); - }; - static void clear() noexcept { - policy::template - clear(parent_register::rw_mem_device()); - }; - static void toggle() noexcept { - policy::template - toggle(parent_register::rw_mem_device()); - }; - static bool is_set() noexcept { - return (Field::read() == (mask >> offset)); - }; - static bool is_clear() noexcept { - return (Field::read() == 0u); - }; - static_assert(parent_register::size >= width, - "field width is larger than parent register size"); - static_assert(parent_register::size >= width + offset, - "offset + width is larger than parent register size"); - static_assert(width != 0u, - "defining a Field type of width 0u is not allowed"); - }; -} -#endif + parent_register::shadow::shadow_value); + } + template + static void write(if_no_shadow* = nullptr) noexcept { + policy::template write( + parent_register::rw_mem_device()); + static_assert( + internals::check_overflow> offset)>::value, + "Field::write: value too large for the field"); + } + template + static void write(if_shadow* = nullptr) noexcept { + write(value); + static_assert( + internals::check_overflow> offset)>::value, + "Field::write: value too large for the field"); + } + static void set() noexcept { + policy::template set( + parent_register::rw_mem_device()); + } + static void clear() noexcept { + policy::template clear( + parent_register::rw_mem_device()); + } + static void toggle() noexcept { + policy::template toggle( + parent_register::rw_mem_device()); + } + static bool is_set() noexcept { + return (Field::read() == (mask >> offset)); + } + static bool is_clear() noexcept { + return (Field::read() == type{0}); + } + static_assert(parent_register::size >= width, + "Field:: field width is larger than parent register size"); + static_assert(parent_register::size >= width + offset, + "Field:: offset + width is larger than parent register size"); + static_assert(width != FieldWidth{0}, + "Field:: defining a Field type of zero width is not allowed"); +}; +} +#endif