2023-09-29 01:03:19 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @file globals.c
|
2023-12-02 10:16:14 +08:00
|
|
|
|
* @author ATShining (1358745329@qq.com)
|
2023-12-05 21:16:00 +08:00
|
|
|
|
* @brief
|
2023-09-29 01:03:19 +08:00
|
|
|
|
* @version 0.1
|
|
|
|
|
|
* @date 2023-09-29
|
2023-12-05 21:16:00 +08:00
|
|
|
|
*
|
2023-09-29 01:03:19 +08:00
|
|
|
|
* @copyright Copyright (c) 2023
|
2023-12-05 21:16:00 +08:00
|
|
|
|
*
|
2023-08-20 20:52:23 +08:00
|
|
|
|
*/
|
|
|
|
|
|
#include "globals.h"
|
|
|
|
|
|
#include "types.h"
|
|
|
|
|
|
#include "init.h"
|
|
|
|
|
|
#include "mm.h"
|
|
|
|
|
|
#include "kobject.h"
|
|
|
|
|
|
#include "prot.h"
|
|
|
|
|
|
#include "assert.h"
|
2023-08-27 16:52:53 +08:00
|
|
|
|
#include "mm_man.h"
|
2023-08-29 16:16:25 +08:00
|
|
|
|
#include "ipc.h"
|
2023-08-20 20:52:23 +08:00
|
|
|
|
static mem_t global_mem; //!< 全局内存管理块
|
2023-12-08 23:55:00 +08:00
|
|
|
|
static uint8_t mem_block[31*1024 * 1024]; //!< 内核内存分配堆 TODO:自动识别大小,或者从bootstrap中读取
|
2023-08-20 20:52:23 +08:00
|
|
|
|
static kobject_t *kobj_ls[FACTORY_FUNC_MAX]; //!< 全局静态内核对象
|
2023-12-05 21:16:00 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @brief 注册一个全局静态的内核对象
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param kobj 注册的内核对象
|
|
|
|
|
|
* @param inx 注册的内核对象号
|
|
|
|
|
|
*/
|
2023-08-20 20:52:23 +08:00
|
|
|
|
void global_reg_kobj(kobject_t *kobj, int inx)
|
|
|
|
|
|
{
|
|
|
|
|
|
assert(inx >= 0);
|
|
|
|
|
|
assert(inx < FACTORY_FUNC_MAX);
|
|
|
|
|
|
kobj_ls[inx - 1] = kobj;
|
|
|
|
|
|
}
|
2023-12-05 21:16:00 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @brief 获取注册的内核对象
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param inx 获取哪一个
|
|
|
|
|
|
* @return kobject_t* ==NULL 失败 !=NULL成功
|
|
|
|
|
|
*/
|
2023-08-22 00:26:34 +08:00
|
|
|
|
kobject_t *global_get_kobj(int inx)
|
|
|
|
|
|
{
|
|
|
|
|
|
assert(inx >= 0);
|
|
|
|
|
|
assert(inx < FACTORY_FUNC_MAX);
|
|
|
|
|
|
return kobj_ls[inx - 1];
|
|
|
|
|
|
}
|
2023-12-05 21:16:00 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @brief 获取内存分配对象
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return mem_t*
|
|
|
|
|
|
*/
|
2023-08-20 20:52:23 +08:00
|
|
|
|
mem_t *mm_get_global(void)
|
|
|
|
|
|
{
|
|
|
|
|
|
return &global_mem;
|
|
|
|
|
|
}
|
2023-12-05 21:16:00 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @brief 系统内存初始化
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
2023-08-22 00:26:34 +08:00
|
|
|
|
static void mem_sys_init(void)
|
2023-08-20 20:52:23 +08:00
|
|
|
|
{
|
|
|
|
|
|
mem_init(&global_mem);
|
|
|
|
|
|
mem_heap_add(mm_get_global(), mem_block, sizeof(mem_block));
|
|
|
|
|
|
}
|
2023-08-22 00:26:34 +08:00
|
|
|
|
INIT_MEM(mem_sys_init);
|