mirror of
https://github.com/stnolting/neorv32.git
synced 2025-04-19 11:55:05 -04:00
[sw/lib] add CSR swap function
Some checks failed
Processor / processor simulation (push) Has been cancelled
Some checks failed
Processor / processor simulation (push) Has been cancelled
This commit is contained in:
parent
dbbba7631e
commit
efe240254b
1 changed files with 15 additions and 0 deletions
|
@ -213,6 +213,21 @@ inline void __attribute__ ((always_inline)) neorv32_cpu_csr_clr(const int csr_id
|
|||
}
|
||||
|
||||
|
||||
/**********************************************************************//**
|
||||
* Atomic write-after-read CSR operation.
|
||||
*
|
||||
* @param[in] csr_id ID of CSR. See #NEORV32_CSR_enum.
|
||||
* @param[in] wdata New data to write to selected CSR.
|
||||
* @return Old data read from selected CSR.
|
||||
**************************************************************************/
|
||||
inline uint32_t __attribute__ ((always_inline)) neorv32_cpu_csr_swap(const int csr_id, uint32_t wdata) {
|
||||
|
||||
uint32_t tmp;
|
||||
asm volatile ("csrrw %[dst], %[id], %[src]" : [dst] "=r" (tmp) : [id] "i" (csr_id), [src] "r" (wdata));
|
||||
return tmp;
|
||||
}
|
||||
|
||||
|
||||
/**********************************************************************//**
|
||||
* Put CPU into sleep / power-down mode.
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue