Commit Graph

1771 Commits

Author SHA1 Message Date
Ville Juven 0976258299 riscv/kstack: Remove riscv_current_ksp as obsolete
Unwinding the kernel stack did not work previously due to the way the task
startup logic works via nxtask_start and the up_task_start() system call.

After modifying the logic behind those, the kernel stack is in fact fully
unwound when return_from_exception is executed, so calling the original
hack "riscv_current_ksp" is not necessary anymore.
2024-10-04 08:33:34 +08:00
Ville Juven 190a2e306c riscv/syscall: Simplify task/pthread_start logic
This removes 2 reserved system calls and replaces them with an ASM snippet.
The result removes an unnecessary ecall from the process startup logic, as
well as ensures the stacks are FULLY unwound when the user process starts.

The logic is ported from ARM64.
2024-10-04 08:33:34 +08:00
Ville Juven e9f96105dd risc-v/syscall: Simplify dispatch_syscall for RISC-V
Port the simplification from ARM64, this removes the ugly inline assembly
trampoline "do_syscall" and replaces it with a simple table lookup and
call via function pointer.
2024-10-04 08:33:34 +08:00
Neo Xu e2e0706009 espressif/spi: fix missing SPI setup
Signed-off-by: Neo Xu <neo.xu1990@gmail.com>
2024-10-02 21:17:38 +08:00
Neo Xu 3636495f39 espressif/spi: fix crash when rx buffer is NULL
Signed-off-by: Neo Xu <neo.xu1990@gmail.com>
2024-10-02 21:17:38 +08:00
W-M-R 5febd80efe cmake: add_compile_options recognizes parameter exception
add_compile_options(--param asan-globals=1) is recognized as
--param-lasan-globals=1, which causes compilation exception:

Signed-off-by: W-M-R <Mike_0528@163.com>
2024-10-02 21:09:31 +08:00
cuiziwei 394a967263 nuttx/arch: Remove GCCVER and add compilation options directly.
Signed-off-by: cuiziwei <cuiziwei@xiaomi.com>
2024-10-01 20:41:02 +08:00
xuxingliang 7044b10c88 task: use get_task_name where possible
Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2024-10-01 20:38:06 +08:00
guoshichao ff4ad07576 greenhills: add cmake support
1. refactor the ghs/gcc/clang/armclang toolchain management in CMake
2. unify the cmake toolchain naming style
3. support greenhills build procedure with CMake
4. add protect build for greenhills and gnu toolchain with CMake

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2024-10-01 11:48:09 +08:00
Filipe Cavalcanti 8153307da5 espressif: remove static from spiflash operations 2024-09-30 20:42:00 +02:00
Filipe Cavalcanti a876f00e2a risc-v/espressif: support marking interrupt as running from IRAM 2024-09-30 20:42:00 +02:00
Huang Qi 52bb516d37 risc-v: Support customize idle loop
Support customize idle loop by CONFIG_ARCH_IDLE_CUSTOM
as other architectures.

Then user can provide their own `up_idle()` function
with CONFIG_ARCH_IDLE_CUSTOM enabled.

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2024-09-30 14:08:56 +08:00
hujun5 9de9f8168d sched: change the SMP scheduling policy from synchronous to asynchronous
reason:
Currently, if we need to schedule a task to another CPU, we have to completely halt the other CPU,
manipulate the scheduling linked list, and then resume the operation of that CPU. This process is both time-consuming and unnecessary.

During this process, both the current CPU and the target CPU are inevitably subjected to busyloop.

The improved strategy is to simply send a cross-core interrupt to the target CPU.
The current CPU continues to run while the target CPU responds to the interrupt, eliminating the certainty of a busyloop occurring.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-09-29 08:54:51 +08:00
Jani Paalijarvi 21f9fc2b28 mpfs_serial.c: Add RX flowcontrol
Disable RX interrupts and clear the fifo in case of full RX buffer.
Enable RX interrupts in case of empty buffer.
2024-09-27 10:53:12 -03:00
hujun5 3e459c0477 riscv: use g_running_task store current regs
This commit fixes the regression from https://github.com/apache/nuttx/pull/13561

In order to determine whether a context switch has occurred,
we can use g_running_task to store the current regs.
This allows us to compare the current register state with the previously
stored state to identify if a context switch has taken place.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-09-27 18:07:31 +08:00
Ville Juven 9ef76e3735 riscv_fork.c: Fix race condition when handling parent integer registers
We need to record the parent's integer register context upon exception
entry to a separate non-volatile area. Why?

Because xcp.regs can move due to a context switch within the fork() system
call, be it either via interrupt or a synchronization point.

Fix this by adding a "sregs" area where the saved user context is placed.
The critical section within fork() is also unnecessary.
2024-09-27 10:22:43 +08:00
Ville Juven 172d2a8491 riscv_fork.c: Fix vfork() for kernel mode + SMP
There was an error in the fork() routine when system calls are in use:
the child context is saved on the child's user stack, which is incorrect,
the context must be saved on the kernel stack instead.

The result is a full system crash if (when) the child executes on a
different CPU which does not have the same MMU mappings active.
2024-09-27 10:22:43 +08:00
ligd 35c8c80a00 arch: change nxsched_suspend/resume_scheduler() called position
for the citimon stats:

thread 0:                     thread 1:
enter_critical (t0)
up_switch_context
note suspend thread0 (t1)

                              thread running
                              IRQ happen, in ISR:
                                post thread0
                                up_switch_context
                                note resume thread0 (t2)
                                ISR continue f1
                                ISR continue f2
                                ...
                                ISR continue fn

leave_critical (t3)

You will see, the thread 0, critical_section time is:
(t1 - t0) + (t3 - t2)

BUT, this result contains f1 f2 .. fn time spent, it is wrong
to tell user thead0 hold the critical lots of time but actually
not belong to it.

Resolve:
change the nxsched_suspend/resume_scheduler to real hanppends

Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-09-27 09:53:33 +08:00
ligd 551e6ce3ab compile: add DEBUG_SYMBOLS_LEVEL allow custom the level
Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-09-27 00:13:07 +08:00
anjiahao c76e83beaa Debug option:change -g to -g3, add macro information to elf
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2024-09-27 00:13:07 +08:00
Huang Qi d9b95c5ca0 riscv: Remove some unnecessary macro guards
If CONFIG_SMP is not enabled, riscv_cpuindex.c will not be compiled
anyway.

And for CONFIG_ARCH_FPU, if it's not enabled, riscv_fpucmp.c will not
be compiled.

So we can remove the unnecessary macro guard for up_cpu_index() and
up_fpucmp().

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2024-09-26 16:23:48 +08:00
Jukka Laitinen 950b63c7f1 arch/risc-v/src/mpfs/mpfs_opensbi.c: Fix conflicting datatypes defined by NuttX vs. opensbi
Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
2024-09-26 16:10:09 +08:00
Jukka Laitinen 82ef3813bd arch/risc-v/src/mpfs: Make mpfs_hart_index2id table modifiable by bootloader
This is actually the same table as entrypoints, so just use the same data, which
can be set before booting any of the harts

Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
2024-09-26 16:10:09 +08:00
Ville Juven 27648479bc mpfs_mpucfg.h: Add missing MPUCFG registers
Now all registers are defined
2024-09-26 16:09:54 +08:00
Jukka Laitinen 06b3416384 arch/risc-v/src/common/riscv_initialstate.c: Fix stack pointer in coloration
The logical CPU index should be retrieved with this_cpu(); the
riscv_mhartid() returns the actual hart id of the SoC.

For mpfs target for example, NuttX can run on a single HART, for example on mhartid 2, but there is still just one logical CPU for the NuttX.

Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
2024-09-26 08:35:42 +08:00
Eero Nurkkala 737d4bf418 risc-v/mpfs: emmcsd: enforce HS DDR mode
Previously, address 0x03b70000u was written with shift bits
that only changed the bit width, not the mode. HS mode is
changed via 0x03B90100, which is required, according to Jedec
specs, for DDR mode. HS mode was not applied before. Enforce
DDR mode (50 MHz) for now.

The real boost, however, comes from removing the DMA limitation
at 0x08xxxxxx address space, which now seems unnecessary.

Signed-off-by: Eero Nurkkala <eero.nurkkala@offcode.fi>
2024-09-25 23:58:08 +08:00
Eero Nurkkala 6db0f7f009 risc-v/mpfs: emmcsd: deny unaligned access
Don't allow unaligned access with the DMA requests.
Return -EFAULT in case the provided address is unaligned.

Signed-off-by: Eero Nurkkala <eero.nurkkala@offcode.fi>
2024-09-25 23:58:08 +08:00
Jari Nippula 9b60f8d9d0 emmc interrupt blackout issue fix
sendfifo() function need enable BWR_IE before checking if BWE is enabled
to avoid BWE to be activated between the BWE check and BWR interrupt
enabling, which causes the interrupt to be missed and Data Timeout error.
2024-09-25 23:58:08 +08:00
Ville Juven c23babbcc7 mpfs/emmcsd: Set 8-bit data width and DDR HS mode for eMMC
This is not the correct way to do this, but it gives a nice perf. boost
2024-09-25 23:58:08 +08:00
Ville Juven c36bdba3cb mpfs/emmcsd: Set same base clock for SDR/DDR modes 2024-09-25 23:58:08 +08:00
Huang Qi c1b41fefeb riscv_cpuinfo: Add support for RVV extension in CPU info
Add missing info for RVV ISA extention, which is already supported
by NuttX.

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2024-09-25 23:54:19 +08:00
Jani Paalijarvi 3613eb209a arch/risc-v/src/mpfs/mpfs_corepwm.c: Disable PWM channels in setup
Set frequency to zero and disable channels in pwm_setup()
to avoid unexpected behaviour when starting PWM.

Signed-off-by: Jani Paalijarvi <jani.paalijarvi@unikie.com>
2024-09-25 21:47:15 +08:00
Jukka Laitinen 7e6e18697c arch/risc-v/src/mpfs: Remove CONFIG_MPFS_COREPWMx_PWMCLK configs
These are always the same as FPGA peripheral clock, so use that directly

Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
2024-09-25 21:47:15 +08:00
chao an 542e2ba625 CMake/preprocess: fix typo PREPROCES -> PREPROCESS
correct the marco define from PREPROCES to PREPROCESS

Signed-off-by: chao an <anchao@lixiang.com>
2024-09-25 11:55:06 +08:00
hujun5 c9bdb598b7 irq: use up_interrupt_context to replace up_current_regs
Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-09-25 08:58:20 +08:00
Tiago Medicci Serrano cdeb720bf8 xtensa/esp32[|s2|s3]: Fix task backtrace dump
- Fix `MAKE_PC_FROM_RA` macro to consider the instruction region
base address;
- Add sanity check for calculated PC and SP registers;
- Check if the stack pointer is within the interrupt stack to
enable backtrace dump if an exception occurs during the ISR;
2024-09-23 20:40:58 +08:00
hujun5 e4a0470527 riscv: add a return value to riscv_swint indicating whether a context switch is required
This commit fixes the regression from https://github.com/apache/nuttx/pull/13561

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-09-22 09:38:26 -03:00
hujun5 c5ecc49c10 riscv: g_current_regs is only used to determine if we are in irq,
with other functionalities removed.

reason:
  by doing this we can reduce context switch time,
  When we exit from an interrupt handler, we directly use tcb->xcp.regs

before
   text    data     bss     dec     hex filename
 138805     337   24256  163398   27e46 nuttx

after
   text    data     bss     dec     hex filename
 138499     337   24240  163076   27d04 nuttx

 szie change -322
Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-09-21 02:59:57 +08:00
wangmingrong1 469418f3c9 mm/kasan: Kasan global support setting alignment length
1. Similar to asan, supports single byte out of bounds detection
2. Fix the script to address the issue of not supporting the big end

Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2024-09-20 21:47:23 +08:00
simbit18 6a0c0722e2 CI: Improvement to speed up compilation and reduce download errors.
The simple improvement is designed to speed up compilation and reduce download errors on github and local.

Added a folder nxtmpdir for storing third-party packages

nuttxworkspace
|
|- nuttx
|- apps
|- nxtmpdir

tools/Unix.mk:
added export NXTMPDIR := $(WSDIR)/nxtmpdir

tools/configure.sh:
added option -S creates the nxtmpdir folder for third-party packages.

tools/Config.mk:
added macro
CLONE - Git clone repository.
CHECK_COMMITSHA - Check if the branch contains the commit SHA-1.

tools/testbuild.sh:
added option -S

For now I added in the folder this package

ESP_HAL_3RDPARTY_URL = https://github.com/espressif/esp-hal-3rdparty.git

ARCH
arch/xtensa/src/esp32/Make.defs
arch/xtensa/src/esp32s2/Make.defs
arch/xtensa/src/esp32s3/Make.defs
arch/risc-v/src/common/espressif/Make.defs
arch/risc-v/src/esp32c3-legacy/Make.defs

but you can also add other packages (maybe also of apps)
2024-09-20 11:26:01 +08:00
Stuart Ianna b60a8b216b arch/risc-v/src/litex_ticked: Set initial tick count to known value.
The tick count should be manually set as there is no guarantee that the
previous boot stage hasn't modified this count since reset.
2024-09-20 10:51:45 +08:00
Huang Qi 6695affe87 risc-v: Add a new option to control exception reason
The number of exception for risc-v is 16 (0 ~ 15)
for the machine ISA version 1.12 or earlier, the number of exception is 20
(0 ~ 19) from the ISA version 1.13. And maybe changed in the future.

Using a dedicated option to control the exception number to allow the earlier
version chip with customized exception number (e.g. 16 ~ 19 used) to define
the exception reason string correctly.

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2024-09-17 15:26:06 -03:00
Masayuki Ishikawa df298c186f Revert "build depend:Revert Make.dep intermediate ddc file"
This reverts commit ddc3119c4e.
2024-09-15 19:29:47 +08:00
xuxin19 ddc3119c4e build depend:Revert Make.dep intermediate ddc file
Revert "Parallelize depend file generation"
This reverts commit d5b6ec450f.

parallel depend ddc does not significantly speed up compilation,
intermediately generated .ddc files can cause problems if compilation is interrupted unexpectedly

Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2024-09-15 10:01:58 +08:00
ouyangxiangzhen 733a68002c arch/riscv: Fixed hardware timer warps-around issue
This commit fixed the issue where the hardware timer wraps around and causes the system to halt.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
2024-09-14 00:07:13 +08:00
hujun5 908df725ad arch: use up_current_regs/up_set_current_regs replace CURRENT_REGS
reason:
1 On different architectures, we can utilize more optimized strategies
  to implement up_current_regs/up_set_current_regs.
eg. use interrupt registersor percpu registers.

code size
before
    text    data     bss     dec     hex filename
 262848   49985   63893  376726   5bf96 nuttx

after
       text    data     bss     dec     hex filename
 262844   49985   63893  376722   5bf92 nuttx

size change -4

Configuring NuttX and compile:
$ ./tools/configure.sh -l qemu-armv8a:nsh_smp
$ make
Running with qemu
$ qemu-system-aarch64 -cpu cortex-a53 -smp 4 -nographic \
   -machine virt,virtualization=on,gic-version=3 \
   -net none -chardev stdio,id=con,mux=on -serial chardev:con \
   -mon chardev=con,mode=readline -kernel ./nuttx

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-09-13 23:18:58 +08:00
liaoao 512a496467 riscv_mtimer: modify riscv_mtimer_current to reduce precision lost
Signed-off-by: liaoao <liaoao@xiaomi.com>
2024-09-13 08:55:00 +08:00
Martin Vajnar 1fa4e61230 espressif: Add Quadrature Encoder driver (using PCNT)
Signed-off-by: Martin Vajnar <martin.vajnar@gmail.com>
Co-authored-by: Pavel Pisa <pisa@fel.cvut.cz>
2024-09-13 01:49:28 +08:00
ligd 6a2c03732f clock: Replace all ts and tick conversion functions
Using the ts/tick conversion functions provided in clock.h

Do this caused we want speed up the time calculation, so change:
clock_time2ticks, clock_ticks2time, clock_timespec_add,
clock_timespec_compare, clock_timespec_subtract... to MACRO

Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-09-12 18:14:39 +08:00
Stuart Ianna 779d4af3e9 arch/risc-v/src/litex: Claim all pending PLIC interrupts.
Attempt to service all interrupts pending in the PLIC's claim register. Ideally, this is more efficient than switching context for each interrupt received.
2024-09-12 15:06:04 +08:00