优化串口

This commit is contained in:
zhangzheng
2025-03-10 00:01:28 +08:00
parent 79d4d1cad3
commit aa35027fa7
13 changed files with 37 additions and 30 deletions

View File

@@ -1,6 +1,6 @@
message("========use armv7_8.cmake")
set(CMAKE_C_FLAGS "-mcpu=${CONFIG_ARCH} -O0 -g3 -mfloat-abi=${CONFIG_FLOAT_TYPE} -mthumb -DMKRTOS \
set(CMAKE_C_FLAGS "-mcpu=${CONFIG_ARCH} -Ofast -g3 -mfloat-abi=${CONFIG_FLOAT_TYPE} -mthumb -DMKRTOS \
-std=gnu11 -ffunction-sections -fdata-sections -fno-builtin -u=_printf_float \
-nostartfiles -nodefaultlibs -nostdlib -nostdinc \
-fno-stack-protector -Wl,--gc-section -D__ARM_ARCH_7M__ \

View File

@@ -6,9 +6,9 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} \
-Wno-unused-function \
-Wno-unused-variable \
-Wno-builtin-declaration-mismatch \
-Ofast \
")
# -Ofast \
# message(编译参数:${CMAKE_C_FLAGS})
# cortex-m 系列处理器采用相同的内核arch

View File

@@ -35,11 +35,15 @@ void uart_tigger(irq_entry_t *irq)
{
/* read one byte from the receive data register */
q_enqueue(&queue, usart_data_receive(PRINT_USARTx));
usart_interrupt_enable(PRINT_USARTx, USART_IDLE_INT, TRUE);
}
if (usart_interrupt_flag_get(PRINT_USARTx, USART_IDLEF_FLAG) != RESET)
{
if (irq->irq->wait_thread && thread_get_status(irq->irq->wait_thread) == THREAD_SUSPEND)
{
thread_ready_remote(irq->irq->wait_thread, TRUE);
}
usart_interrupt_enable(PRINT_USARTx, USART_IDLE_INT, FALSE);
}
}
@@ -72,6 +76,8 @@ void uart_init(void)
usart_receiver_enable(PRINT_USARTx, TRUE);
usart_interrupt_enable(PRINT_USARTx, USART_RDBF_INT, TRUE);
usart_interrupt_enable(PRINT_USARTx, USART_IDLE_INT, TRUE);
usart_enable(PRINT_USARTx, TRUE);
uart_is_init=1;

View File

@@ -6,7 +6,7 @@ typedef struct thread_wait_entry
slist_head_t node;
thread_t *th;
umword_t times;
umword_t times_debug;
// umword_t times_debug;
} thread_wait_entry_t;
void thread_check_timeout(void);
thread_wait_entry_t *thread_sleep_del(thread_t *th);

View File

@@ -25,7 +25,7 @@ static inline void thread_wait_entry_init(thread_wait_entry_t *entry,
slist_init(&entry->node);
entry->th = th;
entry->times = times;
entry->times_debug = 0;
// entry->times_debug = 0;
}
static void thread_timeout_init(void)
{
@@ -48,22 +48,27 @@ void thread_check_timeout(void)
thread_wait_entry_t *next = slist_next_entry(
pos, (slist_head_t *)wait_list,
node);
pos->times_debug++;
// pos->times_debug++;
if (pos->times != 0)
{
pos->times--;
// pos->times_debug = 0;
if (pos->times == 0)
{
assert(pos->th->status == THREAD_SUSPEND);
slist_del(&pos->node);
thread_ready(pos->th, TRUE);
}
} else {
// if (pos->times_debug >= 3000)
// {
// printk("thread:0x%x block times %d.\n", pos->th, pos->times_debug);
// }
} // !< 如果是0则一直休眠
if (pos->times_debug%2000 == 0)
{
// printk("thread 0x%x block %d sec.\n", pos->th, pos->times_debug /1000);
}
// if (pos->times_debug%2000 == 0)
// {
// // printk("thread 0x%x block %d sec.\n", pos->th, pos->times_debug /1000);
// }
pos = next;
}
}

View File

@@ -1,15 +1,15 @@
#!/bin/bash
export TOOLCHAIN=/home/zhangzheng/toolchain/gcc-arm-10.3-2021.07-x86_64-arm-none-eabi/bin/
export TOOLCHAIN_LIB=/home/zhangzheng/toolchain/gcc-arm-10.3-2021.07-x86_64-arm-none-eabi/lib/gcc/arm-none-eabi/10.3.1/thumb/v7-m/nofp
# export TOOLCHAIN=/home/zhangzheng/toolchain/gcc-arm-10.3-2021.07-x86_64-arm-none-eabi/bin/
# export TOOLCHAIN_LIB=/home/zhangzheng/toolchain/gcc-arm-10.3-2021.07-x86_64-arm-none-eabi/lib/gcc/arm-none-eabi/10.3.1/thumb/v7-m/nofp
# linux build
# export TOOLCHAIN=/home/zhangzheng/gcc-arm-none-eabi-5_4-2016q3/bin/
# export TOOLCHAIN_LIB=/home/zhangzheng/gcc-arm-none-eabi-5_4-2016q3/lib/gcc/arm-none-eabi/5.4.1/armv7e-m/fpu
# mac compile
# export TOOLCHAIN=/Users/zhangzheng/gcc-arm-none-eabi-10.3-2021.10/bin/
# export TOOLCHAIN_LIB=/Users/zhangzheng/gcc-arm-none-eabi-10.3-2021.10/lib/gcc/arm-none-eabi/10.3.1/thumb/v7e-m+fp/softfp
export TOOLCHAIN=/Users/zhangzheng/gcc-arm-none-eabi-10.3-2021.10/bin/
export TOOLCHAIN_LIB=/Users/zhangzheng/gcc-arm-none-eabi-10.3-2021.10/lib/gcc/arm-none-eabi/10.3.1/thumb/v7e-m+fp/softfp
# windows compile
# export TOOLCHAIN=/d/GNUArmEmbeddedToolchain/102021.10/bin/

View File

@@ -2,7 +2,7 @@
#include <stdint.h>
#include <errno.h>
#include "malloc_impl.h"
#include "u_malloc.h"
void *aligned_alloc(size_t align, size_t len)
{
unsigned char *mem, *new;
@@ -19,9 +19,9 @@ void *aligned_alloc(size_t align, size_t len)
}
if (align <= SIZE_ALIGN)
return malloc(len);
return u_malloc(len);
if (!(mem = malloc(len + align-1)))
if (!(mem = u_malloc(len + align-1)))
return 0;
new = (void *)((uintptr_t)mem + align-1 & -align);
@@ -48,6 +48,6 @@ void *aligned_alloc(size_t align, size_t len)
n->psize = c->csize = C_INUSE | (new-mem);
n->csize = t->psize -= new-mem;
__bin_chunk(c);
u__bin_chunk(c);
return new;
}

View File

@@ -34,5 +34,6 @@ struct bin {
#define IS_MMAPPED(c) !((c)->csize & (C_INUSE))
void u__bin_chunk(struct chunk *self);
#endif

View File

@@ -12,7 +12,6 @@
// #include "fork_impl.h"
void u_free(void *p);
static void __bin_chunk(struct chunk *self);
// #define malloc __libc_malloc_impl
// #define realloc __libc_realloc
// #define free __libc_free
@@ -400,7 +399,7 @@ void *u_realloc(void *p, size_t n)
struct chunk *split = (void *)((char *)self + n);
self->csize = split->psize = n | C_INUSE;
split->csize = next->psize = n0-n | C_INUSE;
__bin_chunk(split);
u__bin_chunk(split);
return CHUNK_TO_MEM(self);
}
@@ -433,7 +432,7 @@ copy_free_ret:
return new;
}
static void __bin_chunk(struct chunk *self)
void u__bin_chunk(struct chunk *self)
{
struct chunk *next = NEXT_CHUNK(self);
@@ -517,7 +516,7 @@ void u_free(void *p)
if (IS_MMAPPED(self))
unmap_chunk(self);
else
__bin_chunk(self);
u__bin_chunk(self);
}
#if 0
static void __malloc_donate(char *start, char *end)

View File

@@ -85,8 +85,6 @@ static void console_read_func(void)
if (!sys_tty.is_nl && L_ICANON(&sys_tty))
{
tty_write_hw(&sys_tty);
// 规范模式下没有成一行
cons_read_unlock();
}
else
{

View File

@@ -58,7 +58,7 @@ int main(int args, char *argv[])
return -1;
}
again:
ret = ns_query_svr("/eth", &net_drv_hd, 0x1);
ret = ns_query_svr("/dev/eth", &net_drv_hd, 0x1);
if (ret < 0)
{
// 0代表根节点

View File

@@ -19,7 +19,7 @@ int main(int argc, char *argv[])
{
printf("argv[%d]: %s\n", i, argv[i]);
}
exit(-1);
// exit(-1);
net_test();
fs_test3();
fs_test2();

View File

@@ -96,9 +96,7 @@ int main(int argc, char *argv[])
blk_drv_init(&net_drv);
ret = rpc_meta_init_def(TASK_THIS, &hd);
assert(ret >= 0);
// fs_svr_init();
// mkdir("/dev", 0777);
ns_register("/eth", hd, 0);
ns_register("/dev/eth", hd, 0);
meta_reg_svr_obj(&net_drv.svr, BLK_DRV_PROT);
while (1)
{