The FPGA codebase was removed from the UHD repository in 2014 to reduce the size of the repository. However, over the last half-decade, the split between the repositories has proven more burdensome than it has been helpful. By merging the FPGA code back, it will be possible to create atomic commits that touch both FPGA and UHD codebases. Continuous integration testing is also simplified by merging the repositories, because it was previously difficult to automatically derive the correct UHD branch when testing a feature branch on the FPGA repository. This commit also updates the license files and paths therein. We are therefore merging the repositories again. Future development for FPGA code will happen in the same repository as the UHD host code and MPM code. == Original Codebase and Rebasing == The original FPGA repository will be hosted for the foreseeable future at its original local location: https://github.com/EttusResearch/fpga/ It can be used for bisecting, reference, and a more detailed history. The final commit from said repository to be merged here is 05003794e2da61cabf64dd278c45685a7abad7ec. This commit is tagged as v4.0.0.0-pre-uhd-merge. If you have changes in the FPGA repository that you want to rebase onto the UHD repository, simply run the following commands: - Create a directory to store patches (this should be an empty directory): mkdir ~/patches - Now make sure that your FPGA codebase is based on the same state as the code that was merged: cd src/fpga # Or wherever your FPGA code is stored git rebase v4.0.0.0-pre-uhd-merge Note: The rebase command may look slightly different depending on what exactly you're trying to rebase. - Create a patch set for your changes versus v4.0.0.0-pre-uhd-merge: git format-patch v4.0.0.0-pre-uhd-merge -o ~/patches Note: Make sure that only patches are stored in your output directory. It should otherwise be empty. Make sure that you picked the correct range of commits, and only commits you wanted to rebase were exported as patch files. - Go to the UHD repository and apply the patches: cd src/uhd # Or wherever your UHD repository is stored git am --directory fpga ~/patches/* rm -rf ~/patches # This is for cleanup == Contributors == The following people have contributed mainly to these files (this list is not complete): Co-authored-by: Alex Williams <alex.williams@ni.com> Co-authored-by: Andrej Rode <andrej.rode@ettus.com> Co-authored-by: Ashish Chaudhari <ashish@ettus.com> Co-authored-by: Ben Hilburn <ben.hilburn@ettus.com> Co-authored-by: Ciro Nishiguchi <ciro.nishiguchi@ni.com> Co-authored-by: Daniel Jepson <daniel.jepson@ni.com> Co-authored-by: Derek Kozel <derek.kozel@ettus.com> Co-authored-by: EJ Kreinar <ej@he360.com> Co-authored-by: Humberto Jimenez <humberto.jimenez@ni.com> Co-authored-by: Ian Buckley <ian.buckley@gmail.com> Co-authored-by: Jörg Hofrichter <joerg.hofrichter@ni.com> Co-authored-by: Jon Kiser <jon.kiser@ni.com> Co-authored-by: Josh Blum <josh@joshknows.com> Co-authored-by: Jonathon Pendlum <jonathan.pendlum@ettus.com> Co-authored-by: Martin Braun <martin.braun@ettus.com> Co-authored-by: Matt Ettus <matt@ettus.com> Co-authored-by: Michael West <michael.west@ettus.com> Co-authored-by: Moritz Fischer <moritz.fischer@ettus.com> Co-authored-by: Nick Foster <nick@ettus.com> Co-authored-by: Nicolas Cuervo <nicolas.cuervo@ettus.com> Co-authored-by: Paul Butler <paul.butler@ni.com> Co-authored-by: Paul David <paul.david@ettus.com> Co-authored-by: Ryan Marlow <ryan.marlow@ettus.com> Co-authored-by: Sugandha Gupta <sugandha.gupta@ettus.com> Co-authored-by: Sylvain Munaut <tnt@246tNt.com> Co-authored-by: Trung Tran <trung.tran@ettus.com> Co-authored-by: Vidush Vishwanath <vidush.vishwanath@ettus.com> Co-authored-by: Wade Fife <wade.fife@ettus.com>
7 KiB
UHD Coding Standards
Note: This file applies to all code within the UHD repository, not just for code that is actually part of the UHD library.
Preamble
To quote R. W. Emerson: "A foolish consistency is the hobgoblin of little minds, adored by little statesmen and philosophers and divines". Ignoring the little statesmen for a minute, these coding standards are here to make our life easier, not simply add additional rules. They are meant as additional guidance for developers, and are not meant to be interpreted as law.
So, ultimately, it is up to the developer to decide how much these guidelines should be heeded when writing code, and up to reviewers how much they are relevant to new submissions. That said, a consistent codebase is easier to maintain, read, understand, and extend. Choosing personal preferences over these coding guidelines is not a helpful move for the team and future maintainability of the UHD codebase.
General Coding Guidelines
- Never submit code with trailing whitespace.
- Code layout: We use 4 spaces for indentation levels, and never tabs.
- Code is read more often than it's written. Code readability is thus something worth optimizing for.
- Try and keep line lengths to 79 characters, unless readability suffers. We often have to do fun things like SSH into machines and edit code in a terminal, and do side-by-side views of code on small-ish screens, so this is actually pretty helpful.
- Go crazy with log messages. Trace-level log messages in particular can be used copiously and freely (unless in rare cases where they can interfere with performance). Note that in C++, we have the option of fully compiling out trace-level messages (and even higher levels).
C++-specific Guidelines
- All C++ code must be formatted according to the .clang-format file in the root of the project.
- If in doubt, consult the C++ Core Guidelines. If the guidelines have an answer, and it works for you, just pick that.
- Use Doxygen doc-blocks copiously.
- All things equal, prefer standard C++ constructs over Boost constructs (see also Boost guidelines).
- Given the option, prefer C++ lambdas over std::bind, and just don't use boost::bind.
size_tis the correct container for all indexing of C++ structures (such as vectors). But keep in mind that the size ofsize_tis platform-dependent!- Use size-specific types whenever interacting with hardware (
int32_t, etc.). It's very easy to get bitten by incorrect sizes. - Include include files in the following order: Local headers, other UHD headers, 3rd-party library headers, Boost headers, standard headers. The rationale is to include from most to least specific. This is the best way to catch missing includes (if you were to include the standard header first, it would be available to all include files that come later. If they need that standard header too, they should be including it themselves). Note that clang-format will do this for you. Example:
#include "x300_specific.hpp"
#include <uhd/utils/log.hpp>
#include <libusb/foo.hpp>
#include <boost/shared_ptr.hpp>
#include <mutex>
- Feel free to use modern C/C++ features even if they were not used before. Make sure they work with the compilers and dependencies which are set for the version of UHD the commit will be made upon. The Ettus CI system will be able to confirm this. For interesting new features, use 'anchor commits', which describe clearly which new feature was used. They can be used as a reference for other developers. Example:
commit 9fe731cc371efee7f0051186697e611571c5b41b
Author: Andrej Rode <andrej.rode@ettus.com>
Date: Tue Nov 22 16:19:38 2016 -0800
utils: uhd_find_devices display one device for each unique serial found
Note: This also is the first precedent for the usage of the 'auto' keyword
in UHD. Commits past this one will also be able to use 'auto'.
Reviewed-By: Martin Braun <martin.braun@ettus.com>
- Prefer
.at()over[]for maps and vectors. Keep in mind that[]will invoke a default constructor of the value type, whereas.at()will throw an exception if the index doesn't exist -- which is usually the desired behaviour.
Boost-specific Guidelines
- Avoid Boost where possible.
- Don't use Boost's sleep functions. Prefer
std::chronofunctions. - When using
boost::assign::list_oforboost::assign::map_list_of, make sure to explicitly cast to the appropriate container (even better: Avoidboost::assign, maybe use std initializer lists where possible):
std::vector<std::string> foo =
boost::assign::list_of<std::string> // Explicitly list the type (in this
("string1") // case, std::string). Then list all
("string2") // the items (string1, string2, etc).
("etc")
.to_container(foo); // Finally, call conversion routine explicitly.
// Same for maps:
std::map<std::string, std::string> bar =
boost::assign::map_list_of<std::string, std::string>
("a", "b")
("c", "d")
("etc", "etc")
.to_container(bar);
Python-specific Guidelines
- Starting with UHD 4.0, Python 2 is no longer supported, and we don't need to accommodate for it any longer. Prefer Python 3 constructs.
- Follow the suggestions in PEP8 and PEP257. The former is about code layout in general, the latter about docstrings.
- Pylint is good tool for helping with following code guidelines. It's very fussy though, so don't get too worked up about following its suggestions.
CMake-specific Guidelines
- CMake commands are written in lowercase.
Revision Control Hygiene
- In this repository, we almost always use fast-forward merges, and no merge commits.
- Prefix all commit message subject lines with the section of code they apply to, and use the imperative mood (Example: "x300: Fix overflow at full moon"). Try and keep the subject line to 50 characters, but make 72 characters a hard limit.
- Follow up in greater detail in the body of the commmit message. The body is separated from the subject line with one blank line. Consider the body of the git commit an email to the future reader of this changeset, so don't be sparse in the commit body, and use it to explain the what and why of this commit (the "how" part should be obvious from the code change). Lines should be limited to 72 characters.
- Avoid refactoring, whitespace cleanup, or fixing code to match coding guidelines in the same commit as modifying behaviour. Prefer dedicated cleanup commits.
- Remember that we ship git repositories, not just code. This means every commit is part of our product and should be treated as such.
FPGA Guidelines
FPGA guidelines are stored in a separate file. See CODING.md in the FPGA repository.