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构建系统
45 lines
758 B
C
45 lines
758 B
C
#include "system_driver.h"
|
|
#include "py32md530.h"
|
|
#include "system_py32md530.h"
|
|
#include "config.h"
|
|
|
|
static volatile uint32_t sys_tick_count = 0;
|
|
|
|
void SysTick_Handler(void)
|
|
{
|
|
sys_tick_count++;
|
|
}
|
|
|
|
ret_code_t system_driver_init(void)
|
|
{
|
|
SystemCoreClockUpdate();
|
|
|
|
SysTick_Config(SYSTICK_RELOAD_VAL);
|
|
|
|
NVIC_SetPriority(SysTick_IRQn, 0x0F);
|
|
|
|
return RET_OK;
|
|
}
|
|
|
|
void system_delay_ms(uint32_t ms)
|
|
{
|
|
uint32_t start = sys_tick_count;
|
|
while ((sys_tick_count - start) < ms);
|
|
}
|
|
|
|
void system_delay_us(uint32_t us)
|
|
{
|
|
uint32_t count = 0;
|
|
uint32_t fcpu = SystemCoreClock;
|
|
uint32_t cycles = (fcpu / 1000000) * us / 3;
|
|
|
|
while (count < cycles) {
|
|
count++;
|
|
}
|
|
}
|
|
|
|
uint32_t system_get_tick(void)
|
|
{
|
|
return sys_tick_count;
|
|
}
|