123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392 |
- /********************************** (C) COPYRIGHT *******************************
- * File Name : core_riscv.c
- * Author : WCH
- * Version : V1.0.1
- * Date : 2023/11/11
- * Description : RISC-V V4 Core Peripheral Access Layer Source File for CH32V30x
- *********************************************************************************
- * Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
- * Attention: This software (modified or not) and binary are used for
- * microcontroller manufactured by Nanjing Qinheng Microelectronics.
- *******************************************************************************/
- #include <stdint.h>
- /* define compiler specific symbols */
- #if defined ( __CC_ARM )
- #define __ASM __asm /*!< asm keyword for ARM Compiler */
- #define __INLINE __inline /*!< inline keyword for ARM Compiler */
- #elif defined ( __ICCARM__ )
- #define __ASM __asm /*!< asm keyword for IAR Compiler */
- #define __INLINE inline /*!< inline keyword for IAR Compiler. Only avaiable in High optimization mode! */
- #elif defined ( __GNUC__ )
- #define __ASM __asm /*!< asm keyword for GNU Compiler */
- #define __INLINE inline /*!< inline keyword for GNU Compiler */
- #elif defined ( __TASKING__ )
- #define __ASM __asm /*!< asm keyword for TASKING Compiler */
- #define __INLINE inline /*!< inline keyword for TASKING Compiler */
- #endif
- /*********************************************************************
- * @fn __get_FFLAGS
- *
- * @brief Return the Floating-Point Accrued Exceptions
- *
- * @return fflags value
- */
- uint32_t __get_FFLAGS(void)
- {
- uint32_t result;
- __ASM volatile ( "csrr %0," "fflags" : "=r" (result) );
- return (result);
- }
- /*********************************************************************
- * @fn __set_FFLAGS
- *
- * @brief Set the Floating-Point Accrued Exceptions
- *
- * @param value - set FFLAGS value
- *
- * @return none
- */
- void __set_FFLAGS(uint32_t value)
- {
- __ASM volatile ("csrw fflags, %0" : : "r" (value) );
- }
- /*********************************************************************
- * @fn __get_FRM
- *
- * @brief Return the Floating-Point Dynamic Rounding Mode
- *
- * @return frm value
- */
- uint32_t __get_FRM(void)
- {
- uint32_t result;
- __ASM volatile ( "csrr %0," "frm" : "=r" (result) );
- return (result);
- }
- /*********************************************************************
- * @fn __set_FRM
- *
- * @brief Set the Floating-Point Dynamic Rounding Mode
- *
- * @param value - set frm value
- *
- * @return none
- */
- void __set_FRM(uint32_t value)
- {
- __ASM volatile ("csrw frm, %0" : : "r" (value) );
- }
- /*********************************************************************
- * @fn __get_FCSR
- *
- * @brief Return the Floating-Point Control and Status Register
- *
- * @return fcsr value
- */
- uint32_t __get_FCSR(void)
- {
- uint32_t result;
- __ASM volatile ( "csrr %0," "fcsr" : "=r" (result) );
- return (result);
- }
- /*********************************************************************
- * @fn __set_FCSR
- *
- * @brief Set the Floating-Point Dynamic Rounding Mode
- *
- * @param value - set fcsr value
- *
- * @return none
- */
- void __set_FCSR(uint32_t value)
- {
- __ASM volatile ("csrw fcsr, %0" : : "r" (value) );
- }
- /*********************************************************************
- * @fn __get_MSTATUS
- *
- * @brief Return the Machine Status Register
- *
- * @return mstatus value
- */
- uint32_t __get_MSTATUS(void)
- {
- uint32_t result;
- __ASM volatile ( "csrr %0," "mstatus" : "=r" (result) );
- return (result);
- }
- /*********************************************************************
- * @fn __set_MSTATUS
- *
- * @brief Set the Machine Status Register
- *
- * @param value - set mstatus value
- *
- * @return none
- */
- void __set_MSTATUS(uint32_t value)
- {
- __ASM volatile ("csrw mstatus, %0" : : "r" (value) );
- }
- /*********************************************************************
- * @fn __get_MISA
- *
- * @brief Return the Machine ISA Register
- *
- * @return misa value
- */
- uint32_t __get_MISA(void)
- {
- uint32_t result;
- __ASM volatile ( "csrr %0," "misa" : "=r" (result) );
- return (result);
- }
- /*********************************************************************
- * @fn __set_MISA
- *
- * @brief Set the Machine ISA Register
- *
- * @param value - set misa value
- *
- * @return none
- */
- void __set_MISA(uint32_t value)
- {
- __ASM volatile ("csrw misa, %0" : : "r" (value) );
- }
- /*********************************************************************
- * @fn __get_MTVEC
- *
- * @brief Return the Machine Trap-Vector Base-Address Register
- *
- * @return mtvec value
- */
- uint32_t __get_MTVEC(void)
- {
- uint32_t result;
- __ASM volatile ( "csrr %0," "mtvec" : "=r" (result) );
- return (result);
- }
- /*********************************************************************
- * @fn __set_MTVEC
- *
- * @brief Set the Machine Trap-Vector Base-Address Register
- *
- * @param value - set mtvec value
- *
- * @return none
- */
- void __set_MTVEC(uint32_t value)
- {
- __ASM volatile ("csrw mtvec, %0" : : "r" (value) );
- }
- /*********************************************************************
- * @fn __get_MSCRATCH
- *
- * @brief Return the Machine Seratch Register
- *
- * @return mscratch value
- */
- uint32_t __get_MSCRATCH(void)
- {
- uint32_t result;
- __ASM volatile ( "csrr %0," "mscratch" : "=r" (result) );
- return (result);
- }
- /*********************************************************************
- * @fn __set_MSCRATCH
- *
- * @brief Set the Machine Seratch Register
- *
- * @param value - set mscratch value
- *
- * @return none
- */
- void __set_MSCRATCH(uint32_t value)
- {
- __ASM volatile ("csrw mscratch, %0" : : "r" (value) );
- }
- /*********************************************************************
- * @fn __get_MEPC
- *
- * @brief Return the Machine Exception Program Register
- *
- * @return mepc value
- */
- uint32_t __get_MEPC(void)
- {
- uint32_t result;
- __ASM volatile ( "csrr %0," "mepc" : "=r" (result) );
- return (result);
- }
- /*********************************************************************
- * @fn __set_MEPC
- *
- * @brief Set the Machine Exception Program Register
- *
- * @return mepc value
- */
- void __set_MEPC(uint32_t value)
- {
- __ASM volatile ("csrw mepc, %0" : : "r" (value) );
- }
- /*********************************************************************
- * @fn __get_MCAUSE
- *
- * @brief Return the Machine Cause Register
- *
- * @return mcause value
- */
- uint32_t __get_MCAUSE(void)
- {
- uint32_t result;
- __ASM volatile ( "csrr %0," "mcause" : "=r" (result) );
- return (result);
- }
- /*********************************************************************
- * @fn __set_MEPC
- *
- * @brief Set the Machine Cause Register
- *
- * @return mcause value
- */
- void __set_MCAUSE(uint32_t value)
- {
- __ASM volatile ("csrw mcause, %0" : : "r" (value) );
- }
- /*********************************************************************
- * @fn __get_MTVAL
- *
- * @brief Return the Machine Trap Value Register
- *
- * @return mtval value
- */
- uint32_t __get_MTVAL(void)
- {
- uint32_t result;
- __ASM volatile ( "csrr %0," "mtval" : "=r" (result) );
- return (result);
- }
- /*********************************************************************
- * @fn __set_MTVAL
- *
- * @brief Set the Machine Trap Value Register
- *
- * @return mtval value
- */
- void __set_MTVAL(uint32_t value)
- {
- __ASM volatile ("csrw mtval, %0" : : "r" (value) );
- }
- /*********************************************************************
- * @fn __get_MVENDORID
- *
- * @brief Return Vendor ID Register
- *
- * @return mvendorid value
- */
- uint32_t __get_MVENDORID(void)
- {
- uint32_t result;
- __ASM volatile ( "csrr %0," "mvendorid" : "=r" (result) );
- return (result);
- }
- /*********************************************************************
- * @fn __get_MARCHID
- *
- * @brief Return Machine Architecture ID Register
- *
- * @return marchid value
- */
- uint32_t __get_MARCHID(void)
- {
- uint32_t result;
- __ASM volatile ( "csrr %0," "marchid" : "=r" (result) );
- return (result);
- }
- /*********************************************************************
- * @fn __get_MIMPID
- *
- * @brief Return Machine Implementation ID Register
- *
- * @return mimpid value
- */
- uint32_t __get_MIMPID(void)
- {
- uint32_t result;
- __ASM volatile ( "csrr %0," "mimpid" : "=r" (result) );
- return (result);
- }
- /*********************************************************************
- * @fn __get_MHARTID
- *
- * @brief Return Hart ID Register
- *
- * @return mhartid value
- */
- uint32_t __get_MHARTID(void)
- {
- uint32_t result;
- __ASM volatile ( "csrr %0," "mhartid" : "=r" (result) );
- return (result);
- }
- /*********************************************************************
- * @fn __get_SP
- *
- * @brief Return SP Register
- *
- * @return SP value
- */
- uint32_t __get_SP(void)
- {
- uint32_t result;
- __ASM volatile ( "mv %0," "sp" : "=r"(result) : );
- return (result);
- }
|