-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
If the system is reset while a SPI access is going on, the SPI device might not be in the correct state and using it directly will fail, and we don't show helpful message in this case, just "Failed ELF Magic Check". Add a software reset sequence to reset it to a well known state before accessing.
- Loading branch information
Showing
3 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#pragma once | ||
#include <stdint.h> | ||
|
||
static inline uint32_t get_mcycle(void) | ||
{ | ||
uint32_t result; | ||
asm volatile("csrr %0, mcycle;" : "=r"(result)); | ||
return result; | ||
} | ||
|
||
static inline void reset_mcycle(void) | ||
{ | ||
asm volatile("csrw mcycle, x0"); | ||
} | ||
|
||
static inline void wait_mcycle(uint32_t value) | ||
{ | ||
reset_mcycle(); | ||
while (get_mcycle() < value) {} | ||
} |