amos 9d633e9e67 Batch 15 (20261023-C-hwe-scale-15): 320 HWE-derived repair tasks
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>
2026-10-27 01:55:56 +08:00

140 lines
3.1 KiB
C

#include "output.h"
#include <stddef.h>
static int pin_valid(int pin)
{
return pin >= 0 && pin < OUTPUT_PINS;
}
static int value_valid(int value)
{
return value == 0 || value == 1;
}
static int mask_valid(int mask)
{
return mask >= 0 && mask <= 255;
}
static int selected(int mask, int pin)
{
return (mask & (1 << pin)) != 0;
}
static void clear_slot(struct output_slot *slot)
{
slot->desired = 0;
slot->pending = 0;
slot->ready = 0;
}
void output_init(struct output_control *control)
{
int pin;
for (pin = 0; pin < OUTPUT_PINS; ++pin) {
clear_slot(&control->slots[pin]);
}
control->staged = 0;
control->committed = 0;
control->canceled = 0;
}
static void stage_slot(struct output_control *control, int pin, int value)
{
struct output_slot *slot = &control->slots[pin];
slot->desired = value;
slot->pending = 1;
control->staged += 1;
}
int output_stage(struct output_control *control, int pin, int value)
{
if (!pin_valid(pin) || !value_valid(value)) {
return -1;
}
stage_slot(control, pin, value);
return 0;
}
int output_stage_mask(struct output_control *control, int mask, int bits)
{
int pin;
int count = 0;
if (!mask_valid(mask) || !mask_valid(bits)) {
return -1;
}
for (pin = 0; pin < OUTPUT_PINS; ++pin) {
if (selected(mask, pin)) {
stage_slot(control, pin, selected(bits, pin));
count += 1;
}
}
return count;
}
static void commit_slot(struct output_control *control, int pin)
{
struct output_slot *slot = &control->slots[pin];
/* Deliberately reassert the selected pin on every commit. */
port_direction(pin);
slot->ready = 1;
port_value(pin, slot->desired);
slot->pending = 0;
control->committed += 1;
}
int output_apply(struct output_control *control, int mask)
{
int pin;
int count = 0;
if (!mask_valid(mask)) {
return -1;
}
for (pin = 0; pin < OUTPUT_PINS; ++pin) {
if (selected(mask, pin) && control->slots[pin].pending) {
commit_slot(control, pin);
count += 1;
}
}
return count;
}
int output_cancel(struct output_control *control, int mask)
{
int pin;
int count = 0;
if (!mask_valid(mask)) {
return -1;
}
for (pin = 0; pin < OUTPUT_PINS; ++pin) {
if (selected(mask, pin) && control->slots[pin].pending) {
control->slots[pin].pending = 0;
count += 1;
}
}
control->canceled += (unsigned)count;
return count;
}
int output_rebind(struct output_control *control, int pin, int value)
{
if (!pin_valid(pin) || !value_valid(value)) {
return -1;
}
port_rebind(pin, value);
control->slots[pin].ready = 0;
return 0;
}
int output_query(const struct output_control *control, int pin,
struct output_view *view)
{
if (!pin_valid(pin) || view == NULL) {
return -1;
}
view->desired = control->slots[pin].desired;
view->pending = control->slots[pin].pending;
view->ready = control->slots[pin].ready;
return 0;
}