🐛 [sw/bootloader] fixed bug in bootloader's (M)TIME handling

This commit is contained in:
stnolting 2022-01-31 08:27:36 +01:00
parent 8d02a57749
commit 2b06872fbf

View file

@ -3,7 +3,7 @@
// # ********************************************************************************************* #
// # BSD 3-Clause License #
// # #
// # Copyright (c) 2021, Stephan Nolting. All rights reserved. #
// # Copyright (c) 2022, Stephan Nolting. All rights reserved. #
// # #
// # Redistribution and use in source and binary forms, with or without modification, are #
// # permitted provided that the following conditions are met: #
@ -331,9 +331,9 @@ int main(void) {
neorv32_uart0_setup(UART_BAUD, PARITY_NONE, FLOW_CONTROL_NONE);
#endif
// Configure machine system timer interrupt for ~2Hz
// Configure machine system timer interrupt
if (neorv32_mtime_available()) {
neorv32_mtime_set_timecmp(neorv32_cpu_get_systime() + (NEORV32_SYSINFO.CLK/4));
neorv32_mtime_set_timecmp(0 + (NEORV32_SYSINFO.CLK/4));
// active timer IRQ
neorv32_cpu_csr_write(CSR_MIE, 1 << CSR_MIE_MTIE); // activate MTIME IRQ source only!
neorv32_cpu_eint(); // enable global interrupts
@ -372,7 +372,7 @@ int main(void) {
if (neorv32_mtime_available()) {
PRINT_TEXT("\n\nAutoboot in "xstr(AUTO_BOOT_TIMEOUT)"s. Press key to abort.\n");
uint64_t timeout_time = neorv32_cpu_get_systime() + (uint64_t)(AUTO_BOOT_TIMEOUT * NEORV32_SYSINFO.CLK);
uint64_t timeout_time = neorv32_mtime_get_time() + (uint64_t)(AUTO_BOOT_TIMEOUT * NEORV32_SYSINFO.CLK);
while(1){
@ -382,7 +382,7 @@ int main(void) {
}
}
if (neorv32_cpu_get_systime() >= timeout_time) { // timeout? start auto boot sequence
if (neorv32_mtime_get_time() >= timeout_time) { // timeout? start auto boot sequence
get_exe(EXE_STREAM_FLASH); // try booting from flash
PRINT_TEXT("\n");
start_app();
@ -504,7 +504,7 @@ void __attribute__((__interrupt__)) bootloader_trap_handler(void) {
#endif
// set time for next IRQ
if (neorv32_mtime_available()) {
neorv32_mtime_set_timecmp(neorv32_cpu_get_systime() + (NEORV32_SYSINFO.CLK/4));
neorv32_mtime_set_timecmp(neorv32_mtime_get_timecmp() + (NEORV32_SYSINFO.CLK/4));
}
}