Files
sambu 578a770737 chore(M0): 建立 CLion/CMake 工程骨架与测试框架
- CMake 多目标工程:shs_core 静态库 + smart_home 可执行 + shs_tests 测试
- CMakePresets.json:debug/release/asan/coverage 四个预设(debug 告警即错误)
- 自研零依赖测试框架 tests/framework/test_framework.h + 运行器(套件过滤、CTest 集成)
- 工具:tools/header_check.sh 头文件独立编译检查(接口冻结门)
- 已实现公共层:errors / string_utils / num_utils,main 启动自检
- 实测:debug 预设 0 告警、ctest 3/3 通过(45 项断言)
2026-09-14 19:34:18 +08:00

33 lines
1.3 KiB
C
Raw Permalink 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.
/**
* @file bitops.h
* @brief 位运算工具集
*
* 教材对应:项目九 任务一「位运算——设备状态监控与位标志操作」。
* 全部函数围绕"一位代表一种状态"的工程惯例设计(嵌入式开发中的标准做法)。
*/
#ifndef SHS_BITOPS_H
#define SHS_BITOPS_H
#include "shs/common.h"
/** 置位:把 flags 的第 bit 位设为 1 */
uint16_t shs_bit_set(uint16_t flags, uint8_t bit);
/** 清位:把 flags 的第 bit 位设为 0 */
uint16_t shs_bit_clear(uint16_t flags, uint8_t bit);
/** 翻转:把 flags 的第 bit 位取反 */
uint16_t shs_bit_toggle(uint16_t flags, uint8_t bit);
/** 测试:flags 的第 bit 位是否为 1 */
bool shs_bit_test(uint16_t flags, uint8_t bit);
/** 按掩码批量置位 / 清位(mask 中为 1 的位才受影响) */
uint16_t shs_bits_set_mask(uint16_t flags, uint16_t mask);
uint16_t shs_bits_clear_mask(uint16_t flags, uint16_t mask);
/** 统计二进制中 1 的个数(Brian Kernighan 算法:n & (n-1)) */
int shs_bit_count(uint16_t flags);
/** 循环左移(项目九 位运算综合练习) */
uint16_t shs_bit_rotate_left(uint16_t value, uint8_t n);
/** 取低 8 位 / 高 8 位(字节拆分,与协议共用体配合) */
uint8_t shs_low_byte(uint16_t value);
uint8_t shs_high_byte(uint16_t value);
#endif /* SHS_BITOPS_H */