void up_decodeirq(uint32_t *regs) { #ifdef CONFIG_SUPPRESS_INTERRUPTS board_autoled_on(LED_INIRQ); lowsyslog(LOG_ERR, "Unexpected IRQ\n"); current_regs = regs; PANIC(); #else unsigned int irq; /* Read the IRQ number from the IVR register (Could probably get the same * info from CIC register without the setup). */ board_autoled_on(LED_INIRQ); irq = getreg32(STR71X_EIC_IVR); /* Verify that the resulting IRQ number is valid */ if (irq < NR_IRQS) { uint32_t *savestate; /* Current regs non-zero indicates that we are processing an interrupt; * current_regs is also used to manage interrupt level context switches. */ savestate = (uint32_t *)current_regs; current_regs = regs; /* Acknowledge the interrupt */ up_ack_irq(irq); /* Deliver the IRQ */ irq_dispatch(irq, regs); /* Restore the previous value of current_regs. NULL would indicate that * we are no longer in an interrupt handler. It will be non-NULL if we * are returning from a nested interrupt. */ current_regs = savestate; } #ifdef CONFIG_DEBUG else { PANIC(); /* Normally never happens */ } #endif board_autoled_off(LED_INIRQ); #endif }
void up_allocate_heap(FAR void **heap_start, size_t *heap_size) { #if defined(CONFIG_BUILD_PROTECTED) && defined(CONFIG_MM_KERNEL_HEAP) /* Get the unaligned size and position of the user-space heap. * This heap begins after the user-space .bss section at an offset * of CONFIG_MM_KERNEL_HEAPSIZE (subject to alignment). */ uintptr_t ubase = (uintptr_t)USERSPACE->us_bssend + CONFIG_MM_KERNEL_HEAPSIZE; size_t usize = SRAM1_END - ubase; int log2; DEBUGASSERT(ubase < (uintptr_t)SRAM1_END); /* Adjust that size to account for MPU alignment requirements. * NOTE that there is an implicit assumption that the SRAM1_END * is aligned to the MPU requirement. */ log2 = (int)mpu_log2regionfloor(usize); DEBUGASSERT((SRAM1_END & ((1 << log2) - 1)) == 0); usize = (1 << log2); ubase = SRAM1_END - usize; /* Return the user-space heap settings */ board_autoled_on(LED_HEAPALLOCATE); *heap_start = (FAR void *)ubase; *heap_size = usize; /* Colorize the heap for debug */ up_heap_color((FAR void *)ubase, usize); /* Allow user-mode access to the user heap memory */ stm32_mpu_uheap((uintptr_t)ubase, usize); #else /* Return the heap settings */ board_autoled_on(LED_HEAPALLOCATE); *heap_start = (FAR void *)g_idle_topstack; *heap_size = SRAM1_END - g_idle_topstack; /* Colorize the heap for debug */ up_heap_color(*heap_start, *heap_size); #endif }
static void _up_assert(int errorcode) { /* Flush any buffered SYSLOG data */ (void)syslog_flush(); /* Are we in an interrupt handler or the idle task? */ if (g_current_regs || this_task()->pid == 0) { (void)up_irq_save(); for (; ; ) { #if CONFIG_BOARD_RESET_ON_ASSERT >= 1 board_reset(0); #endif #ifdef CONFIG_ARCH_LEDS board_autoled_on(LED_PANIC); up_mdelay(250); board_autoled_off(LED_PANIC); up_mdelay(250); #endif } } else { #if CONFIG_BOARD_RESET_ON_ASSERT >= 2 board_reset(0); #endif exit(errorcode); } }
void up_assert(const uint8_t *filename, int lineno) { #if CONFIG_TASK_NAME_SIZE > 0 && defined(CONFIG_DEBUG_ALERT) struct tcb_s *rtcb = this_task(); #endif board_autoled_on(LED_ASSERTION); #if CONFIG_TASK_NAME_SIZE > 0 _alert("Assertion failed at file:%s line: %d task: %s\n", filename, lineno, rtcb->name); #else _alert("Assertion failed at file:%s line: %d\n", filename, lineno); #endif up_dumpstate(); #ifdef CONFIG_BOARD_CRASHDUMP board_crashdump(up_getsp(), this_task(), filename, lineno); #endif #ifdef CONFIG_ARCH_USBDUMP /* Dump USB trace data */ (void)usbtrace_enumerate(assert_tracecallback, NULL); #endif _up_assert(EXIT_FAILURE); }
void up_sigdeliver(void) { #ifndef CONFIG_DISABLE_SIGNALS FAR struct tcb_s *rtcb = this_task(); chipreg_t regs[XCPTCONTEXT_REGS]; sig_deliver_t sigdeliver; /* Save the errno. This must be preserved throughout the signal handling * so that the user code final gets the correct errno value (probably * EINTR). */ int saved_errno = rtcb->pterrno; board_autoled_on(LED_SIGNAL); sdbg("rtcb=%p sigdeliver=%p sigpendactionq.head=%p\n", rtcb, rtcb->xcp.sigdeliver, rtcb->sigpendactionq.head); ASSERT(rtcb->xcp.sigdeliver != NULL); /* Save the real return state on the stack. */ ez80_copystate(regs, rtcb->xcp.regs); regs[XCPT_PC] = rtcb->xcp.saved_pc; regs[XCPT_I] = rtcb->xcp.saved_i; /* Get a local copy of the sigdeliver function pointer. We do this so * that we can nullify the sigdeliver function pointer in the TCB and * accept more signal deliveries while processing the current pending * signals. */ sigdeliver = rtcb->xcp.sigdeliver; rtcb->xcp.sigdeliver = NULL; /* Then restore the task interrupt state. */ irqrestore(regs[XCPT_I]); /* Deliver the signals */ sigdeliver(rtcb); /* Output any debug messages BEFORE restoring errno (because they may * alter errno), then disable interrupts again and restore the original * errno that is needed by the user logic (it is probably EINTR). */ sdbg("Resuming\n"); (void)irqsave(); rtcb->pterrno = saved_errno; /* Then restore the correct state for this thread of * execution. */ board_autoled_off(LED_SIGNAL); ez80_restorecontext(regs); #endif }
void up_allocate_heap(FAR void **heap_start, size_t *heap_size) { /* Start with the first SRAM region */ board_autoled_on(LED_HEAPALLOCATE); *heap_start = (FAR void *)g_idle_topstack; *heap_size = CONFIG_RAM_END - g_idle_topstack; }
void up_sigdeliver(void) { struct tcb_s *rtcb = this_task(); uint32_t regs[XCPTCONTEXT_REGS]; sig_deliver_t sigdeliver; /* Save the errno. This must be preserved throughout the signal handling * so that the user code final gets the correct errno value (probably * EINTR). */ int saved_errno = rtcb->pterrno; board_autoled_on(LED_SIGNAL); svdbg("rtcb=%p sigdeliver=%p sigpendactionq.head=%p\n", rtcb, rtcb->xcp.sigdeliver, rtcb->sigpendactionq.head); ASSERT(rtcb->xcp.sigdeliver != NULL); /* Save the real return state on the stack. */ up_copyfullstate(regs, rtcb->xcp.regs); regs[REG_PC] = rtcb->xcp.saved_pc; regs[REG_CPSR] = rtcb->xcp.saved_cpsr; /* Get a local copy of the sigdeliver function pointer. we do this so that * we can nullify the sigdeliver function pointer in the TCB and accept * more signal deliveries while processing the current pending signals. */ sigdeliver = rtcb->xcp.sigdeliver; rtcb->xcp.sigdeliver = NULL; /* Then restore the task interrupt state */ irqrestore(regs[REG_CPSR]); /* Deliver the signals */ sigdeliver(rtcb); /* Output any debug messages BEFORE restoring errno (because they may * alter errno), then disable interrupts again and restore the original * errno that is needed by the user logic (it is probably EINTR). */ svdbg("Resuming\n"); (void)irqsave(); rtcb->pterrno = saved_errno; /* Then restore the correct state for this thread of execution. */ board_autoled_off(LED_SIGNAL); #ifdef CONFIG_TASK_SCHED_HISTORY /* Save the task name which will be scheduled */ save_task_scheduling_status(rtcb); #endif up_fullcontextrestore(regs); }
void efm32_led_pminitialize(void) { /* Register to receive power management callbacks */ int ret = pm_register(&g_ledscb); if (ret != OK) { board_autoled_on(LED_ASSERTION); } }
uint32_t *up_doirq(int irq, uint32_t *regs) { board_autoled_on(LED_INIRQ); #ifdef CONFIG_SUPPRESS_INTERRUPTS PANIC(); #else uint32_t *savestate; /* Nested interrupts are not supported in this implementation. If you want * to implement nested interrupts, you would have to (1) change the way that * current_regs is handled and (2) the design associated with * CONFIG_ARCH_INTERRUPTSTACK. The savestate variable will not work for * that purpose as implemented here because only the outermost nested * interrupt can result in a context switch (it can probably be deleted). */ /* Current regs non-zero indicates that we are processing an interrupt; * current_regs is also used to manage interrupt level context switches. */ savestate = (uint32_t *)current_regs; current_regs = regs; /* Acknowledge the interrupt */ up_ack_irq(irq); /* Deliver the IRQ */ irq_dispatch(irq, regs); /* 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 * switch occurred during interrupt processing. */ regs = (uint32_t *)current_regs; /* Restore the previous value of current_regs. NULL would indicate that * we are no longer in an interrupt handler. It will be non-NULL if we * are returning from a nested interrupt. */ current_regs = savestate; #endif board_autoled_off(LED_INIRQ); return regs; }
void up_assert(void) #endif { #if CONFIG_TASK_NAME_SIZE > 0 struct tcb_s *rtcb = this_task(); #endif board_autoled_on(LED_ASSERTION); #ifdef CONFIG_HAVE_FILENAME #if CONFIG_TASK_NAME_SIZE > 0 lldbg("Assertion failed at file:%s line: %d task: %s\n", filename, lineno, rtcb->name); #else lldbg("Assertion failed at file:%s line: %d\n", filename, lineno); #endif #else #if CONFIG_TASK_NAME_SIZE > 0 lldbg("Assertion failed: task: %s\n", rtcb->name); #else lldbg("Assertion failed\n"); #endif #endif up_stackdump(); up_registerdump(); #ifdef CONFIG_ARCH_USBDUMP /* Dump USB trace data */ (void)usbtrace_enumerate(assert_tracecallback, NULL); #endif #ifdef CONFIG_BOARD_CRASHDUMP board_crashdump(up_getsp(), this_task(), filename, lineno); #endif _up_assert(EXIT_FAILURE); }
static void _up_assert(int errorcode) { /* Are we in an interrupt handler or the idle task? */ if (g_current_regs || this_task()->pid == 0) { (void)up_irq_save(); for (; ; ) { #ifdef CONFIG_ARCH_LEDS board_autoled_on(LED_PANIC); up_mdelay(250); board_autoled_off(LED_PANIC); up_mdelay(250); #endif } } else { exit(errorcode); } }
static void _up_assert(int errorcode) /* noreturn_function */ { /* Are we in an interrupt handler or the idle task? */ if (up_interrupt_context() || this_task()->pid == 0) { (void)irqsave(); for (;;) { #ifdef CONFIG_ARCH_LEDS board_autoled_on(LED_PANIC); up_mdelay(250); board_autoled_off(LED_PANIC); up_mdelay(250); #endif } } else { exit(errorcode); } }
void up_assert(const uint8_t *filename, int lineno) { #ifdef CONFIG_PRINT_TASKNAME struct tcb_s *rtcb = this_task(); #endif board_autoled_on(LED_ASSERTION); #ifdef CONFIG_PRINT_TASKNAME lldbg("Assertion failed at file:%s line: %d task: %s\n", filename, lineno, rtcb->name); #else lldbg("Assertion failed at file:%s line: %d\n", filename, lineno); #endif up_dumpstate(); #ifdef CONFIG_BOARD_CRASHDUMP board_crashdump(up_getsp(), this_task(), filename, lineno); #endif _up_assert(EXIT_FAILURE); }
int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype) { /* Is there already a stack allocated of a different size? Because of * alignment issues, stack_size might erroneously appear to be of a * different size. Fortunately, this is not a critical operation. */ if (tcb->stack_alloc_ptr && tcb->adj_stack_size != stack_size) { /* Yes.. Release the old stack */ up_release_stack(tcb, ttype); } /* Do we need to allocate a new stack? */ if (!tcb->stack_alloc_ptr) { /* Allocate the stack. If DEBUG is enabled (but not stack debug), * then create a zeroed stack to make stack dumps easier to trace. */ #if defined(CONFIG_BUILD_KERNEL) && defined(CONFIG_MM_KERNEL_HEAP) /* Use the kernel allocator if this is a kernel thread */ if (ttype == TCB_FLAG_TTYPE_KERNEL) { tcb->stack_alloc_ptr = (uint32_t *)kmm_malloc(stack_size); } else #endif { /* Use the user-space allocator if this is a task or pthread */ tcb->stack_alloc_ptr = (uint32_t *)kumm_malloc(stack_size); } #ifdef CONFIG_DEBUG_FEATURES /* Was the allocation successful? */ if (!tcb->stack_alloc_ptr) { serr("ERROR: Failed to allocate stack, size %d\n", stack_size); } #endif } /* Did we successfully allocate a stack? */ if (tcb->stack_alloc_ptr) { size_t top_of_stack; size_t size_of_stack; /* Yes.. If stack debug is enabled, then fill the stack with a * recognizable value that we can use later to test for high * water marks. */ #ifdef CONFIG_STACK_COLORATION memset(tcb->stack_alloc_ptr, 0xaa, stack_size); #endif /* The SH family uses a push-down stack: the stack grows * toward loweraddresses in memory. The stack pointer * register, points to the lowest, valid work address * (the "top" of the stack). Items on the stack are * referenced as positive word offsets from sp. */ top_of_stack = (uint32_t)tcb->stack_alloc_ptr + stack_size - 4; /* The SH stack must be aligned at word (4 byte) * boundaries. If necessary top_of_stack must be rounded * down to the next boundary */ top_of_stack &= ~3; size_of_stack = top_of_stack - (uint32_t)tcb->stack_alloc_ptr + 4; /* Save the adjusted stack values in the struct tcb_s */ tcb->adj_stack_ptr = (uint32_t*)top_of_stack; tcb->adj_stack_size = size_of_stack; board_autoled_on(LED_STACKCREATED); return OK; } return ERROR; }
uint8_t *up_doirq(int irq, uint8_t *regs) { board_autoled_on(LED_INIRQ); #ifdef CONFIG_SUPPRESS_INTERRUPTS PANIC(); #else /* Current regs non-zero indicates that we are processing an interrupt; * current_regs is also used to manage interrupt level context switches. * * Nested interrupts are not supported */ DEBUGASSERT(current_regs == NULL); current_regs = regs; /* Deliver the IRQ */ irq_dispatch(irq, regs); #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 */ up_restorefpu((uint32_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. */ (void)group_addrenv(NULL); #endif } #endif /* 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 * switch occurred during interrupt processing. */ regs = (uint8_t*)current_regs; /* Set current_regs to NULL to indicate that we are no longer in an * interrupt handler. */ current_regs = NULL; #endif board_autoled_off(LED_INIRQ); return regs; }
__EXPORT int board_app_initialize(uintptr_t arg) { #if defined(CONFIG_HAVE_CXX) && defined(CONFIG_HAVE_CXXINITIALIZE) /* run C++ ctors before we go any further */ up_cxxinitialize(); # if defined(CONFIG_EXAMPLES_NSH_CXXINITIALIZE) # error CONFIG_EXAMPLES_NSH_CXXINITIALIZE Must not be defined! Use CONFIG_HAVE_CXX and CONFIG_HAVE_CXXINITIALIZE. # endif #else # error platform is dependent on c++ both CONFIG_HAVE_CXX and CONFIG_HAVE_CXXINITIALIZE must be defined. #endif /* configure the high-resolution time/callout interface */ hrt_init(); param_init(); /* configure the DMA allocator */ if (board_dma_alloc_init() < 0) { message("DMA alloc FAILED"); } /* configure CPU load estimation */ #ifdef CONFIG_SCHED_INSTRUMENTATION cpuload_initialize_once(); #endif /* set up the serial DMA polling */ static struct hrt_call serial_dma_call; struct timespec ts; /* * Poll at 1ms intervals for received bytes that have not triggered * a DMA event. */ ts.tv_sec = 0; ts.tv_nsec = 1000000; hrt_call_every(&serial_dma_call, ts_to_abstime(&ts), ts_to_abstime(&ts), (hrt_callout)stm32_serial_dma_poll, NULL); #if defined(CONFIG_STM32_BBSRAM) /* NB. the use of the console requires the hrt running * to poll the DMA */ /* Using Battery Backed Up SRAM */ int filesizes[CONFIG_STM32_BBSRAM_FILES + 1] = BSRAM_FILE_SIZES; stm32_bbsraminitialize(BBSRAM_PATH, filesizes); #if defined(CONFIG_STM32_SAVE_CRASHDUMP) /* Panic Logging in Battery Backed Up Files */ /* * In an ideal world, if a fault happens in flight the * system save it to BBSRAM will then reboot. Upon * rebooting, the system will log the fault to disk, recover * the flight state and continue to fly. But if there is * a fault on the bench or in the air that prohibit the recovery * or committing the log to disk, the things are too broken to * fly. So the question is: * * Did we have a hard fault and not make it far enough * through the boot sequence to commit the fault data to * the SD card? */ /* Do we have an uncommitted hard fault in BBSRAM? * - this will be reset after a successful commit to SD */ int hadCrash = hardfault_check_status("boot"); if (hadCrash == OK) { message("[boot] There is a hard fault logged. Hold down the SPACE BAR," \ " while booting to halt the system!\n"); /* Yes. So add one to the boot count - this will be reset after a successful * commit to SD */ int reboots = hardfault_increment_reboot("boot", false); /* Also end the misery for a user that holds for a key down on the console */ int bytesWaiting; ioctl(fileno(stdin), FIONREAD, (unsigned long)((uintptr_t) &bytesWaiting)); if (reboots > 2 || bytesWaiting != 0) { /* Since we can not commit the fault dump to disk. Display it * to the console. */ hardfault_write("boot", fileno(stdout), HARDFAULT_DISPLAY_FORMAT, false); message("[boot] There were %d reboots with Hard fault that were not committed to disk - System halted %s\n", reboots, (bytesWaiting == 0 ? "" : " Due to Key Press\n")); /* For those of you with a debugger set a break point on up_assert and * then set dbgContinue = 1 and go. */ /* Clear any key press that got us here */ static volatile bool dbgContinue = false; int c = '>'; while (!dbgContinue) { switch (c) { case EOF: case '\n': case '\r': case ' ': continue; default: putchar(c); putchar('\n'); switch (c) { case 'D': case 'd': hardfault_write("boot", fileno(stdout), HARDFAULT_DISPLAY_FORMAT, false); break; case 'C': case 'c': hardfault_rearm("boot"); hardfault_increment_reboot("boot", true); break; case 'B': case 'b': dbgContinue = true; break; default: break; } // Inner Switch message("\nEnter B - Continue booting\n" \ "Enter C - Clear the fault log\n" \ "Enter D - Dump fault log\n\n?>"); fflush(stdout); if (!dbgContinue) { c = getchar(); } break; } // outer switch } // for } // inner if } // outer if #endif // CONFIG_STM32_SAVE_CRASHDUMP #endif // CONFIG_STM32_BBSRAM /* initial LED state */ drv_led_start(); led_off(LED_RED); led_off(LED_GREEN); led_off(LED_BLUE); #ifdef CONFIG_SPI int ret = stm32_spi_bus_initialize(); if (ret != OK) { board_autoled_on(LED_RED); return ret; } #endif #ifdef CONFIG_MMCSD ret = stm32_sdio_initialize(); if (ret != OK) { board_autoled_on(LED_RED); return ret; } #endif return OK; }
void up_initialize(void) { /* Initialize global variables */ g_current_regs = NULL; /* Calibrate the timing loop */ up_calibratedelay(); /* Colorize the interrupt stack */ up_color_intstack(); /* Add any extra memory fragments to the memory manager */ up_addregion(); /* Initialize the interrupt subsystem */ up_irqinitialize(); /* Initialize the DMA subsystem if the weak function stm32_dmainitialize has been * brought into the build */ #ifdef CONFIG_ARCH_DMA #ifdef CONFIG_HAVE_WEAKFUNCTIONS if (up_dmainitialize) #endif { up_dmainitialize(); } #endif /* Initialize the system timer interrupt */ #if !defined(CONFIG_SUPPRESS_INTERRUPTS) && !defined(CONFIG_SUPPRESS_TIMER_INTS) up_timer_initialize(); #endif /* Register devices */ #if CONFIG_NFILE_DESCRIPTORS > 0 #if defined(CONFIG_DEV_NULL) devnull_register(); /* Standard /dev/null */ #endif #if defined(CONFIG_DEV_ZERO) devzero_register(); /* Standard /dev/zero */ #endif #if defined(CONFIG_DEV_LOOP) loop_register(); /* Standard /dev/loop */ #endif #endif /* CONFIG_NFILE_DESCRIPTORS */ #if defined(CONFIG_SCHED_INSTRUMENTATION_BUFFER) && \ defined(CONFIG_DRIVER_NOTE) note_register(); /* Non-standard /dev/note */ #endif /* Initialize the serial device driver */ #ifdef USE_SERIALDRIVER up_serialinit(); #endif /* Initialize the console device driver (if it is other than the standard * serial driver). */ #if defined(CONFIG_DEV_LOWCONSOLE) lowconsole_init(); #elif defined(CONFIG_SYSLOG_CONSOLE) syslog_console_init(); #elif defined(CONFIG_RAMLOG_CONSOLE) ramlog_consoleinit(); #endif /* Initialize the system logging device */ #ifdef CONFIG_SYSLOG_CHAR syslog_initialize(); #endif #ifdef CONFIG_RAMLOG_SYSLOG ramlog_sysloginit(); #endif #ifndef CONFIG_NETDEV_LATEINIT /* Initialize the network */ up_netinitialize(); #endif #ifdef CONFIG_NETDEV_LOOPBACK /* Initialize the local loopback device */ (void)localhost_initialize(); #endif #ifdef CONFIG_NET_TUN /* Initialize the TUN device */ (void)tun_initialize(); #endif #ifdef CONFIG_NETDEV_TELNET /* Initialize the Telnet session factory */ (void)telnet_initialize(); #endif /* Initialize USB */ up_usbinitialize(); #if defined(ARCH_HAVE_LEDS) board_autoled_on(LED_IRQSENABLED); #endif }
void up_sigdeliver(void) { struct tcb_s *rtcb = this_task(); #if 0 uint32_t regs[XCPTCONTEXT_REGS+3]; /* Why +3? See below */ #else uint32_t regs[XCPTCONTEXT_REGS]; #endif sig_deliver_t sigdeliver; /* Save the errno. This must be preserved throughout the signal handling * so that the user code final gets the correct errno value (probably EINTR). */ int saved_errno = rtcb->pterrno; board_autoled_on(LED_SIGNAL); sdbg("rtcb=%p sigdeliver=%p sigpendactionq.head=%p\n", rtcb, rtcb->xcp.sigdeliver, rtcb->sigpendactionq.head); ASSERT(rtcb->xcp.sigdeliver != NULL); /* Save the real return state on the stack. */ up_copystate(regs, rtcb->xcp.regs); regs[REG_PC] = rtcb->xcp.saved_pc; regs[REG_SR] = rtcb->xcp.saved_sr; /* Get a local copy of the sigdeliver function pointer. We do this so that * we can nullify the sigdeliver function pointer in the TCB and accept * more signal deliveries while processing the current pending signals. */ sigdeliver = rtcb->xcp.sigdeliver; rtcb->xcp.sigdeliver = NULL; /* Then restore the task interrupt state */ up_irq_restore(regs[REG_SR]); /* Deliver the signals */ sigdeliver(rtcb); /* Output any debug messages BEFORE restoring errno (because they may * alter errno), then disable interrupts again and restore the original * errno that is needed by the user logic (it is probably EINTR). */ sdbg("Resuming\n"); (void)up_irq_save(); rtcb->pterrno = saved_errno; /* Then restore the correct state for this thread of execution. This is an * unusual case that must be handled by up_fullcontextresore. This case is * unusal in two ways: * * 1. It is not a context switch between threads. Rather, up_fullcontextrestore * must behave more it more like a longjmp within the same task, using * he same stack. * 2. In this case, up_fullcontextrestore is called with r12 pointing to * a register save area on the stack to be destroyed. This is * dangerous because there is the very real possibility that the new * stack pointer might overlap with the register save area and hat stack * usage in up_fullcontextrestore might corrupt the register save data * before the state is restored. At present, there does not appear to * be any stack overlap problems. If there were, then adding 3 words * to the size of register save structure size will protect its contents. */ board_autoled_off(LED_SIGNAL); up_fullcontextrestore(regs); }
void up_initialize(void) { #ifdef CONFIG_SMP int i; /* Initialize global variables */ for (i = 0; i < CONFIG_SMP_NCPUS; i++) { g_current_regs[i] = NULL; } #else CURRENT_REGS = NULL; #endif /* Add any extra memory fragments to the memory manager */ xtensa_add_region(); /* Initialize the interrupt subsystem */ xtensa_irq_initialize(); #ifdef CONFIG_PM /* Initialize the power management subsystem. This MCU-specific function * must be called *very* early in the initialization sequence *before* any * other device drivers are initialized (since they may attempt to register * with the power management subsystem). */ up_pminitialize(); #endif #ifdef CONFIG_ARCH_DMA /* Initialize the DMA subsystem if the weak function xtensa_dma_initialize * has been brought into the build */ #ifdef CONFIG_HAVE_WEAKFUNCTIONS if (xtensa_dma_initialize) #endif { xtensa_dma_initialize(); } #endif #if !defined(CONFIG_SUPPRESS_INTERRUPTS) && !defined(CONFIG_SUPPRESS_TIMER_INTS) /* Initialize the system timer interrupt */ xtensa_timer_initialize(); #endif #ifdef CONFIG_MM_IOB /* Initialize IO buffering */ iob_initialize(); #endif #if CONFIG_NFILE_DESCRIPTORS > 0 /* Register devices */ #if defined(CONFIG_DEV_NULL) devnull_register(); /* Standard /dev/null */ #endif #if defined(CONFIG_DEV_RANDOM) devrandom_register(); /* Standard /dev/random */ #endif #if defined(CONFIG_DEV_URANDOM) devurandom_register(); /* Standard /dev/urandom */ #endif #if defined(CONFIG_DEV_ZERO) devzero_register(); /* Standard /dev/zero */ #endif #if defined(CONFIG_DEV_LOOP) loop_register(); /* Standard /dev/loop */ #endif #endif /* CONFIG_NFILE_DESCRIPTORS */ #if defined(CONFIG_SCHED_INSTRUMENTATION_BUFFER) && \ defined(CONFIG_DRIVER_NOTE) note_register(); /* Non-standard /dev/note */ #endif /* Initialize the serial device driver */ #ifdef USE_SERIALDRIVER xtensa_serial_initialize(); #endif /* Initialize the console device driver (if it is other than the standard * serial driver). */ #if defined(CONFIG_DEV_LOWCONSOLE) lowconsole_init(); #elif defined(CONFIG_CONSOLE_SYSLOG) syslog_console_init(); #elif defined(CONFIG_RAMLOG_CONSOLE) ramlog_consoleinit(); #endif #if CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_PSEUDOTERM_SUSV1) /* Register the master pseudo-terminal multiplexor device */ (void)ptmx_register(); #endif /* Early initialization of the system logging device. Some SYSLOG channel * can be initialized early in the initialization sequence because they * depend on only minimal OS initialization. */ syslog_initialize(SYSLOG_INIT_EARLY); #if defined(CONFIG_CRYPTO) /* Initialize the HW crypto and /dev/crypto */ up_cryptoinitialize(); #endif #if CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_CRYPTO_CRYPTODEV) devcrypto_register(); #endif #ifndef CONFIG_NETDEV_LATEINIT /* Initialize the network */ up_netinitialize(); #endif #ifdef CONFIG_NETDEV_LOOPBACK /* Initialize the local loopback device */ (void)localhost_initialize(); #endif #ifdef CONFIG_NET_TUN /* Initialize the TUN device */ (void)tun_initialize(); #endif #ifdef CONFIG_NETDEV_TELNET /* Initialize the Telnet session factory */ (void)telnet_initialize(); #endif /* Initialize USB -- device and/or host */ up_usbinitialize(); board_autoled_on(LED_IRQSENABLED); }
int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype) { /* Is there already a stack allocated of a different size? Because of * alignment issues, stack_size might erroneously appear to be of a * different size. Fortunately, this is not a critical operation. */ if (tcb->stack_alloc_ptr && tcb->adj_stack_size != stack_size) { /* Yes.. Release the old stack */ up_release_stack(tcb, ttype); } /* Do we need to allocate a new stack? */ if (!tcb->stack_alloc_ptr) { /* Allocate the stack. If DEBUG is enabled (but not stack debug), * then create a zeroed stack to make stack dumps easier to trace. */ tcb->stack_alloc_ptr = (uint32_t *)kumm_malloc(stack_size); #ifdef CONFIG_DEBUG /* Was the allocation successful? */ if (!tcb->stack_alloc_ptr) { sdbg("ERROR: Failed to allocate stack, size %d\n", stack_size); } #endif } /* Did we successfully allocate a stack? */ if (tcb->stack_alloc_ptr) { size_t top_of_stack; /* Yes.. If stack debug is enabled, then fill the stack with a * recognizable value that we can use later to test for high * water marks. */ #ifdef CONFIG_STACK_COLORATION memset(tcb->stack_alloc_ptr, STACK_COLOR, stack_size); #endif /* The AVR uses a push-down stack: the stack grows toward lower * addresses in memory. The stack pointer register, points to the * lowest, valid work address (the "top" of the stack). Items on the * stack are referenced as positive word offsets from sp. */ top_of_stack = (size_t)tcb->stack_alloc_ptr + stack_size - 1; /* Save the adjusted stack values in the struct tcb_s */ tcb->adj_stack_ptr = (FAR void *)top_of_stack; tcb->adj_stack_size = stack_size; #if defined(ARCH_HAVE_LEDS) board_autoled_on(LED_STACKCREATED); #endif return OK; } return ERROR; }
void up_sigdeliver(void) { struct tcb_s *rtcb = this_task(); uint32_t regs[XCPTCONTEXT_REGS]; sig_deliver_t sigdeliver; /* Save the errno. This must be preserved throughout the signal handling * so that the user code final gets the correct errno value (probably * EINTR). */ int saved_errno = rtcb->pterrno; board_autoled_on(LED_SIGNAL); sinfo("rtcb=%p sigdeliver=%p sigpendactionq.head=%p\n", rtcb, rtcb->xcp.sigdeliver, rtcb->sigpendactionq.head); ASSERT(rtcb->xcp.sigdeliver != NULL); /* Save the real return state on the stack. */ up_copystate(regs, rtcb->xcp.regs); regs[REG_EPC] = rtcb->xcp.saved_epc; regs[REG_STATUS] = rtcb->xcp.saved_status; /* Get a local copy of the sigdeliver function pointer. We do this so that * we can nullify the sigdeliver function pointer in the TCB and accept * more signal deliveries while processing the current pending signals. */ sigdeliver = rtcb->xcp.sigdeliver; rtcb->xcp.sigdeliver = NULL; /* Then restore the task interrupt state */ up_irq_restore((irqstate_t)regs[REG_STATUS]); /* Deliver the signals */ sigdeliver(rtcb); /* Output any debug messages BEFORE restoring errno (because they may * alter errno), then disable interrupts again and restore the original * errno that is needed by the user logic (it is probably EINTR). */ sinfo("Resuming EPC: %08x STATUS: %08x\n", regs[REG_EPC], regs[REG_STATUS]); (void)up_irq_save(); rtcb->pterrno = saved_errno; /* Then restore the correct state for this thread of * execution. */ board_autoled_off(LED_SIGNAL); up_fullcontextrestore(regs); /* up_fullcontextrestore() should not return but could if the software * interrupts are disabled. */ PANIC(); }
__EXPORT int board_app_initialize(uintptr_t arg) { #if defined(CONFIG_HAVE_CXX) && defined(CONFIG_HAVE_CXXINITIALIZE) /* run C++ ctors before we go any further */ up_cxxinitialize(); # if defined(CONFIG_EXAMPLES_NSH_CXXINITIALIZE) # error CONFIG_EXAMPLES_NSH_CXXINITIALIZE Must not be defined! Use CONFIG_HAVE_CXX and CONFIG_HAVE_CXXINITIALIZE. # endif #else # error platform is dependent on c++ both CONFIG_HAVE_CXX and CONFIG_HAVE_CXXINITIALIZE must be defined. #endif /* configure the high-resolution time/callout interface */ hrt_init(); param_init(); /* configure the DMA allocator */ if (board_dma_alloc_init() < 0) { message("DMA alloc FAILED"); } /* configure CPU load estimation */ #ifdef CONFIG_SCHED_INSTRUMENTATION cpuload_initialize_once(); #endif /* set up the serial DMA polling */ static struct hrt_call serial_dma_call; struct timespec ts; /* * Poll at 1ms intervals for received bytes that have not triggered * a DMA event. */ ts.tv_sec = 0; ts.tv_nsec = 1000000; hrt_call_every(&serial_dma_call, ts_to_abstime(&ts), ts_to_abstime(&ts), (hrt_callout)stm32_serial_dma_poll, NULL); /* initial LED state */ drv_led_start(); led_off(LED_AMBER); /* Configure SPI-based devices */ spi3 = px4_spibus_initialize(3); if (!spi3) { message("[boot] FAILED to initialize SPI port 3\n"); board_autoled_on(LED_AMBER); return -ENODEV; } /* Default SPI3 to 1MHz and de-assert the known chip selects. */ SPI_SETFREQUENCY(spi3, 10000000); SPI_SETBITS(spi3, 8); SPI_SETMODE(spi3, SPIDEV_MODE3); SPI_SELECT(spi3, PX4_SPIDEV_GYRO, false); SPI_SELECT(spi3, PX4_SPIDEV_ACCEL_MAG, false); SPI_SELECT(spi3, PX4_SPIDEV_BARO, false); up_udelay(20); /* Get the SPI port for the FRAM */ spi4 = px4_spibus_initialize(4); if (!spi4) { message("[boot] FAILED to initialize SPI port 4\n"); board_autoled_on(LED_AMBER); return -ENODEV; } /* Default SPI4 to 37.5 MHz (40 MHz rounded to nearest valid divider, F4 max) * and de-assert the known chip selects. */ // XXX start with 10.4 MHz in FRAM usage and go up to 37.5 once validated SPI_SETFREQUENCY(spi4, 12 * 1000 * 1000); SPI_SETBITS(spi4, 8); SPI_SETMODE(spi4, SPIDEV_MODE3); SPI_SELECT(spi4, SPIDEV_FLASH(0), false); return OK; }
void up_allocate_heap(FAR void **heap_start, size_t *heap_size) { board_autoled_on(LED_HEAPALLOCATE); *heap_start = (FAR void *)g_idle_topstack; *heap_size = CONFIG_RAM_END - g_idle_topstack; }
void up_initialize(void) { /* Initialize global variables */ g_current_regs = NULL; /* Calibrate the timing loop */ up_calibratedelay(); /* Initialize the interrupt subsystem */ up_irqinitialize(); #ifdef CONFIG_PM /* Initialize the power management subsystem. This MCU-specific function * must be called *very* early in the initialization sequence *before* any * other device drivers are initialized (since they may attempt to register * with the power management subsystem). */ up_pminitialize(); #endif #if !defined(CONFIG_SUPPRESS_INTERRUPTS) && !defined(CONFIG_SUPPRESS_TIMER_INTS) /* Initialize the system timer interrupt */ up_timer_initialize(); #endif /* Register devices */ #if CONFIG_NFILE_DESCRIPTORS > 0 #if defined(CONFIG_DEV_NULL) devnull_register(); /* Standard /dev/null */ #endif #if defined(CONFIG_DEV_RANDOM) devrandom_register(); /* Standard /dev/random */ #endif #if defined(CONFIG_DEV_URANDOM) devurandom_register(); /* Standard /dev/urandom */ #endif #if defined(CONFIG_DEV_ZERO) devzero_register(); /* Standard /dev/zero */ #endif #if defined(CONFIG_DEV_LOOP) loop_register(); /* Standard /dev/loop */ #endif #endif /* CONFIG_NFILE_DESCRIPTORS */ #if defined(CONFIG_SCHED_INSTRUMENTATION_BUFFER) && \ defined(CONFIG_DRIVER_NOTE) note_register(); /* Non-standard /dev/note */ #endif /* Initialize the serial device driver */ #ifdef USE_SERIALDRIVER up_serialinit(); #endif /* Initialize the console device driver (if it is other than the standard * serial driver). NOTE that the naming implies that the console is a serial * driver. That is usually the case, however, if no UARTs are enabled, the * console could als be provided through some other device, such as an LCD. * Architecture-specific logic will have to detect that case. */ #if defined(CONFIG_DEV_LOWCONSOLE) lowconsole_init(); #elif defined(CONFIG_CONSOLE_SYSLOG) syslog_console_init(); #elif defined(CONFIG_RAMLOG_CONSOLE) ramlog_consoleinit(); #endif #if CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_PSEUDOTERM_SUSV1) /* Register the master pseudo-terminal multiplexor device */ (void)ptmx_register(); #endif /* Early initialization of the system logging device. Some SYSLOG channel * can be initialized early in the initialization sequence because they * depend on only minimal OS initialization. */ syslog_initialize(SYSLOG_INIT_EARLY); #if defined(CONFIG_CRYPTO) /* Initialize the HW crypto and /dev/crypto */ up_cryptoinitialize(); #endif #if CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_CRYPTO_CRYPTODEV) devcrypto_register(); #endif #ifndef CONFIG_NETDEV_LATEINIT /* Initialize the network */ up_netinitialize(); #endif #ifdef CONFIG_NETDEV_LOOPBACK /* Initialize the local loopback device */ (void)localhost_initialize(); #endif #ifdef CONFIG_NET_TUN /* Initialize the TUN device */ (void)tun_initialize(); #endif #ifdef CONFIG_NETDEV_TELNET /* Initialize the Telnet session factory */ (void)telnet_initialize(); #endif /* Initialize USB */ up_usbinitialize(); board_autoled_on(LED_IRQSENABLED); }
uint32_t *up_doirq(int irq, uint32_t* regs) { board_autoled_on(LED_INIRQ); #ifdef CONFIG_SUPPRESS_INTERRUPTS PANIC(); #else if ((unsigned)irq < NR_IRQS) { /* Current regs non-zero indicates that we are processing * an interrupt; g_current_regs is also used to manage * interrupt level context switches. * * Nested interrupts are not supported. */ DEBUGASSERT(g_current_regs == NULL); g_current_regs = regs; /* Deliver the IRQ */ irq_dispatch(irq, regs); #if defined(CONFIG_ARCH_FPU) || defined(CONFIG_ARCH_ADDRENV) /* Check for a context switch. If a context switch occurred, then * g_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 != g_current_regs) { #ifdef CONFIG_ARCH_FPU /* Restore floating point registers */ up_restorefpu((uint32_t*)g_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. */ (void)group_addrenv(NULL); #endif } #endif /* Get the current value of regs... it may have changed because * of a context switch performed during interrupt processing. */ regs = g_current_regs; /* Set g_current_regs to NULL to indicate that we are no longer in an * interrupt handler. */ g_current_regs = NULL; } board_autoled_off(LED_INIRQ); #endif return regs; }
void up_initialize(void) { /* Initialize global variables */ INIT_IRQCONTEXT(); /* Calibrate the timing loop */ up_calibratedelay(); #if CONFIG_MM_REGIONS > 1 /* Add any extra memory fragments to the memory manager */ up_addregion(); #endif /* Initialize the interrupt subsystem */ up_irqinitialize(); #ifdef CONFIG_PM /* Initialize the power management subsystem. This MCU-specific function * must be called *very* early in the initialization sequence *before* any * other device drivers are initialized (since they may attempt to register * with the power management subsystem). */ up_pminitialize(); #endif #if !defined(CONFIG_SUPPRESS_INTERRUPTS) && !defined(CONFIG_SUPPRESS_TIMER_INTS) /* Initialize the system timer interrupt */ z80_timer_initialize(); #endif /* Initialize the CPU for those that use it (only for the Z180). This * needs to be done before any tasks are created). */ #ifdef CONFIG_ARCH_ADDRENV (void)up_mmuinit(); #endif #ifdef CONFIG_MM_IOB /* Initialize IO buffering */ iob_initialize(); #endif #if CONFIG_NFILE_DESCRIPTORS > 0 /* Register devices */ #if defined(CONFIG_DEV_NULL) devnull_register(); /* Standard /dev/null */ #endif #if defined(CONFIG_DEV_RANDOM) devrandom_register(); /* Standard /dev/random */ #endif #if defined(CONFIG_DEV_URANDOM) devurandom_register(); /* Standard /dev/urandom */ #endif #if defined(CONFIG_DEV_ZERO) devzero_register(); /* Standard /dev/zero */ #endif #if defined(CONFIG_DEV_LOOP) loop_register(); /* Standard /dev/loop */ #endif #endif /* CONFIG_NFILE_DESCRIPTORS */ #if defined(CONFIG_SCHED_INSTRUMENTATION_BUFFER) && \ defined(CONFIG_DRIVER_NOTE) note_register(); /* Non-standard /dev/note */ #endif /* Initialize the serial device driver */ #ifdef USE_SERIALDRIVER up_serialinit(); #endif /* Initialize the console device driver (if it is other than the standard * serial driver). */ #if defined(CONFIG_DEV_LOWCONSOLE) lowconsole_init(); #elif defined(CONFIG_CONSOLE_SYSLOG) syslog_console_init(); #elif defined(CONFIG_RAMLOG_CONSOLE) ramlog_consoleinit(); #endif #if CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_PSEUDOTERM_SUSV1) /* Register the master pseudo-terminal multiplexor device */ (void)ptmx_register(); #endif /* Early initialization of the system logging device. Some SYSLOG channel * can be initialized early in the initialization sequence because they * depend on minimal OS initialization. */ syslog_initialize(SYSLOG_INIT_EARLY); #if defined(CONFIG_CRYPTO) /* Initialize the HW crypto and /dev/crypto */ up_cryptoinitialize(); #endif #if CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_CRYPTO_CRYPTODEV) devcrypto_register(); #endif #ifndef CONFIG_NETDEV_LATEINIT /* Initialize the network */ up_netinitialize(); #endif #ifdef CONFIG_NETDEV_LOOPBACK /* Initialize the local loopback device */ (void)localhost_initialize(); #endif #ifdef CONFIG_NET_TUN /* Initialize the TUN device */ (void)tun_initialize(); #endif #ifdef CONFIG_NETDEV_TELNET /* Initialize the Telnet session factory */ (void)telnet_initialize(); #endif board_autoled_on(LED_IRQSENABLED); }
__EXPORT int board_app_initialize(uintptr_t arg) { int result; /* IN12 and IN13 further below */ #if defined(CONFIG_HAVE_CXX) && defined(CONFIG_HAVE_CXXINITIALIZE) /* run C++ ctors before we go any further */ up_cxxinitialize(); # if defined(CONFIG_EXAMPLES_NSH_CXXINITIALIZE) # error CONFIG_EXAMPLES_NSH_CXXINITIALIZE Must not be defined! Use CONFIG_HAVE_CXX and CONFIG_HAVE_CXXINITIALIZE. # endif #else # error platform is dependent on c++ both CONFIG_HAVE_CXX and CONFIG_HAVE_CXXINITIALIZE must be defined. #endif /* configure the high-resolution time/callout interface */ hrt_init(); /* configure CPU load estimation */ #ifdef CONFIG_SCHED_INSTRUMENTATION cpuload_initialize_once(); #endif /* set up the serial DMA polling */ static struct hrt_call serial_dma_call; struct timespec ts; /* * Poll at 1ms intervals for received bytes that have not triggered * a DMA event. */ ts.tv_sec = 0; ts.tv_nsec = 1000000; hrt_call_every(&serial_dma_call, ts_to_abstime(&ts), ts_to_abstime(&ts), (hrt_callout)stm32_serial_dma_poll, NULL); /* initial LED state */ drv_led_start(); led_off(LED_AMBER); led_off(LED_BLUE); /* Configure SPI-based devices */ spi1 = stm32_spibus_initialize(1); if (!spi1) { message("[boot] FAILED to initialize SPI port 1\r\n"); board_autoled_on(LED_AMBER); return -ENODEV; } /* Default SPI1 to 1MHz and de-assert the known chip selects. */ SPI_SETFREQUENCY(spi1, 10000000); SPI_SETBITS(spi1, 8); SPI_SETMODE(spi1, SPIDEV_MODE3); SPI_SELECT(spi1, PX4_SPIDEV_GYRO, false); SPI_SELECT(spi1, PX4_SPIDEV_ACCEL, false); SPI_SELECT(spi1, PX4_SPIDEV_MPU, false); up_udelay(20); /* * If SPI2 is enabled in the defconfig, we loose some ADC pins as chip selects. * Keep the SPI2 init optional and conditionally initialize the ADC pins */ #ifdef CONFIG_STM32_SPI2 spi2 = stm32_spibus_initialize(2); /* Default SPI2 to 1MHz and de-assert the known chip selects. */ SPI_SETFREQUENCY(spi2, 10000000); SPI_SETBITS(spi2, 8); SPI_SETMODE(spi2, SPIDEV_MODE3); SPI_SELECT(spi2, PX4_SPIDEV_GYRO, false); SPI_SELECT(spi2, PX4_SPIDEV_ACCEL_MAG, false); message("[boot] Initialized SPI port2 (ADC IN12/13 blocked)\n"); #else spi2 = NULL; message("[boot] Enabling IN12/13 instead of SPI2\n"); /* no SPI2, use pins for ADC */ stm32_configgpio(GPIO_ADC1_IN12); stm32_configgpio(GPIO_ADC1_IN13); // jumperable to MPU6000 DRDY on some boards #endif /* Get the SPI port for the microSD slot */ spi3 = stm32_spibus_initialize(3); if (!spi3) { message("[boot] FAILED to initialize SPI port 3\n"); board_autoled_on(LED_AMBER); return -ENODEV; } /* Now bind the SPI interface to the MMCSD driver */ result = mmcsd_spislotinitialize(CONFIG_NSH_MMCSDMINOR, CONFIG_NSH_MMCSDSLOTNO, spi3); if (result != OK) { message("[boot] FAILED to bind SPI port 3 to the MMCSD driver\n"); board_autoled_on(LED_AMBER); return -ENODEV; } return OK; }
void up_sigdeliver(void) { struct tcb_s *rtcb = this_task(); uint32_t regs[XCPTCONTEXT_REGS]; sig_deliver_t sigdeliver; /* Save the errno. This must be preserved throughout the signal handling * so that the user code final gets the correct errno value (probably * EINTR). */ int saved_errno = rtcb->pterrno; board_autoled_on(LED_SIGNAL); sdbg("rtcb=%p sigdeliver=%p sigpendactionq.head=%p\n", rtcb, rtcb->xcp.sigdeliver, rtcb->sigpendactionq.head); ASSERT(rtcb->xcp.sigdeliver != NULL); /* Save the real return state on the stack. */ up_copyfullstate(regs, rtcb->xcp.regs); regs[REG_PC] = rtcb->xcp.saved_pc; #ifdef CONFIG_ARMV7M_USEBASEPRI regs[REG_BASEPRI] = rtcb->xcp.saved_basepri; #else regs[REG_PRIMASK] = rtcb->xcp.saved_primask; #endif regs[REG_XPSR] = rtcb->xcp.saved_xpsr; #ifdef CONFIG_BUILD_PROTECTED regs[REG_LR] = rtcb->xcp.saved_lr; #endif /* Get a local copy of the sigdeliver function pointer. We do this so that * we can nullify the sigdeliver function pointer in the TCB and accept * more signal deliveries while processing the current pending signals. */ sigdeliver = rtcb->xcp.sigdeliver; rtcb->xcp.sigdeliver = NULL; /* Then restore the task interrupt state */ #ifdef CONFIG_ARMV7M_USEBASEPRI irqrestore((uint8_t)regs[REG_BASEPRI]); #else irqrestore((uint16_t)regs[REG_PRIMASK]); #endif /* Deliver the signal */ sigdeliver(rtcb); /* Output any debug messages BEFORE restoring errno (because they may * alter errno), then disable interrupts again and restore the original * errno that is needed by the user logic (it is probably EINTR). */ sdbg("Resuming\n"); (void)irqsave(); rtcb->pterrno = saved_errno; /* Then restore the correct state for this thread of * execution. */ board_autoled_off(LED_SIGNAL); up_fullcontextrestore(regs); }
__EXPORT int board_app_initialize(uintptr_t arg) { #if defined(CONFIG_HAVE_CXX) && defined(CONFIG_HAVE_CXXINITIALIZE) /* run C++ ctors before we go any further */ up_cxxinitialize(); # if defined(CONFIG_EXAMPLES_NSH_CXXINITIALIZE) # error CONFIG_EXAMPLES_NSH_CXXINITIALIZE Must not be defined! Use CONFIG_HAVE_CXX and CONFIG_HAVE_CXXINITIALIZE. # endif #else # error platform is dependent on c++ both CONFIG_HAVE_CXX and CONFIG_HAVE_CXXINITIALIZE must be defined. #endif /* configure the high-resolution time/callout interface */ hrt_init(); /* configure the DMA allocator */ if (board_dma_alloc_init() < 0) { message("DMA alloc FAILED"); } /* configure CPU load estimation */ #ifdef CONFIG_SCHED_INSTRUMENTATION cpuload_initialize_once(); #endif /* set up the serial DMA polling */ static struct hrt_call serial_dma_call; struct timespec ts; /* * Poll at 1ms intervals for received bytes that have not triggered * a DMA event. */ ts.tv_sec = 0; ts.tv_nsec = 1000000; hrt_call_every(&serial_dma_call, ts_to_abstime(&ts), ts_to_abstime(&ts), (hrt_callout)stm32_serial_dma_poll, NULL); #if defined(CONFIG_STM32_BBSRAM) /* NB. the use of the console requires the hrt running * to poll the DMA */ /* Using Battery Backed Up SRAM */ int filesizes[CONFIG_STM32_BBSRAM_FILES + 1] = BSRAM_FILE_SIZES; stm32_bbsraminitialize(BBSRAM_PATH, filesizes); #if defined(CONFIG_STM32_SAVE_CRASHDUMP) /* Panic Logging in Battery Backed Up Files */ /* * In an ideal world, if a fault happens in flight the * system save it to BBSRAM will then reboot. Upon * rebooting, the system will log the fault to disk, recover * the flight state and continue to fly. But if there is * a fault on the bench or in the air that prohibit the recovery * or committing the log to disk, the things are too broken to * fly. So the question is: * * Did we have a hard fault and not make it far enough * through the boot sequence to commit the fault data to * the SD card? */ /* Do we have an uncommitted hard fault in BBSRAM? * - this will be reset after a successful commit to SD */ int hadCrash = hardfault_check_status("boot"); if (hadCrash == OK) { message("[boot] There is a hard fault logged. Hold down the SPACE BAR," \ " while booting to halt the system!\n"); /* Yes. So add one to the boot count - this will be reset after a successful * commit to SD */ int reboots = hardfault_increment_reboot("boot", false); /* Also end the misery for a user that holds for a key down on the console */ int bytesWaiting; ioctl(fileno(stdin), FIONREAD, (unsigned long)((uintptr_t) &bytesWaiting)); if (reboots > 2 || bytesWaiting != 0) { /* Since we can not commit the fault dump to disk. Display it * to the console. */ hardfault_write("boot", fileno(stdout), HARDFAULT_DISPLAY_FORMAT, false); message("[boot] There were %d reboots with Hard fault that were not committed to disk - System halted %s\n", reboots, (bytesWaiting == 0 ? "" : " Due to Key Press\n")); /* For those of you with a debugger set a break point on up_assert and * then set dbgContinue = 1 and go. */ /* Clear any key press that got us here */ static volatile bool dbgContinue = false; int c = '>'; while (!dbgContinue) { switch (c) { case EOF: case '\n': case '\r': case ' ': continue; default: putchar(c); putchar('\n'); switch (c) { case 'D': case 'd': hardfault_write("boot", fileno(stdout), HARDFAULT_DISPLAY_FORMAT, false); break; case 'C': case 'c': hardfault_rearm("boot"); hardfault_increment_reboot("boot", true); break; case 'B': case 'b': dbgContinue = true; break; default: break; } // Inner Switch message("\nEnter B - Continue booting\n" \ "Enter C - Clear the fault log\n" \ "Enter D - Dump fault log\n\n?>"); fflush(stdout); if (!dbgContinue) { c = getchar(); } break; } // outer switch } // for } // inner if } // outer if #endif // CONFIG_STM32_SAVE_CRASHDUMP #endif // CONFIG_STM32_BBSRAM /* initial LED state */ drv_led_start(); led_off(LED_RED); led_off(LED_GREEN); led_off(LED_BLUE); /* Configure SPI-based devices */ spi1 = stm32_spibus_initialize(1); if (!spi1) { message("[boot] FAILED to initialize SPI port 1\n"); board_autoled_on(LED_RED); return -ENODEV; } /* Default SPI1 to 1MHz and de-assert the known chip selects. */ SPI_SETFREQUENCY(spi1, 10000000); SPI_SETBITS(spi1, 8); SPI_SETMODE(spi1, SPIDEV_MODE3); SPI_SELECT(spi1, PX4_SPIDEV_GYRO, false); SPI_SELECT(spi1, PX4_SPIDEV_HMC, false); SPI_SELECT(spi1, PX4_SPIDEV_MPU, false); up_udelay(20); /* Get the SPI port for the FRAM */ spi2 = stm32_spibus_initialize(2); if (!spi2) { message("[boot] FAILED to initialize SPI port 2\n"); board_autoled_on(LED_RED); return -ENODEV; } /* Default SPI2 to 12MHz and de-assert the known chip selects. * MS5611 has max SPI clock speed of 20MHz */ // XXX start with 10.4 MHz and go up to 20 once validated SPI_SETFREQUENCY(spi2, 20 * 1000 * 1000); SPI_SETBITS(spi2, 8); SPI_SETMODE(spi2, SPIDEV_MODE3); SPI_SELECT(spi2, SPIDEV_FLASH, false); SPI_SELECT(spi2, PX4_SPIDEV_BARO, false); #ifdef CONFIG_MMCSD /* First, get an instance of the SDIO interface */ sdio = sdio_initialize(CONFIG_NSH_MMCSDSLOTNO); if (!sdio) { message("[boot] Failed to initialize SDIO slot %d\n", CONFIG_NSH_MMCSDSLOTNO); return -ENODEV; } /* Now bind the SDIO interface to the MMC/SD driver */ int ret = mmcsd_slotinitialize(CONFIG_NSH_MMCSDMINOR, sdio); if (ret != OK) { message("[boot] Failed to bind SDIO to the MMC/SD driver: %d\n", ret); return ret; } /* Then let's guess and say that there is a card in the slot. There is no card detect GPIO. */ sdio_mediachange(sdio, true); #endif return OK; }
void up_initialize(void) { /* Colorize the interrupt stack */ up_color_intstack(); /* Add any extra memory fragments to the memory manager */ up_addregion(); /* Initialize the interrupt subsystem */ up_irqinitialize(); /* Initialize the system timer interrupt */ #if !defined(CONFIG_SUPPRESS_INTERRUPTS) && !defined(CONFIG_SUPPRESS_TIMER_INTS) && \ !defined(CONFIG_SYSTEMTICK_EXTCLK) riscv_timer_initialize(); #endif #ifdef CONFIG_MM_IOB /* Initialize IO buffering */ iob_initialize(); #endif #if CONFIG_NFILE_DESCRIPTORS > 0 /* Register devices */ #if defined(CONFIG_DEV_NULL) devnull_register(); /* Standard /dev/null */ #endif #if defined(CONFIG_DEV_ZERO) devzero_register(); /* Standard /dev/zero */ #endif #endif /* CONFIG_NFILE_DESCRIPTORS */ /* Initialize the serial device driver */ #ifdef USE_SERIALDRIVER up_serialinit(); #endif /* Initialize the console device driver (if it is other than the standard * serial driver). */ #if defined(CONFIG_DEV_LOWCONSOLE) lowconsole_init(); #elif defined(CONFIG_SYSLOG_CONSOLE) syslog_console_init(); #elif defined(CONFIG_RAMLOG_CONSOLE) ramlog_consoleinit(); #endif #if CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_PSEUDOTERM_SUSV1) /* Register the master pseudo-terminal multiplexor device */ (void)ptmx_register(); #endif /* Early initialization of the system logging device. Some SYSLOG channel * can be initialized early in the initialization sequence because they * depend on only minimal OS initialization. */ syslog_initialize(SYSLOG_INIT_EARLY); #ifdef CONFIG_RAMLOG_SYSLOG ramlog_sysloginit(); #endif board_autoled_on(LED_IRQSENABLED); }