system/sys.h

68 lines
2.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.

/***
* @Author:
* @Date: 2023-04-11 18:46:58
* @LastEditors: xxx
* @LastEditTime: 2023-04-11 22:16:47
* @Description:
* @email:
* @Copyright (c) 2023 by xxx, All Rights Reserved.
*/
#ifndef _SYS_H
#define _SYS_H
#include "main.h"
#include "lib.h"
#define CLOCK_CHANGE_ENABLE FALSE ///< 时钟切换使能
#define LOCK() __disable_irq() ///< 系统关全局中断
#define UNLOCK() __enable_irq() ///< 系统开全局中断
typedef struct
{
uint32_t pll_source;
uint32_t pll_m;
uint32_t pll_n;
uint32_t pll_r;
uint32_t ahb_div;
uint32_t apb1_div;
uint32_t apb2_div;
uint32_t sysclk;
// private:
uint32_t sysclk_change; // 改变后的系统时钟 这个参数由change_system_clock函数设置作为内部观察使用
} clock_config_t; /* 时钟配置结构体 */
typedef struct
{
uint32_t ticks_max; // 最大ticks
uint32_t ticks_current; // 当前使用的ticks
uint32_t uticks; // 使用的ticks,用于计算
} utime_ticks_t;
void sys_nvic_set_vector_table(uint32_t baseaddr, uint32_t offset); /* 设置中断偏移量 */
void sys_standby(void); /* 进入待机模式 */
void sys_soft_reset(void); /* 系统软复位 */
void LL_IncTick(void); /* 系统滴答时钟 */
void sys_millis_reset(void); /* 系统计时器重新开始 */
uint32_t sys_get_tick(void); /* 获取系统滴答时钟 */
uint32_t sys_millis(void); /* 获取系统时间 */
uint32_t sys_to_seconds(uint32_t start_time); /* 将系统时间转换为秒 */
// 以下为汇编函数
void sys_wfi_set(void); /* 执行WFI指令 */
void sys_intx_disable(void); /* 关闭所有中断 */
void sys_intx_enable(void); /* 开启所有中断 */
void sys_msr_msp(uint32_t addr); /* 设置栈顶地址 */
void scheduler_time_start(void);
uint32_t scheduler_time_stop(void);
uint32_t scheduler_time_occupancy_get(uint32_t run_time);
void system_clock_read(void);
void restore_system_clock(void);
clock_config_t *get_original_clock_config(void);
void change_system_clock(clock_config_t *new_config);
#endif