Skip to content

Commit f324e75

Browse files
committed
fix(interrupt): fixed interrupt thresholds not working on C5
1 parent ea010f8 commit f324e75

File tree

1 file changed

+30
-19
lines changed

1 file changed

+30
-19
lines changed

components/riscv/include/esp_private/interrupt_clic.h

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,27 @@ extern "C" {
4646
#define MTVT_CSR 0x307
4747

4848

49+
#if CONFIG_IDF_TARGET_ESP32P4 || CONFIG_IDF_TARGET_ESP32C5_BETA3_VERSION
50+
51+
/**
52+
* The ESP32-P4 and the beta version of the ESP32-C5 implement a non-standard version of the CLIC:
53+
* - The interrupt threshold is configured via a memory-mapped register instead of a CSR
54+
* - The mintstatus CSR is at 0x346 instead of 0xFB1 as per the official specification
55+
*/
56+
#define INTTHRESH_STANDARD 0
57+
#define MINTSTATUS_CSR 0x346
58+
59+
#elif CONFIG_IDF_TARGET_ESP32C5 || CONFIG_IDF_TARGET_ESP32C61
60+
61+
/* The ESP32-C5 (MP) and C61 use the standard CLIC specification, for example, it defines the mintthresh CSR */
62+
#define INTTHRESH_STANDARD 1
63+
#define MINTSTATUS_CSR 0xFB1
64+
#define MINTTHRESH_CSR 0x347
65+
66+
#else
67+
#error "Check the implementation of the CLIC on this target."
68+
#endif
69+
4970
/**
5071
* @brief Convert a priority level from 8-bit to NLBITS and NLBITS to 8-bit
5172
*
@@ -59,11 +80,20 @@ extern "C" {
5980
#define NLBITS_TO_BYTE(level) (((level) << NLBITS_SHIFT) | ((1 << NLBITS_SHIFT) - 1))
6081

6182

83+
#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))
86+
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)))
89+
#else
90+
/* For the non-standard intthresh implementation the threshold is stored in the upper 8 bits of CLIC_CPU_INT_THRESH reg */
6291
/* Helper macro to translate absolute interrupt level to CLIC interrupt threshold bits in the mintthresh reg */
6392
#define CLIC_INT_THRESH(intlevel) (NLBITS_TO_BYTE(intlevel) << CLIC_CPU_INT_THRESH_S)
6493

6594
/* Helper macro to translate a CLIC interrupt threshold bits to an absolute interrupt level */
6695
#define CLIC_THRESH_TO_INT(intlevel) (BYTE_TO_NLBITS((intlevel >> CLIC_CPU_INT_THRESH_S) & CLIC_CPU_INT_THRESH_V))
96+
#endif //INTTHRESH_STANDARD
6797

6898
/* Helper macro to set interrupt level RVHAL_EXCM_LEVEL. Used during critical sections */
6999
#define RVHAL_EXCM_LEVEL_CLIC (CLIC_INT_THRESH(RVHAL_EXCM_LEVEL - 1))
@@ -72,26 +102,7 @@ extern "C" {
72102
#define RVHAL_INTR_ENABLE_THRESH_CLIC (CLIC_INT_THRESH(RVHAL_INTR_ENABLE_THRESH))
73103

74104

75-
#if CONFIG_IDF_TARGET_ESP32P4 || CONFIG_IDF_TARGET_ESP32C5_BETA3_VERSION
76-
77-
/**
78-
* The ESP32-P4 and the beta version of the ESP32-C5 implement a non-standard version of the CLIC:
79-
* - The interrupt threshold is configured via a memory-mapped register instead of a CSR
80-
* - The mintstatus CSR is at 0x346 instead of 0xFB1 as per the official specification
81-
*/
82-
#define INTTHRESH_STANDARD 0
83-
#define MINTSTATUS_CSR 0x346
84-
85-
#elif CONFIG_IDF_TARGET_ESP32C5 || CONFIG_IDF_TARGET_ESP32C61
86-
87-
/* The ESP32-C5 (MP) and C61 use the standard CLIC specification, for example, it defines the mintthresh CSR */
88-
#define INTTHRESH_STANDARD 1
89-
#define MINTSTATUS_CSR 0xFB1
90-
#define MINTTHRESH_CSR 0x347
91105

92-
#else
93-
#error "Check the implementation of the CLIC on this target."
94-
#endif
95106

96107

97108
FORCE_INLINE_ATTR void assert_valid_rv_int_num(int rv_int_num)

0 commit comments

Comments
 (0)