Skip to content

Commit a7e6122

Browse files
Merge branch 'fix/lp_periph_use_int_raw' into 'master'
change(lp-core): Update LP I2C and LP UART drivers to use raw interrupt status See merge request espressif/esp-idf!39008
2 parents 644e38f + 0f45b6c commit a7e6122

File tree

7 files changed

+75
-29
lines changed

7 files changed

+75
-29
lines changed

components/hal/esp32c5/include/hal/i2c_ll.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,19 @@ static inline void i2c_ll_get_intr_mask(i2c_dev_t *hw, uint32_t *intr_status)
291291
*intr_status = hw->int_status.val;
292292
}
293293

294+
/**
295+
* @brief Get I2C raw interrupt status
296+
*
297+
* @param hw Beginning address of the peripheral registers
298+
*
299+
* @return I2C raw interrupt status
300+
*/
301+
__attribute__((always_inline))
302+
static inline void i2c_ll_get_intr_raw_mask(i2c_dev_t *hw, uint32_t *intr_status)
303+
{
304+
*intr_status = hw->int_raw.val;
305+
}
306+
294307
/**
295308
* @brief Configure I2C memory access mode, FIFO mode or non-FIFO mode
296309
*

components/hal/esp32c6/include/hal/i2c_ll.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,19 @@ static inline void i2c_ll_get_intr_mask(i2c_dev_t *hw, uint32_t *intr_status)
295295
*intr_status = hw->int_status.val;
296296
}
297297

298+
/**
299+
* @brief Get I2C raw interrupt status
300+
*
301+
* @param hw Beginning address of the peripheral registers
302+
*
303+
* @return I2C raw interrupt status
304+
*/
305+
__attribute__((always_inline))
306+
static inline void i2c_ll_get_intr_raw_mask(i2c_dev_t *hw, uint32_t *intr_status)
307+
{
308+
*intr_status = hw->int_raw.val;
309+
}
310+
298311
/**
299312
* @brief Configure I2C memory access mode, FIFO mode or non-FIFO mode
300313
*

components/hal/esp32p4/include/hal/i2c_ll.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,19 @@ static inline void i2c_ll_get_intr_mask(i2c_dev_t *hw, uint32_t *intr_status)
310310
*intr_status = hw->int_status.val;
311311
}
312312

313+
/**
314+
* @brief Get I2C raw interrupt status
315+
*
316+
* @param hw Beginning address of the peripheral registers
317+
*
318+
* @return I2C raw interrupt status
319+
*/
320+
__attribute__((always_inline))
321+
static inline void i2c_ll_get_intr_raw_mask(i2c_dev_t *hw, uint32_t *intr_status)
322+
{
323+
*intr_status = hw->int_raw.val;
324+
}
325+
313326
/**
314327
* @brief Configure I2C memory access mode, FIFO mode or non-FIFO mode
315328
*

components/ulp/lp_core/lp_core/lp_core_i2c.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -72,7 +72,7 @@ static inline esp_err_t lp_core_i2c_wait_for_interrupt(uint32_t intr_mask, int32
7272
uint32_t to = 0;
7373

7474
while (1) {
75-
i2c_ll_get_intr_mask(dev, &intr_status);
75+
i2c_ll_get_intr_raw_mask(dev, &intr_status);
7676
if (intr_status & intr_mask) {
7777
if (intr_status & LP_I2C_NACK_INT_ST) {
7878
/* The ACK/NACK received during a WRITE operation does not match the expected ACK/NACK level
@@ -82,9 +82,8 @@ static inline esp_err_t lp_core_i2c_wait_for_interrupt(uint32_t intr_mask, int32
8282
return ESP_ERR_INVALID_RESPONSE;
8383
} else if (intr_status & LP_I2C_TRANS_COMPLETE_INT_ST_M) {
8484
/* Transaction complete.
85-
* Disable and clear interrupt bits and break
85+
* Clear interrupt bits and break
8686
*/
87-
i2c_ll_disable_intr_mask(dev, intr_mask);
8887
i2c_ll_clear_intr_mask(dev, intr_mask);
8988
break;
9089
} else {
@@ -105,8 +104,7 @@ static inline esp_err_t lp_core_i2c_wait_for_interrupt(uint32_t intr_mask, int32
105104
ulp_lp_core_delay_cycles(1);
106105
to++;
107106
if (to >= ticks_to_wait) {
108-
/* Disable and clear interrupt bits */
109-
i2c_ll_disable_intr_mask(dev, intr_mask);
107+
/* Timeout. Clear interrupt bits and return an error */
110108
i2c_ll_clear_intr_mask(dev, intr_mask);
111109
return ESP_ERR_TIMEOUT;
112110
}
@@ -169,7 +167,7 @@ esp_err_t lp_core_i2c_master_read_from_device(i2c_port_t lp_i2c_num, uint16_t de
169167

170168
/* Enable trans complete interrupt and end detect interrupt for read/write operation */
171169
uint32_t intr_mask = (1 << LP_I2C_TRANS_COMPLETE_INT_ST_S) | (1 << LP_I2C_END_DETECT_INT_ST_S);
172-
i2c_ll_enable_intr_mask(dev, intr_mask);
170+
i2c_ll_clear_intr_mask(dev, intr_mask);
173171

174172
/* Read data */
175173
uint32_t fifo_size = 0;
@@ -273,7 +271,7 @@ esp_err_t lp_core_i2c_master_write_to_device(i2c_port_t lp_i2c_num, uint16_t dev
273271
/* Enable LP_I2C_NACK_INT to check for ACK errors */
274272
intr_mask |= (1 << LP_I2C_NACK_INT_ST_S);
275273
}
276-
i2c_ll_enable_intr_mask(dev, intr_mask);
274+
i2c_ll_clear_intr_mask(dev, intr_mask);
277275

278276
/* Write data */
279277
uint32_t fifo_available = LP_I2C_FIFO_LEN - addr_len; // Initially, 1 or 2 fifo slots are taken by the device address
@@ -358,7 +356,7 @@ esp_err_t lp_core_i2c_master_write_read_device(i2c_port_t lp_i2c_num, uint16_t d
358356
/* Enable LP_I2C_NACK_INT to check for ACK errors */
359357
intr_mask |= (1 << LP_I2C_NACK_INT_ST_S);
360358
}
361-
i2c_ll_enable_intr_mask(dev, intr_mask);
359+
i2c_ll_clear_intr_mask(dev, intr_mask);
362360

363361
/* Execute RSTART command to send the START bit */
364362
lp_core_i2c_format_cmd(cmd_idx++, I2C_LL_CMD_RESTART, 0, 0, 0, 0);

components/ulp/lp_core/lp_core/lp_core_uart.c

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -99,7 +99,6 @@ esp_err_t lp_core_uart_write_bytes(uart_port_t lp_uart_num, const void *src, siz
9999
/* Enable the Tx done interrupt */
100100
uint32_t intr_mask = LP_UART_TX_INT_FLAG | LP_UART_ERR_INT_FLAG;
101101
uart_hal_clr_intsts_mask(&hal, intr_mask);
102-
uart_hal_ena_intr_mask(&hal, intr_mask);
103102

104103
/* Transmit data */
105104
uint32_t tx_len;
@@ -118,22 +117,23 @@ esp_err_t lp_core_uart_write_bytes(uart_port_t lp_uart_num, const void *src, siz
118117
/* We have managed to write some data to the Tx FIFO. Check Tx interrupt status */
119118
while (1) {
120119
/* Fetch the interrupt status */
121-
intr_status = uart_hal_get_intsts_mask(&hal);
120+
intr_status = uart_hal_get_intraw_mask(&hal);
122121
if (intr_status & LP_UART_TX_INT_FLAG) {
123122
/* Clear interrupt status and break */
124123
uart_hal_clr_intsts_mask(&hal, intr_mask);
125124
break;
126125
} else if ((intr_status & LP_UART_ERR_INT_FLAG)) {
127126
/* Transaction error. Abort */
127+
uart_hal_clr_intsts_mask(&hal, intr_mask);
128128
return ESP_FAIL;
129129
}
130130

131131
/* Check for transaction timeout */
132132
ret = lp_core_uart_check_timeout(intr_mask, timeout, &to);
133133
if (ret == ESP_ERR_TIMEOUT) {
134-
/* Timeout */
135-
uart_hal_disable_intr_mask(&hal, intr_mask);
136-
return ret;
134+
/* Timeout. Clear interrupt status and break */
135+
uart_hal_clr_intsts_mask(&hal, intr_mask);
136+
break;
137137
}
138138
}
139139

@@ -144,16 +144,13 @@ esp_err_t lp_core_uart_write_bytes(uart_port_t lp_uart_num, const void *src, siz
144144
/* Tx FIFO does not have empty slots. Check for transaction timeout */
145145
ret = lp_core_uart_check_timeout(intr_mask, timeout, &to);
146146
if (ret == ESP_ERR_TIMEOUT) {
147-
/* Timeout */
148-
uart_hal_disable_intr_mask(&hal, intr_mask);
149-
return ret;
147+
/* Timeout. Clear interrupt status and break */
148+
uart_hal_clr_intsts_mask(&hal, intr_mask);
149+
break;
150150
}
151151
}
152152
}
153153

154-
/* Disable the Tx done interrupt */
155-
uart_hal_disable_intr_mask(&hal, intr_mask);
156-
157154
return ret;
158155
}
159156

@@ -179,8 +176,6 @@ int lp_core_uart_read_bytes(uart_port_t lp_uart_num, void *buf, size_t size, int
179176
/* Enable the Rx interrupts */
180177
uint32_t intr_mask = LP_UART_RX_INT_FLAG | LP_UART_ERR_INT_FLAG;
181178
uart_hal_clr_intsts_mask(&hal, intr_mask);
182-
uart_hal_ena_intr_mask(&hal, intr_mask);
183-
184179
/* Receive data */
185180
int rx_len = 0;
186181
uint32_t bytes_rcvd = 0;
@@ -198,7 +193,7 @@ int lp_core_uart_read_bytes(uart_port_t lp_uart_num, void *buf, size_t size, int
198193

199194
if (rx_len) {
200195
/* We have some data to read from the Rx FIFO. Check Rx interrupt status */
201-
intr_status = uart_hal_get_intsts_mask(&hal);
196+
intr_status = uart_hal_get_intraw_mask(&hal);
202197
if ((intr_status & UART_INTR_RXFIFO_FULL) ||
203198
(intr_status & UART_INTR_RXFIFO_TOUT)) {
204199
/* This is expected. Clear interrupt status and break */
@@ -212,7 +207,6 @@ int lp_core_uart_read_bytes(uart_port_t lp_uart_num, void *buf, size_t size, int
212207
} else if ((intr_status & LP_UART_ERR_INT_FLAG)) {
213208
/* Transaction error. Abort */
214209
uart_hal_clr_intsts_mask(&hal, intr_mask);
215-
uart_hal_disable_intr_mask(&hal, intr_mask);
216210
return -1;
217211
}
218212

@@ -223,14 +217,13 @@ int lp_core_uart_read_bytes(uart_port_t lp_uart_num, void *buf, size_t size, int
223217
/* We have no data to read from the Rx FIFO. Check for transaction timeout */
224218
ret = lp_core_uart_check_timeout(intr_mask, timeout, &to);
225219
if (ret == ESP_ERR_TIMEOUT) {
220+
/* Timeout. Clear interrupt status and break */
221+
uart_hal_clr_intsts_mask(&hal, intr_mask);
226222
break;
227223
}
228224
}
229225
}
230226

231-
/* Disable the Rx interrupts */
232-
uart_hal_disable_intr_mask(&hal, intr_mask);
233-
234227
/* Return the number of bytes received */
235228
return bytes_rcvd;
236229
}

components/ulp/test_apps/lp_core/lp_core_basic_tests/main/lp_core/test_main_i2c.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -8,6 +8,7 @@
88
#include "test_shared.h"
99
#include "ulp_lp_core_utils.h"
1010
#include "ulp_lp_core_i2c.h"
11+
#include "ulp_lp_core_interrupts.h"
1112

1213
#define LP_I2C_TRANS_WAIT_FOREVER -1
1314

@@ -19,6 +20,13 @@ uint8_t data_wr[DATA_LENGTH] = {};
1920

2021
int main(void)
2122
{
23+
/* Enable interrupts.
24+
* This does not affect how the LP I2C functions
25+
* but it will add extra test coverage to make sure
26+
* the interrupt handler does not cause any issues.
27+
*/
28+
ulp_lp_core_intr_enable();
29+
2230
lp_core_i2c_master_read_from_device(LP_I2C_NUM_0, I2C_SLAVE_ADDRESS, data_rd, RW_TEST_LENGTH, LP_I2C_TRANS_WAIT_FOREVER);
2331
read_test_reply = LP_CORE_COMMAND_OK;
2432

components/ulp/test_apps/lp_core/lp_core_basic_tests/main/lp_core/test_main_uart.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "ulp_lp_core_uart.h"
1212
#include "ulp_lp_core_print.h"
1313
#include "soc/soc_caps.h"
14+
#include "ulp_lp_core_interrupts.h"
1415

1516
#define LP_UART_PORT_NUM LP_UART_NUM_0
1617
#define LP_UART_BUFFER_LEN UART_BUF_SIZE
@@ -37,6 +38,13 @@ volatile char test_character;
3738

3839
int main(void)
3940
{
41+
/* Enable interrupts.
42+
* This does not affect how the LP UART functions
43+
* but it will add extra test coverage to make sure
44+
* the interrupt handler does not cause any issues.
45+
*/
46+
ulp_lp_core_intr_enable();
47+
4048
while (1) {
4149
/* Wait for the HP core to start the test */
4250
while (test_cmd == LP_CORE_NO_COMMAND) {

0 commit comments

Comments
 (0)