Skip to content

Commit

Permalink
Merge pull request #191 from sifive/esat-25
Browse files Browse the repository at this point in the history
Add macro & inline for get/set CSR
  • Loading branch information
bsousi5 authored Oct 7, 2019
2 parents 56bb58e + 931bd23 commit 55b9f2b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ nobase_include_HEADERS = \
metal/clock.h \
metal/compiler.h \
metal/cpu.h \
metal/csr.h \
metal/gpio.h \
metal/init.h \
metal/interrupt.h \
Expand Down
1 change: 1 addition & 0 deletions Makefile.in

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions metal/csr.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* Copyright 2019 SiFive, Inc */
/* SPDX-License-Identifier: Apache-2.0 */

#ifndef METAL__CSR_H
#define METAL__CSR_H

#include <metal/compiler.h>
#include <stddef.h>
#include <stdint.h>

/*!
* @file csr.h
* @brief A collection of APIs for get and set CSR registers
*/

/*!
* @brief Read a given CSR register without checking validity of CSR offset
* @param crs Register label or hex value offset to read from
* @param value Variable name of uintprt_t type to get the value
*/
#define METAL_CPU_GET_CSR(reg, value) \
__asm__ volatile("csrr %0, " #reg : "=r"(value));

/*!
* @brief Write to a given CSR register without checking validity of CSR offset
* @param crs Register label or hex value offset to write to
* @param value Variable name of uintprt_t type to set the value
*/
#define METAL_CPU_SET_CSR(reg, value) \
__asm__ volatile("csrw " #reg ", %0" : : "r"(value));

#endif // METAL__CSR_H

0 comments on commit 55b9f2b

Please sign in to comment.