One user-space repair task per eligible HWE debug-diag / compile-deploy base ID: 320 admitted (C 218, C++ 97, build scripts 5), 1 skipped by the content filter. Each ships a public spec with a check-to-basis table, at least two defects with single-fix fixtures, a symptom-masking fixture and an alternative correct implementation. Claude re-checked all 320: structure, the HWE quality items and trace6 Docker calibration receipts against current digests (320/320 USABLE). Difficulty is unmeasured. Known follow-up: 212 tasks use 120 ad-hoc family names; the next batch maps them to the canonical list. The batch's 1,256-line progress log stays in its factory report and the 36-local branch batch15-hwe. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
123 lines
3.3 KiB
C
123 lines
3.3 KiB
C
#include "scan.h"
|
|
#include <inttypes.h>
|
|
#include <string.h>
|
|
|
|
void scanner_init(Scanner *scanner, Port *port)
|
|
{
|
|
scanner->port = port;
|
|
for (int slot = 0; slot < SESSION_COUNT; slot++) {
|
|
Session *session = &scanner->sessions[slot];
|
|
session->handle = -1;
|
|
session->bus = -1;
|
|
session->sweeps = 0;
|
|
session->discoveries = 0;
|
|
}
|
|
}
|
|
|
|
int scanner_close(Scanner *scanner, int slot)
|
|
{
|
|
if (slot < 0 || slot >= SESSION_COUNT) {
|
|
return ERR_INVALID;
|
|
}
|
|
Session *session = &scanner->sessions[slot];
|
|
int result = 0;
|
|
if (session->handle >= 0) {
|
|
result = port_close(scanner->port, session->handle);
|
|
}
|
|
session->handle = -1;
|
|
session->bus = -1;
|
|
return result;
|
|
}
|
|
|
|
static int prepare(Scanner *scanner, int slot, int bus)
|
|
{
|
|
Session *session = &scanner->sessions[slot];
|
|
if (session->handle >= 0 && session->bus != bus) {
|
|
scanner_close(scanner, slot);
|
|
}
|
|
if (session->handle < 0) {
|
|
int descriptor = port_open(scanner->port, bus);
|
|
if (descriptor < 0) {
|
|
return descriptor;
|
|
}
|
|
session->handle = descriptor;
|
|
session->bus = bus;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static int probe(Scanner *scanner, int slot, int address, ScanResult *result)
|
|
{
|
|
Session *session = &scanner->sessions[slot];
|
|
int status = port_select(scanner->port, session->handle, address);
|
|
if (status < 0) {
|
|
return status;
|
|
}
|
|
int value = 0;
|
|
status = port_read(scanner->port, session->handle, &value);
|
|
result->visited++;
|
|
if (status < 0) {
|
|
return status;
|
|
}
|
|
if (status == 1) {
|
|
result->seen[address] = 1;
|
|
result->values[address] = value;
|
|
result->found++;
|
|
result->digest = result->digest * UINT64_C(131) +
|
|
(uint64_t)(address * 65536 + value + 1);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int scanner_run(Scanner *scanner, int slot, int bus, int low, int high,
|
|
int reverse, ScanResult *result)
|
|
{
|
|
memset(result, 0, sizeof(*result));
|
|
if (slot < 0 || slot >= SESSION_COUNT || bus < 0 || bus >= BUS_COUNT) {
|
|
return ERR_INVALID;
|
|
}
|
|
if (low < 3 || high > 119 || low > high || (reverse != 0 && reverse != 1)) {
|
|
return ERR_INVALID;
|
|
}
|
|
bus = 0;
|
|
int status = prepare(scanner, slot, bus);
|
|
if (status < 0) {
|
|
return status;
|
|
}
|
|
int address = reverse ? high : low;
|
|
int last = reverse ? low : high;
|
|
int step = reverse ? -1 : 1;
|
|
for (;;) {
|
|
status = probe(scanner, slot, address, result);
|
|
if (status < 0) {
|
|
scanner_close(scanner, slot);
|
|
return status;
|
|
}
|
|
if (address == last) {
|
|
break;
|
|
}
|
|
address += step;
|
|
}
|
|
Session *session = &scanner->sessions[slot];
|
|
session->sweeps++;
|
|
session->discoveries += (uint64_t)result->found;
|
|
return 0;
|
|
}
|
|
|
|
void scanner_finish(Scanner *scanner)
|
|
{
|
|
for (int slot = 0; slot < SESSION_COUNT; slot++) {
|
|
scanner_close(scanner, slot);
|
|
}
|
|
}
|
|
|
|
void scanner_dump(const Scanner *scanner, FILE *output)
|
|
{
|
|
for (int slot = 0; slot < SESSION_COUNT; slot++) {
|
|
const Session *session = &scanner->sessions[slot];
|
|
fprintf(output, "Q %d %d %d %" PRIu64 " %" PRIu64 "\n", slot,
|
|
session->handle, session->bus, session->sweeps,
|
|
session->discoveries);
|
|
}
|
|
}
|