Repository navigation
RVC4: keep on-board frame sync when the FSYNC pin is busy, add the ISOLATED role #2206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
c8c74e1
Add the STANDALONE external frame sync role
sb-lxn 0ece0e2
Pipeline: start STANDALONE devices with the frame sync masters
sb-lxn aa2182c
Test on-board frame sync in the STANDALONE role
sb-lxn 24563ef
Merge remote-tracking branch 'origin/develop' into feat/aux-controlle…
sb-lxn 3457839
Bump rvc4 device
sb-lxn f440886
DeviceBase: document the frame sync role results
sb-lxn 86b5a5a
bump rvc4 device
sb-lxn f844a30
Merge remote-tracking branch 'origin/develop' into feat/aux-controlle…
sb-lxn 2eb8e79
FsyncController: keep the frame sync role in one RoleState
sb-lxn 1d30b0f
FsyncController: write CONFIG 0 at start, apply the role when the pip…
sb-lxn 712cd57
FsyncController: add the STANDALONE frame sync role
sb-lxn 18dd10e
FsyncController: keep on-board sync when the FSYNC pin is unavailable
sb-lxn ed6a118
FsyncController: name the holder of a busy FSYNC pin
sb-lxn 912f2f0
PipelineBuilder: check a forced frame sync role before building the n…
sb-lxn 68b0f5c
FsyncController: read CONFIG back before keeping on-board sync
sb-lxn 106fffa
FsyncController: fail an explicit role when fsync-stm cannot be opened
sb-lxn f3efcac
FsyncController: fail an explicit role after an earlier controller fa…
sb-lxn ab52822
Merge remote-tracking branch 'origin/develop' into feat/aux-controlle…
sb-lxn 7533ac3
chore(rvc4): pass the comment lint in the FSYNC and aux connector code
sb-lxn 1d96d47
Build the RVC4 firmware on Luxonis OS 1.50.0
sb-lxn 153e296
Rename the STANDALONE external frame sync role to ISOLATED
sb-lxn c464274
Refuse a frame sync role change while a pipeline runs
sb-lxn ef91a29
FsyncController: fail a forced role on a device without external fram…
sb-lxn 314dfa3
FsyncController: tie EAGAIN and EBUSY to the connector state
sb-lxn f9339a2
Tests: check the RVC4 frame sync role rules on the host
sb-lxn cae43e3
Tests: require the isolated camera log in the ISOLATED frame sync case
sb-lxn 227ab8a
FsyncController: apply AUTO_DETECT again at a later pipeline start
sb-lxn 04fc419
DeviceBase: say when the frame sync role is final and what a SLAVE needs
sb-lxn 9f729a7
Examples: apply the frame sync role before reading it
sb-lxn 30db263
FsyncController: share the device tree string reader
sb-lxn a1c785e
FsyncController: keep linux/aux-connector.h out of AuxConnector.hpp
sb-lxn 6b32d7f
DeviceBase: say that a controller failure lasts for the session
sb-lxn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,170 @@ | ||
| #include "utilities/AuxConnector.hpp" | ||
|
|
||
| #include <fcntl.h> | ||
| #include <linux/aux-connector.h> | ||
| #include <linux/gpio.h> | ||
| #include <sys/ioctl.h> | ||
| #include <unistd.h> | ||
|
|
||
| #include <algorithm> | ||
| #include <cerrno> | ||
| #include <cstring> | ||
| #include <fstream> | ||
| #include <system_error> | ||
|
|
||
| #include "utilities/OSUtils.hpp" | ||
|
|
||
| namespace dai { | ||
| namespace aux { | ||
|
|
||
| namespace { | ||
|
|
||
| template <std::size_t N> | ||
| std::string fixedString(const char (&chars)[N]) { | ||
| return std::string(chars, strnlen(chars, N)); // A kernel string that fills its whole array has no NUL | ||
| } | ||
|
|
||
| struct FileDescriptor { | ||
| int fd; | ||
| explicit FileDescriptor(int fd) : fd(fd) {} | ||
| FileDescriptor(const FileDescriptor&) = delete; | ||
| FileDescriptor& operator=(const FileDescriptor&) = delete; | ||
| ~FileDescriptor() { | ||
| if(fd >= 0) { | ||
| close(fd); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| } // namespace | ||
|
|
||
| bool fsyncLinkedToConnector(const std::filesystem::path& deviceTree) { | ||
| auto node = gate::readDeviceTreeString(deviceTree / "aliases/stm_fsync"); | ||
| if(!node || node->empty()) { | ||
| return false; | ||
| } | ||
| std::error_code ec; | ||
| if(!std::filesystem::exists(deviceTree / std::filesystem::path(*node).relative_path() / "luxonis,aux-connector", ec)) { | ||
| return false; | ||
| } | ||
| auto status = gate::readDeviceTreeString(deviceTree / "aux-connector/status"); | ||
| return !status || *status == "okay" || *status == "ok"; | ||
| } | ||
|
|
||
| bool connectorBound(const std::filesystem::path& device) { | ||
| int fd = open(device.c_str(), O_RDONLY | O_CLOEXEC); | ||
| if(fd < 0) { | ||
| return false; | ||
| } | ||
| close(fd); | ||
| return true; | ||
| } | ||
|
|
||
| Pin parsePin(const aux_pin_info& info, const aux_pin_state& state) { | ||
| Pin pin{info.pin, fixedString(info.label), {}, std::nullopt, {NoOwner{}, (state.flags & AUX_PIN_FLAG_LINE) != 0}}; | ||
| for(uint32_t i = 0; i < std::min<uint32_t>(info.nfuncs, AUX_MAX_PIN_FUNCS); i++) { | ||
| pin.functions.push_back(info.funcs[i].function); | ||
| } | ||
| if(info.gpio.chip[0] != '\0') { | ||
| pin.gpio = GpioLineRef{fixedString(info.gpio.chip), info.gpio.offset}; | ||
| } | ||
| switch(state.owner.type) { | ||
| case AUX_OWNER_ME: | ||
| case AUX_OWNER_OTHER: | ||
| pin.state.owner = ProcessOwner{static_cast<pid_t>(state.owner.pid)}; | ||
| break; | ||
| case AUX_OWNER_KERNEL: | ||
| pin.state.owner = KernelOwner{fixedString(state.owner.name)}; | ||
| break; | ||
| default: | ||
| break; | ||
| } | ||
| return pin; | ||
| } | ||
|
|
||
| std::optional<Pin> findPinWithFunction(const std::vector<Pin>& pins, uint32_t function) { | ||
| auto pin = std::find_if(pins.begin(), pins.end(), [function](const Pin& candidate) { | ||
| return std::find(candidate.functions.begin(), candidate.functions.end(), function) != candidate.functions.end(); | ||
| }); | ||
| if(pin == pins.end()) { | ||
| return std::nullopt; | ||
| } | ||
| return *pin; | ||
| } | ||
|
|
||
| std::variant<std::vector<Pin>, int> readConnector(const std::filesystem::path& device) { | ||
| FileDescriptor connector(open(device.c_str(), O_RDONLY | O_CLOEXEC)); | ||
| if(connector.fd < 0) { | ||
| return errno; | ||
| } | ||
| aux_info info{}; | ||
| info.size = sizeof(info); | ||
| if(ioctl(connector.fd, AUX_IOC_INFO, &info) != 0) { | ||
| return errno; | ||
| } | ||
| aux_state state{}; | ||
| state.size = sizeof(state); | ||
| if(ioctl(connector.fd, AUX_IOC_STATE, &state) != 0) { | ||
| return errno; | ||
| } | ||
| std::vector<Pin> pins; | ||
| for(uint32_t index = 0; index < std::min<uint32_t>(info.npins, AUX_MAX_PINS); index++) { | ||
| aux_pin_info pinInfo{}; | ||
| pinInfo.size = sizeof(pinInfo); | ||
| pinInfo.pin = index; | ||
| if(ioctl(connector.fd, AUX_IOC_PIN_INFO, &pinInfo) != 0) { | ||
| return errno; | ||
| } | ||
| pins.push_back(parsePin(pinInfo, state.pins[index])); | ||
| } | ||
| return pins; | ||
| } | ||
|
|
||
| std::string readComm(pid_t pid) { | ||
| std::ifstream file("/proc/" + std::to_string(pid) + "/comm"); | ||
| std::string comm; | ||
| std::getline(file, comm); | ||
| return comm; | ||
| } | ||
|
|
||
| std::string lineConsumer(const GpioLineRef& line) { | ||
| std::error_code ec; | ||
| for(std::filesystem::directory_iterator entry("/dev", ec), end; !ec && entry != end; entry.increment(ec)) { | ||
| if(entry->path().filename().string().rfind("gpiochip", 0) != 0) { | ||
| continue; | ||
| } | ||
| FileDescriptor chipFd(open(entry->path().c_str(), O_RDONLY | O_CLOEXEC)); | ||
| gpiochip_info chip{}; | ||
| if(chipFd.fd < 0 || ioctl(chipFd.fd, GPIO_GET_CHIPINFO_IOCTL, &chip) != 0 || fixedString(chip.label) != line.chip) { | ||
| continue; | ||
| } | ||
| gpio_v2_line_info lineInfo{}; | ||
| lineInfo.offset = line.offset; | ||
| if(ioctl(chipFd.fd, GPIO_V2_GET_LINEINFO_IOCTL, &lineInfo) != 0) { | ||
| return ""; | ||
| } | ||
| std::string consumer = fixedString(lineInfo.consumer); | ||
| return consumer == "?" ? "" : consumer; // gpiolib names the consumer of a request that gave none "?" | ||
| } | ||
| return ""; | ||
| } | ||
|
|
||
| gate::PinUnavailable busyFsyncPin(const std::vector<Pin>& pins) { | ||
| gate::PinUnavailable busy{gate::PinProblem::Busy, "", std::nullopt}; | ||
| auto pin = findPinWithFunction(pins, AUX_FUNC_FSYNC); | ||
| if(!pin) { | ||
| return busy; | ||
| } | ||
| busy.pinLabel = pin->label; | ||
| if(const auto* process = std::get_if<ProcessOwner>(&pin->state.owner)) { | ||
| busy.holder = gate::ProcessHolder{process->pid, readComm(process->pid)}; | ||
| } else if(const auto* kernel = std::get_if<KernelOwner>(&pin->state.owner)) { | ||
| busy.holder = gate::KernelHolder{kernel->name}; | ||
| } else if(pin->state.lineRequested) { | ||
| busy.holder = gate::LineHolder{"aux-" + pin->label, pin->gpio ? lineConsumer(*pin->gpio) : ""}; // The connector names its lines aux-<label> | ||
| } | ||
| return busy; | ||
| } | ||
|
|
||
| } // namespace aux | ||
| } // namespace dai |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| #pragma once | ||
|
|
||
| #include <sys/types.h> | ||
|
|
||
| #include <cstdint> | ||
| #include <filesystem> | ||
| #include <optional> | ||
| #include <string> | ||
| #include <variant> | ||
| #include <vector> | ||
|
|
||
| #include "utilities/FsyncRole.hpp" | ||
|
|
||
| struct aux_pin_info; | ||
| struct aux_pin_state; | ||
|
|
||
| namespace dai { | ||
| namespace aux { | ||
|
|
||
| bool fsyncLinkedToConnector(const std::filesystem::path& deviceTree = "/proc/device-tree"); // fsync-stm looks the connector up only with this link | ||
|
|
||
| bool connectorBound(const std::filesystem::path& device = "/dev/aux-connector"); | ||
|
|
||
| struct GpioLineRef { | ||
| std::string chip; | ||
| uint32_t offset; | ||
| }; | ||
|
|
||
| struct NoOwner {}; | ||
| struct ProcessOwner { | ||
| pid_t pid; | ||
| }; | ||
| struct KernelOwner { | ||
| std::string name; | ||
| }; | ||
| using Owner = std::variant<NoOwner, ProcessOwner, KernelOwner>; | ||
|
|
||
| struct PinState { | ||
| Owner owner; | ||
| bool lineRequested; | ||
| }; | ||
|
|
||
| struct Pin { | ||
| uint32_t index; | ||
| std::string label; | ||
| std::vector<uint32_t> functions; // AUX_FUNC_*, empty on a fixed pin | ||
| std::optional<GpioLineRef> gpio; | ||
| PinState state; | ||
| }; | ||
|
|
||
| Pin parsePin(const aux_pin_info& info, const aux_pin_state& state); | ||
| std::optional<Pin> findPinWithFunction(const std::vector<Pin>& pins, uint32_t function); | ||
|
|
||
| std::variant<std::vector<Pin>, int> readConnector(const std::filesystem::path& device = "/dev/aux-connector"); | ||
|
|
||
| std::string readComm(pid_t pid); | ||
|
|
||
| std::string lineConsumer(const GpioLineRef& line); | ||
|
|
||
| gate::PinUnavailable busyFsyncPin(const std::vector<Pin>& pins); | ||
|
|
||
| } // namespace aux | ||
| } // namespace dai |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
M1. A role change from STANDALONE to MASTER while the cameras stream crashes the firmware.
The RPC applies the role at once and has no check for a running pipeline. STANDALONE is the first role in which a pipeline streams with CONFIG 0, so develop cannot reach this state. The RPC returns
(True, ''). Then no frames come for 10 s, CamX aborts inExtensionModule::RecoveryThread(SIGABRT), and the host reportsDevice ... has crashed. Seen in 2 of 4 sessions on an OAK4-LITE with OS 1.49.1 (0 of 5 changes on an OAK4-D with OS 1.44.0). MASTER to STANDALONE, MASTER to SLAVE and MASTER to MASTER while running never crashed.Smallest fix: In
setExternalFrameSyncRole, refuse a change while a pipeline runs. Or keep the role and apply it at the next start (waitForDeviceReadyalready callsapplyPendingRole). If live changes must stay, ask the STM and OS owners if a CONFIG change while streaming is supported.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refusing to change role while running is the best fix here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in c464274. The
setExternalFrameSyncRoleRPC returns false while a pipeline runs and writes nothing:Cannot set external frame sync role {ROLE} while a pipeline runs. Set the role before the pipeline starts.On an OAK4-LITE R1 PoE, ISOLATED to MASTER, MASTER to MASTER and MASTER to ISOLATED while streaming each returned that text. The role read stayed, 510 Sync groups came in the 17 s after the call, and nothing crashed.