[kernel]: 不测试 中断驱动串口了
This commit is contained in:
@@ -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
|
|
||||||
13
magnitude/kernel/include/klibc/kerrno.h
Normal file
13
magnitude/kernel/include/klibc/kerrno.h
Normal 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
|
||||||
@@ -13,7 +13,7 @@ void __assert_fail(const char *file, int line, const char *expr)
|
|||||||
while (1) ;
|
while (1) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MAGNITUDE_ASSERT(cond) \
|
#define MAG_ASSERT(cond) \
|
||||||
do { \
|
do { \
|
||||||
if (!(cond)) \
|
if (!(cond)) \
|
||||||
__assert_fail(__FILE__, __LINE__, #cond); \
|
__assert_fail(__FILE__, __LINE__, #cond); \
|
||||||
@@ -5,13 +5,13 @@
|
|||||||
#ifndef PRINT_H
|
#ifndef PRINT_H
|
||||||
#define PRINT_H
|
#define PRINT_H
|
||||||
|
|
||||||
#include <magnitude_types.h>
|
#include <magtypes.h>
|
||||||
|
|
||||||
void magnitude_serial_up ( void );
|
void magnitude_serial_up ( void );
|
||||||
|
|
||||||
ssize_t magnitude_putc ( char c );
|
ssize_t magnitude_putc ( char c );
|
||||||
|
|
||||||
ssize_t magnitude_puts ( char* string );
|
char magnitude_get ( void );
|
||||||
|
|
||||||
|
|
||||||
#endif //PRINT_H
|
#endif //PRINT_H
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
#ifndef RING_BUFFER_H
|
#ifndef RING_BUFFER_H
|
||||||
#define RING_BUFFER_H
|
#define RING_BUFFER_H
|
||||||
|
|
||||||
#include <magnitude_types.h>
|
#include <magtypes.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
head 和 tail 这个命名确实容易让新手误解。它们源自“队列”的传统叫法:
|
head 和 tail 这个命名确实容易让新手误解。它们源自“队列”的传统叫法:
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
#ifndef MAGNITUDE_IRQ_H
|
#ifndef MAGNITUDE_IRQ_H
|
||||||
#define MAGNITUDE_IRQ_H
|
#define MAGNITUDE_IRQ_H
|
||||||
|
|
||||||
#include <magnitude_types.h>
|
#include <magtypes.h>
|
||||||
|
|
||||||
typedef void (*irq_handler_t)(void *arg);
|
typedef void (*irq_handler_t)(void *arg);
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
#ifndef PMM_H
|
#ifndef PMM_H
|
||||||
#define PMM_H
|
#define PMM_H
|
||||||
|
|
||||||
#include <magnitude_types.h>
|
#include <magtypes.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
#ifndef STACK_H
|
#ifndef STACK_H
|
||||||
#define STACK_H
|
#define STACK_H
|
||||||
|
|
||||||
#include <magnitude_types.h>
|
#include <magtypes.h>
|
||||||
|
|
||||||
extern uint64_t mag_stack_top;
|
extern uint64_t mag_stack_top;
|
||||||
extern uint64_t mag_stack_bottom;
|
extern uint64_t mag_stack_bottom;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
#ifndef VMM_H
|
#ifndef VMM_H
|
||||||
#define VMM_H
|
#define VMM_H
|
||||||
|
|
||||||
#include <magnitude_types.h>
|
#include <magtypes.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -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
|
|
||||||
@@ -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
|
|
||||||
11
magnitude/kernel/include/magreg.h
Normal file
11
magnitude/kernel/include/magreg.h
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
//
|
||||||
|
// Created by dongl on 25-9-5.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef MAGREG_H
|
||||||
|
#define MAGREG_H
|
||||||
|
|
||||||
|
#include <magtypes.h>
|
||||||
|
|
||||||
|
|
||||||
|
#endif //MAGREG_H
|
||||||
@@ -22,11 +22,22 @@ typedef unsigned char uint8_t;
|
|||||||
typedef signed char int8_t;
|
typedef signed char int8_t;
|
||||||
|
|
||||||
|
|
||||||
typedef uint64_t reg_t;
|
typedef unsigned long off_t;
|
||||||
typedef uint64_t pte_t;
|
|
||||||
typedef uint64_t vma_t;
|
|
||||||
typedef uint64_t va_t;
|
typedef uint64_t reg_t;
|
||||||
typedef uint64_t pa_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)
|
#define NULL ((void*)0)
|
||||||
|
|
||||||
@@ -6,65 +6,25 @@
|
|||||||
|
|
||||||
#include <magnitude/io/io.h>
|
#include <magnitude/io/io.h>
|
||||||
#include <magnitude/io/ringbuf.h>
|
#include <magnitude/io/ringbuf.h>
|
||||||
#include <magnitude/irq/irq.h>
|
|
||||||
|
|
||||||
#include <serial/bspuart.h>
|
#include <serial/bspuart.h>
|
||||||
#include <irq/bspgic.h>
|
#include <bspconsole.h>
|
||||||
|
|
||||||
#include <bsp.h>
|
//
|
||||||
|
static bsp_console_ptr console = &bsp_console[0];
|
||||||
|
|
||||||
// 环形缓冲区控制块
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
void magnitude_serial_up ( void ) {
|
void magnitude_serial_up ( void ) {
|
||||||
// 初始化环形缓冲区
|
|
||||||
magnitude_ring_buffer_create(
|
|
||||||
&mag_print_tx,
|
|
||||||
mag_uart_tx,
|
|
||||||
MAGNITUDE_PRINT_BUFFER_SIZE);
|
|
||||||
// 使能串口
|
// 使能串口
|
||||||
bsp_uart_up();
|
bsp_mini_uart_up();
|
||||||
// 安装 UART IRQ handler
|
console->ops.bsp_console_cfg(console);
|
||||||
magnitude_irq_install_handler(IRQ_UART, uart_isr_handler, &mag_print_tx);
|
|
||||||
// 启用中断号
|
|
||||||
bsp_gic_enable_irq(IRQ_UART);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t magnitude_putc ( char c ) {
|
ssize_t magnitude_putc ( char c ) {
|
||||||
if ( !magnitude_ring_buffer_put(&mag_print_tx, c) )
|
return console->ops.bsp_console_putc(console, c);
|
||||||
return 0; // 缓冲区满
|
}
|
||||||
|
|
||||||
// 如果 FIFO 空,则手动写一个字符,触发中断循环
|
char magnitude_get ( void ) {
|
||||||
if ( bsp_uart_tx_fifo_has_space() ) { // TXFF = 0 表示有空位
|
return console->ops.bsp_console_getc(console);
|
||||||
char ch;
|
|
||||||
if (magnitude_ring_buffer_get(&mag_print_tx, &ch) == 0) {
|
|
||||||
bsp_uart_putc(ch);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 写入环形缓冲区
|
|
||||||
return magnitude_ring_buffer_put(&mag_print_tx, c);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -19,11 +19,6 @@ void magnitude_irq_up ( void ) {
|
|||||||
irq_table[i].handler = NULL;
|
irq_table[i].handler = NULL;
|
||||||
irq_table[i].arg = 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 ) {
|
void magnitude_irq_install_handler( uint32_t irq, irq_handler_t handler, void* arg ) {
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ bsp = get_option('bsp')
|
|||||||
# 创建包含多个目录的对象
|
# 创建包含多个目录的对象
|
||||||
libkernel_inc = include_directories(
|
libkernel_inc = include_directories(
|
||||||
'include', # 通用头文件路径
|
'include', # 通用头文件路径
|
||||||
'../', # libk 未构建完成时的临时路径
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# C 源文件变量声明
|
# C 源文件变量声明
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
* SPDX-License-Identifier: BSD-3-Clause
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <magnitude_types.h>
|
#include <magtypes.h>
|
||||||
|
|
||||||
// #include <string.h>
|
// #include <string.h>
|
||||||
// #include <limits.h>
|
// #include <limits.h>
|
||||||
|
|||||||
@@ -7,8 +7,8 @@
|
|||||||
#ifndef INCLUDED_tlsf
|
#ifndef INCLUDED_tlsf
|
||||||
#define INCLUDED_tlsf
|
#define INCLUDED_tlsf
|
||||||
|
|
||||||
#include <magnitude_assert.h>
|
#include <magassert.h>
|
||||||
#include <magnitude_types.h>
|
#include <magtypes.h>
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|||||||
@@ -11,6 +11,10 @@
|
|||||||
|
|
||||||
#include <magnitude/io/io.h>
|
#include <magnitude/io/io.h>
|
||||||
|
|
||||||
|
#include <magnitude/irq/irq.h>
|
||||||
|
#include <magnitude/irq/isr.h>
|
||||||
|
|
||||||
|
|
||||||
__attribute__((section(".text.boot")))
|
__attribute__((section(".text.boot")))
|
||||||
void magnitude_start(void) {
|
void magnitude_start(void) {
|
||||||
// 注册页表分配基本算法实现
|
// 注册页表分配基本算法实现
|
||||||
@@ -22,12 +26,15 @@ void magnitude_start(void) {
|
|||||||
|
|
||||||
magnitude_serial_up();
|
magnitude_serial_up();
|
||||||
|
|
||||||
|
magnitude_isr_enable(); // 打开 IRQ 中断
|
||||||
magnitude_putc('M');
|
magnitude_putc('M');
|
||||||
magnitude_putc('a');
|
magnitude_putc('a');
|
||||||
magnitude_putc('g');
|
magnitude_putc('g');
|
||||||
magnitude_putc('\n');
|
magnitude_putc('\n');
|
||||||
|
magnitude_isr_disable(); // 打开 IRQ 中断
|
||||||
|
|
||||||
__asm__ __volatile__("wfi");
|
while (true)
|
||||||
|
__asm__ __volatile__("wfi");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ magnitude = executable(
|
|||||||
'magnitude',
|
'magnitude',
|
||||||
magnitude,
|
magnitude,
|
||||||
include_directories: inc,
|
include_directories: inc,
|
||||||
|
link_whole: [libarch, libbsp, libkernel],
|
||||||
dependencies : [
|
dependencies : [
|
||||||
dependency('libarch'), # 自动找到 arch/ 导出的 libarch_dep
|
dependency('libarch'), # 自动找到 arch/ 导出的 libarch_dep
|
||||||
dependency('libbsp'), # 自动找到 bsp/ 导出的 libbsp_dep
|
dependency('libbsp'), # 自动找到 bsp/ 导出的 libbsp_dep
|
||||||
|
|||||||
Reference in New Issue
Block a user