kernel support kconfig

This commit is contained in:
zhangzheng
2023-12-05 00:01:26 +08:00
parent feda3c7aaa
commit 7522bf9c1f
29 changed files with 138 additions and 563 deletions

View File

@@ -7,19 +7,19 @@
#include <fd_map.h>
#include <string.h>
#define FD_MAP_ROW_CN 16
#define FD_MAP_ROW_NR 16
#define CONFIG_FD_MAP_ROW_CN 16
#define CONFIG_FD_MAP_ROW_NR 16
#define FD_MAP_TOTAL (FD_MAP_ROW_CN * FD_MAP_ROW_NR)
#define FD_MAP_TOTAL (CONFIG_FD_MAP_ROW_CN * CONFIG_FD_MAP_ROW_NR)
typedef struct fd_map_row
{
fd_map_entry_t entry[FD_MAP_ROW_CN];
fd_map_entry_t entry[CONFIG_FD_MAP_ROW_CN];
} fd_map_row_t;
typedef struct fd_map
{
fd_map_row_t *row[FD_MAP_ROW_NR];
fd_map_row_t *row[CONFIG_FD_MAP_ROW_NR];
pthread_spinlock_t lock;
uint16_t free_fd;
} fd_map_t;
@@ -35,13 +35,13 @@ again_alloc:
if (fd_map.free_fd >= FD_MAP_TOTAL)
{
// 没有可用的fd了尝试循环查找
for (int i = 0; i < FD_MAP_ROW_NR; i++)
for (int i = 0; i < CONFIG_FD_MAP_ROW_NR; i++)
{
for (int j = 0; j < FD_MAP_ROW_CN; j++)
for (int j = 0; j < CONFIG_FD_MAP_ROW_CN; j++)
{
if (fd_map.row[i]->entry[j].flags == 0)
{
alloc_fd = i * FD_MAP_ROW_CN + j;
alloc_fd = i * CONFIG_FD_MAP_ROW_CN + j;
goto next;
}
}
@@ -55,10 +55,10 @@ again_alloc:
alloc_fd = fd_map.free_fd;
}
next:;
int row_inx = alloc_fd / FD_MAP_ROW_CN;
int inx = alloc_fd % FD_MAP_ROW_CN;
int row_inx = alloc_fd / CONFIG_FD_MAP_ROW_CN;
int inx = alloc_fd % CONFIG_FD_MAP_ROW_CN;
assert(row_inx < FD_MAP_ROW_NR);
assert(row_inx < CONFIG_FD_MAP_ROW_NR);
if (fd_map.row[row_inx] == NULL)
{
fd_map.row[row_inx] = malloc(sizeof(fd_map_row_t));
@@ -86,8 +86,8 @@ int fd_map_get(int fd, fd_map_entry_t *new_entry)
{
return -1;
}
int row_inx = fd / FD_MAP_ROW_CN;
int inx = fd % FD_MAP_ROW_CN;
int row_inx = fd / CONFIG_FD_MAP_ROW_CN;
int inx = fd % CONFIG_FD_MAP_ROW_CN;
*new_entry = fd_map.row[row_inx]->entry[inx];
return 0;
@@ -98,8 +98,8 @@ int fd_map_update(int fd, fd_map_entry_t *new_entry)
{
return -1;
}
int row_inx = fd / FD_MAP_ROW_CN;
int inx = fd % FD_MAP_ROW_CN;
int row_inx = fd / CONFIG_FD_MAP_ROW_CN;
int inx = fd % CONFIG_FD_MAP_ROW_CN;
pthread_spin_lock(&fd_map.lock);
int flags = fd_map.row[row_inx]->entry[inx].flags;
@@ -115,8 +115,8 @@ int fd_map_free(int fd, fd_map_entry_t *ret_entry)
{
return -1;
}
int row_inx = fd / FD_MAP_ROW_CN;
int inx = fd % FD_MAP_ROW_CN;
int row_inx = fd / CONFIG_FD_MAP_ROW_CN;
int inx = fd % CONFIG_FD_MAP_ROW_CN;
pthread_spin_lock(&fd_map.lock);
if (fd_map.row[row_inx]->entry[inx].flags == 1)

View File

@@ -1,6 +1,6 @@
#pragma once
#include "u_types.h"
#define SYS_SCHE_HZ 1000 //!< 系统调度频率
// #define CONFIG_SYS_SCHE_HZ 1000 //!< 系统调度频率
#define MK_PAGE_SIZE 512
#define WORD_BYTES (sizeof(void *))

View File

@@ -12,5 +12,5 @@ static obj_handler_t hd = HANDLER_INVALID;
void u_sleep_ms(size_t ms)
{
thread_ipc_wait(ipc_timeout_create2(0, ms / (1000 / SYS_SCHE_HZ)), NULL);
thread_ipc_wait(ipc_timeout_create2(0, ms / (1000 / CONFIG_SYS_SCHE_HZ)), NULL);
}

View File

@@ -40,8 +40,6 @@ if(NOT DEFINED RT_USING_SPI_BITOPS)
list(REMOVE_ITEM deps ${CMAKE_CURRENT_LIST_DIR}/drv_soft_spi.c)
endif()
message("========"${deps})
add_library(
hal_drviers
STATIC

View File

@@ -49,7 +49,7 @@ void console_init(void)
cons_svr_obj_init(&cons_obj);
meta_reg_svr_obj(&cons_obj.svr, CONS_PROT);
u_thread_create(&cons_th, cons_stack, sizeof(cons_stack), NULL, console_read_func);
u_thread_run(cons_th, 2);
u_thread_run(cons_th, 3);
printf("cons svr init...\n");
}
/**