Skip to content

Commit dce5170

Browse files
o-marshmallowespressif-bot
authored andcommitted
fix(riscv): fix a that affected mintstatus CSR value in the CLIC
1 parent 8795e7a commit dce5170

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

components/riscv/include/esp_private/interrupt_clic.h

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)