Merge pull request #3469 from jepler/noreturn

Add some NORETURN attributes
This commit is contained in:
Scott Shawcroft 2020-10-01 11:18:36 -07:00 committed by GitHub
commit d62ac24493
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 40 additions and 10 deletions

View File

@ -29,6 +29,8 @@
#include "reset.h" #include "reset.h"
#include "supervisor/filesystem.h" #include "supervisor/filesystem.h"
void NVIC_SystemReset(void) NORETURN;
void reset(void) { void reset(void) {
filesystem_flush(); filesystem_flush();
NVIC_SystemReset(); NVIC_SystemReset();

View File

@ -29,14 +29,16 @@
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include "py/mpconfig.h"
// Copied from inc/uf2.h in https://github.com/Microsoft/uf2-samd21 // Copied from inc/uf2.h in https://github.com/Microsoft/uf2-samd21
#define DBL_TAP_MAGIC 0xf01669ef // Randomly selected, adjusted to have first and last bit set #define DBL_TAP_MAGIC 0xf01669ef // Randomly selected, adjusted to have first and last bit set
#define DBL_TAP_MAGIC_QUICK_BOOT 0xf02669ef #define DBL_TAP_MAGIC_QUICK_BOOT 0xf02669ef
extern uint32_t _bootloader_dbl_tap; extern uint32_t _bootloader_dbl_tap;
void reset_to_bootloader(void); void reset_to_bootloader(void) NORETURN;
void reset(void); void reset(void) NORETURN;
bool bootloader_available(void); bool bootloader_available(void);
#endif // MICROPY_INCLUDED_ATMEL_SAMD_RESET_H #endif // MICROPY_INCLUDED_ATMEL_SAMD_RESET_H

View File

@ -71,6 +71,8 @@ safe_mode_t port_init(void) {
void reset_cpu(void) { void reset_cpu(void) {
boardctl(BOARDIOC_RESET, 0); boardctl(BOARDIOC_RESET, 0);
for (;;) {
}
} }
void reset_port(void) { void reset_port(void) {
@ -91,6 +93,9 @@ void reset_port(void) {
} }
void reset_to_bootloader(void) { void reset_to_bootloader(void) {
boardctl(BOARDIOC_RESET, 0);
for (;;) {
}
} }
supervisor_allocation* port_fixed_stack(void) { supervisor_allocation* port_fixed_stack(void) {

View File

@ -56,6 +56,8 @@ uint32_t heap_size;
STATIC esp_timer_handle_t _tick_timer; STATIC esp_timer_handle_t _tick_timer;
extern void esp_restart(void) NORETURN;
void tick_timer_cb(void* arg) { void tick_timer_cb(void* arg) {
supervisor_tick(); supervisor_tick();
} }
@ -118,9 +120,11 @@ void reset_port(void) {
} }
void reset_to_bootloader(void) { void reset_to_bootloader(void) {
esp_restart();
} }
void reset_cpu(void) { void reset_cpu(void) {
esp_restart();
} }
uint32_t *port_heap_get_bottom(void) { uint32_t *port_heap_get_bottom(void) {

View File

@ -85,9 +85,17 @@ void reset_port(void) {
void reset_to_bootloader(void) { void reset_to_bootloader(void) {
reboot_ctrl_write(0xac); reboot_ctrl_write(0xac);
for(;;) {}
} }
void reset_cpu(void) { void reset_cpu(void) {
// "You can reset Fomu by writing a special value to the CSR_REBOOT_CTRL
// register at 0xe0006000L. All writes to this register must start with
// 0xac, to ensure random values arent written. We can reboot Fomu by
// simply writing this value" --
// https://workshop.fomu.im/en/latest/riscv.html
reboot_ctrl_write(0xac);
for(;;) {}
} }
supervisor_allocation* port_fixed_stack(void) { supervisor_allocation* port_fixed_stack(void) {

View File

@ -30,12 +30,14 @@
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include "py/mpconfig.h"
// Copied from inc/uf2.h in https://github.com/Microsoft/uf2-samd21 // Copied from inc/uf2.h in https://github.com/Microsoft/uf2-samd21
#define DBL_TAP_MAGIC 0xf01669ef // Randomly selected, adjusted to have first and last bit set #define DBL_TAP_MAGIC 0xf01669ef // Randomly selected, adjusted to have first and last bit set
#define DBL_TAP_MAGIC_QUICK_BOOT 0xf02669ef #define DBL_TAP_MAGIC_QUICK_BOOT 0xf02669ef
void reset_to_bootloader(void); void reset_to_bootloader(void) NORETURN;
void reset(void); void reset(void) NORETURN;
bool bootloader_available(void); bool bootloader_available(void);
#endif // MICROPY_INCLUDED_MIMXRT10XX_RESET_H #endif // MICROPY_INCLUDED_MIMXRT10XX_RESET_H

View File

@ -234,6 +234,8 @@ void reset_cpu(void) {
uint32_t ticks = nrfx_rtc_counter_get(&rtc_instance); uint32_t ticks = nrfx_rtc_counter_get(&rtc_instance);
overflow_tracker.overflowed_ticks += ticks / 32; overflow_tracker.overflowed_ticks += ticks / 32;
NVIC_SystemReset(); NVIC_SystemReset();
for (;;) {
}
} }
// The uninitialized data section is placed directly after BSS, under the theory // The uninitialized data section is placed directly after BSS, under the theory

View File

@ -56,6 +56,8 @@
#include STM32_HAL_H #include STM32_HAL_H
void NVIC_SystemReset(void) NORETURN;
#if (CPY_STM32H7) || (CPY_STM32F7) #if (CPY_STM32H7) || (CPY_STM32F7)
// Device memories must be accessed in order. // Device memories must be accessed in order.
@ -247,7 +249,7 @@ void reset_port(void) {
} }
void reset_to_bootloader(void) { void reset_to_bootloader(void) {
NVIC_SystemReset();
} }
void reset_cpu(void) { void reset_cpu(void) {

View File

@ -44,7 +44,7 @@ extern uint32_t _ebss;
safe_mode_t port_init(void); safe_mode_t port_init(void);
// Reset the microcontroller completely. // Reset the microcontroller completely.
void reset_cpu(void); void reset_cpu(void) NORETURN;
// Reset the microcontroller state. // Reset the microcontroller state.
void reset_port(void); void reset_port(void);
@ -53,7 +53,7 @@ void reset_port(void);
void reset_board(void); void reset_board(void);
// Reset to the bootloader // Reset to the bootloader
void reset_to_bootloader(void); void reset_to_bootloader(void) NORETURN;
// Get stack limit address // Get stack limit address
uint32_t *port_stack_get_limit(void); uint32_t *port_stack_get_limit(void);

View File

@ -27,6 +27,8 @@
#ifndef MICROPY_INCLUDED_SUPERVISOR_SAFE_MODE_H #ifndef MICROPY_INCLUDED_SUPERVISOR_SAFE_MODE_H
#define MICROPY_INCLUDED_SUPERVISOR_SAFE_MODE_H #define MICROPY_INCLUDED_SUPERVISOR_SAFE_MODE_H
#include "py/mpconfig.h"
typedef enum { typedef enum {
NO_SAFE_MODE = 0, NO_SAFE_MODE = 0,
BROWNOUT, BROWNOUT,
@ -48,7 +50,7 @@ typedef enum {
safe_mode_t wait_for_safe_mode_reset(void); safe_mode_t wait_for_safe_mode_reset(void);
void safe_mode_on_next_reset(safe_mode_t reason); void safe_mode_on_next_reset(safe_mode_t reason);
void reset_into_safe_mode(safe_mode_t reason); void reset_into_safe_mode(safe_mode_t reason) NORETURN;
void print_safe_mode_message(safe_mode_t reason); void print_safe_mode_message(safe_mode_t reason);

View File

@ -26,14 +26,15 @@
#include "supervisor/shared/safe_mode.h" #include "supervisor/shared/safe_mode.h"
#include <stdlib.h>
safe_mode_t wait_for_safe_mode_reset(void) { safe_mode_t wait_for_safe_mode_reset(void) {
return NO_SAFE_MODE; return NO_SAFE_MODE;
} }
void reset_into_safe_mode(safe_mode_t reason) { void reset_into_safe_mode(safe_mode_t reason) {
(void) reason; (void) reason;
for (;;) { abort();
}
} }
void print_safe_mode_message(safe_mode_t reason) { void print_safe_mode_message(safe_mode_t reason) {