[kernel]: 不测试 中断驱动串口了

This commit is contained in:
2025-09-06 01:16:07 +08:00
parent ddf23cead9
commit 03e4f782d2
22 changed files with 69 additions and 212 deletions

View File

@@ -1,59 +0,0 @@
//
// Created by dongl on 25-8-18.
//
#ifndef MAGNITUDE_TYPES_H
#define MAGNITUDE_TYPES_H
typedef unsigned long size_t;
typedef unsigned long uintptr_t;
typedef unsigned long uint64_t;
typedef signed long ssize_t;
typedef signed long intptr_t;
typedef signed long int64_t;
typedef unsigned int uint32_t;
typedef signed int int32_t;
typedef unsigned short uint16_t;
typedef signed short int16_t;
typedef unsigned char uint8_t;
typedef signed char int8_t;
typedef uint64_t reg_t;
typedef uint64_t pte_t;
typedef uint64_t vma_t;
typedef uint64_t va_t;
typedef uint64_t pa_t;
#define NULL ((void*)0)
#ifndef __cplusplus
#define bool _Bool
#define true 1
#define false 0
#else /* __cplusplus */
/* Supporting _Bool in C++ is a GCC extension. */
#define _Bool bool
#if __cplusplus < 201103L
/* Defining these macros in C++98 is a GCC extension. */
#define bool bool
#define false false
#define true true
#endif
#endif /* __cplusplus */
/* Signal that all the definitions are present. */
#define __bool_true_false_are_defined 1
#endif //MAGNITUDE_TYPES_H

View File

@@ -0,0 +1,13 @@
//
// Created by dongl on 25-9-3.
//
#ifndef KERRNO_H
#define KERRNO_H
#include <magtypes.h>
#define MAG_EOK 0 /**< There is no error */
#define MAG_ERROR 255 /**< A generic/unknown error happens */
#endif //KERRNO_H

View File

@@ -13,7 +13,7 @@ void __assert_fail(const char *file, int line, const char *expr)
while (1) ;
}
#define MAGNITUDE_ASSERT(cond) \
#define MAG_ASSERT(cond) \
do { \
if (!(cond)) \
__assert_fail(__FILE__, __LINE__, #cond); \

View File

@@ -5,13 +5,13 @@
#ifndef PRINT_H
#define PRINT_H
#include <magnitude_types.h>
#include <magtypes.h>
void magnitude_serial_up ( void );
ssize_t magnitude_putc ( char c );
ssize_t magnitude_puts ( char* string );
char magnitude_get ( void );
#endif //PRINT_H

View File

@@ -5,7 +5,7 @@
#ifndef RING_BUFFER_H
#define RING_BUFFER_H
#include <magnitude_types.h>
#include <magtypes.h>
/**
head 和 tail 这个命名确实容易让新手误解。它们源自“队列”的传统叫法:

View File

@@ -10,7 +10,7 @@
#ifndef MAGNITUDE_IRQ_H
#define MAGNITUDE_IRQ_H
#include <magnitude_types.h>
#include <magtypes.h>
typedef void (*irq_handler_t)(void *arg);

View File

@@ -5,7 +5,7 @@
#ifndef PMM_H
#define PMM_H
#include <magnitude_types.h>
#include <magtypes.h>
/**
*

View File

@@ -5,7 +5,7 @@
#ifndef STACK_H
#define STACK_H
#include <magnitude_types.h>
#include <magtypes.h>
extern uint64_t mag_stack_top;
extern uint64_t mag_stack_bottom;

View File

@@ -5,7 +5,7 @@
#ifndef VMM_H
#define VMM_H
#include <magnitude_types.h>
#include <magtypes.h>
/**
*

View File

@@ -1,22 +0,0 @@
//
// Created by dongl on 25-8-21.
//
#ifndef MAGNITUDE_ASSERT_H
#define MAGNITUDE_ASSERT_H
#include <console/bsp-console.h>
void __assert_fail(const char *file, int line, const char *expr)
{
// uart_printf("\nASSERT failed at %s:%d %s\n", file, line, expr);
while (1) ;
}
#define MAGNITUDE_ASSERT(cond) \
do { \
if (!(cond)) \
__assert_fail(__FILE__, __LINE__, #cond); \
} while (0)
#endif //MAGNITUDE_ASSERT_H

View File

@@ -1,59 +0,0 @@
//
// Created by dongl on 25-8-18.
//
#ifndef MAGNITUDE_TYPES_H
#define MAGNITUDE_TYPES_H
typedef unsigned long size_t;
typedef unsigned long uintptr_t;
typedef unsigned long uint64_t;
typedef signed long ssize_t;
typedef signed long intptr_t;
typedef signed long int64_t;
typedef unsigned int uint32_t;
typedef signed int int32_t;
typedef unsigned short uint16_t;
typedef signed short int16_t;
typedef unsigned char uint8_t;
typedef signed char int8_t;
typedef uint64_t reg_t;
typedef uint64_t pte_t;
typedef uint64_t vma_t;
typedef uint64_t va_t;
typedef uint64_t pa_t;
#define NULL ((void*)0)
#ifndef __cplusplus
#define bool _Bool
#define true 1
#define false 0
#else /* __cplusplus */
/* Supporting _Bool in C++ is a GCC extension. */
#define _Bool bool
#if __cplusplus < 201103L
/* Defining these macros in C++98 is a GCC extension. */
#define bool bool
#define false false
#define true true
#endif
#endif /* __cplusplus */
/* Signal that all the definitions are present. */
#define __bool_true_false_are_defined 1
#endif //MAGNITUDE_TYPES_H

View File

@@ -0,0 +1,11 @@
//
// Created by dongl on 25-9-5.
//
#ifndef MAGREG_H
#define MAGREG_H
#include <magtypes.h>
#endif //MAGREG_H

View File

@@ -22,12 +22,23 @@ typedef unsigned char uint8_t;
typedef signed char int8_t;
typedef unsigned long off_t;
typedef uint64_t reg_t;
typedef uint64_t pte_t;
typedef uint64_t vma_t;
typedef uint64_t va_t;
typedef uint64_t pa_t;
typedef uint64_t mag_base_t;
typedef mag_base_t mag_err_t;
#define NULL ((void*)0)

View File

@@ -6,65 +6,25 @@
#include <magnitude/io/io.h>
#include <magnitude/io/ringbuf.h>
#include <magnitude/irq/irq.h>
#include <serial/bspuart.h>
#include <irq/bspgic.h>
#include <bspconsole.h>
#include <bsp.h>
// 环形缓冲区控制块
static magnitude_ring_buffer_t mag_print_tx; // 待发送数据
//static magnitude_ring_buffer_t mag_print_rx; // 待接收数据
// 环形缓冲区空间
static char mag_uart_tx[MAGNITUDE_PRINT_BUFFER_SIZE];
// static char mag_uart_rx[MAGNITUDE_PRINT_BUFFER_SIZE];
static void uart_isr_handler ( void *arg ) {
magnitude_ring_buffer_t *tx_rb = (magnitude_ring_buffer_t *) arg;
char c;
// 检查是否有数据待发送
if ( magnitude_ring_buffer_get(tx_rb, &c) ) {
// 将一个字符写入 UART 数据寄存器
bsp_uart_putc(c);
}
// 清除 UART 中断标志,为下一次中断做准备
bsp_uart_clear_interrupt();
}
//
static bsp_console_ptr console = &bsp_console[0];
void magnitude_serial_up ( void ) {
// 初始化环形缓冲区
magnitude_ring_buffer_create(
&mag_print_tx,
mag_uart_tx,
MAGNITUDE_PRINT_BUFFER_SIZE);
// 使能串口
bsp_uart_up();
// 安装 UART IRQ handler
magnitude_irq_install_handler(IRQ_UART, uart_isr_handler, &mag_print_tx);
// 启用中断号
bsp_gic_enable_irq(IRQ_UART);
bsp_mini_uart_up();
console->ops.bsp_console_cfg(console);
}
ssize_t magnitude_putc ( char c ) {
if ( !magnitude_ring_buffer_put(&mag_print_tx, c) )
return 0; // 缓冲区满
// 如果 FIFO 空,则手动写一个字符,触发中断循环
if ( bsp_uart_tx_fifo_has_space() ) { // TXFF = 0 表示有空位
char ch;
if (magnitude_ring_buffer_get(&mag_print_tx, &ch) == 0) {
bsp_uart_putc(ch);
}
return console->ops.bsp_console_putc(console, c);
}
// 写入环形缓冲区
return magnitude_ring_buffer_put(&mag_print_tx, c);
char magnitude_get ( void ) {
return console->ops.bsp_console_getc(console);
}

View File

@@ -19,11 +19,6 @@ void magnitude_irq_up ( void ) {
irq_table[i].handler = NULL;
irq_table[i].arg = NULL;
}
// 初始化 GIC 硬件
bsp_gic_up();
// 打开 IRQ 中断
magnitude_isr_enable();
}
void magnitude_irq_install_handler( uint32_t irq, irq_handler_t handler, void* arg ) {

View File

@@ -8,7 +8,6 @@ bsp = get_option('bsp')
# 创建包含多个目录的对象
libkernel_inc = include_directories(
'include', # 通用头文件路径
'../', # libk 未构建完成时的临时路径
)
# C 源文件变量声明

View File

@@ -4,7 +4,7 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <magnitude_types.h>
#include <magtypes.h>
// #include <string.h>
// #include <limits.h>

View File

@@ -7,8 +7,8 @@
#ifndef INCLUDED_tlsf
#define INCLUDED_tlsf
#include <magnitude_assert.h>
#include <magnitude_types.h>
#include <magassert.h>
#include <magtypes.h>
#if defined(__cplusplus)
extern "C" {

View File

@@ -11,6 +11,10 @@
#include <magnitude/io/io.h>
#include <magnitude/irq/irq.h>
#include <magnitude/irq/isr.h>
__attribute__((section(".text.boot")))
void magnitude_start(void) {
// 注册页表分配基本算法实现
@@ -22,11 +26,14 @@ void magnitude_start(void) {
magnitude_serial_up();
magnitude_isr_enable(); // 打开 IRQ 中断
magnitude_putc('M');
magnitude_putc('a');
magnitude_putc('g');
magnitude_putc('\n');
magnitude_isr_disable(); // 打开 IRQ 中断
while (true)
__asm__ __volatile__("wfi");
}

View File

@@ -13,6 +13,7 @@ magnitude = executable(
'magnitude',
magnitude,
include_directories: inc,
link_whole: [libarch, libbsp, libkernel],
dependencies : [
dependency('libarch'), # 自动找到 arch/ 导出的 libarch_dep
dependency('libbsp'), # 自动找到 bsp/ 导出的 libbsp_dep