Files
player/Project_App_Calendar/App_Src/main/global.c
2025-10-15 19:34:08 +08:00

96 lines
1.2 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.

#include "global.h"
#include "main_inc.h"
//获取和保存r9寄存器
void *get_r9(void);
void set_r9(void *r9);
//用来保存全局变量基地址
static void * const g_r9;
//指向app自身
static app_struct *g_me;
//给const类型变量赋值
static void save_const(void *const_addr, u32 value)
{
__asm__ volatile (
"str %1, [%0]"
:
: "r" (const_addr), "r" (value)
: "memory"
);
}
void *get_r9(void)
{
void *result;
__asm__ volatile (
"mov %0, r9"
: "=r" (result)
:
:
);
return result;
}
void set_r9(void *r9_val)
{
__asm__ volatile (
"mov r9, %0"
:
: "r" (r9_val)
: "r9"
);
}
void *global_in(void)
{
void *t=get_r9();
set_r9(g_r9);
return t;
}
void global_out(void *r9)
{
set_r9(r9);
}
void global_init(app_struct *me)
{
void *t=get_r9();
//使用函数强行赋值
save_const((void *)&g_r9,(u32)t);
g_me=me;
//这个函数提供给系统调用用以退出app
extern int __app_exit(void *);
g_me->exit=__app_exit;
}
//app正在运行
void global_run_start(void)
{
if(g_me) g_me->run_state++;
}
//app结束运行
void global_run_exit(void)
{
if(g_me)
{
if(g_me->run_state) g_me->run_state--;
}
}