b49c9ab0c6
完整实现了以下模块: - 系统数据总线(sys_data_bus)模块间通信 - UART/USART/LPUART驱动 + RS485半双工 - I2C驱动(AS5600角度传感器 + AT24C02 EEPROM) - Modbus RTU从站协议 - 步进电机微步进控制(正弦/余弦换相+S曲线加减速) - 到位开关驱动(DI_MIN/DI_MAX) - PGA+ADC电流检测 - 系统监控任务(内存/串口/传感器/任务状态) - LED/Key外设驱动 - 基于CMake + arm-none-eabi-gcc构建系统
55 lines
983 B
C
55 lines
983 B
C
#include "sys_data_bus.h"
|
|
|
|
static sys_data_bus_value_t data_pool[SYS_DATA_BUS_ID_MAX];
|
|
static uint32_t flag_bits;
|
|
|
|
ret_code_t sys_data_bus_init(void)
|
|
{
|
|
uint32_t i;
|
|
|
|
for (i = 0; i < SYS_DATA_BUS_ID_MAX; i++) {
|
|
data_pool[i].u = 0;
|
|
}
|
|
|
|
flag_bits = 0;
|
|
|
|
return RET_OK;
|
|
}
|
|
|
|
void sys_data_bus_write(sys_data_bus_id_t id, sys_data_bus_value_t value)
|
|
{
|
|
if (id >= SYS_DATA_BUS_ID_MAX) {
|
|
return;
|
|
}
|
|
|
|
data_pool[id] = value;
|
|
}
|
|
|
|
sys_data_bus_value_t sys_data_bus_read(sys_data_bus_id_t id)
|
|
{
|
|
if (id >= SYS_DATA_BUS_ID_MAX) {
|
|
sys_data_bus_value_t zero = {.u = 0};
|
|
return zero;
|
|
}
|
|
|
|
return data_pool[id];
|
|
}
|
|
|
|
void sys_data_bus_set_flag(uint8_t bit)
|
|
{
|
|
if (bit >= 32) return;
|
|
flag_bits |= (1UL << bit);
|
|
}
|
|
|
|
void sys_data_bus_clear_flag(uint8_t bit)
|
|
{
|
|
if (bit >= 32) return;
|
|
flag_bits &= ~(1UL << bit);
|
|
}
|
|
|
|
uint8_t sys_data_bus_get_flag(uint8_t bit)
|
|
{
|
|
if (bit >= 32) return 0;
|
|
return (flag_bits >> bit) & 1;
|
|
}
|