diff --git a/arch/Kconfig b/arch/Kconfig index 5bf143bdb6e31..bd5d0803bd666 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -359,11 +359,6 @@ config ARCH_HAVE_PROGMEM_READ default n depends on ARCH_HAVE_PROGMEM -config ARCH_HAVE_PROGMEM_ERASESTATE - bool - default n - depends on ARCH_HAVE_PROGMEM - config ARCH_HAVE_RESET bool default n diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index f2b7b4c787553..36f12f4995685 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -377,6 +377,8 @@ config ARCH_CHIP_STM32H7 select ARCH_HAVE_SPI_BITORDER select ARM_HAVE_MPU_UNIFIED select ARMV7M_HAVE_STACKCHECK + select ARCH_HAVE_TICKLESS + select ARCH_HAVE_TIMEKEEPING ---help--- STMicro STM32H7 architectures (ARM Cortex-M7). diff --git a/arch/arm/include/cxd56xx/crashdump.h b/arch/arm/include/cxd56xx/crashdump.h index cabdf1c2359fc..e6b7dd142ae6b 100644 --- a/arch/arm/include/cxd56xx/crashdump.h +++ b/arch/arm/include/cxd56xx/crashdump.h @@ -104,7 +104,7 @@ typedef struct fault_flags_t flags; /* What is in the dump */ uintptr_t current_regs; /* Used to validate the dump */ int lineno; /* __LINE__ to up_assert */ - int pid; /* Process ID */ + pid_t pid; /* Process ID */ uint32_t regs[XCPTCONTEXT_REGS]; /* Interrupt register save area */ stack_t stacks; /* Stack info */ #if CONFIG_TASK_NAME_SIZE > 0 diff --git a/arch/arm/src/arm/Toolchain.defs b/arch/arm/src/arm/Toolchain.defs index 58671f3809853..07127dc568958 100644 --- a/arch/arm/src/arm/Toolchain.defs +++ b/arch/arm/src/arm/Toolchain.defs @@ -73,6 +73,10 @@ else MAXOPTIMIZATION += -fomit-frame-pointer endif +ifeq ($(CONFIG_MM_KASAN),y) + ARCHCPUFLAGS += -fsanitize=kernel-address +endif + # NuttX buildroot under Linux or Cygwin ifeq ($(CONFIG_ARM_TOOLCHAIN),BUILDROOT) @@ -103,12 +107,12 @@ OBJDUMP = $(CROSSDEV)objdump # Add the builtin library -EXTRA_LIBS += ${shell $(CC) $(ARCHCPUFLAGS) --print-libgcc-file-name} +EXTRA_LIBS += ${wildcard ${shell $(CC) $(ARCHCPUFLAGS) --print-libgcc-file-name}} ifneq ($(CONFIG_LIBM),y) EXTRA_LIBS += ${wildcard ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libm.a}} endif ifeq ($(CONFIG_LIBSUPCXX),y) - EXTRA_LIBS += ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libsupc++.a} + EXTRA_LIBS += ${wildcard ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libsupc++.a}} endif diff --git a/arch/arm/src/arm/arm_initialstate.c b/arch/arm/src/arm/arm_initialstate.c index 6a49db4a617b5..e4e0c74914fe1 100644 --- a/arch/arm/src/arm/arm_initialstate.c +++ b/arch/arm/src/arm/arm_initialstate.c @@ -61,7 +61,7 @@ void up_initial_state(struct tcb_s *tcb) /* Initialize the idle thread stack */ - if (tcb->pid == 0) + if (tcb->pid == IDLE_PROCESS_ID) { tcb->stack_alloc_ptr = (void *)(g_idle_topstack - CONFIG_IDLETHREAD_STACKSIZE); diff --git a/arch/arm/src/arm/arm_schedulesigaction.c b/arch/arm/src/arm/arm_schedulesigaction.c index 9e37043162b93..2d37ec6ed8325 100644 --- a/arch/arm/src/arm/arm_schedulesigaction.c +++ b/arch/arm/src/arm/arm_schedulesigaction.c @@ -134,13 +134,14 @@ void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver) * delivered. */ - CURRENT_REGS = - (FAR void *)STACK_ALIGN_DOWN((uint32_t)CURRENT_REGS - - (uint32_t)XCPTCONTEXT_SIZE); + CURRENT_REGS = (FAR void *) + ((uint32_t)CURRENT_REGS - + (uint32_t)XCPTCONTEXT_SIZE); memcpy((FAR uint32_t *)CURRENT_REGS, tcb->xcp.saved_regs, XCPTCONTEXT_SIZE); - CURRENT_REGS[REG_SP] = (uint32_t)CURRENT_REGS; + CURRENT_REGS[REG_SP] = (uint32_t)CURRENT_REGS + + (uint32_t)XCPTCONTEXT_SIZE; /* Then set up to vector to the trampoline with interrupts * disabled @@ -175,12 +176,13 @@ void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver) * delivered. */ - tcb->xcp.regs = - (FAR void *)STACK_ALIGN_DOWN((uint32_t)tcb->xcp.regs - - (uint32_t)XCPTCONTEXT_SIZE); + tcb->xcp.regs = (FAR void *) + ((uint32_t)tcb->xcp.regs - + (uint32_t)XCPTCONTEXT_SIZE); memcpy(tcb->xcp.regs, tcb->xcp.saved_regs, XCPTCONTEXT_SIZE); - tcb->xcp.regs[REG_SP] = (uint32_t)tcb->xcp.regs; + tcb->xcp.regs[REG_SP] = (uint32_t)tcb->xcp.regs + + (uint32_t)XCPTCONTEXT_SIZE; /* Then set up to vector to the trampoline with interrupts * disabled diff --git a/arch/arm/src/armv6-m/Toolchain.defs b/arch/arm/src/armv6-m/Toolchain.defs index 6b55720c9bbe8..c08d23e5b79d2 100644 --- a/arch/arm/src/armv6-m/Toolchain.defs +++ b/arch/arm/src/armv6-m/Toolchain.defs @@ -81,6 +81,10 @@ ifeq ($(CONFIG_ARMV6M_TOOLCHAIN),GNU_EABI) ARCHCPUFLAGS = -mcpu=cortex-m0 -mthumb -mfloat-abi=soft endif +ifeq ($(CONFIG_MM_KASAN),y) + ARCHCPUFLAGS += -fsanitize=kernel-address +endif + # Default toolchain CC = $(CROSSDEV)gcc @@ -95,12 +99,12 @@ OBJDUMP = $(CROSSDEV)objdump # Add the builtin library -EXTRA_LIBS += ${shell $(CC) $(ARCHCPUFLAGS) --print-libgcc-file-name} +EXTRA_LIBS += ${wildcard ${shell $(CC) $(ARCHCPUFLAGS) --print-libgcc-file-name}} ifneq ($(CONFIG_LIBM),y) EXTRA_LIBS += ${wildcard ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libm.a}} endif ifeq ($(CONFIG_LIBSUPCXX),y) - EXTRA_LIBS += ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libsupc++.a} + EXTRA_LIBS += ${wildcard ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libsupc++.a}} endif diff --git a/arch/arm/src/armv6-m/arm_exception.S b/arch/arm/src/armv6-m/arm_exception.S index c438bf595eed2..224ecdd535142 100644 --- a/arch/arm/src/armv6-m/arm_exception.S +++ b/arch/arm/src/armv6-m/arm_exception.S @@ -167,10 +167,7 @@ exception_common: */ #if CONFIG_ARCH_INTERRUPTSTACK > 3 - setintstack r7, r6 /* SP = IRQ stack top */ - push {r1} /* Save the MSP on the interrupt stack */ - bl arm_doirq /* R0=IRQ, R1=register save area on stack */ - pop {r1} /* Recover R1=main stack pointer */ + setintstack r7, r6 /* SP = IRQ stack top */ #else /* If the interrupt stack is disabled, reserve xcpcontext to ensure * that signal processing can have a separate xcpcontext to handle @@ -183,64 +180,30 @@ exception_common: * also the sp should be restore after arm_doirq() */ - sub r1, r1, #XCPTCONTEXT_SIZE /* Reserve signal context */ - - msr msp, r1 /* We are using the main stack pointer */ - - add r1, r1, #XCPTCONTEXT_SIZE /* Restore signal context */ + mov r2, r1 /* Reserve signal context */ + sub r2, r2, #XCPTCONTEXT_SIZE + msr msp, r2 /* We are using the main stack pointer */ +#endif bl arm_doirq /* R0=IRQ, R1=register save area on stack */ - mrs r1, msp /* Recover R1=main stack pointer */ -#endif - /* On return from arm_doirq, R0 will hold a pointer to register context - * array to use for the interrupt return. If that return value is the same - * as current stack pointer, then things are relatively easy. - */ - - cmp r0, r1 /* Context switch? */ - beq 3f /* Branch if no context switch */ - - /* We are returning with a pending context switch. This case is different - * because in this case, the register save structure does not lie on the - * stack but, rather within a TCB structure. We'll have to copy some - * values to the stack. - */ - - /* Copy the hardware-saved context to the new stack */ - - mov r2, #SW_XCPT_SIZE /* R2=Size of software-saved portion of the context array */ - add r1, r0, r2 /* R1=Address of HW save area in reg array */ - ldr r2, [r0, #(4*REG_SP)] /* R2=Value of SP before the interrupt */ - sub r2, #HW_XCPT_SIZE /* R2=Address of HW save area on the return stack */ - ldmia r1!, {r4-r7} /* Fetch four registers from the HW save area */ - stmia r2!, {r4-r7} /* Copy four registers to the return stack */ - ldmia r1!, {r4-r7} /* Fetch four registers from the HW save area */ - stmia r2!, {r4-r7} /* Copy four registers to the return stack */ - - /* Restore the register contents */ - - mov r1, r0 - -3: - /* We are returning with no context switch. We simply need to "unwind" - * the same stack frame that we created at entry. + * array to use for the interrupt return. */ /* Recover R8-R11 and EXEC_RETURN (5 registers) */ mov r2, #(4*REG_R8) /* R2=Offset to R8 storage */ - add r0, r1, r2 /* R0=Address of R8 storage */ + add r1, r0, r2 /* R1=Address of R8 storage */ #ifdef CONFIG_BUILD_PROTECTED - ldmia r0!, {r2-r6} /* Recover R8-R11 and R14 (5 registers)*/ + ldmia r1!, {r2-r6} /* Recover R8-R11 and R14 (5 registers)*/ mov r8, r2 /* Move to position in high registers */ mov r9, r3 mov r10, r4 mov r11, r5 mov r14, r6 /* EXEC_RETURN */ #else - ldmia r0!, {r2-r5} /* Recover R8-R11 and R14 (5 registers)*/ + ldmia r1!, {r2-r5} /* Recover R8-R11 (4 registers)*/ mov r8, r2 /* Move to position in high registers */ mov r9, r3 mov r10, r4 @@ -251,7 +214,7 @@ exception_common: * the stack pointer as it was on entry to the exception handler. */ - ldmia r1!, {r2-r7} /* Recover R4-R7 + 2 temp values */ + ldmia r0!, {r2-r7} /* Recover R4-R7 + 2 temp values */ mov r1, #HW_XCPT_SIZE /* R1=Size of hardware-saved portion of the context array */ sub r1, r2, r1 /* R1=Value of MSP/PSP on exception entry */ @@ -262,14 +225,14 @@ exception_common: #ifdef CONFIG_BUILD_PROTECTED mov r0, r14 /* Copy high register to low register */ lsl r0, #(31 - EXC_RETURN_PROCESS_BITNO) /* Move to bit 31 */ - bmi 5f /* Test bit 31 */ + bmi 3f /* Test bit 31 */ msr msp, r1 /* R1=The main stack pointer */ - b 6f + b 4f -5: +3: msr psp, r1 /* R1=The process stack pointer */ -6: +4: #else msr msp, r1 /* R1=The main stack pointer */ ldr r0, =EXC_RETURN_PRIVTHR /* R0=EXC_RETURN to privileged mode */ diff --git a/arch/arm/src/armv6-m/arm_initialstate.c b/arch/arm/src/armv6-m/arm_initialstate.c index 59482b977c9ec..b3e068fc3de40 100644 --- a/arch/arm/src/armv6-m/arm_initialstate.c +++ b/arch/arm/src/armv6-m/arm_initialstate.c @@ -62,7 +62,7 @@ void up_initial_state(struct tcb_s *tcb) /* Initialize the idle thread stack */ - if (tcb->pid == 0) + if (tcb->pid == IDLE_PROCESS_ID) { tcb->stack_alloc_ptr = (void *)(g_idle_topstack - CONFIG_IDLETHREAD_STACKSIZE); diff --git a/arch/arm/src/armv6-m/arm_schedulesigaction.c b/arch/arm/src/armv6-m/arm_schedulesigaction.c index 23e4290628d56..1f30fed6de88d 100644 --- a/arch/arm/src/armv6-m/arm_schedulesigaction.c +++ b/arch/arm/src/armv6-m/arm_schedulesigaction.c @@ -136,13 +136,14 @@ void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver) * delivered. */ - CURRENT_REGS = - (FAR void *)STACK_ALIGN_DOWN((uint32_t)CURRENT_REGS - - (uint32_t)XCPTCONTEXT_SIZE); + CURRENT_REGS = (FAR void *) + ((uint32_t)CURRENT_REGS - + (uint32_t)XCPTCONTEXT_SIZE); memcpy((FAR uint32_t *)CURRENT_REGS, tcb->xcp.saved_regs, XCPTCONTEXT_SIZE); - CURRENT_REGS[REG_SP] = (uint32_t)CURRENT_REGS; + CURRENT_REGS[REG_SP] = (uint32_t)CURRENT_REGS + + (uint32_t)XCPTCONTEXT_SIZE; /* Then set up to vector to the trampoline with interrupts * disabled. The kernel-space trampoline must run in @@ -182,12 +183,13 @@ void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver) * delivered. */ - tcb->xcp.regs = - (FAR void *)STACK_ALIGN_DOWN((uint32_t)tcb->xcp.regs - - (uint32_t)XCPTCONTEXT_SIZE); + tcb->xcp.regs = (FAR void *) + ((uint32_t)tcb->xcp.regs - + (uint32_t)XCPTCONTEXT_SIZE); memcpy(tcb->xcp.regs, tcb->xcp.saved_regs, XCPTCONTEXT_SIZE); - tcb->xcp.regs[REG_SP] = (uint32_t)tcb->xcp.regs; + tcb->xcp.regs[REG_SP] = (uint32_t)tcb->xcp.regs + + (uint32_t)XCPTCONTEXT_SIZE; /* Then set up to vector to the trampoline with interrupts * disabled. We must already be in privileged thread mode to be @@ -285,13 +287,14 @@ void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver) * been delivered. */ - tcb->xcp.regs = - (FAR void *)STACK_ALIGN_DOWN((uint32_t)tcb->xcp.regs - - (uint32_t)XCPTCONTEXT_SIZE); + tcb->xcp.regs = (FAR void *) + ((uint32_t)tcb->xcp.regs - + (uint32_t)XCPTCONTEXT_SIZE); memcpy(tcb->xcp.regs, tcb->xcp.saved_regs, XCPTCONTEXT_SIZE); - tcb->xcp.regs[REG_SP] = (uint32_t)tcb->xcp.regs; + tcb->xcp.regs[REG_SP] = (uint32_t)tcb->xcp.regs + + (uint32_t)XCPTCONTEXT_SIZE; /* Then set up vector to the trampoline with interrupts * disabled. We must already be in privileged thread mode @@ -328,13 +331,14 @@ void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver) * been delivered. */ - CURRENT_REGS = - (FAR void *)STACK_ALIGN_DOWN((uint32_t)CURRENT_REGS - - (uint32_t)XCPTCONTEXT_SIZE); + CURRENT_REGS = (FAR void *) + ((uint32_t)CURRENT_REGS - + (uint32_t)XCPTCONTEXT_SIZE); memcpy((FAR uint32_t *)CURRENT_REGS, tcb->xcp.saved_regs, XCPTCONTEXT_SIZE); - CURRENT_REGS[REG_SP] = (uint32_t)CURRENT_REGS; + CURRENT_REGS[REG_SP] = (uint32_t)CURRENT_REGS + + (uint32_t)XCPTCONTEXT_SIZE; /* Then set up vector to the trampoline with interrupts * disabled. The kernel-space trampoline must run in @@ -395,12 +399,13 @@ void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver) * delivered. */ - tcb->xcp.regs = - (FAR void *)STACK_ALIGN_DOWN((uint32_t)tcb->xcp.regs - - (uint32_t)XCPTCONTEXT_SIZE); + tcb->xcp.regs = (FAR void *) + ((uint32_t)tcb->xcp.regs - + (uint32_t)XCPTCONTEXT_SIZE); memcpy(tcb->xcp.regs, tcb->xcp.saved_regs, XCPTCONTEXT_SIZE); - tcb->xcp.regs[REG_SP] = (uint32_t)tcb->xcp.regs; + tcb->xcp.regs[REG_SP] = (uint32_t)tcb->xcp.regs + + (uint32_t)XCPTCONTEXT_SIZE; /* Increment the IRQ lock count so that when the task is restarted, * it will hold the IRQ spinlock. diff --git a/arch/arm/src/armv7-a/Toolchain.defs b/arch/arm/src/armv7-a/Toolchain.defs index 173deccf57e7e..23a7cf9680c12 100644 --- a/arch/arm/src/armv7-a/Toolchain.defs +++ b/arch/arm/src/armv7-a/Toolchain.defs @@ -102,6 +102,10 @@ else ARCHFPUFLAGS += -mfloat-abi=soft endif +ifeq ($(CONFIG_MM_KASAN),y) + ARCHCPUFLAGS += -fsanitize=kernel-address +endif + ifeq ($(CONFIG_DEBUG_CUSTOMOPT),y) MAXOPTIMIZATION := $(CONFIG_DEBUG_OPTLEVEL) else @@ -150,12 +154,12 @@ OBJDUMP = $(CROSSDEV)objdump # Add the builtin library -EXTRA_LIBS += ${shell $(CC) $(ARCHCPUFLAGS) --print-libgcc-file-name} +EXTRA_LIBS += ${wildcard ${shell $(CC) $(ARCHCPUFLAGS) --print-libgcc-file-name}} ifneq ($(CONFIG_LIBM),y) EXTRA_LIBS += ${wildcard ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libm.a}} endif ifeq ($(CONFIG_LIBSUPCXX),y) - EXTRA_LIBS += ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libsupc++.a} + EXTRA_LIBS += ${wildcard ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libsupc++.a}} endif diff --git a/arch/arm/src/armv7-a/arm_initialstate.c b/arch/arm/src/armv7-a/arm_initialstate.c index 9489b5101f979..36650eb451f24 100644 --- a/arch/arm/src/armv7-a/arm_initialstate.c +++ b/arch/arm/src/armv7-a/arm_initialstate.c @@ -61,7 +61,7 @@ void up_initial_state(struct tcb_s *tcb) /* Initialize the idle thread stack */ - if (tcb->pid == 0) + if (tcb->pid == IDLE_PROCESS_ID) { tcb->stack_alloc_ptr = (void *)(g_idle_topstack - CONFIG_IDLETHREAD_STACKSIZE); diff --git a/arch/arm/src/armv7-a/arm_schedulesigaction.c b/arch/arm/src/armv7-a/arm_schedulesigaction.c index aaf03c03f88ab..497cec24afe53 100644 --- a/arch/arm/src/armv7-a/arm_schedulesigaction.c +++ b/arch/arm/src/armv7-a/arm_schedulesigaction.c @@ -139,13 +139,14 @@ void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver) * delivered. */ - CURRENT_REGS = - (FAR void *)STACK_ALIGN_DOWN((uint32_t)CURRENT_REGS - - (uint32_t)XCPTCONTEXT_SIZE); + CURRENT_REGS = (FAR void *) + ((uint32_t)CURRENT_REGS - + (uint32_t)XCPTCONTEXT_SIZE); memcpy((FAR uint32_t *)CURRENT_REGS, tcb->xcp.saved_regs, XCPTCONTEXT_SIZE); - CURRENT_REGS[REG_SP] = (uint32_t)CURRENT_REGS; + CURRENT_REGS[REG_SP] = (uint32_t)CURRENT_REGS + + (uint32_t)XCPTCONTEXT_SIZE; /* Then set up to vector to the trampoline with interrupts * disabled @@ -183,12 +184,13 @@ void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver) * delivered. */ - tcb->xcp.regs = - (FAR void *)STACK_ALIGN_DOWN((uint32_t)tcb->xcp.regs - - (uint32_t)XCPTCONTEXT_SIZE); + tcb->xcp.regs = (FAR void *) + ((uint32_t)tcb->xcp.regs - + (uint32_t)XCPTCONTEXT_SIZE); memcpy(tcb->xcp.regs, tcb->xcp.saved_regs, XCPTCONTEXT_SIZE); - tcb->xcp.regs[REG_SP] = (uint32_t)tcb->xcp.regs; + tcb->xcp.regs[REG_SP] = (uint32_t)tcb->xcp.regs + + (uint32_t)XCPTCONTEXT_SIZE; /* Then set up to vector to the trampoline with interrupts * disabled @@ -284,13 +286,14 @@ void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver) * been delivered. */ - tcb->xcp.regs = - (FAR void *)STACK_ALIGN_DOWN((uint32_t)tcb->xcp.regs - - (uint32_t)XCPTCONTEXT_SIZE); + tcb->xcp.regs = (FAR void *) + ((uint32_t)tcb->xcp.regs - + (uint32_t)XCPTCONTEXT_SIZE); memcpy(tcb->xcp.regs, tcb->xcp.saved_regs, XCPTCONTEXT_SIZE); - tcb->xcp.regs[REG_SP] = (uint32_t)tcb->xcp.regs; + tcb->xcp.regs[REG_SP] = (uint32_t)tcb->xcp.regs + + (uint32_t)XCPTCONTEXT_SIZE; /* Then set up to vector to the trampoline with interrupts * disabled @@ -326,13 +329,14 @@ void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver) * been delivered. */ - CURRENT_REGS = - (FAR void *)STACK_ALIGN_DOWN((uint32_t)CURRENT_REGS - - (uint32_t)XCPTCONTEXT_SIZE); + CURRENT_REGS = (FAR void *) + ((uint32_t)CURRENT_REGS - + (uint32_t)XCPTCONTEXT_SIZE); memcpy((FAR uint32_t *)CURRENT_REGS, tcb->xcp.saved_regs, XCPTCONTEXT_SIZE); - CURRENT_REGS[REG_SP] = (uint32_t)CURRENT_REGS; + CURRENT_REGS[REG_SP] = (uint32_t)CURRENT_REGS + + (uint32_t)XCPTCONTEXT_SIZE; /* Then set up vector to the trampoline with interrupts * disabled. The kernel-space trampoline must run in @@ -393,12 +397,13 @@ void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver) * delivered. */ - tcb->xcp.regs = - (FAR void *)STACK_ALIGN_DOWN((uint32_t)tcb->xcp.regs - - (uint32_t)XCPTCONTEXT_SIZE); + tcb->xcp.regs = (FAR void *) + ((uint32_t)tcb->xcp.regs - + (uint32_t)XCPTCONTEXT_SIZE); memcpy(tcb->xcp.regs, tcb->xcp.saved_regs, XCPTCONTEXT_SIZE); - tcb->xcp.regs[REG_SP] = (uint32_t)tcb->xcp.regs; + tcb->xcp.regs[REG_SP] = (uint32_t)tcb->xcp.regs + + (uint32_t)XCPTCONTEXT_SIZE; /* Increment the IRQ lock count so that when the task is restarted, * it will hold the IRQ spinlock. diff --git a/arch/arm/src/armv7-m/Toolchain.defs b/arch/arm/src/armv7-m/Toolchain.defs index 8bfc49eb70a74..c6f9639baab06 100644 --- a/arch/arm/src/armv7-m/Toolchain.defs +++ b/arch/arm/src/armv7-m/Toolchain.defs @@ -130,6 +130,10 @@ else endif endif +ifeq ($(CONFIG_MM_KASAN),y) + ARCHCPUFLAGS += -fsanitize=kernel-address +endif + # Generic GNU EABI toolchain ifeq ($(CONFIG_ARMV7M_TOOLCHAIN),GNU_EABI) @@ -160,12 +164,12 @@ OBJDUMP = $(CROSSDEV)objdump # Add the builtin library -EXTRA_LIBS += ${shell $(CC) $(ARCHCPUFLAGS) --print-libgcc-file-name} +EXTRA_LIBS += ${wildcard ${shell $(CC) $(ARCHCPUFLAGS) --print-libgcc-file-name}} ifneq ($(CONFIG_LIBM),y) EXTRA_LIBS += ${wildcard ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libm.a}} endif ifeq ($(CONFIG_LIBSUPCXX),y) - EXTRA_LIBS += ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libsupc++.a} + EXTRA_LIBS += ${wildcard ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libsupc++.a}} endif diff --git a/arch/arm/src/armv7-m/arm_initialstate.c b/arch/arm/src/armv7-m/arm_initialstate.c index 2c5144658a16c..e57cdb93bff7d 100644 --- a/arch/arm/src/armv7-m/arm_initialstate.c +++ b/arch/arm/src/armv7-m/arm_initialstate.c @@ -63,7 +63,7 @@ void up_initial_state(struct tcb_s *tcb) /* Initialize the idle thread stack */ - if (tcb->pid == 0) + if (tcb->pid == IDLE_PROCESS_ID) { tcb->stack_alloc_ptr = (void *)(g_idle_topstack - CONFIG_IDLETHREAD_STACKSIZE); diff --git a/boards/arm/stm32/omnibusf4/src/stm32_perfcount.c b/arch/arm/src/armv7-m/arm_perf.c similarity index 69% rename from boards/arm/stm32/omnibusf4/src/stm32_perfcount.c rename to arch/arm/src/armv7-m/arm_perf.c index df393a9c71da6..fdf78196f2c9e 100644 --- a/boards/arm/stm32/omnibusf4/src/stm32_perfcount.c +++ b/arch/arm/src/armv7-m/arm_perf.c @@ -1,5 +1,5 @@ /**************************************************************************** - * boards/arm/stm32/omnibusf4/src/stm32_perfcount.c + * arch/arm/src/armv7-m/arm_perf.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -22,49 +22,55 @@ * Included Files ****************************************************************************/ -#include - -#include -#include - -#include "dwt.h" -#include "arm_internal.h" - +#include #include -#include +#include "arm_internal.h" +#include "dwt.h" +#include "itm.h" +#include "nvic.h" /**************************************************************************** - * Public Functions + * Private Data ****************************************************************************/ +static uint32_t g_cpu_freq; + /**************************************************************************** - * Name: up_perf_gettime + * Public Functions ****************************************************************************/ -uint32_t up_perf_gettime(void) +void up_perf_init(FAR void *arg) { - return getreg32(DWT_CYCCNT); -} + g_cpu_freq = (uint32_t)(uintptr_t)arg; -/**************************************************************************** - * Name: up_perf_getfreq - ****************************************************************************/ + /* Enable ITM and DWT resources, if not left enabled by debugger. */ + + modifyreg32(NVIC_DEMCR, 0, NVIC_DEMCR_TRCENA); + + /* Make sure the high speed cycle counter is running. It will be started + * automatically only if a debugger is connected. + */ + + putreg32(0xc5acce55, ITM_LAR); + modifyreg32(DWT_CTRL, 0, DWT_CTRL_CYCCNTENA_MASK); +} uint32_t up_perf_getfreq(void) { - return STM32_SYSCLK_FREQUENCY; + return g_cpu_freq; } -/**************************************************************************** - * Name: up_perf_convert - ****************************************************************************/ +uint32_t up_perf_gettime(void) +{ + return getreg32(DWT_CYCCNT); +} void up_perf_convert(uint32_t elapsed, FAR struct timespec *ts) { - b32_t b32elapsed; + uint32_t left; - b32elapsed = itob32(elapsed) / STM32_SYSCLK_FREQUENCY; - ts->tv_sec = b32toi(b32elapsed); - ts->tv_nsec = NSEC_PER_SEC * b32frac(b32elapsed) / b32ONE; + ts->tv_sec = elapsed / g_cpu_freq; + left = elapsed - ts->tv_sec * g_cpu_freq; + ts->tv_nsec = NSEC_PER_SEC * (uint64_t)left / g_cpu_freq; } diff --git a/arch/arm/src/armv7-m/arm_schedulesigaction.c b/arch/arm/src/armv7-m/arm_schedulesigaction.c index 9bcf40e1b337a..b8c224fbc4a32 100644 --- a/arch/arm/src/armv7-m/arm_schedulesigaction.c +++ b/arch/arm/src/armv7-m/arm_schedulesigaction.c @@ -137,13 +137,14 @@ void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver) * delivered. */ - CURRENT_REGS = - (FAR void *)STACK_ALIGN_DOWN((uint32_t)CURRENT_REGS - - (uint32_t)XCPTCONTEXT_SIZE); + CURRENT_REGS = (FAR void *) + ((uint32_t)CURRENT_REGS - + (uint32_t)XCPTCONTEXT_SIZE); memcpy((FAR uint32_t *)CURRENT_REGS, tcb->xcp.saved_regs, XCPTCONTEXT_SIZE); - CURRENT_REGS[REG_SP] = (uint32_t)CURRENT_REGS; + CURRENT_REGS[REG_SP] = (uint32_t)CURRENT_REGS + + (uint32_t)XCPTCONTEXT_SIZE; /* Then set up to vector to the trampoline with interrupts * disabled. The kernel-space trampoline must run in @@ -187,12 +188,13 @@ void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver) * delivered. */ - tcb->xcp.regs = - (FAR void *)STACK_ALIGN_DOWN((uint32_t)tcb->xcp.regs - - (uint32_t)XCPTCONTEXT_SIZE); + tcb->xcp.regs = (FAR void *) + ((uint32_t)tcb->xcp.regs - + (uint32_t)XCPTCONTEXT_SIZE); memcpy(tcb->xcp.regs, tcb->xcp.saved_regs, XCPTCONTEXT_SIZE); - tcb->xcp.regs[REG_SP] = (uint32_t)tcb->xcp.regs; + tcb->xcp.regs[REG_SP] = (uint32_t)tcb->xcp.regs + + (uint32_t)XCPTCONTEXT_SIZE; /* Then set up to vector to the trampoline with interrupts * disabled. We must already be in privileged thread mode to be @@ -294,13 +296,14 @@ void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver) * been delivered. */ - tcb->xcp.regs = - (FAR void *)STACK_ALIGN_DOWN((uint32_t)tcb->xcp.regs - - (uint32_t)XCPTCONTEXT_SIZE); + tcb->xcp.regs = (FAR void *) + ((uint32_t)tcb->xcp.regs - + (uint32_t)XCPTCONTEXT_SIZE); memcpy(tcb->xcp.regs, tcb->xcp.saved_regs, XCPTCONTEXT_SIZE); - tcb->xcp.regs[REG_SP] = (uint32_t)tcb->xcp.regs; + tcb->xcp.regs[REG_SP] = (uint32_t)tcb->xcp.regs + + (uint32_t)XCPTCONTEXT_SIZE; /* Then set up vector to the trampoline with interrupts * disabled. We must already be in privileged thread mode @@ -341,13 +344,14 @@ void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver) * been delivered. */ - CURRENT_REGS = - (FAR void *)STACK_ALIGN_DOWN((uint32_t)CURRENT_REGS - - (uint32_t)XCPTCONTEXT_SIZE); + CURRENT_REGS = (FAR void *) + ((uint32_t)CURRENT_REGS - + (uint32_t)XCPTCONTEXT_SIZE); memcpy((FAR uint32_t *)CURRENT_REGS, tcb->xcp.saved_regs, XCPTCONTEXT_SIZE); - CURRENT_REGS[REG_SP] = (uint32_t)CURRENT_REGS; + CURRENT_REGS[REG_SP] = (uint32_t)CURRENT_REGS + + (uint32_t)XCPTCONTEXT_SIZE; /* Then set up vector to the trampoline with interrupts * disabled. The kernel-space trampoline must run in @@ -412,12 +416,13 @@ void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver) * delivered. */ - tcb->xcp.regs = - (FAR void *)STACK_ALIGN_DOWN((uint32_t)tcb->xcp.regs - - (uint32_t)XCPTCONTEXT_SIZE); + tcb->xcp.regs = (FAR void *) + ((uint32_t)tcb->xcp.regs - + (uint32_t)XCPTCONTEXT_SIZE); memcpy(tcb->xcp.regs, tcb->xcp.saved_regs, XCPTCONTEXT_SIZE); - tcb->xcp.regs[REG_SP] = (uint32_t)tcb->xcp.regs; + tcb->xcp.regs[REG_SP] = (uint32_t)tcb->xcp.regs + + (uint32_t)XCPTCONTEXT_SIZE; /* Increment the IRQ lock count so that when the task is restarted, * it will hold the IRQ spinlock. diff --git a/arch/arm/src/armv7-m/gnu/arm_exception.S b/arch/arm/src/armv7-m/gnu/arm_exception.S index 8836f40308c3b..be6cc94d9daa9 100644 --- a/arch/arm/src/armv7-m/gnu/arm_exception.S +++ b/arch/arm/src/armv7-m/gnu/arm_exception.S @@ -188,10 +188,6 @@ exception_common: mov r1, sp - /* Also save the top of the stack in a preserved register */ - - mov r4, sp - #if CONFIG_ARCH_INTERRUPTSTACK > 7 /* If CONFIG_ARCH_INTERRUPTSTACK is defined, we will set the MSP to use * a special special interrupt stack pointer. The way that this is done @@ -199,9 +195,12 @@ exception_common: */ setintstack r2, r3 /* SP = IRQ stack top */ - - bl arm_doirq /* R0=IRQ, R1=register save (msp) */ #else + /* Otherwise, we will re-use the interrupted thread's stack. That may + * mean using either MSP or PSP stack for interrupt level processing (in + * kernel mode). + */ + /* If the interrupt stack is disabled, reserve xcpcontext to ensure * that signal processing can have a separate xcpcontext to handle * signal context (reference: arm_schedulesigaction.c): @@ -213,77 +212,22 @@ exception_common: * also the sp should be restore after arm_doirq() */ - sub r4, r4, #XCPTCONTEXT_SIZE /* Reserve signal context */ - - /* Otherwise, we will re-use the interrupted thread's stack. That may - * mean using either MSP or PSP stack for interrupt level processing (in - * kernel mode). - */ - - bic r2, r4, #7 /* Get the stack pointer with 8-byte alignment */ + sub r2, r1, #XCPTCONTEXT_SIZE /* Reserve signal context */ + bic r2, r2, #7 /* Get the stack pointer with 8-byte alignment */ mov sp, r2 /* Instantiate the aligned stack */ - - bl arm_doirq /* R0=IRQ, R1=register save (msp) */ - - /* If the interrupt stack is disabled, restore the signal context */ - - add r4, r4, #XCPTCONTEXT_SIZE /* Restore signal context */ #endif - mov r1, r4 /* Recover R1=main stack pointer */ + bl arm_doirq /* R0=IRQ, R1=register save (msp) */ /* On return from arm_doirq, R0 will hold a pointer to register context - * array to use for the interrupt return. If that return value is the same - * as current stack pointer, then things are relatively easy. + * array to use for the interrupt return. */ - cmp r0, r1 /* Context switch? */ - beq 2f /* Branch if no context switch */ - - /* We are returning with a pending context switch. This case is different - * because in this case, the register save structure does not lie on the - * stack but, rather within a TCB structure. We'll have to copy some - * values to the stack. - */ - - /* Copy the hardware-saved context to the stack, and restore the software - * saved context directly. - * - * XXX In the normal case, it appears that this entire operation is unnecessary; - * context switch time would be improved if we could work out when the stack - * is dirty and avoid the work... - */ - - add r1, r0, #SW_XCPT_SIZE /* R1=Address of HW save area in reg array */ - ldmia r1!, {r4-r11} /* Fetch eight registers in HW save area */ -#ifdef CONFIG_ARCH_FPU - vldmia r1!, {s0-s15} /* Fetch sixteen FP registers in HW save area */ - ldmia r1, {r2-r3} /* Fetch FPSCR and Reserved in HW save area */ -#endif - ldr r1, [r0, #(4*REG_SP)] /* R1=Value of SP before interrupt */ -#ifdef CONFIG_ARCH_FPU - stmdb r1!, {r2-r3} /* Store FPSCR and Reserved on the return stack */ - vstmdb r1!, {s0-s15} /* Store sixteen FP registers on the return stack */ -#endif - stmdb r1!, {r4-r11} /* Store eight registers on the return stack */ ldmia r0!, {r2-r11,r14} /* Recover R4-R11, r14 + 2 temp values */ #ifdef CONFIG_ARCH_FPU - vldmia r0, {s16-s31} /* Recover S16-S31 */ + vldmia r0!, {s16-s31} /* Recover S16-S31 */ #endif - b 3f /* Re-join common logic */ - -2: - /* We are returning with no context switch. We simply need to "unwind" - * the same stack frame that we created at entry. - */ - - ldmia r1!, {r2-r11,r14} /* Recover R4-R11, r14 + 2 temp values */ -#ifdef CONFIG_ARCH_FPU - vldmia r1!, {s16-s31} /* Recover S16-S31 */ -#endif - -3: /* The EXC_RETURN value tells us whether we are returning on the MSP or PSP */ @@ -295,21 +239,21 @@ exception_common: mrs r2, control /* R2=Contents of the control register */ tst r14, #EXC_RETURN_PROCESS_STACK /* nonzero if context on process stack */ - beq 4f /* Branch if privileged */ + beq 2f /* Branch if privileged */ orr r2, r2, #1 /* Unprivileged mode */ - msr psp, r1 /* R1=The process stack pointer */ - b 5f -4: + msr psp, r0 /* R0=The process stack pointer */ + b 3f +2: bic r2, r2, #1 /* Privileged mode */ - msr msp, r1 /* R1=The main stack pointer */ -5: + msr msp, r0 /* R0=The main stack pointer */ +3: msr control, r2 /* Save the updated control register */ #else tst r14, #EXC_RETURN_PROCESS_STACK /* nonzero if context on process stack */ ite eq /* Next two instructions conditional */ - msreq msp, r1 /* R1=The main stack pointer */ - msrne psp, r1 /* R1=The process stack pointer */ + msreq msp, r0 /* R0=The main stack pointer */ + msrne psp, r0 /* R0=The process stack pointer */ #endif /* Restore the interrupt state */ diff --git a/arch/arm/src/armv7-m/gnu/arm_lazyexception.S b/arch/arm/src/armv7-m/gnu/arm_lazyexception.S index 9cf57816ca1a3..29b88f638b123 100644 --- a/arch/arm/src/armv7-m/gnu/arm_lazyexception.S +++ b/arch/arm/src/armv7-m/gnu/arm_lazyexception.S @@ -193,9 +193,12 @@ exception_common: */ setintstack r2, r3 /* SP = IRQ stack top */ - - bl arm_doirq /* R0=IRQ, R1=register save (msp) */ #else + /* Otherwise, we will re-use the interrupted thread's stack. That may + * mean using either MSP or PSP stack for interrupt level processing (in + * kernel mode). + */ + /* If the interrupt stack is disabled, reserve xcpcontext to ensure * that signal processing can have a separate xcpcontext to handle * signal context (reference: arm_schedulesigaction.c): @@ -207,31 +210,19 @@ exception_common: * also the sp should be restore after arm_doirq() */ - sub r4, r4, #XCPTCONTEXT_SIZE /* Reserve signal context */ - - /* Otherwise, we will re-use the interrupted thread's stack. That may - * mean using either MSP or PSP stack for interrupt level processing (in - * kernel mode). - */ - - bic r2, r4, #7 /* Get the stack pointer with 8-byte alignment */ + sub r2, r4, #XCPTCONTEXT_SIZE /* Reserve signal context */ + bic r2, r2, #7 /* Get the stack pointer with 8-byte alignment */ mov sp, r2 /* Instantiate the aligned stack */ - - bl arm_doirq /* R0=IRQ, R1=register save (msp) */ - - /* If the interrupt stack is disabled, restore the signal context */ - - add r4, r4, #XCPTCONTEXT_SIZE /* Restore signal context */ #endif - mov r1, r4 /* Recover R1=main stack pointer */ + bl arm_doirq /* R0=IRQ, R1=register save (msp) */ /* On return from arm_doirq, R0 will hold a pointer to register context * array to use for the interrupt return. If that return value is the same * as current stack pointer, then things are relatively easy. */ - cmp r0, r1 /* Context switch? */ + cmp r0, r4 /* Context switch? */ beq 2f /* Branch if no context switch */ /* We are returning with a pending context switch. @@ -253,56 +244,30 @@ exception_common: bl arm_restorefpu /* Restore the FPU registers */ #endif - /* We are returning with a pending context switch. This case is different - * because in this case, the register save structure does not lie in the - * stack but, rather, within a TCB structure. We'll have to copy some - * values to the stack. - */ - - add r1, r0, #SW_XCPT_SIZE /* R1=Address of HW save area in reg array */ - ldmia r1, {r4-r11} /* Fetch eight registers in HW save area */ - ldr r1, [r0, #(4*REG_SP)] /* R1=Value of SP before interrupt */ - stmdb r1!, {r4-r11} /* Store eight registers in HW save area */ -#ifdef CONFIG_BUILD_PROTECTED - ldmia r0, {r2-r11,r14} /* Recover R4-R11, r14 + 2 temp values */ -#else - ldmia r0, {r2-r11} /* Recover R4-R11 + 2 temp values */ -#endif - b 3f /* Re-join common logic */ - - /* We are returning with no context switch. We simply need to "unwind" - * the same stack frame that we created - * - * Here: - * r1 = Address of the return stack (same as r0) - */ - 2: #ifdef CONFIG_BUILD_PROTECTED - ldmia r1!, {r2-r11,r14} /* Recover R4-R11, r14 + 2 temp values */ + ldmia r0!, {r2-r11,r14} /* Recover R4-R11, r14 + 2 temp values */ #else - ldmia r1!, {r2-r11} /* Recover R4-R11 + 2 temp values */ + ldmia r0!, {r2-r11} /* Recover R4-R11 + 2 temp values */ #endif #ifdef CONFIG_ARCH_FPU /* Skip over the block of memory reserved for floating pointer register - * save. Then R1 is the address of the HW save area + * save. Then R0 is the address of the HW save area */ - add r1, #(4*SW_FPU_REGS) + add r0, #(4*SW_FPU_REGS) #endif /* Set up to return from the exception * * Here: - * r1 = Address on the target thread's stack position at the start of + * r0 = Address on the target thread's stack position at the start of * the registers saved by hardware * r3 = primask or basepri * r4-r11 = restored register values */ -3: - #ifdef CONFIG_BUILD_PROTECTED /* The EXC_RETURN value will be 0xfffffff9 (privileged thread) or 0xfffffff1 * (handler mode) if the stack is on the MSP. It can only be on the PSP if @@ -311,18 +276,18 @@ exception_common: mrs r2, control /* R2=Contents of the control register */ tst r14, #EXC_RETURN_PROCESS_STACK /* nonzero if context on process stack */ - beq 4f /* Branch if privileged */ + beq 3f /* Branch if privileged */ orr r2, r2, #1 /* Unprivileged mode */ - msr psp, r1 /* R1=The process stack pointer */ - b 5f -4: + msr psp, r0 /* R0=The process stack pointer */ + b 4f +3: bic r2, r2, #1 /* Privileged mode */ - msr msp, r1 /* R1=The main stack pointer */ -5: + msr msp, r0 /* R0=The main stack pointer */ +4: msr control, r2 /* Save the updated control register */ #else - msr msp, r1 /* Recover the return MSP value */ + msr msp, r0 /* Recover the return MSP value */ /* Preload r14 with the special return value first (so that the return * actually occurs with interrupts still disabled). diff --git a/arch/arm/src/armv7-r/Toolchain.defs b/arch/arm/src/armv7-r/Toolchain.defs index 00a6db6abff0c..43860d442cb9e 100644 --- a/arch/arm/src/armv7-r/Toolchain.defs +++ b/arch/arm/src/armv7-r/Toolchain.defs @@ -90,6 +90,10 @@ ifeq ($(CONFIG_ENDIAN_BIG),y) ARCHCPUFLAGS += -mbig-endian endif +ifeq ($(CONFIG_MM_KASAN),y) + ARCHCPUFLAGS += -fsanitize=kernel-address +endif + ifeq ($(CONFIG_ENDIAN_BIG),y) TARGET_ARCH := armeb else @@ -126,12 +130,12 @@ OBJDUMP = $(CROSSDEV)objdump # Add the builtin library -EXTRA_LIBS += ${shell $(CC) $(ARCHCPUFLAGS) --print-libgcc-file-name} +EXTRA_LIBS += ${wildcard ${shell $(CC) $(ARCHCPUFLAGS) --print-libgcc-file-name}} ifneq ($(CONFIG_LIBM),y) EXTRA_LIBS += ${wildcard ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libm.a}} endif ifeq ($(CONFIG_LIBSUPCXX),y) - EXTRA_LIBS += ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libsupc++.a} + EXTRA_LIBS += ${wildcard ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libsupc++.a}} endif diff --git a/arch/arm/src/armv7-r/arm_initialstate.c b/arch/arm/src/armv7-r/arm_initialstate.c index 41d173af3162c..1c40415f00d73 100644 --- a/arch/arm/src/armv7-r/arm_initialstate.c +++ b/arch/arm/src/armv7-r/arm_initialstate.c @@ -61,7 +61,7 @@ void up_initial_state(struct tcb_s *tcb) /* Initialize the idle thread stack */ - if (tcb->pid == 0) + if (tcb->pid == IDLE_PROCESS_ID) { tcb->stack_alloc_ptr = (void *)(g_idle_topstack - CONFIG_IDLETHREAD_STACKSIZE); diff --git a/arch/arm/src/armv7-r/arm_schedulesigaction.c b/arch/arm/src/armv7-r/arm_schedulesigaction.c index 284ca3d057878..245696378a468 100644 --- a/arch/arm/src/armv7-r/arm_schedulesigaction.c +++ b/arch/arm/src/armv7-r/arm_schedulesigaction.c @@ -134,13 +134,14 @@ void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver) * delivered. */ - CURRENT_REGS = - (FAR void *)STACK_ALIGN_DOWN((uint32_t)CURRENT_REGS - - (uint32_t)XCPTCONTEXT_SIZE); + CURRENT_REGS = (FAR void *) + ((uint32_t)CURRENT_REGS - + (uint32_t)XCPTCONTEXT_SIZE); memcpy((FAR uint32_t *)CURRENT_REGS, tcb->xcp.saved_regs, XCPTCONTEXT_SIZE); - CURRENT_REGS[REG_SP] = (uint32_t)CURRENT_REGS; + CURRENT_REGS[REG_SP] = (uint32_t)CURRENT_REGS + + (uint32_t)XCPTCONTEXT_SIZE; /* Then set up to vector to the trampoline with interrupts * disabled @@ -179,12 +180,13 @@ void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver) * delivered. */ - tcb->xcp.regs = - (FAR void *)STACK_ALIGN_DOWN((uint32_t)tcb->xcp.regs - - (uint32_t)XCPTCONTEXT_SIZE); + tcb->xcp.regs = (FAR void *) + ((uint32_t)tcb->xcp.regs - + (uint32_t)XCPTCONTEXT_SIZE); memcpy(tcb->xcp.regs, tcb->xcp.saved_regs, XCPTCONTEXT_SIZE); - tcb->xcp.regs[REG_SP] = (uint32_t)tcb->xcp.regs; + tcb->xcp.regs[REG_SP] = (uint32_t)tcb->xcp.regs + + (uint32_t)XCPTCONTEXT_SIZE; /* Then set up to vector to the trampoline with interrupts * disabled diff --git a/arch/arm/src/armv8-m/Toolchain.defs b/arch/arm/src/armv8-m/Toolchain.defs index b9e0216ac9b7e..1a8f38e0c7c9c 100644 --- a/arch/arm/src/armv8-m/Toolchain.defs +++ b/arch/arm/src/armv8-m/Toolchain.defs @@ -128,6 +128,10 @@ else endif endif +ifeq ($(CONFIG_MM_KASAN),y) + ARCHCPUFLAGS += -fsanitize=kernel-address +endif + # Generic GNU EABI toolchain ifeq ($(CONFIG_ARMV8M_TOOLCHAIN),GNU_EABI) @@ -156,12 +160,12 @@ OBJDUMP = $(CROSSDEV)objdump # Add the builtin library -EXTRA_LIBS += ${shell $(CC) $(ARCHCPUFLAGS) --print-libgcc-file-name} +EXTRA_LIBS += ${wildcard ${shell $(CC) $(ARCHCPUFLAGS) --print-libgcc-file-name}} ifneq ($(CONFIG_LIBM),y) EXTRA_LIBS += ${wildcard ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libm.a}} endif ifeq ($(CONFIG_LIBSUPCXX),y) - EXTRA_LIBS += ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libsupc++.a} + EXTRA_LIBS += ${wildcard ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libsupc++.a}} endif diff --git a/arch/arm/src/armv8-m/arm_exception.S b/arch/arm/src/armv8-m/arm_exception.S index aa8128022054e..042b3609aaab3 100644 --- a/arch/arm/src/armv8-m/arm_exception.S +++ b/arch/arm/src/armv8-m/arm_exception.S @@ -204,10 +204,6 @@ exception_common: mov r1, sp - /* Also save the top of the stack in a preserved register */ - - mov r4, sp - #if CONFIG_ARCH_INTERRUPTSTACK > 7 /* If CONFIG_ARCH_INTERRUPTSTACK is defined, we will set the MSP to use * a special special interrupt stack pointer. The way that this is done @@ -215,9 +211,12 @@ exception_common: */ setintstack r2, r3 /* SP = IRQ stack top */ - - bl arm_doirq /* R0=IRQ, R1=register save (msp) */ #else + /* Otherwise, we will re-use the interrupted thread's stack. That may + * mean using either MSP or PSP stack for interrupt level processing (in + * kernel mode). + */ + /* If the interrupt stack is disabled, reserve xcpcontext to ensure * that signal processing can have a separate xcpcontext to handle * signal context (reference: arm_schedulesigaction.c): @@ -229,85 +228,26 @@ exception_common: * also the sp should be restore after arm_doirq() */ - sub r4, r4, #XCPTCONTEXT_SIZE /* Reserve signal context */ - - /* Otherwise, we will re-use the interrupted thread's stack. That may - * mean using either MSP or PSP stack for interrupt level processing (in - * kernel mode). - */ - - bic r2, r4, #7 /* Get the stack pointer with 8-byte alignment */ + sub r2, r1, #XCPTCONTEXT_SIZE /* Reserve signal context */ + bic r2, r2, #7 /* Get the stack pointer with 8-byte alignment */ mov sp, r2 /* Instantiate the aligned stack */ - - bl arm_doirq /* R0=IRQ, R1=register save (msp) */ - - /* If the interrupt stack is disabled, restore the signal context */ - - add r4, r4, #XCPTCONTEXT_SIZE /* Restore signal context */ #endif - mov r1, r4 /* Recover R1=main stack pointer */ + bl arm_doirq /* R0=IRQ, R1=register save (msp) */ /* On return from arm_doirq, R0 will hold a pointer to register context - * array to use for the interrupt return. If that return value is the same - * as current stack pointer, then things are relatively easy. + * array to use for the interrupt return. */ - cmp r0, r1 /* Context switch? */ - beq 2f /* Branch if no context switch */ - - /* We are returning with a pending context switch. This case is different - * because in this case, the register save structure does not lie on the - * stack but, rather within a TCB structure. We'll have to copy some - * values to the stack. - */ - - /* Copy the hardware-saved context to the stack, and restore the software - * saved context directly. - * - * XXX In the normal case, it appears that this entire operation is unnecessary; - * context switch time would be improved if we could work out when the stack - * is dirty and avoid the work... - */ - - add r1, r0, #SW_XCPT_SIZE /* R1=Address of HW save area in reg array */ - ldmia r1!, {r4-r11} /* Fetch eight registers in HW save area */ -#ifdef CONFIG_ARCH_FPU - vldmia r1!, {s0-s15} /* Fetch sixteen FP registers in HW save area */ - ldmia r1, {r2-r3} /* Fetch FPSCR and Reserved in HW save area */ -#endif - ldr r1, [r0, #(4*REG_SP)] /* R1=Value of SP before interrupt */ -#ifdef CONFIG_ARCH_FPU - stmdb r1!, {r2-r3} /* Store FPSCR and Reserved on the return stack */ - vstmdb r1!, {s0-s15} /* Store sixteen FP registers on the return stack */ -#endif - stmdb r1!, {r4-r11} /* Store eight registers on the return stack */ ldmia r0!, {r2-r11,r14} /* Recover R4-R11, r14 + 2 temp values */ #ifdef CONFIG_ARCH_FPU vldmia r0!, {s16-s31} /* Recover S16-S31 */ #endif #ifdef CONFIG_ARMV8M_STACKCHECK_HARDWARE - ldmia r0, {r0} /* Get psplim/msplim */ + ldmia r0!, {r1} /* Get psplim/msplim */ #endif - b 3f /* Re-join common logic */ - -2: - /* We are returning with no context switch. We simply need to "unwind" - * the same stack frame that we created at entry. - */ - - ldmia r1!, {r2-r11,r14} /* Recover R4-R11, r14 + 2 temp values */ -#ifdef CONFIG_ARCH_FPU - vldmia r1!, {s16-s31} /* Recover S16-S31 */ -#endif - -#ifdef CONFIG_ARMV8M_STACKCHECK_HARDWARE - ldmia r1!, {r0} /* Get psplim/msplim */ -#endif - -3: /* The EXC_RETURN value tells us whether we are returning on the MSP or PSP */ @@ -319,33 +259,33 @@ exception_common: mrs r2, control /* R2=Contents of the control register */ tst r14, #EXC_RETURN_PROCESS_STACK /* nonzero if context on process stack */ - beq 4f /* Branch if privileged */ + beq 2f /* Branch if privileged */ orr r2, r2, #1 /* Unprivileged mode */ #ifdef CONFIG_ARMV8M_STACKCHECK_HARDWARE - msr psplim, r0 + msr psplim, r1 #endif - msr psp, r1 /* R1=The process stack pointer */ - b 5f -4: + msr psp, r0 /* R0=The process stack pointer */ + b 3f +2: bic r2, r2, #1 /* Privileged mode */ #ifdef CONFIG_ARMV8M_STACKCHECK_HARDWARE - msr msplim, r0 + msr msplim, r1 #endif - msr msp, r1 /* R1=The main stack pointer */ -5: + msr msp, r0 /* R0=The main stack pointer */ +3: msr control, r2 /* Save the updated control register */ #else tst r14, #EXC_RETURN_PROCESS_STACK /* nonzero if context on process stack */ #ifdef CONFIG_ARMV8M_STACKCHECK_HARDWARE itete eq - msreq msplim, r0 - msrne psplim, r0 + msreq msplim, r1 + msrne psplim, r1 #else ite eq /* Next two instructions conditional */ #endif - msreq msp, r1 /* R1=The main stack pointer */ - msrne psp, r1 /* R1=The process stack pointer */ + msreq msp, r0 /* R0=The main stack pointer */ + msrne psp, r0 /* R0=The process stack pointer */ #endif /* Restore the interrupt state */ diff --git a/arch/arm/src/armv8-m/arm_initialstate.c b/arch/arm/src/armv8-m/arm_initialstate.c index 3b2714b23dd45..bb92eb196931b 100644 --- a/arch/arm/src/armv8-m/arm_initialstate.c +++ b/arch/arm/src/armv8-m/arm_initialstate.c @@ -63,7 +63,7 @@ void up_initial_state(struct tcb_s *tcb) /* Initialize the idle thread stack */ - if (tcb->pid == 0) + if (tcb->pid == IDLE_PROCESS_ID) { tcb->stack_alloc_ptr = (void *)(g_idle_topstack - CONFIG_IDLETHREAD_STACKSIZE); diff --git a/arch/arm/src/armv8-m/arm_lazyexception.S b/arch/arm/src/armv8-m/arm_lazyexception.S index d70e2bd8af70b..cc9b994925a0c 100644 --- a/arch/arm/src/armv8-m/arm_lazyexception.S +++ b/arch/arm/src/armv8-m/arm_lazyexception.S @@ -210,9 +210,12 @@ exception_common: */ setintstack r2, r3 /* SP = IRQ stack top */ - - bl arm_doirq /* R0=IRQ, R1=register save (msp) */ #else + /* Otherwise, we will re-use the interrupted thread's stack. That may + * mean using either MSP or PSP stack for interrupt level processing (in + * kernel mode). + */ + /* If the interrupt stack is disabled, reserve xcpcontext to ensure * that signal processing can have a separate xcpcontext to handle * signal context (reference: arm_schedulesigaction.c): @@ -224,31 +227,18 @@ exception_common: * also the sp should be restore after arm_doirq() */ - sub r4, r4, #XCPTCONTEXT_SIZE /* Reserve signal context */ - - /* Otherwise, we will re-use the interrupted thread's stack. That may - * mean using either MSP or PSP stack for interrupt level processing (in - * kernel mode). - */ - - bic r2, r4, #7 /* Get the stack pointer with 8-byte alignment */ + sub r2, r4, #XCPTCONTEXT_SIZE /* Reserve signal context */ + bic r2, r2, #7 /* Get the stack pointer with 8-byte alignment */ mov sp, r2 /* Instantiate the aligned stack */ - - bl arm_doirq /* R0=IRQ, R1=register save (msp) */ - - /* If the interrupt stack is disabled, restore the signal context */ - - add r4, r4, #XCPTCONTEXT_SIZE /* Restore signal context */ #endif - mov r1, r4 /* Recover R1=main stack pointer */ + bl arm_doirq /* R0=IRQ, R1=register save (msp) */ /* On return from arm_doirq, R0 will hold a pointer to register context - * array to use for the interrupt return. If that return value is the same - * as current stack pointer, then things are relatively easy. + * array to use for the interrupt return. */ - cmp r0, r1 /* Context switch? */ + cmp r0, r4 /* Context switch? */ beq 2f /* Branch if no context switch */ /* We are returning with a pending context switch. @@ -270,63 +260,34 @@ exception_common: bl arm_restorefpu /* Restore the FPU registers */ #endif - /* We are returning with a pending context switch. This case is different - * because in this case, the register save structure does not lie in the - * stack but, rather, within a TCB structure. We'll have to copy some - * values to the stack. - */ - - add r1, r0, #SW_XCPT_SIZE /* R1=Address of HW save area in reg array */ - ldmia r1, {r4-r11} /* Fetch eight registers in HW save area */ - ldr r1, [r0, #(4*REG_SP)] /* R1=Value of SP before interrupt */ - stmdb r1!, {r4-r11} /* Store eight registers in HW save area */ +2: #ifdef CONFIG_BUILD_PROTECTED ldmia r0!, {r2-r11,r14} /* Recover R4-R11, r14 + 2 temp values */ #else ldmia r0!, {r2-r11} /* Recover R4-R11 + 2 temp values */ #endif -#ifdef CONFIG_ARMV8M_STACKCHECK_HARDWARE - ldmia r0, {r0} /* Get psplim/msplim*/ -#endif - b 3f /* Re-join common logic */ - - /* We are returning with no context switch. We simply need to "unwind" - * the same stack frame that we created - * - * Here: - * r1 = Address of the return stack (same as r0) - */ - -2: -#ifdef CONFIG_BUILD_PROTECTED - ldmia r1!, {r2-r11,r14} /* Recover R4-R11, r14 + 2 temp values */ -#else - ldmia r1!, {r2-r11} /* Recover R4-R11 + 2 temp values */ -#endif #ifdef CONFIG_ARCH_FPU /* Skip over the block of memory reserved for floating pointer register * save. Then R1 is the address of the HW save area */ - add r1, #(4*SW_FPU_REGS) + add r0, #(4*SW_FPU_REGS) #endif #ifdef CONFIG_ARMV8M_STACKCHECK_HARDWARE - ldmia r1!, {r0} /* Get psplim/msplim */ + ldmia r0!, {r1} /* Get psplim/msplim */ #endif /* Set up to return from the exception * * Here: - * r1 = Address on the target thread's stack position at the start of + * r0 = Address on the target thread's stack position at the start of * the registers saved by hardware * r3 = primask or basepri * r4-r11 = restored register values */ -3: - #ifdef CONFIG_BUILD_PROTECTED /* The EXC_RETURN value will be 0xfffffff9 (privileged thread) or 0xfffffff1 * (handler mode) if the stack is on the MSP. It can only be on the PSP if @@ -335,27 +296,27 @@ exception_common: mrs r2, control /* R2=Contents of the control register */ tst r14, #EXC_RETURN_PROCESS_STACK /* nonzero if context on process stack */ - beq 4f /* Branch if privileged */ + beq 3f /* Branch if privileged */ orr r2, r2, #1 /* Unprivileged mode */ #ifdef CONFIG_ARMV8M_STACKCHECK_HARDWARE - msr psplim, r0 + msr psplim, r1 #endif - msr psp, r1 /* R1=The process stack pointer */ - b 5f -4: + msr psp, r0 /* R1=The process stack pointer */ + b 4f +3: bic r2, r2, #1 /* Privileged mode */ #ifdef CONFIG_ARMV8M_STACKCHECK_HARDWARE - msr msplim, r0 + msr msplim, r1 #endif - msr msp, r1 /* R1=The main stack pointer */ -5: + msr msp, r0 /* R1=The main stack pointer */ +4: msr control, r2 /* Save the updated control register */ #else #ifdef CONFIG_ARMV8M_STACKCHECK_HARDWARE - msr msplim, r0 + msr msplim, r1 #endif - msr msp, r1 /* Recover the return MSP value */ + msr msp, r0 /* Recover the return MSP value */ /* Preload r14 with the special return value first (so that the return * actually occurs with interrupts still disabled). diff --git a/boards/arm/stm32/stm32f4discovery/src/stm32_perfcount.c b/arch/arm/src/armv8-m/arm_perf.c similarity index 69% rename from boards/arm/stm32/stm32f4discovery/src/stm32_perfcount.c rename to arch/arm/src/armv8-m/arm_perf.c index 8053b205e071b..0a981a4948653 100644 --- a/boards/arm/stm32/stm32f4discovery/src/stm32_perfcount.c +++ b/arch/arm/src/armv8-m/arm_perf.c @@ -1,5 +1,5 @@ /**************************************************************************** - * boards/arm/stm32/stm32f4discovery/src/stm32_perfcount.c + * arch/arm/src/armv8-m/arm_perf.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -22,49 +22,55 @@ * Included Files ****************************************************************************/ -#include - -#include -#include - -#include "dwt.h" -#include "arm_internal.h" - +#include #include -#include +#include "arm_internal.h" +#include "dwt.h" +#include "itm.h" +#include "nvic.h" /**************************************************************************** - * Public Functions + * Private Data ****************************************************************************/ +static uint32_t g_cpu_freq; + /**************************************************************************** - * Name: up_perf_gettime + * Public Functions ****************************************************************************/ -uint32_t up_perf_gettime(void) +void up_perf_init(FAR void *arg) { - return getreg32(DWT_CYCCNT); -} + g_cpu_freq = (uint32_t)(uintptr_t)arg; -/**************************************************************************** - * Name: up_perf_getfreq - ****************************************************************************/ + /* Enable ITM and DWT resources, if not left enabled by debugger. */ + + modifyreg32(NVIC_DEMCR, 0, NVIC_DEMCR_TRCENA); + + /* Make sure the high speed cycle counter is running. It will be started + * automatically only if a debugger is connected. + */ + + putreg32(0xc5acce55, ITM_LAR); + modifyreg32(DWT_CTRL, 0, DWT_CTRL_CYCCNTENA_MASK); +} uint32_t up_perf_getfreq(void) { - return STM32_SYSCLK_FREQUENCY; + return g_cpu_freq; } -/**************************************************************************** - * Name: up_perf_convert - ****************************************************************************/ +uint32_t up_perf_gettime(void) +{ + return getreg32(DWT_CYCCNT); +} void up_perf_convert(uint32_t elapsed, FAR struct timespec *ts) { - b32_t b32elapsed; + uint32_t left; - b32elapsed = itob32(elapsed) / STM32_SYSCLK_FREQUENCY; - ts->tv_sec = b32toi(b32elapsed); - ts->tv_nsec = NSEC_PER_SEC * b32frac(b32elapsed) / b32ONE; + ts->tv_sec = elapsed / g_cpu_freq; + left = elapsed - ts->tv_sec * g_cpu_freq; + ts->tv_nsec = NSEC_PER_SEC * (uint64_t)left / g_cpu_freq; } diff --git a/arch/arm/src/armv8-m/arm_schedulesigaction.c b/arch/arm/src/armv8-m/arm_schedulesigaction.c index 228efadd648ad..495aed85a5c9b 100644 --- a/arch/arm/src/armv8-m/arm_schedulesigaction.c +++ b/arch/arm/src/armv8-m/arm_schedulesigaction.c @@ -137,13 +137,14 @@ void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver) * delivered. */ - CURRENT_REGS = - (FAR void *)STACK_ALIGN_DOWN((uint32_t)CURRENT_REGS - - (uint32_t)XCPTCONTEXT_SIZE); + CURRENT_REGS = (FAR void *) + ((uint32_t)CURRENT_REGS - + (uint32_t)XCPTCONTEXT_SIZE); memcpy((FAR uint32_t *)CURRENT_REGS, tcb->xcp.saved_regs, XCPTCONTEXT_SIZE); - CURRENT_REGS[REG_SP] = (uint32_t)CURRENT_REGS; + CURRENT_REGS[REG_SP] = (uint32_t)CURRENT_REGS + + (uint32_t)XCPTCONTEXT_SIZE; /* Then set up to vector to the trampoline with interrupts * disabled. The kernel-space trampoline must run in @@ -187,12 +188,13 @@ void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver) * delivered. */ - tcb->xcp.regs = - (FAR void *)STACK_ALIGN_DOWN((uint32_t)tcb->xcp.regs - - (uint32_t)XCPTCONTEXT_SIZE); + tcb->xcp.regs = (FAR void *) + ((uint32_t)tcb->xcp.regs - + (uint32_t)XCPTCONTEXT_SIZE); memcpy(tcb->xcp.regs, tcb->xcp.saved_regs, XCPTCONTEXT_SIZE); - tcb->xcp.regs[REG_SP] = (uint32_t)tcb->xcp.regs; + tcb->xcp.regs[REG_SP] = (uint32_t)tcb->xcp.regs + + (uint32_t)XCPTCONTEXT_SIZE; /* Then set up to vector to the trampoline with interrupts * disabled. We must already be in privileged thread mode to be @@ -294,13 +296,14 @@ void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver) * been delivered. */ - tcb->xcp.regs = - (FAR void *)STACK_ALIGN_DOWN((uint32_t)tcb->xcp.regs - - (uint32_t)XCPTCONTEXT_SIZE); + tcb->xcp.regs = (FAR void *) + ((uint32_t)tcb->xcp.regs - + (uint32_t)XCPTCONTEXT_SIZE); memcpy(tcb->xcp.regs, tcb->xcp.saved_regs, XCPTCONTEXT_SIZE); - tcb->xcp.regs[REG_SP] = (uint32_t)tcb->xcp.regs; + tcb->xcp.regs[REG_SP] = (uint32_t)tcb->xcp.regs + + (uint32_t)XCPTCONTEXT_SIZE; /* Then set up vector to the trampoline with interrupts * disabled. We must already be in privileged thread mode @@ -341,13 +344,14 @@ void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver) * been delivered. */ - CURRENT_REGS = - (FAR void *)STACK_ALIGN_DOWN((uint32_t)CURRENT_REGS - - (uint32_t)XCPTCONTEXT_SIZE); + CURRENT_REGS = (FAR void *) + ((uint32_t)CURRENT_REGS - + (uint32_t)XCPTCONTEXT_SIZE); memcpy((FAR uint32_t *)CURRENT_REGS, tcb->xcp.saved_regs, XCPTCONTEXT_SIZE); - CURRENT_REGS[REG_SP] = (uint32_t)CURRENT_REGS; + CURRENT_REGS[REG_SP] = (uint32_t)CURRENT_REGS + + (uint32_t)XCPTCONTEXT_SIZE; /* Then set up vector to the trampoline with interrupts * disabled. The kernel-space trampoline must run in @@ -416,12 +420,13 @@ void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver) * delivered. */ - tcb->xcp.regs = - (FAR void *)STACK_ALIGN_DOWN((uint32_t)tcb->xcp.regs - - (uint32_t)XCPTCONTEXT_SIZE); + tcb->xcp.regs = (FAR void *) + ((uint32_t)tcb->xcp.regs - + (uint32_t)XCPTCONTEXT_SIZE); memcpy(tcb->xcp.regs, tcb->xcp.saved_regs, XCPTCONTEXT_SIZE); - tcb->xcp.regs[REG_SP] = (uint32_t)tcb->xcp.regs; + tcb->xcp.regs[REG_SP] = (uint32_t)tcb->xcp.regs + + (uint32_t)XCPTCONTEXT_SIZE; /* Increment the IRQ lock count so that when the task is restarted, * it will hold the IRQ spinlock. diff --git a/arch/arm/src/common/arm_assert.c b/arch/arm/src/common/arm_assert.c index e3da777c3a92e..ee6306170d175 100644 --- a/arch/arm/src/common/arm_assert.c +++ b/arch/arm/src/common/arm_assert.c @@ -165,6 +165,9 @@ static void arm_dump_task(FAR struct tcb_s *tcb, FAR void *arg) /* Dump interesting properties of this task */ _alert(" %4d %4d" +#ifdef CONFIG_SMP + " %4d" +#endif #ifdef CONFIG_STACK_COLORATION " %7lu" #endif @@ -180,6 +183,9 @@ static void arm_dump_task(FAR struct tcb_s *tcb, FAR void *arg) #endif "\n", tcb->pid, tcb->sched_priority, +#ifdef CONFIG_SMP + tcb->cpu, +#endif #ifdef CONFIG_STACK_COLORATION (unsigned long)up_check_tcbstack(tcb), #endif @@ -234,6 +240,9 @@ static void arm_showtasks(void) /* Dump interesting properties of each task in the crash environment */ _alert(" PID PRI" +#ifdef CONFIG_SMP + " CPU" +#endif #ifdef CONFIG_STACK_COLORATION " USED" #endif @@ -251,6 +260,9 @@ static void arm_showtasks(void) #if CONFIG_ARCH_INTERRUPTSTACK > 7 _alert(" ---- ----" +# ifdef CONFIG_SMP + " ----" +# endif # ifdef CONFIG_STACK_COLORATION " %7lu" # endif diff --git a/arch/arm/src/common/arm_vfork.c b/arch/arm/src/common/arm_vfork.c index f265aaf51bfbc..edad4cc2a4e58 100644 --- a/arch/arm/src/common/arm_vfork.c +++ b/arch/arm/src/common/arm_vfork.c @@ -137,10 +137,18 @@ pid_t up_vfork(const struct vfork_s *context) * effort is overkill. */ - newtop = STACK_ALIGN_DOWN((uint32_t)child->cmn.stack_base_ptr + - child->cmn.adj_stack_size - - XCPTCONTEXT_SIZE); + newtop = (uint32_t)child->cmn.stack_base_ptr + + child->cmn.adj_stack_size; + newsp = newtop - stackutil; + + /* Move the register context to newtop. */ + + memcpy((void *)(newsp - XCPTCONTEXT_SIZE), + child->cmn.xcp.regs, XCPTCONTEXT_SIZE); + + child->cmn.xcp.regs = (void *)(newsp - XCPTCONTEXT_SIZE); + memcpy((void *)newsp, (const void *)context->sp, stackutil); /* Was there a frame pointer in place before? */ diff --git a/arch/arm/src/cxd56xx/cxd56_cpu1signal.c b/arch/arm/src/cxd56xx/cxd56_cpu1signal.c index 1dcccc60e47bf..d7b70a09c9297 100644 --- a/arch/arm/src/cxd56xx/cxd56_cpu1signal.c +++ b/arch/arm/src/cxd56xx/cxd56_cpu1signal.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -59,7 +60,7 @@ struct cxd56_sigtype_s struct cxd56cpu1_info_s { - int workerpid; + pid_t workerpid; int ndev; struct cxd56_sigtype_s sigtype[CXD56_CPU1_DATA_TYPE_MAX]; }; @@ -70,7 +71,11 @@ struct cxd56cpu1_info_s static struct cxd56cpu1_info_s g_cpu1_info = { - 0 + INVALID_PROCESS_ID, + 0, + { + 0 + } }; /**************************************************************************** @@ -193,9 +198,9 @@ int cxd56_cpu1siginit(uint8_t sigtype, FAR void *data) } pid = kthread_create("gnss_receiver", - CONFIG_CXD56CPU1_WORKER_THREAD_PRIORITY, - CONFIG_CXD56CPU1_WORKER_STACKSIZE, cxd56cpu1_worker, - (FAR char * const *) NULL); + CONFIG_CXD56CPU1_WORKER_THREAD_PRIORITY, + CONFIG_CXD56CPU1_WORKER_STACKSIZE, cxd56cpu1_worker, + (FAR char * const *) NULL); if (pid < 0) { @@ -221,7 +226,7 @@ int cxd56_cpu1siginit(uint8_t sigtype, FAR void *data) int cxd56_cpu1siguninit(uint8_t sigtype) { struct cxd56cpu1_info_s *priv = &g_cpu1_info; - int pid; + pid_t pid; int ret; if (sigtype >= CXD56_CPU1_DATA_TYPE_MAX) @@ -249,7 +254,7 @@ int cxd56_cpu1siguninit(uint8_t sigtype) } pid = priv->workerpid; - priv->workerpid = 0; + priv->workerpid = INVALID_PROCESS_ID; sched_unlock(); diff --git a/arch/arm/src/cxd56xx/cxd56_gnss.c b/arch/arm/src/cxd56xx/cxd56_gnss.c index eadea751211a9..ade0ec24d4bd6 100644 --- a/arch/arm/src/cxd56xx/cxd56_gnss.c +++ b/arch/arm/src/cxd56xx/cxd56_gnss.c @@ -135,7 +135,7 @@ extern int fw_pm_sleepcpu(int cpuid, int mode); struct cxd56_gnss_sig_s { uint8_t enable; - int pid; + pid_t pid; FAR struct cxd56_gnss_signal_info_s info; }; @@ -1466,7 +1466,7 @@ static int cxd56_gnss_set_signal(FAR struct file *filep, unsigned long arg) FAR struct cxd56_gnss_signal_setting_s *setting; FAR struct cxd56_gnss_sig_s *sig; FAR struct cxd56_gnss_sig_s *checksig; - int pid; + pid_t pid; int i; if (!arg) diff --git a/arch/arm/src/cxd56xx/cxd56_icc.c b/arch/arm/src/cxd56xx/cxd56_icc.c index 7f4f9c7843668..b2c2c5ed0f0e5 100644 --- a/arch/arm/src/cxd56xx/cxd56_icc.c +++ b/arch/arm/src/cxd56xx/cxd56_icc.c @@ -116,7 +116,7 @@ struct iccdev_s /* for POSIX signal */ int signo; - int pid; + pid_t pid; FAR void *sigdata; struct sq_queue_s recvq; diff --git a/arch/arm/src/cxd56xx/cxd56_scu.c b/arch/arm/src/cxd56xx/cxd56_scu.c index 52cf197b8dbfb..f84e7a4cb04a4 100644 --- a/arch/arm/src/cxd56xx/cxd56_scu.c +++ b/arch/arm/src/cxd56xx/cxd56_scu.c @@ -113,7 +113,7 @@ struct ev_notify_s { int signo; /* Signal number */ - int pid; /* Target PID */ + pid_t pid; /* Target PID */ struct scuev_arg_s *arg; /* Event argument */ struct scufifo_s *fifo; /* Reverse reference to FIFO */ }; @@ -121,7 +121,7 @@ struct ev_notify_s struct wm_notify_s { int signo; /* Signal number */ - int pid; /* Target PID */ + pid_t pid; /* Target PID */ struct scutimestamp_s *ts; /* Event argument */ struct scufifo_s *fifo; /* Reverse reference to FIFO */ }; diff --git a/arch/arm/src/cxd56xx/cxd56_usbdev.c b/arch/arm/src/cxd56xx/cxd56_usbdev.c index c78f35ab6744d..9ca79ad7525e1 100644 --- a/arch/arm/src/cxd56xx/cxd56_usbdev.c +++ b/arch/arm/src/cxd56xx/cxd56_usbdev.c @@ -380,7 +380,7 @@ struct cxd56_usbdev_s /* signal */ int signo; - int pid; + pid_t pid; }; /* For maintaining tables of endpoint info */ diff --git a/arch/arm/src/efm32/efm32_flash.c b/arch/arm/src/efm32/efm32_flash.c index e042ac36ff834..6c689728b7481 100644 --- a/arch/arm/src/efm32/efm32_flash.c +++ b/arch/arm/src/efm32/efm32_flash.c @@ -88,7 +88,7 @@ /* Only for the EFM32 family for now */ -#if (defined(CONFIG_ARCH_CHIP_EFM32) && defined(CONFIG_EFM32_FLASHPROG)) +#if defined(CONFIG_ARCH_CHIP_EFM32) && defined(CONFIG_EFM32_FLASHPROG) /**************************************************************************** * Pre-processor Definitions @@ -114,6 +114,8 @@ # define EFM32_USERDATA_PAGESIZE (EFM32_USERDATA_SIZE/EFM32_USERDATA_NPAGES) #endif +#define EFM32_FLASH_ERASEDVAL (0xffu) + /* brief: * The timeout used while waiting for the flash to become ready after * a write. This number indicates the number of iterations to perform @@ -749,7 +751,7 @@ ssize_t up_progmem_ispageerased(size_t page) count = up_progmem_pagesize(page); count; count--, addr++) { - if (getreg8(addr) != 0xff) + if (getreg8(addr) != EFM32_FLASH_ERASEDVAL) { bwritten++; } @@ -880,4 +882,9 @@ ssize_t __ramfunc__ up_progmem_write(size_t addr, return word_count; } +uint8_t up_progmem_erasestate(void) +{ + return EFM32_FLASH_ERASEDVAL; +} + #endif /* defined(CONFIG_ARCH_CHIP_EFM32) */ diff --git a/arch/arm/src/lpc17xx_40xx/lpc17_40_progmem.c b/arch/arm/src/lpc17xx_40xx/lpc17_40_progmem.c index 7ad7930248705..e83a248944d5b 100644 --- a/arch/arm/src/lpc17xx_40xx/lpc17_40_progmem.c +++ b/arch/arm/src/lpc17xx_40xx/lpc17_40_progmem.c @@ -382,7 +382,7 @@ ssize_t up_progmem_ispageerased(size_t page) for (i = 0; i < page_size; i++) { - if (p[i] != 0xffu) + if (p[i] != LPC17_40_FLASH_ERASEDVAL) { break; } @@ -454,3 +454,16 @@ ssize_t up_progmem_write(size_t addr, FAR const void *buf, size_t count) return count; } + +/**************************************************************************** + * Name: up_progmem_erasestate + * + * Description: + * Return value of erase state. + * + ****************************************************************************/ + +uint8_t up_progmem_erasestate(void) +{ + return LPC17_40_FLASH_ERASEDVAL; +} diff --git a/arch/arm/src/lpc17xx_40xx/lpc17_40_progmem.h b/arch/arm/src/lpc17xx_40xx/lpc17_40_progmem.h index 18f766df67fff..6f7b544dabac6 100644 --- a/arch/arm/src/lpc17xx_40xx/lpc17_40_progmem.h +++ b/arch/arm/src/lpc17xx_40xx/lpc17_40_progmem.h @@ -53,6 +53,10 @@ #define LPC17_40_FLASH_NUM_SECTORS \ (LPC17_40_FLASH_NUM_4K_SECTORS + LPC17_40_FLASH_NUM_32K_SECTORS) +/* Flash erased byte value */ + +#define LPC17_40_FLASH_ERASEDVAL (0xffu) + /* Size of a write page. */ #define LPC17_40_WRITE_SIZE 256 diff --git a/arch/arm/src/nrf52/nrf52_flash.c b/arch/arm/src/nrf52/nrf52_flash.c index eddcec0f63ce0..e8f6ef312729d 100644 --- a/arch/arm/src/nrf52/nrf52_flash.c +++ b/arch/arm/src/nrf52/nrf52_flash.c @@ -63,6 +63,8 @@ #define NRF52_FLASH_PAGE_SIZE (4*1024) +#define NRF52_FLASH_ERASEDVAL (0xffu) + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -269,7 +271,7 @@ ssize_t up_progmem_ispageerased(size_t page) for (addr = up_progmem_getaddress(page), count = up_progmem_pagesize(page); count; count--, addr++) { - if (getreg8(addr) != 0xff) + if (getreg8(addr) != NRF52_FLASH_ERASEDVAL) { bwritten++; } @@ -342,3 +344,16 @@ ssize_t up_progmem_write(size_t addr, const void *buf, size_t count) return written; } + +/**************************************************************************** + * Name: up_progmem_erasestate + * + * Description: + * Return value of erase state. + * + ****************************************************************************/ + +uint8_t up_progmem_erasestate(void) +{ + return NRF52_FLASH_ERASEDVAL; +} diff --git a/arch/arm/src/rtl8720c/amebaz_depend.c b/arch/arm/src/rtl8720c/amebaz_depend.c index 0432baca31d40..9143cee8af336 100644 --- a/arch/arm/src/rtl8720c/amebaz_depend.c +++ b/arch/arm/src/rtl8720c/amebaz_depend.c @@ -661,7 +661,7 @@ int rtw_create_task(struct task_struct *task, const char *name, return pid; } - wrap->pid = pid; + wrap->pid = (pid_t)pid; return 1; } diff --git a/arch/arm/src/rtl8720c/amebaz_depend.h b/arch/arm/src/rtl8720c/amebaz_depend.h index dac328feb12a3..d3d9794ad2470 100644 --- a/arch/arm/src/rtl8720c/amebaz_depend.h +++ b/arch/arm/src/rtl8720c/amebaz_depend.h @@ -66,7 +66,7 @@ struct task_struct }; struct nthread_wrapper { - int pid; + pid_t pid; thread_func_t func; void *thctx; }; diff --git a/arch/arm/src/s32k1xx/s32k1xx_progmem.c b/arch/arm/src/s32k1xx/s32k1xx_progmem.c index ef90f118043e6..239ad59efe652 100644 --- a/arch/arm/src/s32k1xx/s32k1xx_progmem.c +++ b/arch/arm/src/s32k1xx/s32k1xx_progmem.c @@ -50,13 +50,13 @@ union fccob_flash_addr { - uint32_t addr; - struct + uint32_t addr; + struct { - uint8_t fccob3; - uint8_t fccob2; - uint8_t fccob1; - uint8_t pad; + uint8_t fccob3; + uint8_t fccob2; + uint8_t fccob1; + uint8_t pad; } fccobs; }; @@ -64,7 +64,7 @@ union fccob_flash_addr * Private Functions ****************************************************************************/ -static inline void wait_ftfc_ready() +static inline void wait_ftfc_ready(void) { while ((getreg8(S32K1XX_FTFC_FSTAT) & FTTC_FSTAT_CCIF) == 0) { @@ -72,7 +72,7 @@ static inline void wait_ftfc_ready() } } -static uint32_t execute_ftfc_command() +static uint32_t execute_ftfc_command(void) { uint8_t regval; uint32_t retval; @@ -288,7 +288,7 @@ ssize_t up_progmem_ispageerased(size_t page) for (i = 0; i < S32K1XX_PROGMEM_PAGE_SIZE; i++) { - if (p[i] != 0xff) + if (p[i] != S32K1XX_PROGMEM_ERASEDVAL) { break; } @@ -387,7 +387,20 @@ ssize_t up_progmem_write(size_t addr, FAR const void *buf, size_t count) return count; } -void s32k1xx_progmem_init() +/**************************************************************************** + * Name: up_progmem_erasestate + * + * Description: + * Return value of erase state. + * + ****************************************************************************/ + +uint8_t up_progmem_erasestate(void) +{ + return S32K1XX_PROGMEM_ERASEDVAL; +} + +void s32k1xx_progmem_init(void) { /* Disable D-Flash Cache */ diff --git a/arch/arm/src/s32k1xx/s32k1xx_progmem.h b/arch/arm/src/s32k1xx/s32k1xx_progmem.h index 09bfe9de919e1..3222cf1bcd50d 100644 --- a/arch/arm/src/s32k1xx/s32k1xx_progmem.h +++ b/arch/arm/src/s32k1xx/s32k1xx_progmem.h @@ -71,10 +71,12 @@ #define S32K1XX_PROGMEM_DFLASH_WRITE_UNIT_SIZE 8 +#define S32K1XX_PROGMEM_ERASEDVAL (0xffu) + /**************************************************************************** * Public Function Prototypes ****************************************************************************/ -void s32k1xx_progmem_init(); +void s32k1xx_progmem_init(void); #endif /* __ARCH_ARM_SRC_S32K1XX_S32K1XX_PROGMEM_H */ diff --git a/arch/arm/src/samd5e5/sam_progmem.c b/arch/arm/src/samd5e5/sam_progmem.c index 7a03c18440bba..e3f612d770186 100644 --- a/arch/arm/src/samd5e5/sam_progmem.c +++ b/arch/arm/src/samd5e5/sam_progmem.c @@ -137,6 +137,8 @@ #define SAMD5E5_PROGMEM_ENDSEC (SAMD5E5_TOTAL_NSECTORS) #define SAMD5E5_PROGMEM_STARTSEC (SAMD5E5_PROGMEM_ENDSEC - CONFIG_SAMD5E5_PROGMEM_NSECTORS) +#define SAMD5E5_PROGMEM_ERASEDVAL (0xffu) + /* Misc stuff */ #ifndef MIN @@ -608,7 +610,7 @@ ssize_t up_progmem_ispageerased(size_t cluster) nleft > 0; nleft--, address++) { - if (getreg8(address) != 0xff) + if (getreg8(address) != SAMD5E5_PROGMEM_ERASEDVAL) { nwritten++; } @@ -866,6 +868,19 @@ ssize_t up_progmem_write(size_t address, const void *buffer, size_t buflen) return written; } +/**************************************************************************** + * Name: up_progmem_erasestate + * + * Description: + * Return value of erase state. + * + ****************************************************************************/ + +uint8_t up_progmem_erasestate(void) +{ + return SAMD5E5_PROGMEM_ERASEDVAL; +} + /**************************************************************************** * The NVM User Row contains calibration data that are * automatically read at device power on. diff --git a/arch/arm/src/samv7/Kconfig b/arch/arm/src/samv7/Kconfig index 5e81a095b4f08..0b29d2cffb11d 100644 --- a/arch/arm/src/samv7/Kconfig +++ b/arch/arm/src/samv7/Kconfig @@ -1046,13 +1046,6 @@ config SAMV7_PROGMEM_NSECTORS flash memory that will be reserved for use with by the interfaces prototyped in include/nuttx/progmem.h -config SAMV7_PROGMEM_ERASESTATE - bool "Flash progmem erasestate ioctl support" - default y - select ARCH_HAVE_PROGMEM_ERASESTATE - ---help--- - Add progmem erasestate ioctl command. - endif # SAMV7_PROGMEM menu "SDRAM Configuration" diff --git a/arch/arm/src/samv7/sam_progmem.c b/arch/arm/src/samv7/sam_progmem.c index 46df88796f287..c8f52ed60e45e 100644 --- a/arch/arm/src/samv7/sam_progmem.c +++ b/arch/arm/src/samv7/sam_progmem.c @@ -136,7 +136,7 @@ #define SAMV7_PROGMEM_ENDSEC (SAMV7_TOTAL_NSECTORS) #define SAMV7_PROGMEM_STARTSEC (SAMV7_PROGMEM_ENDSEC - CONFIG_SAMV7_PROGMEM_NSECTORS) -#define SAMV7_PROGMEM_ERASEDVAL (0xff) +#define SAMV7_PROGMEM_ERASEDVAL (0xffu) /* Misc stuff */ @@ -622,7 +622,7 @@ ssize_t up_progmem_write(size_t address, const void *buffer, size_t buflen) * ****************************************************************************/ -ssize_t up_progmem_erasestate(void) +uint8_t up_progmem_erasestate(void) { return SAMV7_PROGMEM_ERASEDVAL; } diff --git a/arch/arm/src/stm32/stm32f10xxf30xx_flash.c b/arch/arm/src/stm32/stm32f10xxf30xx_flash.c index d2e3618df8a14..794ac7efb3044 100644 --- a/arch/arm/src/stm32/stm32f10xxf30xx_flash.c +++ b/arch/arm/src/stm32/stm32f10xxf30xx_flash.c @@ -55,7 +55,7 @@ #define FLASH_KEY2 0xcdef89ab #define FLASH_OPTKEY1 0x08192a3b #define FLASH_OPTKEY2 0x4c5d6e7f -#define FLASH_ERASEDVALUE 0xff +#define FLASH_ERASEDVALUE 0xffu #if defined(STM32_FLASH_DUAL_BANK) /* Bank 0 is 512Kb; Bank 1 is up to 512Kb */ @@ -385,4 +385,9 @@ ssize_t up_progmem_write(size_t addr, const void *buf, size_t count) return written; } +uint8_t up_progmem_erasestate(void) +{ + return FLASH_ERASEDVALUE; +} + #endif /* defined(CONFIG_STM32_STM32F10XX) || defined(CONFIG_STM32_STM32F30XX) */ diff --git a/arch/arm/src/stm32/stm32f20xxf40xx_flash.c b/arch/arm/src/stm32/stm32f20xxf40xx_flash.c index fd1b0cd98da1d..fa781ffc30e23 100644 --- a/arch/arm/src/stm32/stm32f20xxf40xx_flash.c +++ b/arch/arm/src/stm32/stm32f20xxf40xx_flash.c @@ -452,4 +452,9 @@ ssize_t up_progmem_write(size_t addr, const void *buf, size_t count) return written; } +uint8_t up_progmem_erasestate(void) +{ + return FLASH_ERASEDVALUE; +} + #endif /* defined(CONFIG_STM32_STM32F20XX) || defined(CONFIG_STM32_STM32F4XXX) */ diff --git a/arch/arm/src/stm32/stm32l15xx_flash.c b/arch/arm/src/stm32/stm32l15xx_flash.c index cfb0ed640e0f3..269efb16e649d 100644 --- a/arch/arm/src/stm32/stm32l15xx_flash.c +++ b/arch/arm/src/stm32/stm32l15xx_flash.c @@ -557,4 +557,10 @@ ssize_t up_progmem_write(size_t addr, const void *buf, size_t count) sem_unlock(); return (ret == OK) ? written : ret; } + +uint8_t up_progmem_erasestate(void) +{ + return FLASH_ERASEDVALUE; +} + #endif /* defined(CONFIG_STM32_STM32L15XX) */ diff --git a/arch/arm/src/stm32f7/stm32_flash.c b/arch/arm/src/stm32f7/stm32_flash.c index efa82129aa142..36886d9f03dd3 100644 --- a/arch/arm/src/stm32f7/stm32_flash.c +++ b/arch/arm/src/stm32f7/stm32_flash.c @@ -455,3 +455,8 @@ ssize_t up_progmem_write(size_t addr, const void *buf, size_t count) sem_unlock(); return written; } + +uint8_t up_progmem_erasestate(void) +{ + return FLASH_ERASEDVALUE; +} diff --git a/arch/arm/src/stm32h7/Kconfig b/arch/arm/src/stm32h7/Kconfig index 1dad0d0a6c7a1..804586bfb259e 100644 --- a/arch/arm/src/stm32h7/Kconfig +++ b/arch/arm/src/stm32h7/Kconfig @@ -332,14 +332,6 @@ config STM32H7_PROGMEM Add progmem support, start block and end block options are provided to obtain an uniform flash memory mapping. -config STM32H7_PROGMEM_ERASESTATE - bool "Flash progmem erasestate ioctl support" - depends on STM32H7_PROGMEM - default y - select ARCH_HAVE_PROGMEM_ERASESTATE - ---help--- - Add progmem erasestate ioctl command. - menu "STM32H7 Peripheral Selection" # These "hidden" settings determine whether a peripheral option is available @@ -1846,6 +1838,27 @@ config STM32H7_DMACAPABLE_ASSUME_CACHE_ALIGNED menu "Timer Configuration" +if SCHED_TICKLESS + +config STM32H7_TICKLESS_TIMER + int "Tickless hardware timer" + default 2 + range 1 17 + ---help--- + If the Tickless OS feature is enabled, then one clock must be + assigned to provided the timer needed by the OS. + +config STM32H7_TICKLESS_CHANNEL + int "Tickless timer channel" + default 1 + range 1 4 + ---help--- + If the Tickless OS feature is enabled, the one clock must be + assigned to provided the free-running timer needed by the OS + and one channel on that clock is needed to handle intervals. + +endif # SCHED_TICKLESS + config STM32H7_ONESHOT bool "TIM one-shot wrapper" default n diff --git a/arch/arm/src/stm32h7/Make.defs b/arch/arm/src/stm32h7/Make.defs index 38aa9716386b8..2092016cbe068 100644 --- a/arch/arm/src/stm32h7/Make.defs +++ b/arch/arm/src/stm32h7/Make.defs @@ -36,6 +36,10 @@ CMN_CSRCS += arm_systemreset.c arm_trigger_irq.c arm_udelay.c arm_unblocktask.c CMN_CSRCS += arm_usestack.c arm_vfork.c arm_switchcontext.c arm_puts.c CMN_CSRCS += arm_tcbinfo.c +ifeq ($(CONFIG_ARMV7M_SYSTICK),y) +CMN_CSRCS += arm_systick.c +endif + # Configuration-dependent common files ifeq ($(CONFIG_ARMV7M_STACKCHECK),y) @@ -86,7 +90,9 @@ CHIP_CSRCS = stm32_allocateheap.c stm32_exti_gpio.c stm32_gpio.c stm32_irq.c CHIP_CSRCS += stm32_start.c stm32_rcc.c stm32_lowputc.c stm32_serial.c CHIP_CSRCS += stm32_uid.c -ifneq ($(CONFIG_SCHED_TICKLESS),y) +ifeq ($(CONFIG_SCHED_TICKLESS),y) +CHIP_CSRCS += stm32_tickless.c +else CHIP_CSRCS += stm32_timerisr.c endif diff --git a/arch/arm/src/stm32h7/hardware/stm32_tim.h b/arch/arm/src/stm32h7/hardware/stm32_tim.h index 51cf921f11204..a33bd09664201 100644 --- a/arch/arm/src/stm32h7/hardware/stm32_tim.h +++ b/arch/arm/src/stm32h7/hardware/stm32_tim.h @@ -700,25 +700,26 @@ /* Capture/compare enable register */ -#define ATIM_CCER_CC1E (1 << 0) /* Bit 0: Capture/Compare 1 output enable */ -#define ATIM_CCER_CC1P (1 << 1) /* Bit 1: Capture/Compare 1 output Polarity */ -#define ATIM_CCER_CC1NE (1 << 2) /* Bit 2: Capture/Compare 1 Complementary output enable */ -#define ATIM_CCER_CC1NP (1 << 3) /* Bit 3: Capture/Compare 1 Complementary output polarity */ -#define ATIM_CCER_CC2E (1 << 4) /* Bit 4: Capture/Compare 2 output enable */ -#define ATIM_CCER_CC2P (1 << 5) /* Bit 5: Capture/Compare 2 output Polarity */ -#define ATIM_CCER_CC2NE (1 << 6) /* Bit 6: Capture/Compare 2 Complementary output enable */ -#define ATIM_CCER_CC2NP (1 << 7) /* Bit 7: Capture/Compare 2 Complementary output polarity */ -#define ATIM_CCER_CC3E (1 << 8) /* Bit 8: Capture/Compare 3 output enable */ -#define ATIM_CCER_CC3P (1 << 9) /* Bit 9: Capture/Compare 3 output Polarity */ -#define ATIM_CCER_CC3NE (1 << 10) /* Bit 10: Capture/Compare 3 Complementary output enable */ -#define ATIM_CCER_CC3NP (1 << 11) /* Bit 11: Capture/Compare 3 Complementary output polarity */ -#define ATIM_CCER_CC4E (1 << 12) /* Bit 12: Capture/Compare 4 output enable */ -#define ATIM_CCER_CC4P (1 << 13) /* Bit 13: Capture/Compare 4 output Polarity */ -#define ATIM_CCER_CC4NP (1 << 15) /* Bit 15: Capture/Compare 4 Complementary output polarity */ -#define ATIM_CCER_CC5E (1 << 16) /* Bit 16: Capture/Compare 5 output enable */ -#define ATIM_CCER_CC5P (1 << 17) /* Bit 17: Capture/Compare 5 output Polarity */ -#define ATIM_CCER_CC6E (1 << 20) /* Bit 20: Capture/Compare 6 output enable */ -#define ATIM_CCER_CC6P (1 << 21) /* Bit 21: Capture/Compare 6 output Polarity */ +#define ATIM_CCER_CC1E (1 << 0) /* Bit 0: Capture/Compare 1 output enable */ +#define ATIM_CCER_CC1P (1 << 1) /* Bit 1: Capture/Compare 1 output Polarity */ +#define ATIM_CCER_CC1NE (1 << 2) /* Bit 2: Capture/Compare 1 Complementary output enable */ +#define ATIM_CCER_CC1NP (1 << 3) /* Bit 3: Capture/Compare 1 Complementary output polarity */ +#define ATIM_CCER_CC2E (1 << 4) /* Bit 4: Capture/Compare 2 output enable */ +#define ATIM_CCER_CC2P (1 << 5) /* Bit 5: Capture/Compare 2 output Polarity */ +#define ATIM_CCER_CC2NE (1 << 6) /* Bit 6: Capture/Compare 2 Complementary output enable */ +#define ATIM_CCER_CC2NP (1 << 7) /* Bit 7: Capture/Compare 2 Complementary output polarity */ +#define ATIM_CCER_CC3E (1 << 8) /* Bit 8: Capture/Compare 3 output enable */ +#define ATIM_CCER_CC3P (1 << 9) /* Bit 9: Capture/Compare 3 output Polarity */ +#define ATIM_CCER_CC3NE (1 << 10) /* Bit 10: Capture/Compare 3 Complementary output enable */ +#define ATIM_CCER_CC3NP (1 << 11) /* Bit 11: Capture/Compare 3 Complementary output polarity */ +#define ATIM_CCER_CC4E (1 << 12) /* Bit 12: Capture/Compare 4 output enable */ +#define ATIM_CCER_CC4P (1 << 13) /* Bit 13: Capture/Compare 4 output Polarity */ +#define ATIM_CCER_CC4NP (1 << 15) /* Bit 15: Capture/Compare 4 Complementary output polarity */ +#define ATIM_CCER_CC5E (1 << 16) /* Bit 16: Capture/Compare 5 output enable */ +#define ATIM_CCER_CC5P (1 << 17) /* Bit 17: Capture/Compare 5 output Polarity */ +#define ATIM_CCER_CC6E (1 << 20) /* Bit 20: Capture/Compare 6 output enable */ +#define ATIM_CCER_CC6P (1 << 21) /* Bit 21: Capture/Compare 6 output Polarity */ +#define ATIM_CCER_CCXBASE(ch) ((ch) << 2) /* Each channel uses 4-bits */ /* 16-bit counter register */ @@ -1096,21 +1097,22 @@ /* Capture/compare enable register (TIM1 and TIM8, TIM2-5 and TIM9-14) */ -#define GTIM_CCER_CC1E (1 << 0) /* Bit 0: Capture/Compare 1 output enable */ -#define GTIM_CCER_CC1P (1 << 1) /* Bit 1: Capture/Compare 1 output polarity */ -#define GTIM_CCER_CC1NE (1 << 2) /* Bit 2: Capture/Compare 1 complementary output enable (TIM1 and TIM8 only) */ -#define GTIM_CCER_CC1NP (1 << 3) /* Bit 3: Capture/Compare 1 output Polarity (F2,F3,F4 and TIM15-17) */ -#define GTIM_CCER_CC2E (1 << 4) /* Bit 4: Capture/Compare 2 output enable (TIM2-5,9&12 only) */ -#define GTIM_CCER_CC2P (1 << 5) /* Bit 5: Capture/Compare 2 output polarity (TIM2-5,9&12 only) */ -#define GTIM_CCER_CC2NE (1 << 6) /* Bit 6: Capture/Compare 2 complementary output enable (TIM1 and TIM8 only) */ -#define GTIM_CCER_CC2NP (1 << 7) /* Bit 7: Capture/Compare 2 output Polarity (F2,F3,F4 and TIM2-5,9,12&15 only) */ -#define GTIM_CCER_CC3E (1 << 8) /* Bit 8: Capture/Compare 3 output enable (TIM2-5 only) */ -#define GTIM_CCER_CC3P (1 << 9) /* Bit 9: Capture/Compare 3 output Polarity (TIM2-5 only) */ -#define GTIM_CCER_CC3NE (1 << 10) /* Bit 10: Capture/Compare 3 complementary output enable (TIM1 and TIM8 only) */ -#define GTIM_CCER_CC3NP (1 << 11) /* Bit 11: Capture/Compare 3 output Polarity (F2,F4 and TIM2-5 only) */ -#define GTIM_CCER_CC4E (1 << 12) /* Bit 12: Capture/Compare 4 output enable (TIM2-5 only) */ -#define GTIM_CCER_CC4P (1 << 13) /* Bit 13: Capture/Compare 4 output Polarity (TIM2-5 only) */ -#define GTIM_CCER_CC4NP (1 << 15) /* Bit 15: Capture/Compare 4 output Polarity */ +#define GTIM_CCER_CC1E (1 << 0) /* Bit 0: Capture/Compare 1 output enable */ +#define GTIM_CCER_CC1P (1 << 1) /* Bit 1: Capture/Compare 1 output polarity */ +#define GTIM_CCER_CC1NE (1 << 2) /* Bit 2: Capture/Compare 1 complementary output enable (TIM1 and TIM8 only) */ +#define GTIM_CCER_CC1NP (1 << 3) /* Bit 3: Capture/Compare 1 output Polarity (F2,F3,F4 and TIM15-17) */ +#define GTIM_CCER_CC2E (1 << 4) /* Bit 4: Capture/Compare 2 output enable (TIM2-5,9&12 only) */ +#define GTIM_CCER_CC2P (1 << 5) /* Bit 5: Capture/Compare 2 output polarity (TIM2-5,9&12 only) */ +#define GTIM_CCER_CC2NE (1 << 6) /* Bit 6: Capture/Compare 2 complementary output enable (TIM1 and TIM8 only) */ +#define GTIM_CCER_CC2NP (1 << 7) /* Bit 7: Capture/Compare 2 output Polarity (F2,F3,F4 and TIM2-5,9,12&15 only) */ +#define GTIM_CCER_CC3E (1 << 8) /* Bit 8: Capture/Compare 3 output enable (TIM2-5 only) */ +#define GTIM_CCER_CC3P (1 << 9) /* Bit 9: Capture/Compare 3 output Polarity (TIM2-5 only) */ +#define GTIM_CCER_CC3NE (1 << 10) /* Bit 10: Capture/Compare 3 complementary output enable (TIM1 and TIM8 only) */ +#define GTIM_CCER_CC3NP (1 << 11) /* Bit 11: Capture/Compare 3 output Polarity (F2,F4 and TIM2-5 only) */ +#define GTIM_CCER_CC4E (1 << 12) /* Bit 12: Capture/Compare 4 output enable (TIM2-5 only) */ +#define GTIM_CCER_CC4P (1 << 13) /* Bit 13: Capture/Compare 4 output Polarity (TIM2-5 only) */ +#define GTIM_CCER_CC4NP (1 << 15) /* Bit 15: Capture/Compare 4 output Polarity */ +#define GTIM_CCER_CCXBASE(ch) ((ch) << 2) /* Each channel uses 4-bits */ /* 16-bit counter register */ diff --git a/arch/arm/src/stm32h7/hardware/stm32h7xxx_dbgmcu.h b/arch/arm/src/stm32h7/hardware/stm32h7xxx_dbgmcu.h index 177b4610a6cc1..77515b33523e9 100644 --- a/arch/arm/src/stm32h7/hardware/stm32h7xxx_dbgmcu.h +++ b/arch/arm/src/stm32h7/hardware/stm32h7xxx_dbgmcu.h @@ -105,7 +105,6 @@ #define DBGMCU_APB2Z1_TIM15STOP (1 << 16) /* Bit 16: TIM15 stopped when halted */ #define DBGMCU_APB2Z1_TIM16STOP (1 << 17) /* Bit 17: TIM16 stopped when halted */ #define DBGMCU_APB2Z1_TIM17STOP (1 << 18) /* Bit 18: TIM17 stopped when halted */ -#define DBGMCU_APB2Z1_TIM17STOP (1 << 18) /* Bit 18: TIM17 stopped when halted */ #define DBGMCU_APB2Z1_HRTIMSTOP (1 << 29) /* Bit 29: HRTIM stopped when halted */ /* Debug MCU APB4 freeze register */ diff --git a/arch/arm/src/stm32h7/stm32_flash.c b/arch/arm/src/stm32h7/stm32_flash.c index 28ea69f8828c4..7e174b590de87 100644 --- a/arch/arm/src/stm32h7/stm32_flash.c +++ b/arch/arm/src/stm32h7/stm32_flash.c @@ -150,10 +150,10 @@ #define FLASH_KEY2 0xcdef89ab #define FLASH_OPTKEY1 0x08192a3b #define FLASH_OPTKEY2 0x4c5d6e7f -#define FLASH_ERASEDVALUE 0xff +#define FLASH_ERASEDVALUE 0xffu #define FLASH_ERASEDVALUE_DW 0xffffffff -#define PROGMEM_NBLOCKS STM32_FLASH_NBLOCKS -#define FLASH_NPAGES (STM32_FLASH_SIZE / FLASH_PAGE_SIZE) +#define PROGMEM_NBLOCKS STM32_FLASH_NBLOCKS +#define FLASH_NPAGES (STM32_FLASH_SIZE / FLASH_PAGE_SIZE) #define FLASH_TIMEOUT_VALUE 5000000 /* 5s */ @@ -987,7 +987,7 @@ ssize_t up_progmem_write(size_t addr, const void *buf, size_t count) return written; } -ssize_t up_progmem_erasestate(void) +uint8_t up_progmem_erasestate(void) { return FLASH_ERASEDVALUE; } diff --git a/arch/arm/src/stm32h7/stm32_tickless.c b/arch/arm/src/stm32h7/stm32_tickless.c new file mode 100644 index 0000000000000..a341403499334 --- /dev/null +++ b/arch/arm/src/stm32h7/stm32_tickless.c @@ -0,0 +1,1057 @@ +/**************************************************************************** + * arch/arm/src/stm32h7/stm32_tickless.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Tickless OS Support. + * + * When CONFIG_SCHED_TICKLESS is enabled, all support for timer interrupts + * is suppressed and the platform specific code is expected to provide the + * following custom functions. + * + * void up_timer_initialize(void): Initializes the timer facilities. + * Called early in the initialization sequence (by up_initialize()). + * int up_timer_gettime(FAR struct timespec *ts): Returns the current + * time from the platform specific time source. + * int up_timer_cancel(void): Cancels the interval timer. + * int up_timer_start(FAR const struct timespec *ts): Start (or re-starts) + * the interval timer. + * + * The RTOS will provide the following interfaces for use by the platform- + * specific interval timer implementation: + * + * void nxsched_timer_expiration(void): Called by the platform-specific + * logic when the interval timer expires. + * + ****************************************************************************/ + +/**************************************************************************** + * STM32 Timer Usage + * + * This implementation uses one timer: A free running timer to provide + * the current time and a capture/compare channel for timed-events. + * + * BASIC timers that are found on some STM32 chips (timers 6 and 7) are + * incompatible with this implementation because they don't have capture/ + * compare channels. There are two interrupts generated from our timer, + * the overflow interrupt which drives the timing handler and the capture/ + * compare interrupt which drives the interval handler. There are some low + * level timer control functions implemented here because the API of + * stm32_tim.c does not provide adequate control over capture/compare + * interrupts. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "arm_internal.h" + +#include "stm32_tim.h" +#include "stm32_dbgmcu.h" + +#include "systick.h" + +#ifdef CONFIG_SCHED_TICKLESS + +/* Only TIM2 and TIM5 timers may be 32-bits in width */ + +#undef HAVE_32BIT_TICKLESS + +#if (CONFIG_STM32H7_TICKLESS_TIMER == 2) || \ + (CONFIG_STM32H7_TICKLESS_TIMER == 5) + #define HAVE_32BIT_TICKLESS 1 +#endif + +#if (CONFIG_STM32H7_TICKLESS_TIMER == 6) || \ + (CONFIG_STM32H7_TICKLESS_TIMER == 7) +# error Basic timers not supported by the tickless driver +#endif + +#if CONFIG_STM32H7_TICKLESS_CHANNEL == 1 +#define DIER_CAPT_IE GTIM_DIER_CC1IE +#elif CONFIG_STM32H7_TICKLESS_CHANNEL == 2 +#define DIER_CAPT_IE GTIM_DIER_CC2IE +#elif CONFIG_STM32H7_TICKLESS_CHANNEL == 3 +#define DIER_CAPT_IE GTIM_DIER_CC3IE +#elif CONFIG_STM32H7_TICKLESS_CHANNEL == 4 +#define DIER_CAPT_IE GTIM_DIER_CC4IE +#endif + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +struct stm32_tickless_s +{ + uint8_t timer; /* The timer/counter in use */ + uint8_t channel; /* The timer channel to use for intervals */ + FAR struct stm32_tim_dev_s *tch; /* Handle returned by stm32_tim_init() */ + uint32_t frequency; + uint32_t overflow; /* Timer counter overflow */ + volatile bool pending; /* True: pending task */ + uint32_t period; /* Interval period */ + uint32_t base; +#ifdef CONFIG_SCHED_TICKLESS_ALARM + uint64_t last_alrm; +#endif +}; + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static struct stm32_tickless_s g_tickless; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: stm32_getreg16 + * + * Description: + * Get a 16-bit register value by offset + * + ****************************************************************************/ + +static inline uint16_t stm32_getreg16(uint8_t offset) +{ + return getreg16(g_tickless.base + offset); +} + +/**************************************************************************** + * Name: stm32_putreg16 + * + * Description: + * Put a 16-bit register value by offset + * + ****************************************************************************/ + +static inline void stm32_putreg16(uint8_t offset, uint16_t value) +{ + putreg16(value, g_tickless.base + offset); +} + +/**************************************************************************** + * Name: stm32_modifyreg16 + * + * Description: + * Modify a 16-bit register value by offset + * + ****************************************************************************/ + +static inline void stm32_modifyreg16(uint8_t offset, uint16_t clearbits, + uint16_t setbits) +{ + modifyreg16(g_tickless.base + offset, clearbits, setbits); +} + +/**************************************************************************** + * Name: stm32_tickless_enableint + ****************************************************************************/ + +static inline void stm32_tickless_enableint(int channel) +{ + stm32_modifyreg16(STM32_BTIM_DIER_OFFSET, 0, 1 << channel); +} + +/**************************************************************************** + * Name: stm32_tickless_disableint + ****************************************************************************/ + +static inline void stm32_tickless_disableint(int channel) +{ + stm32_modifyreg16(STM32_BTIM_DIER_OFFSET, 1 << channel, 0); +} + +/**************************************************************************** + * Name: stm32_tickless_ackint + ****************************************************************************/ + +static inline void stm32_tickless_ackint(int channel) +{ + stm32_putreg16(STM32_BTIM_SR_OFFSET, ~(1 << channel)); +} + +/**************************************************************************** + * Name: stm32_tickless_getint + ****************************************************************************/ + +static inline uint16_t stm32_tickless_getint(void) +{ + return stm32_getreg16(STM32_BTIM_SR_OFFSET); +} + +/**************************************************************************** + * Name: stm32_tickless_setchannel + ****************************************************************************/ + +static int stm32_tickless_setchannel(uint8_t channel) +{ + uint16_t ccmr_orig = 0; + uint16_t ccmr_val = 0; + uint16_t ccmr_mask = 0xff; + uint16_t ccer_val = stm32_getreg16(STM32_GTIM_CCER_OFFSET); + uint8_t ccmr_offset = STM32_GTIM_CCMR1_OFFSET; + + /* Further we use range as 0..3; if channel=0 it will also overflow here */ + + if (--channel > 4) + { + return -EINVAL; + } + + /* Assume that channel is disabled and polarity is active high */ + + ccer_val &= ~((GTIM_CCER_CC1P | GTIM_CCER_CC1E) << + GTIM_CCER_CCXBASE(channel)); + + /* This function is not supported on basic timers. To enable or + * disable it, simply set its clock to valid frequency or zero. + */ + + if (g_tickless.base == STM32_TIM6_BASE || + g_tickless.base == STM32_TIM7_BASE) + { + return -EINVAL; + } + + /* Frozen mode because we don't want to change the GPIO, preload register + * disabled. + */ + + ccmr_val = (GTIM_CCMR_MODE_FRZN << GTIM_CCMR1_OC1M_SHIFT); + + /* Set polarity */ + + ccer_val |= GTIM_CCER_CC1P << GTIM_CCER_CCXBASE(channel); + + /* Define its position (shift) and get register offset */ + + if ((channel & 1) != 0) + { + ccmr_val <<= 8; + ccmr_mask <<= 8; + } + + if (channel > 1) + { + ccmr_offset = STM32_GTIM_CCMR2_OFFSET; + } + + ccmr_orig = stm32_getreg16(ccmr_offset); + ccmr_orig &= ~ccmr_mask; + ccmr_orig |= ccmr_val; + stm32_putreg16(ccmr_offset, ccmr_orig); + stm32_putreg16(STM32_GTIM_CCER_OFFSET, ccer_val); + + return OK; +} + +/**************************************************************************** + * Name: stm32_interval_handler + * + * Description: + * Called when the timer counter matches the compare register + * + * Input Parameters: + * None + * + * Returned Value: + * None + * + * Assumptions: + * Called early in the initialization sequence before any special + * concurrency protections are required. + * + ****************************************************************************/ + +static void stm32_interval_handler(void) +{ +#ifdef CONFIG_SCHED_TICKLESS_ALARM + struct timespec tv; +#endif + tmrinfo("Expired...\n"); + + /* Disable the compare interrupt now. */ + + stm32_tickless_disableint(g_tickless.channel); + stm32_tickless_ackint(g_tickless.channel); + + g_tickless.pending = false; + +#ifndef CONFIG_SCHED_TICKLESS_ALARM + nxsched_timer_expiration(); +#else + up_timer_gettime(&tv); + nxsched_alarm_expiration(&tv); +#endif +} + +/**************************************************************************** + * Name: stm32_timing_handler + * + * Description: + * Timer interrupt callback. When the freerun timer counter overflows, + * this interrupt will occur. We will just increment an overflow count. + * + * Input Parameters: + * None + * + * Returned Value: + * None + * + ****************************************************************************/ + +static void stm32_timing_handler(void) +{ + g_tickless.overflow++; + + STM32_TIM_ACKINT(g_tickless.tch, GTIM_SR_UIF); +} + +/**************************************************************************** + * Name: stm32_tickless_handler + * + * Description: + * Generic interrupt handler for this timer. It checks the source of the + * interrupt and fires the appropriate handler. + * + * Input Parameters: + * None + * + * Returned Value: + * None + * + ****************************************************************************/ + +static int stm32_tickless_handler(int irq, void *context, void *arg) +{ + int interrupt_flags = stm32_tickless_getint(); + + if (interrupt_flags & GTIM_SR_UIF) + { + stm32_timing_handler(); + } + + if (interrupt_flags & (1 << g_tickless.channel)) + { + stm32_interval_handler(); + } + + return OK; +} + +/**************************************************************************** + * Name: stm32_get_counter + * + ****************************************************************************/ + +static uint64_t stm32_get_counter(void) +{ +#ifdef HAVE_32BIT_TICKLESS + return ((uint64_t)g_tickless.overflow << 32) | + STM32_TIM_GETCOUNTER(g_tickless.tch); +#else + return ((uint64_t)g_tickless.overflow << 16) | + STM32_TIM_GETCOUNTER(g_tickless.tch); +#endif +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: up_timer_initialize + * + * Description: + * Initializes all platform-specific timer facilities. This function is + * called early in the initialization sequence by up_initialize(). + * On return, the current up-time should be available from + * up_timer_gettime() and the interval timer is ready for use (but not + * actively timing. + * + * Provided by platform-specific code and called from the architecture- + * specific logic. + * + * Input Parameters: + * None + * + * Returned Value: + * None + * + * Assumptions: + * Called early in the initialization sequence before any special + * concurrency protections are required. + * + ****************************************************************************/ + +void up_timer_initialize(void) +{ + switch (CONFIG_STM32H7_TICKLESS_TIMER) + { +#ifdef CONFIG_STM32H7_TIM1 + case 1: + g_tickless.base = STM32_TIM1_BASE; + modifyreg32(STM32_DBGMCU_APB2FZ1, 0, DBGMCU_APB2Z1_TIM1STOP); + break; +#endif + +#ifdef CONFIG_STM32H7_TIM2 + case 2: + g_tickless.base = STM32_TIM2_BASE; + modifyreg32(STM32_DBGMCU_APB1LFZ1, 0, DBGMCU_APB1L_TIM2STOP); + break; +#endif + +#ifdef CONFIG_STM32H7_TIM3 + case 3: + g_tickless.base = STM32_TIM3_BASE; + modifyreg32(STM32_DBGMCU_APB1LFZ1, 0, DBGMCU_APB1L_TIM3STOP); + break; +#endif + +#ifdef CONFIG_STM32H7_TIM4 + case 4: + g_tickless.base = STM32_TIM4_BASE; + modifyreg32(STM32_DBGMCU_APB1LFZ1, 0, DBGMCU_APB1L_TIM4STOP); + break; +#endif +#ifdef CONFIG_STM32H7_TIM5 + case 5: + g_tickless.base = STM32_TIM5_BASE; + modifyreg32(STM32_DBGMCU_APB1LFZ1, 0, DBGMCU_APB1L_TIM5STOP); + break; +#endif + +#ifdef CONFIG_STM32H7_TIM8 + case 8: + g_tickless.base = STM32_TIM8_BASE; + modifyreg32(STM32_DBGMCU_APB2FZ1, 0, DBGMCU_APB2Z1_TIM8STOP); + break; +#endif + +#ifdef CONFIG_STM32H7_TIM9 + case 9: + g_tickless.base = STM32_TIM9_BASE; + + /* A freeze bit for TIM9 doesn't seem to exist */ + + break; +#endif +#ifdef CONFIG_STM32H7_TIM10 + case 10: + g_tickless.base = STM32_TIM10_BASE; + + /* A freeze bit for TIM10 doesn't seem to exist */ + + break; +#endif + +#ifdef CONFIG_STM32H7_TIM11 + case 11: + g_tickless.base = STM32_TIM11_BASE; + + /* A freeze bit for TIM11 doesn't seem to exist */ + + break; +#endif +#ifdef CONFIG_STM32H7_TIM12 + case 12: + g_tickless.base = STM32_TIM12_BASE; + modifyreg32(STM32_DBGMCU_APB1LFZ1, 0, DBGMCU_APB1L_TIM12STOP); + break; +#endif +#ifdef CONFIG_STM32H7_TIM13 + case 13: + g_tickless.base = STM32_TIM13_BASE; + modifyreg32(STM32_DBGMCU_APB1LFZ1, 0, DBGMCU_APB1L_TIM13STOP); + break; +#endif + +#ifdef CONFIG_STM32H7_TIM14 + case 14: + g_tickless.base = STM32_TIM14_BASE; + modifyreg32(STM32_DBGMCU_APB1LFZ1, 0, DBGMCU_APB1L_TIM14STOP); + break; +#endif +#ifdef CONFIG_STM32H7_TIM15 + case 15: + g_tickless.base = STM32_TIM15_BASE; + modifyreg32(STM32_DBGMCU_APB2FZ1, 0, DBGMCU_APB2Z1_TIM15STOP); + break; +#endif + +#ifdef CONFIG_STM32H7_TIM16 + case 16: + g_tickless.base = STM32_TIM16_BASE; + modifyreg32(STM32_DBGMCU_APB2FZ1, 0, DBGMCU_APB2Z1_TIM16STOP); + break; +#endif + +#ifdef CONFIG_STM32H7_TIM17 + case 17: + g_tickless.base = STM32_TIM17_BASE; + modifyreg32(STM32_DBGMCU_APB2FZ1, 0, DBGMCU_APB2Z1_TIM17STOP); + break; +#endif + + default: + DEBUGASSERT(0); + } + + /* Get the TC frequency that corresponds to the requested resolution */ + + g_tickless.frequency = USEC_PER_SEC / (uint32_t)CONFIG_USEC_PER_TICK; + g_tickless.timer = CONFIG_STM32H7_TICKLESS_TIMER; + g_tickless.channel = CONFIG_STM32H7_TICKLESS_CHANNEL; + g_tickless.pending = false; + g_tickless.period = 0; + g_tickless.overflow = 0; + + tmrinfo("timer=%d channel=%d frequency=%lu Hz\n", + g_tickless.timer, g_tickless.channel, g_tickless.frequency); + + g_tickless.tch = stm32_tim_init(g_tickless.timer); + if (g_tickless.tch == NULL) + { + tmrerr("ERROR: Failed to allocate TIM%d\n", g_tickless.timer); + DEBUGASSERT(0); + } + + STM32_TIM_SETCLOCK(g_tickless.tch, g_tickless.frequency); + + /* Set up to receive the callback when the counter overflow occurs */ + + STM32_TIM_SETISR(g_tickless.tch, stm32_tickless_handler, NULL, 0); + + /* Initialize interval to zero */ + + STM32_TIM_SETCOMPARE(g_tickless.tch, g_tickless.channel, 0); + + /* Setup compare channel for the interval timing */ + + stm32_tickless_setchannel(g_tickless.channel); + + /* Set timer period */ + +#ifdef HAVE_32BIT_TICKLESS + STM32_TIM_SETPERIOD(g_tickless.tch, UINT32_MAX); +#ifdef CONFIG_SCHED_TICKLESS_LIMIT_MAX_SLEEP + g_oneshot_maxticks = UINT32_MAX; +#endif +#else + STM32_TIM_SETPERIOD(g_tickless.tch, UINT16_MAX); +#ifdef CONFIG_SCHED_TICKLESS_LIMIT_MAX_SLEEP + g_oneshot_maxticks = UINT16_MAX; +#endif +#endif + + /* Initialize the counter */ + + STM32_TIM_SETMODE(g_tickless.tch, STM32_TIM_MODE_UP); + + /* Start the timer */ + + STM32_TIM_ACKINT(g_tickless.tch, ~0); + STM32_TIM_ENABLEINT(g_tickless.tch, 0); + +#if defined(CONFIG_ARMV7M_SYSTICK) && defined(CONFIG_CPULOAD_PERIOD) + nxsched_period_extclk(systick_initialize(true, + STM32_CPUCLK_FREQUENCY, -1)); +#endif +} + +/**************************************************************************** + * Name: up_timer_gettime + * + * Description: + * Return the elapsed time since power-up (or, more correctly, since + * up_timer_initialize() was called). This function is functionally + * equivalent to: + * + * int clock_gettime(clockid_t clockid, FAR struct timespec *ts); + * + * when clockid is CLOCK_MONOTONIC. + * + * This function provides the basis for reporting the current time and + * also is used to eliminate error build-up from small errors in interval + * time calculations. + * + * Provided by platform-specific code and called from the RTOS base code. + * + * Input Parameters: + * ts - Provides the location in which to return the up-time. + * + * Returned Value: + * Zero (OK) is returned on success; a negated errno value is returned on + * any failure. + * + * Assumptions: + * Called from the normal tasking context. The implementation must + * provide whatever mutual exclusion is necessary for correct operation. + * This can include disabling interrupts in order to assure atomic register + * operations. + * + ****************************************************************************/ + +int up_timer_gettime(FAR struct timespec *ts) +{ + uint64_t usec; + uint32_t counter; + uint32_t verify; + uint32_t overflow; + uint32_t sec; + int pending; + irqstate_t flags; + + DEBUGASSERT(ts); + + /* Timer not initialized yet, return zero */ + + if (g_tickless.tch == NULL) + { + ts->tv_nsec = 0; + ts->tv_sec = 0; + return OK; + } + + /* Temporarily disable the overflow counter. NOTE that we have to be + * careful here because stm32_tc_getpending() will reset the pending + * interrupt status. If we do not handle the overflow here then, it will + * be lost. + */ + + flags = enter_critical_section(); + + overflow = g_tickless.overflow; + counter = STM32_TIM_GETCOUNTER(g_tickless.tch); + pending = STM32_TIM_CHECKINT(g_tickless.tch, GTIM_SR_UIF); + verify = STM32_TIM_GETCOUNTER(g_tickless.tch); + + /* If an interrupt was pending before we re-enabled interrupts, + * then the overflow needs to be incremented. + */ + + if (pending) + { + STM32_TIM_ACKINT(g_tickless.tch, GTIM_SR_UIF); + + /* Increment the overflow count and use the value of the + * guaranteed to be AFTER the overflow occurred. + */ + + overflow++; + counter = verify; + + /* Update tickless overflow counter. */ + + g_tickless.overflow = overflow; + } + + leave_critical_section(flags); + + tmrinfo("counter=%lu (%lu) overflow=%lu, pending=%i\n", + (unsigned long)counter, (unsigned long)verify, + (unsigned long)overflow, pending); + tmrinfo("frequency=%lu\n", g_tickless.frequency); + + /* Convert the whole thing to units of microseconds. + * + * frequency = ticks / second + * seconds = ticks * frequency + * usecs = (ticks * USEC_PER_SEC) / frequency; + */ +#ifdef HAVE_32BIT_TICKLESS + usec = ((((uint64_t)overflow << 32) + (uint64_t)counter) * USEC_PER_SEC) / + g_tickless.frequency; +#else + usec = ((((uint64_t)overflow << 16) + (uint64_t)counter) * USEC_PER_SEC) / + g_tickless.frequency; +#endif + + /* And return the value of the timer */ + + sec = (uint32_t)(usec / USEC_PER_SEC); + ts->tv_sec = sec; + ts->tv_nsec = (usec - (sec * USEC_PER_SEC)) * NSEC_PER_USEC; + + tmrinfo("usec=%llu ts=(%lu, %lu)\n", + usec, (unsigned long)ts->tv_sec, (unsigned long)ts->tv_nsec); + + return OK; +} + +#ifdef CONFIG_CLOCK_TIMEKEEPING + +/**************************************************************************** + * Name: up_timer_getcounter + * + * Description: + * To be provided + * + * Input Parameters: + * cycles - 64-bit return value + * + * Returned Value: + * None + * + ****************************************************************************/ + +int up_timer_getcounter(FAR uint64_t *cycles) +{ + *cycles = (uint64_t)STM32_TIM_GETCOUNTER(g_tickless.tch); + return OK; +} + +/**************************************************************************** + * Name: up_timer_getmask + * + * Description: + * To be provided + * + * Input Parameters: + * mask - Location to return the 64-bit mask + * + * Returned Value: + * None + * + ****************************************************************************/ + +void up_timer_getmask(FAR uint64_t *mask) +{ + DEBUGASSERT(mask != NULL); +#ifdef HAVE_32BIT_TICKLESS + *mask = UINT32_MAX; +#else + *mask = UINT16_MAX; +#endif +} + +#endif /* CONFIG_CLOCK_TIMEKEEPING */ + +/**************************************************************************** + * Name: up_timer_cancel + * + * Description: + * Cancel the interval timer and return the time remaining on the timer. + * These two steps need to be as nearly atomic as possible. + * nxsched_timer_expiration() will not be called unless the timer is + * restarted with up_timer_start(). + * + * If, as a race condition, the timer has already expired when this + * function is called, then that pending interrupt must be cleared so + * that up_timer_start() and the remaining time of zero should be + * returned. + * + * NOTE: This function may execute at a high rate with no timer running (as + * when pre-emption is enabled and disabled). + * + * Provided by platform-specific code and called from the RTOS base code. + * + * Input Parameters: + * ts - Location to return the remaining time. Zero should be returned + * if the timer is not active. ts may be zero in which case the + * time remaining is not returned. + * + * Returned Value: + * Zero (OK) is returned on success. A call to up_timer_cancel() when + * the timer is not active should also return success; a negated errno + * value is returned on any failure. + * + * Assumptions: + * May be called from interrupt level handling or from the normal tasking + * level. Interrupts may need to be disabled internally to assure + * non-reentrancy. + * + ****************************************************************************/ + +#ifndef CONFIG_SCHED_TICKLESS_ALARM +int up_timer_cancel(FAR struct timespec *ts) +{ + irqstate_t flags; + uint64_t usec; + uint64_t sec; + uint64_t nsec; + uint32_t count; + uint32_t period; + + /* Was the timer running? */ + + flags = enter_critical_section(); + if (!g_tickless.pending) + { + /* No.. Just return zero timer remaining and successful cancellation. + * This function may execute at a high rate with no timer running + * (as when pre-emption is enabled and disabled). + */ + + if (ts != NULL) + { + ts->tv_sec = 0; + ts->tv_nsec = 0; + } + + leave_critical_section(flags); + return OK; + } + + /* Yes.. Get the timer counter and period registers and disable the compare + * interrupt. + */ + + tmrinfo("Cancelling...\n"); + + /* Disable the interrupt. */ + + stm32_tickless_disableint(g_tickless.channel); + + count = STM32_TIM_GETCOUNTER(g_tickless.tch); + period = g_tickless.period; + + g_tickless.pending = false; + leave_critical_section(flags); + + /* Did the caller provide us with a location to return the time + * remaining? + */ + + if (ts != NULL) + { + /* Yes.. then calculate and return the time remaining on the + * oneshot timer. + */ + + tmrinfo("period=%lu count=%lu\n", + (unsigned long)period, (unsigned long)count); + +#ifndef HAVE_32BIT_TICKLESS + if (count > period) + { + /* Handle rollover */ + + period += UINT16_MAX; + } + else if (count == period) +#else + if (count >= period) +#endif + { + /* No time remaining */ + + ts->tv_sec = 0; + ts->tv_nsec = 0; + return OK; + } + + /* The total time remaining is the difference. Convert that + * to units of microseconds. + * + * frequency = ticks / second + * seconds = ticks * frequency + * usecs = (ticks * USEC_PER_SEC) / frequency; + */ + + usec = (((uint64_t)(period - count)) * USEC_PER_SEC) / + g_tickless.frequency; + + /* Return the time remaining in the correct form */ + + sec = usec / USEC_PER_SEC; + nsec = ((usec) - (sec * USEC_PER_SEC)) * NSEC_PER_USEC; + + ts->tv_sec = (time_t)sec; + ts->tv_nsec = (unsigned long)nsec; + + tmrinfo("remaining (%lu, %lu)\n", + (unsigned long)ts->tv_sec, (unsigned long)ts->tv_nsec); + } + + return OK; +} +#endif + +/**************************************************************************** + * Name: up_timer_start + * + * Description: + * Start the interval timer. nxsched_timer_expiration() will be + * called at the completion of the timeout (unless up_timer_cancel + * is called to stop the timing. + * + * Provided by platform-specific code and called from the RTOS base code. + * + * Input Parameters: + * ts - Provides the time interval until nxsched_timer_expiration() is + * called. + * + * Returned Value: + * Zero (OK) is returned on success; a negated errno value is returned on + * any failure. + * + * Assumptions: + * May be called from interrupt level handling or from the normal tasking + * level. Interrupts may need to be disabled internally to assure + * non-reentrancy. + * + ****************************************************************************/ + +#ifndef CONFIG_SCHED_TICKLESS_ALARM +int up_timer_start(FAR const struct timespec *ts) +{ + uint64_t usec; + uint64_t period; + uint32_t count; + irqstate_t flags; + + tmrinfo("ts=(%lu, %lu)\n", + (unsigned long)ts->tv_sec, (unsigned long)ts->tv_nsec); + DEBUGASSERT(ts); + DEBUGASSERT(g_tickless.tch); + + /* Was an interval already running? */ + + flags = enter_critical_section(); + if (g_tickless.pending) + { + /* Yes.. then cancel it */ + + tmrinfo("Already running... cancelling\n"); + up_timer_cancel(NULL); + } + + /* Express the delay in microseconds */ + + usec = (uint64_t)ts->tv_sec * USEC_PER_SEC + + (uint64_t)(ts->tv_nsec / NSEC_PER_USEC); + + /* Get the timer counter frequency and determine the number of counts need + * to achieve the requested delay. + * + * frequency = ticks / second + * ticks = seconds * frequency + * = (usecs * frequency) / USEC_PER_SEC; + */ + + period = (usec * (uint64_t)g_tickless.frequency) / USEC_PER_SEC; + count = STM32_TIM_GETCOUNTER(g_tickless.tch); + + tmrinfo("usec=%llu period=%08llx\n", usec, period); + + /* Set interval compare value. Rollover is fine, + * channel will trigger on the next period. + */ + +#ifdef HAVE_32BIT_TICKLESS + DEBUGASSERT(period <= UINT32_MAX); + g_tickless.period = (uint32_t)(period + count); +#else + DEBUGASSERT(period <= UINT16_MAX); + g_tickless.period = (uint16_t)(period + count); +#endif + + STM32_TIM_SETCOMPARE(g_tickless.tch, g_tickless.channel, + g_tickless.period); + + /* Enable interrupts. We should get the callback when the interrupt + * occurs. + */ + + stm32_tickless_ackint(g_tickless.channel); + stm32_tickless_enableint(g_tickless.channel); + + g_tickless.pending = true; + leave_critical_section(flags); + return OK; +} +#endif + +#ifdef CONFIG_SCHED_TICKLESS_ALARM +int up_alarm_start(FAR const struct timespec *ts) +{ + size_t offset = 1; + uint64_t tm = ((uint64_t)ts->tv_sec * NSEC_PER_SEC + ts->tv_nsec) / + NSEC_PER_TICK; + irqstate_t flags; + + flags = enter_critical_section(); + + STM32_TIM_SETCOMPARE(g_tickless.tch, CONFIG_STM32H7_TICKLESS_CHANNEL, tm); + + stm32_tickless_ackint(g_tickless.channel); + stm32_tickless_enableint(CONFIG_STM32H7_TICKLESS_CHANNEL); + + g_tickless.pending = true; + + /* If we have already passed this time, there is a chance we didn't set the + * compare register in time and we've missed the interrupt. If we don't + * catch this case, we won't interrupt until a full loop of the clock. + * + * Since we can't make assumptions about the clock speed and tick rate, + * we simply keep adding an offset to the current time, until we can leave + * certain that the interrupt is going to fire as soon as we leave the + * critical section. + */ + + while (tm <= stm32_get_counter()) + { + tm = stm32_get_counter() + offset++; + STM32_TIM_SETCOMPARE(g_tickless.tch, CONFIG_STM32H7_TICKLESS_CHANNEL, + tm); + } + + leave_critical_section(flags); + return OK; +} + +int up_alarm_cancel(FAR struct timespec *ts) +{ +#ifdef HAVE_32BIT_TICKLESS + uint64_t nsecs = (((uint64_t)g_tickless.overflow << 32) | + STM32_TIM_GETCOUNTER(g_tickless.tch)) * NSEC_PER_TICK; +#else + uint64_t nsecs = (((uint64_t)g_tickless.overflow << 16) | + STM32_TIM_GETCOUNTER(g_tickless.tch)) * NSEC_PER_TICK; +#endif + + ts->tv_sec = nsecs / NSEC_PER_SEC; + ts->tv_nsec = nsecs - ts->tv_sec * NSEC_PER_SEC; + + stm32_tickless_disableint(CONFIG_STM32H7_TICKLESS_CHANNEL); + + return 0; +} +#endif + +#endif /* CONFIG_SCHED_TICKLESS */ diff --git a/arch/arm/src/stm32h7/stm32_tim.c b/arch/arm/src/stm32h7/stm32_tim.c index 50765c25c7332..de52a0b0984e6 100644 --- a/arch/arm/src/stm32h7/stm32_tim.c +++ b/arch/arm/src/stm32h7/stm32_tim.c @@ -251,24 +251,33 @@ struct stm32_tim_priv_s /* Timer methods */ -static int stm32_tim_setmode(FAR struct stm32_tim_dev_s *dev, - stm32_tim_mode_t mode); -static int stm32_tim_setclock(FAR struct stm32_tim_dev_s *dev, - uint32_t freq); -static void stm32_tim_setperiod(FAR struct stm32_tim_dev_s *dev, - uint32_t period); -static int stm32_tim_setchannel(FAR struct stm32_tim_dev_s *dev, - uint8_t channel, stm32_tim_channel_t mode); -static int stm32_tim_setcompare(FAR struct stm32_tim_dev_s *dev, - uint8_t channel, uint32_t compare); -static int stm32_tim_getcapture(FAR struct stm32_tim_dev_s *dev, - uint8_t channel); -static int stm32_tim_setisr(FAR struct stm32_tim_dev_s *dev, xcpt_t handler, - void *arg, int source); -static void stm32_tim_enableint(FAR struct stm32_tim_dev_s *dev, int source); -static void stm32_tim_disableint(FAR struct stm32_tim_dev_s *dev, +static int stm32_tim_setmode(FAR struct stm32_tim_dev_s *dev, + stm32_tim_mode_t mode); +static int stm32_tim_setclock(FAR struct stm32_tim_dev_s *dev, + uint32_t freq); +static void stm32_tim_setperiod(FAR struct stm32_tim_dev_s *dev, + uint32_t period); +static uint32_t stm32_tim_getcounter(FAR struct stm32_tim_dev_s *dev); +static void stm32_tim_setcounter(FAR struct stm32_tim_dev_s *dev, + uint32_t count); +static int stm32_tim_getwidth(FAR struct stm32_tim_dev_s *dev); +static int stm32_tim_setchannel(FAR struct stm32_tim_dev_s *dev, + uint8_t channel, + stm32_tim_channel_t mode); +static int stm32_tim_setcompare(FAR struct stm32_tim_dev_s *dev, + uint8_t channel, uint32_t compare); +static int stm32_tim_getcapture(FAR struct stm32_tim_dev_s *dev, + uint8_t channel); +static int stm32_tim_setisr(FAR struct stm32_tim_dev_s *dev, + xcpt_t handler, void *arg, int source); +static void stm32_tim_enableint(FAR struct stm32_tim_dev_s *dev, + int source); +static void stm32_tim_disableint(FAR struct stm32_tim_dev_s *dev, + int source); +static void stm32_tim_ackint(FAR struct stm32_tim_dev_s *dev, int source); -static void stm32_tim_ackint(FAR struct stm32_tim_dev_s *dev, int source); +static int stm32_tim_checkint(FAR struct stm32_tim_dev_s *dev, + int source); /**************************************************************************** * Private Data @@ -279,13 +288,17 @@ static const struct stm32_tim_ops_s stm32_tim_ops = .setmode = &stm32_tim_setmode, .setclock = &stm32_tim_setclock, .setperiod = &stm32_tim_setperiod, + .getcounter = &stm32_tim_getcounter, + .setcounter = &stm32_tim_setcounter, + .getwidth = &stm32_tim_getwidth, .setchannel = &stm32_tim_setchannel, .setcompare = &stm32_tim_setcompare, .getcapture = &stm32_tim_getcapture, .setisr = &stm32_tim_setisr, .enableint = &stm32_tim_enableint, .disableint = &stm32_tim_disableint, - .ackint = &stm32_tim_ackint + .ackint = &stm32_tim_ackint, + .checkint = &stm32_tim_checkint, }; #ifdef CONFIG_STM32H7_TIM1 @@ -485,6 +498,64 @@ static void stm32_tim_disable(FAR struct stm32_tim_dev_s *dev) stm32_putreg16(dev, STM32_GTIM_CR1_OFFSET, val); } +/**************************************************************************** + * Name: stm32_tim_getwidth + ****************************************************************************/ + +static int stm32_tim_getwidth(FAR struct stm32_tim_dev_s *dev) +{ + /* Only TIM2 and TIM5 timers may be 32-bits in width */ + + switch (((struct stm32_tim_priv_s *)dev)->base) + { +#if defined(CONFIG_STM32H7_TIM2) + case STM32_TIM2_BASE: + return 32; +#endif + +#if defined(CONFIG_STM32H7_TIM5) + case STM32_TIM5_BASE: + return 32; +#endif + + /* All others are 16-bit times */ + + default: + return 16; + } +} + +/**************************************************************************** + * Name: stm32_tim_getcounter + ****************************************************************************/ + +static uint32_t stm32_tim_getcounter(FAR struct stm32_tim_dev_s *dev) +{ + DEBUGASSERT(dev != NULL); + return stm32_tim_getwidth(dev) > 16 ? + stm32_getreg32(dev, STM32_BTIM_CNT_OFFSET) : + (uint32_t)stm32_getreg16(dev, STM32_BTIM_CNT_OFFSET); +} + +/**************************************************************************** + * Name: stm32_tim_setcounter + ****************************************************************************/ + +static void stm32_tim_setcounter(FAR struct stm32_tim_dev_s *dev, + uint32_t count) +{ + DEBUGASSERT(dev != NULL); + + if (stm32_tim_getwidth(dev) > 16) + { + stm32_putreg32(dev, STM32_BTIM_CNT_OFFSET, count); + } + else + { + stm32_putreg16(dev, STM32_BTIM_CNT_OFFSET, (uint16_t)count); + } +} + /* Reset timer into system default state, but do not affect output/input * pins */ @@ -773,6 +844,12 @@ static void stm32_tim_disableint(FAR struct stm32_tim_dev_s *dev, int source) stm32_modifyreg16(dev, STM32_GTIM_DIER_OFFSET, source, 0); } +static int stm32_tim_checkint(FAR struct stm32_tim_dev_s *dev, int source) +{ + uint16_t regval = stm32_getreg16(dev, STM32_BTIM_SR_OFFSET); + return (regval & source) ? 1 : 0; +} + static void stm32_tim_ackint(FAR struct stm32_tim_dev_s *dev, int source) { stm32_putreg16(dev, STM32_GTIM_SR_OFFSET, ~source); @@ -864,7 +941,7 @@ static int stm32_tim_setchannel(FAR struct stm32_tim_dev_s *dev, /* Assume that channel is disabled and polarity is active high */ - ccer_val &= ~(3 << (channel << 2)); + ccer_val &= ~(3 << GTIM_CCER_CCXBASE(channel)); /* This function is not supported on basic timers. To enable or * disable it, simply set its clock to valid frequency or zero. @@ -885,13 +962,13 @@ static int stm32_tim_setchannel(FAR struct stm32_tim_dev_s *dev, case STM32_TIM_CH_OUTTOGGLE: ccmr_val = (GTIM_CCMR_MODE_OCREFTOG << GTIM_CCMR1_OC1M_SHIFT); - ccer_val |= GTIM_CCER_CC1E << (channel << 2); + ccer_val |= GTIM_CCER_CC1E << GTIM_CCER_CCXBASE(channel); break; case STM32_TIM_CH_OUTPWM: ccmr_val = (GTIM_CCMR_MODE_PWM1 << GTIM_CCMR1_OC1M_SHIFT) + GTIM_CCMR1_OC1PE; - ccer_val |= GTIM_CCER_CC1E << (channel << 2); + ccer_val |= GTIM_CCER_CC1E << GTIM_CCER_CCXBASE(channel); break; default: @@ -902,7 +979,7 @@ static int stm32_tim_setchannel(FAR struct stm32_tim_dev_s *dev, if (mode & STM32_TIM_CH_POLARITY_NEG) { - ccer_val |= GTIM_CCER_CC1P << (channel << 2); + ccer_val |= GTIM_CCER_CC1P << GTIM_CCER_CCXBASE(channel); } /* Define its position (shift) and get register offset */ diff --git a/arch/arm/src/stm32h7/stm32_tim.h b/arch/arm/src/stm32h7/stm32_tim.h index e22d98f7194d5..cc4fb64922789 100644 --- a/arch/arm/src/stm32h7/stm32_tim.h +++ b/arch/arm/src/stm32h7/stm32_tim.h @@ -39,6 +39,9 @@ #define STM32_TIM_SETMODE(d,mode) ((d)->ops->setmode(d,mode)) #define STM32_TIM_SETCLOCK(d,freq) ((d)->ops->setclock(d,freq)) #define STM32_TIM_SETPERIOD(d,period) ((d)->ops->setperiod(d,period)) +#define STM32_TIM_GETCOUNTER(d) ((d)->ops->getcounter(d)) +#define STM32_TIM_SETCOUNTER(d,c) ((d)->ops->setcounter(d,c)) +#define STM32_TIM_GETWIDTH(d) ((d)->ops->getwidth(d)) #define STM32_TIM_SETCHANNEL(d,ch,mode) ((d)->ops->setchannel(d,ch,mode)) #define STM32_TIM_SETCOMPARE(d,ch,comp) ((d)->ops->setcompare(d,ch,comp)) #define STM32_TIM_GETCAPTURE(d,ch) ((d)->ops->getcapture(d,ch)) @@ -46,6 +49,7 @@ #define STM32_TIM_ENABLEINT(d,s) ((d)->ops->enableint(d,s)) #define STM32_TIM_DISABLEINT(d,s) ((d)->ops->disableint(d,s)) #define STM32_TIM_ACKINT(d,s) ((d)->ops->ackint(d,s)) +#define STM32_TIM_CHECKINT(d,s) ((d)->ops->checkint(d,s)) /**************************************************************************** * Public Types @@ -121,8 +125,13 @@ typedef enum /* Output Compare Modes */ - STM32_TIM_CH_OUTPWM = 0x04, /* Enable standard PWM mode, active high when counter < compare */ - STM32_TIM_CH_OUTTOGGLE = 0x08, /* Toggle TIM_CHx output on UEV */ + /* Enable standard PWM mode, active high when counter < compare */ + + STM32_TIM_CH_OUTPWM = 0x04, + + /* Toggle TIM_CHx output on UEV */ + + STM32_TIM_CH_OUTTOGGLE = 0x08, #if 0 STM32_TIM_CH_OUTCOMPARE = 0x06, @@ -130,7 +139,7 @@ typedef enum STM32_TIM_CH_INCAPTURE = 0x10, STM32_TIM_CH_INPWM = 0x20 - STM32_TIM_CH_DRIVE_OC -- open collector mode + STM32_TIM_CH_DRIVE_OC - open collector mode #endif } stm32_tim_channel_t; @@ -143,9 +152,12 @@ struct stm32_tim_ops_s int (*setmode)(FAR struct stm32_tim_dev_s *dev, stm32_tim_mode_t mode); int (*setclock)(FAR struct stm32_tim_dev_s *dev, uint32_t freq); void (*setperiod)(FAR struct stm32_tim_dev_s *dev, uint32_t period); + uint32_t (*getcounter)(FAR struct stm32_tim_dev_s *dev); + void (*setcounter)(FAR struct stm32_tim_dev_s *dev, uint32_t count); /* General and Advanced Timers Adds */ + int (*getwidth)(FAR struct stm32_tim_dev_s *dev); int (*setchannel)(FAR struct stm32_tim_dev_s *dev, uint8_t channel, stm32_tim_channel_t mode); int (*setcompare)(FAR struct stm32_tim_dev_s *dev, uint8_t channel, @@ -159,6 +171,7 @@ struct stm32_tim_ops_s void (*enableint)(FAR struct stm32_tim_dev_s *dev, int source); void (*disableint)(FAR struct stm32_tim_dev_s *dev, int source); void (*ackint)(FAR struct stm32_tim_dev_s *dev, int source); + int (*checkint)(FAR struct stm32_tim_dev_s *dev, int source); }; /**************************************************************************** diff --git a/arch/arm/src/stm32l4/stm32l4_flash.c b/arch/arm/src/stm32l4/stm32l4_flash.c index 555021d893d52..cda4ea41573b7 100644 --- a/arch/arm/src/stm32l4/stm32l4_flash.c +++ b/arch/arm/src/stm32l4/stm32l4_flash.c @@ -62,6 +62,7 @@ #define FLASH_KEY1 0x45670123 #define FLASH_KEY2 0xCDEF89AB +#define FLASH_ERASEDVALUE 0xffu #define OPTBYTES_KEY1 0x08192A3B #define OPTBYTES_KEY2 0x4C5D6E7F @@ -405,7 +406,7 @@ ssize_t up_progmem_ispageerased(size_t page) for (addr = up_progmem_getaddress(page), count = up_progmem_pagesize(page); count; count--, addr++) { - if (getreg8(addr) != 0xff) + if (getreg8(addr) != FLASH_ERASEDVALUE) { bwritten++; } @@ -579,3 +580,8 @@ ssize_t up_progmem_write(size_t addr, const void *buf, size_t buflen) sem_unlock(); return (ret == OK) ? written : ret; } + +uint8_t up_progmem_erasestate(void) +{ + return FLASH_ERASEDVALUE; +} diff --git a/arch/arm/src/stm32l4/stm32l4_pwr.c b/arch/arm/src/stm32l4/stm32l4_pwr.c index 674790cc09d5d..d34a2bd7b9cd2 100644 --- a/arch/arm/src/stm32l4/stm32l4_pwr.c +++ b/arch/arm/src/stm32l4/stm32l4_pwr.c @@ -212,6 +212,102 @@ bool stm32l4_pwr_enableusv(bool set) return was_set; } +/**************************************************************************** + * Name: stm32l4_pwr_enable_pvme2 + * + * Description: + * Enables or disables the peripheral voltage monitoring for Vddio2. + * + * Input Parameters: + * set - True: Vddio2 monitoring enable; False: Vddio2 monitoring disable. + * + * Returned Value: + * True: The bit was previously set. + * + ****************************************************************************/ + +#if !defined(CONFIG_STM32L4_STM32L4X3) +bool stm32l4_pwr_enable_pvme2(bool set) +{ + uint32_t regval; + bool was_set; + bool was_clk_enabled; + + regval = getreg32(STM32L4_RCC_APB1ENR1); + was_clk_enabled = ((regval & RCC_APB1ENR1_PWREN) != 0); + + if (!was_clk_enabled) + { + stm32l4_pwr_enableclk(true); + } + + /* Get the current state of the STM32L4 PWR control register 2 */ + + regval = stm32l4_pwr_getreg(STM32L4_PWR_CR2_OFFSET); + was_set = ((regval & PWR_CR2_PVME2) != 0); + + /* Enable or disable the ability to write */ + + if (was_set && !set) + { + /* Disable the Vddio2 monitoring */ + + regval &= ~PWR_CR2_PVME2; + stm32l4_pwr_putreg(STM32L4_PWR_CR2_OFFSET, regval); + } + else if (!was_set && set) + { + /* Enable the Vddio2 monitoring */ + + regval |= PWR_CR2_PVME2; + stm32l4_pwr_putreg(STM32L4_PWR_CR2_OFFSET, regval); + } + + if (!was_clk_enabled) + { + stm32l4_pwr_enableclk(false); + } + + return was_set; +} + +/**************************************************************************** + * Name: stm32l4_pwr_get_pvmo2 + * + * Description: + * Get value of peripheral voltage monitor output 2 (Vddio2). + * + * Returned Value: + * True: Vddio2 voltage is below PVM2 threshold. + * False: Vddio2 voltage is above PVM2 threshold. + * + ****************************************************************************/ + +bool stm32l4_pwr_get_pvmo2(void) +{ + uint32_t regval; + bool was_clk_enabled; + + regval = getreg32(STM32L4_RCC_APB1ENR1); + was_clk_enabled = ((regval & RCC_APB1ENR1_PWREN) != 0); + + if (!was_clk_enabled) + { + stm32l4_pwr_enableclk(true); + } + + /* Get the current state of the STM32L4 SR2 control register 2 */ + + regval = stm32l4_pwr_getreg(STM32L4_PWR_SR2_OFFSET); + + if (!was_clk_enabled) + { + stm32l4_pwr_enableclk(false); + } + + return !!(regval & PWR_SR2_PVMO2); +} + /**************************************************************************** * Name: stm32l4_pwr_vddio2_valid * @@ -220,7 +316,7 @@ bool stm32l4_pwr_enableusv(bool set) * Setting this bit is mandatory to use the PG2 - PG15 I/Os. * * Input Parameters: - * set - True: Vddio2 is value; False: Vddio2 is not present. Logical and + * set - True: Vddio2 is valid; False: Vddio2 is not present. Logical and * electrical isolation is applied to ignore this supply. * * Returned Value: @@ -228,7 +324,6 @@ bool stm32l4_pwr_enableusv(bool set) * ****************************************************************************/ -#if !defined(CONFIG_STM32L4_STM32L4X3) bool stm32l4_pwr_vddio2_valid(bool set) { uint32_t regval; diff --git a/arch/arm/src/stm32l4/stm32l4_pwr.h b/arch/arm/src/stm32l4/stm32l4_pwr.h index 5d15397ca1dae..4bbe661aacd71 100644 --- a/arch/arm/src/stm32l4/stm32l4_pwr.h +++ b/arch/arm/src/stm32l4/stm32l4_pwr.h @@ -105,6 +105,40 @@ bool stm32l4_pwr_enablebkp(bool writable); bool stm32l4_pwr_enableusv(bool set); +/**************************************************************************** + * Name: stm32l4_pwr_enable_pvme2 + * + * Description: + * Enables or disables the peripheral voltage monitoring for Vddio2. + * + * Input Parameters: + * set - True: Vddio2 monitoring enable; False: Vddio2 monitoring disable. + * + * Returned Value: + * True: The bit was previously set. + * + ****************************************************************************/ + +#if !defined(CONFIG_STM32L4_STM32L4X3) +bool stm32l4_pwr_enable_pvme2(bool set); +#endif + +/**************************************************************************** + * Name: stm32l4_pwr_get_pvmo2 + * + * Description: + * Get value of peripheral voltage monitor output 2 (Vddio2). + * + * Returned Value: + * True: Vddio2 voltage is below PVM2 threshold. + * False: Vddio2 voltage is above PVM2 threshold. + * + ****************************************************************************/ + +#if !defined(CONFIG_STM32L4_STM32L4X3) +bool stm32l4_pwr_get_pvmo2(void); +#endif + /**************************************************************************** * Name: stm32l4_pwr_vddio2_valid * @@ -113,7 +147,7 @@ bool stm32l4_pwr_enableusv(bool set); * Setting this bit is mandatory to use the PG2 - PG15 I/Os. * * Input Parameters: - * set - True: Vddio2 is value; False: Vddio2 is not present. Logical and + * set - True: Vddio2 is valid; False: Vddio2 is not present. Logical and * electrical isolation is applied to ignore this supply. * * Returned Value: diff --git a/arch/arm/src/stm32l5/stm32l5_flash.c b/arch/arm/src/stm32l5/stm32l5_flash.c index 9bdd1c7591182..bff483c30c215 100644 --- a/arch/arm/src/stm32l5/stm32l5_flash.c +++ b/arch/arm/src/stm32l5/stm32l5_flash.c @@ -46,7 +46,7 @@ #include "stm32l5_flash.h" #include "arm_internal.h" -#if !(defined(CONFIG_STM32L5_STM32L562XX)) +#if !defined(CONFIG_STM32L5_STM32L562XX) # error "Unrecognized STM32 chip" #endif @@ -60,6 +60,7 @@ #define FLASH_KEY1 0x45670123 #define FLASH_KEY2 0xCDEF89AB +#define FLASH_ERASEDVALUE 0xffu #define OPTBYTES_KEY1 0x08192A3B #define OPTBYTES_KEY2 0x4C5D6E7F @@ -351,7 +352,7 @@ ssize_t up_progmem_ispageerased(size_t page) for (addr = up_progmem_getaddress(page), count = up_progmem_pagesize(page); count; count--, addr++) { - if (getreg8(addr) != 0xff) + if (getreg8(addr) != FLASH_ERASEDVALUE) { bwritten++; } @@ -504,3 +505,8 @@ ssize_t up_progmem_write(size_t addr, const void *buf, size_t buflen) sem_unlock(); return (ret == OK) ? written : ret; } + +uint8_t up_progmem_erasestate(void) +{ + return FLASH_ERASEDVALUE; +} diff --git a/arch/arm/src/stm32u5/stm32_flash.c b/arch/arm/src/stm32u5/stm32_flash.c index a202f21191847..f444176e14c4b 100644 --- a/arch/arm/src/stm32u5/stm32_flash.c +++ b/arch/arm/src/stm32u5/stm32_flash.c @@ -46,7 +46,7 @@ #include "stm32_flash.h" #include "arm_internal.h" -#if !(defined(CONFIG_STM32U5_STM32U585XX)) +#if !defined(CONFIG_STM32U5_STM32U585XX) # error "Unrecognized STM32 chip" #endif @@ -60,6 +60,7 @@ #define FLASH_KEY1 0x45670123 #define FLASH_KEY2 0xCDEF89AB +#define FLASH_ERASEDVALUE 0xffu #define OPTBYTES_KEY1 0x08192A3B #define OPTBYTES_KEY2 0x4C5D6E7F @@ -351,7 +352,7 @@ ssize_t up_progmem_ispageerased(size_t page) for (addr = up_progmem_getaddress(page), count = up_progmem_pagesize(page); count; count--, addr++) { - if (getreg8(addr) != 0xff) + if (getreg8(addr) != FLASH_ERASEDVALUE) { bwritten++; } @@ -504,3 +505,16 @@ ssize_t up_progmem_write(size_t addr, const void *buf, size_t buflen) sem_unlock(); return (ret == OK) ? written : ret; } + +/**************************************************************************** + * Name: up_progmem_erasestate + * + * Description: + * Return value of erase state. + * + ****************************************************************************/ + +uint8_t up_progmem_erasestate(void) +{ + return FLASH_ERASEDVALUE; +} diff --git a/arch/arm/src/tiva/common/tiva_can.c b/arch/arm/src/tiva/common/tiva_can.c index 0221f5766acbc..66e904b460889 100644 --- a/arch/arm/src/tiva/common/tiva_can.c +++ b/arch/arm/src/tiva/common/tiva_can.c @@ -141,7 +141,7 @@ struct tiva_canmod_s /* kthread message handler thread ID */ - int kthd_id; + pid_t kthd_id; #ifdef CONFIG_CAN_ERRORS /* Asynchronously report errors when status interrupts are disabled */ @@ -438,7 +438,7 @@ static int tivacan_setup(FAR struct can_dev_s *dev) } else { - canmod->kthd_id = ret; + canmod->kthd_id = (pid_t)ret; } #ifdef CONFIG_CAN_EXTID diff --git a/arch/avr/src/avr/Toolchain.defs b/arch/avr/src/avr/Toolchain.defs index bb8238eb9a1c5..bed4f32ea5033 100644 --- a/arch/avr/src/avr/Toolchain.defs +++ b/arch/avr/src/avr/Toolchain.defs @@ -126,12 +126,12 @@ OBJDUMP = $(CROSSDEV)objdump # Add the builtin library -EXTRA_LIBS += ${shell $(CC) $(ARCHCPUFLAGS) --print-libgcc-file-name} +EXTRA_LIBS += ${wildcard ${shell $(CC) $(ARCHCPUFLAGS) --print-libgcc-file-name}} ifneq ($(CONFIG_LIBM),y) EXTRA_LIBS += ${wildcard ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libm.a}} endif ifeq ($(CONFIG_LIBSUPCXX),y) - EXTRA_LIBS += ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libsupc++.a} + EXTRA_LIBS += ${wildcard ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libsupc++.a}} endif diff --git a/arch/avr/src/avr/up_initialstate.c b/arch/avr/src/avr/up_initialstate.c index 92f31b1c72566..84de3f0837834 100644 --- a/arch/avr/src/avr/up_initialstate.c +++ b/arch/avr/src/avr/up_initialstate.c @@ -58,7 +58,7 @@ void up_initial_state(struct tcb_s *tcb) /* Initialize the idle thread stack */ - if (tcb->pid == 0) + if (tcb->pid == IDLE_PROCESS_ID) { char *stack_ptr = (char *)(g_idle_topstack - CONFIG_IDLETHREAD_STACKSIZE); diff --git a/arch/avr/src/avr32/Toolchain.defs b/arch/avr/src/avr32/Toolchain.defs index 5f33635f3d4ae..87b61352b96d8 100644 --- a/arch/avr/src/avr32/Toolchain.defs +++ b/arch/avr/src/avr32/Toolchain.defs @@ -50,12 +50,12 @@ OBJDUMP = $(CROSSDEV)objdump # Add the builtin library -EXTRA_LIBS += ${shell $(CC) $(ARCHCPUFLAGS) --print-libgcc-file-name} +EXTRA_LIBS += ${wildcard ${shell $(CC) $(ARCHCPUFLAGS) --print-libgcc-file-name}} ifneq ($(CONFIG_LIBM),y) EXTRA_LIBS += ${wildcard ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libm.a}} endif ifeq ($(CONFIG_LIBSUPCXX),y) - EXTRA_LIBS += ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libsupc++.a} + EXTRA_LIBS += ${wildcard ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libsupc++.a}} endif diff --git a/arch/avr/src/avr32/up_initialstate.c b/arch/avr/src/avr32/up_initialstate.c index f2555a5c0149d..58d99b913c515 100644 --- a/arch/avr/src/avr32/up_initialstate.c +++ b/arch/avr/src/avr32/up_initialstate.c @@ -55,7 +55,7 @@ void up_initial_state(struct tcb_s *tcb) /* Initialize the idle thread stack */ - if (tcb->pid == 0) + if (tcb->pid == IDLE_PROCESS_ID) { char *stack_ptr = (char *)(g_idle_topstack - CONFIG_IDLETHREAD_STACKSIZE); diff --git a/arch/ceva/src/common/up_assert.c b/arch/ceva/src/common/up_assert.c index 4f13cb22afd53..c5a5d233a507b 100644 --- a/arch/ceva/src/common/up_assert.c +++ b/arch/ceva/src/common/up_assert.c @@ -296,7 +296,7 @@ static void _up_assert(int errorcode) /* Are we in an interrupt handler or the idle task? */ - if (CURRENT_REGS || running_task()->pid == 0) + if (up_interrupt_context() || sched_idletask()) { up_irq_save(); for (; ; ) diff --git a/arch/ceva/src/xc5/up_initialstate.c b/arch/ceva/src/xc5/up_initialstate.c index bdd62bdfc485e..14e37dcd4741b 100644 --- a/arch/ceva/src/xc5/up_initialstate.c +++ b/arch/ceva/src/xc5/up_initialstate.c @@ -55,7 +55,7 @@ void up_initial_state(struct tcb_s *tcb) /* Initialize the idle thread stack */ - if (tcb->pid == 0) + if (tcb->pid == IDLE_PROCESS_ID) { tcb->stack_alloc_ptr = g_idle_basestack; tcb->stack_base_ptr = tcb->stack_alloc_ptr; diff --git a/arch/ceva/src/xm6/up_initialstate.c b/arch/ceva/src/xm6/up_initialstate.c index d7207cb8b10d2..4677c19ce4bec 100644 --- a/arch/ceva/src/xm6/up_initialstate.c +++ b/arch/ceva/src/xm6/up_initialstate.c @@ -61,7 +61,7 @@ void up_initial_state(struct tcb_s *tcb) /* Initialize the idle thread stack */ - if (tcb->pid == 0) + if (tcb->pid == IDLE_PROCESS_ID) { tcb->stack_alloc_ptr = g_idle_basestack; tcb->stack_base_ptr = tcb->stack_alloc_ptr; diff --git a/arch/hc/src/Makefile b/arch/hc/src/Makefile index 1b4365f4bd3cb..cfab40831b0cc 100644 --- a/arch/hc/src/Makefile +++ b/arch/hc/src/Makefile @@ -74,14 +74,14 @@ endif # Add the builtin library -EXTRA_LIBS += ${shell $(CC) $(ARCHCPUFLAGS) --print-libgcc-file-name} +EXTRA_LIBS += ${wildcard ${shell $(CC) $(ARCHCPUFLAGS) --print-libgcc-file-name}} ifneq ($(CONFIG_LIBM),y) EXTRA_LIBS += ${wildcard ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libm.a}} endif ifeq ($(CONFIG_LIBSUPCXX),y) - EXTRA_LIBS += ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libsupc++.a} + EXTRA_LIBS += ${wildcard ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libsupc++.a}} endif VPATH = chip:common:$(ARCH_SUBDIR) diff --git a/arch/hc/src/m9s12/m9s12_initialstate.c b/arch/hc/src/m9s12/m9s12_initialstate.c index d2ffa75d7f512..a91c2e58e8607 100644 --- a/arch/hc/src/m9s12/m9s12_initialstate.c +++ b/arch/hc/src/m9s12/m9s12_initialstate.c @@ -56,7 +56,7 @@ void up_initial_state(struct tcb_s *tcb) /* Initialize the idle thread stack */ - if (tcb->pid == 0) + if (tcb->pid == IDLE_PROCESS_ID) { char *stack_ptr = (char *)(g_idle_topstack - CONFIG_IDLETHREAD_STACKSIZE); diff --git a/arch/mips/src/mips32/Toolchain.defs b/arch/mips/src/mips32/Toolchain.defs index ffeb1ee88b5df..5a89a868d62d8 100644 --- a/arch/mips/src/mips32/Toolchain.defs +++ b/arch/mips/src/mips32/Toolchain.defs @@ -279,12 +279,12 @@ OBJDUMP = $(CROSSDEV)objdump # Add the builtin library -EXTRA_LIBS += ${shell $(CC) $(ARCHCPUFLAGS) --print-libgcc-file-name} +EXTRA_LIBS += ${wildcard ${shell $(CC) $(ARCHCPUFLAGS) --print-libgcc-file-name}} ifneq ($(CONFIG_LIBM),y) EXTRA_LIBS += ${wildcard ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libm.a}} endif ifeq ($(CONFIG_LIBSUPCXX),y) - EXTRA_LIBS += ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libsupc++.a} + EXTRA_LIBS += ${wildcard ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libsupc++.a}} endif diff --git a/arch/mips/src/mips32/mips_initialstate.c b/arch/mips/src/mips32/mips_initialstate.c index 9ad52f142c104..2b83e0c12da34 100644 --- a/arch/mips/src/mips32/mips_initialstate.c +++ b/arch/mips/src/mips32/mips_initialstate.c @@ -59,7 +59,7 @@ void up_initial_state(struct tcb_s *tcb) /* Initialize the idle thread stack */ - if (tcb->pid == 0) + if (tcb->pid == IDLE_PROCESS_ID) { char *stack_ptr = (char *)(g_idle_topstack - CONFIG_IDLETHREAD_STACKSIZE); diff --git a/arch/misoc/src/lm32/Toolchain.defs b/arch/misoc/src/lm32/Toolchain.defs index 30cd2902496f0..72071809652f8 100644 --- a/arch/misoc/src/lm32/Toolchain.defs +++ b/arch/misoc/src/lm32/Toolchain.defs @@ -87,12 +87,12 @@ OBJDUMP = $(CROSSDEV)objdump # Add the builtin library -EXTRA_LIBS += ${shell $(CC) $(ARCHCPUFLAGS) --print-libgcc-file-name} +EXTRA_LIBS += ${wildcard ${shell $(CC) $(ARCHCPUFLAGS) --print-libgcc-file-name}} ifneq ($(CONFIG_LIBM),y) EXTRA_LIBS += ${wildcard ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libm.a}} endif ifeq ($(CONFIG_LIBSUPCXX),y) - EXTRA_LIBS += ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libsupc++.a} + EXTRA_LIBS += ${wildcard ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libsupc++.a}} endif diff --git a/arch/misoc/src/lm32/lm32_initialstate.c b/arch/misoc/src/lm32/lm32_initialstate.c index da5a2281b3e47..42ccb3db2e405 100644 --- a/arch/misoc/src/lm32/lm32_initialstate.c +++ b/arch/misoc/src/lm32/lm32_initialstate.c @@ -57,7 +57,7 @@ void up_initial_state(struct tcb_s *tcb) /* Initialize the idle thread stack */ - if (tcb->pid == 0) + if (tcb->pid == IDLE_PROCESS_ID) { char *stack_ptr = (char *)(g_idle_topstack - CONFIG_IDLETHREAD_STACKSIZE); diff --git a/arch/misoc/src/minerva/Toolchain.defs b/arch/misoc/src/minerva/Toolchain.defs index 84dbd28f3282d..a75c4468b2875 100644 --- a/arch/misoc/src/minerva/Toolchain.defs +++ b/arch/misoc/src/minerva/Toolchain.defs @@ -41,12 +41,12 @@ OBJDUMP = $(CROSSDEV)objdump # Add the builtin library -EXTRA_LIBS += ${shell $(CC) $(ARCHCPUFLAGS) --print-libgcc-file-name} +EXTRA_LIBS += ${wildcard ${shell $(CC) $(ARCHCPUFLAGS) --print-libgcc-file-name}} ifneq ($(CONFIG_LIBM),y) EXTRA_LIBS += ${wildcard ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libm.a}} endif ifeq ($(CONFIG_LIBSUPCXX),y) - EXTRA_LIBS += ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libsupc++.a} + EXTRA_LIBS += ${wildcard ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libsupc++.a}} endif diff --git a/arch/misoc/src/minerva/minerva_initialstate.c b/arch/misoc/src/minerva/minerva_initialstate.c index e0f5d974f2aaf..ab1184af91f40 100644 --- a/arch/misoc/src/minerva/minerva_initialstate.c +++ b/arch/misoc/src/minerva/minerva_initialstate.c @@ -61,7 +61,7 @@ void up_initial_state(struct tcb_s *tcb) /* Initialize the idle thread stack */ - if (tcb->pid == 0) + if (tcb->pid == IDLE_PROCESS_ID) { char *stack_ptr = (char *)(g_idle_topstack - CONFIG_IDLETHREAD_STACKSIZE); diff --git a/arch/or1k/src/common/up_initialstate.c b/arch/or1k/src/common/up_initialstate.c index 502f04d9c5030..f0d010d5068b9 100644 --- a/arch/or1k/src/common/up_initialstate.c +++ b/arch/or1k/src/common/up_initialstate.c @@ -74,7 +74,7 @@ void up_initial_state(struct tcb_s *tcb) /* Initialize the idle thread stack */ - if (tcb->pid == 0) + if (tcb->pid == IDLE_PROCESS_ID) { tcb->stack_alloc_ptr = (void *)(g_idle_topstack - CONFIG_IDLETHREAD_STACKSIZE); diff --git a/arch/or1k/src/mor1kx/Toolchain.defs b/arch/or1k/src/mor1kx/Toolchain.defs index 201de9b34bdd9..43320d7a09437 100644 --- a/arch/or1k/src/mor1kx/Toolchain.defs +++ b/arch/or1k/src/mor1kx/Toolchain.defs @@ -68,12 +68,12 @@ OBJDUMP = $(CROSSDEV)objdump # Add the builtin library -EXTRA_LIBS += ${shell $(CC) $(ARCHCPUFLAGS) --print-libgcc-file-name} +EXTRA_LIBS += ${wildcard ${shell $(CC) $(ARCHCPUFLAGS) --print-libgcc-file-name}} ifneq ($(CONFIG_LIBM),y) EXTRA_LIBS += ${wildcard ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libm.a}} endif ifeq ($(CONFIG_LIBSUPCXX),y) - EXTRA_LIBS += ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libsupc++.a} + EXTRA_LIBS += ${wildcard ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libsupc++.a}} endif diff --git a/arch/renesas/src/Makefile b/arch/renesas/src/Makefile index ade1adb8f6f0a..9d52a012f816d 100644 --- a/arch/renesas/src/Makefile +++ b/arch/renesas/src/Makefile @@ -74,7 +74,7 @@ ifneq ($(CONFIG_LIBM),y) endif ifeq ($(CONFIG_LIBSUPCXX),y) - EXTRA_LIBS += ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libsupc++.a} + EXTRA_LIBS += ${wildcard ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libsupc++.a}} endif VPATH = chip:common diff --git a/arch/renesas/src/m16c/m16c_initialstate.c b/arch/renesas/src/m16c/m16c_initialstate.c index 600cb9ec180e4..6b7e386f30b85 100644 --- a/arch/renesas/src/m16c/m16c_initialstate.c +++ b/arch/renesas/src/m16c/m16c_initialstate.c @@ -57,7 +57,7 @@ void up_initial_state(FAR struct tcb_s *tcb) /* Initialize the idle thread stack */ - if (tcb->pid == 0) + if (tcb->pid == IDLE_PROCESS_ID) { char *stack_ptr = (char *)(g_idle_topstack - CONFIG_IDLETHREAD_STACKSIZE); diff --git a/arch/renesas/src/rx65n/rx65n_initialstate.c b/arch/renesas/src/rx65n/rx65n_initialstate.c index cd07fb3451b9c..65a3b938efdb7 100644 --- a/arch/renesas/src/rx65n/rx65n_initialstate.c +++ b/arch/renesas/src/rx65n/rx65n_initialstate.c @@ -62,7 +62,7 @@ void up_initial_state(struct tcb_s *tcb) /* Initialize the idle thread stack */ - if (tcb->pid == 0) + if (tcb->pid == IDLE_PROCESS_ID) { char *stack_ptr = (char *)(g_idle_topstack - CONFIG_IDLETHREAD_STACKSIZE); diff --git a/arch/renesas/src/sh1/sh1_initialstate.c b/arch/renesas/src/sh1/sh1_initialstate.c index 3b6915081790c..abbda0409f74d 100644 --- a/arch/renesas/src/sh1/sh1_initialstate.c +++ b/arch/renesas/src/sh1/sh1_initialstate.c @@ -74,7 +74,7 @@ void up_initial_state(struct tcb_s *tcb) /* Initialize the idle thread stack */ - if (tcb->pid == 0) + if (tcb->pid == IDLE_PROCESS_ID) { char *stack_ptr = (char *)(g_idle_topstack - CONFIG_IDLETHREAD_STACKSIZE); diff --git a/arch/risc-v/include/irq.h b/arch/risc-v/include/irq.h index a8a3bb4db3173..20651c9a3d8bb 100644 --- a/arch/risc-v/include/irq.h +++ b/arch/risc-v/include/irq.h @@ -498,8 +498,7 @@ struct xcptcontext * another signal handler is executing will be ignored! */ - uintptr_t saved_epc; /* Trampoline PC */ - uintptr_t saved_int_ctx; /* Interrupt context with interrupts disabled. */ + uintptr_t *saved_regs; #ifndef CONFIG_BUILD_FLAT /* This is the saved address to use when returning from a user-space @@ -517,11 +516,27 @@ struct xcptcontext uint8_t nsyscalls; struct xcpt_syscall_s syscall[CONFIG_SYS_NNEST]; +#endif + +#ifdef CONFIG_ARCH_ADDRENV +#ifdef CONFIG_ARCH_KERNEL_STACK + /* In this configuration, all syscalls execute from an internal kernel + * stack. Why? Because when we instantiate and initialize the address + * environment of the new user process, we will temporarily lose the + * address environment of the old user process, including its stack + * contents. The kernel C logic will crash immediately with no valid + * stack in place. + */ + + uintptr_t *ustkptr; /* Saved user stack pointer */ + uintptr_t *kstack; /* Allocate base of the (aligned) kernel stack */ + uintptr_t *kstkptr; /* Saved kernel stack pointer */ +#endif #endif /* Register save area */ - uintptr_t regs[XCPTCONTEXT_REGS]; + uintptr_t *regs; }; #endif /* __ASSEMBLY__ */ diff --git a/arch/risc-v/include/syscall.h b/arch/risc-v/include/syscall.h index 00c9d79b61f0d..a357d1d84d169 100644 --- a/arch/risc-v/include/syscall.h +++ b/arch/risc-v/include/syscall.h @@ -67,14 +67,14 @@ /* SYS call 1: * - * void riscv_fullcontextrestore(uint32_t *restoreregs) noreturn_function; + * void riscv_fullcontextrestore(uintptr_t *restoreregs) noreturn_function; */ #define SYS_restore_context (1) /* SYS call 2: * - * void riscv_switchcontext(uint32_t *saveregs, uint32_t *restoreregs); + * void riscv_switchcontext(uintptr_t **saveregs, uintptr_t *restoreregs); */ #define SYS_switch_context (2) @@ -130,7 +130,7 @@ /* SYS call 0: * - * int riscv_saveusercontext(uint64_t *saveregs); + * int riscv_saveusercontext(uintptr_t *saveregs); * * Return: * 0: Normal Return @@ -138,23 +138,23 @@ */ #define riscv_saveusercontext(saveregs) \ - (int)sys_call1(SYS_save_context, (uintptr_t)saveregs) + (int)sys_call1(SYS_save_context, (uintptr_t)(saveregs)) /* SYS call 1: * - * void riscv_fullcontextrestore(uint32_t *restoreregs) noreturn_function; + * void riscv_fullcontextrestore(uintptr_t *restoreregs) noreturn_function; */ #define riscv_fullcontextrestore(restoreregs) \ - sys_call1(SYS_restore_context, (uintptr_t)restoreregs) + sys_call1(SYS_restore_context, (uintptr_t)(restoreregs)) /* SYS call 2: * - * void riscv_switchcontext(uint32_t *saveregs, uint32_t *restoreregs); + * void riscv_switchcontext(uintptr_t **saveregs, uintptr_t *restoreregs); */ #define riscv_switchcontext(saveregs, restoreregs) \ - sys_call2(SYS_switch_context, (uintptr_t)saveregs, (uintptr_t)restoreregs) + sys_call2(SYS_switch_context, (uintptr_t)(saveregs), (uintptr_t)(restoreregs)) #ifdef CONFIG_BUILD_KERNEL /* SYS call 3: diff --git a/arch/risc-v/src/bl602/Make.defs b/arch/risc-v/src/bl602/Make.defs index 251f1980d5ce8..f4d78cd39a6eb 100644 --- a/arch/risc-v/src/bl602/Make.defs +++ b/arch/risc-v/src/bl602/Make.defs @@ -30,7 +30,7 @@ CMN_CSRCS += riscv_initialize.c riscv_swint.c CMN_CSRCS += riscv_createstack.c riscv_exit.c CMN_CSRCS += riscv_assert.c riscv_blocktask.c riscv_copystate.c riscv_initialstate.c CMN_CSRCS += riscv_interruptcontext.c riscv_modifyreg32.c riscv_puts.c riscv_mdelay.c -CMN_CSRCS += riscv_releasepending.c riscv_reprioritizertr.c riscv_copyfullstate.c +CMN_CSRCS += riscv_releasepending.c riscv_reprioritizertr.c CMN_CSRCS += riscv_releasestack.c riscv_stackframe.c riscv_schedulesigaction.c CMN_CSRCS += riscv_sigdeliver.c riscv_udelay.c riscv_unblocktask.c riscv_usestack.c CMN_CSRCS += riscv_idle.c riscv_tcbinfo.c riscv_getnewintctx.c diff --git a/arch/risc-v/src/bl602/bl602_irq.c b/arch/risc-v/src/bl602/bl602_irq.c index 9540f793bde0a..09472a4a8b659 100644 --- a/arch/risc-v/src/bl602/bl602_irq.c +++ b/arch/risc-v/src/bl602/bl602_irq.c @@ -40,6 +40,12 @@ #include "chip.h" +/**************************************************************************** + * Public Data + ****************************************************************************/ + +volatile uintptr_t *g_current_regs[1]; + /**************************************************************************** * Private Functions ****************************************************************************/ diff --git a/arch/risc-v/src/bl602/bl602_irq_dispatch.c b/arch/risc-v/src/bl602/bl602_irq_dispatch.c index 10c89cad0d117..ee53bd08a4091 100644 --- a/arch/risc-v/src/bl602/bl602_irq_dispatch.c +++ b/arch/risc-v/src/bl602/bl602_irq_dispatch.c @@ -35,12 +35,6 @@ #include "riscv_internal.h" #include "chip.h" -/**************************************************************************** - * Public Data - ****************************************************************************/ - -volatile uintptr_t *g_current_regs[1]; - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -51,12 +45,12 @@ volatile uintptr_t *g_current_regs[1]; void *riscv_dispatch_irq(uintptr_t vector, uintptr_t *regs) { - uintptr_t irq = vector & 0x3ff; /* E24 [9:0] */ + int irq = vector & 0x3ff; /* E24 [9:0] */ uintptr_t *mepc = regs; /* If current is interrupt */ - if (vector & 0x80000000u) + if ((vector & RISCV_IRQ_BIT) != 0) { irq += RISCV_IRQ_ASYNC; } @@ -124,7 +118,7 @@ void *riscv_dispatch_irq(uintptr_t vector, uintptr_t *regs) * switch occurred during interrupt processing. */ - regs = (uintptr_t *)CURRENT_REGS; + regs = (uintptr_t *)CURRENT_REGS; CURRENT_REGS = NULL; return regs; diff --git a/arch/risc-v/src/bl602/bl602_os_hal.c b/arch/risc-v/src/bl602/bl602_os_hal.c index 08056fcf673bf..e2c3fdb9669b7 100644 --- a/arch/risc-v/src/bl602/bl602_os_hal.c +++ b/arch/risc-v/src/bl602/bl602_os_hal.c @@ -340,9 +340,9 @@ int bl_os_task_create(const char *name, void bl_os_task_delete(void *task_handle) { - pid_t task = (int)task_handle; + pid_t pid = (pid_t)((uintptr_t)task_handle); - task_delete((pid_t)task); + task_delete(pid); } /**************************************************************************** @@ -358,7 +358,9 @@ void bl_os_task_delete(void *task_handle) void *bl_os_task_get_current_task(void) { - return (void *)0; + pid_t pid = getpid(); + + return (void *)((uintptr_t)pid); } /**************************************************************************** diff --git a/arch/risc-v/src/c906/Make.defs b/arch/risc-v/src/c906/Make.defs index 75c6cddd7dc10..2dc5e775547c8 100644 --- a/arch/risc-v/src/c906/Make.defs +++ b/arch/risc-v/src/c906/Make.defs @@ -33,7 +33,7 @@ CMN_CSRCS += riscv_interruptcontext.c riscv_modifyreg32.c riscv_puts.c CMN_CSRCS += riscv_releasepending.c riscv_reprioritizertr.c CMN_CSRCS += riscv_releasestack.c riscv_stackframe.c riscv_schedulesigaction.c CMN_CSRCS += riscv_sigdeliver.c riscv_unblocktask.c riscv_usestack.c -CMN_CSRCS += riscv_mdelay.c riscv_copyfullstate.c riscv_idle.c +CMN_CSRCS += riscv_mdelay.c riscv_idle.c CMN_CSRCS += riscv_tcbinfo.c riscv_getnewintctx.c ifeq ($(CONFIG_SCHED_BACKTRACE),y) diff --git a/arch/risc-v/src/c906/c906_irq.c b/arch/risc-v/src/c906/c906_irq.c index e315b7456df63..c7059be753ad0 100644 --- a/arch/risc-v/src/c906/c906_irq.c +++ b/arch/risc-v/src/c906/c906_irq.c @@ -40,7 +40,7 @@ * Public Data ****************************************************************************/ -volatile uint64_t *g_current_regs[1]; +volatile uintptr_t *g_current_regs[1]; /**************************************************************************** * Public Functions diff --git a/arch/risc-v/src/c906/c906_irq_dispatch.c b/arch/risc-v/src/c906/c906_irq_dispatch.c index c032864b6ff2f..c2bf9662c22be 100644 --- a/arch/risc-v/src/c906/c906_irq_dispatch.c +++ b/arch/risc-v/src/c906/c906_irq_dispatch.c @@ -35,6 +35,12 @@ #include "riscv_internal.h" #include "group/group.h" +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define RV_IRQ_MASK 59 + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -43,16 +49,16 @@ * riscv_dispatch_irq ****************************************************************************/ -void *riscv_dispatch_irq(uint64_t vector, uint64_t *regs) +void *riscv_dispatch_irq(uintptr_t vector, uintptr_t *regs) { - uint32_t irq = (vector >> (27 + 32)) | (vector & 0xf); - uint64_t *mepc = regs; + int irq = (vector >> RV_IRQ_MASK) | (vector & 0xf); + uintptr_t *mepc = regs; /* Check if fault happened */ if (vector < RISCV_IRQ_ECALLU) { - riscv_fault((int)irq, regs); + riscv_fault(irq, regs); } /* Firstly, check if the irq is machine external interrupt */ @@ -118,7 +124,7 @@ void *riscv_dispatch_irq(uint64_t vector, uint64_t *regs) #ifdef CONFIG_ARCH_FPU /* Restore floating point registers */ - riscv_restorefpu((uint64_t *)CURRENT_REGS); + riscv_restorefpu((uintptr_t *)CURRENT_REGS); #endif #ifdef CONFIG_ARCH_ADDRENV @@ -141,7 +147,7 @@ void *riscv_dispatch_irq(uint64_t vector, uint64_t *regs) * switch occurred during interrupt processing. */ - regs = (uint64_t *)CURRENT_REGS; + regs = (uintptr_t *)CURRENT_REGS; CURRENT_REGS = NULL; return regs; diff --git a/arch/risc-v/src/common/Toolchain.defs b/arch/risc-v/src/common/Toolchain.defs index 95f7854c3ed61..1c871110dd0f1 100644 --- a/arch/risc-v/src/common/Toolchain.defs +++ b/arch/risc-v/src/common/Toolchain.defs @@ -115,6 +115,10 @@ ifeq ($(CONFIG_RISCV_TOOLCHAIN),GNU_RVG) endif +ifeq ($(CONFIG_MM_KASAN),y) + ARCHCPUFLAGS += -fsanitize=kernel-address +endif + # Default toolchain CC = $(CROSSDEV)gcc @@ -129,12 +133,12 @@ OBJDUMP = $(CROSSDEV)objdump # Add the builtin library -EXTRA_LIBS += ${shell $(CC) $(ARCHCPUFLAGS) --print-libgcc-file-name} +EXTRA_LIBS += ${wildcard ${shell $(CC) $(ARCHCPUFLAGS) --print-libgcc-file-name}} ifneq ($(CONFIG_LIBM),y) EXTRA_LIBS += ${wildcard ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libm.a}} endif ifeq ($(CONFIG_LIBSUPCXX),y) - EXTRA_LIBS += ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libsupc++.a} + EXTRA_LIBS += ${wildcard ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libsupc++.a}} endif diff --git a/arch/risc-v/src/common/riscv_copyfullstate.c b/arch/risc-v/src/common/addrenv.h similarity index 67% rename from arch/risc-v/src/common/riscv_copyfullstate.c rename to arch/risc-v/src/common/addrenv.h index 9ccd46b892d42..fc89138984372 100644 --- a/arch/risc-v/src/common/riscv_copyfullstate.c +++ b/arch/risc-v/src/common/addrenv.h @@ -1,5 +1,5 @@ /**************************************************************************** - * arch/risc-v/src/common/riscv_copyfullstate.c + * arch/risc-v/src/common/addrenv.h * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -18,45 +18,35 @@ * ****************************************************************************/ +#ifndef __ARCH_RISC_V_SRC_COMMON_ADDRENV_H +#define __ARCH_RISC_V_SRC_COMMON_ADDRENV_H + /**************************************************************************** * Included Files ****************************************************************************/ #include +#include #include -#include #include "riscv_internal.h" +#ifdef CONFIG_ARCH_ADDRENV + /**************************************************************************** - * Public Functions + * Pre-processor Definitions ****************************************************************************/ +/* Aligned size of the kernel stack */ + +#ifdef CONFIG_ARCH_KERNEL_STACK +# define ARCH_KERNEL_STACKSIZE STACK_ALIGN_UP(CONFIG_ARCH_KERNEL_STACKSIZE) +#endif + /**************************************************************************** - * Name: riscv_copyfullstate - * - * Description: - * Copy the entire register save area (including the floating point - * registers if applicable). This is a little faster than most memcpy's - * since it does 32-bit transfers. - * + * Public Function Prototypes ****************************************************************************/ -void riscv_copyfullstate(uintptr_t *dest, uintptr_t *src) -{ - int i; - - /* In the RV32 targets, the state is copied from the stack to the TCB, - * but only a reference is passed to get the state from the TCB. So the - * following check avoids copying the TCB save area onto itself: - */ - - if (src != dest) - { - for (i = 0; i < XCPTCONTEXT_REGS; i++) - { - *dest++ = *src++; - } - } -} +#endif /* CONFIG_ARCH_ADDRENV */ +#endif /* __ARCH_RISC_V_SRC_COMMON_ADDRENV_H */ diff --git a/arch/risc-v/src/common/riscv_addrenv_kstack.c b/arch/risc-v/src/common/riscv_addrenv_kstack.c new file mode 100644 index 0000000000000..c0fd0f0a1556e --- /dev/null +++ b/arch/risc-v/src/common/riscv_addrenv_kstack.c @@ -0,0 +1,111 @@ +/**************************************************************************** + * arch/risc-v/src/common/riscv_addrenv_kstack.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include +#include +#include +#include + +#include "addrenv.h" +#include "riscv_internal.h" + +#if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_ARCH_KERNEL_STACK) + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: up_addrenv_kstackalloc + * + * Description: + * This function is called when a new thread is created to allocate + * the new thread's kernel stack. This function may be called for certain + * terminating threads which have no kernel stack. It must be tolerant of + * that case. + * + * Input Parameters: + * tcb - The TCB of the thread that requires the kernel stack. + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int up_addrenv_kstackalloc(FAR struct tcb_s *tcb) +{ + DEBUGASSERT(tcb && tcb->xcp.kstack == NULL); + + /* Allocate the kernel stack */ + + tcb->xcp.kstack = (uintptr_t *)kmm_memalign(STACK_ALIGNMENT, + ARCH_KERNEL_STACKSIZE); + if (!tcb->xcp.kstack) + { + berr("ERROR: Failed to allocate the kernel stack\n"); + return -ENOMEM; + } + + return OK; +} + +/**************************************************************************** + * Name: up_addrenv_kstackfree + * + * Description: + * This function is called when any thread exits. This function frees + * the kernel stack. + * + * Input Parameters: + * tcb - The TCB of the thread that no longer requires the kernel stack. + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int up_addrenv_kstackfree(FAR struct tcb_s *tcb) +{ + DEBUGASSERT(tcb); + + /* Does the exiting thread have a kernel stack? */ + + if (tcb->xcp.kstack) + { + /* Yes.. Free the kernel stack */ + + kmm_free(tcb->xcp.kstack); + tcb->xcp.kstack = NULL; + } + + return OK; +} + +#endif /* CONFIG_ARCH_ADDRENV && CONFIG_ARCH_KERNEL_STACK */ diff --git a/arch/risc-v/src/common/riscv_assert.c b/arch/risc-v/src/common/riscv_assert.c index d0c0416241d1f..39b6a2b49321f 100644 --- a/arch/risc-v/src/common/riscv_assert.c +++ b/arch/risc-v/src/common/riscv_assert.c @@ -175,6 +175,9 @@ static void riscv_dump_task(struct tcb_s *tcb, void *arg) /* Dump interesting properties of this task */ _alert(" %4d %4d" +#ifdef CONFIG_SMP + " %4d" +#endif #ifdef CONFIG_STACK_COLORATION " %7lu" #endif @@ -190,6 +193,9 @@ static void riscv_dump_task(struct tcb_s *tcb, void *arg) #endif "\n", tcb->pid, tcb->sched_priority, +#ifdef CONFIG_SMP + tcb->cpu, +#endif #ifdef CONFIG_STACK_COLORATION (unsigned long)up_check_tcbstack(tcb), #endif @@ -244,6 +250,9 @@ static inline void riscv_showtasks(void) /* Dump interesting properties of each task in the crash environment */ _alert(" PID PRI" +#ifdef CONFIG_SMP + " CPU" +#endif #ifdef CONFIG_STACK_COLORATION " USED" #endif @@ -261,6 +270,9 @@ static inline void riscv_showtasks(void) #if CONFIG_ARCH_INTERRUPTSTACK > 15 _alert(" ---- ----" +# ifdef CONFIG_SMP + " ----" +# endif # ifdef CONFIG_STACK_COLORATION " %7lu" # endif @@ -306,6 +318,9 @@ static void riscv_dumpstate(void) uintptr_t istackbase; uintptr_t istacksize; #endif +#ifdef CONFIG_ARCH_KERNEL_STACK + uintptr_t kstackbase = 0; +#endif /* Show back trace */ @@ -383,18 +398,46 @@ static void riscv_dumpstate(void) _alert("stack size: %" PRIxREG "\n", ustacksize); #endif +#ifdef CONFIG_ARCH_KERNEL_STACK + /* Does this thread have a kernel stack allocated? */ + + if (rtcb->xcp.kstack) + { + kstackbase = (uintptr_t)rtcb->xcp.kstack; + + _alert("Kernel stack:\n"); + _alert(" base: %" PRIxREG "\n", kstackbase); + _alert(" size: %" PRIxREG "\n", CONFIG_ARCH_KERNEL_STACKSIZE); + } +#endif + /* Dump the user stack if the stack pointer lies within the allocated user * stack memory. */ if (sp >= ustackbase && sp < ustackbase + ustacksize) { - _alert("ERROR: Stack pointer is not within allocated stack\n"); - riscv_stackdump(ustackbase, ustackbase + ustacksize); + _alert("User Stack\n"); + riscv_stackdump(sp, ustackbase + ustacksize); } + +#ifdef CONFIG_ARCH_KERNEL_STACK + /* Dump the kernel stack if the stack pointer lies within the allocated + * kernel stack memory. + */ + + else if (kstackbase != 0 && + sp >= kstackbase && + sp < kstackbase + CONFIG_ARCH_KERNEL_STACKSIZE) + { + _alert("Kernel Stack\n"); + riscv_stackdump(sp, kstackbase + CONFIG_ARCH_KERNEL_STACKSIZE); + } +#endif else { - riscv_stackdump(sp, ustackbase + ustacksize); + _alert("ERROR: Stack pointer is not within allocated stack\n"); + riscv_stackdump(ustackbase, ustackbase + ustacksize); } } #else diff --git a/arch/risc-v/src/common/riscv_blocktask.c b/arch/risc-v/src/common/riscv_blocktask.c index 45aa779cc9d17..00fa65d0ab66c 100644 --- a/arch/risc-v/src/common/riscv_blocktask.c +++ b/arch/risc-v/src/common/riscv_blocktask.c @@ -151,7 +151,7 @@ void up_block_task(struct tcb_s *tcb, tstate_t task_state) /* Then switch contexts */ - riscv_switchcontext(rtcb->xcp.regs, nexttcb->xcp.regs); + riscv_switchcontext(&rtcb->xcp.regs, nexttcb->xcp.regs); /* riscv_switchcontext forces a context switch to the task at the * head of the ready-to-run list. It does not 'return' in the diff --git a/arch/risc-v/src/common/riscv_exception_common.S b/arch/risc-v/src/common/riscv_exception_common.S index d5ba803a437a3..4d5665ac2dc4a 100644 --- a/arch/risc-v/src/common/riscv_exception_common.S +++ b/arch/risc-v/src/common/riscv_exception_common.S @@ -107,24 +107,37 @@ exception_common: #if CONFIG_ARCH_INTERRUPTSTACK > 15 /* Load mhartid (cpuid) */ - csrr s0, mhartid + csrr s0, mhartid /* Switch to interrupt stack */ #if IRQ_NSTACKS > 1 - li t0, (CONFIG_ARCH_INTERRUPTSTACK & ~15) - mul t0, s0, t0 - la s0, g_intstacktop - sub sp, s0, t0 + li t0, (CONFIG_ARCH_INTERRUPTSTACK & ~15) + mul t0, s0, t0 + la s0, g_intstacktop + sub sp, s0, t0 #else - la sp, g_intstacktop + la sp, g_intstacktop #endif -#endif + /* Call interrupt handler in C */ + + jal x1, riscv_dispatch_irq + +#else + /* Reserve some space for CURRENT_REGS if interrupt stack disabled */ + + addi sp, sp, -XCPTCONTEXT_SIZE /* Call interrupt handler in C */ jal x1, riscv_dispatch_irq + /* Restore sp */ + + addi sp, sp, XCPTCONTEXT_SIZE +#endif + + /* If context switch is needed, return a new sp */ mv sp, a0 diff --git a/arch/risc-v/src/common/riscv_initialstate.c b/arch/risc-v/src/common/riscv_initialstate.c index f83eeb3b24897..95de7b37e74fb 100644 --- a/arch/risc-v/src/common/riscv_initialstate.c +++ b/arch/risc-v/src/common/riscv_initialstate.c @@ -32,6 +32,7 @@ #include #include "riscv_internal.h" + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -55,9 +56,13 @@ void up_initial_state(struct tcb_s *tcb) struct xcptcontext *xcp = &tcb->xcp; uintptr_t regval; + /* Initialize the initial exception register context structure */ + + memset(xcp, 0, sizeof(struct xcptcontext)); + /* Initialize the idle thread stack */ - if (tcb->pid == 0) + if (tcb->pid == IDLE_PROCESS_ID) { tcb->stack_alloc_ptr = (void *)(g_idle_topstack - CONFIG_IDLETHREAD_STACKSIZE); @@ -72,11 +77,13 @@ void up_initial_state(struct tcb_s *tcb) riscv_stack_color(tcb->stack_alloc_ptr, 0); #endif /* CONFIG_STACK_COLORATION */ + return; } - /* Initialize the initial exception register context structure */ + xcp->regs = (uintptr_t *)( + (uintptr_t)tcb->stack_base_ptr + tcb->adj_stack_size - XCPTCONTEXT_SIZE); - memset(xcp, 0, sizeof(struct xcptcontext)); + memset(xcp->regs, 0, XCPTCONTEXT_SIZE); /* Save the initial stack pointer. Hmmm.. the stack is set to the very * beginning of the stack region. Some functions may want to store data on diff --git a/arch/risc-v/src/common/riscv_internal.h b/arch/risc-v/src/common/riscv_internal.h index 7c5a73f4e52e9..acdc9e788f2a6 100644 --- a/arch/risc-v/src/common/riscv_internal.h +++ b/arch/risc-v/src/common/riscv_internal.h @@ -68,7 +68,11 @@ * only a referenced is passed to get the state from the TCB. */ -#define riscv_savestate(regs) riscv_copystate(regs, (uintptr_t*)CURRENT_REGS) +#ifdef CONFIG_ARCH_FPU +#define riscv_savestate(regs) (regs = (uintptr_t *)CURRENT_REGS, riscv_savefpu(regs)) +#else +#define riscv_savestate(regs) (regs = (uintptr_t *)CURRENT_REGS) +#endif #define riscv_restorestate(regs) (CURRENT_REGS = regs) #define _START_TEXT &_stext @@ -193,7 +197,6 @@ void riscv_addregion(void); void riscv_ack_irq(int irq); void riscv_copystate(uintptr_t *dest, uintptr_t *src); -void riscv_copyfullstate(uintptr_t *dest, uintptr_t *src); void riscv_sigdeliver(void); int riscv_swint(int irq, void *context, void *arg); diff --git a/arch/risc-v/src/common/riscv_releasepending.c b/arch/risc-v/src/common/riscv_releasepending.c index 18f791581c513..234c660c6b6a6 100644 --- a/arch/risc-v/src/common/riscv_releasepending.c +++ b/arch/risc-v/src/common/riscv_releasepending.c @@ -122,7 +122,7 @@ void up_release_pending(void) /* Then switch contexts */ - riscv_switchcontext(rtcb->xcp.regs, nexttcb->xcp.regs); + riscv_switchcontext(&rtcb->xcp.regs, nexttcb->xcp.regs); /* riscv_switchcontext forces a context switch to the task at the * head of the ready-to-run list. It does not 'return' in the diff --git a/arch/risc-v/src/common/riscv_reprioritizertr.c b/arch/risc-v/src/common/riscv_reprioritizertr.c index 8cb46f49091fd..c9d42232e5f0b 100644 --- a/arch/risc-v/src/common/riscv_reprioritizertr.c +++ b/arch/risc-v/src/common/riscv_reprioritizertr.c @@ -174,7 +174,7 @@ void up_reprioritize_rtr(struct tcb_s *tcb, uint8_t priority) /* Then switch contexts */ - riscv_switchcontext(rtcb->xcp.regs, nexttcb->xcp.regs); + riscv_switchcontext(&rtcb->xcp.regs, nexttcb->xcp.regs); /* riscv_switchcontext forces a context switch to the task at * the head of the ready-to-run list. It does not 'return' in diff --git a/arch/risc-v/src/common/riscv_schedulesigaction.c b/arch/risc-v/src/common/riscv_schedulesigaction.c index 0b5ef29483fa3..e8c5eab946a45 100644 --- a/arch/risc-v/src/common/riscv_schedulesigaction.c +++ b/arch/risc-v/src/common/riscv_schedulesigaction.c @@ -35,6 +35,7 @@ #include "sched/sched.h" #include "riscv_internal.h" + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -120,22 +121,33 @@ void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver) else { - /* Save the return EPC and STATUS registers. These will be + /* Save the context registers. These will be * restored by the signal trampoline after the signals have * been delivered. */ - tcb->xcp.sigdeliver = sigdeliver; - tcb->xcp.saved_epc = CURRENT_REGS[REG_EPC]; - tcb->xcp.saved_int_ctx = CURRENT_REGS[REG_INT_CTX]; + tcb->xcp.saved_regs = (uintptr_t *)CURRENT_REGS; + + riscv_savestate(tcb->xcp.saved_regs); + + /* Duplicate the register context. These will be + * restored by the signal trampoline after the signal has + * been delivered. + */ + + CURRENT_REGS = (uintptr_t *)((uintptr_t)CURRENT_REGS - + XCPTCONTEXT_SIZE); + + memcpy((uintptr_t *)CURRENT_REGS, tcb->xcp.saved_regs, + XCPTCONTEXT_SIZE); /* Then set up to vector to the trampoline with interrupts * disabled. The kernel-space trampoline must run in * privileged thread mode. */ - CURRENT_REGS[REG_EPC] = (uintptr_t)riscv_sigdeliver; - + tcb->xcp.sigdeliver = sigdeliver; + CURRENT_REGS[REG_EPC] = (uintptr_t)riscv_sigdeliver; int_ctx = CURRENT_REGS[REG_INT_CTX]; int_ctx &= ~MSTATUS_MPIE; #ifndef CONFIG_BUILD_FLAT @@ -144,15 +156,13 @@ void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver) CURRENT_REGS[REG_INT_CTX] = int_ctx; - /* And make sure that the saved context in the TCB - * is the same as the interrupt return context. - */ - - riscv_savestate(tcb->xcp.regs); + CURRENT_REGS[REG_SP] = (uintptr_t)CURRENT_REGS + + XCPTCONTEXT_SIZE; sinfo("PC/STATUS Saved: %" PRIxREG "/%" PRIxREG " New: %" PRIxREG "/%" PRIxREG "\n", - tcb->xcp.saved_epc, tcb->xcp.saved_int_ctx, + tcb->xcp.saved_regs[REG_EPC], + tcb->xcp.saved_regs[REG_INT_CTX], CURRENT_REGS[REG_EPC], CURRENT_REGS[REG_INT_CTX]); } } @@ -170,17 +180,26 @@ void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver) * been delivered. */ - tcb->xcp.sigdeliver = sigdeliver; - tcb->xcp.saved_epc = tcb->xcp.regs[REG_EPC]; - tcb->xcp.saved_int_ctx = tcb->xcp.regs[REG_INT_CTX]; + tcb->xcp.sigdeliver = sigdeliver; - /* Then set up to vector to the trampoline with interrupts - * disabled. We must already be in privileged thread mode to be - * here. + /* Save the current register context location */ + + tcb->xcp.saved_regs = tcb->xcp.regs; + + /* Duplicate the register context. These will be + * restored by the signal trampoline after the signal has been + * delivered. */ - tcb->xcp.regs[REG_EPC] = (uintptr_t)riscv_sigdeliver; + tcb->xcp.regs = (uintptr_t *)((uintptr_t)tcb->xcp.regs - + XCPTCONTEXT_SIZE); + + memcpy(tcb->xcp.regs, tcb->xcp.saved_regs, XCPTCONTEXT_SIZE); + + tcb->xcp.regs[REG_SP] = (uintptr_t)tcb->xcp.regs + + XCPTCONTEXT_SIZE; + tcb->xcp.regs[REG_EPC] = (uintptr_t)riscv_sigdeliver; int_ctx = tcb->xcp.regs[REG_INT_CTX]; int_ctx &= ~MSTATUS_MPIE; @@ -188,7 +207,8 @@ void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver) sinfo("PC/STATUS Saved: %" PRIxREG "/%" PRIxREG " New: %" PRIxREG "/%" PRIxREG "\n", - tcb->xcp.saved_epc, tcb->xcp.saved_int_ctx, + tcb->xcp.saved_regs[REG_EPC], + tcb->xcp.saved_regs[REG_INT_CTX], tcb->xcp.regs[REG_EPC], tcb->xcp.regs[REG_INT_CTX]); } } @@ -265,34 +285,65 @@ void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver) * been delivered. */ - tcb->xcp.sigdeliver = (void *)sigdeliver; - tcb->xcp.saved_epc = tcb->xcp.regs[REG_EPC]; - tcb->xcp.saved_int_ctx = tcb->xcp.regs[REG_INT_CTX]; + tcb->xcp.sigdeliver = sigdeliver; /* Then set up vector to the trampoline with interrupts * disabled. We must already be in privileged thread mode * to be here. */ - tcb->xcp.regs[REG_EPC] = (uintptr_t)riscv_sigdeliver; + /* Save the current register context location */ - int_ctx = tcb->xcp.regs[REG_INT_CTX]; - int_ctx &= ~MSTATUS_MPIE; + tcb->xcp.saved_regs = tcb->xcp.regs; + /* Duplicate the register context. These will be + * restored by the signal trampoline after the signal has + * been delivered. + */ + + tcb->xcp.regs = (uintptr_t *)((uintptr_t)tcb->xcp.regs - + XCPTCONTEXT_SIZE); + + memcpy(tcb->xcp.regs, tcb->xcp.saved_regs, + XCPTCONTEXT_SIZE); + + tcb->xcp.regs[REG_SP] = (uintptr_t)tcb->xcp.regs + + XCPTCONTEXT_SIZE; + + tcb->xcp.regs[REG_EPC] = (uintptr_t)riscv_sigdeliver; + int_ctx = tcb->xcp.regs[REG_INT_CTX]; + int_ctx &= ~MSTATUS_MPIE; +#ifdef CONFIG_BUILD_PROTECTED + int_ctx |= MSTATUS_MPPM; +#endif tcb->xcp.regs[REG_INT_CTX] = int_ctx; } else { /* tcb is running on the same CPU */ - /* Save the return EPC and STATUS registers. These will be + /* Save the context registers. These will be * restored by the signal trampoline after the signal has * been delivered. */ - tcb->xcp.sigdeliver = (void *)sigdeliver; - tcb->xcp.saved_epc = CURRENT_REGS[REG_EPC]; - tcb->xcp.saved_int_ctx = CURRENT_REGS[REG_INT_CTX]; + tcb->xcp.sigdeliver = (void *)sigdeliver; + + tcb->xcp.saved_regs = (uintptr_t *)CURRENT_REGS; + + /* Duplicate the register context. These will be + * restored by the signal trampoline after the signal has + * been delivered. + */ + + CURRENT_REGS = (uintptr_t *)((uintptr_t)CURRENT_REGS - + XCPTCONTEXT_SIZE); + + memcpy((uintptr_t *)CURRENT_REGS, tcb->xcp.saved_regs, + XCPTCONTEXT_SIZE); + + CURRENT_REGS[REG_SP] = (uintptr_t)CURRENT_REGS + + XCPTCONTEXT_SIZE; /* Then set up vector to the trampoline with interrupts * disabled. The kernel-space trampoline must run in @@ -302,18 +353,12 @@ void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver) CURRENT_REGS[REG_EPC] = (uintptr_t)riscv_sigdeliver; int_ctx = CURRENT_REGS[REG_INT_CTX]; - int_ctx &= ~MSTATUS_MPIE; + int_ctx &= ~MSTATUS_MPIE; #ifndef CONFIG_BUILD_FLAT - int_ctx |= MSTATUS_MPPM; + int_ctx |= MSTATUS_MPPM; #endif CURRENT_REGS[REG_INT_CTX] = int_ctx; - - /* And make sure that the saved context in the TCB is the - * same as the interrupt return context. - */ - - riscv_savestate(tcb->xcp.regs); } /* Increment the IRQ lock count so that when the task is @@ -351,8 +396,23 @@ void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver) */ tcb->xcp.sigdeliver = (void *)sigdeliver; - tcb->xcp.saved_epc = tcb->xcp.regs[REG_EPC]; - tcb->xcp.saved_int_ctx = tcb->xcp.regs[REG_INT_CTX]; + + /* Save the current register context location */ + + tcb->xcp.saved_regs = tcb->xcp.regs; + + /* Duplicate the register context. These will be + * restored by the signal trampoline after the signal has been + * delivered. + */ + + tcb->xcp.regs = (uintptr_t *)((uintptr_t)tcb->xcp.regs - + XCPTCONTEXT_SIZE); + + memcpy(tcb->xcp.regs, tcb->xcp.saved_regs, XCPTCONTEXT_SIZE); + + tcb->xcp.regs[REG_SP] = (uintptr_t)tcb->xcp.regs + + XCPTCONTEXT_SIZE; /* Increment the IRQ lock count so that when the task is restarted, * it will hold the IRQ spinlock. @@ -366,12 +426,12 @@ void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver) * here. */ - tcb->xcp.regs[REG_EPC] = (uintptr_t)riscv_sigdeliver; + tcb->xcp.regs[REG_EPC] = (uintptr_t)riscv_sigdeliver; - int_ctx = tcb->xcp.regs[REG_INT_CTX]; - int_ctx &= ~MSTATUS_MPIE; + int_ctx = tcb->xcp.regs[REG_INT_CTX]; + int_ctx &= ~MSTATUS_MPIE; - tcb->xcp.regs[REG_INT_CTX] = int_ctx; + tcb->xcp.regs[REG_INT_CTX] = int_ctx; } } } diff --git a/arch/risc-v/src/common/riscv_sigdeliver.c b/arch/risc-v/src/common/riscv_sigdeliver.c index 153c3ecd0fb02..ac817be55ac57 100644 --- a/arch/risc-v/src/common/riscv_sigdeliver.c +++ b/arch/risc-v/src/common/riscv_sigdeliver.c @@ -55,7 +55,7 @@ void riscv_sigdeliver(void) { struct tcb_s *rtcb = this_task(); - uintptr_t regs[XCPTCONTEXT_REGS]; + uintptr_t *regs = rtcb->xcp.saved_regs; #ifdef CONFIG_SMP /* In the SMP case, we must terminate the critical section while the signal @@ -72,10 +72,6 @@ void riscv_sigdeliver(void) rtcb, rtcb->xcp.sigdeliver, rtcb->sigpendactionq.head); DEBUGASSERT(rtcb->xcp.sigdeliver != NULL); - /* Save the return state on the stack. */ - - riscv_copyfullstate(regs, rtcb->xcp.regs); - #ifdef CONFIG_SMP /* In the SMP case, up_schedule_sigaction(0) will have incremented * 'irqcount' in order to force us into a critical section. Save the @@ -142,8 +138,6 @@ void riscv_sigdeliver(void) * could be modified by a hostile program. */ - regs[REG_EPC] = rtcb->xcp.saved_epc; - regs[REG_INT_CTX] = rtcb->xcp.saved_int_ctx; rtcb->xcp.sigdeliver = NULL; /* Allows next handler to be scheduled */ /* Then restore the correct state for this thread of diff --git a/arch/risc-v/src/common/riscv_swint.c b/arch/risc-v/src/common/riscv_swint.c index 95d20e86a3adc..91865d62193f7 100644 --- a/arch/risc-v/src/common/riscv_swint.c +++ b/arch/risc-v/src/common/riscv_swint.c @@ -41,6 +41,7 @@ #include "signal/signal.h" #include "riscv_internal.h" +#include "addrenv.h" /**************************************************************************** * Pre-processor Definitions @@ -205,7 +206,7 @@ int riscv_swint(int irq, void *context, void *arg) /* A0=SYS_restore_context: This a restore context command: * * void - * riscv_fullcontextrestore(uint32_t *restoreregs) noreturn_function; + * riscv_fullcontextrestore(uintptr_t *restoreregs) noreturn_function; * * At this point, the following values are saved in context: * @@ -227,7 +228,8 @@ int riscv_swint(int irq, void *context, void *arg) /* A0=SYS_switch_context: This a switch context command: * - * void riscv_switchcontext(uint64_t *saveregs, uint64_t *restoreregs); + * void + * riscv_switchcontext(uintptr_t *saveregs, uintptr_t *restoreregs); * * At this point, the following values are saved in context: * @@ -244,7 +246,10 @@ int riscv_swint(int irq, void *context, void *arg) case SYS_switch_context: { DEBUGASSERT(regs[REG_A1] != 0 && regs[REG_A2] != 0); - riscv_copystate((uintptr_t *)regs[REG_A1], regs); +#ifdef CONFIG_ARCH_FPU + riscv_savefpu(regs); +#endif + *(uintptr_t **)regs[REG_A1] = (uintptr_t *)regs; CURRENT_REGS = (uintptr_t *)regs[REG_A2]; } break; @@ -286,6 +291,19 @@ int riscv_swint(int irq, void *context, void *arg) regs[REG_A0] = regs[REG_A2]; +#ifdef CONFIG_ARCH_KERNEL_STACK + /* If this is the outermost SYSCALL and if there is a saved user + * stack pointer, then restore the user stack pointer on this + * final return to user code. + */ + + if (index == 0 && rtcb->xcp.ustkptr != NULL) + { + regs[REG_SP] = (uintptr_t)rtcb->xcp.ustkptr; + rtcb->xcp.ustkptr = NULL; + } +#endif + /* Save the new SYSCALL nesting level */ rtcb->xcp.nsyscalls = index; @@ -415,6 +433,24 @@ int riscv_swint(int irq, void *context, void *arg) regs[REG_A1] = regs[REG_A2]; /* signal */ regs[REG_A2] = regs[REG_A3]; /* info */ regs[REG_A3] = regs[REG_A4]; /* ucontext */ + +#ifdef CONFIG_ARCH_KERNEL_STACK + /* If we are signalling a user process, then we must be operating + * on the kernel stack now. We need to switch back to the user + * stack before dispatching the signal handler to the user code. + * The existence of an allocated kernel stack is sufficient + * information to make this decision. + */ + + if (rtcb->xcp.kstack != NULL) + { + DEBUGASSERT(rtcb->xcp.kstkptr == NULL && + rtcb->xcp.ustkptr != NULL); + + rtcb->xcp.kstkptr = (uintptr_t *)regs[REG_SP]; + regs[REG_SP] = (uintptr_t)rtcb->xcp.ustkptr; + } +#endif } break; #endif @@ -440,6 +476,22 @@ int riscv_swint(int irq, void *context, void *arg) regs[REG_INT_CTX] |= MSTATUS_MPPM; /* Machine mode */ rtcb->xcp.sigreturn = 0; + +#ifdef CONFIG_ARCH_KERNEL_STACK + /* We must enter here be using the user stack. We need to switch + * to back to the kernel user stack before returning to the kernel + * mode signal trampoline. + */ + + if (rtcb->xcp.kstack != NULL) + { + DEBUGASSERT(rtcb->xcp.kstkptr != NULL && + (uintptr_t)rtcb->xcp.ustkptr == regs[REG_SP]); + + regs[REG_SP] = (uintptr_t)rtcb->xcp.kstkptr; + rtcb->xcp.kstkptr = NULL; + } +#endif } break; #endif @@ -490,6 +542,19 @@ int riscv_swint(int irq, void *context, void *arg) #else svcerr("ERROR: Bad SYS call: %" PRIdPTR "\n", regs[REG_A0]); #endif + +#ifdef CONFIG_ARCH_KERNEL_STACK + /* If this is the first SYSCALL and if there is an allocated + * kernel stack, then switch to the kernel stack. + */ + + if (index == 0 && rtcb->xcp.kstack != NULL) + { + rtcb->xcp.ustkptr = (uintptr_t *)regs[REG_SP]; + regs[REG_SP] = (uintptr_t)rtcb->xcp.kstack + + ARCH_KERNEL_STACKSIZE; + } +#endif } break; } diff --git a/arch/risc-v/src/common/riscv_unblocktask.c b/arch/risc-v/src/common/riscv_unblocktask.c index 6aa94c9489377..678f895871253 100644 --- a/arch/risc-v/src/common/riscv_unblocktask.c +++ b/arch/risc-v/src/common/riscv_unblocktask.c @@ -137,7 +137,7 @@ void up_unblock_task(struct tcb_s *tcb) /* Then switch contexts */ - riscv_switchcontext(rtcb->xcp.regs, nexttcb->xcp.regs); + riscv_switchcontext(&rtcb->xcp.regs, nexttcb->xcp.regs); /* riscv_switchcontext forces a context switch to the task at the * head of the ready-to-run list. It does not 'return' in the diff --git a/arch/risc-v/src/esp32c3/Make.defs b/arch/risc-v/src/esp32c3/Make.defs index bfa54a7df77b7..7bc2fbb61e3a6 100644 --- a/arch/risc-v/src/esp32c3/Make.defs +++ b/arch/risc-v/src/esp32c3/Make.defs @@ -33,7 +33,7 @@ CMN_CSRCS += riscv_initialize.c riscv_swint.c CMN_CSRCS += riscv_allocateheap.c riscv_createstack.c riscv_exit.c riscv_exception.c CMN_CSRCS += riscv_assert.c riscv_blocktask.c riscv_copystate.c riscv_initialstate.c CMN_CSRCS += riscv_interruptcontext.c riscv_modifyreg32.c riscv_puts.c riscv_mdelay.c -CMN_CSRCS += riscv_releasepending.c riscv_reprioritizertr.c riscv_copyfullstate.c +CMN_CSRCS += riscv_releasepending.c riscv_reprioritizertr.c CMN_CSRCS += riscv_releasestack.c riscv_stackframe.c riscv_schedulesigaction.c CMN_CSRCS += riscv_sigdeliver.c riscv_udelay.c riscv_unblocktask.c riscv_usestack.c CMN_CSRCS += riscv_tcbinfo.c riscv_getnewintctx.c diff --git a/arch/risc-v/src/esp32c3/esp32c3_ble_adapter.c b/arch/risc-v/src/esp32c3/esp32c3_ble_adapter.c index dba1b98d78936..ceaa9bcdfaa3d 100644 --- a/arch/risc-v/src/esp32c3/esp32c3_ble_adapter.c +++ b/arch/risc-v/src/esp32c3/esp32c3_ble_adapter.c @@ -553,7 +553,7 @@ static int32_t esp_task_create_pinned_to_core(void *entry, wlerr("Failed to create task\n"); } - return pid > 0 ? true : false; + return pid > 0; } /**************************************************************************** diff --git a/arch/risc-v/src/esp32c3/esp32c3_rt_timer.c b/arch/risc-v/src/esp32c3/esp32c3_rt_timer.c index f7c148a4c9d5b..3ea81a3bc7ccd 100644 --- a/arch/risc-v/src/esp32c3/esp32c3_rt_timer.c +++ b/arch/risc-v/src/esp32c3/esp32c3_rt_timer.c @@ -68,7 +68,7 @@ struct esp32c3_rt_priv_s { - int pid; + pid_t pid; sem_t toutsem; struct list_node runlist; struct list_node toutlist; @@ -81,7 +81,7 @@ struct esp32c3_rt_priv_s static struct esp32c3_rt_priv_s g_rt_priv = { - .pid = -EINVAL, + .pid = INVALID_PROCESS_ID, }; /**************************************************************************** @@ -736,7 +736,7 @@ int esp32c3_rt_timer_init(void) list_initialize(&priv->runlist); list_initialize(&priv->toutlist); - priv->pid = pid; + priv->pid = (pid_t)pid; flags = enter_critical_section(); @@ -789,10 +789,10 @@ void esp32c3_rt_timer_deinit(void) leave_critical_section(flags); - if (priv->pid != -EINVAL) + if (priv->pid != INVALID_PROCESS_ID) { kthread_delete(priv->pid); - priv->pid = -EINVAL; + priv->pid = INVALID_PROCESS_ID; } nxsem_destroy(&priv->toutsem); diff --git a/arch/risc-v/src/esp32c3/esp32c3_wifi_adapter.c b/arch/risc-v/src/esp32c3/esp32c3_wifi_adapter.c index 343c8aaef2c4f..321d196e363f7 100644 --- a/arch/risc-v/src/esp32c3/esp32c3_wifi_adapter.c +++ b/arch/risc-v/src/esp32c3/esp32c3_wifi_adapter.c @@ -1997,7 +1997,7 @@ static int32_t esp_task_create_pinned_to_core(void *entry, wlerr("ERROR: Failed to create task\n"); } - return pid > 0 ? true : false; + return pid > 0; } /**************************************************************************** diff --git a/arch/risc-v/src/fe310/Make.defs b/arch/risc-v/src/fe310/Make.defs index dcb63384f50b3..4e91ca053b277 100644 --- a/arch/risc-v/src/fe310/Make.defs +++ b/arch/risc-v/src/fe310/Make.defs @@ -30,7 +30,7 @@ CMN_CSRCS += riscv_initialize.c riscv_swint.c CMN_CSRCS += riscv_allocateheap.c riscv_createstack.c riscv_exit.c CMN_CSRCS += riscv_assert.c riscv_blocktask.c riscv_copystate.c riscv_initialstate.c CMN_CSRCS += riscv_interruptcontext.c riscv_modifyreg32.c riscv_puts.c riscv_mdelay.c -CMN_CSRCS += riscv_releasepending.c riscv_reprioritizertr.c riscv_copyfullstate.c +CMN_CSRCS += riscv_releasepending.c riscv_reprioritizertr.c CMN_CSRCS += riscv_releasestack.c riscv_stackframe.c riscv_schedulesigaction.c CMN_CSRCS += riscv_sigdeliver.c riscv_udelay.c riscv_unblocktask.c riscv_usestack.c CMN_CSRCS += riscv_idle.c riscv_tcbinfo.c riscv_getnewintctx.c diff --git a/arch/risc-v/src/fe310/fe310_irq.c b/arch/risc-v/src/fe310/fe310_irq.c index 9e0e17a0e4099..1a44ccf4bb508 100644 --- a/arch/risc-v/src/fe310/fe310_irq.c +++ b/arch/risc-v/src/fe310/fe310_irq.c @@ -38,6 +38,12 @@ #include "riscv_internal.h" #include "fe310.h" +/**************************************************************************** + * Public Data + ****************************************************************************/ + +volatile uintptr_t *g_current_regs[1]; + /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/arch/risc-v/src/fe310/fe310_irq_dispatch.c b/arch/risc-v/src/fe310/fe310_irq_dispatch.c index 906594d8c0b4d..898f1c3157a71 100644 --- a/arch/risc-v/src/fe310/fe310_irq_dispatch.c +++ b/arch/risc-v/src/fe310/fe310_irq_dispatch.c @@ -37,10 +37,10 @@ #include "fe310.h" /**************************************************************************** - * Public Data + * Pre-processor Definitions ****************************************************************************/ -volatile uintptr_t *g_current_regs[1]; +#define RV_IRQ_MASK 27 /**************************************************************************** * Public Functions @@ -52,7 +52,7 @@ volatile uintptr_t *g_current_regs[1]; void *riscv_dispatch_irq(uintptr_t vector, uintptr_t *regs) { - uintptr_t irq = (vector >> 27) | (vector & 0xf); + int irq = (vector >> RV_IRQ_MASK) | (vector & 0xf); uintptr_t *mepc = regs; /* Firstly, check if the irq is machine external interrupt */ diff --git a/arch/risc-v/src/k210/Make.defs b/arch/risc-v/src/k210/Make.defs index 38ac64f67863f..7f22688893f51 100644 --- a/arch/risc-v/src/k210/Make.defs +++ b/arch/risc-v/src/k210/Make.defs @@ -33,7 +33,7 @@ CMN_CSRCS += riscv_interruptcontext.c riscv_modifyreg32.c riscv_puts.c CMN_CSRCS += riscv_releasepending.c riscv_reprioritizertr.c CMN_CSRCS += riscv_releasestack.c riscv_stackframe.c riscv_schedulesigaction.c CMN_CSRCS += riscv_sigdeliver.c riscv_unblocktask.c riscv_usestack.c -CMN_CSRCS += riscv_mdelay.c riscv_copyfullstate.c riscv_idle.c +CMN_CSRCS += riscv_mdelay.c riscv_idle.c CMN_CSRCS += riscv_tcbinfo.c riscv_cpuidlestack.c riscv_getnewintctx.c ifeq ($(CONFIG_SMP), y) diff --git a/arch/risc-v/src/k210/k210_head.S b/arch/risc-v/src/k210/k210_head.S index 1930806f99dd9..03045997e3dc1 100644 --- a/arch/risc-v/src/k210/k210_head.S +++ b/arch/risc-v/src/k210/k210_head.S @@ -73,9 +73,14 @@ __start: ld sp, 0(t0) - /* sp (stack top) = sp + idle stack size */ - - li t0, CONFIG_IDLETHREAD_STACKSIZE + /* + * sp (stack top) = sp + idle stack size - XCPTCONTEXT_SIZE + * + * Note: Reserve some space used by up_initial_state since we are already + * running and using the per CPU idle stack. + */ + + li t0, STACK_ALIGN_UP(CONFIG_IDLETHREAD_STACKSIZE - XCPTCONTEXT_SIZE) add sp, sp, t0 2: diff --git a/arch/risc-v/src/k210/k210_irq.c b/arch/risc-v/src/k210/k210_irq.c index 983c6c86116a9..b01ee914fdd76 100644 --- a/arch/risc-v/src/k210/k210_irq.c +++ b/arch/risc-v/src/k210/k210_irq.c @@ -40,16 +40,8 @@ * Public Data ****************************************************************************/ -/* For the case of configurations with multiple CPUs, then there must be one - * such value for each processor that can receive an interrupt. - */ - volatile uintptr_t *g_current_regs[CONFIG_SMP_NCPUS]; -#ifdef CONFIG_SMP -extern int riscv_pause_handler(int irq, void *c, void *arg); -#endif - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/arch/risc-v/src/k210/k210_irq_dispatch.c b/arch/risc-v/src/k210/k210_irq_dispatch.c index 5c152dc8f26d9..7879891b6b619 100644 --- a/arch/risc-v/src/k210/k210_irq_dispatch.c +++ b/arch/risc-v/src/k210/k210_irq_dispatch.c @@ -35,6 +35,12 @@ #include "riscv_internal.h" #include "group/group.h" +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define RV_IRQ_MASK 59 + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -45,14 +51,14 @@ void *riscv_dispatch_irq(uintptr_t vector, uintptr_t *regs) { - uintptr_t irq = (vector >> (27 + 32)) | (vector & 0xf); + int irq = (vector >> RV_IRQ_MASK) | (vector & 0xf); uintptr_t *mepc = regs; /* Check if fault happened */ if (vector < RISCV_IRQ_ECALLU) { - riscv_fault((int)irq, regs); + riscv_fault(irq, regs); } /* Firstly, check if the irq is machine external interrupt */ diff --git a/arch/risc-v/src/litex/Make.defs b/arch/risc-v/src/litex/Make.defs index f992c6bddba03..13754a65bcc31 100644 --- a/arch/risc-v/src/litex/Make.defs +++ b/arch/risc-v/src/litex/Make.defs @@ -30,7 +30,7 @@ CMN_CSRCS += riscv_initialize.c riscv_swint.c CMN_CSRCS += riscv_allocateheap.c riscv_createstack.c riscv_exit.c CMN_CSRCS += riscv_assert.c riscv_blocktask.c riscv_copystate.c riscv_initialstate.c CMN_CSRCS += riscv_interruptcontext.c riscv_modifyreg32.c riscv_puts.c riscv_mdelay.c -CMN_CSRCS += riscv_releasepending.c riscv_reprioritizertr.c riscv_copyfullstate.c +CMN_CSRCS += riscv_releasepending.c riscv_reprioritizertr.c CMN_CSRCS += riscv_releasestack.c riscv_stackframe.c riscv_schedulesigaction.c CMN_CSRCS += riscv_sigdeliver.c riscv_udelay.c riscv_unblocktask.c riscv_usestack.c CMN_CSRCS += riscv_idle.c riscv_tcbinfo.c riscv_getnewintctx.c diff --git a/arch/risc-v/src/litex/litex_irq.c b/arch/risc-v/src/litex/litex_irq.c index e1df1d37866a9..7f8978f0bd7ba 100644 --- a/arch/risc-v/src/litex/litex_irq.c +++ b/arch/risc-v/src/litex/litex_irq.c @@ -38,6 +38,12 @@ #include "riscv_internal.h" #include "litex.h" +/**************************************************************************** + * Public Data + ****************************************************************************/ + +volatile uintptr_t *g_current_regs[1]; + /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/arch/risc-v/src/litex/litex_irq_dispatch.c b/arch/risc-v/src/litex/litex_irq_dispatch.c index 1a4fe4a0df4eb..309ade1f4c173 100644 --- a/arch/risc-v/src/litex/litex_irq_dispatch.c +++ b/arch/risc-v/src/litex/litex_irq_dispatch.c @@ -36,10 +36,10 @@ #include "litex.h" /**************************************************************************** - * Public Data + * Pre-processor Definitions ****************************************************************************/ -volatile uintptr_t *g_current_regs[1]; +#define RV_IRQ_MASK 27 /**************************************************************************** * Public Functions @@ -51,7 +51,7 @@ volatile uintptr_t *g_current_regs[1]; void *riscv_dispatch_irq(uintptr_t vector, uintptr_t *regs) { - uintptr_t irq = (vector >> 27) | (vector & 0xf); + int irq = (vector >> RV_IRQ_MASK) | (vector & 0xf); uintptr_t *mepc = regs; int i; diff --git a/arch/risc-v/src/mpfs/Make.defs b/arch/risc-v/src/mpfs/Make.defs index e46bf5e10ab9f..435b628cb4446 100755 --- a/arch/risc-v/src/mpfs/Make.defs +++ b/arch/risc-v/src/mpfs/Make.defs @@ -30,7 +30,7 @@ CMN_CSRCS += riscv_interruptcontext.c riscv_modifyreg32.c riscv_puts.c CMN_CSRCS += riscv_releasepending.c riscv_reprioritizertr.c CMN_CSRCS += riscv_releasestack.c riscv_stackframe.c riscv_schedulesigaction.c CMN_CSRCS += riscv_sigdeliver.c riscv_unblocktask.c riscv_usestack.c -CMN_CSRCS += riscv_mdelay.c riscv_udelay.c riscv_copyfullstate.c +CMN_CSRCS += riscv_mdelay.c riscv_udelay.c CMN_CSRCS += riscv_idle.c riscv_tcbinfo.c riscv_getnewintctx.c CMN_CSRCS += riscv_cpuindex.c @@ -81,6 +81,10 @@ ifeq ($(CONFIG_ARCH_USE_MMU),y) CMN_CSRCS += riscv_mmu.c endif +ifeq ($(CONFIG_ARCH_KERNEL_STACK),y) +CMN_CSRCS += riscv_addrenv_kstack.c +endif + ifeq ($(CONFIG_SPI),y) CHIP_CSRCS += mpfs_spi.c endif diff --git a/arch/risc-v/src/mpfs/mpfs_irq_dispatch.c b/arch/risc-v/src/mpfs/mpfs_irq_dispatch.c index c6c4be7cde52d..1e420c0c78cbc 100755 --- a/arch/risc-v/src/mpfs/mpfs_irq_dispatch.c +++ b/arch/risc-v/src/mpfs/mpfs_irq_dispatch.c @@ -48,10 +48,10 @@ * riscv_dispatch_irq ****************************************************************************/ -void *riscv_dispatch_irq(uint64_t vector, uint64_t *regs) +void *riscv_dispatch_irq(uintptr_t vector, uintptr_t *regs) { - uint32_t irq = (vector & 0x3f); - uint64_t *mepc = regs; + int irq = (vector & 0x3f); + uintptr_t *mepc = regs; board_autoled_on(LED_INIRQ); @@ -63,10 +63,10 @@ void *riscv_dispatch_irq(uint64_t vector, uint64_t *regs) vector == RISCV_IRQ_SROREPF || vector == RISCV_IRQ_RESERVED) { - riscv_fault((int)irq, regs); + riscv_fault(irq, regs); } - if (vector & 0x8000000000000000) + if ((vector & RISCV_IRQ_BIT) != 0) { irq += MPFS_IRQ_ASYNC; } @@ -136,7 +136,7 @@ void *riscv_dispatch_irq(uint64_t vector, uint64_t *regs) #ifdef CONFIG_ARCH_FPU /* Restore floating point registers */ - riscv_restorefpu((uint64_t *)CURRENT_REGS); + riscv_restorefpu((uintptr_t *)CURRENT_REGS); #endif #ifdef CONFIG_ARCH_ADDRENV @@ -159,7 +159,7 @@ void *riscv_dispatch_irq(uint64_t vector, uint64_t *regs) * switch occurred during interrupt processing. */ - regs = (uint64_t *)CURRENT_REGS; + regs = (uintptr_t *)CURRENT_REGS; CURRENT_REGS = NULL; board_autoled_off(LED_INIRQ); diff --git a/arch/risc-v/src/mpfs/mpfs_timerisr.c b/arch/risc-v/src/mpfs/mpfs_timerisr.c index 1008205ce51b0..b9db1e760d23c 100755 --- a/arch/risc-v/src/mpfs/mpfs_timerisr.c +++ b/arch/risc-v/src/mpfs/mpfs_timerisr.c @@ -47,8 +47,8 @@ * Private Data ****************************************************************************/ -static bool _b_tick_started = false; -static uint64_t *_mtime_cmp = 0L; +static bool _b_tick_started; +static uint64_t *_mtime_cmp; /**************************************************************************** * Private Functions diff --git a/arch/risc-v/src/qemu-rv/Make.defs b/arch/risc-v/src/qemu-rv/Make.defs index a86700252c303..e4e9e3b05637c 100644 --- a/arch/risc-v/src/qemu-rv/Make.defs +++ b/arch/risc-v/src/qemu-rv/Make.defs @@ -30,7 +30,7 @@ CMN_CSRCS += riscv_initialize.c riscv_swint.c CMN_CSRCS += riscv_allocateheap.c riscv_createstack.c riscv_exit.c CMN_CSRCS += riscv_assert.c riscv_blocktask.c riscv_copystate.c riscv_initialstate.c CMN_CSRCS += riscv_interruptcontext.c riscv_modifyreg32.c riscv_puts.c -CMN_CSRCS += riscv_releasepending.c riscv_reprioritizertr.c riscv_copyfullstate.c +CMN_CSRCS += riscv_releasepending.c riscv_reprioritizertr.c CMN_CSRCS += riscv_releasestack.c riscv_stackframe.c riscv_schedulesigaction.c CMN_CSRCS += riscv_sigdeliver.c riscv_unblocktask.c riscv_usestack.c CMN_CSRCS += riscv_idle.c riscv_tcbinfo.c riscv_cpuidlestack.c diff --git a/arch/risc-v/src/qemu-rv/qemu_rv_head.S b/arch/risc-v/src/qemu-rv/qemu_rv_head.S index 0b0adb7b7f7d3..3f217f5084edc 100644 --- a/arch/risc-v/src/qemu-rv/qemu_rv_head.S +++ b/arch/risc-v/src/qemu-rv/qemu_rv_head.S @@ -26,6 +26,7 @@ #include #include "chip.h" +#include "riscv_internal.h" /**************************************************************************** * Public Symbols @@ -77,9 +78,14 @@ __start: ld sp, 0(t0) #endif - /* sp (stack top) = sp + idle stack size */ + /* + * sp (stack top) = sp + idle stack size - XCPTCONTEXT_SIZE + * + * Note: Reserve some space used by up_initial_state since we are already + * running and using the per CPU idle stack. + */ - li t0, CONFIG_IDLETHREAD_STACKSIZE + li t0, STACK_ALIGN_UP(CONFIG_IDLETHREAD_STACKSIZE - XCPTCONTEXT_SIZE) add sp, sp, t0 2: diff --git a/arch/risc-v/src/qemu-rv/qemu_rv_irq.c b/arch/risc-v/src/qemu-rv/qemu_rv_irq.c index a309cf81097ba..36c4e89d41bf2 100644 --- a/arch/risc-v/src/qemu-rv/qemu_rv_irq.c +++ b/arch/risc-v/src/qemu-rv/qemu_rv_irq.c @@ -38,6 +38,12 @@ #include "riscv_internal.h" #include "chip.h" +/**************************************************************************** + * Public Data + ****************************************************************************/ + +volatile uintptr_t *g_current_regs[CONFIG_SMP_NCPUS]; + /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/arch/risc-v/src/qemu-rv/qemu_rv_irq_dispatch.c b/arch/risc-v/src/qemu-rv/qemu_rv_irq_dispatch.c index 670aca4869eed..3a3a79988bd6c 100644 --- a/arch/risc-v/src/qemu-rv/qemu_rv_irq_dispatch.c +++ b/arch/risc-v/src/qemu-rv/qemu_rv_irq_dispatch.c @@ -46,12 +46,6 @@ # define RV_IRQ_MASK 59 #endif -/**************************************************************************** - * Public Data - ****************************************************************************/ - -volatile uintptr_t *g_current_regs[CONFIG_SMP_NCPUS]; - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -62,7 +56,7 @@ volatile uintptr_t *g_current_regs[CONFIG_SMP_NCPUS]; void *riscv_dispatch_irq(uintptr_t vector, uintptr_t *regs) { - uintptr_t irq = (vector >> RV_IRQ_MASK) | (vector & 0xf); + int irq = (vector >> RV_IRQ_MASK) | (vector & 0xf); uintptr_t *mepc = regs; if (vector < RISCV_IRQ_ECALLM) @@ -117,6 +111,34 @@ void *riscv_dispatch_irq(uintptr_t vector, uintptr_t *regs) } #endif +#if defined(CONFIG_ARCH_FPU) || defined(CONFIG_ARCH_ADDRENV) + /* Check for a context switch. If a context switch occurred, then + * CURRENT_REGS will have a different value than it did on entry. If an + * interrupt level context switch has occurred, then restore the floating + * point state and the establish the correct address environment before + * returning from the interrupt. + */ + + if (regs != CURRENT_REGS) + { +#ifdef CONFIG_ARCH_FPU + /* Restore floating point registers */ + + riscv_restorefpu((uintptr_t *)CURRENT_REGS); +#endif + +#ifdef CONFIG_ARCH_ADDRENV + /* Make sure that the address environment for the previously + * running task is closed down gracefully (data caches dump, + * MMU flushed) and set up the address environment for the new + * thread at the head of the ready-to-run list. + */ + + group_addrenv(NULL); +#endif + } +#endif /* CONFIG_ARCH_FPU || CONFIG_ARCH_ADDRENV */ + /* If a context switch occurred while processing the interrupt then * CURRENT_REGS may have change value. If we return any value different * from the input regs, then the lower level will know that a context diff --git a/arch/risc-v/src/rv32m1/Make.defs b/arch/risc-v/src/rv32m1/Make.defs index f44ea46cf08b2..99f6d5b45f5ce 100644 --- a/arch/risc-v/src/rv32m1/Make.defs +++ b/arch/risc-v/src/rv32m1/Make.defs @@ -30,7 +30,7 @@ CMN_CSRCS += riscv_initialize.c riscv_swint.c CMN_CSRCS += riscv_allocateheap.c riscv_createstack.c riscv_exit.c CMN_CSRCS += riscv_assert.c riscv_blocktask.c riscv_copystate.c riscv_initialstate.c CMN_CSRCS += riscv_interruptcontext.c riscv_modifyreg32.c riscv_puts.c -CMN_CSRCS += riscv_releasepending.c riscv_reprioritizertr.c riscv_copyfullstate.c +CMN_CSRCS += riscv_releasepending.c riscv_reprioritizertr.c CMN_CSRCS += riscv_releasestack.c riscv_stackframe.c riscv_schedulesigaction.c CMN_CSRCS += riscv_sigdeliver.c riscv_unblocktask.c riscv_usestack.c CMN_CSRCS += riscv_idle.c riscv_tcbinfo.c riscv_getnewintctx.c diff --git a/arch/risc-v/src/rv32m1/rv32m1_irq.c b/arch/risc-v/src/rv32m1/rv32m1_irq.c index 7692a0b298778..2dc5d13e7969c 100644 --- a/arch/risc-v/src/rv32m1/rv32m1_irq.c +++ b/arch/risc-v/src/rv32m1/rv32m1_irq.c @@ -38,6 +38,12 @@ #include "rv32m1.h" #include "hardware/rv32m1_eu.h" +/**************************************************************************** + * Public Data + ****************************************************************************/ + +volatile uintptr_t *g_current_regs[1]; + /**************************************************************************** * Private Functions ****************************************************************************/ diff --git a/arch/risc-v/src/rv32m1/rv32m1_irq_dispatch.c b/arch/risc-v/src/rv32m1/rv32m1_irq_dispatch.c index e5bf557de9571..077c78a2b254b 100644 --- a/arch/risc-v/src/rv32m1/rv32m1_irq_dispatch.c +++ b/arch/risc-v/src/rv32m1/rv32m1_irq_dispatch.c @@ -37,10 +37,10 @@ #include "hardware/rv32m1_eu.h" /**************************************************************************** - * Public Data + * Pre-processor Definitions ****************************************************************************/ -volatile uintptr_t *g_current_regs[1]; +#define RV_IRQ_MASK 27 /**************************************************************************** * Public Functions @@ -53,10 +53,9 @@ volatile uintptr_t *g_current_regs[1]; LOCATE_ITCM void *rv32m1_dispatch_irq(uintptr_t vector, uintptr_t *regs) { - uintptr_t vec = vector & 0x1f; - uintptr_t irq = (vector >> 27) + vec; + uint32_t vec = vector & 0x1f; + int irq = (vector >> RV_IRQ_MASK) + vec; uintptr_t *mepc = regs; - int irqofs = 0; /* NOTE: In case of ecall, we need to adjust mepc in the context */ diff --git a/arch/sim/src/sim/up_initialstate.c b/arch/sim/src/sim/up_initialstate.c index a257b5d1cf6be..408c88009e7e1 100644 --- a/arch/sim/src/sim/up_initialstate.c +++ b/arch/sim/src/sim/up_initialstate.c @@ -54,7 +54,7 @@ void up_initial_state(struct tcb_s *tcb) { - if (tcb->pid == 0) + if (tcb->pid == IDLE_PROCESS_ID) { tcb->stack_alloc_ptr = (void *)(up_getsp() - CONFIG_IDLETHREAD_STACKSIZE - diff --git a/arch/sparc/src/sparc_v8/up_dumpstate.c b/arch/sparc/src/sparc_v8/up_dumpstate.c index 75f7b1e84d904..d31a70d25f627 100644 --- a/arch/sparc/src/sparc_v8/up_dumpstate.c +++ b/arch/sparc/src/sparc_v8/up_dumpstate.c @@ -108,7 +108,7 @@ void up_dumpstate(void) /* Get the limits on the user stack memory */ - if (rtcb->pid == 0) /* Check for CPU0 IDLE thread */ + if (rtcb->pid == IDLE_PROCESS_ID) /* Check for CPU0 IDLE thread */ { ustackbase = g_idle_topstack - 4; ustacksize = CONFIG_IDLETHREAD_STACKSIZE; diff --git a/arch/sparc/src/sparc_v8/up_initialstate.c b/arch/sparc/src/sparc_v8/up_initialstate.c index 46ee07cf06abb..6ef0754516bdd 100644 --- a/arch/sparc/src/sparc_v8/up_initialstate.c +++ b/arch/sparc/src/sparc_v8/up_initialstate.c @@ -68,7 +68,7 @@ void up_initial_state(struct tcb_s *tcb) /* Initialize the idle thread stack */ - if (tcb->pid == 0) + if (tcb->pid == IDLE_PROCESS_ID) { tcb->stack_alloc_ptr = (void *)(g_idle_topstack - CONFIG_IDLETHREAD_STACKSIZE); diff --git a/arch/x86/src/Makefile b/arch/x86/src/Makefile index 4204edd222dd5..ae9add03ff8e6 100644 --- a/arch/x86/src/Makefile +++ b/arch/x86/src/Makefile @@ -71,14 +71,14 @@ endif # Add the builtin library -EXTRA_LIBS += ${shell $(CC) $(ARCHCPUFLAGS) --print-libgcc-file-name} +EXTRA_LIBS += ${wildcard ${shell $(CC) $(ARCHCPUFLAGS) --print-libgcc-file-name}} ifneq ($(CONFIG_LIBM),y) EXTRA_LIBS += ${wildcard ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libm.a}} endif ifeq ($(CONFIG_LIBSUPCXX),y) - EXTRA_LIBS += ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libsupc++.a} + EXTRA_LIBS += ${wildcard ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libsupc++.a}} endif VPATH = chip:common:$(ARCH_SUBDIR) diff --git a/arch/x86/src/i486/up_initialstate.c b/arch/x86/src/i486/up_initialstate.c index 1f5b9b5aa6c11..41d8dd3ac3adc 100644 --- a/arch/x86/src/i486/up_initialstate.c +++ b/arch/x86/src/i486/up_initialstate.c @@ -55,7 +55,7 @@ void up_initial_state(struct tcb_s *tcb) /* Initialize the idle thread stack */ - if (tcb->pid == 0) + if (tcb->pid == IDLE_PROCESS_ID) { char *stack_ptr = (char *)(g_idle_topstack - CONFIG_IDLETHREAD_STACKSIZE); diff --git a/arch/x86_64/src/Makefile b/arch/x86_64/src/Makefile index 047f0fbe44470..00f815f79c368 100644 --- a/arch/x86_64/src/Makefile +++ b/arch/x86_64/src/Makefile @@ -73,14 +73,14 @@ endif # Add the builtin library -EXTRA_LIBS += ${shell $(CC) $(ARCHCPUFLAGS) --print-libgcc-file-name} +EXTRA_LIBS += ${wildcard ${shell $(CC) $(ARCHCPUFLAGS) --print-libgcc-file-name}} ifneq ($(CONFIG_LIBM),y) EXTRA_LIBS += ${wildcard ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libm.a}} endif ifeq ($(CONFIG_LIBSUPCXX),y) - EXTRA_LIBS += ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libsupc++.a} + EXTRA_LIBS += ${wildcard ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libsupc++.a}} endif VPATH = chip:common:$(ARCH_SUBDIR) diff --git a/arch/x86_64/src/intel64/up_initialstate.c b/arch/x86_64/src/intel64/up_initialstate.c index dea02567cf479..66f61f95ddc0c 100644 --- a/arch/x86_64/src/intel64/up_initialstate.c +++ b/arch/x86_64/src/intel64/up_initialstate.c @@ -56,7 +56,7 @@ void up_initial_state(struct tcb_s *tcb) /* Initialize the idle thread stack */ - if (tcb->pid == 0) + if (tcb->pid == IDLE_PROCESS_ID) { char *stack_ptr = (char *)(g_idle_topstack - CONFIG_IDLETHREAD_STACKSIZE); diff --git a/arch/xtensa/include/esp32s3/irq.h b/arch/xtensa/include/esp32s3/irq.h index fecdb3c60ec37..b379a22896426 100644 --- a/arch/xtensa/include/esp32s3/irq.h +++ b/arch/xtensa/include/esp32s3/irq.h @@ -25,6 +25,12 @@ #ifndef __ARCH_XTENSA_INCLUDE_ESP32S3_IRQ_H #define __ARCH_XTENSA_INCLUDE_ESP32S3_IRQ_H +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -309,19 +315,20 @@ #define ESP32S3_NIRQ_PERIPH ESP32S3_NPERIPHERALS -/* Second level GPIO interrupts. GPIO interrupts are decoded and dispatched - * as a second level of decoding: The first level dispatches to the GPIO - * interrupt handler. The second to the decoded GPIO interrupt handler. +#ifdef CONFIG_ESP32S3_GPIO_IRQ + +/* Second level GPIO interrupts. GPIO interrupts are decoded and dispatched + * as a second level of decoding: The first level dispatches to the GPIO + * interrupt handler. The second to the decoded GPIO interrupt handler. */ -#ifdef CONFIG_ESP32S3_GPIO_IRQ -# define ESP32S3_NIRQ_GPIO 40 -# define ESP32S3_FIRST_GPIOIRQ (XTENSA_NIRQ_INTERNAL + ESP32S3_NIRQ_PERIPH) -# define ESP32S3_LAST_GPIOIRQ (ESP32S3_FIRST_GPIOIRQ + ESP32S3_NIRQ_GPIO - 1) -# define ESP32S3_PIN2IRQ(p) ((p) + ESP32S3_FIRST_GPIOIRQ) -# define ESP32S3_IRQ2PIN(i) ((i) - ESP32S3_FIRST_GPIOIRQ) +# define ESP32S3_NIRQ_GPIO 49 +# define ESP32S3_FIRST_GPIOIRQ (XTENSA_NIRQ_INTERNAL + ESP32S3_NIRQ_PERIPH) +# define ESP32S3_LAST_GPIOIRQ (ESP32S3_FIRST_GPIOIRQ + ESP32S3_NIRQ_GPIO - 1) +# define ESP32S3_PIN2IRQ(p) ((p) + ESP32S3_FIRST_GPIOIRQ) +# define ESP32S3_IRQ2PIN(i) ((i) - ESP32S3_FIRST_GPIOIRQ) #else -# define ESP32S3_NIRQ_GPIO 0 +# define ESP32S3_NIRQ_GPIO 0 #endif /* Total number of interrupts */ diff --git a/arch/xtensa/src/common/xtensa_dumpstate.c b/arch/xtensa/src/common/xtensa_dumpstate.c index f5869f5a77eb3..1b9e59fcd52f4 100644 --- a/arch/xtensa/src/common/xtensa_dumpstate.c +++ b/arch/xtensa/src/common/xtensa_dumpstate.c @@ -90,6 +90,9 @@ static void xtensa_dump_task(struct tcb_s *tcb, void *arg) /* Dump interesting properties of this task */ _alert(" %4d %4d" +#ifdef CONFIG_SMP + " %4d" +#endif #ifdef CONFIG_STACK_COLORATION " %7lu" #endif @@ -105,6 +108,9 @@ static void xtensa_dump_task(struct tcb_s *tcb, void *arg) #endif "\n", tcb->pid, tcb->sched_priority, +#ifdef CONFIG_SMP + tcb->cpu, +#endif #ifdef CONFIG_STACK_COLORATION (unsigned long)up_check_tcbstack(tcb), #endif @@ -159,6 +165,9 @@ static inline void xtensa_showtasks(void) /* Dump interesting properties of each task in the crash environment */ _alert(" PID PRI" +#ifdef CONFIG_SMP + " CPU" +#endif #ifdef CONFIG_STACK_COLORATION " USED" #endif @@ -176,6 +185,9 @@ static inline void xtensa_showtasks(void) #if CONFIG_ARCH_INTERRUPTSTACK > 15 _alert(" ---- ----" +# ifdef CONFIG_SMP + " ----" +# endif # ifdef CONFIG_STACK_COLORATION " %7lu" # endif diff --git a/arch/xtensa/src/common/xtensa_initialstate.c b/arch/xtensa/src/common/xtensa_initialstate.c index 9b5157af90251..b059d62cbd434 100644 --- a/arch/xtensa/src/common/xtensa_initialstate.c +++ b/arch/xtensa/src/common/xtensa_initialstate.c @@ -60,7 +60,7 @@ void up_initial_state(struct tcb_s *tcb) /* Initialize the idle thread stack */ - if (tcb->pid == 0) + if (tcb->pid == IDLE_PROCESS_ID) { tcb->stack_alloc_ptr = g_idlestack; tcb->stack_base_ptr = tcb->stack_alloc_ptr; diff --git a/arch/xtensa/src/esp32/Make.defs b/arch/xtensa/src/esp32/Make.defs index dbd13749973f2..5e0b238a55ecc 100644 --- a/arch/xtensa/src/esp32/Make.defs +++ b/arch/xtensa/src/esp32/Make.defs @@ -39,15 +39,10 @@ CMN_CSRCS += xtensa_modifyreg8.c xtensa_modifyreg16.c xtensa_modifyreg32.c CMN_CSRCS += xtensa_puts.c xtensa_releasepending.c xtensa_releasestack.c CMN_CSRCS += xtensa_reprioritizertr.c xtensa_schedsigaction.c CMN_CSRCS += xtensa_sigdeliver.c xtensa_stackframe.c xtensa_udelay.c -CMN_CSRCS += xtensa_unblocktask.c xtensa_usestack.c xtensa_swint.c -CMN_CSRCS += esp32_systemreset.c esp32_resetcause.c xtensa_switchcontext.c +CMN_CSRCS += xtensa_unblocktask.c xtensa_usestack.c xtensa_swint.c xtensa_switchcontext.c # Configuration-dependent common XTENSA files -ifneq ($(CONFIG_ARCH_IDLE_CUSTOM),y) - CMN_CSRCS += esp32_idle.c -endif - ifeq ($(CONFIG_DEBUG_ALERT),y) CMN_CSRCS += xtensa_dumpstate.c endif @@ -72,10 +67,15 @@ endif # Required ESP32 files (arch/xtensa/src/lx6) CHIP_CSRCS = esp32_allocateheap.c esp32_clockconfig.c esp32_gpio.c +CHIP_CSRCS += esp32_systemreset.c esp32_resetcause.c CHIP_CSRCS += esp32_irq.c esp32_region.c CHIP_CSRCS += esp32_user.c CHIP_CSRCS += esp32_dma.c +ifneq ($(CONFIG_ARCH_IDLE_CUSTOM),y) +CHIP_CSRCS += esp32_idle.c +endif + ifeq ($(CONFIG_SCHED_TICKLESS),y) CHIP_CSRCS += esp32_tickless.c else @@ -105,9 +105,9 @@ endif ifeq ($(CONFIG_ESP32_SPI),y) CHIP_CSRCS += esp32_spi.c - ifeq ($(CONFIG_SPI_SLAVE),y) - CHIP_CSRCS += esp32_spi_slave.c - endif +ifeq ($(CONFIG_SPI_SLAVE),y) +CHIP_CSRCS += esp32_spi_slave.c +endif endif # SPIFLASH and SPIRAM need spicache.c @@ -142,15 +142,15 @@ endif ifeq ($(CONFIG_SMP),y) CHIP_ASRCS = esp32_cpuindex.S -CMN_CSRCS += esp32_cpuidlestack.c esp32_cpustart.c esp32_intercpu_interrupt.c +CHIP_CSRCS += esp32_cpuidlestack.c esp32_cpustart.c esp32_intercpu_interrupt.c endif ifeq ($(CONFIG_ESP32_UART),y) -CMN_CSRCS += esp32_serial.c +CHIP_CSRCS += esp32_serial.c endif ifeq ($(CONFIG_ESP32_RNG),y) -CMN_CSRCS += esp32_rng.c +CHIP_CSRCS += esp32_rng.c endif ifeq ($(CONFIG_ESP32_TIMER),y) @@ -193,7 +193,7 @@ endif ifeq ($(CONFIG_ARCH_USE_TEXT_HEAP),y) CHIP_CSRCS += esp32_textheap.c -CMN_ASRCS += xtensa_loadstore.S +CMN_ASRCS += xtensa_loadstore.S endif ifeq ($(CONFIG_ESP32_RT_TIMER),y) diff --git a/arch/xtensa/src/esp32/esp32_ble_adapter.c b/arch/xtensa/src/esp32/esp32_ble_adapter.c index ab7c332118fc7..681de7cc595b1 100644 --- a/arch/xtensa/src/esp32/esp32_ble_adapter.c +++ b/arch/xtensa/src/esp32/esp32_ble_adapter.c @@ -802,7 +802,7 @@ static int32_t esp_task_create_pinned_to_core(void *entry, wlerr("Failed to create task, error %d\n", pid); } - return pid > 0 ? true : false; + return pid > 0; } /**************************************************************************** diff --git a/arch/xtensa/src/esp32/esp32_rt_timer.c b/arch/xtensa/src/esp32/esp32_rt_timer.c index 6732902d58097..34f3c21673251 100644 --- a/arch/xtensa/src/esp32/esp32_rt_timer.c +++ b/arch/xtensa/src/esp32/esp32_rt_timer.c @@ -66,7 +66,7 @@ struct esp32_rt_priv_s { - int pid; + pid_t pid; sem_t toutsem; @@ -81,7 +81,10 @@ struct esp32_rt_priv_s * Private Data ****************************************************************************/ -static struct esp32_rt_priv_s g_rt_priv; +static struct esp32_rt_priv_s g_rt_priv = +{ + .pid = INVALID_PROCESS_ID +}; /**************************************************************************** * Private Function Prototypes @@ -705,7 +708,7 @@ int esp32_rt_timer_init(void) list_initialize(&priv->toutlist); priv->timer = tim; - priv->pid = pid; + priv->pid = (pid_t)pid; flags = spin_lock_irqsave(&priv->lock); @@ -757,7 +760,12 @@ void esp32_rt_timer_deinit(void) spin_unlock_irqrestore(&priv->lock, flags); - kthread_delete(priv->pid); + if (priv->pid != INVALID_PROCESS_ID) + { + kthread_delete(priv->pid); + priv->pid = INVALID_PROCESS_ID; + } + nxsem_destroy(&priv->toutsem); } diff --git a/arch/xtensa/src/esp32/esp32_wifi_adapter.c b/arch/xtensa/src/esp32/esp32_wifi_adapter.c index c00b41e2e9fa2..b752ca0e55dcb 100644 --- a/arch/xtensa/src/esp32/esp32_wifi_adapter.c +++ b/arch/xtensa/src/esp32/esp32_wifi_adapter.c @@ -1933,7 +1933,7 @@ static int32_t esp_task_create_pinned_to_core(void *entry, wlerr("Failed to create task\n"); } - return pid > 0 ? true : false; + return pid > 0; } /**************************************************************************** diff --git a/arch/xtensa/src/esp32s2/Kconfig b/arch/xtensa/src/esp32s2/Kconfig index 9ccfb65be7f49..eabe497dbafd3 100644 --- a/arch/xtensa/src/esp32s2/Kconfig +++ b/arch/xtensa/src/esp32s2/Kconfig @@ -10,22 +10,48 @@ comment "ESP32-S2 Configuration Options" choice prompt "ESP32-S2 Chip Selection" default ARCH_CHIP_ESP32S2WROVER - depends on ARCH_CHIP_ESP32S2 config ARCH_CHIP_ESP32S2WROVER bool "ESP32-S2-WROVER" - select ESP32S2_ESP32S2DXWDXX select ESP32S2_FLASH_4M - select ESP32S2_PSRAM_8M + select ESP32S2_PSRAM_2M ---help--- Generic module with an embedded ESP32-S2 -endchoice # ESP32S2 Chip Selection +endchoice # ESP32-S2 Chip Selection -choice - prompt "Instruction CACHE Size" +choice ESP32S2_DEFAULT_CPU_FREQ + prompt "CPU Frequency" + default ESP32S2_DEFAULT_CPU_FREQ_240 + ---help--- + CPU frequency to be set on application startup. + +config ESP32S2_DEFAULT_CPU_FREQ_80 + bool "80 MHz" + +config ESP32S2_DEFAULT_CPU_FREQ_160 + bool "160 MHz" + +config ESP32S2_DEFAULT_CPU_FREQ_240 + bool "240 MHz" + +endchoice # CPU Frequency + +config ESP32S2_DEFAULT_CPU_FREQ_MHZ + int + default 80 if ESP32S2_DEFAULT_CPU_FREQ_80 + default 160 if ESP32S2_DEFAULT_CPU_FREQ_160 + default 240 if ESP32S2_DEFAULT_CPU_FREQ_240 + +menu "Cache Configuration" + +choice ESP32S2_INSTRUCTION_CACHE_SIZE + prompt "Instruction cache size" default ESP32S2_INSTRUCTION_CACHE_8KB - depends on ARCH_CHIP_ESP32S2 + ---help--- + Instruction cache size to be set on application startup. + If you use 8KB instruction cache rather than 16KB instruction cache, + then the other 8KB will be managed by heap allocator. config ESP32S2_INSTRUCTION_CACHE_8KB bool "8KB" @@ -37,12 +63,41 @@ config ESP32S2_INSTRUCTION_CACHE_16KB ---help--- Use 16KB of SRAM as Instruction Cache -endchoice # ESP32S2 Instruction CACHE size +endchoice # Instruction cache size -choice - prompt "Data CACHE Size" - default ESP32S2_DATA_CACHE_8KB - depends on ARCH_CHIP_ESP32S2 +config ESP32S2_INSTRUCTION_CACHE_SIZE + hex + default 0x2000 if ESP32S2_INSTRUCTION_CACHE_8KB + default 0x4000 if ESP32S2_INSTRUCTION_CACHE_16KB + +choice ESP32S2_INSTRUCTION_CACHE_LINE_SIZE + prompt "Instruction cache line size" + default ESP32S2_INSTRUCTION_CACHE_LINE_32B + ---help--- + Instruction cache line size to be set on application startup. + + config ESP32S2_INSTRUCTION_CACHE_LINE_16B + bool "16 Bytes" + depends on ESP32S2_INSTRUCTION_CACHE_16KB + + config ESP32S2_INSTRUCTION_CACHE_LINE_32B + bool "32 Bytes" + +endchoice + +config ESP32S2_INSTRUCTION_CACHE_LINE_SIZE + int + default 16 if ESP32S2_INSTRUCTION_CACHE_LINE_16B + default 32 if ESP32S2_INSTRUCTION_CACHE_LINE_32B + +choice ESP32S2_DATA_CACHE_SIZE + prompt "Data cache size" + default ESP32S2_DATA_CACHE_0KB + ---help--- + Data cache size to be set on application startup. + If you use 0KB data cache, the other 16KB will be added to the heap. + If you use 8KB data cache rather than 16KB data cache, the other 8KB + will be added to the heap. config ESP32S2_DATA_CACHE_0KB bool "No DATA CACHE" @@ -59,11 +114,34 @@ config ESP32S2_DATA_CACHE_16KB ---help--- Use 16KB of SRAM as Data Cache -endchoice # ESP32S2 Data CACHE size +endchoice # Data cache size -config ESP32S2_SINGLE_CPU - bool - default y +config ESP32S2_DATA_CACHE_SIZE + hex + default 0x0 if ESP32S2_DATA_CACHE_0KB + default 0x2000 if ESP32S2_DATA_CACHE_8KB + default 0x4000 if ESP32S2_DATA_CACHE_16KB + +choice ESP32S2_DATA_CACHE_LINE_SIZE + prompt "Data cache line size" + default ESP32S2_DATA_CACHE_LINE_32B + ---help--- + Data cache line size to be set on application startup. + + config ESP32S2_DATA_CACHE_LINE_16B + bool "16 Bytes" + + config ESP32S2_DATA_CACHE_LINE_32B + bool "32 Bytes" + +endchoice + +config ESP32S2_DATA_CACHE_LINE_SIZE + int + default 16 if ESP32S2_DATA_CACHE_LINE_16B + default 32 if ESP32S2_DATA_CACHE_LINE_32B + +endmenu # Cache Configuration config ESP32S2_FLASH_2M bool @@ -77,7 +155,7 @@ config ESP32S2_FLASH_8M bool default n -config ESP32S2_FLASH_16M +config ESP32S2_PSRAM_2M bool default n @@ -97,16 +175,6 @@ config ESP32S2_FLASH_DETECT ---help--- Auto detect flash size when flashing. -config ESP32S2_PSRAM_8M - bool - default n - -config ESP32S2_ESP32S2SXWDXX - bool - default n - select ESP32S2_SINGLE_CPU - select ARCH_HAVE_I2CRESET - choice ESP32S2_FLASH_MODE prompt "SPI FLASH mode" default ESP32S2_FLASH_MODE_DIO @@ -127,7 +195,7 @@ choice ESP32S2_FLASH_MODE config ESP32S2_FLASH_MODE_QOUT bool "Quad Output (QOUT)" -endchoice # ESP32S2_FLASH_MODE +endchoice # SPI FLASH mode choice ESP32S2_FLASH_FREQ prompt "SPI FLASH frequency" @@ -147,44 +215,7 @@ choice ESP32S2_FLASH_FREQ config ESP32S2_FLASH_FREQ_20M bool "20 MHz" -endchoice # ESP32S2_FLASH_FREQ - -choice ESP32S2_DEFAULT_CPU_FREQ - prompt "CPU frequency" - default ESP32S2_DEFAULT_CPU_FREQ_240 - ---help--- - CPU frequency to be set on application startup. - - config ESP32S2_DEFAULT_CPU_FREQ_80 - bool "80 MHz" - config ESP32S2_DEFAULT_CPU_FREQ_160 - bool "160 MHz" - config ESP32S2_DEFAULT_CPU_FREQ_240 - bool "240 MHz" -endchoice # CPU frequency - -config ESP32S2_DEFAULT_CPU_FREQ_MHZ - int - default 80 if ESP32S2_DEFAULT_CPU_FREQ_80 - default 160 if ESP32S2_DEFAULT_CPU_FREQ_160 - default 240 if ESP32S2_DEFAULT_CPU_FREQ_240 - -choice - prompt "On-board Crystal Frequency" - default ESP32S2_XTAL_40MZ - -config ESP32S2_XTAL_40MZ - bool "40MHz" - -config ESP32S2_XTAL_26MHz - bool "26MHz" - -endchoice # On-board Crystal Frequency - -config ESP32S2_RT_TIMER - bool "Real-time Timer" - select ESP32S2_TIMER - default n +endchoice # SPI FLASH frequency config ESP32S2_RUN_IRAM bool "Run from IRAM" @@ -207,112 +238,16 @@ config ESP32S2_WDT bool default n -config ESP32S2_BT - bool "Bluetooth" - default n - depends on EXPERIMENTAL - ---help--- - No yet implemented - -config ESP32S2_EFUSE - bool "EFUSE support" - default n - ---help--- - Enable ESP32S2 efuse support. - -config ESP32S2_I2C - bool - default n - -config ESP32S2_I2S0 - bool "I2S 0" - default n - depends on EXPERIMENTAL - ---help--- - No yet implemented - -config ESP32S2_LEDC - bool "LED PWM (LEDC)" - default n - depends on EXPERIMENTAL - ---help--- - No yet implemented - -config ESP32S2_PCNT - bool "Pulse Count Module (PCNT)" - default n - depends on EXPERIMENTAL - ---help--- - No yet implemented - -config ESP32S2_RMT - bool "Remote Control Module (RMT)" - default n - depends on EXPERIMENTAL - ---help--- - No yet implemented - config ESP32S2_RNG bool "Random Number Generator (RNG)" default n select ARCH_HAVE_RNG ---help--- - ESP32S2 supports a RNG that passed on Dieharder test suite. - -config ESP32S2_SPI - bool - default n + ESP32-S2 supports a RNG that passed on Dieharder test suite. config ESP32S2_SPIFLASH bool "SPI Flash" default n - select MTD - select MTD_BYTE_WRITE - select MTD_PARTITION - -config ESP32S2_SPI2 - bool "SPI 2" - default n - select ESP32S2_SPI - select ESP32S2_GPIO_IRQ - select SPI - -config ESP32S2_SPI3 - bool "SPI 3" - default n - select ESP32S2_SPI - select ESP32S2_GPIO_IRQ - select SPI - -config ESP32S2_SPIRAM - bool "SPI RAM Support" - default n - select ARCH_HAVE_HEAP2 - select XTENSA_IMEM_USE_SEPARATE_HEAP - -if ESP32S2_SPIRAM && SMP - -choice - prompt "How does SPIRAM share cache?" - default ESP32S2_MEMMAP_SPIRAM_CACHE_EVENODD - ---help--- - Selects the cache mode to CPU access the external memory. - - config ESP32S2_MEMMAP_SPIRAM_CACHE_EVENODD - bool "Pro CPU uses even 32 byte ranges, App uses odd ones" - config ESP32S2_MEMMAP_SPIRAM_CACHE_LOWHIGH - bool "Pro CPU uses low 2MB ranges, App uses high ones" -endchoice # CPU frequency - -endif - -config XTENSA_TIMER1 - bool "Xtensa Timer 1" - default n - -config XTENSA_TIMER2 - bool "Xtensa Timer 2" - default n config ESP32S2_TIMER0 bool "64-bit Timer 0 (Group 0 Timer 0)" @@ -383,39 +318,15 @@ config ESP32S2_UART1 select UART1_SERIALDRIVER select ARCH_HAVE_SERIAL_TERMIOS -config ESP32S2_WIRELESS - bool "Wireless" - default n - select NET - select ARCH_PHY_INTERRUPT - select ESP32S2_RNG - select ESP32S2_RT_TIMER - select ESP32S2_TIMER0 - ---help--- - Enable Wireless support - -config ESP32S2_I2C0 - bool "I2C 0" - default n - select ESP32S2_I2C - -config ESP32S2_I2C1 - bool "I2C 1" - default n - select ESP32S2_I2C - -config ESP32S2_AES_ACCELERATOR - bool "AES Accelerator" +config ESP32S2_RT_TIMER + bool "Real-time Timer" + select ESP32S2_TIMER default n -endmenu # ESP32S2 Peripheral Selection +endmenu # ESP32-S2 Peripheral Selection menu "Memory Configuration" -config ESP32S2_BT_RESERVE_DRAM - int "Reserved BT DRAM" - default 0 - config ESP32S2_TRACEMEM_RESERVE_DRAM int "Reserved trace memory DRAM" default 0 @@ -429,9 +340,9 @@ endmenu # Memory Configuration config ESP32S2_GPIO_IRQ bool "GPIO pin interrupts" ---help--- - Enable support for interrupting GPIO pins + Enable support for interrupting GPIO pins. -menu "UART configuration" +menu "UART Configuration" depends on ESP32S2_UART if ESP32S2_UART0 @@ -486,135 +397,9 @@ config ESP32S2_UART1_CTSPIN endif # ESP32S2_UART1 -endmenu # UART configuration - -menu "I2C configuration" - depends on ESP32S2_I2C +endmenu # UART Configuration -if ESP32S2_I2C0 - -config ESP32S2_I2C0_SCLPIN - int "I2C0 SCL Pin" - default 22 - range 0 39 - -config ESP32S2_I2C0_SDAPIN - int "I2C0 SDA Pin" - default 23 - range 0 39 - -endif # ESP32S2_I2C0 - -if ESP32S2_I2C1 - -config ESP32S2_I2C1_SCLPIN - int "I2C1 SCL Pin" - default 26 - range 0 39 - -config ESP32S2_I2C1_SDAPIN - int "I2C1 SDA Pin" - default 25 - range 0 39 - -endif # ESP32S2_I2C1 - -endmenu # I2C configuration - -menu "SPI configuration" - depends on ESP32S2_SPI - -config ESP32S2_SPI_SWCS - bool "SPI software CS" - default y - ---help--- - Use SPI software CS. - -config ESP32S2_SPI_UDCS - bool "User defined CS" - default n - depends on ESP32S2_SPI_SWCS - ---help--- - Use user defined CS. - -config ESP32S2_SPI2_DMA - bool "SPI2 use DMA" - default y - depends on ESP32S2_SPI2 - -config ESP32S2_SPI3_DMA - bool "SPI3 use DMA" - default y - depends on ESP32S2_SPI3 - -config SPI_DMADESC_NUM - int "SPI master DMA description number" - default 2 - -config SPI_SLAVE_BUFSIZE - int "SPI slave buffer size" - default 2048 - depends on SPI_SLAVE - -config ESP32S2_SPI_DMATHRESHOLD - int "SPI DMA threshold" - default 64 - depends on ESP32S2_SPI2_DMA || ESP32S2_SPI3_DMA - ---help--- - When SPI DMA is enabled, DMA transfers whose size are below the - defined threshold will be performed by polling logic. - -if ESP32S2_SPI2 - -config ESP32S2_SPI2_CSPIN - int "SPI2 CS Pin" - default 15 - range 0 39 - -config ESP32S2_SPI2_CLKPIN - int "SPI2 CLK Pin" - default 14 - range 0 39 - -config ESP32S2_SPI2_MOSIPIN - int "SPI2 MOSI Pin" - default 13 - range 0 39 - -config ESP32S2_SPI2_MISOPIN - int "SPI2 MISO Pin" - default 12 - range 0 39 - -endif # ESP32S2_SPI2 - -if ESP32S2_SPI3 - -config ESP32S2_SPI3_CSPIN - int "SPI3 CS Pin" - default 5 - range 0 39 - -config ESP32S2_SPI3_CLKPIN - int "SPI3 CLK Pin" - default 18 - range 0 39 - -config ESP32S2_SPI3_MOSIPIN - int "SPI3 MOSI Pin" - default 23 - range 0 39 - -config ESP32S2_SPI3_MISOPIN - int "SPI3 MISO Pin" - default 19 - range 0 39 - -endif # ESP32S2_SPI3 - -endmenu # ESP32S2_SPI - -menu "SPI Flash configuration" +menu "SPI Flash Configuration" depends on ESP32S2_SPIFLASH if ESP32S2_HAVE_OTA_PARTITION @@ -655,219 +440,9 @@ config ESP32S2_OTA_SCRATCH_DEVPATH endif -comment "General storage MTD configuration" - -config ESP32S2_STORAGE_MTD_OFFSET - hex "Storage MTD base address in SPI Flash" - default 0x180000 if !ESP32S2_HAVE_OTA_PARTITION - default 0x250000 if ESP32S2_HAVE_OTA_PARTITION - ---help--- - MTD base address in SPI Flash. - -config ESP32S2_STORAGE_MTD_SIZE - hex "Storage MTD size in SPI Flash" - default 0x100000 - ---help--- - MTD size in SPI Flash. - -config ESP32S2_SPIFLASH_DEBUG - bool "Debug SPI Flash" - default n - depends on DEBUG_FS_INFO - ---help--- - Enable this option, read and write of SPI Flash - will show input arguments and result. - -endmenu # SPI Flash configuration - -menu "SPI RAM Config" - depends on ESP32S2_SPIRAM - -choice ESP32S2_SPIRAM_TYPE - prompt "Type of SPI RAM chip in use" - default ESP32S2_SPIRAM_TYPE_AUTO - -config ESP32S2_SPIRAM_TYPE_AUTO - bool "Auto-detect" - -config ESP32S2_SPIRAM_TYPE_ESPPSRAM32 - bool "ESP-PSRAM32 or IS25WP032" - -config ESP32S2_SPIRAM_TYPE_ESPPSRAM64 - bool "ESP-PSRAM64 or LY68L6400" -endchoice #ESP32S2_SPIRAM_TYPE - -config ESP32S2_SPIRAM_SIZE - int - default -1 if ESP32S2_SPIRAM_TYPE_AUTO - default 4194304 if ESP32S2_SPIRAM_TYPE_ESPPSRAM32 - default 8388608 if ESP32S2_SPIRAM_TYPE_ESPPSRAM64 - default 0 - -choice ESP32S2_SPIRAM_SPEED - prompt "Set RAM clock speed" - default ESP32S2_SPIRAM_SPEED_40M - ---help--- - Select the speed for the SPI RAM chip. - -config ESP32S2_SPIRAM_SPEED_40M - bool "40MHz clock speed" - -config ESP32S2_SPIRAM_SPEED_80M - bool "80MHz clock speed" - -endchoice # ESP32S2_SPIRAM_SPEED - -config ESP32S2_SPIRAM_BOOT_INIT - bool "Initialize SPI RAM during startup" - depends on ESP32S2_SPIRAM - default "y" - ---help--- - If this is enabled, the SPI RAM will be enabled during initial - boot. Unless you have specific requirements, you'll want to leave - this enabled so memory allocated during boot-up can also be - placed in SPI RAM. - -config ESP32S2_SPIRAM_IGNORE_NOTFOUND - bool "Ignore PSRAM when not found" - default "n" - depends on ESP32S2_SPIRAM_BOOT_INIT && !BOOT_SDRAM_DATA - ---help--- - Normally, if psram initialization is enabled during compile time - but not found at runtime, it is seen as an error making the CPU - panic. If this is enabled, booting will complete but no PSRAM - will be available. - -config ESP32S2_SPIRAM_2T_MODE - bool "Enable SPI PSRAM 2T mode" - depends on ESP32S2_SPIRAM - default "n" - ---help--- - Enable this option to fix single bit errors inside 64Mbit PSRAM. - Some 64Mbit PSRAM chips have a hardware issue in the RAM which - causes bit errors at multiple fixed bit positions. - Note: If this option is enabled, the 64Mbit PSRAM chip will appear - to be 32Mbit in size. - Applications will not be affected unless the use the esp_himem - APIs, which are not supported in 2T mode. - -config ESP32S2_SPIRAM_BANKSWITCH_ENABLE - bool "Enable bank switching for >4MiB external RAM" - default y - ---help--- - The ESP32S2 only supports 4MiB of external RAM in its address - space. The hardware does support larger memories, but these - have to be bank-switched in and out of this address space. - Enabling this allows you to reserve some MMU pages for this, - which allows the use of the esp_himem api to manage these - banks. - #Note that this is limited to 62 banks, as - #esp_spiram_writeback_cache needs some kind of mapping of - #some banks below that mark to work. We cannot at this - #moment guarantee this to exist when himem is enabled. - If spiram 2T mode is enabled, the size of 64Mbit psram will - be changed as 32Mbit, so himem will be unusable. - -config SPIRAM_BANKSWITCH_RESERVE - int "Amount of 32K pages to reserve for bank switching" - depends on ESP32S2_SPIRAM_BANKSWITCH_ENABLE - default 8 - range 1 62 - ---help--- - Select the amount of banks reserved for bank switching. Note - that the amount of RAM allocatable with malloc will decrease - by 32K for each page reserved here. - Note that this reservation is only actually done if your - program actually uses the himem API. Without any himem - calls, the reservation is not done and the original amount - of memory will be available. - -endmenu #SPI RAM Config - -menu "Wi-Fi configuration" - depends on ESP32S2_WIRELESS - -choice - prompt "ESP32-S2 Wi-Fi mode" - default ESP32S2_WIFI_STATION - -config ESP32S2_WIFI_STATION - bool "Station mode" - -config ESP32S2_WIFI_SOFTAP - bool "SoftAP mode" +endmenu # SPI Flash Configuration -config ESP32S2_WIFI_STATION_SOFTAP_COEXISTENCE - bool "Station + SoftAP coexistence" - -endchoice # ESP32S2 Wi-Fi mode - -config ESP32S2_WIFI_STATIC_RXBUF_NUM - int "Wi-Fi static RX buffer number" - default 10 - -config ESP32S2_WIFI_DYNAMIC_RXBUF_NUM - int "Wi-Fi dynamic RX buffer number" - default 32 - -config ESP32S2_WIFI_DYNAMIC_TXBUF_NUM - int "Wi-Fi dynamic TX buffer number" - default 32 - -config ESP32S2_WIFI_TX_AMPDU - bool "Wi-Fi TX AMPDU" - default y - -config ESP32S2_WIFI_RX_AMPDU - bool "Wi-Fi RX AMPDU" - default y - -config ESP32S2_WIFI_RXBA_AMPDU_WZ - int "Wi-Fi RX BA AMPDU windown size" - default 6 - -config ESP32S2_WLAN_PKTBUF_NUM - int "WLAN netcard packet buffer number per netcard" - default 16 - -config ESP32S2_WIFI_CONNECT_TIMEOUT - int "Connect timeout by second" - default 10 - ---help--- - Max waiting time of connecting to AP. - -config ESP32S2_WIFI_SCAN_RESULT_SIZE - int "Scan result buffer" - default 4096 - ---help--- - Maximum scan result buffer size. - -config ESP32S2_WIFI_SAVE_PARAM - bool "Save Wi-Fi Parameters" - default n - ---help--- - If you enable this option, Wi-Fi adapter parameters will be saved - into the file system instead of computing them each time. - - These parameters mainly contains: - - SSID - - Password - - BSSID - - PMK(compute when connecting) - - Author mode - - MAC address - - Wi-Fi hardware configuration parameters - -config ESP32S2_WIFI_FS_MOUNTPT - string "Wi-Fi parameters mount point" - default "/mnt/esp/wifi" - depends on ESP32S2_WIFI_SAVE_PARAM - ---help--- - Mount point of Wi-Fi storage file system. - -endmenu # ESP32S2_WIRELESS - -menu "Real-Time Timer" +menu "Real-Time Timer Configuration" depends on ESP32S2_RT_TIMER config ESP32S2_RT_TIMER_TASK_NAME @@ -882,10 +457,10 @@ config ESP32S2_RT_TIMER_TASK_STACK_SIZE int "Timer task stack size" default 2048 -endmenu # Real-Time Timer +endmenu # Real-Time Timer Configuration -if ESP32S2_TIMER -menu "Timer/counter Configuration" +menu "Timer/Counter Configuration" + depends on ESP32S2_TIMER config ESP32S2_ONESHOT bool "One-shot wrapper" @@ -901,8 +476,7 @@ config ESP32S2_FREERUN Enable a wrapper around the low level timer/counter functions to support freerun timer. -endmenu # Timer/counter Configuration -endif # ESP32S2_TIMER +endmenu # Timer/Counter Configuration config ESP32S2_HAVE_OTA_PARTITION bool @@ -1001,13 +575,4 @@ source "arch/xtensa/src/esp32s2/Kconfig.security" endmenu # Application Image Configuration -menu "AES accelerate" - depends on ESP32S2_AES_ACCELERATOR - -config ESP32S2_AES_ACCELERATOR_TEST - bool "AES driver test" - default n - -endmenu # ESP32S2_AES_ACCELERATOR - endif # ARCH_CHIP_ESP32S2 diff --git a/arch/xtensa/src/esp32s2/esp32s2_rt_timer.c b/arch/xtensa/src/esp32s2/esp32s2_rt_timer.c index 20539badd1e53..86e2161d37b80 100644 --- a/arch/xtensa/src/esp32s2/esp32s2_rt_timer.c +++ b/arch/xtensa/src/esp32s2/esp32s2_rt_timer.c @@ -74,7 +74,7 @@ struct esp32s2_rt_priv_s { - int pid; + pid_t pid; sem_t toutsem; struct list_node runlist; struct list_node toutlist; @@ -87,7 +87,7 @@ struct esp32s2_rt_priv_s static struct esp32s2_rt_priv_s g_rt_priv = { - .pid = -EINVAL, + .pid = INVALID_PROCESS_ID, }; /**************************************************************************** @@ -752,7 +752,7 @@ int esp32s2_rt_timer_init(void) list_initialize(&priv->runlist); list_initialize(&priv->toutlist); - priv->pid = pid; + priv->pid = (pid_t)pid; priv->timer = tim; flags = enter_critical_section(); @@ -832,10 +832,10 @@ void esp32s2_rt_timer_deinit(void) leave_critical_section(flags); - if (priv->pid != -EINVAL) + if (priv->pid != INVALID_PROCESS_ID) { kthread_delete(priv->pid); - priv->pid = -EINVAL; + priv->pid = INVALID_PROCESS_ID; } nxsem_destroy(&priv->toutsem); diff --git a/arch/xtensa/src/esp32s2/esp32s2_start.c b/arch/xtensa/src/esp32s2/esp32s2_start.c index 18dfe3408d749..addf53a46cab0 100644 --- a/arch/xtensa/src/esp32s2/esp32s2_start.c +++ b/arch/xtensa/src/esp32s2/esp32s2_start.c @@ -82,20 +82,55 @@ extern uint32_t _image_drom_lma; extern uint32_t _image_drom_size; #endif +typedef enum +{ + CACHE_MEMORY_INVALID = 0, + CACHE_MEMORY_ICACHE_LOW = 1 << 0, + CACHE_MEMORY_ICACHE_HIGH = 1 << 1, + CACHE_MEMORY_DCACHE_LOW = 1 << 2, + CACHE_MEMORY_DCACHE_HIGH = 1 << 3, +} cache_layout_t; + +typedef enum +{ + CACHE_SIZE_HALF = 0, /* 8KB for icache and dcache */ + CACHE_SIZE_FULL = 1, /* 16KB for icache and dcache */ +} cache_size_t; + +typedef enum +{ + CACHE_4WAYS_ASSOC = 0, /* 4 way associated cache */ + CACHE_8WAYS_ASSOC = 1, /* 8 way associated cache */ +} cache_ways_t; + +typedef enum +{ + CACHE_LINE_SIZE_16B = 0, /* 16 Byte cache line size */ + CACHE_LINE_SIZE_32B = 1, /* 32 Byte cache line size */ + CACHE_LINE_SIZE_64B = 2, /* 64 Byte cache line size */ +} cache_line_size_t; + /**************************************************************************** * ROM Function Prototypes ****************************************************************************/ #ifdef CONFIG_ESP32S2_APP_FORMAT_MCUBOOT extern int ets_printf(const char *fmt, ...); -extern uint32_t cache_suspend_icache(void); -extern void cache_resume_icache(uint32_t val); -extern void cache_invalidate_icache_all(void); extern int cache_ibus_mmu_set(uint32_t ext_ram, uint32_t vaddr, uint32_t paddr, uint32_t psize, uint32_t num, uint32_t fixed); #endif +extern uint32_t cache_suspend_icache(void); +extern void cache_resume_icache(uint32_t val); +extern void cache_invalidate_icache_all(void); +extern void cache_set_icache_mode(cache_size_t cache_size, cache_ways_t ways, + cache_line_size_t cache_line_size); +extern void cache_allocate_sram(cache_layout_t sram0_layout, + cache_layout_t sram1_layout, + cache_layout_t sram2_layout, + cache_layout_t sram3_layout); + /**************************************************************************** * Private Function Prototypes ****************************************************************************/ @@ -125,6 +160,54 @@ uint32_t g_idlestack[IDLETHREAD_STACKWORDS] * Private Functions ****************************************************************************/ +/**************************************************************************** + * Name: configure_cpu_caches + * + * Description: + * Configure the Instruction and Data CPU caches. + * + * Input Parameters: + * None. + * + * Returned Value: + * None. + * + ****************************************************************************/ + +static void IRAM_ATTR configure_cpu_caches(void) +{ + cache_size_t cache_size; + cache_ways_t cache_ways; + cache_line_size_t cache_line_size; + + /* Configure the mode of instruction cache: cache size, cache associated + * ways, cache line size. + */ + +#ifdef CONFIG_ESP32S2_INSTRUCTION_CACHE_8KB + cache_allocate_sram(CACHE_MEMORY_ICACHE_LOW, CACHE_MEMORY_INVALID, + CACHE_MEMORY_INVALID, CACHE_MEMORY_INVALID); + cache_size = CACHE_SIZE_HALF; +#else + cache_allocate_sram(CACHE_MEMORY_ICACHE_LOW, CACHE_MEMORY_ICACHE_HIGH, + CACHE_MEMORY_INVALID, CACHE_MEMORY_INVALID); + cache_size = CACHE_SIZE_FULL; +#endif + + cache_ways = CACHE_4WAYS_ASSOC; + +#ifdef CONFIG_ESP32S2_INSTRUCTION_CACHE_LINE_16B + cache_line_size = CACHE_LINE_SIZE_16B; +#else + cache_line_size = CACHE_LINE_SIZE_32B; +#endif + + cache_suspend_icache(); + cache_set_icache_mode(cache_size, cache_ways, cache_line_size); + cache_invalidate_icache_all(); + cache_resume_icache(0); +} + /**************************************************************************** * Name: __esp32s2_start * @@ -139,15 +222,10 @@ uint32_t g_idlestack[IDLETHREAD_STACKWORDS] * ****************************************************************************/ -void IRAM_ATTR __esp32s2_start(void) +static void noreturn_function IRAM_ATTR __esp32s2_start(void) { - uint32_t regval; uint32_t sp; - regval = getreg32(DR_REG_BB_BASE + 0x48); /* DR_REG_BB_BASE+48 */ - regval &= ~(1 << 14); - putreg32(regval, DR_REG_BB_BASE + 0x48); - /* Make sure that normal interrupts are disabled. This is really only an * issue when we are started in un-usual ways (such as from IRAM). In this * case, we can at least defer some unexpected interrupts left over from @@ -173,8 +251,6 @@ void IRAM_ATTR __esp32s2_start(void) __asm__ __volatile__ ("wsr %0, vecbase\n"::"r" (&_init_start)); - /* Set .bss to zero */ - /* Clear .bss. We'll do this inline (vs. calling memset) just to be * certain that there are no issues with the state of global variables. */ @@ -335,15 +411,11 @@ static int map_rom_segments(void) * * Description: * We arrive here after the bootloader finished loading the program from - * flash. The hardware is mostly uninitialized, and the app CPU is in - * reset. We do have a stack, so we can do the initialization in C. - * - * The app CPU will remain in reset unless CONFIG_SMP is selected and - * up_cpu_start() is called later in the bring-up sequence. + * flash. We do have a stack, so we can do the initialization in C. * ****************************************************************************/ -void __start(void) +void IRAM_ATTR __start(void) { #ifdef CONFIG_ESP32S2_APP_FORMAT_MCUBOOT if (map_rom_segments() != 0) @@ -353,6 +425,9 @@ void __start(void) } #endif + + configure_cpu_caches(); + __esp32s2_start(); while (true); /* Should not return */ diff --git a/arch/xtensa/src/esp32s2/esp32s2_timerisr.c b/arch/xtensa/src/esp32s2/esp32s2_timerisr.c index 58130e4ba04a8..9220364c225d2 100644 --- a/arch/xtensa/src/esp32s2/esp32s2_timerisr.c +++ b/arch/xtensa/src/esp32s2/esp32s2_timerisr.c @@ -24,17 +24,17 @@ #include +#include #include #include -#include #include -#include #include +#include #include "clock/clock.h" -#include "xtensa_timer.h" #include "xtensa.h" +#include "xtensa_counter.h" /**************************************************************************** * Private data @@ -46,52 +46,6 @@ static uint32_t g_tick_divisor; * Private Functions ****************************************************************************/ -/**************************************************************************** - * Function: xtensa_getcount, xtensa_getcompare, and xtensa_setcompare - * - * Description: - * Lower level operations on Xtensa special registers. - * - ****************************************************************************/ - -/* Return the current value of the cycle count register */ - -static inline uint32_t xtensa_getcount(void) -{ - uint32_t count; - - __asm__ __volatile__ - ( - "rsr %0, CCOUNT" : "=r"(count) - ); - - return count; -} - -/* Return the old value of the compare register */ - -static inline uint32_t xtensa_getcompare(void) -{ - uint32_t compare; - - __asm__ __volatile__ - ( - "rsr %0, %1" : "=r"(compare) : "i"(XT_CCOMPARE) - ); - - return compare; -} - -/* Set the value of the compare register */ - -static inline void xtensa_setcompare(uint32_t compare) -{ - __asm__ __volatile__ - ( - "wsr %0, %1" : : "r"(compare), "i"(XT_CCOMPARE) - ); -} - /**************************************************************************** * Function: esp32s2_timerisr * diff --git a/arch/xtensa/src/esp32s3/Kconfig b/arch/xtensa/src/esp32s3/Kconfig index ab7a1423c2b26..d9896ab75c2cd 100644 --- a/arch/xtensa/src/esp32s3/Kconfig +++ b/arch/xtensa/src/esp32s3/Kconfig @@ -511,6 +511,12 @@ config ESP32S3_SPIRAM_IGNORE_NOTFOUND endmenu # SPI RAM Configuration +config ESP32S3_GPIO_IRQ + bool "GPIO pin interrupts" + default n + ---help--- + Enable support for interrupting GPIO pins. + menu "UART Configuration" depends on ESP32S3_UART diff --git a/arch/xtensa/src/esp32s3/esp32s3_gpio.c b/arch/xtensa/src/esp32s3/esp32s3_gpio.c index a562dc0132acd..c10948ad27b6b 100644 --- a/arch/xtensa/src/esp32s3/esp32s3_gpio.c +++ b/arch/xtensa/src/esp32s3/esp32s3_gpio.c @@ -24,21 +24,20 @@ #include -#include -#include #include #include +#include +#include +#include #include #include -#include #include "xtensa.h" +#include "esp32s3_gpio.h" #include "esp32s3_irq.h" -#include "hardware/esp32s3_iomux.h" #include "hardware/esp32s3_gpio.h" - -#include "esp32s3_gpio.h" +#include "hardware/esp32s3_iomux.h" /**************************************************************************** * Pre-processor Definitions @@ -50,6 +49,10 @@ * Private Data ****************************************************************************/ +#ifdef CONFIG_ESP32S3_GPIO_IRQ +static int g_gpio_cpuint; +#endif + /**************************************************************************** * Private Functions ****************************************************************************/ @@ -75,6 +78,94 @@ static inline bool is_valid_gpio(uint32_t pin) return pin <= 21 || (pin >= 26 && pin < ESP32S3_NPINS); } +/**************************************************************************** + * Name: gpio_dispatch + * + * Description: + * Second level dispatch for GPIO interrupt handling. + * + * Input Parameters: + * irq - GPIO IRQ number. + * status - Value from the GPIO interrupt status clear register. + * regs - Saved CPU context. + * + * Returned Value: + * None. + * + ****************************************************************************/ + +#ifdef CONFIG_ESP32S3_GPIO_IRQ +static void gpio_dispatch(int irq, uint32_t status, uint32_t *regs) +{ + uint32_t mask; + int i; + + /* Check each bit in the status register */ + + for (i = 0; i < 32 && status != 0; i++) + { + /* Check if there is an interrupt pending for this pin */ + + mask = UINT32_C(1) << i; + if ((status & mask) != 0) + { + /* Yes... perform the second level dispatch */ + + irq_dispatch(irq + i, regs); + + /* Clear the bit in the status so that we might execute this loop + * sooner. + */ + + status &= ~mask; + } + } +} +#endif + +/**************************************************************************** + * Name: gpio_interrupt + * + * Description: + * GPIO interrupt handler. + * + * Input Parameters: + * irq - Identifier of the interrupt request. + * context - Context data from the ISR. + * arg - Opaque pointer to the internal driver state structure. + * + * Returned Value: + * Zero (OK) is returned on success; a negated errno value is returned + * on failure. + * + ****************************************************************************/ + +#ifdef CONFIG_ESP32S3_GPIO_IRQ +static int gpio_interrupt(int irq, void *context, void *arg) +{ + uint32_t status; + + /* Read and clear the lower GPIO interrupt status */ + + status = getreg32(GPIO_STATUS_REG); + putreg32(status, GPIO_STATUS_W1TC_REG); + + /* Dispatch pending interrupts in the lower GPIO status register */ + + gpio_dispatch(ESP32S3_FIRST_GPIOIRQ, status, (uint32_t *)context); + + /* Read and clear the upper GPIO interrupt status */ + + status = getreg32(GPIO_STATUS1_REG); + putreg32(status, GPIO_STATUS1_W1TC_REG); + + /* Dispatch pending interrupts in the lower GPIO status register */ + + gpio_dispatch(ESP32S3_FIRST_GPIOIRQ + 32, status, (uint32_t *)context); + return OK; +} +#endif + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -198,12 +289,220 @@ int esp32s3_configgpio(uint32_t pin, gpio_pinattr_t attr) return OK; } +/**************************************************************************** + * Name: esp32s3_gpiowrite + * + * Description: + * Write one or zero to the selected GPIO pin. + * + * Input Parameters: + * pin - GPIO pin to be written. + * value - Value to be written to the GPIO pin. True will output + * 1 (one) to the GPIO, while false will output 0 (zero). + * + * Returned Value: + * None. + * + ****************************************************************************/ + +void esp32s3_gpiowrite(int pin, bool value) +{ + DEBUGASSERT(is_valid_gpio(pin)); + + if (value) + { + if (pin < 32) + { + putreg32(UINT32_C(1) << pin, GPIO_OUT_W1TS_REG); + } + else + { + putreg32(UINT32_C(1) << (pin - 32), GPIO_OUT1_W1TS_REG); + } + } + else + { + if (pin < 32) + { + putreg32(UINT32_C(1) << pin, GPIO_OUT_W1TC_REG); + } + else + { + putreg32(UINT32_C(1) << (pin - 32), GPIO_OUT1_W1TC_REG); + } + } +} + +/**************************************************************************** + * Name: esp32s3_gpioread + * + * Description: + * Read one or zero from the selected GPIO pin. + * + * Input Parameters: + * pin - GPIO pin to be read. + * + * Returned Value: + * True in case the read value is 1 (one). If 0 (zero), then false will be + * returned. + * + ****************************************************************************/ + +bool esp32s3_gpioread(int pin) +{ + uint32_t regval; + + DEBUGASSERT(is_valid_gpio(pin)); + + if (pin < 32) + { + regval = getreg32(GPIO_IN_REG); + return ((regval >> pin) & 1) != 0; + } + else + { + regval = getreg32(GPIO_IN1_REG); + return ((regval >> (pin - 32)) & 1) != 0; + } +} + +/**************************************************************************** + * Name: esp32s3_gpioirqinitialize + * + * Description: + * Initialize logic to support a second level of interrupt decoding for + * GPIO pins. + * + * Input Parameters: + * None. + * + * Returned Value: + * None. + * + ****************************************************************************/ + +#ifdef CONFIG_ESP32S3_GPIO_IRQ +void esp32s3_gpioirqinitialize(void) +{ + int cpu; + + /* Setup the GPIO interrupt. */ + + cpu = up_cpu_index(); + + g_gpio_cpuint = esp32s3_setup_irq(cpu, ESP32S3_PERIPH_GPIO_INT_CPU, 1, + ESP32S3_CPUINT_LEVEL); + DEBUGASSERT(g_gpio_cpuint >= 0); + + /* Attach and enable the interrupt handler */ + + DEBUGVERIFY(irq_attach(ESP32S3_IRQ_GPIO_INT_CPU, gpio_interrupt, NULL)); + up_enable_irq(ESP32S3_IRQ_GPIO_INT_CPU); +} +#endif + +/**************************************************************************** + * Name: esp32s3_gpioirqenable + * + * Description: + * Enable the interrupt for the specified GPIO IRQ. + * + * Input Parameters: + * irq - Identifier of the interrupt request. + * intrtype - Interrupt type, select from gpio_intrtype_t. + * + * Returned Value: + * None. + * + ****************************************************************************/ + +#ifdef CONFIG_ESP32S3_GPIO_IRQ +void esp32s3_gpioirqenable(int irq, gpio_intrtype_t intrtype) +{ + uintptr_t regaddr; + uint32_t regval; + int pin; + + DEBUGASSERT(irq >= ESP32S3_FIRST_GPIOIRQ && irq <= ESP32S3_LAST_GPIOIRQ); + + /* Convert the IRQ number to a pin number */ + + pin = ESP32S3_IRQ2PIN(irq); + + /* Disable the GPIO interrupt during the configuration. */ + + up_disable_irq(ESP32S3_IRQ_GPIO_INT_CPU); + + /* Get the address of the GPIO PIN register for this pin */ + + regaddr = GPIO_REG(pin); + regval = getreg32(regaddr); + regval &= ~(GPIO_PIN0_INT_ENA_M | GPIO_PIN0_INT_TYPE_M); + + /* Set the pin ENA field. + * On ESP32-S3, CPU0 and CPU1 share the same interrupt enable bit. + */ + + regval |= GPIO_PIN0_INT_ENA_M; + regval |= (uint32_t)intrtype << GPIO_PIN0_INT_TYPE_S; + putreg32(regval, regaddr); + + /* Configuration done. Re-enable the GPIO interrupt. */ + + up_enable_irq(ESP32S3_IRQ_GPIO_INT_CPU); +} +#endif + +/**************************************************************************** + * Name: esp32s3_gpioirqdisable + * + * Description: + * Disable the interrupt for the specified GPIO IRQ. + * + * Input Parameters: + * irq - Identifier of the interrupt request. + * + * Returned Value: + * None. + * + ****************************************************************************/ + +#ifdef CONFIG_ESP32S3_GPIO_IRQ +void esp32s3_gpioirqdisable(int irq) +{ + uintptr_t regaddr; + uint32_t regval; + int pin; + + DEBUGASSERT(irq >= ESP32S3_FIRST_GPIOIRQ && irq <= ESP32S3_LAST_GPIOIRQ); + + /* Convert the IRQ number to a pin number */ + + pin = ESP32S3_IRQ2PIN(irq); + + /* Disable the GPIO interrupt during the configuration. */ + + up_disable_irq(ESP32S3_IRQ_GPIO_INT_CPU); + + /* Reset the pin ENA and TYPE fields */ + + regaddr = GPIO_REG(pin); + regval = getreg32(regaddr); + regval &= ~(GPIO_PIN0_INT_ENA_M | GPIO_PIN0_INT_TYPE_M); + putreg32(regval, regaddr); + + /* Configuration done. Re-enable the GPIO interrupt. */ + + up_enable_irq(ESP32S3_IRQ_GPIO_INT_CPU); +} +#endif + /**************************************************************************** * Name: esp32s3_gpio_matrix_in * * Description: * Set GPIO input to a signal. - * NOTE: one GPIO can input to several signals. + * NOTE: one GPIO can receive inputs from several signals. * * Input Parameters: * pin - GPIO pin to be configured. diff --git a/arch/xtensa/src/esp32s3/esp32s3_gpio.h b/arch/xtensa/src/esp32s3/esp32s3_gpio.h index b173e047d553b..7d2c203b63f80 100644 --- a/arch/xtensa/src/esp32s3/esp32s3_gpio.h +++ b/arch/xtensa/src/esp32s3/esp32s3_gpio.h @@ -93,15 +93,6 @@ # define OUTPUT_FUNCTION_5 (OUTPUT_FUNCTION | FUNCTION_5) # define OUTPUT_FUNCTION_6 (OUTPUT_FUNCTION | FUNCTION_6) -/* Interrupt type used with esp32s3_gpioirqenable() */ - -#define DISABLED 0x00 -#define RISING 0x01 -#define FALLING 0x02 -#define CHANGE 0x03 -#define ONLOW 0x04 -#define ONHIGH 0x05 - /**************************************************************************** * Public Types ****************************************************************************/ @@ -111,7 +102,16 @@ /* Must be big enough to hold the above encodings */ typedef uint16_t gpio_pinattr_t; -typedef uint8_t gpio_intrtype_t; + +typedef enum gpio_intrtype_e +{ + GPIO_INTR_DISABLE = 0, /* Disable GPIO interrupt */ + GPIO_INTR_POSEDGE = 1, /* Rising edge */ + GPIO_INTR_NEGEDGE = 2, /* Falling edge */ + GPIO_INTR_ANYEDGE = 3, /* Both rising and falling edge */ + GPIO_INTR_LOW_LEVEL = 4, /* Input low level trigger */ + GPIO_INTR_HIGH_LEVEL = 5 /* Input high level trigger */ +} gpio_intrtype_t; /**************************************************************************** * Public Data @@ -130,6 +130,27 @@ extern "C" * Public Function Prototypes ****************************************************************************/ +/**************************************************************************** + * Name: esp32s3_gpioirqinitialize + * + * Description: + * Initialize logic to support a second level of interrupt decoding for + * GPIO pins. + * + * Input Parameters: + * None. + * + * Returned Value: + * None. + * + ****************************************************************************/ + +#ifdef CONFIG_ESP32S3_GPIO_IRQ +void esp32s3_gpioirqinitialize(void); +#else +# define esp32s3_gpioirqinitialize() +#endif + /**************************************************************************** * Name: esp32s3_configgpio * @@ -154,12 +175,88 @@ extern "C" int esp32s3_configgpio(uint32_t pin, gpio_pinattr_t attr); +/**************************************************************************** + * Name: esp32s3_gpiowrite + * + * Description: + * Write one or zero to the selected GPIO pin. + * + * Input Parameters: + * pin - GPIO pin to be written. + * value - Value to be written to the GPIO pin. True will output + * 1 (one) to the GPIO, while false will output 0 (zero). + * + * Returned Value: + * None. + * + ****************************************************************************/ + +void esp32s3_gpiowrite(int pin, bool value); + +/**************************************************************************** + * Name: esp32s3_gpioread + * + * Description: + * Read one or zero from the selected GPIO pin. + * + * Input Parameters: + * pin - GPIO pin to be read. + * + * Returned Value: + * True in case the read value is 1 (one). If 0 (zero), then false will be + * returned. + * + ****************************************************************************/ + +bool esp32s3_gpioread(int pin); + +/**************************************************************************** + * Name: esp32s3_gpioirqenable + * + * Description: + * Enable the interrupt for the specified GPIO IRQ. + * + * Input Parameters: + * irq - Identifier of the interrupt request. + * intrtype - Interrupt type, select from gpio_intrtype_t. + * + * Returned Value: + * None. + * + ****************************************************************************/ + +#ifdef CONFIG_ESP32S3_GPIO_IRQ +void esp32s3_gpioirqenable(int irq, gpio_intrtype_t intrtype); +#else +# define esp32s3_gpioirqenable(irq,intrtype) +#endif + +/**************************************************************************** + * Name: esp32s3_gpioirqdisable + * + * Description: + * Disable the interrupt for the specified GPIO IRQ. + * + * Input Parameters: + * irq - Identifier of the interrupt request. + * + * Returned Value: + * None. + * + ****************************************************************************/ + +#ifdef CONFIG_ESP32S3_GPIO_IRQ +void esp32s3_gpioirqdisable(int irq); +#else +# define esp32s3_gpioirqdisable(irq) +#endif + /**************************************************************************** * Name: esp32s3_gpio_matrix_in * * Description: * Set GPIO input to a signal. - * NOTE: one GPIO can input to several signals. + * NOTE: one GPIO can receive inputs from several signals. * * Input Parameters: * pin - GPIO pin to be configured. diff --git a/arch/xtensa/src/esp32s3/esp32s3_irq.c b/arch/xtensa/src/esp32s3/esp32s3_irq.c index 5e98d4b63e93c..c9f1d8e936473 100644 --- a/arch/xtensa/src/esp32s3/esp32s3_irq.c +++ b/arch/xtensa/src/esp32s3/esp32s3_irq.c @@ -38,6 +38,7 @@ #include "xtensa.h" +#include "esp32s3_gpio.h" #include "esp32s3_irq.h" #ifdef CONFIG_SMP #include "esp32s3_smp.h" @@ -446,6 +447,10 @@ void up_irqinitialize(void) xtensa_attach_fromcpu1_interrupt(); #endif + /* Initialize GPIO interrupt support */ + + esp32s3_gpioirqinitialize(); + #ifndef CONFIG_SUPPRESS_INTERRUPTS /* And finally, enable interrupts. Also clears PS.EXCM */ diff --git a/arch/xtensa/src/esp32s3/esp32s3_rt_timer.c b/arch/xtensa/src/esp32s3/esp32s3_rt_timer.c index b69d093a63a16..52d9f669fae47 100644 --- a/arch/xtensa/src/esp32s3/esp32s3_rt_timer.c +++ b/arch/xtensa/src/esp32s3/esp32s3_rt_timer.c @@ -72,7 +72,7 @@ static_assert(RT_TIMER_TASK_PRIORITY < CONFIG_SCHED_HPWORKPRIORITY, struct esp32s3_rt_priv_s { - int pid; /* PID of RT Timer kernel thread */ + pid_t pid; /* PID of RT Timer kernel thread */ int cpuint; /* CPU interrupt assigned to this timer */ int core; /* Core that is taking care of the timer * interrupts @@ -91,7 +91,7 @@ struct esp32s3_rt_priv_s static struct esp32s3_rt_priv_s g_rt_priv = { - .pid = -EINVAL, + .pid = INVALID_PROCESS_ID, .cpuint = -ENOMEM, .core = -ENODEV }; @@ -961,7 +961,7 @@ int esp32s3_rt_timer_init(void) list_initialize(&priv->runlist); list_initialize(&priv->toutlist); - priv->pid = pid; + priv->pid = (pid_t)pid; flags = spin_lock_irqsave(&priv->lock); @@ -1044,10 +1044,10 @@ void esp32s3_rt_timer_deinit(void) spin_unlock_irqrestore(&priv->lock, flags); - if (priv->pid != -EINVAL) + if (priv->pid != INVALID_PROCESS_ID) { kthread_delete(priv->pid); - priv->pid = -EINVAL; + priv->pid = INVALID_PROCESS_ID; } nxsem_destroy(&priv->toutsem); diff --git a/arch/xtensa/src/lx6/Toolchain.defs b/arch/xtensa/src/lx6/Toolchain.defs index b0db847f4a2b6..4dc7236e9e5e7 100644 --- a/arch/xtensa/src/lx6/Toolchain.defs +++ b/arch/xtensa/src/lx6/Toolchain.defs @@ -55,6 +55,10 @@ else MAXOPTIMIZATION += -fomit-frame-pointer endif +ifeq ($(CONFIG_MM_KASAN),y) + ARCHCPUFLAGS += -fsanitize=kernel-address +endif + # Default toolchain ifeq ($(CONFIG_XTENSA_TOOLCHAIN_XCC), y) CC = $(CROSSDEV)xcc @@ -79,12 +83,12 @@ OBJDUMP = $(CROSSDEV)objdump # Add the builtin library -EXTRA_LIBS += ${shell $(CC) $(ARCHCPUFLAGS) --print-libgcc-file-name} +EXTRA_LIBS += ${wildcard ${shell $(CC) $(ARCHCPUFLAGS) --print-libgcc-file-name}} ifneq ($(CONFIG_LIBM),y) EXTRA_LIBS += ${wildcard ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libm.a}} endif ifeq ($(CONFIG_LIBSUPCXX),y) - EXTRA_LIBS += ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libsupc++.a} + EXTRA_LIBS += ${wildcard ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libsupc++.a}} endif diff --git a/arch/xtensa/src/lx7/Toolchain.defs b/arch/xtensa/src/lx7/Toolchain.defs index 5406264e73809..9f94f87cc7ed5 100644 --- a/arch/xtensa/src/lx7/Toolchain.defs +++ b/arch/xtensa/src/lx7/Toolchain.defs @@ -55,6 +55,10 @@ else MAXOPTIMIZATION += -fomit-frame-pointer endif +ifeq ($(CONFIG_MM_KASAN),y) + ARCHCPUFLAGS += -fsanitize=kernel-address +endif + # Default toolchain ifeq ($(CONFIG_XTENSA_TOOLCHAIN_XCC), y) CC = $(CROSSDEV)xcc @@ -79,12 +83,12 @@ OBJDUMP = $(CROSSDEV)objdump # Add the builtin library -EXTRA_LIBS += ${shell $(CC) $(ARCHCPUFLAGS) --print-libgcc-file-name} +EXTRA_LIBS += ${wildcard ${shell $(CC) $(ARCHCPUFLAGS) --print-libgcc-file-name}} ifneq ($(CONFIG_LIBM),y) EXTRA_LIBS += ${wildcard ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libm.a}} endif ifeq ($(CONFIG_LIBSUPCXX),y) - EXTRA_LIBS += ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libsupc++.a} + EXTRA_LIBS += ${wildcard ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libsupc++.a}} endif diff --git a/arch/z80/src/z180/z180_initialstate.c b/arch/z80/src/z180/z180_initialstate.c index 74d2801203033..14c0d002b37f0 100644 --- a/arch/z80/src/z180/z180_initialstate.c +++ b/arch/z80/src/z180/z180_initialstate.c @@ -54,7 +54,7 @@ void up_initial_state(struct tcb_s *tcb) /* Initialize the idle thread stack */ - if (tcb->pid == 0) + if (tcb->pid == IDLE_PROCESS_ID) { char *stack_ptr = (char *)CONFIG_STACK_BASE; #ifdef CONFIG_STACK_COLORATION diff --git a/arch/z80/src/z80/z80_initialstate.c b/arch/z80/src/z80/z80_initialstate.c index 2b63860d3c790..b26c3f1be1207 100644 --- a/arch/z80/src/z80/z80_initialstate.c +++ b/arch/z80/src/z80/z80_initialstate.c @@ -54,7 +54,7 @@ void up_initial_state(struct tcb_s *tcb) /* Initialize the idle thread stack */ - if (tcb->pid == 0) + if (tcb->pid == IDLE_PROCESS_ID) { char *stack_ptr = (char *)CONFIG_STACK_BASE; #ifdef CONFIG_STACK_COLORATION diff --git a/binfmt/libelf/libelf_coredump.c b/binfmt/libelf/libelf_coredump.c index a012ce441cbc8..014621aca5c81 100644 --- a/binfmt/libelf/libelf_coredump.c +++ b/binfmt/libelf/libelf_coredump.c @@ -227,11 +227,11 @@ static void elf_emit_note_info(FAR struct elf_dumpinfo_s *cinfo) elf_emit(cinfo, &nhdr, sizeof(nhdr)); - strncpy(name, tcb->name, sizeof(name)); + strlcpy(name, tcb->name, sizeof(name)); elf_emit(cinfo, name, sizeof(name)); info.pr_pid = tcb->pid; - strncpy(info.pr_fname, tcb->name, sizeof(info.pr_fname)); + strlcpy(info.pr_fname, tcb->name, sizeof(info.pr_fname)); elf_emit(cinfo, &info, sizeof(info)); /* Fill Process status */ diff --git a/boards/Kconfig b/boards/Kconfig index 4d8c44911e85d..a571070007980 100644 --- a/boards/Kconfig +++ b/boards/Kconfig @@ -283,6 +283,8 @@ config ARCH_BOARD_ESP32S3_DEVKIT bool "Espressif ESP32-S3 DevKit" depends on ARCH_CHIP_ESP32S3WROOM1 || ARCH_CHIP_ESP32S3MINI1 select ARCH_HAVE_LEDS + select ARCH_HAVE_BUTTONS + select ARCH_HAVE_IRQBUTTONS if ESP32S3_GPIO_IRQ ---help--- The ESP32-S3 DevKit features the ESP32-S3 CPU with dual Xtensa LX7 cores. It comes in two flavors, the ESP32-S3-DevKitM-1 and the ESP32-S3-DevKitC-1. diff --git a/boards/arm/imxrt/imxrt1020-evk/src/imxrt_usbhost.c b/boards/arm/imxrt/imxrt1020-evk/src/imxrt_usbhost.c index b36fde03c9b66..c32dcbc785bd3 100644 --- a/boards/arm/imxrt/imxrt1020-evk/src/imxrt_usbhost.c +++ b/boards/arm/imxrt/imxrt1020-evk/src/imxrt_usbhost.c @@ -131,7 +131,6 @@ static int ehci_waiter(int argc, char *argv[]) int imxrt_usbhost_initialize(void) { - pid_t pid; int ret; imxrt_clockall_usboh3(); @@ -205,10 +204,10 @@ int imxrt_usbhost_initialize(void) /* Start a thread to handle device connection. */ - pid = kthread_create("EHCI Monitor", CONFIG_USBHOST_DEFPRIO, + ret = kthread_create("EHCI Monitor", CONFIG_USBHOST_DEFPRIO, CONFIG_USBHOST_STACKSIZE, (main_t)ehci_waiter, (FAR char * const *)NULL); - if (pid < 0) + if (ret < 0) { uerr("ERROR: Failed to create ehci_waiter task: %d\n", ret); return -ENODEV; diff --git a/boards/arm/imxrt/imxrt1060-evk/src/imxrt_usbhost.c b/boards/arm/imxrt/imxrt1060-evk/src/imxrt_usbhost.c index eabd144d13b26..ac3c6b4612440 100644 --- a/boards/arm/imxrt/imxrt1060-evk/src/imxrt_usbhost.c +++ b/boards/arm/imxrt/imxrt1060-evk/src/imxrt_usbhost.c @@ -131,7 +131,6 @@ static int ehci_waiter(int argc, char *argv[]) int imxrt_usbhost_initialize(void) { - pid_t pid; int ret; imxrt_clockall_usboh3(); @@ -203,10 +202,10 @@ int imxrt_usbhost_initialize(void) /* Start a thread to handle device connection. */ - pid = kthread_create("EHCI Monitor", CONFIG_USBHOST_DEFPRIO, + ret = kthread_create("EHCI Monitor", CONFIG_USBHOST_DEFPRIO, CONFIG_USBHOST_STACKSIZE, (main_t)ehci_waiter, (FAR char * const *)NULL); - if (pid < 0) + if (ret < 0) { uerr("ERROR: Failed to create ehci_waiter task: %d\n", ret); return -ENODEV; diff --git a/boards/arm/imxrt/imxrt1064-evk/src/imxrt_usbhost.c b/boards/arm/imxrt/imxrt1064-evk/src/imxrt_usbhost.c index 925bba420f2ae..580fc1dd9d142 100644 --- a/boards/arm/imxrt/imxrt1064-evk/src/imxrt_usbhost.c +++ b/boards/arm/imxrt/imxrt1064-evk/src/imxrt_usbhost.c @@ -131,7 +131,6 @@ static int ehci_waiter(int argc, char *argv[]) int imxrt_usbhost_initialize(void) { - pid_t pid; int ret; imxrt_clockall_usboh3(); @@ -203,10 +202,10 @@ int imxrt_usbhost_initialize(void) /* Start a thread to handle device connection. */ - pid = kthread_create("EHCI Monitor", CONFIG_USBHOST_DEFPRIO, + ret = kthread_create("EHCI Monitor", CONFIG_USBHOST_DEFPRIO, CONFIG_USBHOST_STACKSIZE, (main_t)ehci_waiter, (FAR char * const *)NULL); - if (pid < 0) + if (ret < 0) { uerr("ERROR: Failed to create ehci_waiter task: %d\n", ret); return -ENODEV; diff --git a/boards/arm/imxrt/teensy-4.x/configs/lua-4.1/defconfig b/boards/arm/imxrt/teensy-4.x/configs/lua-4.1/defconfig new file mode 100644 index 0000000000000..e63363f8303ff --- /dev/null +++ b/boards/arm/imxrt/teensy-4.x/configs/lua-4.1/defconfig @@ -0,0 +1,66 @@ +# +# This file is autogenerated: PLEASE DO NOT EDIT IT. +# +# You can use "make menuconfig" to make any modifications to the installed .config file. +# You can then do "make savedefconfig" to generate a new defconfig file that includes your +# modifications. +# +# CONFIG_ARCH_LEDS is not set +# CONFIG_MMCSD_HAVE_WRITEPROTECT is not set +# CONFIG_MMCSD_SPI is not set +CONFIG_ARCH="arm" +CONFIG_ARCH_BOARD="teensy-4.x" +CONFIG_ARCH_BOARD_TEENSY_4X=y +CONFIG_ARCH_CHIP="imxrt" +CONFIG_ARCH_CHIP_IMXRT=y +CONFIG_ARCH_CHIP_MIMXRT1062DVL6A=y +CONFIG_ARCH_STACKDUMP=y +CONFIG_ARMV7M_DCACHE=y +CONFIG_ARMV7M_DCACHE_WRITETHROUGH=y +CONFIG_ARMV7M_ICACHE=y +CONFIG_ARMV7M_USEBASEPRI=y +CONFIG_BOARD_LOOPSPERMSEC=104926 +CONFIG_BUILTIN=y +CONFIG_CDCACM=y +CONFIG_CDCACM_CONSOLE=y +CONFIG_EXAMPLES_LUA_MODULE=y +CONFIG_FAT_LCNAMES=y +CONFIG_FAT_LFN=y +CONFIG_FS_FAT=y +CONFIG_FS_PROCFS=y +CONFIG_IDLETHREAD_STACKSIZE=2048 +CONFIG_IMXRT_LPUART1=y +CONFIG_IMXRT_USBDEV=y +CONFIG_IMXRT_USDHC1=y +CONFIG_IMXRT_USDHC1_INVERT_CD=y +CONFIG_IMXRT_USDHC1_WIDTH_D1_D4=y +CONFIG_INIT_ENTRYPOINT="nsh_main" +CONFIG_INTELHEX_BINARY=y +CONFIG_INTERPRETERS_LUA=y +CONFIG_LIBC_FLOATINGPOINT=y +CONFIG_MMCSD=y +CONFIG_MMCSD_MULTIBLOCK_LIMIT=1 +CONFIG_MMCSD_SDIO=y +CONFIG_NSH_ARCHINIT=y +CONFIG_NSH_BUILTIN_APPS=y +CONFIG_NSH_DISABLE_IFUPDOWN=y +CONFIG_NSH_FILEIOSIZE=512 +CONFIG_NSH_LINELEN=64 +CONFIG_NSH_READLINE=y +CONFIG_NSH_USBCONSOLE=y +CONFIG_RAM_SIZE=1048576 +CONFIG_RAM_START=0x20200000 +CONFIG_READLINE_CMD_HISTORY=y +CONFIG_READLINE_TABCOMPLETION=y +CONFIG_SCHED_HPWORK=y +CONFIG_SDIO_BLOCKSETUP=y +CONFIG_SPI=y +CONFIG_SPI_CALLBACK=y +CONFIG_SPI_CMDDATA=y +CONFIG_START_DAY=14 +CONFIG_START_MONTH=3 +CONFIG_SYSTEM_NSH=y +CONFIG_TEENSY_41=y +CONFIG_USBDEV=y +CONFIG_USERLED=y +CONFIG_USERLED_LOWER=y diff --git a/boards/arm/kinetis/freedom-k28f/src/k28_usbhshost.c b/boards/arm/kinetis/freedom-k28f/src/k28_usbhshost.c index 4013c1863e5b8..b5d67cda657ac 100644 --- a/boards/arm/kinetis/freedom-k28f/src/k28_usbhshost.c +++ b/boards/arm/kinetis/freedom-k28f/src/k28_usbhshost.c @@ -398,7 +398,6 @@ static void usb_msc_disconnect(FAR void *arg) int k28_usbhost_initialize(void) { - pid_t pid; int ret; # ifdef HAVE_USB_AUTOMOUNTER int index; @@ -479,10 +478,10 @@ int k28_usbhost_initialize(void) /* Start a thread to handle device connection. */ - pid = kthread_create("EHCI Monitor", CONFIG_USBHOST_DEFPRIO, + ret = kthread_create("EHCI Monitor", CONFIG_USBHOST_DEFPRIO, CONFIG_USBHOST_STACKSIZE, (main_t)ehci_waiter, (FAR char * const *)NULL); - if (pid < 0) + if (ret < 0) { uerr("ERROR: Failed to create ehci_waiter task: %d\n", ret); return -ENODEV; diff --git a/boards/arm/kinetis/freedom-k64f/src/k64_uid.c b/boards/arm/kinetis/freedom-k64f/src/k64_uid.c index 5b6c8b2cac3ce..7095eb0faf43e 100644 --- a/boards/arm/kinetis/freedom-k64f/src/k64_uid.c +++ b/boards/arm/kinetis/freedom-k64f/src/k64_uid.c @@ -52,7 +52,7 @@ int board_uniqueid(FAR uint8_t *uniqueid) { - if (uniqueid == 0) + if (uniqueid == NULL) { return -EINVAL; } diff --git a/boards/arm/kinetis/twr-k64f120m/README.txt b/boards/arm/kinetis/twr-k64f120m/README.txt index 4026b9eaa88d7..17ee5b8d73a91 100644 --- a/boards/arm/kinetis/twr-k64f120m/README.txt +++ b/boards/arm/kinetis/twr-k64f120m/README.txt @@ -36,7 +36,7 @@ Kinetis TWR-K64F120M Features: o Touch TWRPI Socket adds support for various capacitive touch boards (e.g. keypads, rotary dials, sliders, etc.) o Tower connectivity for access to USB, Ethernet, RS232/RS485, CAN, SPI, - I²C, Flexbus, etc. + I²C, Flexbus, etc. o Plus: Potentiometer, 4 LEDs, 2 pushbuttons, accelerometer, RTC battery Kinetis TWR-K64F120M Pin Configuration diff --git a/boards/arm/lpc17xx_40xx/lpc4088-devkit/src/lpc17_40_bringup.c b/boards/arm/lpc17xx_40xx/lpc4088-devkit/src/lpc17_40_bringup.c index 4c8f17d5ede7d..0d3ddc963560a 100644 --- a/boards/arm/lpc17xx_40xx/lpc4088-devkit/src/lpc17_40_bringup.c +++ b/boards/arm/lpc17xx_40xx/lpc4088-devkit/src/lpc17_40_bringup.c @@ -260,7 +260,6 @@ static int nsh_sdinitialize(void) #ifdef NSH_HAVE_USBHOST static int nsh_usbhostinitialize(void) { - int pid; int ret; /* First, register all of the class drivers needed to support the drivers @@ -302,10 +301,10 @@ static int nsh_usbhostinitialize(void) syslog(LOG_INFO, "Start nsh_waiter\n"); - pid = kthread_create("usbhost", CONFIG_USBHOST_DEFPRIO, + ret = kthread_create("usbhost", CONFIG_USBHOST_DEFPRIO, CONFIG_USBHOST_STACKSIZE, (main_t)nsh_waiter, (FAR char * const *)NULL); - return pid < 0 ? -ENOEXEC : OK; + return ret < 0 ? -ENOEXEC : OK; } return -ENODEV; diff --git a/boards/arm/lpc17xx_40xx/lpc4088-quickstart/src/lpc17_40_bringup.c b/boards/arm/lpc17xx_40xx/lpc4088-quickstart/src/lpc17_40_bringup.c index 69fb4e59ecb53..0c60eb0fb4cf6 100644 --- a/boards/arm/lpc17xx_40xx/lpc4088-quickstart/src/lpc17_40_bringup.c +++ b/boards/arm/lpc17xx_40xx/lpc4088-quickstart/src/lpc17_40_bringup.c @@ -296,7 +296,6 @@ static int nsh_sdinitialize(void) #ifdef NSH_HAVE_USBHOST static int nsh_usbhostinitialize(void) { - int pid; int ret; /* First, register all of the class drivers needed to support the drivers @@ -338,10 +337,10 @@ static int nsh_usbhostinitialize(void) syslog(LOG_INFO, "Start nsh_waiter\n"); - pid = kthread_create("usbhost", CONFIG_USBHOST_DEFPRIO, + ret = kthread_create("usbhost", CONFIG_USBHOST_DEFPRIO, CONFIG_USBHOST_STACKSIZE, (main_t)nsh_waiter, (FAR char * const *)NULL); - return pid < 0 ? -ENOEXEC : OK; + return ret < 0 ? -ENOEXEC : OK; } return -ENODEV; diff --git a/boards/arm/lpc17xx_40xx/lx_cpu/src/lpc17_40_bringup.c b/boards/arm/lpc17xx_40xx/lx_cpu/src/lpc17_40_bringup.c index 50493bd42b4df..c2ac67846ab93 100644 --- a/boards/arm/lpc17xx_40xx/lx_cpu/src/lpc17_40_bringup.c +++ b/boards/arm/lpc17xx_40xx/lx_cpu/src/lpc17_40_bringup.c @@ -294,7 +294,6 @@ static int nsh_sdinitialize(void) #ifdef NSH_HAVE_USBHOST static int nsh_usbhostinitialize(void) { - int pid; int ret; /* First, register all of the class drivers needed to support the drivers @@ -337,10 +336,10 @@ static int nsh_usbhostinitialize(void) syslog(LOG_INFO, "Start nsh_waiter\n"); - pid = kthread_create("usbhost", CONFIG_USBHOST_DEFPRIO, + ret = kthread_create("usbhost", CONFIG_USBHOST_DEFPRIO, CONFIG_USBHOST_STACKSIZE, (main_t)nsh_waiter, (FAR char * const *)NULL); - return pid < 0 ? -ENOEXEC : OK; + return ret < 0 ? -ENOEXEC : OK; } UNUSED(ret); diff --git a/boards/arm/lpc17xx_40xx/mcb1700/src/lpc17_40_bringup.c b/boards/arm/lpc17xx_40xx/mcb1700/src/lpc17_40_bringup.c index fe2944e29d204..01118a26736f2 100644 --- a/boards/arm/lpc17xx_40xx/mcb1700/src/lpc17_40_bringup.c +++ b/boards/arm/lpc17xx_40xx/mcb1700/src/lpc17_40_bringup.c @@ -238,7 +238,6 @@ static int nsh_sdinitialize(void) #ifdef HAVE_USBHOST static int nsh_usbhostinitialize(void) { - int pid; int ret; /* First, register all of the class drivers needed to support the drivers @@ -294,10 +293,10 @@ static int nsh_usbhostinitialize(void) syslog(LOG_ERR, "ERROR: Start nsh_waiter\n"); - pid = kthread_create("usbhost", CONFIG_MCB1700_USBHOST_PRIO, + ret = kthread_create("usbhost", CONFIG_MCB1700_USBHOST_PRIO, CONFIG_MCB1700_USBHOST_STACKSIZE, (main_t)nsh_waiter, (FAR char * const *)NULL); - return pid < 0 ? -ENOEXEC : OK; + return ret < 0 ? -ENOEXEC : OK; } return -ENODEV; diff --git a/boards/arm/lpc17xx_40xx/olimex-lpc1766stk/src/lpc17_40_bringup.c b/boards/arm/lpc17xx_40xx/olimex-lpc1766stk/src/lpc17_40_bringup.c index 378f48088ded8..684e728e64355 100644 --- a/boards/arm/lpc17xx_40xx/olimex-lpc1766stk/src/lpc17_40_bringup.c +++ b/boards/arm/lpc17xx_40xx/olimex-lpc1766stk/src/lpc17_40_bringup.c @@ -237,7 +237,6 @@ static int nsh_sdinitialize(void) #ifdef HAVE_USBHOST static int nsh_usbhostinitialize(void) { - int pid; int ret; /* First, register all of the class drivers needed to support the drivers @@ -313,10 +312,10 @@ static int nsh_usbhostinitialize(void) syslog(LOG_ERR, "ERROR: Start nsh_waiter\n"); - pid = kthread_create("usbhost", CONFIG_LPC1766STK_USBHOST_PRIO, + ret = kthread_create("usbhost", CONFIG_LPC1766STK_USBHOST_PRIO, CONFIG_LPC1766STK_USBHOST_STACKSIZE, (main_t)nsh_waiter, (FAR char * const *)NULL); - return pid < 0 ? -ENOEXEC : OK; + return ret < 0 ? -ENOEXEC : OK; } return -ENODEV; diff --git a/boards/arm/lpc17xx_40xx/open1788/src/lpc17_40_bringup.c b/boards/arm/lpc17xx_40xx/open1788/src/lpc17_40_bringup.c index d48fa9ff57ea8..f770f4ca4ddbc 100644 --- a/boards/arm/lpc17xx_40xx/open1788/src/lpc17_40_bringup.c +++ b/boards/arm/lpc17xx_40xx/open1788/src/lpc17_40_bringup.c @@ -295,7 +295,6 @@ static int nsh_sdinitialize(void) #ifdef NSH_HAVE_USBHOST static int nsh_usbhostinitialize(void) { - int pid; int ret; /* First, register all of the class drivers needed to support the drivers @@ -337,10 +336,10 @@ static int nsh_usbhostinitialize(void) syslog(LOG_INFO, "Start nsh_waiter\n"); - pid = kthread_create("usbhost", CONFIG_USBHOST_DEFPRIO, + ret = kthread_create("usbhost", CONFIG_USBHOST_DEFPRIO, CONFIG_USBHOST_STACKSIZE, (main_t)nsh_waiter, (FAR char * const *)NULL); - return pid < 0 ? -ENOEXEC : OK; + return ret < 0 ? -ENOEXEC : OK; } return -ENODEV; diff --git a/boards/arm/lpc31xx/ea3131/src/lpc31_usbhost.c b/boards/arm/lpc31xx/ea3131/src/lpc31_usbhost.c index 02b72bcf53d06..203f85927e109 100644 --- a/boards/arm/lpc31xx/ea3131/src/lpc31_usbhost.c +++ b/boards/arm/lpc31xx/ea3131/src/lpc31_usbhost.c @@ -159,7 +159,6 @@ void weak_function lpc31_usbhost_bootinitialize(void) int lpc31_usbhost_initialize(void) { - pid_t pid; int ret; /* First, register all of the class drivers needed to support the drivers @@ -218,10 +217,10 @@ int lpc31_usbhost_initialize(void) /* Start a thread to handle device connection. */ - pid = kthread_create("EHCI Monitor", CONFIG_USBHOST_DEFPRIO, + ret = kthread_create("EHCI Monitor", CONFIG_USBHOST_DEFPRIO, CONFIG_USBHOST_STACKSIZE, (main_t)ehci_waiter, (FAR char * const *)NULL); - if (pid < 0) + if (ret < 0) { uerr("ERROR: Failed to create ehci_waiter task: %d\n", ret); return -ENODEV; diff --git a/boards/arm/lpc31xx/olimex-lpc-h3131/src/lpc31_usbhost.c b/boards/arm/lpc31xx/olimex-lpc-h3131/src/lpc31_usbhost.c index 8c9dcc7da01d1..41b399afa508b 100644 --- a/boards/arm/lpc31xx/olimex-lpc-h3131/src/lpc31_usbhost.c +++ b/boards/arm/lpc31xx/olimex-lpc-h3131/src/lpc31_usbhost.c @@ -160,7 +160,6 @@ void weak_function lpc31_usbhost_bootinitialize(void) int lpc31_usbhost_initialize(void) { - pid_t pid; int ret; /* First, register all of the class drivers needed to support the drivers @@ -218,10 +217,10 @@ int lpc31_usbhost_initialize(void) /* Start a thread to handle device connection. */ - pid = kthread_create("EHCI Monitor", CONFIG_USBHOST_DEFPRIO, i + ret = kthread_create("EHCI Monitor", CONFIG_USBHOST_DEFPRIO, i CONFIG_USBHOST_STACKSIZE, (main_t)ehci_waiter, (FAR char * const *)NULL); - if (pid < 0) + if (ret < 0) { uerr("ERROR: Failed to create ehci_waiter task: %d\n", ret); return -ENODEV; diff --git a/boards/arm/sama5/giant-board/src/sam_usb.c b/boards/arm/sama5/giant-board/src/sam_usb.c index 9b4e78f3d566f..c0e8829eb05f6 100644 --- a/boards/arm/sama5/giant-board/src/sam_usb.c +++ b/boards/arm/sama5/giant-board/src/sam_usb.c @@ -230,7 +230,6 @@ void weak_function sam_usbinitialize(void) #ifdef HAVE_USBHOST int sam_usbhost_initialize(void) { - pid_t pid; int ret; /* First, register all of the class drivers needed to support the drivers @@ -291,11 +290,11 @@ int sam_usbhost_initialize(void) /* Start a thread to handle device connection. */ - pid = kthread_create("OHCI Monitor", + ret = kthread_create("OHCI Monitor", CONFIG_SAMA5D27_GIANT_BOARD_USBHOST_PRIO, CONFIG_SAMA5D27_GIANT_BOARD_USBHOST_STACKSIZE, (main_t)ohci_waiter, (FAR char * const *)NULL); - if (pid < 0) + if (ret < 0) { uerr("ERROR: Failed to create ohci_waiter task: %d\n", ret); return -ENODEV; @@ -314,11 +313,11 @@ int sam_usbhost_initialize(void) /* Start a thread to handle device connection. */ - pid = kthread_create("EHCI Monitor", + ret = kthread_create("EHCI Monitor", CONFIG_SAMA5D27_GIANT_BOARD_USBHOST_PRIO, CONFIG_SAMA5D27_GIANT_BOARD_USBHOST_STACKSIZE, (main_t)ehci_waiter, (FAR char * const *)NULL); - if (pid < 0) + if (ret < 0) { uerr("ERROR: Failed to create ehci_waiter task: %d\n", ret); return -ENODEV; diff --git a/boards/arm/sama5/sama5d2-xult/src/sam_usb.c b/boards/arm/sama5/sama5d2-xult/src/sam_usb.c index de7cfc0a786d7..5ed9194368eb1 100644 --- a/boards/arm/sama5/sama5d2-xult/src/sam_usb.c +++ b/boards/arm/sama5/sama5d2-xult/src/sam_usb.c @@ -278,7 +278,6 @@ void weak_function sam_usbinitialize(void) #ifdef HAVE_USBHOST int sam_usbhost_initialize(void) { - pid_t pid; int ret; /* First, register all of the class drivers needed to support the drivers @@ -339,10 +338,10 @@ int sam_usbhost_initialize(void) /* Start a thread to handle device connection. */ - pid = kthread_create("OHCI Monitor", CONFIG_SAMA5D2XULT_USBHOST_PRIO, + ret = kthread_create("OHCI Monitor", CONFIG_SAMA5D2XULT_USBHOST_PRIO, CONFIG_SAMA5D2XULT_USBHOST_STACKSIZE, (main_t)ohci_waiter, (FAR char * const *)NULL); - if (pid < 0) + if (ret < 0) { uerr("ERROR: Failed to create ohci_waiter task: %d\n", ret); return -ENODEV; @@ -361,10 +360,10 @@ int sam_usbhost_initialize(void) /* Start a thread to handle device connection. */ - pid = kthread_create("EHCI Monitor", CONFIG_SAMA5D2XULT_USBHOST_PRIO, + ret = kthread_create("EHCI Monitor", CONFIG_SAMA5D2XULT_USBHOST_PRIO, CONFIG_SAMA5D2XULT_USBHOST_STACKSIZE, (main_t)ehci_waiter, (FAR char * const *)NULL); - if (pid < 0) + if (ret < 0) { uerr("ERROR: Failed to create ehci_waiter task: %d\n", ret); return -ENODEV; diff --git a/boards/arm/sama5/sama5d3-xplained/src/sam_usb.c b/boards/arm/sama5/sama5d3-xplained/src/sam_usb.c index 473d9c5ba3acd..d973bfbaa5789 100644 --- a/boards/arm/sama5/sama5d3-xplained/src/sam_usb.c +++ b/boards/arm/sama5/sama5d3-xplained/src/sam_usb.c @@ -286,7 +286,6 @@ void weak_function sam_usbinitialize(void) #ifdef HAVE_USBHOST int sam_usbhost_initialize(void) { - pid_t pid; int ret; /* First, register all of the class drivers needed to support the drivers @@ -347,10 +346,10 @@ int sam_usbhost_initialize(void) /* Start a thread to handle device connection. */ - pid = kthread_create("OHCI Monitor", CONFIG_SAMA5D3XPLAINED_USBHOST_PRIO, + ret = kthread_create("OHCI Monitor", CONFIG_SAMA5D3XPLAINED_USBHOST_PRIO, CONFIG_SAMA5D3XPLAINED_USBHOST_STACKSIZE, (main_t)ohci_waiter, (FAR char * const *)NULL); - if (pid < 0) + if (ret < 0) { uerr("ERROR: Failed to create ohci_waiter task: %d\n", ret); return -ENODEV; @@ -369,10 +368,10 @@ int sam_usbhost_initialize(void) /* Start a thread to handle device connection. */ - pid = kthread_create("EHCI Monitor", CONFIG_SAMA5D3XPLAINED_USBHOST_PRIO, + ret = kthread_create("EHCI Monitor", CONFIG_SAMA5D3XPLAINED_USBHOST_PRIO, CONFIG_SAMA5D3XPLAINED_USBHOST_STACKSIZE, (main_t)ehci_waiter, (FAR char * const *)NULL); - if (pid < 0) + if (ret < 0) { uerr("ERROR: Failed to create ehci_waiter task: %d\n", ret); return -ENODEV; diff --git a/boards/arm/sama5/sama5d3x-ek/src/sam_usb.c b/boards/arm/sama5/sama5d3x-ek/src/sam_usb.c index 8532e18a3adc0..6582853e6d42d 100644 --- a/boards/arm/sama5/sama5d3x-ek/src/sam_usb.c +++ b/boards/arm/sama5/sama5d3x-ek/src/sam_usb.c @@ -284,7 +284,6 @@ void weak_function sam_usbinitialize(void) #ifdef HAVE_USBHOST int sam_usbhost_initialize(void) { - pid_t pid; int ret; /* First, register all of the class drivers needed to support the drivers @@ -345,11 +344,11 @@ int sam_usbhost_initialize(void) /* Start a thread to handle device connection. */ - pid = kthread_create("OHCI Monitor", + ret = kthread_create("OHCI Monitor", CONFIG_SAMA5D3XEK_USBHOST_PRIO, CONFIG_SAMA5D3XEK_USBHOST_STACKSIZE, (main_t)ohci_waiter, (FAR char * const *)NULL); - if (pid < 0) + if (ret < 0) { uerr("ERROR: Failed to create ohci_waiter task: %d\n", ret); return -ENODEV; @@ -368,10 +367,10 @@ int sam_usbhost_initialize(void) /* Start a thread to handle device connection. */ - pid = kthread_create("EHCI Monitor", CONFIG_SAMA5D3XEK_USBHOST_PRIO, + ret = kthread_create("EHCI Monitor", CONFIG_SAMA5D3XEK_USBHOST_PRIO, CONFIG_SAMA5D3XEK_USBHOST_STACKSIZE, (main_t)ehci_waiter, (FAR char * const *)NULL); - if (pid < 0) + if (ret < 0) { uerr("ERROR: Failed to create ehci_waiter task: %d\n", ret); return -ENODEV; diff --git a/boards/arm/sama5/sama5d4-ek/src/sam_usb.c b/boards/arm/sama5/sama5d4-ek/src/sam_usb.c index f884e29c9a132..ae8606c448818 100644 --- a/boards/arm/sama5/sama5d4-ek/src/sam_usb.c +++ b/boards/arm/sama5/sama5d4-ek/src/sam_usb.c @@ -284,7 +284,6 @@ void weak_function sam_usbinitialize(void) #ifdef HAVE_USBHOST int sam_usbhost_initialize(void) { - pid_t pid; int ret; /* First, register all of the class drivers needed to support the drivers @@ -345,10 +344,10 @@ int sam_usbhost_initialize(void) /* Start a thread to handle device connection. */ - pid = kthread_create("OHCI Monitor", CONFIG_SAMA5D4EK_USBHOST_PRIO, + ret = kthread_create("OHCI Monitor", CONFIG_SAMA5D4EK_USBHOST_PRIO, CONFIG_SAMA5D4EK_USBHOST_STACKSIZE, (main_t)ohci_waiter, (FAR char * const *)NULL); - if (pid < 0) + if (ret < 0) { uerr("ERROR: Failed to create ohci_waiter task: %d\n", ret); return -ENODEV; @@ -367,10 +366,10 @@ int sam_usbhost_initialize(void) /* Start a thread to handle device connection. */ - pid = kthread_create("EHCI Monitor", CONFIG_SAMA5D4EK_USBHOST_PRIO, + ret = kthread_create("EHCI Monitor", CONFIG_SAMA5D4EK_USBHOST_PRIO, CONFIG_SAMA5D4EK_USBHOST_STACKSIZE, (main_t)ehci_waiter, (FAR char * const *)NULL); - if (pid < 0) + if (ret < 0) { uerr("ERROR: Failed to create ehci_waiter task: %d\n", ret); return -ENODEV; diff --git a/boards/arm/samd5e5/metro-m4/src/sam_usbhost.c b/boards/arm/samd5e5/metro-m4/src/sam_usbhost.c index be2ee12140954..f9da729c0827f 100644 --- a/boards/arm/samd5e5/metro-m4/src/sam_usbhost.c +++ b/boards/arm/samd5e5/metro-m4/src/sam_usbhost.c @@ -171,7 +171,6 @@ void sam_usbhost_vbusdrive(int iface, bool enable) #ifdef CONFIG_USBHOST int samd_usbhost_initialize(void) { - int pid; int ret; /* First, register all of the class drivers needed to support the drivers @@ -219,11 +218,10 @@ int samd_usbhost_initialize(void) /* Start a thread to handle device connection. */ uinfo("Start usbhost_waiter\n"); - pid = - kthread_create("usbhost", CONFIG_METRO_M4_USBHOST_PRIO, - CONFIG_METRO_M4_USBHOST_STACKSIZE, - (main_t) usbhost_waiter, (FAR char *const *)NULL); - return pid < 0 ? -ENOEXEC : OK; + ret = kthread_create("usbhost", CONFIG_METRO_M4_USBHOST_PRIO, + CONFIG_METRO_M4_USBHOST_STACKSIZE, + (main_t)usbhost_waiter, (FAR char *const *)NULL); + return ret < 0 ? -ENOEXEC : OK; } return -ENODEV; diff --git a/boards/arm/samv7/common/Kconfig b/boards/arm/samv7/common/Kconfig index a0c7bb963b5b3..8fa68fc64ca8f 100644 --- a/boards/arm/samv7/common/Kconfig +++ b/boards/arm/samv7/common/Kconfig @@ -62,9 +62,7 @@ config SAMV7_PROGMEM_OTA_PARTITION select MTD_BYTE_WRITE select MTD_PARTITION select MTD_PROGMEM - select MTD_PROGMEM_ERASESTATE select SAMV7_PROGMEM - select SAMV7_PROGMEM_ERASESTATE config SAMV7_MCUBOOT_HEADER_SIZE hex diff --git a/boards/arm/stm32/axoloti/src/stm32_boot.c b/boards/arm/stm32/axoloti/src/stm32_boot.c index 917973884a88a..bfb8384ea30e0 100644 --- a/boards/arm/stm32/axoloti/src/stm32_boot.c +++ b/boards/arm/stm32/axoloti/src/stm32_boot.c @@ -54,16 +54,7 @@ void stm32_boardinitialize(void) { #ifdef CONFIG_SCHED_CRITMONITOR - /* Enable ITM and DWT resources, if not left enabled by debugger. */ - - modifyreg32(NVIC_DEMCR, 0, NVIC_DEMCR_TRCENA); - - /* Make sure the high speed cycle counter is running. It will be started - * automatically only if a debugger is connected. - */ - - putreg32(0xc5acce55, ITM_LAR); - modifyreg32(DWT_CTRL, 0, DWT_CTRL_CYCCNTENA_MASK); + up_perf_init((FAR void *)STM32_SYSCLK_FREQUENCY); #endif #if defined(CONFIG_STM32_SPI1) || defined(CONFIG_STM32_SPI2) || \ diff --git a/boards/arm/stm32/axoloti/src/stm32_usbhost.c b/boards/arm/stm32/axoloti/src/stm32_usbhost.c index 33d54221445e8..3249dda9ec0e7 100644 --- a/boards/arm/stm32/axoloti/src/stm32_usbhost.c +++ b/boards/arm/stm32/axoloti/src/stm32_usbhost.c @@ -203,7 +203,6 @@ int stm32_setup_overcurrent(xcpt_t handler, void *arg) #ifdef CONFIG_USBHOST int stm32_usbhost_initialize(void) { - int pid; int ret; /* First, register all of the class drivers needed to support the drivers @@ -251,11 +250,10 @@ int stm32_usbhost_initialize(void) /* Start a thread to handle device connection. */ uinfo("Start usbhost_waiter\n"); - pid = - kthread_create("usbhost", CONFIG_AXOLOTI_USBHOST_PRIO, - CONFIG_AXOLOTI_USBHOST_STACKSIZE, - (main_t) usbhost_waiter, (FAR char *const *)NULL); - return pid < 0 ? -ENOEXEC : OK; + ret = kthread_create("usbhost", CONFIG_AXOLOTI_USBHOST_PRIO, + CONFIG_AXOLOTI_USBHOST_STACKSIZE, + (main_t)usbhost_waiter, (FAR char *const *)NULL); + return ret < 0 ? -ENOEXEC : OK; } return -ENODEV; diff --git a/boards/arm/stm32/cloudctrl/src/stm32_usb.c b/boards/arm/stm32/cloudctrl/src/stm32_usb.c index d278e3e87adad..e4fc3f3d4174a 100644 --- a/boards/arm/stm32/cloudctrl/src/stm32_usb.c +++ b/boards/arm/stm32/cloudctrl/src/stm32_usb.c @@ -160,7 +160,6 @@ void stm32_usbinitialize(void) #ifdef CONFIG_USBHOST int stm32_usbhost_initialize(void) { - int pid; int ret; /* First, register all of the class drivers needed to support the drivers @@ -199,10 +198,10 @@ int stm32_usbhost_initialize(void) uinfo("Start usbhost_waiter\n"); - pid = kthread_create("usbhost", CONFIG_USBHOST_DEFPRIO, + ret = kthread_create("usbhost", CONFIG_USBHOST_DEFPRIO, CONFIG_USBHOST_STACKSIZE, (main_t)usbhost_waiter, (FAR char * const *)NULL); - return pid < 0 ? -ENOEXEC : OK; + return ret < 0 ? -ENOEXEC : OK; } return -ENODEV; diff --git a/boards/arm/stm32/mikroe-stm32f4/src/stm32_usb.c b/boards/arm/stm32/mikroe-stm32f4/src/stm32_usb.c index 95b9108e1cb49..3271d962b436e 100644 --- a/boards/arm/stm32/mikroe-stm32f4/src/stm32_usb.c +++ b/boards/arm/stm32/mikroe-stm32f4/src/stm32_usb.c @@ -160,7 +160,6 @@ void stm32_usbinitialize(void) #ifdef CONFIG_USBHOST int stm32_usbhost_initialize(void) { - int pid; int ret; /* First, register all of the class drivers needed to support the drivers @@ -199,10 +198,10 @@ int stm32_usbhost_initialize(void) uinfo("Start usbhost_waiter\n"); - pid = kthread_create("usbhost", CONFIG_USBHOST_DEFPRIO, + ret = kthread_create("usbhost", CONFIG_USBHOST_DEFPRIO, CONFIG_USBHOST_STACKSIZE, (main_t)usbhost_waiter, (FAR char * const *)NULL); - return pid < 0 ? -ENOEXEC : OK; + return ret < 0 ? -ENOEXEC : OK; } return -ENODEV; diff --git a/boards/arm/stm32/nucleo-f207zg/src/stm32_usb.c b/boards/arm/stm32/nucleo-f207zg/src/stm32_usb.c index 2659b04c70e15..1c431d79bd35e 100644 --- a/boards/arm/stm32/nucleo-f207zg/src/stm32_usb.c +++ b/boards/arm/stm32/nucleo-f207zg/src/stm32_usb.c @@ -157,11 +157,7 @@ void stm32_usbinitialize(void) #ifdef CONFIG_USBHOST int stm32_usbhost_initialize(void) { - int pid; -#if defined(CONFIG_USBHOST_HUB) || defined(CONFIG_USBHOST_MSC) || \ - defined(CONFIG_USBHOST_HIDKBD) || defined(CONFIG_USBHOST_HIDMOUSE) int ret; -#endif /* First, register all of the class drivers needed to support the drivers * that we care about: @@ -229,10 +225,10 @@ int stm32_usbhost_initialize(void) uinfo("Start usbhost_waiter\n"); - pid = kthread_create("usbhost", CONFIG_NUCLEOF207ZG_USBHOST_PRIO, + ret = kthread_create("usbhost", CONFIG_NUCLEOF207ZG_USBHOST_PRIO, CONFIG_NUCLEOF207ZG_USBHOST_STACKSIZE, (main_t)usbhost_waiter, (FAR char * const *)NULL); - return pid < 0 ? -ENOEXEC : OK; + return ret < 0 ? -ENOEXEC : OK; } return -ENODEV; diff --git a/boards/arm/stm32/nucleo-f303re/src/stm32_uid.c b/boards/arm/stm32/nucleo-f303re/src/stm32_uid.c index e7a1894f7ab39..027a39c76e16e 100644 --- a/boards/arm/stm32/nucleo-f303re/src/stm32_uid.c +++ b/boards/arm/stm32/nucleo-f303re/src/stm32_uid.c @@ -59,7 +59,7 @@ #if defined(CONFIG_BOARDCTL_UNIQUEID) int board_uniqueid(uint8_t *uniqueid) { - if (uniqueid == 0) + if (uniqueid == NULL) { return -EINVAL; } diff --git a/boards/arm/stm32/nucleo-f412zg/src/stm32_usb.c b/boards/arm/stm32/nucleo-f412zg/src/stm32_usb.c index cfb85f8d85036..46c056c2b0e10 100644 --- a/boards/arm/stm32/nucleo-f412zg/src/stm32_usb.c +++ b/boards/arm/stm32/nucleo-f412zg/src/stm32_usb.c @@ -170,12 +170,7 @@ void stm32_usbinitialize(void) #ifdef CONFIG_USBHOST int stm32_usbhost_initialize(void) { - int pid; -#if defined(CONFIG_USBHOST_HUB) || defined(CONFIG_USBHOST_MSC) || \ - defined(CONFIG_USBHOST_HIDKBD) || defined(CONFIG_USBHOST_HIDMOUSE) || \ - defined(CONFIG_USBHOST_XBOXCONTROLLER) int ret; -#endif /* First, register all of the class drivers needed to support the drivers * that we care about: @@ -253,10 +248,10 @@ int stm32_usbhost_initialize(void) uinfo("Start usbhost_waiter\n"); - pid = kthread_create("usbhost", CONFIG_STM32F411DISCO_USBHOST_PRIO, + ret = kthread_create("usbhost", CONFIG_STM32F411DISCO_USBHOST_PRIO, CONFIG_STM32F411DISCO_USBHOST_STACKSIZE, (main_t)usbhost_waiter, (FAR char * const *)NULL); - return pid < 0 ? -ENOEXEC : OK; + return ret < 0 ? -ENOEXEC : OK; } return -ENODEV; diff --git a/boards/arm/stm32/nucleo-f429zi/src/stm32_bbsram.c b/boards/arm/stm32/nucleo-f429zi/src/stm32_bbsram.c index 505361716b966..15c52e6406cc7 100644 --- a/boards/arm/stm32/nucleo-f429zi/src/stm32_bbsram.c +++ b/boards/arm/stm32/nucleo-f429zi/src/stm32_bbsram.c @@ -235,7 +235,7 @@ typedef struct fault_flags_t flags; /* What is in the dump */ uintptr_t current_regs; /* Used to validate the dump */ int lineno; /* __LINE__ to up_assert */ - int pid; /* Process ID */ + pid_t pid; /* Process ID */ uint32_t regs[XCPTCONTEXT_REGS]; /* Interrupt register save area */ stack_t stacks; /* Stack info */ #if CONFIG_TASK_NAME_SIZE > 0 diff --git a/boards/arm/stm32/nucleo-f429zi/src/stm32_usb.c b/boards/arm/stm32/nucleo-f429zi/src/stm32_usb.c index b41addd049c6f..4de6fb2ce6943 100644 --- a/boards/arm/stm32/nucleo-f429zi/src/stm32_usb.c +++ b/boards/arm/stm32/nucleo-f429zi/src/stm32_usb.c @@ -156,11 +156,7 @@ void stm32_usbinitialize(void) #ifdef CONFIG_USBHOST int stm32_usbhost_initialize(void) { - int pid; -#if defined(CONFIG_USBHOST_HUB) || defined(CONFIG_USBHOST_MSC) || \ - defined(CONFIG_USBHOST_HIDKBD) || defined(CONFIG_USBHOST_HIDMOUSE) int ret; -#endif /* First, register all of the class drivers needed to support the drivers * that we care about: @@ -228,10 +224,10 @@ int stm32_usbhost_initialize(void) uinfo("Start usbhost_waiter\n"); - pid = kthread_create("usbhost", CONFIG_STM32F4DISCO_USBHOST_PRIO, + ret = kthread_create("usbhost", CONFIG_STM32F4DISCO_USBHOST_PRIO, CONFIG_STM32F4DISCO_USBHOST_STACKSIZE, (main_t)usbhost_waiter, (FAR char * const *)NULL); - return pid < 0 ? -ENOEXEC : OK; + return ret < 0 ? -ENOEXEC : OK; } return -ENODEV; diff --git a/boards/arm/stm32/olimex-stm32-e407/src/stm32_usb.c b/boards/arm/stm32/olimex-stm32-e407/src/stm32_usb.c index 8cbe4fdfd1a7f..0971e0113be2d 100644 --- a/boards/arm/stm32/olimex-stm32-e407/src/stm32_usb.c +++ b/boards/arm/stm32/olimex-stm32-e407/src/stm32_usb.c @@ -155,11 +155,7 @@ void stm32_usbinitialize(void) #ifdef CONFIG_USBHOST int stm32_usbhost_initialize(void) { - int pid; -#if defined(CONFIG_USBHOST_HUB) || defined(CONFIG_USBHOST_MSC) || \ - defined(CONFIG_USBHOST_HIDKBD) || defined(CONFIG_USBHOST_HIDMOUSE) int ret; -#endif /* First, register all of the class drivers needed to support the drivers * that we care about: @@ -227,10 +223,10 @@ int stm32_usbhost_initialize(void) uinfo("Start usbhost_waiter\n"); - pid = kthread_create("usbhost", CONFIG_STM32F4DISCO_USBHOST_PRIO, + ret = kthread_create("usbhost", CONFIG_STM32F4DISCO_USBHOST_PRIO, CONFIG_STM32F4DISCO_USBHOST_STACKSIZE, (main_t)usbhost_waiter, (FAR char * const *)NULL); - return pid < 0 ? -ENOEXEC : OK; + return ret < 0 ? -ENOEXEC : OK; } return -ENODEV; diff --git a/boards/arm/stm32/olimex-stm32-h407/src/stm32_usb.c b/boards/arm/stm32/olimex-stm32-h407/src/stm32_usb.c index 3bdf60caaa15e..d0c459fdb81ed 100644 --- a/boards/arm/stm32/olimex-stm32-h407/src/stm32_usb.c +++ b/boards/arm/stm32/olimex-stm32-h407/src/stm32_usb.c @@ -157,7 +157,6 @@ void stm32_usbinitialize(void) #ifdef CONFIG_USBHOST int stm32_usbhost_initialize(void) { - int pid; int ret; /* First, register all of the class drivers needed to support the drivers @@ -206,10 +205,10 @@ int stm32_usbhost_initialize(void) uinfo("Start usbhost_waiter\n"); - pid = kthread_create("usbhost", CONFIG_STM32H407_USBHOST_PRIO, + ret = kthread_create("usbhost", CONFIG_STM32H407_USBHOST_PRIO, CONFIG_STM32H407_USBHOST_STACKSIZE, (main_t)usbhost_waiter, (FAR char * const *)NULL); - return pid < 0 ? -ENOEXEC : OK; + return ret < 0 ? -ENOEXEC : OK; } return -ENODEV; diff --git a/boards/arm/stm32/olimex-stm32-p207/src/stm32_usb.c b/boards/arm/stm32/olimex-stm32-p207/src/stm32_usb.c index 16ab6497cdfe2..f646adecbc05e 100644 --- a/boards/arm/stm32/olimex-stm32-p207/src/stm32_usb.c +++ b/boards/arm/stm32/olimex-stm32-p207/src/stm32_usb.c @@ -159,10 +159,7 @@ void stm32_usbinitialize(void) #ifdef CONFIG_STM32_USBHOST int stm32_usbhost_initialize(void) { - int pid; -#if defined(CONFIG_USBHOST_HUB) || defined(CONFIG_USBHOST_MSC) || defined(CONFIG_USBHOST_CDCACM) int ret; -#endif /* First, register all of the class drivers needed to support the drivers * that we care about: @@ -210,10 +207,10 @@ int stm32_usbhost_initialize(void) uinfo("Start usbhost_waiter\n"); - pid = kthread_create("usbhost", CONFIG_USBHOST_DEFPRIO, + ret = kthread_create("usbhost", CONFIG_USBHOST_DEFPRIO, CONFIG_USBHOST_STACKSIZE, (main_t)usbhost_waiter, (FAR char * const *)NULL); - return pid < 0 ? -ENOEXEC : OK; + return ret < 0 ? -ENOEXEC : OK; } return -ENODEV; diff --git a/boards/arm/stm32/olimex-stm32-p407/src/stm32_usb.c b/boards/arm/stm32/olimex-stm32-p407/src/stm32_usb.c index 645e818dcba93..88c208715a49c 100644 --- a/boards/arm/stm32/olimex-stm32-p407/src/stm32_usb.c +++ b/boards/arm/stm32/olimex-stm32-p407/src/stm32_usb.c @@ -156,7 +156,6 @@ void stm32_usb_configure(void) #ifdef CONFIG_USBHOST int stm32_usbhost_setup(void) { - int pid; int ret; /* First, register all of the class drivers needed to support the drivers @@ -215,8 +214,6 @@ int stm32_usbhost_setup(void) } #endif - UNUSED(ret); - /* Then get an instance of the USB host interface */ uinfo("Initialize USB host\n"); @@ -227,10 +224,10 @@ int stm32_usbhost_setup(void) uinfo("Start usbhost_waiter\n"); - pid = kthread_create("usbhost", CONFIG_OLIMEXP407_USBHOST_PRIO, + ret = kthread_create("usbhost", CONFIG_OLIMEXP407_USBHOST_PRIO, CONFIG_OLIMEXP407_USBHOST_STACKSIZE, (main_t)usbhost_waiter, (FAR char * const *)NULL); - return pid < 0 ? -ENOEXEC : OK; + return ret < 0 ? -ENOEXEC : OK; } return -ENODEV; diff --git a/boards/arm/stm32/omnibusf4/src/Make.defs b/boards/arm/stm32/omnibusf4/src/Make.defs index f59c3494b55c5..3e7e821550bfc 100644 --- a/boards/arm/stm32/omnibusf4/src/Make.defs +++ b/boards/arm/stm32/omnibusf4/src/Make.defs @@ -20,7 +20,7 @@ include $(TOPDIR)/Make.defs -CSRCS = stm32_boot.c stm32_bringup.c stm32_spi.c stm32_userleds.c stm32_perfcount.c +CSRCS = stm32_boot.c stm32_bringup.c stm32_spi.c stm32_userleds.c ifeq ($(CONFIG_SENSORS_MPU60X0),y) CSRCS += stm32_mpu6000.c diff --git a/boards/arm/stm32/omnibusf4/src/stm32_boot.c b/boards/arm/stm32/omnibusf4/src/stm32_boot.c index 57f787a1c41bb..b5b203d5c6fc6 100644 --- a/boards/arm/stm32/omnibusf4/src/stm32_boot.c +++ b/boards/arm/stm32/omnibusf4/src/stm32_boot.c @@ -54,16 +54,7 @@ void stm32_boardinitialize(void) { #ifdef CONFIG_SCHED_CRITMONITOR - /* Enable ITM and DWT resources, if not left enabled by debugger. */ - - modifyreg32(NVIC_DEMCR, 0, NVIC_DEMCR_TRCENA); - - /* Make sure the high speed cycle counter is running. It will be started - * automatically only if a debugger is connected. - */ - - putreg32(0xc5acce55, ITM_LAR); - modifyreg32(DWT_CTRL, 0, DWT_CTRL_CYCCNTENA_MASK); + up_perf_init((FAR void *)STM32_SYSCLK_FREQUENCY); #endif #if defined(CONFIG_STM32_SPI1) || defined(CONFIG_STM32_SPI2) || defined(CONFIG_STM32_SPI3) diff --git a/boards/arm/stm32/omnibusf4/src/stm32_uid.c b/boards/arm/stm32/omnibusf4/src/stm32_uid.c index 35a639c8b61de..810cd7ed5033c 100644 --- a/boards/arm/stm32/omnibusf4/src/stm32_uid.c +++ b/boards/arm/stm32/omnibusf4/src/stm32_uid.c @@ -59,7 +59,7 @@ #if defined(CONFIG_BOARDCTL_UNIQUEID) int board_uniqueid(uint8_t *uniqueid) { - if (uniqueid == 0) + if (uniqueid == NULL) { return -EINVAL; } diff --git a/boards/arm/stm32/omnibusf4/src/stm32_usb.c b/boards/arm/stm32/omnibusf4/src/stm32_usb.c index 79fa7d566c76f..2a1febf1985d2 100644 --- a/boards/arm/stm32/omnibusf4/src/stm32_usb.c +++ b/boards/arm/stm32/omnibusf4/src/stm32_usb.c @@ -154,12 +154,7 @@ void stm32_usbinitialize(void) #ifdef CONFIG_USBHOST int stm32_usbhost_initialize(void) { - int pid; -#if defined(CONFIG_USBHOST_HUB) || defined(CONFIG_USBHOST_MSC) || \ - defined(CONFIG_USBHOST_HIDKBD) || defined(CONFIG_USBHOST_HIDMOUSE) || \ - defined(CONFIG_USBHOST_XBOXCONTROLLER) int ret; -#endif /* First, register all of the class drivers needed to support the drivers * that we care about: @@ -237,10 +232,10 @@ int stm32_usbhost_initialize(void) uinfo("Start usbhost_waiter\n"); - pid = kthread_create("usbhost", CONFIG_OMNIBUSF4_USBHOST_PRIO, - CONFIG_OMNIBUSF4_USBHOST_STACKSIZE, - (main_t)usbhost_waiter, (FAR char * const *)NULL); - return pid < 0 ? -ENOEXEC : OK; + ret = kthread_create("usbhost", CONFIG_OMNIBUSF4_USBHOST_PRIO, + CONFIG_OMNIBUSF4_USBHOST_STACKSIZE, + (main_t)usbhost_waiter, (FAR char * const *)NULL); + return ret < 0 ? -ENOEXEC : OK; } return -ENODEV; diff --git a/boards/arm/stm32/shenzhou/src/stm32_usb.c b/boards/arm/stm32/shenzhou/src/stm32_usb.c index 92e97da87fb25..2f73fe24fc525 100644 --- a/boards/arm/stm32/shenzhou/src/stm32_usb.c +++ b/boards/arm/stm32/shenzhou/src/stm32_usb.c @@ -160,7 +160,6 @@ void stm32_usbinitialize(void) #ifdef CONFIG_USBHOST int stm32_usbhost_initialize(void) { - int pid; int ret; /* First, register all of the class drivers needed to support the drivers @@ -199,10 +198,10 @@ int stm32_usbhost_initialize(void) uinfo("Start usbhost_waiter\n"); - pid = kthread_create("usbhost", CONFIG_USBHOST_DEFPRIO, + ret = kthread_create("usbhost", CONFIG_USBHOST_DEFPRIO, CONFIG_USBHOST_STACKSIZE, (main_t)usbhost_waiter, (FAR char * const *)NULL); - return pid < 0 ? -ENOEXEC : OK; + return ret < 0 ? -ENOEXEC : OK; } return -ENODEV; diff --git a/boards/arm/stm32/stm3220g-eval/src/stm32_usb.c b/boards/arm/stm32/stm3220g-eval/src/stm32_usb.c index 660d94ea20518..a6e88886e5499 100644 --- a/boards/arm/stm32/stm3220g-eval/src/stm32_usb.c +++ b/boards/arm/stm32/stm3220g-eval/src/stm32_usb.c @@ -160,7 +160,6 @@ void stm32_usbinitialize(void) #ifdef CONFIG_USBHOST int stm32_usbhost_initialize(void) { - int pid; int ret; /* First, register all of the class drivers needed to support the drivers @@ -199,10 +198,10 @@ int stm32_usbhost_initialize(void) uinfo("Start usbhost_waiter\n"); - pid = kthread_create("usbhost", CONFIG_USBHOST_DEFPRIO, + ret = kthread_create("usbhost", CONFIG_USBHOST_DEFPRIO, CONFIG_USBHOST_STACKSIZE, (main_t)usbhost_waiter, (FAR char * const *)NULL); - return pid < 0 ? -ENOEXEC : OK; + return ret < 0 ? -ENOEXEC : OK; } return -ENODEV; diff --git a/boards/arm/stm32/stm3240g-eval/src/stm32_usb.c b/boards/arm/stm32/stm3240g-eval/src/stm32_usb.c index 7116d1bc42687..7676255073f81 100644 --- a/boards/arm/stm32/stm3240g-eval/src/stm32_usb.c +++ b/boards/arm/stm32/stm3240g-eval/src/stm32_usb.c @@ -160,7 +160,6 @@ void stm32_usbinitialize(void) #ifdef CONFIG_USBHOST int stm32_usbhost_initialize(void) { - int pid; int ret; /* First, register all of the class drivers needed to support the drivers @@ -199,10 +198,10 @@ int stm32_usbhost_initialize(void) uinfo("Start usbhost_waiter\n"); - pid = kthread_create("usbhost", CONFIG_USBHOST_DEFPRIO, - CONFIG_USBHOST_STACKSIZE, - (main_t)usbhost_waiter, (FAR char * const *)NULL); - return pid < 0 ? -ENOEXEC : OK; + ret = kthread_create("usbhost", CONFIG_USBHOST_DEFPRIO, + CONFIG_USBHOST_STACKSIZE, + (main_t)usbhost_waiter, (FAR char * const *)NULL); + return ret < 0 ? -ENOEXEC : OK; } return -ENODEV; diff --git a/boards/arm/stm32/stm32f411-minimum/src/stm32_usb.c b/boards/arm/stm32/stm32f411-minimum/src/stm32_usb.c index 3d750b278965e..0de05c34f8135 100644 --- a/boards/arm/stm32/stm32f411-minimum/src/stm32_usb.c +++ b/boards/arm/stm32/stm32f411-minimum/src/stm32_usb.c @@ -152,12 +152,7 @@ void stm32_usbinitialize(void) #ifdef CONFIG_USBHOST int stm32_usbhost_initialize(void) { - int pid; -#if defined(CONFIG_USBHOST_HUB) || defined(CONFIG_USBHOST_MSC) || \ - defined(CONFIG_USBHOST_HIDKBD) || defined(CONFIG_USBHOST_HIDMOUSE) || \ - defined(CONFIG_USBHOST_XBOXCONTROLLER) int ret; -#endif /* First, register all of the class drivers needed to support the drivers * that we care about: @@ -235,10 +230,10 @@ int stm32_usbhost_initialize(void) uinfo("Start usbhost_waiter\n"); - pid = kthread_create("usbhost", CONFIG_STM32F411MINIMUM_USBHOST_PRIO, + ret = kthread_create("usbhost", CONFIG_STM32F411MINIMUM_USBHOST_PRIO, CONFIG_STM32F411MINIMUM_USBHOST_STACKSIZE, (main_t)usbhost_waiter, (FAR char * const *)NULL); - return pid < 0 ? -ENOEXEC : OK; + return ret < 0 ? -ENOEXEC : OK; } return -ENODEV; diff --git a/boards/arm/stm32/stm32f411e-disco/src/stm32_usb.c b/boards/arm/stm32/stm32f411e-disco/src/stm32_usb.c index cd65546cd8a2e..be38985a240d0 100644 --- a/boards/arm/stm32/stm32f411e-disco/src/stm32_usb.c +++ b/boards/arm/stm32/stm32f411e-disco/src/stm32_usb.c @@ -171,12 +171,7 @@ void stm32_usbinitialize(void) #ifdef CONFIG_USBHOST int stm32_usbhost_initialize(void) { - int pid; -#if defined(CONFIG_USBHOST_HUB) || defined(CONFIG_USBHOST_MSC) || \ - defined(CONFIG_USBHOST_HIDKBD) || defined(CONFIG_USBHOST_HIDMOUSE) || \ - defined(CONFIG_USBHOST_XBOXCONTROLLER) int ret; -#endif /* First, register all of the class drivers needed to support the drivers * that we care about: @@ -254,10 +249,10 @@ int stm32_usbhost_initialize(void) uinfo("Start usbhost_waiter\n"); - pid = kthread_create("usbhost", CONFIG_STM32F411DISCO_USBHOST_PRIO, + ret = kthread_create("usbhost", CONFIG_STM32F411DISCO_USBHOST_PRIO, CONFIG_STM32F411DISCO_USBHOST_STACKSIZE, (main_t)usbhost_waiter, (FAR char * const *)NULL); - return pid < 0 ? -ENOEXEC : OK; + return ret < 0 ? -ENOEXEC : OK; } return -ENODEV; diff --git a/boards/arm/stm32/stm32f429i-disco/src/stm32_usb.c b/boards/arm/stm32/stm32f429i-disco/src/stm32_usb.c index 704907d24f405..74a998b2a2f39 100644 --- a/boards/arm/stm32/stm32f429i-disco/src/stm32_usb.c +++ b/boards/arm/stm32/stm32f429i-disco/src/stm32_usb.c @@ -156,7 +156,6 @@ void stm32_usbinitialize(void) #ifdef CONFIG_USBHOST int stm32_usbhost_initialize(void) { - int pid; int ret; /* First, register all of the class drivers needed to support the drivers @@ -205,10 +204,10 @@ int stm32_usbhost_initialize(void) uinfo("Start usbhost_waiter\n"); - pid = kthread_create("usbhost", CONFIG_STM32F429IDISCO_USBHOST_PRIO, + ret = kthread_create("usbhost", CONFIG_STM32F429IDISCO_USBHOST_PRIO, CONFIG_STM32F429IDISCO_USBHOST_STACKSIZE, (main_t)usbhost_waiter, (FAR char * const *)NULL); - return pid < 0 ? -ENOEXEC : OK; + return ret < 0 ? -ENOEXEC : OK; } return -ENODEV; diff --git a/boards/arm/stm32/stm32f4discovery/src/Make.defs b/boards/arm/stm32/stm32f4discovery/src/Make.defs index fc8ddc85e279d..d0e06dc9da951 100644 --- a/boards/arm/stm32/stm32f4discovery/src/Make.defs +++ b/boards/arm/stm32/stm32f4discovery/src/Make.defs @@ -20,7 +20,7 @@ include $(TOPDIR)/Make.defs -CSRCS = stm32_boot.c stm32_bringup.c stm32_spi.c stm32_perfcount.c +CSRCS = stm32_boot.c stm32_bringup.c stm32_spi.c ifeq ($(CONFIG_ARCH_LEDS),y) CSRCS += stm32_autoleds.c diff --git a/boards/arm/stm32/stm32f4discovery/src/stm32_boot.c b/boards/arm/stm32/stm32f4discovery/src/stm32_boot.c index 5c9278fa4a401..0ebd3a25ac716 100644 --- a/boards/arm/stm32/stm32f4discovery/src/stm32_boot.c +++ b/boards/arm/stm32/stm32f4discovery/src/stm32_boot.c @@ -54,16 +54,7 @@ void stm32_boardinitialize(void) { #ifdef CONFIG_SCHED_CRITMONITOR - /* Enable ITM and DWT resources, if not left enabled by debugger. */ - - modifyreg32(NVIC_DEMCR, 0, NVIC_DEMCR_TRCENA); - - /* Make sure the high speed cycle counter is running. It will be started - * automatically only if a debugger is connected. - */ - - putreg32(0xc5acce55, ITM_LAR); - modifyreg32(DWT_CTRL, 0, DWT_CTRL_CYCCNTENA_MASK); + up_perf_init((FAR void *)STM32_SYSCLK_FREQUENCY); #endif #if defined(CONFIG_STM32_SPI1) || defined(CONFIG_STM32_SPI2) || defined(CONFIG_STM32_SPI3) diff --git a/boards/arm/stm32/stm32f4discovery/src/stm32_uid.c b/boards/arm/stm32/stm32f4discovery/src/stm32_uid.c index 1f4d0c3b5f316..5c03486606e3d 100644 --- a/boards/arm/stm32/stm32f4discovery/src/stm32_uid.c +++ b/boards/arm/stm32/stm32f4discovery/src/stm32_uid.c @@ -59,7 +59,7 @@ #if defined(CONFIG_BOARDCTL_UNIQUEID) int board_uniqueid(uint8_t *uniqueid) { - if (uniqueid == 0) + if (uniqueid == NULL) { return -EINVAL; } diff --git a/boards/arm/stm32/stm32f4discovery/src/stm32_usb.c b/boards/arm/stm32/stm32f4discovery/src/stm32_usb.c index c0df65df219db..bbc036fc8518a 100644 --- a/boards/arm/stm32/stm32f4discovery/src/stm32_usb.c +++ b/boards/arm/stm32/stm32f4discovery/src/stm32_usb.c @@ -156,12 +156,7 @@ void stm32_usbinitialize(void) #ifdef CONFIG_USBHOST int stm32_usbhost_initialize(void) { - int pid; -#if defined(CONFIG_USBHOST_HUB) || defined(CONFIG_USBHOST_MSC) || \ - defined(CONFIG_USBHOST_HIDKBD) || defined(CONFIG_USBHOST_HIDMOUSE) || \ - defined(CONFIG_USBHOST_XBOXCONTROLLER) int ret; -#endif /* First, register all of the class drivers needed to support the drivers * that we care about: @@ -239,10 +234,10 @@ int stm32_usbhost_initialize(void) uinfo("Start usbhost_waiter\n"); - pid = kthread_create("usbhost", CONFIG_STM32F4DISCO_USBHOST_PRIO, - CONFIG_STM32F4DISCO_USBHOST_STACKSIZE, - (main_t)usbhost_waiter, (FAR char * const *)NULL); - return pid < 0 ? -ENOEXEC : OK; + ret = kthread_create("usbhost", CONFIG_STM32F4DISCO_USBHOST_PRIO, + CONFIG_STM32F4DISCO_USBHOST_STACKSIZE, + (main_t)usbhost_waiter, (FAR char * const *)NULL); + return ret < 0 ? -ENOEXEC : OK; } return -ENODEV; diff --git a/boards/arm/stm32/viewtool-stm32f107/src/stm32_max3421e.c b/boards/arm/stm32/viewtool-stm32f107/src/stm32_max3421e.c index cb29146ecda76..599202a60136c 100644 --- a/boards/arm/stm32/viewtool-stm32f107/src/stm32_max3421e.c +++ b/boards/arm/stm32/viewtool-stm32f107/src/stm32_max3421e.c @@ -276,7 +276,6 @@ static int usbhost_detect(int argc, FAR char *argv[]) int stm32_max3421e_setup(void) { FAR struct spi_dev_s *spi; - pid_t monpid; int ret; /* Configure the MAX3421E interrupt pin as an input and the reset and power @@ -396,13 +395,13 @@ int stm32_max3421e_setup(void) /* Start the USB connection monitor kernel thread */ - monpid = kthread_create("MAX3421E ConnMon", - CONFIG_VIEWTOOL_MAX3421E_CONNMON_PRIORITY, - CONFIG_VIEWTOOL_MAX3421E_CONNMON_STACKSIZE, - usbhost_detect, NULL); - if (monpid < 0) + ret = kthread_create("MAX3421E ConnMon", + CONFIG_VIEWTOOL_MAX3421E_CONNMON_PRIORITY, + CONFIG_VIEWTOOL_MAX3421E_CONNMON_STACKSIZE, + usbhost_detect, NULL); + if (ret < 0) { - uerr("ERROR: Failed to start connection monitor: %d\n", monpid); + uerr("ERROR: Failed to start connection monitor: %d\n", ret); } return OK; diff --git a/boards/arm/stm32f7/nucleo-144/src/stm32_usb.c b/boards/arm/stm32f7/nucleo-144/src/stm32_usb.c index 65eec7623c6f3..0060192b4ab00 100644 --- a/boards/arm/stm32f7/nucleo-144/src/stm32_usb.c +++ b/boards/arm/stm32f7/nucleo-144/src/stm32_usb.c @@ -157,11 +157,7 @@ void stm32_usbinitialize(void) #ifdef CONFIG_USBHOST int stm32_usbhost_initialize(void) { - int pid; -#if defined(CONFIG_USBHOST_HUB) || defined(CONFIG_USBHOST_MSC) || \ - defined(CONFIG_USBHOST_HIDKBD) || defined(CONFIG_USBHOST_HIDMOUSE) int ret; -#endif /* First, register all of the class drivers needed to support the drivers * that we care about: @@ -229,10 +225,10 @@ int stm32_usbhost_initialize(void) uinfo("Start usbhost_waiter\n"); - pid = kthread_create("usbhost", CONFIG_STM32F4DISCO_USBHOST_PRIO, + ret = kthread_create("usbhost", CONFIG_STM32F4DISCO_USBHOST_PRIO, CONFIG_STM32F4DISCO_USBHOST_STACKSIZE, (main_t)usbhost_waiter, (FAR char * const *)NULL); - return pid < 0 ? -ENOEXEC : OK; + return ret < 0 ? -ENOEXEC : OK; } return -ENODEV; diff --git a/boards/arm/stm32f7/stm32f746-ws/src/stm32_usb.c b/boards/arm/stm32f7/stm32f746-ws/src/stm32_usb.c index 204fe8b36bc0d..673917f482525 100644 --- a/boards/arm/stm32f7/stm32f746-ws/src/stm32_usb.c +++ b/boards/arm/stm32f7/stm32f746-ws/src/stm32_usb.c @@ -159,11 +159,7 @@ void stm32_usbinitialize(void) #ifdef CONFIG_USBHOST int stm32_usbhost_initialize(void) { - int pid; -#if defined(CONFIG_USBHOST_HUB) || defined(CONFIG_USBHOST_MSC) || \ - defined(CONFIG_USBHOST_HIDKBD) || defined(CONFIG_USBHOST_HIDMOUSE) int ret; -#endif /* First, register all of the class drivers needed to support the drivers * that we care about: @@ -231,10 +227,10 @@ int stm32_usbhost_initialize(void) uinfo("Start usbhost_waiter\n"); - pid = kthread_create("usbhost", CONFIG_STM32F7F4DISCO_USBHOST_PRIO, + ret = kthread_create("usbhost", CONFIG_STM32F7F4DISCO_USBHOST_PRIO, CONFIG_STM32F7F4DISCO_USBHOST_STACKSIZE, (main_t)usbhost_waiter, (FAR char * const *)NULL); - return pid < 0 ? -ENOEXEC : OK; + return ret < 0 ? -ENOEXEC : OK; } return -ENODEV; diff --git a/boards/arm/stm32h7/nucleo-h743zi/src/stm32_uid.c b/boards/arm/stm32h7/nucleo-h743zi/src/stm32_uid.c index 0bccf9deb19c6..8fadc299c1a59 100644 --- a/boards/arm/stm32h7/nucleo-h743zi/src/stm32_uid.c +++ b/boards/arm/stm32h7/nucleo-h743zi/src/stm32_uid.c @@ -60,7 +60,7 @@ #if defined(CONFIG_BOARDCTL_UNIQUEID) int board_uniqueid(uint8_t *uniqueid) { - if (uniqueid == 0) + if (uniqueid == NULL) { return -EINVAL; } diff --git a/boards/arm/stm32h7/nucleo-h743zi/src/stm32_usb.c b/boards/arm/stm32h7/nucleo-h743zi/src/stm32_usb.c index 70df1389fa83d..b9ed68043a113 100644 --- a/boards/arm/stm32h7/nucleo-h743zi/src/stm32_usb.c +++ b/boards/arm/stm32h7/nucleo-h743zi/src/stm32_usb.c @@ -157,11 +157,7 @@ void stm32_usbinitialize(void) #ifdef CONFIG_USBHOST int stm32_usbhost_initialize(void) { - int pid; -#if defined(CONFIG_USBHOST_HUB) || defined(CONFIG_USBHOST_MSC) || \ - defined(CONFIG_USBHOST_HIDKBD) || defined(CONFIG_USBHOST_HIDMOUSE) int ret; -#endif /* First, register all of the class drivers needed to support the drivers * that we care about: @@ -229,10 +225,10 @@ int stm32_usbhost_initialize(void) uinfo("Start usbhost_waiter\n"); - pid = kthread_create("usbhost", CONFIG_NUCLEOH743ZI_USBHOST_PRIO, + ret = kthread_create("usbhost", CONFIG_NUCLEOH743ZI_USBHOST_PRIO, CONFIG_NUCLEOH743ZI_USBHOST_STACKSIZE, (main_t)usbhost_waiter, (FAR char * const *)NULL); - return pid < 0 ? -ENOEXEC : OK; + return ret < 0 ? -ENOEXEC : OK; } return -ENODEV; diff --git a/boards/arm/stm32h7/nucleo-h743zi2/src/stm32_usb.c b/boards/arm/stm32h7/nucleo-h743zi2/src/stm32_usb.c index 4d315e46f898a..a78689830006b 100644 --- a/boards/arm/stm32h7/nucleo-h743zi2/src/stm32_usb.c +++ b/boards/arm/stm32h7/nucleo-h743zi2/src/stm32_usb.c @@ -157,11 +157,7 @@ void stm32_usbinitialize(void) #ifdef CONFIG_USBHOST int stm32_usbhost_initialize(void) { - int pid; -#if defined(CONFIG_USBHOST_HUB) || defined(CONFIG_USBHOST_MSC) || \ - defined(CONFIG_USBHOST_HIDKBD) || defined(CONFIG_USBHOST_HIDMOUSE) int ret; -#endif /* First, register all of the class drivers needed to support the drivers * that we care about: @@ -229,10 +225,10 @@ int stm32_usbhost_initialize(void) uinfo("Start usbhost_waiter\n"); - pid = kthread_create("usbhost", CONFIG_USBHOST_DEFPRIO, + ret = kthread_create("usbhost", CONFIG_USBHOST_DEFPRIO, CONFIG_USBHOST_STACKSIZE, (main_t)usbhost_waiter, (FAR char * const *)NULL); - return pid < 0 ? -ENOEXEC : OK; + return ret < 0 ? -ENOEXEC : OK; } return -ENODEV; diff --git a/boards/arm/stm32h7/stm32h747i-disco/src/stm32_uid.c b/boards/arm/stm32h7/stm32h747i-disco/src/stm32_uid.c index a354e26fd68e9..39e3c329b8bcc 100644 --- a/boards/arm/stm32h7/stm32h747i-disco/src/stm32_uid.c +++ b/boards/arm/stm32h7/stm32h747i-disco/src/stm32_uid.c @@ -60,7 +60,7 @@ #if defined(CONFIG_BOARDCTL_UNIQUEID) int board_uniqueid(uint8_t *uniqueid) { - if (uniqueid == 0) + if (uniqueid == NULL) { return -EINVAL; } diff --git a/boards/arm/stm32h7/stm32h747i-disco/src/stm32_usb.c b/boards/arm/stm32h7/stm32h747i-disco/src/stm32_usb.c index 2523be71dc37b..460870ed296c1 100644 --- a/boards/arm/stm32h7/stm32h747i-disco/src/stm32_usb.c +++ b/boards/arm/stm32h7/stm32h747i-disco/src/stm32_usb.c @@ -148,11 +148,7 @@ void stm32_usbinitialize(void) #ifdef CONFIG_USBHOST int stm32_usbhost_initialize(void) { - int pid; -#if defined(CONFIG_USBHOST_HUB) || defined(CONFIG_USBHOST_MSC) || \ - defined(CONFIG_USBHOST_HIDKBD) || defined(CONFIG_USBHOST_HIDMOUSE) int ret; -#endif /* First, register all of the class drivers needed to support the drivers * that we care about: @@ -220,10 +216,10 @@ int stm32_usbhost_initialize(void) uinfo("Start usbhost_waiter\n"); - pid = kthread_create("usbhost", CONFIG_STM32H747XI_DISCO_USBHOST_PRIO, + ret = kthread_create("usbhost", CONFIG_STM32H747XI_DISCO_USBHOST_PRIO, CONFIG_STM32H747XI_DISCO_USBHOST_STACKSIZE, (main_t)usbhost_waiter, (FAR char * const *)NULL); - return pid < 0 ? -ENOEXEC : OK; + return ret < 0 ? -ENOEXEC : OK; } return -ENODEV; diff --git a/boards/arm/stm32l4/nucleo-l432kc/src/stm32_appinit.c b/boards/arm/stm32l4/nucleo-l432kc/src/stm32_appinit.c index ad8ecf4d6d548..922c3d2b4ab97 100644 --- a/boards/arm/stm32l4/nucleo-l432kc/src/stm32_appinit.c +++ b/boards/arm/stm32l4/nucleo-l432kc/src/stm32_appinit.c @@ -388,7 +388,7 @@ int board_ioctl(unsigned int cmd, uintptr_t arg) #if defined(CONFIG_BOARDCTL_UNIQUEID) int board_uniqueid(uint8_t *uniqueid) { - if (uniqueid == 0) + if (uniqueid == NULL) { return -EINVAL; } diff --git a/boards/arm/stm32l4/nucleo-l476rg/src/stm32_appinit.c b/boards/arm/stm32l4/nucleo-l476rg/src/stm32_appinit.c index 12e8741abde6a..a3cade9f668f5 100644 --- a/boards/arm/stm32l4/nucleo-l476rg/src/stm32_appinit.c +++ b/boards/arm/stm32l4/nucleo-l476rg/src/stm32_appinit.c @@ -442,7 +442,7 @@ int board_ioctl(unsigned int cmd, uintptr_t arg) #if defined(CONFIG_BOARDCTL_UNIQUEID) int board_uniqueid(uint8_t *uniqueid) { - if (uniqueid == 0) + if (uniqueid == NULL) { return -EINVAL; } diff --git a/boards/arm/stm32l4/nucleo-l496zg/src/stm32_usb.c b/boards/arm/stm32l4/nucleo-l496zg/src/stm32_usb.c index 67533dd8a5a57..5a8c77bd3dbed 100644 --- a/boards/arm/stm32l4/nucleo-l496zg/src/stm32_usb.c +++ b/boards/arm/stm32l4/nucleo-l496zg/src/stm32_usb.c @@ -157,11 +157,7 @@ void stm32_usbinitialize(void) #ifdef CONFIG_USBHOST int stm32_usbhost_initialize(void) { - int pid; -#if defined(CONFIG_USBHOST_HUB) || defined(CONFIG_USBHOST_MSC) || \ - defined(CONFIG_USBHOST_HIDKBD) || defined(CONFIG_USBHOST_HIDMOUSE) int ret; -#endif /* First, register all of the class drivers needed to support the drivers * that we care about: @@ -229,10 +225,10 @@ int stm32_usbhost_initialize(void) uinfo("Start usbhost_waiter\n"); - pid = kthread_create("usbhost", CONFIG_STM32F4DISCO_USBHOST_PRIO, + ret = kthread_create("usbhost", CONFIG_STM32F4DISCO_USBHOST_PRIO, CONFIG_STM32F4DISCO_USBHOST_STACKSIZE, (main_t)usbhost_waiter, (FAR char * const *)NULL); - return pid < 0 ? -ENOEXEC : OK; + return ret < 0 ? -ENOEXEC : OK; } return -ENODEV; diff --git a/boards/arm/stm32l4/stm32l476-mdk/src/stm32_bringup.c b/boards/arm/stm32l4/stm32l476-mdk/src/stm32_bringup.c index b13b7cafb9bfa..dc8d8b5801052 100644 --- a/boards/arm/stm32l4/stm32l476-mdk/src/stm32_bringup.c +++ b/boards/arm/stm32l4/stm32l476-mdk/src/stm32_bringup.c @@ -155,7 +155,7 @@ int board_app_initialize(uintptr_t arg) #if defined(CONFIG_BOARDCTL_UNIQUEID) int board_uniqueid(uint8_t *uniqueid) { - if (uniqueid == 0) + if (uniqueid == NULL) { return -EINVAL; } diff --git a/boards/arm/stm32l4/stm32l476vg-disco/src/stm32_appinit.c b/boards/arm/stm32l4/stm32l476vg-disco/src/stm32_appinit.c index a61f1af69a713..92bf86c68c6e1 100644 --- a/boards/arm/stm32l4/stm32l476vg-disco/src/stm32_appinit.c +++ b/boards/arm/stm32l4/stm32l476vg-disco/src/stm32_appinit.c @@ -346,7 +346,7 @@ int board_ioctl(unsigned int cmd, uintptr_t arg) #if defined(CONFIG_BOARDCTL_UNIQUEID) int board_uniqueid(uint8_t *uniqueid) { - if (uniqueid == 0) + if (uniqueid == NULL) { return -EINVAL; } diff --git a/boards/arm/stm32l4/stm32l476vg-disco/src/stm32_usb.c b/boards/arm/stm32l4/stm32l476vg-disco/src/stm32_usb.c index 6fc97bce5a0bb..5f4c185bfe7a2 100644 --- a/boards/arm/stm32l4/stm32l476vg-disco/src/stm32_usb.c +++ b/boards/arm/stm32l4/stm32l476vg-disco/src/stm32_usb.c @@ -156,11 +156,7 @@ void stm32l4_usbinitialize(void) #ifdef CONFIG_USBHOST int stm32l4_usbhost_initialize(void) { - int pid; -#if defined(CONFIG_USBHOST_HUB) || defined(CONFIG_USBHOST_MSC) || \ - defined(CONFIG_USBHOST_HIDKBD) || defined(CONFIG_USBHOST_HIDMOUSE) int ret; -#endif /* First, register all of the class drivers needed to support the drivers * that we care about: @@ -228,10 +224,10 @@ int stm32l4_usbhost_initialize(void) uvdbg("Start usbhost_waiter\n"); - pid = kthread_create("usbhost", CONFIG_STM32L4DISCO_USBHOST_PRIO, + ret = kthread_create("usbhost", CONFIG_STM32L4DISCO_USBHOST_PRIO, CONFIG_STM32L4DISCO_USBHOST_STACKSIZE, (main_t)usbhost_waiter, (FAR char * const *)NULL); - return pid < 0 ? -ENOEXEC : OK; + return ret < 0 ? -ENOEXEC : OK; } return -ENODEV; diff --git a/boards/arm/stm32l4/stm32l4r9ai-disco/src/stm32_appinit.c b/boards/arm/stm32l4/stm32l4r9ai-disco/src/stm32_appinit.c index b7ace74daf953..4559727e614d7 100644 --- a/boards/arm/stm32l4/stm32l4r9ai-disco/src/stm32_appinit.c +++ b/boards/arm/stm32l4/stm32l4r9ai-disco/src/stm32_appinit.c @@ -228,7 +228,7 @@ int board_ioctl(unsigned int cmd, uintptr_t arg) #if defined(CONFIG_BOARDCTL_UNIQUEID) int board_uniqueid(uint8_t *uniqueid) { - if (uniqueid == 0) + if (uniqueid == NULL) { return -EINVAL; } diff --git a/boards/arm/stm32l4/stm32l4r9ai-disco/src/stm32_usb.c b/boards/arm/stm32l4/stm32l4r9ai-disco/src/stm32_usb.c index 6074418fe37be..b8e404d4e2e01 100644 --- a/boards/arm/stm32l4/stm32l4r9ai-disco/src/stm32_usb.c +++ b/boards/arm/stm32l4/stm32l4r9ai-disco/src/stm32_usb.c @@ -156,11 +156,7 @@ void stm32l4_usbinitialize(void) #ifdef CONFIG_USBHOST int stm32l4_usbhost_initialize(void) { - int pid; -#if defined(CONFIG_USBHOST_HUB) || defined(CONFIG_USBHOST_MSC) || \ - defined(CONFIG_USBHOST_HIDKBD) || defined(CONFIG_USBHOST_HIDMOUSE) int ret; -#endif /* First, register all of the class drivers needed to support the drivers * that we care about: @@ -228,10 +224,10 @@ int stm32l4_usbhost_initialize(void) uvdbg("Start usbhost_waiter\n"); - pid = kthread_create("usbhost", CONFIG_STM32L4DISCO_USBHOST_PRIO, + ret = kthread_create("usbhost", CONFIG_STM32L4DISCO_USBHOST_PRIO, CONFIG_STM32L4DISCO_USBHOST_STACKSIZE, (main_t)usbhost_waiter, (FAR char * const *)NULL); - return pid < 0 ? -ENOEXEC : OK; + return ret < 0 ? -ENOEXEC : OK; } return -ENODEV; diff --git a/boards/mips/pic32mx/pic32mx-starterkit/src/pic32mx_appinit.c b/boards/mips/pic32mx/pic32mx-starterkit/src/pic32mx_appinit.c index 05a4b4644413d..43068ff902eb4 100644 --- a/boards/mips/pic32mx/pic32mx-starterkit/src/pic32mx_appinit.c +++ b/boards/mips/pic32mx/pic32mx-starterkit/src/pic32mx_appinit.c @@ -259,7 +259,6 @@ static int nsh_sdinitialize(void) #ifdef NSH_HAVEUSBHOST static int nsh_usbhostinitialize(void) { - int pid; int ret; /* First, register all of the class drivers needed to support the drivers @@ -301,10 +300,10 @@ static int nsh_usbhostinitialize(void) syslog(LOG_INFO, "Start nsh_waiter\n"); - pid = kthread_create("usbhost", CONFIG_USBHOST_DEFPRIO, + ret = kthread_create("usbhost", CONFIG_USBHOST_DEFPRIO, CONFIG_USBHOST_STACKSIZE, (main_t)nsh_waiter, (FAR char * const *)NULL); - return pid < 0 ? -ENOEXEC : OK; + return ret < 0 ? -ENOEXEC : OK; } return -ENODEV; diff --git a/boards/mips/pic32mx/pic32mx7mmb/src/pic32_bringup.c b/boards/mips/pic32mx/pic32mx7mmb/src/pic32_bringup.c index 5de25d95320bd..7ed6ac7b8a9a3 100644 --- a/boards/mips/pic32mx/pic32mx7mmb/src/pic32_bringup.c +++ b/boards/mips/pic32mx/pic32mx7mmb/src/pic32_bringup.c @@ -272,7 +272,6 @@ static int nsh_sdinitialize(void) #ifdef NSH_HAVEUSBHOST static int nsh_usbhostinitialize(void) { - int pid; int ret; /* First, register all of the class drivers needed to support the drivers @@ -314,10 +313,10 @@ static int nsh_usbhostinitialize(void) syslog(LOG_INFO, "Start nsh_waiter\n"); - pid = kthread_create("usbhost", CONFIG_USBHOST_DEFPRIO, + ret = kthread_create("usbhost", CONFIG_USBHOST_DEFPRIO, CONFIG_USBHOST_STACKSIZE, (main_t)nsh_waiter, (FAR char * const *)NULL); - return pid < 0 ? -ENOEXEC : OK; + return ret < 0 ? -ENOEXEC : OK; } return -ENODEV; diff --git a/boards/mips/pic32mx/sure-pic32mx/src/pic32mx_appinit.c b/boards/mips/pic32mx/sure-pic32mx/src/pic32mx_appinit.c index 55c861632a362..de02be7648e4c 100644 --- a/boards/mips/pic32mx/sure-pic32mx/src/pic32mx_appinit.c +++ b/boards/mips/pic32mx/sure-pic32mx/src/pic32mx_appinit.c @@ -271,7 +271,6 @@ static int nsh_sdinitialize(void) #ifdef NSH_HAVE_USBHOST static int nsh_usbhostinitialize(void) { - int pid; int ret; /* First, register all of the class drivers needed to support the drivers @@ -314,10 +313,10 @@ static int nsh_usbhostinitialize(void) syslog(LOG_INFO, "Start nsh_waiter\n"); - pid = kthread_create("usbhost", CONFIG_USBHOST_DEFPRIO, + ret = kthread_create("usbhost", CONFIG_USBHOST_DEFPRIO, CONFIG_USBHOST_STACKSIZE, (main_t)nsh_waiter, (FAR char * const *)NULL); - return pid < 0 ? -ENOEXEC : OK; + return ret < 0 ? -ENOEXEC : OK; } return -ENODEV; diff --git a/boards/renesas/rx65n/rx65n-grrose/src/rx65n_bringup.c b/boards/renesas/rx65n/rx65n-grrose/src/rx65n_bringup.c index 740ecf021ed2c..bc7262168a548 100644 --- a/boards/renesas/rx65n/rx65n-grrose/src/rx65n_bringup.c +++ b/boards/renesas/rx65n/rx65n-grrose/src/rx65n_bringup.c @@ -149,7 +149,6 @@ static int nsh_waiter(int argc, char *argv[]) #ifdef NSH_HAVE_USBHOST static int nsh_usbhostinitialize(void) { - int pid; int ret; /* First, register all of the class drivers needed to support the drivers @@ -210,11 +209,11 @@ static int nsh_usbhostinitialize(void) syslog(LOG_INFO, "Start nsh_waiter\n"); - pid = kthread_create("usbhost", CONFIG_USBHOST_DEFPRIO, + ret = kthread_create("usbhost", CONFIG_USBHOST_DEFPRIO, CONFIG_USBHOST_STACKSIZE, (main_t)nsh_waiter, (FAR char * const *)NULL); - syslog(LOG_INFO, "USBHost: Created pid = %d\n", pid); - return pid < 0 ? -ENOEXEC : OK; + syslog(LOG_INFO, "USBHost: Created pid = %d\n", ret); + return ret < 0 ? -ENOEXEC : OK; } return -ENODEV; diff --git a/boards/renesas/rx65n/rx65n-grrose/src/rx65n_sbram.c b/boards/renesas/rx65n/rx65n-grrose/src/rx65n_sbram.c index 298e8f1e336a6..a5c2382a48442 100644 --- a/boards/renesas/rx65n/rx65n-grrose/src/rx65n_sbram.c +++ b/boards/renesas/rx65n/rx65n-grrose/src/rx65n_sbram.c @@ -184,7 +184,7 @@ typedef struct fault_flags_t flags; /* What is in the dump */ uintptr_t current_regs; /* Used to validate the dump */ int lineno; /* __LINE__ to up_assert */ - int pid; /* Process ID */ + pid_t pid; /* Process ID */ uint32_t regs[XCPTCONTEXT_REGS]; /* Interrupt register save area */ stack_t stacks; /* Stack info */ #if CONFIG_TASK_NAME_SIZE > 0 diff --git a/boards/renesas/rx65n/rx65n-rsk2mb/src/rx65n_bringup.c b/boards/renesas/rx65n/rx65n-rsk2mb/src/rx65n_bringup.c index a571264dd180e..cd43344b50f7c 100644 --- a/boards/renesas/rx65n/rx65n-rsk2mb/src/rx65n_bringup.c +++ b/boards/renesas/rx65n/rx65n-rsk2mb/src/rx65n_bringup.c @@ -146,7 +146,6 @@ static int nsh_waiter(int argc, char *argv[]) #ifdef NSH_HAVE_USBHOST static int nsh_usbhostinitialize(void) { - int pid; int ret; /* First, register all of the class drivers needed to support the drivers @@ -209,11 +208,11 @@ static int nsh_usbhostinitialize(void) syslog(LOG_INFO, "Start nsh_waiter\n"); - pid = kthread_create("usbhost", CONFIG_USBHOST_DEFPRIO, + ret = kthread_create("usbhost", CONFIG_USBHOST_DEFPRIO, CONFIG_USBHOST_STACKSIZE, (main_t)nsh_waiter, (FAR char * const *)NULL); - syslog(LOG_INFO, "USBHost: Created pid = %d\n", pid); - return pid < 0 ? -ENOEXEC : OK; + syslog(LOG_INFO, "USBHost: Created pid = %d\n", ret); + return ret < 0 ? -ENOEXEC : OK; } return -ENODEV; diff --git a/boards/renesas/rx65n/rx65n-rsk2mb/src/rx65n_sbram.c b/boards/renesas/rx65n/rx65n-rsk2mb/src/rx65n_sbram.c index d50cf108dde7e..98bf5a52555a5 100644 --- a/boards/renesas/rx65n/rx65n-rsk2mb/src/rx65n_sbram.c +++ b/boards/renesas/rx65n/rx65n-rsk2mb/src/rx65n_sbram.c @@ -184,7 +184,7 @@ typedef struct fault_flags_t flags; /* What is in the dump */ uintptr_t current_regs; /* Used to validate the dump */ int lineno; /* __LINE__ to up_assert */ - int pid; /* Process ID */ + pid_t pid; /* Process ID */ uint32_t regs[XCPTCONTEXT_REGS]; /* Interrupt register save area */ stack_t stacks; /* Stack info */ #if CONFIG_TASK_NAME_SIZE > 0 diff --git a/boards/risc-v/qemu-rv/rv-virt/configs/nsh64/defconfig b/boards/risc-v/qemu-rv/rv-virt/configs/nsh64/defconfig index 65c449558a3c8..f621901598b59 100644 --- a/boards/risc-v/qemu-rv/rv-virt/configs/nsh64/defconfig +++ b/boards/risc-v/qemu-rv/rv-virt/configs/nsh64/defconfig @@ -47,6 +47,7 @@ CONFIG_DEV_ZERO=y CONFIG_FS_PROCFS=y CONFIG_IDLETHREAD_STACKSIZE=2048 CONFIG_INIT_ENTRYPOINT="nsh_main" +CONFIG_INIT_STACKSIZE=3072 CONFIG_INTELHEX_BINARY=y CONFIG_LIBC_FLOATINGPOINT=y CONFIG_LIBC_PERROR_STDOUT=y @@ -65,6 +66,7 @@ CONFIG_STACK_COLORATION=y CONFIG_START_MONTH=12 CONFIG_START_YEAR=2021 CONFIG_SYSTEM_NSH=y +CONFIG_SYSTEM_NSH_STACKSIZE=3072 CONFIG_TESTING_OSTEST=y CONFIG_TESTING_OSTEST_FPUSIZE=264 CONFIG_USEC_PER_TICK=1000 diff --git a/boards/risc-v/qemu-rv/rv-virt/configs/smp64/defconfig b/boards/risc-v/qemu-rv/rv-virt/configs/smp64/defconfig index 8567615a8ce42..e9a7d67d2b959 100644 --- a/boards/risc-v/qemu-rv/rv-virt/configs/smp64/defconfig +++ b/boards/risc-v/qemu-rv/rv-virt/configs/smp64/defconfig @@ -47,6 +47,7 @@ CONFIG_DEV_ZERO=y CONFIG_FS_PROCFS=y CONFIG_IDLETHREAD_STACKSIZE=2048 CONFIG_INIT_ENTRYPOINT="nsh_main" +CONFIG_INIT_STACKSIZE=3072 CONFIG_INTELHEX_BINARY=y CONFIG_LIBC_FLOATINGPOINT=y CONFIG_LIBC_PERROR_STDOUT=y @@ -67,6 +68,7 @@ CONFIG_STACK_COLORATION=y CONFIG_START_MONTH=12 CONFIG_START_YEAR=2021 CONFIG_SYSTEM_NSH=y +CONFIG_SYSTEM_NSH_STACKSIZE=3072 CONFIG_TESTING_OSTEST=y CONFIG_TESTING_OSTEST_FPUSIZE=264 CONFIG_TESTING_SMP=y diff --git a/boards/sim/sim/sim/configs/cxxtest/defconfig b/boards/sim/sim/sim/configs/cxxtest/defconfig index 4dd7aced4c3e1..92a2250aff018 100644 --- a/boards/sim/sim/sim/configs/cxxtest/defconfig +++ b/boards/sim/sim/sim/configs/cxxtest/defconfig @@ -11,6 +11,8 @@ CONFIG_ARCH_BOARD_SIM=y CONFIG_ARCH_CHIP="sim" CONFIG_ARCH_SIM=y CONFIG_BOARD_LOOPSPERMSEC=100 +CONFIG_CXX_EXCEPTION=y +CONFIG_CXX_RTTI=y CONFIG_HAVE_CXX=y CONFIG_IDLETHREAD_STACKSIZE=4096 CONFIG_INIT_ENTRYPOINT="cxxtest_main" diff --git a/boards/sim/sim/sim/configs/foc/defconfig b/boards/sim/sim/sim/configs/foc/defconfig index 781f2dba2247b..167e2aa974dd3 100644 --- a/boards/sim/sim/sim/configs/foc/defconfig +++ b/boards/sim/sim/sim/configs/foc/defconfig @@ -82,6 +82,7 @@ CONFIG_READLINE_TABCOMPLETION=y CONFIG_SCHED_HAVE_PARENT=y CONFIG_SCHED_HPWORK=y CONFIG_SCHED_ONEXIT=y +CONFIG_SCHED_SPORADIC=y CONFIG_SCHED_WAITPID=y CONFIG_SIM_M32=y CONFIG_START_MONTH=6 diff --git a/boards/sim/sim/sim/configs/libcxxtest/defconfig b/boards/sim/sim/sim/configs/libcxxtest/defconfig index fa8153325c592..d867438364533 100644 --- a/boards/sim/sim/sim/configs/libcxxtest/defconfig +++ b/boards/sim/sim/sim/configs/libcxxtest/defconfig @@ -17,6 +17,7 @@ CONFIG_BOARD_LOOPSPERMSEC=0 CONFIG_BOOT_RUNFROMEXTSRAM=y CONFIG_BUILTIN=y CONFIG_CXX_EXCEPTION=y +CONFIG_CXX_RTTI=y CONFIG_DEBUG_ASSERTIONS=y CONFIG_DEBUG_BINFMT=y CONFIG_DEBUG_BINFMT_ERROR=y diff --git a/boards/sim/sim/sim/configs/lua/defconfig b/boards/sim/sim/sim/configs/lua/defconfig new file mode 100644 index 0000000000000..f73826f231ffd --- /dev/null +++ b/boards/sim/sim/sim/configs/lua/defconfig @@ -0,0 +1,64 @@ +# +# This file is autogenerated: PLEASE DO NOT EDIT IT. +# +# You can use "make menuconfig" to make any modifications to the installed .config file. +# You can then do "make savedefconfig" to generate a new defconfig file that includes your +# modifications. +# +# CONFIG_INTERPRETER_LUA_32BIT is not set +# CONFIG_NSH_CMDOPT_HEXDUMP is not set +CONFIG_ARCH="sim" +CONFIG_ARCH_BOARD="sim" +CONFIG_ARCH_BOARD_SIM=y +CONFIG_ARCH_CHIP="sim" +CONFIG_ARCH_SIM=y +CONFIG_BOARDCTL_APP_SYMTAB=y +CONFIG_BOARDCTL_POWEROFF=y +CONFIG_BOARD_LOOPSPERMSEC=0 +CONFIG_BOOT_RUNFROMEXTSRAM=y +CONFIG_BUILTIN=y +CONFIG_DEBUG_SYMBOLS=y +CONFIG_DEV_LOOP=y +CONFIG_DEV_ZERO=y +CONFIG_EXAMPLES_LUA_MODULE=y +CONFIG_FAT_LCNAMES=y +CONFIG_FAT_LFN=y +CONFIG_FSUTILS_PASSWD=y +CONFIG_FSUTILS_PASSWD_READONLY=y +CONFIG_FS_BINFS=y +CONFIG_FS_FAT=y +CONFIG_FS_PROCFS=y +CONFIG_FS_RAMMAP=y +CONFIG_FS_ROMFS=y +CONFIG_IDLETHREAD_STACKSIZE=4096 +CONFIG_INIT_ENTRYPOINT="nsh_main" +CONFIG_INTERPRETERS_LUA=y +CONFIG_LIBC_ENVPATH=y +CONFIG_LIBC_EXECFUNCS=y +CONFIG_LIBC_FLOATINGPOINT=y +CONFIG_LIBC_LOCALE_CATALOG=y +CONFIG_LIBC_LOCALE_GETTEXT=y +CONFIG_LIBM=y +CONFIG_NSH_ARCHINIT=y +CONFIG_NSH_ARCHROMFS=y +CONFIG_NSH_BUILTIN_APPS=y +CONFIG_NSH_FATDEVNO=2 +CONFIG_NSH_FILE_APPS=y +CONFIG_NSH_READLINE=y +CONFIG_NSH_ROMFSDEVNO=1 +CONFIG_NSH_ROMFSETC=y +CONFIG_PATH_INITIAL="/bin" +CONFIG_POSIX_SPAWN_PROXY_STACKSIZE=2048 +CONFIG_PSEUDOFS_ATTRIBUTES=y +CONFIG_PSEUDOFS_SOFTLINKS=y +CONFIG_READLINE_CMD_HISTORY=y +CONFIG_READLINE_TABCOMPLETION=y +CONFIG_SCHED_HAVE_PARENT=y +CONFIG_SCHED_HPWORK=y +CONFIG_SCHED_ONEXIT=y +CONFIG_SERIAL_TERMIOS=y +CONFIG_SIG_DEFAULT=y +CONFIG_START_MONTH=6 +CONFIG_START_YEAR=2008 +CONFIG_SYSTEM_NSH=y +CONFIG_TTY_SIGINT=y diff --git a/boards/sim/sim/sim/scripts/Make.defs b/boards/sim/sim/sim/scripts/Make.defs index 897dd22bcf12c..fb6bad3a97d30 100644 --- a/boards/sim/sim/sim/scripts/Make.defs +++ b/boards/sim/sim/sim/scripts/Make.defs @@ -73,6 +73,9 @@ ARCHCXXFLAGS = -fno-common -ffunction-sections -fdata-sections -nostdinc++ ifeq ($(CONFIG_CXX_EXCEPTION),) ARCHCXXFLAGS += -fno-exceptions -fcheck-new endif +ifeq ($(CONFIG_CXX_RTTI),) + ARCHCXXFLAGS += -fno-rtti +endif ARCHPICFLAGS = -fpic ARCHWARNINGS = -Wall -Wstrict-prototypes -Wshadow -Wundef ARCHWARNINGSXX = -Wall -Wshadow -Wundef diff --git a/boards/xtensa/esp32s2/esp32s2-saola-1/configs/gpio/defconfig b/boards/xtensa/esp32s2/esp32s2-saola-1/configs/gpio/defconfig index d6c4dbc79ff8c..33a16c2204adc 100644 --- a/boards/xtensa/esp32s2/esp32s2-saola-1/configs/gpio/defconfig +++ b/boards/xtensa/esp32s2/esp32s2-saola-1/configs/gpio/defconfig @@ -21,7 +21,6 @@ CONFIG_ARCH_XTENSA=y CONFIG_BOARD_LOOPSPERMSEC=16717 CONFIG_BUILTIN=y CONFIG_DEV_GPIO=y -CONFIG_ESP32S2_DATA_CACHE_0KB=y CONFIG_ESP32S2_GPIO_IRQ=y CONFIG_ESP32S2_UART0=y CONFIG_EXAMPLES_GPIO=y diff --git a/boards/xtensa/esp32s2/esp32s2-saola-1/configs/mcuboot_nsh/defconfig b/boards/xtensa/esp32s2/esp32s2-saola-1/configs/mcuboot_nsh/defconfig index 8873d2a0e0ed2..cfb6e018f6321 100644 --- a/boards/xtensa/esp32s2/esp32s2-saola-1/configs/mcuboot_nsh/defconfig +++ b/boards/xtensa/esp32s2/esp32s2-saola-1/configs/mcuboot_nsh/defconfig @@ -21,7 +21,6 @@ CONFIG_ARCH_XTENSA=y CONFIG_BOARD_LOOPSPERMSEC=16717 CONFIG_BUILTIN=y CONFIG_ESP32S2_APP_FORMAT_MCUBOOT=y -CONFIG_ESP32S2_DATA_CACHE_0KB=y CONFIG_ESP32S2_SPIFLASH=y CONFIG_ESP32S2_UART0=y CONFIG_EXPERIMENTAL=y diff --git a/boards/xtensa/esp32s2/esp32s2-saola-1/configs/nsh/defconfig b/boards/xtensa/esp32s2/esp32s2-saola-1/configs/nsh/defconfig index 2b5e2070f728b..bb193b1bc5b5a 100644 --- a/boards/xtensa/esp32s2/esp32s2-saola-1/configs/nsh/defconfig +++ b/boards/xtensa/esp32s2/esp32s2-saola-1/configs/nsh/defconfig @@ -20,7 +20,6 @@ CONFIG_ARCH_STACKDUMP=y CONFIG_ARCH_XTENSA=y CONFIG_BOARD_LOOPSPERMSEC=16717 CONFIG_BUILTIN=y -CONFIG_ESP32S2_DATA_CACHE_0KB=y CONFIG_ESP32S2_UART0=y CONFIG_FS_PROCFS=y CONFIG_HAVE_CXX=y diff --git a/boards/xtensa/esp32s2/esp32s2-saola-1/configs/oneshot/defconfig b/boards/xtensa/esp32s2/esp32s2-saola-1/configs/oneshot/defconfig index c48e561ffaa57..4a38450a93577 100644 --- a/boards/xtensa/esp32s2/esp32s2-saola-1/configs/oneshot/defconfig +++ b/boards/xtensa/esp32s2/esp32s2-saola-1/configs/oneshot/defconfig @@ -20,7 +20,6 @@ CONFIG_ARCH_STACKDUMP=y CONFIG_ARCH_XTENSA=y CONFIG_BOARD_LOOPSPERMSEC=16717 CONFIG_BUILTIN=y -CONFIG_ESP32S2_DATA_CACHE_0KB=y CONFIG_ESP32S2_ONESHOT=y CONFIG_ESP32S2_TIMER0=y CONFIG_ESP32S2_UART0=y diff --git a/boards/xtensa/esp32s2/esp32s2-saola-1/configs/random/defconfig b/boards/xtensa/esp32s2/esp32s2-saola-1/configs/random/defconfig index 6b5ba4badfcdb..3a9a20ee527f0 100644 --- a/boards/xtensa/esp32s2/esp32s2-saola-1/configs/random/defconfig +++ b/boards/xtensa/esp32s2/esp32s2-saola-1/configs/random/defconfig @@ -20,7 +20,6 @@ CONFIG_ARCH_STACKDUMP=y CONFIG_ARCH_XTENSA=y CONFIG_BOARD_LOOPSPERMSEC=16717 CONFIG_BUILTIN=y -CONFIG_ESP32S2_DATA_CACHE_0KB=y CONFIG_ESP32S2_RNG=y CONFIG_ESP32S2_UART0=y CONFIG_EXAMPLES_RANDOM=y diff --git a/boards/xtensa/esp32s2/esp32s2-saola-1/configs/timer/defconfig b/boards/xtensa/esp32s2/esp32s2-saola-1/configs/timer/defconfig index 16fac0d5d176e..27969b16cdc9d 100644 --- a/boards/xtensa/esp32s2/esp32s2-saola-1/configs/timer/defconfig +++ b/boards/xtensa/esp32s2/esp32s2-saola-1/configs/timer/defconfig @@ -20,7 +20,6 @@ CONFIG_ARCH_STACKDUMP=y CONFIG_ARCH_XTENSA=y CONFIG_BOARD_LOOPSPERMSEC=16717 CONFIG_BUILTIN=y -CONFIG_ESP32S2_DATA_CACHE_0KB=y CONFIG_ESP32S2_TIMER0=y CONFIG_ESP32S2_TIMER1=y CONFIG_ESP32S2_TIMER2=y diff --git a/boards/xtensa/esp32s2/esp32s2-saola-1/configs/watchdog/defconfig b/boards/xtensa/esp32s2/esp32s2-saola-1/configs/watchdog/defconfig index 7089f732cb0b1..c90d389d430bd 100644 --- a/boards/xtensa/esp32s2/esp32s2-saola-1/configs/watchdog/defconfig +++ b/boards/xtensa/esp32s2/esp32s2-saola-1/configs/watchdog/defconfig @@ -22,7 +22,6 @@ CONFIG_BOARD_LOOPSPERMSEC=16717 CONFIG_BUILTIN=y CONFIG_DEBUG_FULLOPT=y CONFIG_DEBUG_SYMBOLS=y -CONFIG_ESP32S2_DATA_CACHE_0KB=y CONFIG_ESP32S2_MWDT0=y CONFIG_ESP32S2_MWDT1=y CONFIG_ESP32S2_UART0=y diff --git a/boards/xtensa/esp32s2/esp32s2-saola-1/include/board.h b/boards/xtensa/esp32s2/esp32s2-saola-1/include/board.h index 0d462d92f9fbe..ae4fcecd79bff 100644 --- a/boards/xtensa/esp32s2/esp32s2-saola-1/include/board.h +++ b/boards/xtensa/esp32s2/esp32s2-saola-1/include/board.h @@ -21,13 +21,19 @@ #ifndef __BOARDS_XTENSA_ESP32S2_ESP32S2_SAOLA_1_INCLUDE_BOARD_H #define __BOARDS_XTENSA_ESP32S2_ESP32S2_SAOLA_1_INCLUDE_BOARD_H +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ /* Clocking *****************************************************************/ -/* The ESP32S2 board V2 is fitted with a 40MHz crystal */ +/* The ESP32-S2-Saola-1 is fitted with a 40MHz crystal */ #define BOARD_XTAL_FREQUENCY 40000000 @@ -47,13 +53,11 @@ /* Note: The bootloader (esp-idf bootloader.bin) configures: * * - CPU frequency to 80MHz - * - The XTAL frequency according to the SDK config CONFIG_ESP32S2_XTAL_FREQ, - * which is 40MHz by default. * * Reference: * https://github.com/espressif/esp-idf/blob - * /6fd855ab8d00d23bad4660216bc2122c2285d5be/components - * /bootloader_support/src/bootloader_clock.c#L38-L62 + * /ebf7e811b12e3c1e347340e5b9ec014e9c6319ba/components + * /bootloader_support/src/bootloader_clock_init.c#L26-L27 */ #ifdef CONFIG_ESP32S2_RUN_IRAM diff --git a/boards/xtensa/esp32s2/esp32s2-saola-1/scripts/esp32s2.template.ld b/boards/xtensa/esp32s2/esp32s2-saola-1/scripts/esp32s2.template.ld index bb126f9e8dc0e..b08bf7163471b 100644 --- a/boards/xtensa/esp32s2/esp32s2-saola-1/scripts/esp32s2.template.ld +++ b/boards/xtensa/esp32s2/esp32s2-saola-1/scripts/esp32s2.template.ld @@ -16,20 +16,6 @@ #include -#ifdef CONFIG_ESP32S2_INSTRUCTION_CACHE_8KB -# define CONFIG_ESP32S2_INSTRUCTION_CACHE_SIZE 0x2000 -#else -# define CONFIG_ESP32S2_INSTRUCTION_CACHE_SIZE 0x4000 -#endif - -#ifdef CONFIG_ESP32S2_DATA_CACHE_0KB -# define CONFIG_ESP32S2_DATA_CACHE_SIZE 0 -#elif defined CONFIG_ESP32S2_DATA_CACHE_8KB -# define CONFIG_ESP32S2_DATA_CACHE_SIZE 0x2000 -#else -# define CONFIG_ESP32S2_DATA_CACHE_SIZE 0x4000 -#endif - #define RAM_IRAM_START 0x40020000 #define RAM_DRAM_START 0x3ffb0000 diff --git a/boards/xtensa/esp32s2/esp32s2-saola-1/scripts/esp32s2_rom.ld b/boards/xtensa/esp32s2/esp32s2-saola-1/scripts/esp32s2_rom.ld index 3290eb3b6f095..ec17e1d4841da 100644 --- a/boards/xtensa/esp32s2/esp32s2-saola-1/scripts/esp32s2_rom.ld +++ b/boards/xtensa/esp32s2/esp32s2-saola-1/scripts/esp32s2_rom.ld @@ -11,7 +11,7 @@ PROVIDE ( acm_usb_descriptors = 0x3ffaee68 ); PROVIDE ( boot_prepare = 0x4000f348 ); PROVIDE ( Cache_Address_Through_DCache = 0x400180f0 ); PROVIDE ( Cache_Address_Through_ICache = 0x400180bc ); -PROVIDE ( Cache_Allocate_SRAM = 0x40018d6c ); +PROVIDE ( cache_allocate_sram = 0x40018d6c ); PROVIDE ( Cache_Clean_Addr = 0x40018370 ); PROVIDE ( Cache_Clean_All = 0x40018438 ); PROVIDE ( Cache_Clean_Items = 0x40018250 ); @@ -62,7 +62,7 @@ PROVIDE ( cache_resume_icache = 0x40018cdc ); PROVIDE ( Cache_Resume_ICache_Autoload = 0x400184c4 ); PROVIDE ( Cache_Set_DCache_Mode = 0x40018074 ); PROVIDE ( Cache_Set_Default_Mode = 0x4001810c ); -PROVIDE ( Cache_Set_ICache_Mode = 0x4001803c ); +PROVIDE ( cache_set_icache_mode = 0x4001803c ); PROVIDE ( Cache_Start_DCache_Preload = 0x400185c4 ); PROVIDE ( Cache_Start_ICache_Preload = 0x40018530 ); PROVIDE ( Cache_Suspend_DCache = 0x40018d04 ); diff --git a/boards/xtensa/esp32s3/esp32s3-devkit/configs/buttons/defconfig b/boards/xtensa/esp32s3/esp32s3-devkit/configs/buttons/defconfig new file mode 100644 index 0000000000000..3ecc36624bf55 --- /dev/null +++ b/boards/xtensa/esp32s3/esp32s3-devkit/configs/buttons/defconfig @@ -0,0 +1,57 @@ +# +# This file is autogenerated: PLEASE DO NOT EDIT IT. +# +# You can use "make menuconfig" to make any modifications to the installed .config file. +# You can then do "make savedefconfig" to generate a new defconfig file that includes your +# modifications. +# +# CONFIG_ARCH_LEDS is not set +# CONFIG_NSH_ARGCAT is not set +# CONFIG_NSH_CMDOPT_HEXDUMP is not set +# CONFIG_NSH_CMDPARMS is not set +CONFIG_ARCH="xtensa" +CONFIG_ARCH_BOARD="esp32s3-devkit" +CONFIG_ARCH_BOARD_COMMON=y +CONFIG_ARCH_BOARD_ESP32S3_DEVKIT=y +CONFIG_ARCH_BUTTONS=y +CONFIG_ARCH_CHIP="esp32s3" +CONFIG_ARCH_CHIP_ESP32S3=y +CONFIG_ARCH_CHIP_ESP32S3WROOM1=y +CONFIG_ARCH_IRQBUTTONS=y +CONFIG_ARCH_STACKDUMP=y +CONFIG_ARCH_XTENSA=y +CONFIG_BOARD_LOOPSPERMSEC=16717 +CONFIG_BUILTIN=y +CONFIG_DEBUG_FULLOPT=y +CONFIG_DEBUG_SYMBOLS=y +CONFIG_ESP32S3_GPIO_IRQ=y +CONFIG_ESP32S3_UART0=y +CONFIG_EXAMPLES_BUTTONS=y +CONFIG_EXAMPLES_BUTTONS_NAME0="BOOT" +CONFIG_EXAMPLES_BUTTONS_NAMES=y +CONFIG_EXAMPLES_BUTTONS_QTD=1 +CONFIG_FS_PROCFS=y +CONFIG_HAVE_CXX=y +CONFIG_HAVE_CXXINITIALIZE=y +CONFIG_IDLETHREAD_STACKSIZE=3072 +CONFIG_INIT_ENTRYPOINT="nsh_main" +CONFIG_INPUT=y +CONFIG_INPUT_BUTTONS=y +CONFIG_INPUT_BUTTONS_LOWER=y +CONFIG_INTELHEX_BINARY=y +CONFIG_NSH_ARCHINIT=y +CONFIG_NSH_BUILTIN_APPS=y +CONFIG_NSH_FILEIOSIZE=512 +CONFIG_NSH_LINELEN=64 +CONFIG_NSH_READLINE=y +CONFIG_PREALLOC_TIMERS=4 +CONFIG_RAM_SIZE=114688 +CONFIG_RAM_START=0x20000000 +CONFIG_RAW_BINARY=y +CONFIG_RR_INTERVAL=200 +CONFIG_SCHED_WAITPID=y +CONFIG_START_DAY=6 +CONFIG_START_MONTH=12 +CONFIG_START_YEAR=2011 +CONFIG_SYSTEM_NSH=y +CONFIG_UART0_SERIAL_CONSOLE=y diff --git a/boards/xtensa/esp32s3/esp32s3-devkit/configs/nsh/defconfig b/boards/xtensa/esp32s3/esp32s3-devkit/configs/nsh/defconfig index 81a8fb7615839..85854d0848ff5 100644 --- a/boards/xtensa/esp32s3/esp32s3-devkit/configs/nsh/defconfig +++ b/boards/xtensa/esp32s3/esp32s3-devkit/configs/nsh/defconfig @@ -29,7 +29,6 @@ CONFIG_HAVE_CXXINITIALIZE=y CONFIG_IDLETHREAD_STACKSIZE=3072 CONFIG_INIT_ENTRYPOINT="nsh_main" CONFIG_INTELHEX_BINARY=y -CONFIG_MM_REGIONS=3 CONFIG_NSH_ARCHINIT=y CONFIG_NSH_BUILTIN_APPS=y CONFIG_NSH_FILEIOSIZE=512 diff --git a/boards/xtensa/esp32s3/esp32s3-devkit/configs/oneshot/defconfig b/boards/xtensa/esp32s3/esp32s3-devkit/configs/oneshot/defconfig index e35347e66584b..eb664e6917ae9 100644 --- a/boards/xtensa/esp32s3/esp32s3-devkit/configs/oneshot/defconfig +++ b/boards/xtensa/esp32s3/esp32s3-devkit/configs/oneshot/defconfig @@ -37,7 +37,6 @@ CONFIG_HAVE_CXXINITIALIZE=y CONFIG_IDLETHREAD_STACKSIZE=3072 CONFIG_INIT_ENTRYPOINT="nsh_main" CONFIG_INTELHEX_BINARY=y -CONFIG_MM_REGIONS=3 CONFIG_NSH_ARCHINIT=y CONFIG_NSH_BUILTIN_APPS=y CONFIG_NSH_FILEIOSIZE=512 diff --git a/boards/xtensa/esp32s3/esp32s3-devkit/configs/spiflash/defconfig b/boards/xtensa/esp32s3/esp32s3-devkit/configs/spiflash/defconfig index bf4df4936353d..03115d1d44724 100644 --- a/boards/xtensa/esp32s3/esp32s3-devkit/configs/spiflash/defconfig +++ b/boards/xtensa/esp32s3/esp32s3-devkit/configs/spiflash/defconfig @@ -32,7 +32,6 @@ CONFIG_HOST_MACOS=y CONFIG_IDLETHREAD_STACKSIZE=3072 CONFIG_INIT_ENTRYPOINT="nsh_main" CONFIG_INTELHEX_BINARY=y -CONFIG_MM_REGIONS=3 CONFIG_NSH_ARCHINIT=y CONFIG_NSH_BUILTIN_APPS=y CONFIG_NSH_DISABLE_LOSMART=y diff --git a/boards/xtensa/esp32s3/esp32s3-devkit/configs/timer/defconfig b/boards/xtensa/esp32s3/esp32s3-devkit/configs/timer/defconfig index 019aa241c1593..da691d0805448 100644 --- a/boards/xtensa/esp32s3/esp32s3-devkit/configs/timer/defconfig +++ b/boards/xtensa/esp32s3/esp32s3-devkit/configs/timer/defconfig @@ -34,7 +34,6 @@ CONFIG_HAVE_CXXINITIALIZE=y CONFIG_IDLETHREAD_STACKSIZE=3072 CONFIG_INIT_ENTRYPOINT="nsh_main" CONFIG_INTELHEX_BINARY=y -CONFIG_MM_REGIONS=3 CONFIG_NSH_ARCHINIT=y CONFIG_NSH_BUILTIN_APPS=y CONFIG_NSH_FILEIOSIZE=512 diff --git a/boards/xtensa/esp32s3/esp32s3-devkit/configs/watchdog/defconfig b/boards/xtensa/esp32s3/esp32s3-devkit/configs/watchdog/defconfig index ff0d72462ced4..87a9eea1910b3 100644 --- a/boards/xtensa/esp32s3/esp32s3-devkit/configs/watchdog/defconfig +++ b/boards/xtensa/esp32s3/esp32s3-devkit/configs/watchdog/defconfig @@ -32,7 +32,6 @@ CONFIG_HAVE_CXXINITIALIZE=y CONFIG_IDLETHREAD_STACKSIZE=3072 CONFIG_INIT_ENTRYPOINT="nsh_main" CONFIG_INTELHEX_BINARY=y -CONFIG_MM_REGIONS=3 CONFIG_NSH_ARCHINIT=y CONFIG_NSH_BUILTIN_APPS=y CONFIG_NSH_FILEIOSIZE=512 diff --git a/boards/xtensa/esp32s3/esp32s3-devkit/src/Make.defs b/boards/xtensa/esp32s3/esp32s3-devkit/src/Make.defs index 25297e832ef38..65993619dc7da 100644 --- a/boards/xtensa/esp32s3/esp32s3-devkit/src/Make.defs +++ b/boards/xtensa/esp32s3/esp32s3-devkit/src/Make.defs @@ -33,6 +33,10 @@ CSRCS += esp32s3_reset.c endif endif +ifeq ($(CONFIG_ARCH_BUTTONS),y) +CSRCS += esp32s3_buttons.c +endif + SCRIPTIN = $(SCRIPTDIR)$(DELIM)esp32s3.template.ld SCRIPTOUT = $(SCRIPTDIR)$(DELIM)esp32s3_out.ld diff --git a/boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3-devkit.h b/boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3-devkit.h index 5588ecc70be48..be394764ffa43 100644 --- a/boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3-devkit.h +++ b/boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3-devkit.h @@ -33,6 +33,12 @@ * Pre-processor Definitions ****************************************************************************/ +/* ESP32-S3-DEVKIT GPIOs ****************************************************/ + +/* BOOT Button */ + +#define BUTTON_BOOT 0 + /**************************************************************************** * Public Types ****************************************************************************/ diff --git a/boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3_bringup.c b/boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3_bringup.c index 8813a64d15680..555c010b85dbe 100644 --- a/boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3_bringup.c +++ b/boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3_bringup.c @@ -50,6 +50,10 @@ # include "esp32s3_board_wdt.h" #endif +#ifdef CONFIG_INPUT_BUTTONS +# include +#endif + #include "esp32s3-devkit.h" /**************************************************************************** @@ -123,6 +127,16 @@ int esp32s3_bringup(void) } #endif +#ifdef CONFIG_INPUT_BUTTONS + /* Register the BUTTON driver */ + + ret = btn_lower_initialize("/dev/buttons"); + if (ret < 0) + { + syslog(LOG_ERR, "Failed to initialize button driver: %d\n", ret); + } +#endif + #ifdef CONFIG_ESP32S3_SPIFLASH ret = board_spiflash_init(); if (ret) diff --git a/boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3_buttons.c b/boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3_buttons.c new file mode 100644 index 0000000000000..b8be81c95a3fc --- /dev/null +++ b/boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3_buttons.c @@ -0,0 +1,164 @@ +/**************************************************************************** + * boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3_buttons.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include +#include +#include + +#include "esp32s3_gpio.h" +#include "hardware/esp32s3_gpio_sigmap.h" + +#include "esp32s3-devkit.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_button_initialize + * + * Description: + * board_button_initialize() must be called to initialize button resources. + * After that, board_buttons() may be called to collect the current state + * of all buttons or board_button_irq() may be called to register button + * interrupt handlers. + * + ****************************************************************************/ + +uint32_t board_button_initialize(void) +{ + esp32s3_configgpio(BUTTON_BOOT, INPUT_FUNCTION_2 | PULLUP); + return 1; +} + +/**************************************************************************** + * Name: board_buttons + * + * Description: + * After board_button_initialize() has been called, board_buttons() may be + * called to collect the state of all buttons. board_buttons() returns an + * 8-bit bit set with each bit associated with a button. See the + * BUTTON_*_BIT definitions in board.h for the meaning of each bit. + * + ****************************************************************************/ + +uint32_t board_buttons(void) +{ + uint8_t ret = 0; + int i = 0; + int n = 0; + + bool b0 = esp32s3_gpioread(BUTTON_BOOT); + + for (i = 0; i < 10; i++) + { + up_mdelay(1); + + bool b1 = esp32s3_gpioread(BUTTON_BOOT); + + if (b0 == b1) + { + n++; + } + else + { + n = 0; + } + + if (3 == n) + { + break; + } + + b0 = b1; + } + + iinfo("b=%d n=%d\n", b0, n); + + /* Low value means that the button is pressed */ + + if (!b0) + { + ret = 0x1; + } + + return ret; +} + +/**************************************************************************** + * Name: board_button_irq + * + * Description: + * board_button_irq() may be called to register an interrupt handler that + * will be called when a button is depressed or released. The ID value is + * a button enumeration value that uniquely identifies a button resource. + * See the BUTTON_* definitions in board.h for the meaning of enumeration + * value. + * + ****************************************************************************/ + +#ifdef CONFIG_ARCH_IRQBUTTONS +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +{ + int ret; + DEBUGASSERT(id == BUTTON_BOOT); + + int irq = ESP32S3_PIN2IRQ(BUTTON_BOOT); + + if (irqhandler != NULL) + { + /* Make sure the interrupt is disabled */ + + esp32s3_gpioirqdisable(irq); + + ret = irq_attach(irq, irqhandler, arg); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: irq_attach() failed: %d\n", ret); + return ret; + } + + gpioinfo("Attach %p\n", irqhandler); + + gpioinfo("Enabling the interrupt\n"); + + /* Configure the interrupt for rising and falling edges */ + + esp32s3_gpioirqenable(irq, GPIO_INTR_ANYEDGE); + } + else + { + gpioinfo("Disable the interrupt\n"); + esp32s3_gpioirqdisable(irq); + } + + return OK; +} +#endif diff --git a/crypto/random_pool.c b/crypto/random_pool.c index c9fc1e85588d2..005c3558612ed 100644 --- a/crypto/random_pool.c +++ b/crypto/random_pool.c @@ -27,15 +27,14 @@ #include #include #include -#include #include #include #include -#include #include #include - +#include +#include #include /**************************************************************************** diff --git a/drivers/1wire/1wire.c b/drivers/1wire/1wire.c index ce673a0cd3f77..43aee5c15b922 100644 --- a/drivers/1wire/1wire.c +++ b/drivers/1wire/1wire.c @@ -46,7 +46,7 @@ # define onewire_leuint32(x) (x) #endif -#define NO_HOLDER ((pid_t)-1) +#define NO_HOLDER (INVALID_PROCESS_ID) /**************************************************************************** * Private Function Prototypes diff --git a/drivers/lcd/ft80x.h b/drivers/lcd/ft80x.h index 4adc3ba7da1c1..5c5ff979740cb 100644 --- a/drivers/lcd/ft80x.h +++ b/drivers/lcd/ft80x.h @@ -154,7 +154,7 @@ struct ft80x_eventinfo_s struct sigevent event; /* Describe the way a task is to be notified */ struct sigwork_s work; /* Work for SIGEV_THREAD */ bool enable; /* True: enable notification; false: disable */ - int16_t pid; /* Send the notification to this task */ + pid_t pid; /* Send the notification to this task */ }; /* This structure describes the overall state of the FT80x driver */ diff --git a/drivers/mtd/Kconfig b/drivers/mtd/Kconfig index 3c3d79d80116d..006215bc1dbe6 100644 --- a/drivers/mtd/Kconfig +++ b/drivers/mtd/Kconfig @@ -137,13 +137,6 @@ config MTD_PROGMEM interfaces must be exported by chip-specific logic. if MTD_PROGMEM - -config MTD_PROGMEM_ERASESTATE - bool "Enable FLASH MTD device erasestate" - depends on ARCH_HAVE_PROGMEM_ERASESTATE - ---help--- - Enable the ioctl MTDIOCTL_PROGMEM_ERASESTATE command in the on-chip - FLASH interface. endif #MTD_PROGMEM diff --git a/drivers/mtd/mtd_progmem.c b/drivers/mtd/mtd_progmem.c index 3ecb920046124..48e18fd361bda 100644 --- a/drivers/mtd/mtd_progmem.c +++ b/drivers/mtd/mtd_progmem.c @@ -367,7 +367,6 @@ static int progmem_ioctl(FAR struct mtd_dev_s *dev, int cmd, } break; -#ifdef CONFIG_MTD_PROGMEM_ERASESTATE case MTDIOC_ERASESTATE: { FAR uint8_t *result = (FAR uint8_t *)arg; @@ -377,8 +376,6 @@ static int progmem_ioctl(FAR struct mtd_dev_s *dev, int cmd, } break; -#endif /* CONFIG_ARCH_PROGMEM_ERASESTATE */ - default: ret = -ENOTTY; /* Bad command */ break; diff --git a/drivers/net/phy_notify.c b/drivers/net/phy_notify.c index 35b13ebea0136..9f9f0bfc69c57 100644 --- a/drivers/net/phy_notify.c +++ b/drivers/net/phy_notify.c @@ -162,7 +162,7 @@ static FAR struct phy_notify_s *phy_find_unassigned(void) client->assigned = true; client->intf[0] = '\0'; - client->pid = -1; + client->pid = INVALID_PROCESS_ID; client->enable = NULL; /* Return the client entry assigned to the caller */ @@ -388,7 +388,7 @@ int phy_notify_unsubscribe(FAR const char *intf, pid_t pid) client->assigned = false; client->intf[0] = '\0'; - client->pid = -1; + client->pid = INVALID_PROCESS_ID; phy_semgive(); } diff --git a/drivers/net/slip.c b/drivers/net/slip.c index a4c46089293fc..f1b492d4e6a90 100644 --- a/drivers/net/slip.c +++ b/drivers/net/slip.c @@ -1013,30 +1013,34 @@ int slip_initialize(int intf, FAR const char *devname) argv[0] = buffer; argv[1] = NULL; - priv->rxpid = kthread_create("rxslip", CONFIG_NET_SLIP_DEFPRIO, - CONFIG_NET_SLIP_STACKSIZE, slip_rxtask, - (FAR char * const *)argv); - if (priv->rxpid < 0) + ret = kthread_create("rxslip", CONFIG_NET_SLIP_DEFPRIO, + CONFIG_NET_SLIP_STACKSIZE, slip_rxtask, + (FAR char * const *)argv); + if (ret < 0) { nerr("ERROR: Failed to start receiver task\n"); - return priv->rxpid; + return ret; } + priv->rxpid = (pid_t)ret; + /* Wait and make sure that the receive task is started. */ slip_forcetake(priv); /* Start the SLIP transmitter kernel thread */ - priv->txpid = kthread_create("txslip", CONFIG_NET_SLIP_DEFPRIO, - CONFIG_NET_SLIP_STACKSIZE, slip_txtask, - (FAR char * const *)argv); - if (priv->txpid < 0) + ret = kthread_create("txslip", CONFIG_NET_SLIP_DEFPRIO, + CONFIG_NET_SLIP_STACKSIZE, slip_txtask, + (FAR char * const *)argv); + if (ret < 0) { nerr("ERROR: Failed to start receiver task\n"); - return priv->txpid; + return ret; } + priv->txpid = (pid_t)ret; + /* Wait and make sure that the transmit task is started. */ slip_forcetake(priv); diff --git a/drivers/net/telnet.c b/drivers/net/telnet.c index f2bb20bd13ac3..5b7dec309d9ca 100644 --- a/drivers/net/telnet.c +++ b/drivers/net/telnet.c @@ -227,7 +227,7 @@ static const struct file_operations g_factory_fops = * characters received via Telenet (via Ctrl-C SIGINT, in particular). */ -static pid_t g_telnet_io_kthread; +static pid_t g_telnet_io_kthread = INVALID_PROCESS_ID; static struct telnet_dev_s *g_telnet_clients[CONFIG_TELNET_MAXLCLIENTS]; static sem_t g_iosem = SEM_INITIALIZER(0); static sem_t g_clients_sem = SEM_INITIALIZER(1); @@ -1006,7 +1006,7 @@ static int telnet_session(FAR struct telnet_session_s *session) priv->td_pending = 0; priv->td_offset = 0; #ifdef HAVE_SIGNALS - priv->td_pid = -1; + priv->td_pid = INVALID_PROCESS_ID; #endif #ifdef CONFIG_TELNET_SUPPORT_NAWS priv->td_rows = 25; @@ -1092,7 +1092,7 @@ static int telnet_session(FAR struct telnet_session_s *session) /* Has the I/O thread been started? */ - if (g_telnet_io_kthread == (pid_t)0) + if (g_telnet_io_kthread == INVALID_PROCESS_ID) { /* g_iosem is used for signaling and, hence, must not participate in * priority inheritance. @@ -1102,10 +1102,13 @@ static int telnet_session(FAR struct telnet_session_s *session) /* Start the I/O thread */ - g_telnet_io_kthread = - kthread_create("telnet_io", CONFIG_TELNET_IOTHREAD_PRIORITY, - CONFIG_TELNET_IOTHREAD_STACKSIZE, telnet_io_main, - NULL); + ret = kthread_create("telnet_io", CONFIG_TELNET_IOTHREAD_PRIORITY, + CONFIG_TELNET_IOTHREAD_STACKSIZE, telnet_io_main, + NULL); + if (ret > 0) + { + g_telnet_io_kthread = ret; + } } /* Save ourself in the list of Telnet client threads */ diff --git a/drivers/rptun/rptun.c b/drivers/rptun/rptun.c index ad35d0435493f..3186f7c3cf85c 100644 --- a/drivers/rptun/rptun.c +++ b/drivers/rptun/rptun.c @@ -49,7 +49,7 @@ #endif #define RPTUNIOC_NONE 0 -#define NO_HOLDER (pid_t)-1 +#define NO_HOLDER (INVALID_PROCESS_ID) /**************************************************************************** * Private Types @@ -177,7 +177,7 @@ static struct image_store_ops g_rptun_storeops = static sem_t g_rptunlock = SEM_INITIALIZER(1); static pid_t g_holder = NO_HOLDER; -static unsigned int g_count = 0; +static unsigned int g_count; static METAL_DECLARE_LIST(g_rptun_cb); static METAL_DECLARE_LIST(g_rptun_priv); @@ -434,7 +434,7 @@ static void rptun_ns_bind(FAR struct rpmsg_device *rdev, FAR struct rptun_cb_s *cb; bind->dest = dest; - strncpy(bind->name, name, RPMSG_NAME_SIZE); + strlcpy(bind->name, name, RPMSG_NAME_SIZE); rptun_lock(); @@ -919,7 +919,7 @@ int rptun_initialize(FAR struct rptun_dev_s *dev) struct metal_init_params params = METAL_INIT_DEFAULTS; FAR struct rptun_priv_s *priv; FAR char *argv[3]; - char arg1[16]; + char arg1[19]; char name[32]; int ret; @@ -946,23 +946,20 @@ int rptun_initialize(FAR struct rptun_dev_s *dev) nxsem_init(&priv->sem, 0, RPTUN_IS_AUTOSTART(dev) ? 1 : 0); nxsem_set_protocol(&priv->sem, SEM_PRIO_NONE); - snprintf(name, 32, "/dev/rptun/%s", RPTUN_GET_CPUNAME(dev)); + snprintf(name, sizeof(name), "/dev/rptun/%s", RPTUN_GET_CPUNAME(dev)); ret = register_driver(name, &g_rptun_devops, 0222, priv); if (ret < 0) { goto err_driver; } - snprintf(arg1, 16, "0x%" PRIxPTR, (uintptr_t)priv); + snprintf(arg1, sizeof(arg1), "0x%" PRIxPTR, (uintptr_t)priv); argv[0] = (void *)RPTUN_GET_CPUNAME(dev); argv[1] = arg1; argv[2] = NULL; - ret = kthread_create("rptun", - CONFIG_RPTUN_PRIORITY, - CONFIG_RPTUN_STACKSIZE, - rptun_thread, - argv); + ret = kthread_create("rptun", CONFIG_RPTUN_PRIORITY, + CONFIG_RPTUN_STACKSIZE, rptun_thread, argv); if (ret < 0) { goto err_thread; diff --git a/drivers/sensors/fakesensor.c b/drivers/sensors/fakesensor.c index 2860f96fb8770..8631e4dc2a07d 100644 --- a/drivers/sensors/fakesensor.c +++ b/drivers/sensors/fakesensor.c @@ -404,7 +404,8 @@ int fakesensor_init(int type, FAR const char *file_name, argv[0] = arg1; argv[1] = NULL; ret = kthread_create("fakesensor_thread", SCHED_PRIORITY_DEFAULT, - CONFIG_DEFAULT_TASK_STACKSIZE, fakesensor_thread, argv); + CONFIG_DEFAULT_TASK_STACKSIZE, + fakesensor_thread, argv); if (ret < 0) { kmm_free(sensor); diff --git a/drivers/serial/serial.c b/drivers/serial/serial.c index a6bdbf5b2488f..30bc81da2f0c2 100644 --- a/drivers/serial/serial.c +++ b/drivers/serial/serial.c @@ -1428,7 +1428,7 @@ static int uart_ioctl(FAR struct file *filep, int cmd, unsigned long arg) case TIOCNOTTY: { - dev->pid = (pid_t)-1; + dev->pid = INVALID_PROCESS_ID; ret = 0; } break; @@ -1703,7 +1703,7 @@ int uart_register(FAR const char *path, FAR uart_dev_t *dev) #if defined(CONFIG_TTY_SIGINT) || defined(CONFIG_TTY_SIGTSTP) /* Initialize of the task that will receive SIGINT signals. */ - dev->pid = (pid_t)-1; + dev->pid = INVALID_PROCESS_ID; #endif #ifdef CONFIG_SERIAL_TERMIOS diff --git a/drivers/syslog/syslog_device.c b/drivers/syslog/syslog_device.c index 01697f39b9fa6..51d441c9234ab 100644 --- a/drivers/syslog/syslog_device.c +++ b/drivers/syslog/syslog_device.c @@ -57,7 +57,7 @@ /* An invalid thread ID */ -#define NO_HOLDER ((pid_t)-1) +#define NO_HOLDER (INVALID_PROCESS_ID) /**************************************************************************** * Private Types @@ -321,7 +321,7 @@ static int syslog_dev_outputready(FAR struct syslog_dev_s *syslog_dev) /* Cases (4) and (5) */ - if (up_interrupt_context() || getpid() == 0) + if (up_interrupt_context() || sched_idletask()) { return -ENOSYS; } @@ -768,9 +768,9 @@ void syslog_dev_uninitialize(FAR struct syslog_channel_s *channel) * interrupt context. */ - if (up_interrupt_context() || getpid() == 0) + if (up_interrupt_context() || sched_idletask()) { - DEBUGASSERT(!up_interrupt_context() && getpid() != 0); + DEBUGASSERT(!up_interrupt_context() && !sched_idletask()); return; } diff --git a/drivers/usbdev/usbmsc.c b/drivers/usbdev/usbmsc.c index 5c3a3fbf161d3..cd7a683e8a3ee 100644 --- a/drivers/usbdev/usbmsc.c +++ b/drivers/usbdev/usbmsc.c @@ -1689,16 +1689,17 @@ int usbmsc_exportluns(FAR void *handle) g_usbmsc_handoff = priv; uinfo("Starting SCSI worker thread\n"); - priv->thpid = kthread_create("scsid", CONFIG_USBMSC_SCSI_PRIO, - CONFIG_USBMSC_SCSI_STACKSIZE, - usbmsc_scsi_main, NULL); - if (priv->thpid <= 0) + ret = kthread_create("scsid", CONFIG_USBMSC_SCSI_PRIO, + CONFIG_USBMSC_SCSI_STACKSIZE, + usbmsc_scsi_main, NULL); + if (ret < 0) { - usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_THREADCREATE), - (uint16_t)priv->thpid); + usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_THREADCREATE), (uint16_t)ret); goto errout_with_lock; } + priv->thpid = (pid_t)ret; + /* Wait for the worker thread to run and initialize */ uinfo("Waiting for the SCSI worker thread\n"); diff --git a/drivers/usbhost/usbhost_hidkbd.c b/drivers/usbhost/usbhost_hidkbd.c index 84b1862291bc8..c44d3783dc995 100644 --- a/drivers/usbhost/usbhost_hidkbd.c +++ b/drivers/usbhost/usbhost_hidkbd.c @@ -1738,21 +1738,21 @@ static inline int usbhost_devinit(FAR struct usbhost_state_s *priv) g_priv = priv; - priv->pollpid = kthread_create("kbdpoll", CONFIG_HIDKBD_DEFPRIO, - CONFIG_HIDKBD_STACKSIZE, - (main_t)usbhost_kbdpoll, - (FAR char * const *)NULL); - if (priv->pollpid < 0) + ret = kthread_create("kbdpoll", CONFIG_HIDKBD_DEFPRIO, + CONFIG_HIDKBD_STACKSIZE, (main_t)usbhost_kbdpoll, + (FAR char * const *)NULL); + if (ret < 0) { /* Failed to started the poll thread... * probably due to memory resources */ usbhost_givesem(&g_exclsem); - ret = (int)priv->pollpid; goto errout; } + priv->pollpid = (pid_t)ret; + /* Now wait for the poll task to get properly initialized */ ret = usbhost_takesem(&g_syncsem); diff --git a/drivers/usbhost/usbhost_hidmouse.c b/drivers/usbhost/usbhost_hidmouse.c index da4f3c33b640a..84cfa00794462 100644 --- a/drivers/usbhost/usbhost_hidmouse.c +++ b/drivers/usbhost/usbhost_hidmouse.c @@ -1703,21 +1703,21 @@ static inline int usbhost_devinit(FAR struct usbhost_state_s *priv) g_priv = priv; - priv->pollpid = kthread_create("mouse", CONFIG_HIDMOUSE_DEFPRIO, - CONFIG_HIDMOUSE_STACKSIZE, - (main_t)usbhost_mouse_poll, - (FAR char * const *)NULL); - if (priv->pollpid < 0) + ret = kthread_create("mouse", CONFIG_HIDMOUSE_DEFPRIO, + CONFIG_HIDMOUSE_STACKSIZE, (main_t)usbhost_mouse_poll, + (FAR char * const *)NULL); + if (ret < 0) { /* Failed to started the poll thread... * probably due to memory resources */ usbhost_givesem(&g_exclsem); - ret = priv->pollpid; goto errout; } + priv->pollpid = (pid_t)ret; + /* Now wait for the poll task to get properly initialized */ ret = usbhost_takesem(&g_syncsem); diff --git a/drivers/usbhost/usbhost_max3421e.c b/drivers/usbhost/usbhost_max3421e.c index 7261eff0feeb5..30ad9667b115a 100644 --- a/drivers/usbhost/usbhost_max3421e.c +++ b/drivers/usbhost/usbhost_max3421e.c @@ -121,6 +121,8 @@ # define MAX(a, b) (((a) > (b)) ? (a) : (b)) #endif +#define NO_HOLDER (INVALID_PROCESS_ID) + /* Debug ********************************************************************/ #define TR_FMT1 false @@ -1183,7 +1185,7 @@ static void max3421e_give_exclsem(FAR struct max3421e_usbhost_s *priv) { /* No.. give the semaphore */ - priv->holder = (pid_t)-1; + priv->holder = NO_HOLDER; priv->exclcount = 0; max3421e_givesem(&priv->exclsem); } @@ -4800,7 +4802,7 @@ static inline int max3421e_sw_initialize(FAR struct max3421e_usbhost_s *priv, priv->connected = false; priv->irqset = 0; priv->change = false; - priv->holder = (pid_t)-1; + priv->holder = NO_HOLDER; /* Put all of the channels back in their initial, allocated state */ diff --git a/drivers/usbhost/usbhost_xboxcontroller.c b/drivers/usbhost/usbhost_xboxcontroller.c index f7ef5f5b65bb3..87f51418f8db4 100644 --- a/drivers/usbhost/usbhost_xboxcontroller.c +++ b/drivers/usbhost/usbhost_xboxcontroller.c @@ -1404,21 +1404,22 @@ static inline int usbhost_devinit(FAR struct usbhost_state_s *priv) g_priv = priv; uinfo("Starting thread\n"); - priv->pollpid = kthread_create("xbox", CONFIG_XBOXCONTROLLER_DEFPRIO, - CONFIG_XBOXCONTROLLER_STACKSIZE, - (main_t)usbhost_xboxcontroller_poll, - (FAR char * const *)NULL); - if (priv->pollpid < 0) + ret = kthread_create("xbox", CONFIG_XBOXCONTROLLER_DEFPRIO, + CONFIG_XBOXCONTROLLER_STACKSIZE, + (main_t)usbhost_xboxcontroller_poll, + (FAR char * const *)NULL); + if (ret < 0) { /* Failed to started the poll thread... probably due to memory * resources. */ usbhost_givesem(&g_exclsem); - ret = priv->pollpid; goto errout; } + priv->pollpid = (pid_t)ret; + /* Now wait for the poll task to get properly initialized */ usbhost_forcetake(&g_syncsem); diff --git a/drivers/usbmonitor/usbmonitor.c b/drivers/usbmonitor/usbmonitor.c index 209690892d476..22298894dfec7 100644 --- a/drivers/usbmonitor/usbmonitor.c +++ b/drivers/usbmonitor/usbmonitor.c @@ -221,7 +221,7 @@ int usbmonitor_start(void) } else { - g_usbmonitor.pid = ret; + g_usbmonitor.pid = (pid_t)ret; uinfo("Started: %d\n", g_usbmonitor.pid); ret = OK; } diff --git a/drivers/video/vnc/vnc_fbdev.c b/drivers/video/vnc/vnc_fbdev.c index 371b1db8d6fe0..0aa62932fd86e 100644 --- a/drivers/video/vnc/vnc_fbdev.c +++ b/drivers/video/vnc/vnc_fbdev.c @@ -490,7 +490,7 @@ static int vnc_start_server(int display) { FAR char *argv[2]; char str[8]; - pid_t pid; + int ret; DEBUGASSERT(display >= 0 && display < RFB_MAX_DISPLAYS); @@ -515,13 +515,13 @@ static int vnc_start_server(int display) argv[0] = str; argv[1] = NULL; - pid = kthread_create("vnc_server", CONFIG_VNCSERVER_PRIO, + ret = kthread_create("vnc_server", CONFIG_VNCSERVER_PRIO, CONFIG_VNCSERVER_STACKSIZE, (main_t)vnc_server, argv); - if (pid < 0) + if (ret < 0) { - gerr("ERROR: Failed to start the VNC server: %d\n", (int)pid); - return (int)pid; + gerr("ERROR: Failed to start the VNC server: %d\n", ret); + return ret; } return OK; diff --git a/drivers/wireless/bluetooth/bt_uart_shim.c b/drivers/wireless/bluetooth/bt_uart_shim.c index 1c250e4baba61..56707a0cc5dac 100644 --- a/drivers/wireless/bluetooth/bt_uart_shim.c +++ b/drivers/wireless/bluetooth/bt_uart_shim.c @@ -61,7 +61,7 @@ struct hciuart_state_s struct file f; /* File structure */ bool enabled; /* Flag indicating that reception is enabled */ - int serialmontask; /* The receive serial octets task handle */ + pid_t serialmontask; /* The receive serial octets task handle */ }; struct hciuart_config_s @@ -423,10 +423,12 @@ FAR struct btuart_lowerhalf_s *btuart_shim_getdevice(FAR const char *path) argv[0] = arg1; argv[1] = NULL; - s->serialmontask = kthread_create("BT HCI Rx", - CONFIG_BLUETOOTH_TXCONN_PRIORITY, - CONFIG_DEFAULT_TASK_STACKSIZE, - hcicollecttask, argv); + ret = kthread_create("BT HCI Rx", CONFIG_BLUETOOTH_TXCONN_PRIORITY, + CONFIG_DEFAULT_TASK_STACKSIZE, hcicollecttask, argv); + if (ret > 0) + { + s->serialmontask = (pid_t)ret; + } return (FAR struct btuart_lowerhalf_s *)n; } diff --git a/drivers/wireless/ieee80211/bcm43xxx/bcmf_sdio.c b/drivers/wireless/ieee80211/bcm43xxx/bcmf_sdio.c index 9f0d2cc4a5d3c..346861e0de09a 100644 --- a/drivers/wireless/ieee80211/bcm43xxx/bcmf_sdio.c +++ b/drivers/wireless/ieee80211/bcm43xxx/bcmf_sdio.c @@ -781,7 +781,7 @@ int bcmf_bus_sdio_initialize(FAR struct bcmf_dev_s *priv, goto exit_uninit_hw; } - sbus->thread_id = ret; + sbus->thread_id = (pid_t)ret; /* SDIO bus is up and running */ diff --git a/drivers/wireless/ieee80211/bcm43xxx/bcmf_sdio.h b/drivers/wireless/ieee80211/bcm43xxx/bcmf_sdio.h index ac4214919d00f..1eb3db80e8550 100644 --- a/drivers/wireless/ieee80211/bcm43xxx/bcmf_sdio.h +++ b/drivers/wireless/ieee80211/bcm43xxx/bcmf_sdio.h @@ -87,7 +87,7 @@ struct bcmf_sdio_dev_s volatile bool ready; /* Current device status */ bool sleeping; /* Current sleep status */ - int thread_id; /* Processing thread id */ + pid_t thread_id; /* Processing thread id */ sem_t thread_signal; /* Semaphore for processing thread event */ struct wdog_s waitdog; /* Processing thread waitdog */ diff --git a/fs/aio/aio_initialize.c b/fs/aio/aio_initialize.c index 3fa99627b13ae..d2381314063f9 100644 --- a/fs/aio/aio_initialize.c +++ b/fs/aio/aio_initialize.c @@ -49,15 +49,16 @@ static dq_queue_t g_aioc_free; /* This counting semaphore tracks the number of free AIO containers */ -static sem_t g_aioc_freesem; +static sem_t g_aioc_freesem = NXSEM_INITIALIZER(CONFIG_FS_NAIOC, + SEM_PRIO_NONE); /* This binary semaphore supports exclusive access to the list of pending * asynchronous I/O. g_aio_holder and a_aio_count support the reentrant * lock. */ -static sem_t g_aio_exclsem; -static pid_t g_aio_holder; +static sem_t g_aio_exclsem = SEM_INITIALIZER(1); +static pid_t g_aio_holder = INVALID_PROCESS_ID; static uint16_t g_aio_count; /**************************************************************************** @@ -92,19 +93,6 @@ void aio_initialize(void) { int i; - /* Initialize counting semaphores */ - - nxsem_init(&g_aioc_freesem, 0, CONFIG_FS_NAIOC); - nxsem_set_protocol(&g_aioc_freesem, SEM_PRIO_NONE); - nxsem_init(&g_aio_exclsem, 0, 1); - - g_aio_holder = INVALID_PROCESS_ID; - - /* Initialize the container queues */ - - dq_init(&g_aioc_free); - dq_init(&g_aio_pending); - /* Add all of the pre-allocated AIO containers to the free list */ for (i = 0; i < CONFIG_FS_NAIOC; i++) diff --git a/fs/inode/fs_inode.c b/fs/inode/fs_inode.c index 93a05ad07a8a3..a5aa0dbbadb98 100644 --- a/fs/inode/fs_inode.c +++ b/fs/inode/fs_inode.c @@ -37,7 +37,7 @@ * Pre-processor Definitions ****************************************************************************/ -#define NO_HOLDER ((pid_t)-1) +#define NO_HOLDER (INVALID_PROCESS_ID) /**************************************************************************** * Private Types diff --git a/fs/procfs/fs_procfsmeminfo.c b/fs/procfs/fs_procfsmeminfo.c index c53f34e1f55b3..50b3ac40c55ea 100644 --- a/fs/procfs/fs_procfsmeminfo.c +++ b/fs/procfs/fs_procfsmeminfo.c @@ -417,7 +417,8 @@ static ssize_t memdump_read(FAR struct file *filep, FAR char *buffer, #ifdef CONFIG_DEBUG_MM linesize = procfs_snprintf(procfile->line, MEMINFO_LINELEN, - "usage: \n" + "usage: \n" + "on/off backtrace\n" "pid: dump pid allocated node\n"); #else linesize = procfs_snprintf(procfile->line, MEMINFO_LINELEN, @@ -448,9 +449,9 @@ static ssize_t memdump_read(FAR struct file *filep, FAR char *buffer, static ssize_t memdump_write(FAR struct file *filep, FAR const char *buffer, size_t buflen) { - FAR const struct procfs_meminfo_entry_s *entry; + FAR struct procfs_meminfo_entry_s *entry; FAR struct meminfo_file_s *procfile; - pid_t pid = -1; + pid_t pid = INVALID_PROCESS_ID; DEBUGASSERT(filep != NULL && buffer != NULL && buflen > 0); @@ -459,14 +460,35 @@ static ssize_t memdump_write(FAR struct file *filep, FAR const char *buffer, procfile = filep->f_priv; DEBUGASSERT(procfile); +#ifdef CONFIG_DEBUG_MM + if (strcmp(buffer, "on") == 0) + { + for (entry = g_procfs_meminfo; entry != NULL; entry = entry->next) + { + entry->backtrace = true; + } + + return buflen; + } + else if (strcmp(buffer, "off") == 0) + { + for (entry = g_procfs_meminfo; entry != NULL; entry = entry->next) + { + entry->backtrace = false; + } + + return buflen; + } +#endif + switch (buffer[0]) { case 'u': - pid = -1; + pid = (pid_t)-1; break; case 'f': - pid = -2; + pid = (pid_t)-2; break; #ifdef CONFIG_DEBUG_MM default: diff --git a/fs/romfs/fs_romfsutil.c b/fs/romfs/fs_romfsutil.c index 2c2712c0324a8..a5c5ce34cea31 100644 --- a/fs/romfs/fs_romfsutil.c +++ b/fs/romfs/fs_romfsutil.c @@ -108,44 +108,37 @@ static inline int romfs_checkentry(FAR struct romfs_mountpt_s *rm, return ret; } - /* Now we are pointing to the real entry of interest. Is it a - * directory? Or a file? + /* Get the name of the directory entry. */ + + ret = romfs_parsefilename(rm, offset, name); + if (ret < 0) + { + return ret; + } + + /* Then check if this the name segment we are looking for. The + * string comparison is awkward because there is no terminator + * on entryname (there is a terminator on name, however) */ - if (IS_DIRECTORY(next) || IS_FILE(next)) + if (strlen(name) == entrylen && + memcmp(entryname, name, entrylen) == 0) { - /* Get the name of the directory entry. */ + /* Found it -- save the component info and return success */ - ret = romfs_parsefilename(rm, offset, name); - if (ret < 0) + if (IS_DIRECTORY(next)) { - return ret; + nodeinfo->rn_offset = info; + nodeinfo->rn_size = 0; } - - /* Then check if this the name segment we are looking for. The - * string comparison is awkward because there is no terminator - * on entryname (there is a terminator on name, however) - */ - - if (memcmp(entryname, name, entrylen) == 0 && - strlen(name) == entrylen) + else { - /* Found it -- save the component info and return success */ - - if (IS_DIRECTORY(next)) - { - nodeinfo->rn_offset = info; - nodeinfo->rn_size = 0; - } - else - { - nodeinfo->rn_offset = linkoffset; - nodeinfo->rn_size = size; - } - - nodeinfo->rn_next = next; - return OK; + nodeinfo->rn_offset = linkoffset; + nodeinfo->rn_size = size; } + + nodeinfo->rn_next = next; + return OK; } /* The entry is not a directory or it does not have the matching name */ @@ -321,7 +314,7 @@ static inline int romfs_searchdir(FAR struct romfs_mountpt_s *rm, FAR struct romfs_nodeinfo_s **cnodeinfo; cnodeinfo = bsearch(entryname, nodeinfo->rn_child, nodeinfo->rn_count, - sizeof(FAR struct romfs_nodeinfo_s *), + sizeof(struct romfs_nodeinfo_s *), romfs_nodeinfo_search); if (cnodeinfo) { @@ -436,51 +429,44 @@ static int romfs_cachenode(FAR struct romfs_mountpt_s *rm, return ret; } - /* Now we are pointing to the real entry of interest. Is it a - * directory? Or a file? - */ + ret = romfs_parsefilename(rm, offset, childname); + if (ret < 0) + { + return ret; + } - if (IS_DIRECTORY(next) || IS_FILE(next)) + if (strcmp(childname, ".") != 0 && strcmp(childname, "..") != 0) { - ret = romfs_parsefilename(rm, offset, childname); - if (ret < 0) + if (child == NULL || nodeinfo->rn_count == num - 1) { - return ret; - } + FAR void *tmp; - if (strcmp(childname, ".") != 0 && strcmp(childname, "..") != 0) - { - if (child == NULL || nodeinfo->rn_count == num - 1) + tmp = kmm_realloc(nodeinfo->rn_child, + (num + NODEINFO_NINCR) * + sizeof(struct romfs_nodeinfo_s *)); + if (tmp == NULL) { - FAR void *tmp; - - tmp = kmm_realloc(nodeinfo->rn_child, - (num + NODEINFO_NINCR) * - sizeof(FAR struct romfs_nodeinfo_s *)); - if (tmp == NULL) - { - return -ENOMEM; - } - - nodeinfo->rn_child = tmp; - memset(nodeinfo->rn_child + num, 0, NODEINFO_NINCR * - sizeof(FAR struct romfs_nodeinfo_s *)); - num += NODEINFO_NINCR; + return -ENOMEM; } - child = &nodeinfo->rn_child[nodeinfo->rn_count++]; - if (IS_DIRECTORY(next)) - { - linkoffset = info; - } + nodeinfo->rn_child = tmp; + memset(nodeinfo->rn_child + num, 0, NODEINFO_NINCR * + sizeof(struct romfs_nodeinfo_s *)); + num += NODEINFO_NINCR; + } - ret = romfs_cachenode(rm, linkoffset, next, size, - childname, child); - if (ret < 0) - { - nodeinfo->rn_count--; - return ret; - } + child = &nodeinfo->rn_child[nodeinfo->rn_count++]; + if (IS_DIRECTORY(next)) + { + linkoffset = info; + } + + ret = romfs_cachenode(rm, linkoffset, next, size, + childname, child); + if (ret < 0) + { + nodeinfo->rn_count--; + return ret; } } @@ -492,7 +478,7 @@ static int romfs_cachenode(FAR struct romfs_mountpt_s *rm, if (nodeinfo->rn_count > 1) { qsort(nodeinfo->rn_child, nodeinfo->rn_count, - sizeof(FAR struct romfs_nodeinfo_s *), + sizeof(struct romfs_nodeinfo_s *), romfs_nodeinfo_compare); } diff --git a/fs/rpmsgfs/rpmsgfs_client.c b/fs/rpmsgfs/rpmsgfs_client.c index 855d532d2f3fe..29a1dd02dac37 100644 --- a/fs/rpmsgfs/rpmsgfs_client.c +++ b/fs/rpmsgfs/rpmsgfs_client.c @@ -726,11 +726,14 @@ int rpmsgfs_client_rename(FAR void *handle, FAR const char *oldpath, struct rpmsgfs_rename_s *msg; size_t len; size_t oldlen; + size_t newlen; + size_t alignlen; uint32_t space; - len = sizeof(*msg); - oldlen = (strlen(oldpath) + 1 + 0x7) & ~0x7; - len += oldlen + strlen(newpath) + 1; + oldlen = strlen(oldpath) + 1; + alignlen = (oldlen + 0x7) & ~0x7; + newlen = strlen(newpath) + 1; + len = sizeof(*msg) + alignlen + newlen; msg = rpmsg_get_tx_payload_buffer(&priv->ept, &space, true); if (!msg) @@ -740,8 +743,8 @@ int rpmsgfs_client_rename(FAR void *handle, FAR const char *oldpath, DEBUGASSERT(len <= space); - strcpy(msg->pathname, oldpath); - strcpy(msg->pathname + oldlen, newpath); + memcpy(msg->pathname, oldpath, oldlen); + memcpy(msg->pathname + alignlen, newpath, newlen); return rpmsgfs_send_recv(priv, RPMSGFS_RENAME, false, (struct rpmsgfs_header_s *)msg, len, NULL); diff --git a/fs/spiffs/src/spiffs.h b/fs/spiffs/src/spiffs.h index 4a78b2af9a488..bf4b832c70430 100644 --- a/fs/spiffs/src/spiffs.h +++ b/fs/spiffs/src/spiffs.h @@ -70,7 +70,7 @@ extern "C" /* Re-entrant semaphore definitions */ -#define SPIFFS_NO_HOLDER ((pid_t)-1) +#define SPIFFS_NO_HOLDER (INVALID_PROCESS_ID) /**************************************************************************** * Public Types diff --git a/fs/vfs/fs_epoll.c b/fs/vfs/fs_epoll.c index c73731483a324..539fc38312af4 100644 --- a/fs/vfs/fs_epoll.c +++ b/fs/vfs/fs_epoll.c @@ -83,6 +83,16 @@ static const struct file_operations g_epoll_ops = #endif }; +static struct inode g_epoll_inode = +{ + .i_crefs = 1, + .i_flags = FSNODEFLAG_TYPE_DRIVER, + .u = + { + .i_ops = &g_epoll_ops, + }, +}; + /**************************************************************************** * Private Functions ****************************************************************************/ @@ -109,12 +119,12 @@ static FAR struct epoll_head *epoll_head_from_fd(int fd) return NULL; } - return (FAR struct epoll_head *)filep->f_inode->i_private; + return (FAR struct epoll_head *)filep->f_priv; } static int epoll_do_open(FAR struct file *filep) { - FAR struct epoll_head *eph = filep->f_inode->i_private; + FAR struct epoll_head *eph = filep->f_priv; int ret; ret = nxsem_wait(&eph->sem); @@ -130,7 +140,7 @@ static int epoll_do_open(FAR struct file *filep) static int epoll_do_close(FAR struct file *filep) { - FAR struct epoll_head *eph = filep->f_inode->i_private; + FAR struct epoll_head *eph = filep->f_priv; int ret; ret = nxsem_wait(&eph->sem); @@ -187,7 +197,7 @@ static int epoll_do_create(int size, int flags) /* Alloc the file descriptor */ - fd = files_allocate(&eph->in, flags, 0, eph, 0); + fd = files_allocate(&g_epoll_inode, flags, 0, eph, 0); if (fd < 0) { nxsem_destroy(&eph->sem); @@ -196,6 +206,7 @@ static int epoll_do_create(int size, int flags) return -1; } + inode_addref(&g_epoll_inode); nxsem_post(&eph->sem); return fd; } diff --git a/graphics/nxmu/nxmu_start.c b/graphics/nxmu/nxmu_start.c index 271ffe6740c57..5bf224dc4d0af 100644 --- a/graphics/nxmu/nxmu_start.c +++ b/graphics/nxmu/nxmu_start.c @@ -182,7 +182,7 @@ int nxmu_start(int display, int plane) { FAR char display_str[8]; FAR char plane_str[8]; - pid_t server; + int server; FAR char * const argv[3] = { (FAR char * const)display_str, @@ -201,8 +201,8 @@ int nxmu_start(int display, int plane) if (server < 0) { gerr("ERROR: Failed to create nx_server kernel thread: %d\n", - (int)server); - return (int)server; + server); + return server; } g_nxserver_started[display] = true; diff --git a/graphics/nxterm/nxterm.h b/graphics/nxterm/nxterm.h index 45d84d3b34b34..70a25c240c5c0 100644 --- a/graphics/nxterm/nxterm.h +++ b/graphics/nxterm/nxterm.h @@ -54,7 +54,7 @@ /* Semaphore protection */ -#define NO_HOLDER (pid_t)-1 +#define NO_HOLDER (INVALID_PROCESS_ID) /* VT100 escape sequence processing */ diff --git a/include/nuttx/arch.h b/include/nuttx/arch.h index 427307e38e1d4..1d0d8b8688cb0 100644 --- a/include/nuttx/arch.h +++ b/include/nuttx/arch.h @@ -2555,8 +2555,10 @@ void arch_sporadic_resume(FAR struct tcb_s *tcb); * * The second interface simple converts an elapsed time into well known * units. + * ****************************************************************************/ +void up_perf_init(FAR void *arg); uint32_t up_perf_gettime(void); uint32_t up_perf_getfreq(void); void up_perf_convert(uint32_t elapsed, FAR struct timespec *ts); diff --git a/include/nuttx/fs/procfs.h b/include/nuttx/fs/procfs.h index b68a2b70502ee..97bd245f08e5c 100644 --- a/include/nuttx/fs/procfs.h +++ b/include/nuttx/fs/procfs.h @@ -133,6 +133,14 @@ struct procfs_meminfo_entry_s FAR const char *name; FAR struct mm_heap_s *heap; struct procfs_meminfo_entry_s *next; +#if defined(CONFIG_DEBUG_MM) + + /* This is dynamic control flag whether to turn on backtrace in the heap, + * you can set it by /proc/memdump. + */ + + bool backtrace; +#endif }; /**************************************************************************** diff --git a/include/nuttx/progmem.h b/include/nuttx/progmem.h index 933d303aa68b3..719b5d4dd7e1f 100644 --- a/include/nuttx/progmem.h +++ b/include/nuttx/progmem.h @@ -242,9 +242,7 @@ ssize_t up_progmem_read(size_t addr, FAR void *buf, size_t count); * ****************************************************************************/ -#ifdef CONFIG_ARCH_HAVE_PROGMEM_ERASESTATE -ssize_t up_progmem_erasestate(void); -#endif /* CONFIG_ARCH_HAVE_PROGMEM_ERASESTATE */ +uint8_t up_progmem_erasestate(void); #undef EXTERN #if defined(__cplusplus) diff --git a/include/nuttx/sched.h b/include/nuttx/sched.h index 2d8395e0b024f..6c383138bdeb9 100644 --- a/include/nuttx/sched.h +++ b/include/nuttx/sched.h @@ -79,7 +79,7 @@ /* Special task IDS. Any negative PID is invalid. */ -#define NULL_TASK_PROCESS_ID (pid_t)0 +#define IDLE_PROCESS_ID (pid_t)0 #define INVALID_PROCESS_ID (pid_t)-1 /* This is the maximum number of times that a lock can be set */ diff --git a/include/sys/random.h b/include/sys/random.h new file mode 100644 index 0000000000000..0e472d2d3ebdf --- /dev/null +++ b/include/sys/random.h @@ -0,0 +1,79 @@ +/**************************************************************************** + * include/sys/random.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __INCLUDE_SYS_RANDOM_H +#define __INCLUDE_SYS_RANDOM_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Flags for getrandom(2) + * + * GRND_NONBLOCK Don't block and return EAGAIN instead + * GRND_RANDOM Open /dev/random instead of /dev/urandom + * GRND_INSECURE Return non-cryptographic random bytes + */ + +#define GRND_NONBLOCK (1 << 0) +#define GRND_RANDOM (1 << 1) +#define GRND_INSECURE (1 << 2) + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: getrandom + * + * Description: + * Fill a buffer of arbitrary length with randomness. This is the + * preferred interface for getting random numbers. The traditional + * /dev/random approach is susceptible for things like the attacker + * exhausting file descriptors on purpose. + * + * Note that this function cannot fail, other than by asserting. + * + * Input Parameters: + * bytes - Buffer for returned random bytes + * nbytes - Number of bytes requested. + * flags - Bit mask that can contain zero or more of the ORed values + * together. + * + * Returned Value: + * On success, getrandom() returns the number of bytes that were copied + * to the buffer bytes. This may be less than the number of bytes + * requested via nbytes if either GRND_RANDOM was specified in flags and + * insufficient entropy was present in the random source or the system + * call was interrupted by a signal. + * + * On error, -1 is returned, and errno is set appropriately. + * + ****************************************************************************/ + +ssize_t getrandom(FAR void *bytes, size_t nbytes, unsigned int flags); + +#endif /* __INCLUDE_SYS_RANDOM_H */ diff --git a/include/unistd.h b/include/unistd.h index b383f205536e4..d2fd98827b26a 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -410,6 +410,8 @@ gid_t getegid(void); int setreuid(uid_t ruid, uid_t euid); int setregid(gid_t rgid, gid_t egid); +int getentropy(FAR void *buffer, size_t length); + #undef EXTERN #if defined(__cplusplus) } diff --git a/libs/libc/machine/risc-v/common/arch_elf.c b/libs/libc/machine/risc-v/common/arch_elf.c index 275b51fb37e60..67c89e41aa8c6 100644 --- a/libs/libc/machine/risc-v/common/arch_elf.c +++ b/libs/libc/machine/risc-v/common/arch_elf.c @@ -343,7 +343,7 @@ int up_relocateadd(FAR const Elf_Rela *rel, FAR const Elf_Sym *sym, addr, _get_val((uint16_t *)addr), sym, sym->st_value); - offset = (long)sym->st_value - (long)addr; + offset = (long)sym->st_value + (long)rel->r_addend - (long)addr; long imm_hi; long imm_lo; @@ -386,7 +386,7 @@ int up_relocateadd(FAR const Elf_Rela *rel, FAR const Elf_Sym *sym, /* P.23 Conditinal Branches : B type (imm=12bit) */ - offset = (long)sym->st_value - (long)addr; + offset = (long)sym->st_value + (long)rel->r_addend - (long)addr; uint32_t val = _get_val((uint16_t *)addr) & 0xfe000f80; /* NOTE: we assume that a compiler adds an immediate value */ @@ -409,7 +409,7 @@ int up_relocateadd(FAR const Elf_Rela *rel, FAR const Elf_Sym *sym, /* P.19 LUI */ - offset = (long)sym->st_value; + offset = (long)sym->st_value + (long)rel->r_addend; uint32_t insn = _get_val((uint16_t *)addr); ASSERT(OPCODE_LUI == (insn & RVI_OPCODE_MASK)); @@ -433,7 +433,7 @@ int up_relocateadd(FAR const Elf_Rela *rel, FAR const Elf_Sym *sym, /* ADDI, FLW, LD, ... : I-type */ - offset = (long)sym->st_value; + offset = (long)sym->st_value + (long)rel->r_addend; uint32_t insn = _get_val((uint16_t *)addr); long imm_hi; @@ -458,7 +458,7 @@ int up_relocateadd(FAR const Elf_Rela *rel, FAR const Elf_Sym *sym, * may not generates these two instructions continuously. */ - offset = (long)sym->st_value; + offset = (long)sym->st_value + (long)rel->r_addend; long imm_hi; long imm_lo; @@ -484,15 +484,11 @@ int up_relocateadd(FAR const Elf_Rela *rel, FAR const Elf_Sym *sym, /* P.111 Table 16.6 : Instruction listings for RVC */ - offset = ((long)sym->st_value - (long)addr); + offset = (long)sym->st_value + (long)rel->r_addend - (long)addr; ASSERT(-2048 <= offset && offset <= 2047); uint16_t val = (*(uint16_t *)addr) & 0x1ffc; - /* NOTE: we assume that a compiler adds an immediate value */ - - ASSERT(offset && val); - binfo("offset for C.J=%ld (0x%lx) (val=0x%04x) already set!\n", offset, offset, val); } @@ -508,7 +504,7 @@ int up_relocateadd(FAR const Elf_Rela *rel, FAR const Elf_Sym *sym, /* P.111 Table 16.6 : Instruction listings for RVC */ - offset = ((long)sym->st_value - (long)addr); + offset = (long)sym->st_value + (long)rel->r_addend - (long)addr; ASSERT(-256 <= offset && offset <= 255); uint16_t val = (*(uint16_t *)addr) & 0x1c7c; @@ -521,7 +517,26 @@ int up_relocateadd(FAR const Elf_Rela *rel, FAR const Elf_Sym *sym, offset, offset, val); } break; - + case R_RISCV_ADD32: + { + *(uint32_t *)addr += (uint32_t)(sym->st_value + rel->r_addend); + } + break; + case R_RISCV_ADD64: + { + *(uint64_t *)addr += (uint64_t)(sym->st_value + rel->r_addend); + } + break; + case R_RISCV_SUB32: + { + *(uint32_t *)addr -= (uint32_t)(sym->st_value + rel->r_addend); + } + break; + case R_RISCV_SUB64: + { + *(uint64_t *)addr -= (uint64_t)(sym->st_value + rel->r_addend); + } + break; default: berr("ERROR: Unsupported relocation: %ld\n", ARCH_ELF_RELTYPE(rel->r_info)); diff --git a/libs/libc/misc/Make.defs b/libs/libc/misc/Make.defs index 5710b7fb42da3..a4c8bc8ce9c88 100644 --- a/libs/libc/misc/Make.defs +++ b/libs/libc/misc/Make.defs @@ -20,7 +20,7 @@ # Add the internal C files to the build -CSRCS += lib_mknod.c lib_umask.c lib_utsname.c +CSRCS += lib_mknod.c lib_umask.c lib_utsname.c lib_getrandom.c CSRCS += lib_xorshift128.c lib_tea_encrypt.c lib_tea_decrypt.c # Support for platforms that do not have long long types diff --git a/libs/libc/misc/lib_getrandom.c b/libs/libc/misc/lib_getrandom.c new file mode 100644 index 0000000000000..42a17bdf80d1a --- /dev/null +++ b/libs/libc/misc/lib_getrandom.c @@ -0,0 +1,91 @@ +/**************************************************************************** + * libs/libc/misc/lib_getrandom.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: getrandom + * + * Description: + * Fill a buffer of arbitrary length with randomness. This is the + * preferred interface for getting random numbers. The traditional + * /dev/random approach is susceptible for things like the attacker + * exhausting file descriptors on purpose. + * + * Note that this function cannot fail, other than by asserting. + * + * Input Parameters: + * bytes - Buffer for returned random bytes + * nbytes - Number of bytes requested. + * flags - Bit mask that can contain zero or more of the ORed values + * together. + * + * Returned Value: + * On success, getrandom() returns the number of bytes that were copied + * to the buffer bytes. This may be less than the number of bytes + * requested via nbytes if either GRND_RANDOM was specified in flags and + * insufficient entropy was present in the random source or the system + * call was interrupted by a signal. + * + * On error, -1 is returned, and errno is set appropriately. + * + ****************************************************************************/ + +ssize_t getrandom(FAR void *bytes, size_t nbytes, unsigned int flags) +{ + int oflags = O_RDONLY; + FAR const char *dev; + int fd; + + if ((flags & GRND_NONBLOCK) != 0) + { + oflags |= O_NONBLOCK; + } + + if ((flags & GRND_RANDOM) != 0) + { + dev = "/dev/random"; + } + else + { + dev = "/dev/urandom"; + } + + fd = open(dev, oflags); + if (fd < 0) + { + return fd; + } + + nbytes = read(fd, bytes, nbytes); + close(fd); + + return nbytes; +} diff --git a/libs/libc/modlib/modlib_registry.c b/libs/libc/modlib/modlib_registry.c index 850242f03e244..53e4e221388ee 100644 --- a/libs/libc/modlib/modlib_registry.c +++ b/libs/libc/modlib/modlib_registry.c @@ -36,7 +36,7 @@ * Pre-processor Definitions ****************************************************************************/ -#define NO_HOLDER ((pid_t)-1) +#define NO_HOLDER (INVALID_PROCESS_ID) /**************************************************************************** * Private Types diff --git a/libs/libc/sched/sched_dumpstack.c b/libs/libc/sched/sched_dumpstack.c index c504c1106ce6a..6ac50835fae0d 100644 --- a/libs/libc/sched/sched_dumpstack.c +++ b/libs/libc/sched/sched_dumpstack.c @@ -84,7 +84,11 @@ void sched_dumpstack(pid_t tid) } } #else - syslog(LOG_EMERG, "backtrace:\n"); + if (skip == 0) + { + syslog(LOG_EMERG, "backtrace:\n"); + } + for (i = 0; i < size; i++) { syslog(LOG_EMERG, "[%2d] [<%p>] %pS\n", diff --git a/libs/libc/time/lib_strftime.c b/libs/libc/time/lib_strftime.c index d30d380b75ba6..352b970ab20b1 100644 --- a/libs/libc/time/lib_strftime.c +++ b/libs/libc/time/lib_strftime.c @@ -99,6 +99,8 @@ static const char * const g_monthname[12] = * ter, and terminated by a conversion specifier character, and are * replaced in s as follows: * + * %a The abbreviated weekday name according to the current locale. + * %A The full weekday name according to the current locale. * %b The abbreviated month name according to the current locale. * %B The full month name according to the current locale. * %C The century number (year/100) as a 2-digit integer. (SU) @@ -221,16 +223,6 @@ size_t strftime(FAR char *s, size_t max, FAR const char *format, } break; - /* %y: The year as a decimal number without a century - * (range 00 to 99). - */ - - case 'y': - { - len = snprintf(dest, chleft, "%02d", tm->tm_year % 100); - } - break; - /* %C: The century number (year/100) as a 2-digit integer. */ case 'C': @@ -406,6 +398,16 @@ size_t strftime(FAR char *s, size_t max, FAR const char *format, } break; + /* %y: The year as a decimal number without a century + * (range 00 to 99). + */ + + case 'y': + { + len = snprintf(dest, chleft, "%02d", tm->tm_year % 100); + } + break; + /* %Y: The year as a decimal number including the century. */ case 'Y': diff --git a/libs/libc/unistd/Make.defs b/libs/libc/unistd/Make.defs index 6a561bec51380..35e9e6d5ec0f8 100644 --- a/libs/libc/unistd/Make.defs +++ b/libs/libc/unistd/Make.defs @@ -21,7 +21,7 @@ # Add the unistd C files to the build CSRCS += lib_access.c lib_daemon.c lib_swab.c lib_pathconf.c lib_sysconf.c -CSRCS += lib_getopt_common.c lib_getopt.c lib_getopt_long.c +CSRCS += lib_getentropy.c lib_getopt_common.c lib_getopt.c lib_getopt_long.c CSRCS += lib_getopt_longonly.c lib_getoptvars.c lib_getoptargp.c CSRCS += lib_getopterrp.c lib_getoptindp.c lib_getoptoptp.c lib_times.c CSRCS += lib_alarm.c lib_fstatvfs.c lib_statvfs.c lib_sleep.c lib_nice.c diff --git a/libs/libc/unistd/lib_getentropy.c b/libs/libc/unistd/lib_getentropy.c new file mode 100644 index 0000000000000..b47a646a50fc1 --- /dev/null +++ b/libs/libc/unistd/lib_getentropy.c @@ -0,0 +1,83 @@ +/**************************************************************************** + * libs/libc/unistd/lib_getentropy.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: getentropy + * + * Description: + * The getentropy() function writes length bytes of high-quality + * random data to the buffer starting at the location pointed to by + * buffer. The maximum permitted value for the length argument is + * 256. + * + * A successful call to getentropy() always provides the requested + * number of bytes of entropy. + * + * Input Parameters: + * buffer - Buffer for returned random bytes + * length - Number of bytes requested. + * + * Returned Value: + * On success, this function returns zero. On error, -1 is + * returned, and errno is set to indicate the error. + * + ****************************************************************************/ + +int getentropy(FAR void *buffer, size_t length) +{ + FAR char *pos = buffer; + + if (length > 256) + { + errno = EIO; + return -1; + } + + while (length > 0) + { + int ret = getrandom(pos, length, 0); + if (ret < 0) + { + if (errno == EINTR) + { + continue; + } + + return ret; + } + + pos += ret; + length -= ret; + } + + return 0; +} diff --git a/libs/libc/uuid/lib_uuid_create.c b/libs/libc/uuid/lib_uuid_create.c index d2af6e0ca0fea..42eae004ebe03 100644 --- a/libs/libc/uuid/lib_uuid_create.c +++ b/libs/libc/uuid/lib_uuid_create.c @@ -22,9 +22,39 @@ * Included Files ****************************************************************************/ +#include +#include #include #include +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +static int uuid_getrandom(FAR void *buf, size_t size, int flags) +{ + FAR char *tmp = buf; + + while (size > 0) + { + ssize_t ret = getrandom(tmp, size, flags); + if (ret < 0) + { + if (errno == EINTR) + { + continue; + } + + return ret; + } + + tmp += ret; + size -= ret; + } + + return 0; +} + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -42,17 +72,24 @@ void uuid_create(uuid_t *u, uint32_t *status) { -#ifdef CONFIG_CRYPTO_RANDOM_POOL - arc4random_buf(u, sizeof(uuid_t)); -#else - unsigned long *beg = (unsigned long *)u; - unsigned long *end = (unsigned long *)(u + 1); + int ret; - while (beg < end) + ret = uuid_getrandom(u, sizeof(uuid_t), 0); + if (ret < 0) { - *beg++ = rand(); + ret = uuid_getrandom(u, sizeof(uuid_t), GRND_RANDOM); + } + + if (ret < 0) + { + unsigned long *beg = (unsigned long *)u; + unsigned long *end = (unsigned long *)(u + 1); + + while (beg < end) + { + *beg++ = rand(); + } } -#endif u->clock_seq_hi_and_reserved &= ~(1 << 6); u->clock_seq_hi_and_reserved |= (1 << 7); diff --git a/libs/libxx/Kconfig b/libs/libxx/Kconfig index 693c871dd2f60..29a33626ed514 100644 --- a/libs/libxx/Kconfig +++ b/libs/libxx/Kconfig @@ -83,6 +83,9 @@ config HAVE_CXXINITIALIZE config CXX_EXCEPTION bool "Enable Exception Support" +config CXX_RTTI + bool "Enable RTTI Support" + if UCLIBCXX config UCLIBCXX_BUFSIZE diff --git a/mm/Kconfig b/mm/Kconfig index 8746a201dcc04..c4f506aedd9e3 100644 --- a/mm/Kconfig +++ b/mm/Kconfig @@ -186,4 +186,9 @@ config MM_KASAN bugs in native code. After turn on this option, Please add -fsanitize=kernel-address to CFLAGS/CXXFLAGS too. +config MM_BACKTRACE_DEFAULT + bool "Enable the backtrace record by default" + default n + depends on DEBUG_MM + source "mm/iob/Kconfig" diff --git a/mm/mm_heap/mm.h b/mm/mm_heap/mm.h index 6f442dbc69540..af89268a50faa 100644 --- a/mm/mm_heap/mm.h +++ b/mm/mm_heap/mm.h @@ -93,17 +93,24 @@ #ifdef CONFIG_DEBUG_MM # define MM_MIN_SHIFT (MM_MIN_SHIFT_ + 2) # define MM_BACKTRACE_DEPTH 8 -# define MM_ADD_BACKTRACE(ptr) \ +# define MM_ADD_BACKTRACE(heap, ptr) \ do \ { \ FAR struct mm_allocnode_s *tmp = (FAR struct mm_allocnode_s *)(ptr); \ tmp->pid = getpid(); \ - memset(tmp->backtrace, 0, sizeof(tmp->backtrace)); \ - backtrace(tmp->backtrace, MM_BACKTRACE_DEPTH); \ + if ((heap)->mm_procfs.backtrace) \ + { \ + memset(tmp->backtrace, 0, sizeof(tmp->backtrace)); \ + backtrace(tmp->backtrace, MM_BACKTRACE_DEPTH); \ + } \ + else \ + { \ + tmp->backtrace[0] = 0; \ + } \ } \ while (0) #else -# define MM_ADD_BACKTRACE(ptr) +# define MM_ADD_BACKTRACE(heap, ptr) # define MM_MIN_SHIFT MM_MIN_SHIFT_ #endif @@ -160,7 +167,7 @@ typedef uint32_t mmsize_t; struct mm_allocnode_s { #ifdef CONFIG_DEBUG_MM - uint32_t pid; /* The pid for caller */ + pid_t pid; /* The pid for caller */ FAR void *backtrace[MM_BACKTRACE_DEPTH]; /* The backtrace buffer for caller */ #endif mmsize_t size; /* Size of this chunk */ @@ -175,7 +182,7 @@ static_assert(SIZEOF_MM_ALLOCNODE <= MM_MIN_CHUNK, struct mm_freenode_s { #ifdef CONFIG_DEBUG_MM - uint32_t pid; /* The pid for caller */ + pid_t pid; /* The pid for caller */ FAR void *backtrace[MM_BACKTRACE_DEPTH]; /* The backtrace buffer for caller */ #endif mmsize_t size; /* Size of this chunk */ diff --git a/mm/mm_heap/mm_initialize.c b/mm/mm_heap/mm_initialize.c index d13c45cd3ad82..e32c63cdac95c 100644 --- a/mm/mm_heap/mm_initialize.c +++ b/mm/mm_heap/mm_initialize.c @@ -117,7 +117,7 @@ void mm_addregion(FAR struct mm_heap_s *heap, FAR void *heapstart, heap->mm_heapstart[IDX] = (FAR struct mm_allocnode_s *) heapbase; - MM_ADD_BACKTRACE(heap->mm_heapstart[IDX]); + MM_ADD_BACKTRACE(heap, heap->mm_heapstart[IDX]); heap->mm_heapstart[IDX]->size = SIZEOF_MM_ALLOCNODE; heap->mm_heapstart[IDX]->preceding = MM_ALLOC_BIT; node = (FAR struct mm_freenode_s *) @@ -128,7 +128,7 @@ void mm_addregion(FAR struct mm_heap_s *heap, FAR void *heapstart, (heapend - SIZEOF_MM_ALLOCNODE); heap->mm_heapend[IDX]->size = SIZEOF_MM_ALLOCNODE; heap->mm_heapend[IDX]->preceding = node->size | MM_ALLOC_BIT; - MM_ADD_BACKTRACE(heap->mm_heapend[IDX]); + MM_ADD_BACKTRACE(heap, heap->mm_heapend[IDX]); #undef IDX @@ -213,6 +213,9 @@ FAR struct mm_heap_s *mm_initialize(FAR const char *name, #if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__) heap->mm_procfs.name = name; heap->mm_procfs.heap = heap; +#if defined (CONFIG_DEBUG_MM) && defined(CONFIG_MM_BACKTRACE_DEFAULT) + heap->mm_procfs.backtrace = true; +#endif procfs_register_meminfo(&heap->mm_procfs); #endif #endif diff --git a/mm/mm_heap/mm_malloc.c b/mm/mm_heap/mm_malloc.c index d392c2aaa1a46..135e1f3f1cce1 100644 --- a/mm/mm_heap/mm_malloc.c +++ b/mm/mm_heap/mm_malloc.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -223,7 +224,7 @@ FAR void *mm_malloc(FAR struct mm_heap_s *heap, size_t size) /* Handle the case of an exact size match */ node->preceding |= MM_ALLOC_BIT; - MM_ADD_BACKTRACE(node); + MM_ADD_BACKTRACE(heap, node); ret = (FAR void *)((FAR char *)node + SIZEOF_MM_ALLOCNODE); } @@ -243,7 +244,13 @@ FAR void *mm_malloc(FAR struct mm_heap_s *heap, size_t size) #ifdef CONFIG_DEBUG_MM else { + struct mallinfo minfo; + mwarn("WARNING: Allocation failed, size %zu\n", alignsize); + mm_mallinfo(heap, &minfo); + mwarn("Total:%d, used:%d, free:%d, largest:%d, nused:%d, nfree:%d\n", + minfo.arena, minfo.uordblks, minfo.fordblks, + minfo.mxordblk, minfo.aordblks, minfo.ordblks); mm_memdump(heap, -1); DEBUGASSERT(false); } diff --git a/mm/mm_heap/mm_memalign.c b/mm/mm_heap/mm_memalign.c index 0fa3968a6860b..d3681dd79da9b 100644 --- a/mm/mm_heap/mm_memalign.c +++ b/mm/mm_heap/mm_memalign.c @@ -178,7 +178,7 @@ FAR void *mm_memalign(FAR struct mm_heap_s *heap, size_t alignment, newnode->size = (size_t)next - (size_t)newnode; newnode->preceding = precedingsize | MM_ALLOC_BIT; - MM_ADD_BACKTRACE(newnode); + MM_ADD_BACKTRACE(heap, newnode); /* Reduce the size of the original chunk and mark it not allocated, */ diff --git a/mm/mm_heap/mm_realloc.c b/mm/mm_heap/mm_realloc.c index 366cbfef681a0..7b9abe8b7afa5 100644 --- a/mm/mm_heap/mm_realloc.c +++ b/mm/mm_heap/mm_realloc.c @@ -128,7 +128,7 @@ FAR void *mm_realloc(FAR struct mm_heap_s *heap, FAR void *oldmem, oldsize - oldnode->size); } - MM_ADD_BACKTRACE(oldnode); + MM_ADD_BACKTRACE(heap, oldnode); /* Then return the original address */ @@ -334,7 +334,7 @@ FAR void *mm_realloc(FAR struct mm_heap_s *heap, FAR void *oldmem, } } - MM_ADD_BACKTRACE((FAR char *)newmem - SIZEOF_MM_ALLOCNODE); + MM_ADD_BACKTRACE(heap, (FAR char *)newmem - SIZEOF_MM_ALLOCNODE); mm_givesemaphore(heap); diff --git a/net/route/net_fileroute.c b/net/route/net_fileroute.c index e9ff85a21286c..5349979b53f08 100644 --- a/net/route/net_fileroute.c +++ b/net/route/net_fileroute.c @@ -47,7 +47,7 @@ * of the lock. */ -#define NO_HOLDER ((pid_t)-1) +#define NO_HOLDER (INVALID_PROCESS_ID) /**************************************************************************** * Private Data diff --git a/net/rpmsg/rpmsg_sockif.c b/net/rpmsg/rpmsg_sockif.c index b6bd3b9376235..822fb74f37226 100644 --- a/net/rpmsg/rpmsg_sockif.c +++ b/net/rpmsg/rpmsg_sockif.c @@ -376,7 +376,7 @@ static int rpmsg_socket_ept_cb(FAR struct rpmsg_endpoint *ept, written = circbuf_write(&conn->recvbuf, buf, len); if (written != len) { - nerr("circbuf_write overflow, %d, %d\n", written, len); + nerr("circbuf_write overflow, %zu, %zu\n", written, len); } rpmsg_socket_pollnotify(conn, POLLIN); diff --git a/net/utils/net_lock.c b/net/utils/net_lock.c index db2af19a37b60..8d634cbaa45eb 100644 --- a/net/utils/net_lock.c +++ b/net/utils/net_lock.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include @@ -43,7 +44,7 @@ * Pre-processor Definitions ****************************************************************************/ -#define NO_HOLDER (pid_t)-1 +#define NO_HOLDER (INVALID_PROCESS_ID) /**************************************************************************** * Private Data diff --git a/sched/mqueue/mq_notify.c b/sched/mqueue/mq_notify.c index fb0d245808733..021fa41402ef2 100644 --- a/sched/mqueue/mq_notify.c +++ b/sched/mqueue/mq_notify.c @@ -157,7 +157,7 @@ int mq_notify(mqd_t mqdes, FAR const struct sigevent *notification) * Is it trying to remove it? */ - else if ((msgq->ntpid != rtcb->pid) || (notification)) + else if ((msgq->ntpid != rtcb->pid) || (notification != NULL)) { /* This thread does not own the notification OR it is * not trying to remove it. Return EBUSY. diff --git a/sched/pthread/pthread_cancel.c b/sched/pthread/pthread_cancel.c index 469847ae17cd4..9965706517f76 100644 --- a/sched/pthread/pthread_cancel.c +++ b/sched/pthread/pthread_cancel.c @@ -47,7 +47,7 @@ int pthread_cancel(pthread_t thread) /* First, make sure that the handle references a valid thread */ - if (thread == 0) + if ((pid_t)thread == IDLE_PROCESS_ID) { /* pid == 0 is the IDLE task (in a single CPU configuration). Callers * cannot cancel the IDLE task. diff --git a/sched/pthread/pthread_condclockwait.c b/sched/pthread/pthread_condclockwait.c index 8bc046ef0ef40..50995af933a16 100644 --- a/sched/pthread/pthread_condclockwait.c +++ b/sched/pthread/pthread_condclockwait.c @@ -243,7 +243,7 @@ int pthread_cond_clockwait(FAR pthread_cond_t *cond, #endif /* Give up the mutex */ - mutex->pid = -1; + mutex->pid = INVALID_PROCESS_ID; #ifndef CONFIG_PTHREAD_MUTEX_UNSAFE mflags = mutex->flags; #endif diff --git a/sched/pthread/pthread_condwait.c b/sched/pthread/pthread_condwait.c index ad3e7076218b9..2ec4b9909f180 100644 --- a/sched/pthread/pthread_condwait.c +++ b/sched/pthread/pthread_condwait.c @@ -93,7 +93,7 @@ int pthread_cond_wait(FAR pthread_cond_t *cond, FAR pthread_mutex_t *mutex) sinfo("Give up mutex / take cond\n"); sched_lock(); - mutex->pid = -1; + mutex->pid = INVALID_PROCESS_ID; #ifndef CONFIG_PTHREAD_MUTEX_UNSAFE mflags = mutex->flags; #endif diff --git a/sched/pthread/pthread_create.c b/sched/pthread/pthread_create.c index 2e64bf4a68cc4..ea73f11b68f51 100644 --- a/sched/pthread/pthread_create.c +++ b/sched/pthread/pthread_create.c @@ -526,7 +526,7 @@ int nx_pthread_create(pthread_trampoline_t trampoline, FAR pthread_t *thread, * as well. */ - pid = (int)ptcb->cmn.pid; + pid = ptcb->cmn.pid; pjoin->thread = (pthread_t)pid; /* Initialize the semaphores in the join structure to zero. */ diff --git a/sched/pthread/pthread_mutexconsistent.c b/sched/pthread/pthread_mutexconsistent.c index 48fb5f52a01e9..f910510260bad 100644 --- a/sched/pthread/pthread_mutexconsistent.c +++ b/sched/pthread/pthread_mutexconsistent.c @@ -105,7 +105,7 @@ int pthread_mutex_consistent(FAR pthread_mutex_t *mutex) { /* The thread associated with the PID no longer exists */ - mutex->pid = -1; + mutex->pid = INVALID_PROCESS_ID; mutex->flags &= _PTHREAD_MFLAGS_ROBUST; #ifdef CONFIG_PTHREAD_MUTEX_TYPES mutex->nlocks = 0; diff --git a/sched/pthread/pthread_mutexdestroy.c b/sched/pthread/pthread_mutexdestroy.c index a6d9f9efd4cba..354d5fdcdf8cb 100644 --- a/sched/pthread/pthread_mutexdestroy.c +++ b/sched/pthread/pthread_mutexdestroy.c @@ -94,7 +94,7 @@ int pthread_mutex_destroy(FAR pthread_mutex_t *mutex) { /* The thread associated with the PID no longer exists */ - mutex->pid = -1; + mutex->pid = INVALID_PROCESS_ID; /* Reset the semaphore. If threads are were on this * semaphore, then this will awakened them and make @@ -111,7 +111,7 @@ int pthread_mutex_destroy(FAR pthread_mutex_t *mutex) * mutex. */ - else if (mutex->pid != -1) + else if (mutex->pid != INVALID_PROCESS_ID) { /* Yes.. then we cannot destroy the mutex now. */ diff --git a/sched/pthread/pthread_mutexinit.c b/sched/pthread/pthread_mutexinit.c index fc69f630a0e33..95da3f46852f4 100644 --- a/sched/pthread/pthread_mutexinit.c +++ b/sched/pthread/pthread_mutexinit.c @@ -103,7 +103,7 @@ int pthread_mutex_init(FAR pthread_mutex_t *mutex, /* Indicate that the semaphore is not held by any thread. */ - mutex->pid = -1; + mutex->pid = INVALID_PROCESS_ID; /* Initialize the mutex like a semaphore with initial count = 1 */ diff --git a/sched/pthread/pthread_mutextimedlock.c b/sched/pthread/pthread_mutextimedlock.c index 90bc82b4cf51b..af0698851d30b 100644 --- a/sched/pthread/pthread_mutextimedlock.c +++ b/sched/pthread/pthread_mutextimedlock.c @@ -78,7 +78,7 @@ int pthread_mutex_timedlock(FAR pthread_mutex_t *mutex, FAR const struct timespec *abs_timeout) { - int mypid = (int)getpid(); + pid_t mypid = getpid(); int ret = EINVAL; sinfo("mutex=0x%p\n", mutex); diff --git a/sched/pthread/pthread_mutextrylock.c b/sched/pthread/pthread_mutextrylock.c index a225db60817e2..84e2a5632cea0 100644 --- a/sched/pthread/pthread_mutextrylock.c +++ b/sched/pthread/pthread_mutextrylock.c @@ -76,7 +76,7 @@ int pthread_mutex_trylock(FAR pthread_mutex_t *mutex) if (mutex != NULL) { - int mypid = (int)getpid(); + pid_t mypid = getpid(); /* Make sure the semaphore is stable while we make the following * checks. This all needs to be one atomic action. diff --git a/sched/pthread/pthread_mutexunlock.c b/sched/pthread/pthread_mutexunlock.c index 9fb71e5c6a35b..60ec2937552ab 100644 --- a/sched/pthread/pthread_mutexunlock.c +++ b/sched/pthread/pthread_mutexunlock.c @@ -214,7 +214,7 @@ int pthread_mutex_unlock(FAR pthread_mutex_t *mutex) { /* Nullify the pid and lock count then post the semaphore */ - mutex->pid = -1; + mutex->pid = INVALID_PROCESS_ID; #ifdef CONFIG_PTHREAD_MUTEX_TYPES mutex->nlocks = 0; #endif diff --git a/sched/sched/sched_idletask.c b/sched/sched/sched_idletask.c index c48b0f43f4368..ab83fa68427be 100644 --- a/sched/sched/sched_idletask.c +++ b/sched/sched/sched_idletask.c @@ -43,7 +43,7 @@ * Check if the caller is an IDLE thread. For most implementations of * the SYSLOG output semaphore locking is required for mutual exclusion. * The idle threads are unable to lock semaphores because they cannot - * want. So IDLE thread output is a special case and is treated much as + * wait. So IDLE thread output is a special case and is treated much as * we treat debug output from an interrupt handler. * * Input Parameters: diff --git a/sched/sched/sched_timerexpiration.c b/sched/sched/sched_timerexpiration.c index a8999ed4604c7..c58cc05ca6fc3 100644 --- a/sched/sched/sched_timerexpiration.c +++ b/sched/sched/sched_timerexpiration.c @@ -205,8 +205,8 @@ static uint32_t nxsched_cpu_scheduler(int cpu, uint32_t ticks, * committed to updating the scheduler for this TCB. */ - sporadic->sched_time.tv_sec = g_sched_time.tv_sec; - sporadic->sched_time.tv_nsec = g_sched_time.tv_nsec; + sporadic->eventtime = SEC2TICK(g_sched_time.tv_sec) + + NSEC2TICK(g_sched_time.tv_nsec); /* Yes, check if the currently executing task has exceeded its * budget. diff --git a/sched/sched/sched_wait.c b/sched/sched/sched_wait.c index e617a16c0f5f5..bf7f954853df9 100644 --- a/sched/sched/sched_wait.c +++ b/sched/sched/sched_wait.c @@ -44,7 +44,7 @@ pid_t nx_wait(FAR int *stat_loc) { - return nx_waitpid((pid_t)-1, stat_loc, 0); + return nx_waitpid(INVALID_PROCESS_ID, stat_loc, 0); } /**************************************************************************** @@ -61,8 +61,8 @@ pid_t nx_wait(FAR int *stat_loc) * available prior to the call to wait(), return will be immediate. * * The waitpid() function will behave identically to wait(), if the pid - * argument is (pid_t)-1 and the options argument is 0. Otherwise, its - * behaviour will be modified by the values of the pid and options + * argument is INVALID_PROCESS_ID and the options argument is 0. Otherwise, + * its behaviour will be modified by the values of the pid and options * arguments. * * Input Parameters: @@ -79,7 +79,7 @@ pid_t wait(FAR int *stat_loc) * trivial case. */ - return waitpid((pid_t)-1, stat_loc, 0); + return waitpid(INVALID_PROCESS_ID, stat_loc, 0); } #endif /* CONFIG_SCHED_WAITPID && CONFIG_SCHED_HAVE_PARENT */ diff --git a/sched/sched/sched_waitpid.c b/sched/sched/sched_waitpid.c index 92d4d10637262..a1a74fc505a4e 100644 --- a/sched/sched/sched_waitpid.c +++ b/sched/sched/sched_waitpid.c @@ -171,8 +171,8 @@ pid_t nx_waitpid(pid_t pid, int *stat_loc, int options) /**************************************************************************** * * If CONFIG_SCHED_HAVE_PARENT is defined, then waitpid will use the SIGCHLD - * signal. It can also handle the pid == (pid_t)-1 argument. This is - * slightly more spec-compliant. + * signal. It can also handle the pid == INVALID_PROCESS_ID argument. This + * is slightly more spec-compliant. * * But then I have to be concerned about the fact that NuttX does not queue * signals. This means that a flurry of signals can cause signals to be @@ -227,7 +227,7 @@ pid_t nx_waitpid(pid_t pid, int *stat_loc, int options) ret = -ECHILD; goto errout; } - else if (pid != (pid_t)-1) + else if (pid != INVALID_PROCESS_ID) { /* Get the TCB corresponding to this PID. NOTE: If the child has * already exited, then the PID will not map to a valid TCB. @@ -270,7 +270,7 @@ pid_t nx_waitpid(pid_t pid, int *stat_loc, int options) ret = -ECHILD; goto errout; } - else if (pid != (pid_t)-1) + else if (pid != INVALID_PROCESS_ID) { /* Get the TCB corresponding to this PID and make sure that the * thread it is our child. @@ -297,7 +297,7 @@ pid_t nx_waitpid(pid_t pid, int *stat_loc, int options) * instead). */ - if (pid == (pid_t)-1) + if (pid == INVALID_PROCESS_ID) { /* We are waiting for any child, check if there are still * children. @@ -379,7 +379,7 @@ pid_t nx_waitpid(pid_t pid, int *stat_loc, int options) */ if (rtcb->group->tg_nchildren == 0 || - (pid != (pid_t)-1 && nxsig_kill(pid, 0) < 0)) + (pid != INVALID_PROCESS_ID && nxsig_kill(pid, 0) < 0)) { /* We know that the child task was running okay when we started, * so we must have lost the signal. What can we do? @@ -407,11 +407,11 @@ pid_t nx_waitpid(pid_t pid, int *stat_loc, int options) } /* Was this the death of the thread we were waiting for? In the of - * pid == (pid_t)-1, we are waiting for any child thread. + * pid == INVALID_PROCESS_ID, we are waiting for any child thread. */ if (info.si_signo == SIGCHLD && - (pid == (pid_t)-1 || info.si_pid == pid)) + (pid == INVALID_PROCESS_ID || info.si_pid == pid)) { /* Yes... return the status and PID (in the event it was -1) */ diff --git a/sched/task/task_getpid.c b/sched/task/task_getpid.c index f0e0db3d1e81b..102c63323ab30 100644 --- a/sched/task/task_getpid.c +++ b/sched/task/task_getpid.c @@ -96,5 +96,5 @@ pid_t getpid(void) * start-up/IDLE thread before the ready-to-run list has been initialized. */ - return (pid_t)0; + return IDLE_PROCESS_ID; } diff --git a/sched/task/task_getppid.c b/sched/task/task_getppid.c index 0f7978494c204..8d1936061a39a 100644 --- a/sched/task/task_getppid.c +++ b/sched/task/task_getppid.c @@ -96,5 +96,5 @@ pid_t getppid(void) * start-up/IDLE thread before the ready-to-run list has been initialized. */ - return (pid_t)0; + return IDLE_PROCESS_ID; } diff --git a/sched/task/task_posixspawn.c b/sched/task/task_posixspawn.c index 888e7b514d0c9..881d604002709 100644 --- a/sched/task/task_posixspawn.c +++ b/sched/task/task_posixspawn.c @@ -316,7 +316,7 @@ int posix_spawn(FAR pid_t *pid, FAR const char *path, FAR char * const argv[], FAR char * const envp[]) { struct sched_param param; - pid_t proxy; + int proxy; #ifdef CONFIG_SCHED_WAITPID int status; #endif @@ -410,7 +410,7 @@ int posix_spawn(FAR pid_t *pid, FAR const char *path, * for use within the OS. */ - ret = nx_waitpid(proxy, &status, 0); + ret = nx_waitpid((pid_t)proxy, &status, 0); if (ret < 0) { serr("ERROR: waitpid() failed: %d\n", ret); diff --git a/sched/task/task_vfork.c b/sched/task/task_vfork.c index 1642ca440dbad..fe87899d1b056 100644 --- a/sched/task/task_vfork.c +++ b/sched/task/task_vfork.c @@ -276,7 +276,7 @@ pid_t nxtask_start_vfork(FAR struct task_tcb_s *child) /* Get the assigned pid before we start the task */ - pid = (int)child->cmn.pid; + pid = child->cmn.pid; /* Eliminate a race condition by disabling pre-emption. The child task * can be instantiated, but cannot run until we call waitpid(). This diff --git a/tools/jlink-nuttx.c b/tools/jlink-nuttx.c index 8b3ee4eabaedc..0e817888efb67 100644 --- a/tools/jlink-nuttx.c +++ b/tools/jlink-nuttx.c @@ -207,11 +207,11 @@ static inline uint32_t decode_hex(const char *line) } static int get_pid(struct plugin_priv_s *priv, uint32_t idx, - uint16_t *pid) + uint32_t *pid) { int ret; - ret = READU16(priv->pidhash[idx] + priv->tcbinfo->pid_off, pid); + ret = READU32(priv->pidhash[idx] + priv->tcbinfo->pid_off, pid); if (ret != 0) { PERROR("read %d pid error return %d\n", idx, ret); @@ -228,7 +228,7 @@ static int get_idx_from_pid(struct plugin_priv_s *priv, for (idx = 0; idx < priv->ntcb; idx++) { - uint16_t tmppid; + uint32_t tmppid; if (get_pid(priv, idx, &tmppid)) { @@ -466,7 +466,7 @@ uint32_t RTOS_GetThreadId(uint32_t n) { if (n < g_plugin_priv.ntcb) { - uint16_t pid; + uint32_t pid; if (get_pid(&g_plugin_priv, n, &pid) == 0) { diff --git a/tools/minidumpserver.py b/tools/minidumpserver.py new file mode 100755 index 0000000000000..9800708ee3973 --- /dev/null +++ b/tools/minidumpserver.py @@ -0,0 +1,520 @@ +#!/usr/bin/env python3 +# tools/minidumpserver.py +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# + +import argparse +import binascii +import logging +import os +import re +import socket +import struct +import sys + +import elftools +from elftools.elf.elffile import ELFFile + +# ELF section flags +SHF_WRITE = 0x1 +SHF_ALLOC = 0x2 +SHF_EXEC = 0x4 +SHF_WRITE_ALLOC = SHF_WRITE | SHF_ALLOC +SHF_ALLOC_EXEC = SHF_ALLOC | SHF_EXEC + + +logger = logging.getLogger() + + +class dump_elf_file: + """ + Class to parse ELF file for memory content in various sections. + There are read-only sections (e.g. text and rodata) where + the memory content does not need to be dumped via coredump + and can be retrived from the ELF file. + """ + + def __init__(self, elffile): + self.elffile = elffile + self.fd = None + self.elf = None + self.memories = list() + + def open(self): + self.fd = open(self.elffile, "rb") + self.elf = ELFFile(self.fd) + + def close(self): + self.fd.close() + + def parse(self): + if self.fd is None: + self.open() + + for section in self.elf.iter_sections(): + # REALLY NEED to match exact type as all other sections + # (debug, text, etc.) are descendants where + # isinstance() would match. + if ( + type(section) is not elftools.elf.sections.Section + ): # pylint: disable=unidiomatic-typecheck + continue + + size = section["sh_size"] + flags = section["sh_flags"] + start = section["sh_addr"] + end = start + size - 1 + + store = False + desc = "?" + + if section["sh_type"] == "SHT_PROGBITS": + if (flags & SHF_ALLOC_EXEC) == SHF_ALLOC_EXEC: + # Text section + store = True + desc = "text" + elif (flags & SHF_WRITE_ALLOC) == SHF_WRITE_ALLOC: + # Data section + # + # Running app changes the content so no need + # to store + pass + elif (flags & SHF_ALLOC) == SHF_ALLOC: + # Read only data section + store = True + desc = "read-only data" + + if store: + memory = {"start": start, "end": end, "data": section.data()} + logger.info( + "ELF Section: 0x%x to 0x%x of size %d (%s)" + % (memory["start"], memory["end"], len(memory["data"]), desc) + ) + + self.memories.append(memory) + + return True + + +reg_table = { + "arm": { + "R0": 0, + "R1": 1, + "R2": 2, + "R3": 3, + "R4": 4, + "R5": 5, + "R6": 6, + "FP": 7, + "R8": 8, + "SB": 9, + "SL": 10, + "R11": 11, + "IP": 12, + "SP": 13, + "LR": 14, + "PC": 15, + "xPSR": 16, + }, + "riscv": { + "ZERO": 0, + "RA": 1, + "SP": 2, + "GP": 3, + "TP": 4, + "T0": 5, + "T1": 6, + "T2": 7, + "FP": 8, + "S1": 9, + "A0": 10, + "A1": 11, + "A2": 12, + "A3": 13, + "A4": 14, + "A5": 15, + "A6": 16, + "A7": 17, + "S2": 18, + "S3": 19, + "S4": 20, + "S5": 21, + "S6": 22, + "S7": 23, + "S8": 24, + "S9": 25, + "S10": 26, + "S11": 27, + "T3": 28, + "T4": 29, + "T5": 30, + "T6": 31, + "PC": 32, + }, +} + + +class dump_log_file: + def __init__(self, logfile): + self.logfile = logfile + self.fd = None + self.arch = "" + self.registers = [] + self.memories = list() + + def open(self): + self.fd = open(self.logfile, "r") + + def close(self): + self.fd.closeself() + + def parse(self): + data = bytes() + start = 0 + if self.fd is None: + self.open() + while 1: + line = self.fd.readline() + if line == "": + break + + tmp = re.search(r"([^ ]*)_registerdump:?", line) + if tmp is not None: + # find arch + self.arch = tmp.group(1) + if self.arch not in reg_table: + logger.error("%s not supported" % (self.arch)) + # init register list + if len(self.registers) == 0: + for x in range(len(reg_table[self.arch])): + self.registers.append(b"x") + + # find register value + line = line[tmp.span()[1] :] + line = line.replace("\n", " ") + while 1: + tmp = re.search("([^ ]+):", line) + if tmp is None: + break + register = tmp.group(1) + line = line[tmp.span()[1] :] + tmp = re.search("([0-9a-fA-F]+) ", line) + if tmp is None: + break + if register in reg_table[self.arch].keys(): + self.registers[reg_table[self.arch][register]] = int( + "0x" + tmp.group().replace(" ", ""), 16 + ) + line = line[tmp.span()[1] :] + continue + + tmp = re.search("_stackdump:", line) + if tmp is not None: + # find stackdump + line = line[tmp.span()[1] :] + tmp = re.search("([0-9a-fA-F]+):", line) + if tmp is not None: + line_start = int("0x" + tmp.group()[:-1], 16) + + if start + len(data) != line_start: + # stack is not contiguous + if len(data) == 0: + start = line_start + else: + memory = { + "start": start, + "end": start + len(data), + "data": data, + } + self.memories.append(memory) + data = b"" + start = line_start + + line = line[tmp.span()[1] :] + line = line.replace("\n", " ") + + while 1: + # record stack value + tmp = re.search(" ([0-9a-fA-F]+)", line) + if tmp is None: + break + data = data + struct.pack( + " unknown value + # Send in "xxxxxxxx" + pkt += b"x" * 8 + + self.put_gdb_packet(pkt) + + def handle_register_single_read_packet(self, pkt): + # Mark registers as "". + # 'p' packets are usually used for registers + # other than the general ones (e.g. eax, ebx) + # so we can safely reply "xxxxxxxx" here. + self.put_gdb_packet(b"x" * 8) + + def handle_register_group_write_packet(self): + # the 'G' packet for writing to a group of registers + # + # We don't support writing so return error + self.put_gdb_packet(b"E01") + + def handle_register_single_write_packet(self, pkt): + # the 'P' packet for writing to registers + # + # We don't support writing so return error + self.put_gdb_packet(b"E01") + + def handle_memory_read_packet(self, pkt): + # the 'm' packet for reading memory: m, + + def get_mem_region(addr): + for r in self.mem_regions: + if r["start"] <= addr <= r["end"]: + return r + + return None + + # extract address and length from packet + # and convert them into usable integer values + addr, length = pkt[1:].split(b",") + s_addr = int(b"0x" + addr, 16) + length = int(b"0x" + length, 16) + + # FIXME: Need more efficient way of extracting memory content + remaining = length + addr = s_addr + barray = b"" + r = get_mem_region(addr) + while remaining > 0: + if r is None: + barray = None + break + + if addr > r["end"]: + r = get_mem_region(addr) + continue + + offset = addr - r["start"] + barray += r["data"][offset:offset + 1] + + addr += 1 + remaining -= 1 + + if barray is not None: + pkt = binascii.hexlify(barray) + self.put_gdb_packet(pkt) + else: + self.put_gdb_packet(b"E01") + + def handle_memory_write_packet(self, pkt): + # the 'M' packet for writing to memory + # + # We don't support writing so return error + self.put_gdb_packet(b"E02") + + def handle_general_query_packet(self, pkt): + self.put_gdb_packet(b"") + + def run(self, socket): + self.socket = socket + + while True: + pkt = self.get_gdb_packet() + if pkt is None: + continue + + pkt_type = pkt[0:1] + logger.debug(f"Got packet type: {pkt_type}") + + if pkt_type == b"?": + self.handle_signal_query_packet() + elif pkt_type in (b"C", b"S"): + # Continue/stepping execution, which is not supported. + # So signal exception again + self.handle_signal_query_packet() + elif pkt_type == b"g": + self.handle_register_group_read_packet() + elif pkt_type == b"G": + self.handle_register_group_write_packet() + elif pkt_type == b"p": + self.handle_register_single_read_packet(pkt) + elif pkt_type == b"P": + self.handle_register_single_write_packet(pkt) + elif pkt_type == b"m": + self.handle_memory_read_packet(pkt) + elif pkt_type == b"M": + self.handle_memory_write_packet(pkt) + elif pkt_type == b"q": + self.handle_general_query_packet(pkt) + elif pkt_type == b"k": + # GDB quits + break + else: + self.put_gdb_packet(b"") + + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + + parser.add_argument("-e", "--elffile", required=True, help="elffile") + + parser.add_argument("-l", "--logfile", required=True, help="logfile") + + parser.add_argument("-p", "--port", help="gdbport", type=int, default=1234) + + parser.add_argument("--debug", action="store_true", default=False) + + args = parser.parse_args() + + if not os.path.isfile(args.elffile): + logger.error(f"Cannot find file {args.elffile}, exiting...") + sys.exit(1) + + if not os.path.isfile(args.logfile): + logger.error(f"Cannot find file {args.logfile}, exiting...") + sys.exit(1) + + if args.debug: + logger.setLevel(logging.DEBUG) + else: + logger.setLevel(logging.INFO) + + log = dump_log_file(args.logfile) + log.parse() + elf = dump_elf_file(args.elffile) + elf.parse() + + gdbstub = gdb_stub(log, elf) + logging.basicConfig(format="[%(levelname)s][%(name)s] %(message)s") + + gdbserver = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + + # Reuse address so we don't have to wait for socket to be + # close before we can bind to the port again + gdbserver.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + + gdbserver.bind(("", args.port)) + gdbserver.listen(1) + + logger.info(f"Waiting GDB connection on port {args.port} ...") + + conn, remote = gdbserver.accept() + + if conn: + logger.info(f"Accepted GDB connection from {remote}") + + gdbstub.run(conn) + + conn.close() + + gdbserver.close() diff --git a/wireless/bluetooth/bt_conn.c b/wireless/bluetooth/bt_conn.c index 9c524450336be..c69658a6857ba 100644 --- a/wireless/bluetooth/bt_conn.c +++ b/wireless/bluetooth/bt_conn.c @@ -557,14 +557,12 @@ void bt_conn_set_state(FAR struct bt_conn_s *conn, { case BT_CONN_CONNECTED: { - pid_t pid; int ret; ret = bt_queue_open(BT_CONN_TX, O_RDWR | O_CREAT, CONFIG_BLUETOOTH_TXCONN_NMSGS, &conn->tx_queue); DEBUGASSERT(ret >= 0); - UNUSED(ret); /* Get exclusive access to the handoff structure. The count will * be zero when we complete this. @@ -576,12 +574,11 @@ void bt_conn_set_state(FAR struct bt_conn_s *conn, /* Start the Tx connection kernel thread */ g_conn_handoff.conn = bt_conn_addref(conn); - pid = kthread_create("BT Conn Tx", + ret = kthread_create("BT Conn Tx", CONFIG_BLUETOOTH_TXCONN_PRIORITY, CONFIG_BLUETOOTH_TXCONN_STACKSIZE, conn_tx_kthread, NULL); - DEBUGASSERT(pid > 0); - UNUSED(pid); + DEBUGASSERT(ret > 0); /* Take the semaphore again. This will force us to wait with * the sem_count at -1. It will be zero again when we @@ -591,6 +588,8 @@ void bt_conn_set_state(FAR struct bt_conn_s *conn, ret = nxsem_wait_uninterruptible(&g_conn_handoff.sync_sem); nxsem_post(&g_conn_handoff.sync_sem); } + + UNUSED(ret); } break; diff --git a/wireless/bluetooth/bt_hcicore.c b/wireless/bluetooth/bt_hcicore.c index 54532a6d150d5..1914835b53fe0 100644 --- a/wireless/bluetooth/bt_hcicore.c +++ b/wireless/bluetooth/bt_hcicore.c @@ -1438,7 +1438,6 @@ static int hci_initialize(void) static void cmd_queue_init(void) { - pid_t pid; int ret; /* When there is a command to be sent to the Bluetooth driver, it queued on @@ -1448,17 +1447,16 @@ static void cmd_queue_init(void) ret = bt_queue_open(BT_HCI_TX, O_RDWR | O_CREAT, CONFIG_BLUETOOTH_TXCMD_NMSGS, &g_btdev.tx_queue); DEBUGASSERT(ret >= 0); - UNUSED(ret); nxsem_init(&g_btdev.ncmd_sem, 0, 1); nxsem_set_protocol(&g_btdev.ncmd_sem, SEM_PRIO_NONE); g_btdev.ncmd = 1; - pid = kthread_create("BT HCI Tx", CONFIG_BLUETOOTH_TXCMD_PRIORITY, + ret = kthread_create("BT HCI Tx", CONFIG_BLUETOOTH_TXCMD_PRIORITY, CONFIG_BLUETOOTH_TXCMD_STACKSIZE, hci_tx_kthread, NULL); - DEBUGASSERT(pid > 0); - UNUSED(pid); + DEBUGASSERT(ret > 0); + UNUSED(ret); } /****************************************************************************