@@ -79,20 +79,32 @@ extern "C" {
7979/* Align the level to the left, and put 1 in the lowest bits */
8080#define NLBITS_TO_BYTE (level ) (((level) << NLBITS_SHIFT) | ((1 << NLBITS_SHIFT) - 1))
8181
82+ /**
83+ * @brief In the minstatus CSR, the `mil` field is present from bit 24 to bit 31 (included)
84+ */
85+ #define MINTSTATUS_MIL_S 24
86+ #define MINTSTATUS_MIL_V 0xFF
87+
8288
8389#if INTTHRESH_STANDARD
84- /* Helper macro to translate absolute interrupt level to CLIC interrupt threshold bits in the mintthresh reg */
85- #define CLIC_INT_THRESH (intlevel ) (NLBITS_TO_BYTE(intlevel))
90+ /* Helper macro to translate absolute interrupt level to CLIC interrupt threshold bits in the mintthresh reg */
91+ #define CLIC_INT_THRESH (intlevel ) (NLBITS_TO_BYTE(intlevel))
8692
87- /* Helper macro to translate a CLIC interrupt threshold bits to an absolute interrupt level */
88- #define CLIC_THRESH_TO_INT (intlevel ) (BYTE_TO_NLBITS((intlevel)))
93+ /* Helper macro to translate a CLIC interrupt threshold bits to an absolute interrupt level */
94+ #define CLIC_THRESH_TO_INT (intlevel ) (BYTE_TO_NLBITS((intlevel)))
95+
96+ /* Helper macro to translate a CLIC status threshold bits to an absolute interrupt level */
97+ #define CLIC_STATUS_TO_INT (status ) (BYTE_TO_NLBITS((status >> MINTSTATUS_MIL_S) & MINTSTATUS_MIL_V))
8998#else
90- /* For the non-standard intthresh implementation the threshold is stored in the upper 8 bits of CLIC_CPU_INT_THRESH reg */
91- /* Helper macro to translate absolute interrupt level to CLIC interrupt threshold bits in the mintthresh reg */
92- #define CLIC_INT_THRESH (intlevel ) (NLBITS_TO_BYTE(intlevel) << CLIC_CPU_INT_THRESH_S)
99+ /* For the non-standard intthresh implementation the threshold is stored in the upper 8 bits of CLIC_CPU_INT_THRESH reg */
100+ /* Helper macro to translate absolute interrupt level to CLIC interrupt threshold bits in the mintthresh reg */
101+ #define CLIC_INT_THRESH (intlevel ) (NLBITS_TO_BYTE(intlevel) << CLIC_CPU_INT_THRESH_S)
102+
103+ /* Helper macro to translate a CLIC interrupt threshold bits to an absolute interrupt level */
104+ #define CLIC_THRESH_TO_INT (intlevel ) (BYTE_TO_NLBITS((intlevel >> CLIC_CPU_INT_THRESH_S) & CLIC_CPU_INT_THRESH_V))
93105
94- /* Helper macro to translate a CLIC interrupt threshold bits to an absolute interrupt level */
95- #define CLIC_THRESH_TO_INT ( intlevel ) (BYTE_TO_NLBITS((intlevel >> CLIC_CPU_INT_THRESH_S ) & CLIC_CPU_INT_THRESH_V ))
106+ /* Helper macro to translate a CLIC status threshold bits to an absolute interrupt level */
107+ #define CLIC_STATUS_TO_INT ( status ) (BYTE_TO_NLBITS((status >> MINTSTATUS_MIL_S ) & MINTSTATUS_MIL_V ))
96108#endif //INTTHRESH_STANDARD
97109
98110/* Helper macro to set interrupt level RVHAL_EXCM_LEVEL. Used during critical sections */
@@ -151,7 +163,7 @@ FORCE_INLINE_ATTR uint32_t rv_utils_get_interrupt_level(void)
151163{
152164 const uint32_t mintstatus = RV_READ_CSR (MINTSTATUS_CSR );
153165 /* Extract the level from this field */
154- return CLIC_THRESH_TO_INT (mintstatus );
166+ return CLIC_STATUS_TO_INT (mintstatus );
155167}
156168
157169/**
0 commit comments