Files
STM32F4-Base/Drivers/BSP/IOBOARD/ioboard_bits.h
T
wandering1 74efa671bb feat(ioboard): wire 6 new CubeMX pins into 10-channel DO driver
Flat-expand the board output driver from 4 to 10 channels as decided:
IOBOARD_DO_COUNT 4->10, mask uint8_t->uint16_t, IOBOARD_DO_MASK_ALL
0x03FF.  The 6 new pins keep their bit positions: KO_LED1=PF2(bit4),
KO_LED2=PF3(bit5), KO_24V=PF4(bit6), KO4=PF5(bit7), KO5=PC15(bit8),
KO_LED3=PE6(bit9); the original 4 (KO6/TRIP/ERT/CLZ) keep bit0..3.
Backups-domain PC15 is used as a signal bit only (+/-3 mA limit).

No 24V supply interlock and no LED special-casing: the driver writes
KO_24V as an ordinary bit; callers needing relay power sequencing must
assert it before energizing a channel.  do_write/get/read_level and the
shadow register are all uint16_t; do_apply flushes four port segments
(GPIOC/GPIOF/GPIOC/GPIOE) and do_read_level caches three port ODRs.

UI: UI_DATA_DO_N 4->10, dio_do_mask uint16_t, UI_DATA_VER 3->4 because
dio_do_valid shifts 211->212; feed mask and dio row table extended;
content-page golden references regenerated for 51 rows / 7 pages.
Host ioboard tests 127/127 and ui_data tests 305/305 pass; Keil rebuild
0 errors 0 warnings.  RAM ledger, memory snapshot and size attestation
refilled from the authoritative map.  Docs: ioboard spec v1.2->v1.3 and
the resolved 6-pin question closed out.
2026-11-18 14:25:32 +08:00

59 lines
2.7 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#ifndef IOBOARD_BITS_H
#define IOBOARD_BITS_H
/*
* 模块名称:开入开出板的纯逻辑层(位序组装)
* 模块功能:把「74HC165 按手册时序串行读出的 8 个比特」组装成「A 在 LSB」的开入 mask。
* 适用平台:只依赖 <stdint.h>,不 include HAL / CMSIS / FreeRTOS / main.h。
* 主机侧(MSVC)单测直接 include ioboard_bits.c 即可,无需任何桩目录。
* 作者:王建锋
* 创建日期:2026-11-16
* 修改记录:
* 2026-11-16 王建锋 创建:从 ioboard.c 拆出。位序是**静默错误**(错了不报错,只是
* 数据差一位),只能靠主机侧单测钉住——台架上「位序错一位」与
* 「线接错一位」完全同形,无法归因。
*/
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
/* ======================== 常量 ======================== */
/* 开入路数:74HC165 一片 8 位(两块级联,V0.1 只接回一块的数据线,见 README 已知限制) */
#define IOBOARD_DI_COUNT 8
/* 开出路数:10 路板级开出(既有 4 路光耦驱动继电器 + 2026-11-18 新增 6 路普通开出) */
#define IOBOARD_DO_COUNT 10
/* 开入 mask 有效位:bit0..bit7 */
#define IOBOARD_DI_MASK_ALL ((uint8_t)((1U << IOBOARD_DI_COUNT) - 1U))
/* 开出 mask 有效位:bit0..bit9;PC15(bit8)为备份域限流引脚,仅作信号位 */
#define IOBOARD_DO_MASK_ALL ((uint16_t)0x03FFU)
/* ======================== 纯函数 ======================== */
/*
* 函数功能:把 74HC165 串行读出的 8 个比特组装成开入 mask(A 通道落在 bit0)
* 入口参数:bits - 长度为 IOBOARD_DI_COUNT 的数组,bits[i] 为**第 i+1 个时钟沿之前**
* 从 QH(PE3)读到的电平;非 0 即视为高电平(传 0/1 亦可)
* 返回值:8 位开入 mask,bit0 = A 通道 … bit7 = H 通道
* 限定条件:纯函数,无寄存器/无全局状态,任意上下文可调(主机侧可测)
* 函数说明:依据 TI SN74HC165 数据手册(SNx4HC165 Rev.H,第 7.3 节 Functional Modes
* 真值表Shift 行:数据向 QH 方向移动,每个 CLK 低到高沿推出当前最靠前的比特):
* 第一个时钟沿**之前** QH 上已经是 H,第 8 个沿之前是 A。
* 即 reads = [H,G,F,E,D,C,B,A],组装时必须把 reads[0] 放到 bit7、reads[7] 放到 bit0,
* 等价于逐位从 LSB 往里塞:bit(7-i) = reads[i]。
* 算例(README 同款):只有 A 与 H 为 1 → reads=[1,0,0,0,0,0,0,1] → 0x81。
*/
uint8_t ioboard_di_assemble(const uint8_t bits[IOBOARD_DI_COUNT]);
#ifdef __cplusplus
}
#endif
#endif /* IOBOARD_BITS_H */