100 tasks from the HWE arm-linux code-gen pool (outside the lk/man/pth range given to batch 22), each with at least one independent contract-edge defect and plain public docs. Claude reviewed 100/100 USABLE against current digests; no ID or source overlap with main or batch 22. Difficulty is unmeasured. progress.md records the wrap-up: all Codex sessions and Qwen schedulers stopped for the user's rollout, Qwen results so far (57 HARD of 373), and what is left on each batch branch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
260 lines
5.4 KiB
C++
260 lines
5.4 KiB
C++
#include "model.hpp"
|
|
namespace lineirq {
|
|
Controller::Controller()
|
|
{
|
|
reset();
|
|
}
|
|
Reply Controller::result(int code, std::uint64_t value)
|
|
{
|
|
Reply reply;
|
|
reply.code = code;
|
|
reply.value = value;
|
|
return reply;
|
|
}
|
|
bool Controller::in_range(long long id)
|
|
{
|
|
return id >= 0 && id < 6;
|
|
}
|
|
View Controller::blank()
|
|
{
|
|
View line;
|
|
line.live = 0;
|
|
line.mode = 0;
|
|
line.priority = 0;
|
|
line.depth = 0;
|
|
line.pending = 0;
|
|
line.active = 0;
|
|
line.asserted = 0;
|
|
line.received = 0;
|
|
line.handled = 0;
|
|
line.entries = 0;
|
|
return line;
|
|
}
|
|
void Controller::clear_line(int id)
|
|
{
|
|
lines_[id] = blank();
|
|
}
|
|
Reply Controller::reset()
|
|
{
|
|
for (int id = 0; id < 6; ++id) {
|
|
clear_line(id);
|
|
}
|
|
for (std::uint64_t& counter : counters_) {
|
|
counter = 0;
|
|
}
|
|
return result(0);
|
|
}
|
|
Reply Controller::install(long long id, long long mode, long long priority)
|
|
{
|
|
if (!in_range(id)) {
|
|
return result(-1);
|
|
}
|
|
if (mode < 0 || mode > 1) {
|
|
return result(-1);
|
|
}
|
|
if (priority < 0 || priority > 7) {
|
|
return result(-1);
|
|
}
|
|
if (lines_[id].live) {
|
|
return result(-3);
|
|
}
|
|
View replacement = blank();
|
|
replacement.live = 1;
|
|
replacement.mode = static_cast<int>(mode);
|
|
replacement.priority = static_cast<int>(priority);
|
|
lines_[id] = replacement;
|
|
++counters_[0];
|
|
return result(0);
|
|
}
|
|
Reply Controller::remove(long long id)
|
|
{
|
|
if (!in_range(id)) {
|
|
return result(-1);
|
|
}
|
|
const View& line = lines_[id];
|
|
if (!line.live) {
|
|
return result(-2);
|
|
}
|
|
if (line.active) {
|
|
return result(-4);
|
|
}
|
|
clear_line(static_cast<int>(id));
|
|
++counters_[1];
|
|
return result(0);
|
|
}
|
|
Reply Controller::pulse(long long id, long long count)
|
|
{
|
|
if (!in_range(id)) {
|
|
return result(-1);
|
|
}
|
|
if (count < 0 || count > 16) {
|
|
return result(-1);
|
|
}
|
|
View& line = lines_[id];
|
|
if (!line.live) {
|
|
return result(-2);
|
|
}
|
|
if (line.mode != 0) {
|
|
return result(-7);
|
|
}
|
|
line.received += static_cast<std::uint64_t>(count);
|
|
if (count > 0) {
|
|
line.pending = 1;
|
|
}
|
|
++counters_[4];
|
|
return result(0);
|
|
}
|
|
Reply Controller::level(long long id, long long value)
|
|
{
|
|
if (!in_range(id)) {
|
|
return result(-1);
|
|
}
|
|
if (value < 0 || value > 1) {
|
|
return result(-1);
|
|
}
|
|
View& line = lines_[id];
|
|
if (!line.live) {
|
|
return result(-2);
|
|
}
|
|
if (line.mode != 1) {
|
|
return result(-7);
|
|
}
|
|
if (value != 0 && line.asserted == 0) {
|
|
++line.received;
|
|
}
|
|
line.asserted = static_cast<int>(value);
|
|
line.pending = static_cast<int>(value);
|
|
++counters_[5];
|
|
return result(0);
|
|
}
|
|
Reply Controller::countset(long long id, long long value)
|
|
{
|
|
if (!in_range(id)) {
|
|
return result(-1);
|
|
}
|
|
if (value < 0 || value > 1000000) {
|
|
return result(-1);
|
|
}
|
|
View& line = lines_[id];
|
|
if (!line.live) {
|
|
return result(-2);
|
|
}
|
|
if (line.active) {
|
|
return result(-4);
|
|
}
|
|
line.handled = static_cast<std::uint64_t>(value);
|
|
++counters_[8];
|
|
return result(0);
|
|
}
|
|
bool Controller::deliverable(const View& line)
|
|
{
|
|
if (!line.live) {
|
|
return false;
|
|
}
|
|
if (line.depth != 0) {
|
|
return false;
|
|
}
|
|
if (line.active) {
|
|
return false;
|
|
}
|
|
return line.pending != 0;
|
|
}
|
|
int Controller::choose() const
|
|
{
|
|
int selected = -1;
|
|
for (int id = 0; id < 6; ++id) {
|
|
if (!deliverable(lines_[id])) {
|
|
continue;
|
|
}
|
|
if (selected < 0) {
|
|
selected = id;
|
|
continue;
|
|
}
|
|
if (lines_[id].priority < lines_[selected].priority) {
|
|
selected = id;
|
|
}
|
|
}
|
|
return selected;
|
|
}
|
|
Reply Controller::enter()
|
|
{
|
|
const int id = choose();
|
|
if (id < 0) {
|
|
return result(-5);
|
|
}
|
|
View& line = lines_[id];
|
|
line.pending = 0;
|
|
line.active = 1;
|
|
++line.entries;
|
|
++counters_[6];
|
|
return result(0, static_cast<std::uint64_t>(id));
|
|
}
|
|
Reply Controller::finish(long long id)
|
|
{
|
|
if (!in_range(id)) {
|
|
return result(-1);
|
|
}
|
|
View& line = lines_[id];
|
|
if (!line.live) {
|
|
return result(-2);
|
|
}
|
|
if (!line.active) {
|
|
return result(-5);
|
|
}
|
|
line.active = 0;
|
|
++line.handled;
|
|
if (line.mode == 1) {
|
|
line.pending = line.asserted;
|
|
}
|
|
++counters_[7];
|
|
return result(0);
|
|
}
|
|
Reply Controller::inspect(long long id, View& output) const
|
|
{
|
|
output = blank();
|
|
if (!in_range(id)) {
|
|
return result(-1);
|
|
}
|
|
output = lines_[id];
|
|
return result(0);
|
|
}
|
|
Reply Controller::count(long long id) const
|
|
{
|
|
if (!in_range(id)) {
|
|
return result(-1);
|
|
}
|
|
if (!lines_[id].live) {
|
|
return result(-2);
|
|
}
|
|
return result(0, lines_[id].handled);
|
|
}
|
|
Reply Controller::ready(long long id) const
|
|
{
|
|
if (!in_range(id)) {
|
|
return result(-1);
|
|
}
|
|
if (!lines_[id].live) {
|
|
return result(-2);
|
|
}
|
|
const bool value = deliverable(lines_[id]);
|
|
return result(0, value ? 1 : 0);
|
|
}
|
|
Counters Controller::totals() const
|
|
{
|
|
Counters output{};
|
|
for (std::size_t index = 0; index < output.size(); ++index) {
|
|
output[index] = counters_[index];
|
|
}
|
|
return output;
|
|
}
|
|
Snapshot Controller::snapshot() const
|
|
{
|
|
Snapshot output;
|
|
output.counters = totals();
|
|
for (int id = 0; id < 6; ++id) {
|
|
output.lines[id] = lines_[id];
|
|
}
|
|
return output;
|
|
}
|
|
}
|